Skip to content

Commit

Permalink
Bug fixes and optimizations. The new OT ResizeLotSize is slowly commi…
Browse files Browse the repository at this point in the history
…ng together...

Changes to be committed:
	modified:   Base/JackrabbitOliverTwist
	modified:   Base/Library/OliverTwist-ccxt.py
	modified:   Base/Library/OliverTwist-mimic.py
	modified:   Base/Library/OliverTwist-oanda.py
  • Loading branch information
rapmd73 committed Sep 19, 2024
1 parent 8aac346 commit 5d61423
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Base/JackrabbitOliverTwist
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ def main():

EndTime=datetime.datetime.now()
Elapsed=(EndTime-StartTime)
if len(idx)>NumberProcesses:
JRLog.Write(f"{len(StorehouseIDX)} assets scanned in "+str(Elapsed)+" seconds")
# if len(idx)>(NumberProcesses*3):
# JRLog.Write(f"{len(StorehouseIDX)} assets scanned in "+str(Elapsed)+" seconds")

JRRsupport.ElasticSleep(1)
# Safe way of cleanly existing to tracking and diagnostics
Expand Down
12 changes: 6 additions & 6 deletions Base/Library/OliverTwist-ccxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,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 Expand Up @@ -276,9 +276,9 @@ def ProcessOrder(relay,Order,cid,amount,price,strikePrice,ds):
reason=relay.GetFailedReason(result).lower()
relay.JRLog.Write(f"{cid}: Order failed with {reason}")
# If there isnt enough balance, remove the order
if 'insufficient balance' in reason \
or 'not enough to sell/close' in reason \
or 'not enough balance' in reason:
if 'insufficient balance' in reason.lower() \
or 'not enough to sell/close' in reason.lower() \
or 'not enough balance' in reason.lower():
return True
return False
except Exception as e:
Expand Down Expand Up @@ -557,6 +557,6 @@ def OrderProcessor(osh):
relay.JRLog.Write(f"OT CCXT Broke {sys.exc_info()[-1].tb_lineno}: {idx}, {err}",stdOut=False)

EndTime=datetime.datetime.now()
JRLog.Write(f"OP CCXT Elapsed {idx}/{len(OrphanList)}: {EndTime-StartTime} seconds")
# JRLog.Write(f"OP CCXT Elapsed {idx}/{len(OrphanList)}: {EndTime-StartTime} seconds")

return 'Waiting'
9 changes: 5 additions & 4 deletions Base/Library/OliverTwist-mimic.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ def ReadStorehouse(idx=None,OrigOrphanList=None):

rc+=1

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

# Get the hiest and lowest priced orders.
Expand Down Expand Up @@ -274,7 +275,7 @@ def ProcessOrder(relay,Order,cid,amount,price,strikePrice,ds):
# Give OliverTwist a response
relay.JRLog.Write(f"{cid}: Order failed with {relay.GetFailedReason(result)}")
# If there isnt enough balance, remove the order
if 'not enough balance' in result:
if 'not enough balance' in result.lower():
return True
return False
except Exception as e:
Expand Down Expand Up @@ -537,6 +538,6 @@ def OrderProcessor(osh):
# shLock.Unlock()

EndTime=datetime.datetime.now()
JRLog.Write(f"OP MIMIC Elapsed {idx}/{len(OrphanList)}: {EndTime-StartTime} seconds")
# JRLog.Write(f"OP MIMIC Elapsed {idx}/{len(OrphanList)}: {EndTime-StartTime} seconds")

return 'Waiting'
25 changes: 16 additions & 9 deletions Base/Library/OliverTwist-oanda.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,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 @@ -223,12 +223,12 @@ def ReduceLotSize(relay,oldestTrade=None,val=1):
relay.JRLog.Write(f"RLS A: {json.dumps(oldestTrade)}")
if oldestTrade==None:
return
Order=lowestTrade['Order']
Order=oldestTrade['Order']
pair=Order['Asset']

# Verify the trade exists. If it doesn't, delete the key
if not TradeExists(relay,oldestTrade['ID'],pair):
print("RLS B",oldestTrade['id'])
relay.JRLog.Write("RLS B",oldestTrade)
return

lossID=oldestTrade['ID']
Expand All @@ -244,7 +244,7 @@ def ReduceLotSize(relay,oldestTrade=None,val=1):
Dir='long'
Action='Sell'

print("RLS C")
relay.JRLog.Write("RLS C")
newOrder={}
newOrder['OliverTwist']='Conditional ReduceBy'
newOrder['Exchange']=Order['Exchange']
Expand All @@ -261,10 +261,11 @@ def ReduceLotSize(relay,oldestTrade=None,val=1):
newOrder['OrderType']='market'
newOrder['Identity']=relay.Active['Identity']

# print("RLS D")
relay.JRLog.Write("RLS D")
# Feed the new order to Relay
result=relay.SendWebhook(newOrder)
oid=relay.GetOrderID(result)
relay.JRLog.Write(f"RLS E: {oid}")
if oid!=None:
orderDetail=relay.GetOrderDetails(OrderID=oid)

Expand Down Expand Up @@ -332,7 +333,8 @@ 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: {rpl}")
# relay.JRLog.Write(f"RPL: {rpl}")
# relay.JRLog.Write(f"LO: {lowestOrder}")
if rpl>0:
# Don't reduce if we have a loss

Expand Down Expand Up @@ -365,13 +367,18 @@ def ProcessOrder(relay,Order,cid,units,price,strikePrice,ds,lowestOrder=None):

def TradeExists(relay,id,asset):
try:
# Get ID from actual current order
orderDetail=relay.GetOrderDetails(OrderID=id)
cid=orderDetail[-1]['id']

# Get current open trades
openTrades=relay.GetOpenTrades(symbol=asset)
# no open trades
if openTrades==[]:
return False

for cur in openTrades:
if cur['id']==id:
if cur['id']==cid:
return True
except Exception as e:
# Something broke or went horrible wrong
Expand Down Expand Up @@ -690,6 +697,6 @@ def OrderProcessor(osh):
# shLock.Unlock()

EndTime=datetime.datetime.now()
JRLog.Write(f"OP OANDA Elapsed {idx}/{len(OrphanList)}: {EndTime-StartTime} seconds")
# JRLog.Write(f"OP OANDA Elapsed {idx}/{len(OrphanList)}: {EndTime-StartTime} seconds")

return 'Waiting'

0 comments on commit 5d61423

Please sign in to comment.