bitex icon indicating copy to clipboard operation
bitex copied to clipboard

Dev branch, Binance, order_book formatted issue?

Open firepol opened this issue 6 years ago • 7 comments

Dev branch:

I did a test to understand how the formatted order_book should look like, here my test:

binance = bitex.Binance()
binance_orderbook = binance.order_book('XRPBTC').formatted
print(binance_orderbook)

Result (I just included 3 bids and 3 asks for the sake of simplicity): OrderBook(bids=[['0.00009160', '10203.00000000', []], ['0.00009157', '1026.00000000', []], ['0.00009156', '465.00000000', []]], asks=[['0.00009163', '1096.00000000', []], ['0.00009164', '12.00000000', []], ['0.00009165', '268.00000000', []]], timestamp=datetime.datetime(2018, 5, 1, 17, 30, 52, 392448), error=None)

Is this supposed to look like this? Every bid/ask should rather contain the timestamp, but not an empty array, right?

Also the format of bid or ask, I'm guessing it, is: price, then size, then timestamp?

firepol avatar May 01 '18 17:05 firepol

You're on the right track, yes! Have a look at https://github.com/Crypto-toolbox/bitex/blob/master/bitex/formatters/base.py

There are examples for the expected outputs.

deepbrook avatar May 02 '18 06:05 deepbrook

Accoording to base, then it should be "in format [ts, price, size]":

{'bids': [['1480941692', '0.014', '10'],
                      ['1480941690', '0.013', '0.66'],
                      ['1480941688', '0.012', '3']],
             'asks': [['1480941691', '0.015', '1'],
                      ['1480941650', '0.016', '0.67'],
                      ['1480941678', '0.017', '23']]}

Then this should be filed as a bug.

firepol avatar May 02 '18 08:05 firepol

It should be indeed. Or the docs changes - It may be better to sort the data by quality.

The thing is, timestamp is not always given, so some of them are generated by us. IT may be preferable to sort them as you guessed: price, size, ts.

deepbrook avatar May 03 '18 07:05 deepbrook

Ok, then we have 2 issues:

  1. put timestamp in the end and update base.py accordingly, are there tests using that? Then need to update the tests too...

  2. binance bids/asks look like this: ['0.00009160', '10203.00000000', []] which should rather look like this: ['0.00009160', '10203.00000000', ''] empty string, or None (not an empty array)... probably empty string is better since I understand bitex doesn't want to format numbers either, but leave everything as string.

Correct?

firepol avatar May 03 '18 12:05 firepol

None would be more appropriate IMO, since we actually do not receive any timestamp from the API. An empty string looks somewhat like a faulty parser. Otherwise, that's all correct.

deepbrook avatar May 05 '18 10:05 deepbrook

Probably you've seen my binance PR, but I didn't address this issue. I tried to have a look at this, but I'm having some difficulty to understand how it works:

formatters/binance.py

    def order_book(self):
        """Return namedtuple with given data."""
        data = self.json()
        bids = data['bids']
        asks = data['asks']
        timestamp = datetime.utcnow()
        return super(BinanceFormattedResponse, self).order_book(bids, asks, timestamp)

base.py

    @abstractmethod
    def order_book(self, bids, asks, ts, error=None):
        """Return namedtuple with given data."""
        order_book = namedtuple(
            "OrderBook", ("bids", "asks", "timestamp", "error"))
        return order_book(bids, asks, ts, error)

The namedtuple creates the array containing the bids, the asks, timestamp and error. So far so good.

But I don't understand where do you configure how a single value of the array can be changed as discussed?

I mean the bid or ask in the bid or ask array, where do I modify that?

firepol avatar May 29 '18 07:05 firepol

But I don't understand where do you configure how a single value of the array can be changed as discussed? You'd have to loop over bids and asks before passing them to the super() call, I'd assume.

deepbrook avatar Jun 07 '18 12:06 deepbrook