dominiktraxl/pykrakenapi

Key error in get_recent_trades.

AlnsV opened this issue · 3 comments

AlnsV commented

trades = pd.DataFrame(res['result'][pair]) KeyError: 'USDTUSD'
The key actually is USDTZUSD. So the approach to get this working is adding '-' between base and quote.
So the pair should be 'USDT-USD' then the function queries the API using the string replace with '-' by '' and the key to dictionary would be the replace of '-' with 'Z'

AlnsV commented

Proposal:
with pair being '-' instead of ''
and data dictionary now declared in a explicit way

        data = {
            'pair': pair.replace('-', ''),
            'since': since,
            'ascending': ascending
        }

        # query
        res = self.api.query_public('Trades', data=data)

        # check for error
        if len(res['error']) > 0:
            raise KrakenAPIError(res['error'])

        # create dataframe
        trades = pd.DataFrame(res['result'][pair.replace('-', 'Z')])
        # last timestamp
        last = int(res['result']['last'])```

Is there any reason you don't just query by 'USDTZUSD':
trades, last = k.get_recent_trades('USDTZUSD')
?

closing this.