Skip to content

Commit

Permalink
Bug fixes.
Browse files Browse the repository at this point in the history
Code optimizations.

Tweaks to conditional orders framework.

Version update.

Changes to be committed:
	modified:   Base/Conditional.ccxt
	modified:   Base/Conditional.oanda
	modified:   Base/JackrabbitLocker
	modified:   Base/JackrabbitOliverTwist
	modified:   Base/JackrabbitRelay
	modified:   Base/Library/JackrabbitRelay.py
  • Loading branch information
rapmd73 committed Oct 12, 2023
1 parent 700fcd7 commit 026d7a2
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 29 deletions.
19 changes: 11 additions & 8 deletions Base/Conditional.ccxt
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ def FinishOrphan(Key,lID,mID,State):
# Get the order ID. If there isn't an ID, the order FAILED.

def GetOrderID(res):
if res.find('Order Confirmation ID')>-1:
s=res.find('ID:')+4
for e in range(s,len(res)):
if res[e]=='\n':
break
oid=res[s:e]

return oid
try:
if res.find('Order Confirmation ID')>-1:
s=res.find('ID:')+4
for e in range(s,len(res)):
if res[e]=='\n':
break
oid=res[s:e]

return oid
except:
pass
return None

# Calculate Proce Exit
Expand Down
39 changes: 22 additions & 17 deletions Base/Conditional.oanda
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,20 @@ def FinishOrphan(Key,lID,mID,State):
# Get the order ID. If there isn't an ID, the order FAILED.

def GetOrderID(res):
if res.find('Order Confirmation ID')>-1:
s=res.find('ID:')+4
for e in range(s,len(res)):
if res[e]=='\n':
break
oid=res[s:e]

return oid
if res==None:
return None

try:
if res.find('Order Confirmation ID')>-1:
s=res.find('ID:')+4
for e in range(s,len(res)):
if res[e]=='\n':
break
oid=res[s:e]

return oid
except:
pass
return None

# Calculate Price
Expand Down Expand Up @@ -183,28 +189,28 @@ def main():
StrikeHappened=False
if dir=='long':
if 'Diagnostics' in relay.Active:
relay.JRLog.Write(f"{id}: {relay.Asset}/{units} {dir} Price: {price}, Bid: {ticker['Bid']} TP: {tp}/{relay.Order['TakeProfit']}, SL {sl}/{relay.Order['StopLoss']}",stdOut=False)
relay.JRLog.Write(f"{id} -> {cid}: {relay.Asset}/{units} {dir} Price: {price}, Bid: {ticker['Bid']} TP: {tp}/{relay.Order['TakeProfit']}, SL {sl}/{relay.Order['StopLoss']}",stdOut=False)

if ticker['Bid']>tp:
profit=round((units*ticker['Bid'])-(units*price),5)
relay.JRLog.Write(f"{id}: TP {dir} hit: {tp}, {units}: {price:.5f} -> {ticker['Bid']:5f}/{profit}",stdOut=False)
relay.JRLog.Write(f"{id} -> {cid}: TP {dir} hit: {tp}, {units}: {price:.5f} -> {ticker['Bid']:5f}/{profit}",stdOut=False)
if 'StopLoss' in relay.Order and ticker['Bid']<sl:
loss=round((units*price)-(units*ticker['Bid']),5)
relay.JRLog.Write(f"{id}: SL {dir} hit: {sl}, {units}: {price:.5f} -> {ticker['Bid']:5f}/{loss}",stdOut=False)
relay.JRLog.Write(f"{id} -> {cid}: SL {dir} hit: {sl}, {units}: {price:.5f} -> {ticker['Bid']:5f}/{loss}",stdOut=False)

