dominiktraxl/pykrakenapi

Typo error with get_order_book

GGMeakin opened this issue · 1 comments

What are you trying to achieve?

Call the get_order_book function.

# code sample

api = krakenex.API(APIPublic, APIPrivate)
k = KrakenAPI(api)
k.get_order_book('XETHZEUR','10','True')


The relevant function is:


    def get_order_book(self, pair, count=100, ascending=False):
        """Get order book (market depth).

        Return a ``pd.DataFrame`` for both asks and bids for a given pair.

        Parameters
        ----------
        pair : str
            Asset pair to get market depth for.

        count : int, optional (default=100)
            Maximum number of asks/bids. Per default, get the latest 100
            bids and asks.

        ascending : bool, optional (default=False)
            If set to True, the data frame will be sorted with the most recent
            date in the last position. When set to False, the most recent date
            is in the first position.

        Returns
        -------
        asks : pd.DataFrame
            The ask side table.
            index = datetime
            price
            volume
            time (unixtime)

        bids : pd.DataFrame
            The bid side table.
            index = datetime
            price
            volume
            time (unixtime)

        Raises
        ------
        HTTPError
            An HTTP error occurred.

        KrakenAPIError
            A kraken.com API error occurred.

        CallRateLimitError
            The call rate limiter blocked the query.

        """

        # create data dictionary
        data = {arg: value for arg, value in locals().items() if
                arg != 'self' and value is not None}

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

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

        # create dataframe
        asks = pd.DataFrame(res['result'][pair]['asks'])
        bids = pd.DataFrame(res['result'][pair]['bids'])

        # column names
        cols = ['price', 'volume', 'time']

        if not asks.empty:
            asks.columns = cols
            asks['dtime'] = pd.to_datetime(asks.time, unit='s')
            asks.sort_values('dtime', ascending=ascending, inplace=True)
            asks.set_index('dtime', inplace=True)

     
    **if not bids.emtpy:**
            bids.columns = cols
            bids['dtime'] = pd.to_datetime(bids.time, unit='s')
            bids.sort_values('dtime', ascending=ascending, inplace=True)
            bids.set_index('dtime', inplace=True)

        return asks, bids

What do you expect to happen?

I expect 2 DataFrames to returned for Asks and Bids.

At least some other functions from the same library DO work.

What happens instead?

An error results. From my understanding, the API exchange happens successfully, because giving an invalid trading pair name gives an API error from their server. The 'asks' dataframe is filled successfully, but there is then a problem with the 'bids' dataframe as the line

if not bids.emtpy:

causes an error.

# error message

if not bids.emtpy:
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'emtpy'

Thanks, I corrected the typo.