Skip to content

Commit

Permalink
Bug fixes and additinal diagnostics added.
Browse files Browse the repository at this point in the history
Version update.

Changes to be committed:
	modified:   Base/JackrabbitLocker
	modified:   Base/JackrabbitOliverTwist
	modified:   Base/JackrabbitRelay
	modified:   Base/Library/JRRmimic.py
	modified:   Base/Library/JRRsupport.py
	modified:   Base/Library/JackrabbitProxy.py
	modified:   Base/Library/JackrabbitRelay.py
	modified:   Extras/CodeProofs/readOHLCV
	new file:   Extras/OliverTwist/ot2gb
  • Loading branch information
rapmd73 committed Oct 23, 2024
1 parent ae04cdc commit e39a8f3
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Base/JackrabbitLocker
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import json

import JRRsupport

Version="0.0.0.1.1000"
Version="0.0.0.1.1005"
BaseDirectory='/home/JackrabbitRelay2/Base'
ConfigDirectory='/home/JackrabbitRelay2/Config'
LogDirectory="/home/JackrabbitRelay2/Logs"
Expand Down
89 changes: 50 additions & 39 deletions Base/JackrabbitOliverTwist
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
# 2021 Copyright © Robert APM Darin
# All rights reserved unconditionally.

# This is the Jackrabbit limit order manager. Its purpose is to track and maintain "orphaned" orders. Orphan
# orders are liit order that the parent or order initiator does not wat a response for. TradingView is an
# example, but the situation applies to any process that does not manage or maintain limit orders on their
# own.

# IMPORTANT: Under no circumstances should THIS program manage an individual order. It is to be managed by a
# separate process, called an orphan manager. This is simply because there is no way on knowing how many
# exchanges/brokers might be used simultaneously. The memory of a single process managing a thousand orders
# would be absolutely thrashed. The orphan manager will follow the same conventions of the PlaceOrder
# program, ie:
# This is the Jackrabbit limit order manager. Its purpose is to track and maintain
# "orphaned" orders. Orphan orders are liit order that the parent or order
# initiator does not wat a response for. TradingView is an example, but the
# situation applies to any process that does not manage or maintain limit orders on
# their own.

# IMPORTANT: Under no circumstances should THIS program manage an individual order.
# It is to be managed by a separate process, called an orphan manager. This is
# simply because there is no way on knowing how many exchanges/brokers might be
# used simultaneously. The memory of a single process managing a thousand orders
# would be absolutely thrashed. The orphan manager will follow the same conventions
# of the PlaceOrder program, ie:

# Old:
# Orphan.ccxt
Expand All @@ -28,23 +30,28 @@
# OliverTwist-mimic
# OliverTwist-oanda

# ANY order (direct orphan or conditional) is an ORPHAN at all times withis THIS framework.
# ANY order (direct orphan or conditional) is an ORPHAN at all times withis THIS
# framework.

# IMPORTANT: This fraework treats conditionals the same as orphans. The separation and distinction takes
# place in the transactor. While this has plenty of issues to be aware of, it is the most effecient way of
# handling the situation since at this level (dispatcher), they are syntactically the same.
# IMPORTANT: This fraework treats conditionals the same as orphans. The separation
# and distinction takes place in the transactor. While this has plenty of issues to
# be aware of, it is the most effecient way of handling the situation since at this
# level (dispatcher), they are syntactically the same.

# Framework identification, along with any other order verification, is done in the PlaceOrder
# Framework identification, along with any other order verification, is done in the
# PlaceOrder

# MIGRATE to checking the highest (take profit) and lowat prices (stop loss), rather then checking every
# order. This will optimize heavy usagevsystem to handle the most relevant orders first. Will need rethings
# on order list processing approach and methedology.
# MIGRATE to checking the highest (take profit) and lowat prices (stop loss),
# rather then checking every order. This will optimize heavy usagevsystem to handle
# the most relevant orders first. Will need rethings on order list processing
# approach and methedology.

# MOVE to reading storehouse every pass and write price data into main store house... Reading orderdetails
# is 3 minutes for order sweep, pre processing orders brings the time down to 0.00015 seconds. Be re-reading
# the storehouse each pass, we can update order as received to maintain sweepspeed. Reading the ticker will
# slow thing down, but breaking the storehouse down to exchange/account/asset with high/low extreme analysis
# will dramatically improve performance.
# MOVE to reading storehouse every pass and write price data into main store
# house... Reading orderdetails is 3 minutes for order sweep, pre processing orders
# brings the time down to 0.00015 seconds. Be re-reading the storehouse each pass,
# we can update order as received to maintain sweepspeed. Reading the ticker will
# slow thing down, but breaking the storehouse down to exchange/account/asset with
# high/low extreme analysis will dramatically improve performance.

import sys
sys.path.append('/home/JackrabbitRelay2/Base/Library')
Expand All @@ -60,7 +67,7 @@ import subprocess
import JRRsupport
import JackrabbitRelay as JRR

