Polkadex-Substrate / polkadexTEE-worker

Polkadex Off-chain Orderbook
Apache License 2.0
10 stars 1 forks source link

Update Trade settlement logic in Enclave #281

Closed zktony closed 2 years ago

zktony commented 3 years ago

Right now, worker's trade settlement logic is Buyer preferable, which means if following trades are placed:-

place_order(alice, None, btc, usd, 'bid', QUANITY = UNIT, 'limit', PRICE = 2 * UNIT)
place_order(bob, None, btc, usd, 'ask', QUANITY =  UNIT, 'limit',PRICE = UNIT)

then Execution Price => UNIT

But logic followed by Openfinex is based on FCFS which means if same trades are placed as above:-

then Execution Price => 2 * UNIT

Or if orders are in opposite order i.e.

place_order(bob, None, btc, usd, 'ask', QUANITY =  UNIT, 'limit',PRICE = UNIT)
place_order(alice, None, btc, usd, 'bid', QUANITY = UNIT, 'limit', PRICE = 2 * UNIT)

then Execution Price => UNIT

As discussed with @visiondream3, I am going to update our logic to one which OF uses, i.e. FCFS

CC @Gauthamastro @simonsso