Skip to content

Commit

Permalink
Alpha testing bug fixes...
Browse files Browse the repository at this point in the history
Oanda ReduceBy bug fixed...

"Not enough balance" issues addressed.

Changes to be committed:
	modified:   Base/JackrabbitOliverTwist
	modified:   Base/Library/JRRfix.py
	modified:   Base/Library/JRRmimic.py
	modified:   Base/Library/JRRoanda.py
	modified:   Base/Library/OliverTwist-ccxt.py
	modified:   Base/Library/OliverTwist-mimic.py
	modified:   Base/Library/OliverTwist-oanda.py
	modified:   Extras/OliverTwist/OliverTwistEquity
	modified:   Extras/OliverTwist/OliverTwistTrades
	modified:   Extras/OliverTwist/otcWatch
  • Loading branch information
rapmd73 committed Sep 16, 2024
1 parent 340e51a commit 8aac346
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 54 deletions.
24 changes: 9 additions & 15 deletions Base/JackrabbitOliverTwist
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
# 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.
# 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:
# 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 Down Expand Up @@ -412,13 +414,6 @@ def ReadStorehouse(idx=None,OrigOrphanList=None):
JRLog.Write(f"Broken classifier: {Entry}")
continue

# Remove old unnessary data from Storehouse

if 'mID' in Orphan:
Orphan.pop('mID',None)
if 'lID' in Orphan:
Orphan.pop('lID',None)

# Make sure price IS of orphan data

if 'Price' not in Orphan:
Expand Down Expand Up @@ -594,4 +589,3 @@ def main():

if __name__=='__main__':
main()

Empty file modified Base/Library/JRRfix.py
100644 → 100755
Empty file.
Empty file modified Base/Library/JRRmimic.py
100644 → 100755
Empty file.
Empty file modified Base/Library/JRRoanda.py
100644 → 100755
Empty file.
11 changes: 2 additions & 9 deletions Base/Library/OliverTwist-ccxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@ def ReadStorehouse(idx=None,OrigOrphanList=None):
JRLog.Write(f"Broken: {order}")
continue

# Remove old unnessary data from Storehouse

if 'mID' in Orphan:
Orphan.pop('mID',None)
if 'lID' in Orphan:
Orphan.pop('lID',None)

# Make sure price IS of orphan data

if 'Price' not in Orphan:
Expand All @@ -151,8 +144,8 @@ def ReadStorehouse(idx=None,OrigOrphanList=None):
OrphanList[Orphan['Key']]=Orphan
rc+=1

if rc==0:
os.remove(WorkingStorehouse)
# if rc==0:
# os.remove(WorkingStorehouse)
return OrphanList

# Get the hiest and lowest priced orders.
Expand Down
11 changes: 2 additions & 9 deletions Base/Library/OliverTwist-mimic.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,6 @@ def ReadStorehouse(idx=None,OrigOrphanList=None):
JRLog.Write(f"Broken: {order}")
continue

# Remove old unnessary data from Storehouse

if 'mID' in Orphan:
Orphan.pop('mID',None)
if 'lID' in Orphan:
Orphan.pop('lID',None)

# Make sure price IS of orphan data

if 'Price' not in Orphan:
Expand All @@ -150,8 +143,8 @@ def ReadStorehouse(idx=None,OrigOrphanList=None):

rc+=1

if rc==0:
os.remove(WorkingStorehouse)
# if rc==0:
# os.remove(WorkingStorehouse)
return OrphanList

# Get the hiest and lowest priced orders.
Expand Down
17 changes: 5 additions & 12 deletions Base/Library/OliverTwist-oanda.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,6 @@ def ReadStorehouse(idx=None,OrigOrphanList=None):
except Exception as err:
continue

# Remove old unnessary data from Storehouse

if 'mID' in Orphan:
Orphan.pop('mID',None)
if 'lID' in Orphan:
Orphan.pop('lID',None)

# Make sure price IS of orphan data

if 'Price' not in Orphan:
Expand All @@ -151,8 +144,8 @@ def ReadStorehouse(idx=None,OrigOrphanList=None):

rc+=1

if rc==0:
os.remove(WorkingStorehouse)
# if rc==0:
# os.remove(WorkingStorehouse)
return OrphanList

# Get the hiest and lowest priced orders.
Expand Down Expand Up @@ -227,10 +220,10 @@ def CalculatePriceExit(order,ts,dir,price,onePip):

