Closed 0b01 closed 7 years ago
I'm working on the processTrades
and processOrderbookUpdates
functions.
In Poloniex, to receive order book and trade updates, subscribe to the desired currencyPair on WebSocket, e.g. "BTC_ETC". There are two types of order book updates:
[{data: {rate: '0.00300888', type: 'bid', amount: '3.32349029'},type: 'orderBookModify'}]
[{data: {rate: '0.00311164', type: 'ask' },type: 'orderBookRemove'}]
Updates of type orderBookModify
can be either additions to the order book or changes to existing entries. The value of 'amount' indicates the new total amount on the books at the given rate — in other words, it replaces any previous value, rather than indicates an adjustment to a previous value.
Trade history updates are provided in the following format:
[{data: {tradeID: '364476',rate: '0.00300888',amount: '0.03580906',date: '2014-10-07 21:51:20',total: '0.00010775',type: 'sell'},type: 'newTrade'}]
The dictionary portion of each market message ("kwargs" in the Node.js example) will contain a sequence number with the key "seq". In order to keep your order book consistent, you will need to ensure that messages are applied in the order of their sequence numbers, even if they arrive out of order. In some markets, if there is no update for more than 1 second, a heartbeat message consisting of an empty argument list and the latest sequence number will be sent. These will go out once per second, but if there is no update for more than 60 seconds, the heartbeat interval will be reduced to 8 seconds until the next update.
Several order book and trade history updates will often arrive in a single message. Be sure to loop through the entire array, otherwise you will miss some updates.
PR: #405
So does this mean that currently the orderbook is not kept? In other words, if I'm looking to get the data from a method, could I process orderbook data to form a strategy?
So does this mean that currently the orderbook is not kept?
Unfortunately it is not :(
In other words, if I'm looking to get the data from a method, could I process orderbook data to form a strategy?
No you can't atm. On the todo though (integrating the PR)
Don't forget that while the orderbook is obviously very important there are a few reasons why it's importance is (in my opinion) often overstated in basic algo strategies:
BTC/ETH
on poloniex you should also look at the book of USDT/ETH
and USDT/BTC
since price fluctuations caused by thin books (lack of resistance) are corrected pretty fast because of arbitrage.By ignoring the book you eliminate a lot of different ways simple strats can be manipulated.
Another big reason is that any strat supported by Gekko should always be backtestable. While you can record and replay orderbook updates, I don't know how to do this without increasing required store size (right now a year of minutely market data is less then 50mb) and making the strat interface (update/check functions) not extremely completed.
I am closing this as out of scope :(
Keeping a local copy of the orderbook and implementing the execution logic properly will reduce the risk of slippage. It can also be used for HFT.