Skip to content

Commit

Permalink
Mimic wallet bug fix for directional shorting. Added additional diagn…
Browse files Browse the repository at this point in the history
…istics for issue listed on Patreon.

Changes to be committed:
	modified:   Base/Library/JRRmimic.py
  • Loading branch information
rapmd73 committed Apr 10, 2024
1 parent b6f2333 commit 058c651
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions Base/Library/JRRmimic.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,11 @@ def UpdateWallet(self,action,asset,amount,price,fee_rate=0):

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

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

Expand Down Expand Up @@ -373,6 +372,8 @@ def UpdateWallet(self,action,asset,amount,price,fee_rate=0):
self.Wallet['Enabled']='N'
return 'Account Liquidated!'
elif action=='sell':
if base not in self.Wallet['Wallet']:
return 'Nothing to 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
Expand All @@ -384,6 +385,8 @@ def UpdateWallet(self,action,asset,amount,price,fee_rate=0):
self.Wallet['Wallet'][quote]+=total_proceeds
if self.Wallet['Wallet'][base]>0 and actualAmount>0:
self.Wallet['Wallet'][base]-=actualAmount
elif self.Wallet['Wallet'][base]<0 and actualAmount<0:
self.Wallet['Wallet'][base]+=actualAmount
elif self.Wallet['Wallet'][base]>0 and actualAmount<0 \
or self.Wallet['Wallet'][base]<0 and actualAmount>0:
self.Wallet['Wallet'][base]+=actualAmount
Expand Down Expand Up @@ -411,7 +414,6 @@ def UpdateWallet(self,action,asset,amount,price,fee_rate=0):
return order
else:
# Not enough balance, but account is not liquidated. Need to cross analyze this on shorting.
#self.Wallet['Enabled']='N'
return 'Not enough balance!'
else: # Should NEVER happen.
return 'Invalid action!'
Expand Down Expand Up @@ -483,19 +485,6 @@ 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)
elif amount<0 and self.Wallet['Wallet'][base]>0:
result=self.LiquidateWallet(pair,Fee)
result=self.UpdateWallet('buy',pair,amount,price,Fee)
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()
Expand Down

0 comments on commit 058c651

Please sign in to comment.