if ticker['Bid']>tp or ('StopLoss' in relay.Order and ticker['Bid']<sl):
strikePrice=ticker['Bid']
StrikeHappened=True
else:
if 'Diagnostics' in relay.Active:
relay.JRLog.Write(f"{id}: {relay.Asset}/{abs(units)} {dir} Price: {price}, Ask: {ticker['Ask']} TP: {tp}/{relay.Order['TakeProfit']}, SL {sl}/{relay.Order['StopLoss']}",stdOut=False)
relay.JRLog.Write(f"{id} -> {cid}: {relay.Asset}/{abs(units)} {dir} Price: {price}, Ask: {ticker['Ask']} TP: {tp}/{relay.Order['TakeProfit']}, SL {sl}/{relay.Order['StopLoss']}",stdOut=False)

if ticker['Ask']<tp:
profit=round((units*price)-(units*ticker['Ask']),5)
relay.JRLog.Write(f"{id}: TP {dir} hit: {tp}, {units}: {price:.5f} -> {ticker['Ask']:5f}/{profit}",stdOut=False)
relay.JRLog.Write(f"{id} -> {cid}: TP {dir} hit: {tp}, {units}: {price:.5f} -> {ticker['Ask']:5f}/{profit}",stdOut=False)
if 'StopLoss' in relay.Order and ticker['Ask']>sl:
loss=round((units*ticker['Ask'])-(units*price),5)
relay.JRLog.Write(f"{id}: SL {dir} hit: {sl}, {units}: {price:.5f} -> {ticker['Ask']:5f}/{loss}",stdOut=False)
relay.JRLog.Write(f"{id} -> {cid}: SL {dir} hit: {sl}, {units}: {price:.5f} -> {ticker['Ask']:5f}/{loss}",stdOut=False)

if ticker['Ask']<tp or ('StopLoss' in relay.Order and ticker['Ask']>sl):
strikePrice=ticker['Ask']
Expand Down Expand Up @@ -243,14 +249,13 @@ def main():
result=relay.SendWebhook(newOrder)
oid=GetOrderID(result)
if oid!=None:
resp=relay.GetOrderDetails(OrderID=oid)
# Order must be closed as it succedded
newOrder['ID']=oid
relay.WriteLedger(Order=newOrder,Response=resp)
relay.WriteLedger(Order=newOrder,Response=result)
FinishOrphan(Orphan['Key'],Orphan['lID'],Orphan['mID'],'Delete')
else:
# Give OliverTwist a response
relay.JRLog.Write(f"{id}: Order failed",stdOut=False)
relay.JRLog.Write(f"{id} -> {cid}: Order failed",stdOut=False)
FinishOrphan(Orphan['Key'],Orphan['lID'],Orphan['mID'],Orphan['Status'])
else:
# Strike did not happen
Expand Down
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.435"
Version="0.0.0.1.450"
BaseDirectory='/home/JackrabbitRelay2/Base'
ConfigDirectory='/home/JackrabbitRelay2/Config'
LogDirectory="/home/JackrabbitRelay2/Logs"
Expand Down
2 changes: 1 addition & 1 deletion Base/JackrabbitOliverTwist
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import subprocess
import JRRsupport
import JackrabbitRelay as JRR

Version="0.0.0.1.435"
Version="0.0.0.1.450"
BaseDirectory='/home/JackrabbitRelay2/Base'
DataDirectory='/home/JackrabbitRelay2/Data'
ConfigDirectory='/home/JackrabbitRelay2/Config'
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.435"
Version="0.0.0.1.450"
BaseDirectory='/home/JackrabbitRelay2/Base'
ConfigDirectory='/home/JackrabbitRelay2/Config'
LogDirectory="/home/JackrabbitRelay2/Logs"
Expand Down
2 changes: 1 addition & 1 deletion Base/Library/JackrabbitRelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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):
# All the default locations
self.Version="0.0.0.1.435"
self.Version="0.0.0.1.450"
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.BaseDirectory='/home/JackrabbitRelay2/Base'
self.ConfigDirectory='/home/JackrabbitRelay2/Config'
Expand Down
File renamed without changes.

0 comments on commit 026d7a2

Please sign in to comment.