def ReduceLotSize(relay,oldestTrade=None,val=1):
try:
relay.JRLog.Write(f"RLS A: {json.dumps(oldestTrade)}")
if oldestTrade==None:
return
Order=lowestTrade['Order']
relay.JRLog.Write(f"RLS A: {json.dumps(oldestTrade)}")
pair=Order['Asset']

# Verify the trade exists. If it doesn't, delete the key
Expand Down Expand Up @@ -339,7 +332,7 @@ def ProcessOrder(relay,Order,cid,units,price,strikePrice,ds,lowestOrder=None):
LogMSG=f"{oid} -> {cid} Loss {dir}, {units}: {price:.5f} -> {sprice:5f}/{abs(rpl):.5f}, {duration}"
relay.JRLog.Write(f"{LogMSG}")

relay.JRLog.Write(f"{rpl}")
relay.JRLog.Write(f"RPL: {rpl}")
if rpl>0:
# Don't reduce if we have a loss

Expand Down Expand Up @@ -490,7 +483,7 @@ def CheckTakeProfit(relay,Orphan,lowestTrade):
ds=datetime.datetime.strptime(dsS,'%Y-%m-%dT%H:%M:%S.%fZ')
units=abs(float(orderDetail[-1]['units']))

ProcessOrder(relay,Order,cid,units,price,strikePrice,ds)
ProcessOrder(relay,Order,cid,units,price,strikePrice,ds,lowestOrder=lowestTrade)
return Orphan['Key']
else:
# Strike did not happen
Expand Down
4 changes: 2 additions & 2 deletions Extras/OliverTwist/OliverTwistEquity
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ else:
lines=JRRsupport.ReadFile(sys.argv[2]).strip().split('\n')

for line in lines:
if line=='' or ('Prft' not in line and 'Loss' not in line):
if line=='' or ('Prft' not in line and 'Loss' not in line and 'Rduc' not in line):
continue

data=line.split(' ')
Expand All @@ -69,7 +69,7 @@ for line in lines:

if 'Prft' in line:
pnl+=float(pdata)
if 'Loss' in line:
if 'Loss' in line or 'Rduc' in line:
pnl-=float(pdata)

xps.append(dt)
Expand Down
2 changes: 1 addition & 1 deletion Extras/OliverTwist/OliverTwistTrades
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ for order in OpenOrders:
du=float(order['Response']['Details']['Amount'])
dp=float(order['Response']['Details']['Price'])
else: # CCXT framework fall through
du=float(order['Response']['Details']['Amount'])
du=float(order['Response']['Details']['amount'])
dp=float(order['Response']['Details']['price'])

htxt=f"{order['ID']}: {du:.0f}@{dp:.5f}"
Expand Down
15 changes: 9 additions & 6 deletions Extras/OliverTwist/otcWatch
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import JRRsupport
import JackrabbitRelay as JRR

DataDirectory='/home/JackrabbitRelay2/Data'
ConditionalStorehouse=DataDirectory+'/OliverTwist.Storehouse'
ConditionalStorehouse=OliverTwistData=DataDirectory+'/OliverTwist/'

OliverTwistLock=JRRsupport.Locker("OliverTwist")

Expand Down Expand Up @@ -62,9 +62,11 @@ def CalculatePriceExit(order,ts,dir,price):
return val

def main():
if len(sys.argv)>2:
if len(sys.argv)>3:
exchange=sys.argv[1].lower()
account=sys.argv[2]
asset=sys.argv[3]
pair=asset.replace('/','').replace('-','').replace(':','')
else:
print("Exchange/Broker and account must be provided.")
sys.exit(0)
Expand All @@ -73,10 +75,11 @@ def main():
if len(sys.argv)>3:
srch=sys.argv[3]

OliverTwistLock.Lock()
if os.path.exists(ConditionalStorehouse):
buffer=JRRsupport.ReadFile(ConditionalStorehouse).strip()
OliverTwistLock.Unlock()
shf=f"{ConditionalStorehouse}{exchange}.{account}.{pair}.Storehouse"
# OliverTwistLock.Lock()
if os.path.exists(shf):
buffer=JRRsupport.ReadFile(shf).strip()
# OliverTwistLock.Unlock()

Relay={}
TickerData={}
Expand Down

0 comments on commit 8aac346

Please sign in to comment.