Skip to content

Commit

Permalink
Mimic wallet bug fixes.
Browse files Browse the repository at this point in the history
Version update.

Changes to be committed:
	modified:   Base/JackrabbitLocker
	modified:   Base/JackrabbitOliverTwist
	modified:   Base/JackrabbitRelay
	modified:   Base/Library/JRRmimic.py
	modified:   Base/Library/JackrabbitProxy.py
	modified:   Base/Library/JackrabbitRelay.py
  • Loading branch information
rapmd73 committed Apr 2, 2024
1 parent 063652b commit f9eccc1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 58 deletions.
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.787"
Version="0.0.0.1.790"
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 @@ -40,7 +40,7 @@ import subprocess
import JRRsupport
import JackrabbitRelay as JRR

Version="0.0.0.1.787"
Version="0.0.0.1.790"
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.787"
Version="0.0.0.1.790"
BaseDirectory='/home/JackrabbitRelay2/Base'
ConfigDirectory='/home/JackrabbitRelay2/Config'
LogDirectory="/home/JackrabbitRelay2/Logs"
Expand Down
42 changes: 25 additions & 17 deletions Base/Library/JRRmimic.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class mimic:
# placed in init and released at exit.

def __init__(self,Exchange,Config,Active,DataDirectory=None):
self.Version="0.0.0.1.787"
self.Version="0.0.0.1.790"

self.StableCoinUSD=['USDT','USDC','BUSD','UST','DAI','FRAX','TUSD', \
'USDP','LUSD','USDN','HUSD','FEI','TRIBE','RSR','OUSD','XSGD', \
Expand Down Expand Up @@ -322,6 +322,17 @@ def UpdateWallet(self,action,asset,amount,price,fee_rate=0):
else:
actualPrice=max(ticker['Bid'],ticker['Ask'])+ticker['Spread'] # Long

minimum,mincost=self.Broker.GetMinimum(symbol=asset)
# Make sure order is above minimum requirements
if abs(actualAmount)<minimum or abs(actualAmount)*actualPrice<mincost:
return 'Below minimum requirements'

if base in self.Wallet['Wallet'] and action=='buy':
if base in self.Wallet['Wallet'] \
and ((actualAmount>0 and self.Wallet['Wallet'][base]<0) \
or (actualAmount<0 and self.Wallet['Wallet'][base]>0)):
action='sell'

if action=='buy':
# Calculate the total cost for buying the asset including fees
total_cost=abs(actualAmount) * actualPrice * (1 + fee_rate)
Expand Down Expand Up @@ -352,7 +363,7 @@ def UpdateWallet(self,action,asset,amount,price,fee_rate=0):
order['Amount']=round(actualAmount,8)
order['Price']=round(actualPrice,8)
order['Fee']=round(fee,8)
# Remove from allet
# Remove from Wallet
if self.Wallet['Wallet'][base]==0.0:
self.Wallet['Wallet'].pop(base,None)
JRRsupport.AppendFile(self.history,json.dumps(order)+'\n')
Expand All @@ -362,26 +373,19 @@ def UpdateWallet(self,action,asset,amount,price,fee_rate=0):
self.Wallet['Enabled']='N'
return 'Account Liquidated!'
elif action=='sell':
if base in self.Wallet['Wallet'] and self.Wallet['Wallet'][base]==0:
return 'Nothing to sell'
# Check if the base currency is present in the base currency wallet and the amount to sell is available
if base in self.Wallet['Wallet'] and abs(self.Wallet['Wallet'][base])>=abs(actualAmount):
if quote in self.Wallet['Wallet'] and self.Wallet['Wallet'][quote]>=0:
# Calculate the total proceeds from selling the asset after deducting fees
total_proceeds=abs(actualAmount) * actualPrice * (1 - fee_rate)
# Add the total proceeds minus fees to the quote currency balance
if quote in self.Wallet['Wallet']:
self.Wallet['Wallet'][quote]+=total_proceeds
else:
self.Wallet['Wallet'][quote]=total_proceeds # Initialize quote currency balance if not present
# Subtract the appropriate amount of the base currency from the base currency wallet
if actualAmount<0: # handle shorting
if self.Wallet['Wallet'][base]<0:
self.Wallet['Wallet'][base]-=actualAmount
else:
self.Wallet['Wallet'][base]+=actualAmount
# quote MUST be >=0.
self.Wallet['Wallet'][quote]+=total_proceeds
if base in self.Wallet['Wallet']:
self.Wallet['Wallet'][base]+=actualAmount
else:
if self.Wallet['Wallet'][base]<0:
self.Wallet['Wallet'][base]+=actualAmount
else:
self.Wallet['Wallet'][base]-=actualAmount
self.Wallet['Wallet'][base]=actualAmount # Initialize the base currency wallet if not present
# Update fee balance
fee = round(abs(actualAmount) * actualPrice * fee_rate,8)
if 'Fees' in self.Wallet['Wallet']:
Expand Down Expand Up @@ -479,6 +483,7 @@ def PlaceOrder(self,**kwargs):
# Handle long/short flipping

result=None
"""
if amount>0 and self.Wallet['Wallet'][base]>=0 \
or amount<0 and self.Wallet['Wallet'][base]<=0:
result=self.UpdateWallet(action,pair,amount,price,Fee)
Expand All @@ -488,6 +493,9 @@ def PlaceOrder(self,**kwargs):
elif amount>0 and self.Wallet['Wallet'][base]<0:
result=self.LiquidateWallet(pair,Fee)
result=self.UpdateWallet('buy',pair,amount,price,Fee)
"""

result=self.UpdateWallet(action,pair,amount,price,Fee)

self.PutWallet()
if 'ID' in result and result['ID']!=None:
Expand Down
2 changes: 1 addition & 1 deletion Base/Library/JackrabbitProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
class JackrabbitProxy:
def __init__(self,framework=None,payload=None,exchange=None,account=None,asset=None,Usage=None):
# All the default locations
self.Version="0.0.0.1.787"
self.Version="0.0.0.1.790"
self.BaseDirectory='/home/JackrabbitRelay2/Base'
self.ConfigDirectory='/home/JackrabbitRelay2/Config'
self.DataDirectory="/home/JackrabbitRelay2/Data"
Expand Down
2 changes: 1 addition & 1 deletion Base/Library/JackrabbitRelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,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.787"
self.Version="0.0.0.1.790"
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
36 changes: 0 additions & 36 deletions Extras/CodeProofs/x1

This file was deleted.

0 comments on commit f9eccc1

Please sign in to comment.