Codaone / DEXBot

Trading Bot for the BitShares Decentralized Exchange
Other
247 stars 127 forks source link

Arbitrage strategies dex <---> cex #504

Open bitphage opened 5 years ago

bitphage commented 5 years ago

To implement arbitrage strategies dexbot-wide, we need to make a common middleware (hope this is a correct term) which will serve as intermediate between strategy and particular CEX API. So we're not reimplementing strategy for every new exchange.

Strategy —-> middleware —--> bittrex / coinbase / binance / etc

thehapax commented 5 years ago

we can leverage some of the existing code from external feeds for the CEXs that has already been written. specifically the ccxt part and dealing with the prefix, e.g. OPEN.BTC instead of just BTC. Async has already been implemented for fetching market data.

With ccxt we can leverage the private API to handle trades directly on the CEXs. there is also a list of exchanges which are ccxt certified. https://github.com/ccxt/ccxt

For some APIs, websockets would be more efficient but not all CEXs have these; some are still REST.

cloud-8 commented 5 years ago

Ah didnt know about https://github.com/ccxt/ccxt awesome !

PermieBTS commented 5 years ago

CEX-DEX Arbitrage feature specification google doc: Using ccxt

https://docs.google.com/document/d/1-9kPRdOnbc_fd4A4lntLLJMX3rhrcOih7QYqu_FrG6I

note: some ccxt exchanges only allow trades with limit orders only and not market orders. emulating market as limit may have risks. see: https://github.com/ccxt/ccxt/wiki/Manual#exchanges @thehapax

So limit orders can be calculated to be placed in such a way that they in-fact take orders off the book?

If there is a limit order currently on the books to sell 1btc for 100kbts, and DEXBot deems this a profitable opportunity, DEXBot can use its knowledge of the CEX orderbook to place a limit order at the exact same price as the opposite limit order alread on the book. Thus the trade will fill.

I assume the risk is in the fact that placing a limit order that matches to an existing opposing limit order is that this process takes longer to execute than placing a proper market order. Meaning that in some scenarios DEXBot may end up having a sucessfully executed tx on the DEX, but a FAILED tx on the CEX. Therefore resulting in the arbitrage strategy failing?

PermieBTS commented 5 years ago

LIST OF CCXT SUPPORTED EXCHANGES THAT LIST BTS TRADING PAIRS AND HAVE WEBSOCKET API

1) CoinTiger https://coinmarketcap.com/exchanges/cointiger/ Available on ccxt? YES - Websocket Please visit 【www.cointiger.com】-[Account] – [API control] – [create the new key] to create your own API Key. Request Process There are REST and Websocket two methods of Public Api Request; REST is the only method for Private Trading Api Request.

CoinTiger is of particular importance because it lists bitCNY, and arbitrage between CT and the DEX on bitCNY markets would be very helpful for the health of bitCNY, Bitshares’ flagship product.

2) (From here on the CEX's are also ranked in order of bts volume traded) Lbank https://coinmarketcap.com/exchanges/lbank/ Available on ccxt? Yes - Websocket and REST API’s https://github.com/LBank-exchange/lbank-official-api-docs/blob/master/README.md

3) ZB https://coinmarketcap.com/exchanges/zb-com/ Available on ccxt? Yes - Websocket and REST API’s https://www.zb.com/i/developer

4) Poloniex https://coinmarketcap.com/exchanges/poloniex/ Available on ccxt? Yes - Websocket and HTTP API’s https://docs.poloniex.com/#introduction https://github.com/askmike/gekko/issues/517 - simulating market orders using polo api

5) Gate.io https://coinmarketcap.com/exchanges/gate-io/ Available on ccxt? Yes - Websocket and REST API’s https://www.gate.io/api2

6) EXX https://coinmarketcap.com/exchanges/exx/ Available on ccxt? Yes - Websocket and REST API’s https://www.exx.com/help/websocketApi