Version="0.0.0.1.1000"
Version="0.0.0.1.1005"
BaseDirectory='/home/JackrabbitRelay2/Base'
DataDirectory='/home/JackrabbitRelay2/Data'
ConfigDirectory='/home/JackrabbitRelay2/Config'
Expand Down Expand Up @@ -118,9 +125,9 @@ def GetID():
pw+=oc
return pw

# Split the complete list stored on disk, if it exists. Supports both orphans and conditionals.
# RUNS ONLY ONCE, no locking needed as this runs at the very start, if it runs at all.
# At some FUTURE point, this will be REMOVED.
# Split the complete list stored on disk, if it exists. Supports both orphans and
# conditionals. RUNS ONLY ONCE, no locking needed as this runs at the very start,
# if it runs at all. At some FUTURE point, this will be REMOVED.

def SplitStorehouse(cltype=None):
# Required as the blobals are modified
Expand Down Expand Up @@ -160,8 +167,8 @@ def SplitStorehouse(cltype=None):
JRLog.Write(f"Broken: {Entry}")
continue

# I need to be able to extract Exchange, account, and asset to build the separate pair
# files.
# I need to be able to extract Exchange, account, and asset to
# build the separate pair files.

if 'Order' in Orphan:
if type(Orphan['Order'])==str:
Expand All @@ -181,16 +188,18 @@ def SplitStorehouse(cltype=None):
idx=f"{exchange}.{account}.{asset}"
fname=f"{OliverTwistData}/{idx}.Storehouse"

# Write out the new storehouse. We already have the complete line from the original, just
# use it. This is not about preprocessing, only converting.
# Write out the new storehouse. We already have the complete line
# from the original, just use it. This is not about preprocessing,
# only converting.

JRRsupport.AppendFile(fname,Entry+'\n')
rc+=1

if rc>0:
JRLog.Write(f"{rc} record(s) converted")

# Read the complete list stored on disk, if it exists. Supports both orphans and conditionals.
# Read the complete list stored on disk, if it exists. Supports both orphans and
# conditionals.

def ReadReceiver():
# Required as the blobals are modified
Expand Down Expand Up @@ -329,7 +338,8 @@ def WriteStorehouse(idx,OrphanList,deleteKey=None):
interceptor.Critical(False)
JRLog.Write(f"{idx}/{len(OrphanList)} order(s) written in {str(datetime.datetime.now()-StartTime)} seconds")

# Read the complete list stored on disk, if it exists. Supports both orphans and conditionals.
# Read the complete list stored on disk, if it exists. Supports both orphans and
# conditionals.

def ReadStorehouse(idx=None,OrigOrphanList=None):
# Required as the blobals are modified
Expand Down Expand Up @@ -446,18 +456,19 @@ def ProcessOrphan(**kwargs):
osh=kwargs
State='Waiting'

# Massive headache: One of the most significant issues is that we don't know anything about any of the
# orders, so the processor needs to deal with everthing now in a layered approach. At the level we are
# at in this function, we only know the index and framework. Orphan and Conditional status is completely
# unknown...
# Massive headache: One of the most significant issues is that we don't know
# anything about any of the orders, so the processor needs to deal with
# everthing now in a layered approach. At the level we are at in this function,
# we only know the index and framework. Orphan and Conditional status is
# completely unknown...

try:
# We NEED the framework.
idxList=osh['IDX'].split('.')
relay=JRR.JackrabbitRelay(exchange=idxList[0],account=idxList[1],asset=idxList[2])

# IMPORTANT: Modules loaded this way do NOT have access to anything of the parent. These
# modules are in complete and total isolation.
# IMPORTANT: Modules loaded this way do NOT have access to anything of the
# parent. These modules are in complete and total isolation.

Processor=importlib.import_module(f"OliverTwist-{relay.Framework}")
State=Processor.OrderProcessor(osh)
Expand Down
2 changes: 1 addition & 1 deletion Base/JackrabbitRelay
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import json

import JRRsupport

Version="0.0.0.1.1000"
Version="0.0.0.1.1005"
BaseDirectory='/home/JackrabbitRelay2/Base'
ConfigDirectory='/home/JackrabbitRelay2/Config'
LogDirectory="/home/JackrabbitRelay2/Logs"
Expand Down
2 changes: 1 addition & 1 deletion Base/Library/JRRmimic.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class mimic:
# placed in init and released at exit.

def __init__(self,Exchange,Config,Active,DataDirectory=None):
self.Version="0.0.0.1.1000"
self.Version="0.0.0.1.1005"

