Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rapmd73 committed Sep 23, 2024
2 parents 28b4008 + 5d61423 commit 1cf2356
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 59 deletions.
28 changes: 13 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 @@ -584,7 +579,11 @@ def main():

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

JRRsupport.ElasticSleep(1)
Expand All @@ -594,4 +593,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.
15 changes: 5 additions & 10 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 Down Expand Up @@ -283,8 +276,10 @@ 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:
return 'PURGE'
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:
# Something broke or went horrible wrong
Expand Down Expand Up @@ -378,7 +373,7 @@ def CheckTakeProfit(relay,Orphan,lowestTrade):
if type(res) is bool and res==True:
return Orphan['Key']
elif type(res)==str and res=='PURGE':
return 'PURGE'
return True
return None
else:
# Strike did not happen
Expand Down
13 changes: 5 additions & 8 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 @@ -152,6 +145,7 @@ def ReadStorehouse(idx=None,OrigOrphanList=None):

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

# Get the hiest and lowest priced orders.
Expand Down Expand Up @@ -279,7 +273,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.lower():
return True
return False
except Exception as e:
# Something broke or went horrible wrong
Expand Down
30 changes: 15 additions & 15 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 Down Expand Up @@ -227,16 +220,15 @@ 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']
# print("RLS A")
relay.JRLog.Write(f"RLS: {json.dumps(oldestTrade)}")
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 @@ -253,7 +245,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 @@ -270,10 +262,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 @@ -341,6 +334,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"LO: {lowestOrder}")
if rpl>0:
# Don't reduce if we have a loss

Expand Down Expand Up @@ -373,13 +368,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 @@ -491,7 +491,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
10 changes: 5 additions & 5 deletions Extras/CodeProofs/BuyEveryMinute
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import time
import JRRsupport
import JackrabbitRelay as JRR

AssetList=['BTC/USDT','ETH/USDT','BNB/USDT','LTC/USDT','XRP/USDT','TRX/USDT']
AssetList=['BTC/USD','ETH/USD','ADA/USD','LTC/USD','XRP/USD','TRX/USD','SOL/USD','DOGE/USD']

NewOrder={"Recipe":"BuyEveryMinute Conditional","Action":"Buy","Exchange":"binance","Market":"spot","Account":"Sandbox","Asset":"TRX/USDT","USD":"7","OrderType":"Market","Conditional":"Yes","Direction":"Long","SellAction":"Sell","TakeProfit":"1.5%","StopLoss":"1%" }
NewOrder={"Recipe":"BuyEveryMinute Conditional","Action":"Buy","Exchange":"mimic","Market":"spot","Account":"Kraken02","Asset":"TRX/USD","USD":"7","OrderType":"Market","Conditional":"Yes","Direction":"Long","SellAction":"Sell","TakeProfit":"1.5%","StopLoss":"1%" }

def PushOrder(NewOrder):
try:
Expand All @@ -29,7 +29,7 @@ def PushOrder(NewOrder):
if oid!=None:
bal=relay.GetBalance(Base=relay.Order['Asset'].split('/')[0])
detail=relay.GetOrderDetails(id=oid,symbol=relay.Order['Asset'])
print(f"{relay.Order['Asset']} {oid:>16} {round(detail['price'],8):16.8f} {round(bal,8):16.8f}")
print(f"{relay.Order['Asset']:10} {oid:>16} {round(detail['Price'],8):16.8f} {round(bal,8):16.8f}")
except Exception as err:
print(err)

Expand All @@ -38,11 +38,11 @@ def PushOrder(NewOrder):
###

def main():
while True:
# while True:
for asset in AssetList:
NewOrder['Asset']=asset
PushOrder(NewOrder)
JRRsupport.ElasticSleep(60)
# JRRsupport.ElasticSleep(60)

if __name__ == '__main__':
main()
8 changes: 8 additions & 0 deletions Extras/OliverTwist/OliverTwistEquity
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ else:
lines=JRRsupport.ReadFile(sys.argv[2]).strip().split('\n')

for line in lines:
<<<<<<< HEAD
if line=='' or ('prft' not in line.lower() and 'loss' not in line.lower()):
=======
if line=='' or ('Prft' not in line and 'Loss' not in line and 'Rduc' not in line):
>>>>>>> 5d61423a9edba516e8e042b0785b61fad6cfaa1e
continue

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

if 'prft' in line.lower():
pnl+=float(pdata)
<<<<<<< HEAD
if 'loss' in line.lower():
=======
if 'Loss' in line or 'Rduc' in line:
>>>>>>> 5d61423a9edba516e8e042b0785b61fad6cfaa1e
pnl-=float(pdata)

xps.append(dt)
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 1cf2356

Please sign in to comment.