ExchangeUnion / market-maker-bot

MM Bot for OpenDEX. Make profits via arbitrage between OpenDEX and a connected CEX account like Binance 🤖
GNU Affero General Public License v3.0
103 stars 20 forks source link

Use `replace_order_id` instead of rm/create new order #23

Closed kilrau closed 4 years ago

kilrau commented 4 years ago

Currently arby removes all orders and issues new ones, which causes two packets on the p2p layer and all receiving nodes first to remove and then to replace an order. We consider this becoming an issue once there are a 100s/1000s of orders being shared per second:

18/06/2020 16:13:22.551 [P2P] verbose: received order invalidation from 02819c4892b0730e787d63cc9b184179c807eb5ef6f3c41000923cd83395e6c873 (DinosaurCancel): {"id":"a0a895a0-b17e-11ea-8159-4f081f239e40","pairId":"ETH/BTC","quantity":9908711525}
18/06/2020 16:13:22.551 [ORDERBOOK] debug: order removed: a0a895a0-b17e-11ea-8159-4f081f239e40
18/06/2020 16:13:22.552 [P2P] verbose: received order invalidation from 02819c4892b0730e787d63cc9b184179c807eb5ef6f3c41000923cd83395e6c873 (DinosaurCancel): {"id":"a0a82070-b17e-11ea-8159-4f081f239e40","pairId":"ETH/BTC","quantity":1000000000}
18/06/2020 16:13:22.552 [ORDERBOOK] debug: order removed: a0a82070-b17e-11ea-8159-4f081f239e40
18/06/2020 16:13:22.557 [P2P] verbose: received order from 02819c4892b0730e787d63cc9b184179c807eb5ef6f3c41000923cd83395e6c873 (DinosaurCancel): {"id":"a177a570-b17e-11ea-8159-4f081f239e40","pairId":"ETH/BTC","price":0.02562144,"quantity":1000000000,"isBuy":false}
18/06/2020 16:13:22.558 [ORDERBOOK] debug: order added: {"id":"a177a570-b17e-11ea-8159-4f081f239e40","pairId":"ETH/BTC","price":0.02562144,"quantity":1000000000,"isBuy":false,"peerPubKey":"02819c4892b0730e787d63cc9b184179c807eb5ef6f3c41000923cd83395e6c873","createdAt":1592496802557,"initialQuantity":1000000000}
18/06/2020 16:13:22.558 [P2P] verbose: received order from 02819c4892b0730e787d63cc9b184179c807eb5ef6f3c41000923cd83395e6c873 (DinosaurCancel): {"id":"a17841b0-b17e-11ea-8159-4f081f239e40","pairId":"ETH/BTC","price":0.02365056,"quantity":9907504912,"isBuy":true}

Instead arby should track order id's of it's issued orders and replace them with replace_order_id.

hatmer commented 4 years ago

https://github.com/opendexnetwork/opendex/issues/22 has a decent solution for this issue. Here is the proposed order format in protocol buffer format:

string signature;
string pubkey;
uint32 timestamp_secs;
string request_asset_id;
uint64 request_amount;
string offer_asset_id;
uint64 offer_amount;
optional string replace_order_id;

But changing to an entirely new order format might be a major change and so perhaps this is the intermediary step

kilrau commented 4 years ago

Bumping prio here since today I noticed arby replacing orders every 100ms or so due to fast price movements on binance, resulted frequently in the following:

simnet > sell 1 eth/btc mkt
matched 1 ETH @ 0.02883907 with peer DoveSlim order 9e894580-d032-11ea-94f8-19f64578a848, attempting swap...
failed to swap 1 ETH due to OrderNotFound with peer order 9e894580-d032-11ea-94f8-19f64578a848, continuing with matching routine...
matched 1 ETH @ 0.02884004 with peer DoveSlim order 9ef6d462-d032-11ea-94f8-19f64578a848, attempting swap...
failed to swap 1 ETH due to OrderNotFound with peer order 9ef6d462-d032-11ea-94f8-19f64578a848, continuing with matching routine...
matched 1 ETH @ 0.02885168 with peer DoveSlim order 9f39d0d0-d032-11ea-94f8-19f64578a848, attempting swap...
successfully swapped 1 ETH with peer order 9f39d0d0-d032-11ea-94f8-19f64578a848

Because orders disappear for some ms when being cancelled and re-issued by arby.