self.StableCoinUSD=['USDT','USDC','BUSD','UST','DAI','FRAX','TUSD', \
'USDP','LUSD','USDN','HUSD','FEI','TRIBE','RSR','OUSD','XSGD', \
Expand Down
3 changes: 1 addition & 2 deletions Base/Library/JRRsupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,7 @@ def list(self):
# Create a directory

def mkdir(fn):
if not os.path.isdir(fn):
os.makedirs(fn)
os.makedirs(fn,exist_ok=True)

# Get Yesterday's date

Expand Down
2 changes: 1 addition & 1 deletion Base/Library/JackrabbitProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
class JackrabbitProxy:
def __init__(self,framework=None,payload=None,exchange=None,account=None,asset=None,Usage=None):
# All the default locations
self.Version="0.0.0.1.1000"
self.Version="0.0.0.1.1005"
self.BaseDirectory='/home/JackrabbitRelay2/Base'
self.ConfigDirectory='/home/JackrabbitRelay2/Config'
self.DataDirectory="/home/JackrabbitRelay2/Data"
Expand Down
2 changes: 1 addition & 1 deletion Base/Library/JackrabbitRelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def Success(self,f,s):
class JackrabbitRelay:
def __init__(self,framework=None,payload=None,exchange=None,account=None,asset=None,secondary=None,NoIdentityVerification=False,Usage=None,RaiseError=False):
# All the default locations
self.Version="0.0.0.1.1000"
self.Version="0.0.0.1.1005"
self.NOhtml='<html><title>NO!</title><body style="background-color:#ffff00;display:flex;weight:100vw;height:100vh;align-items:center;justify-content:center"><h1 style="color:#ff0000;font-weight:1000;font-size:10rem">NO!</h1></body></html>'
self.Directories={}
self.Directories['Base']='/home/JackrabbitRelay2/Base'
Expand Down
3 changes: 1 addition & 2 deletions Extras/CodeProofs/readOHLCV
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ markets=relay.GetMarkets()
ohlcv=relay.GetOHLCV(symbol=asset,timeframe=tf,limit=count)

for slice in ohlcv:
print(slice)

print(','.join(f'{value:.5f}' for value in slice))
107 changes: 107 additions & 0 deletions Extras/OliverTwist/ot2gb
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Jackrabbit Relay
# 2021 Copyright © Robert APM Darin
# All rights reserved unconditionally.

import sys
sys.path.append('/home/JackrabbitRelay2/Base/Library')
import os
import time
import datetime
import json

import JRRsupport
import JackrabbitRelay as JRR

# Oliver Twist log
# 2024-08-01 06:35:32.669979 476486 88557 -> 88528 Prft short, 71.0: 1.08271 -> 1.081480/0.08730, 4:36:21.447434

chartDir='/home/JackrabbitRelay2/Data/Charts/'

# Initialize global signal interceptor. prevent file trashing on CTRL-C

Log=JRR.JackrabbitLog()
interceptor=JRRsupport.SignalInterceptor(Log=Log)

###
### Main code base.
###

if len(sys.argv)<2:
print("An least OliverTwist log file is required.")
sys.exit(1)

entry={}
relay={}
lines={}
orderList={}

# Copy arg list
gblog=sys.argv[1]

# Remove sys arg list

for i in range(1,len(sys.argv)):
sys.argv.remove(sys.argv[1])

# Read the log file

data=gblog.split('.')

account=data[2]
asset=data[3]

# Add the /
pair=asset[:3]+'/'+asset[3:]
relay=JRR.JackrabbitRelay(framework='oanda',exchange=data[1],account=account,asset=pair)
lines=JRRsupport.ReadFile(gblog).strip().split('\n')

# Get the order IDs and read them into a dictionary.

oList=[]
nList=[]
nLines=[]

for line in lines:
line=line.lower()
if line=='' or ('prft' not in line and 'rduc' not in line and 'loss' not in line):
continue

data=line.split(' ')
while '' in data:
data.remove('')

# Selling date/time
sdt=data[0]+' '+data[1]
pid=data[2]
id=data[3]
cid=data[5]
act=data[6]
dir=data[7].replace(',','')
amt=data[8].replace(':','')
bp=data[9]
sp,rpl=data[11].split('/')
dur=' '.join(data[12:])

oDetail=relay.GetOrderDetails(OrderID=id)[-1]

# Buying date/time
parts=oDetail['time'].replace('T',' ').replace('Z','').split('.')
bdt=f"{parts[0]}.{parts[1][:6]}"
if act=='rduc':
amt=oDetail['units']
bal=oDetail['accountBalance']

if dir=='shrt' or dir=='short':
dir='Short'

nav=float(bp)*abs(float(amt))

if act=='prft' or act=='loss':
print(f"{bdt} {pid} OT {dir} - {id} Buy @{bp} -> {amt}")
print(f"{sdt} {pid} OT {id} {dir} - {cid} Sell {amt} @{sp} -> {rpl} {bal}/{nav:.5f} {dur}")

if act=='rduc':
print(f"{sdt} {pid} OT {id} {dir} - {cid} ReduceBy {1} @{sp} -> {rpl} {bal}/{nav:.5f}")

0 comments on commit e39a8f3

Please sign in to comment.