Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Dev branch, Binance, order_book formatted issue? #190

Open
firepol opened this issue May 1, 2018 · 7 comments
Open

Dev branch, Binance, order_book formatted issue? #190

firepol opened this issue May 1, 2018 · 7 comments

Comments

@firepol
Copy link

firepol commented May 1, 2018

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?

@deepbrook
Copy link
Collaborator

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.

@firepol
Copy link
Author

firepol commented May 2, 2018

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.

@deepbrook
Copy link
Collaborator

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.

@firepol
Copy link
Author

firepol commented May 3, 2018

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?

@deepbrook
Copy link
Collaborator

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.

@firepol
Copy link
Author

firepol commented May 29, 2018

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?

@deepbrook
Copy link
Collaborator

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants