Skip to content

Commit

Permalink
Bug fixes in balance checking.
Browse files Browse the repository at this point in the history
Changes to be committed:
	modified:   Base/Library/OliverTwist-mimic.py
	modified:   Base/Library/OliverTwist-oanda.py
  • Loading branch information
rapmd73 committed Sep 12, 2024
1 parent e21d2f9 commit 340e51a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Base/Library/OliverTwist-mimic.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ def ProcessOrder(relay,Order,cid,amount,price,strikePrice,ds):
return True
else:
# Give OliverTwist a response
relay.JRLog.Write(f"{id} -> {cid}: Order failed with {relay.GetFailedReason(result)}")
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:
return True
return False
except Exception as e:
# Something broke or went horrible wrong
Expand Down
8 changes: 4 additions & 4 deletions Base/Library/OliverTwist-oanda.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,12 @@ def ReduceLotSize(relay,oldestTrade=None,val=1):
if oldestTrade==None:
return
Order=lowestTrade['Order']
# print("RLS A")
relay.JRLog.Write(f"RLS: {json.dumps(oldestTrade)}")
relay.JRLog.Write(f"RLS A: {json.dumps(oldestTrade)}")
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'])
print("RLS B",oldestTrade['id'])
return

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

# print("RLS C")
print("RLS C")
newOrder={}
newOrder['OliverTwist']='Conditional ReduceBy'
newOrder['Exchange']=Order['Exchange']
Expand Down Expand Up @@ -340,6 +339,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}")
if rpl>0:
# Don't reduce if we have a loss

Expand Down

0 comments on commit 340e51a

Please sign in to comment.