Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ws_thread.py funds can return wrong currency #241

Open
mkultra333 opened this issue Mar 29, 2023 · 0 comments
Open

ws_thread.py funds can return wrong currency #241

mkultra333 opened this issue Mar 29, 2023 · 0 comments

Comments

@mkultra333
Copy link

mkultra333 commented Mar 29, 2023

Had a problem with the bot returning spurious wallet values after the March 23rd site maintenance. Support couldn't help but I eventually found the issue.

The funds() function in ws_thread.py looks like this:

def funds(self):
    return self.data['margin'][0]

It just returns whatever is first in the list of currencies returned in data. But after the March 23rd site update this might not be XBt, for instance I was getting spurious data because the first in the list was actually BMEx. Here's the actual margin currency data returned by ws.

'margin': [
{'account': xxxxxxxxxx, 'currency': 'BMEx', 'riskLimit': 9223372036854775807, 'amount': 12082210, 'prevRealisedPnl': 0, 'grossComm': 0, 'grossOpenCost': 0, 'grossOpenPremium': 0, 'grossExecCost': 0, 'grossMarkValue': 0, 'riskValue': 0, 'initMargin': 0, 'maintMargin': 0, 'targetExcessMargin': 0, 'realisedPnl': 0, 'unrealisedPnl': 0, 'walletBalance': 12082210, 'marginBalance': 12082210, 'marginLeverage': 0.0, 'marginUsedPcnt': 0.0, 'excessMargin': 12082210, 'availableMargin': 12082210, 'withdrawableMargin': 12082210, 'timestamp': '2023-03-28T03:50:00.855Z'},
{'account': xxxxxxxxxx, 'currency': 'XBt', 'riskLimit': 1000000000000, 'amount': 20000, 'prevRealisedPnl': -3444113, 'grossComm': 0, 'grossOpenCost': 0, 'grossOpenPremium': 0, 'grossExecCost': 0, 'grossMarkValue': 0, 'riskValue': 0, 'initMargin': 0, 'maintMargin': 0, 'targetExcessMargin': 0, 'realisedPnl': 0, 'unrealisedPnl': 0, 'walletBalance': 20000, 'marginBalance': 20000, 'marginLeverage': 0.0, 'marginUsedPcnt': 0.0, 'excessMargin': 20000, 'availableMargin': 20000, 'withdrawableMargin': 20000, 'timestamp': '2023-03-24T01:03:11.565Z'}]

As you can see, BMEx is returned first, XBt second, so funds() returns BMEx holdings instead of XBt holdings.

In my own code I changed it to the following. It suits my purposes for now but you might want to do something different.

#was returning erroneous data if XBt wasn't the first currency returned in self.data['margin']
#will now look for XBt and exit if it can't find it.
def funds(self):
    #return self.data['margin'][0]
    for o in self.data['margin']:
        if o['currency']=='XBt':
            return o
            
    self.logger.info('ERROR: ws_thread.py cannot find XBt in margin data.')
    sleep(5)
    self.exit()
    sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant