Open firepol opened 6 years ago
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.
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.
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
.
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?
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.
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?
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
andasks
before passing them to the super() call, I'd assume.
Dev branch:
I did a test to understand how the formatted order_book should look like, here my test:
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?