fluidex / dingir-exchange

A high performance crypto trading engine
234 stars 62 forks source link

feature: prevent self trade #98

Closed lispc closed 3 years ago

lispc commented 3 years ago

Motivation:

Many exchanges prevent self trade. Example:

https://support.kraken.com/hc/en-us/articles/360042529892-Self-trading-prevention

If two orders of the same quantity would result in self-execution, the maker (limit) order would stay on the order book and the taker (market) order would be cancelled (regardless of the size of the order).
In the case that an order can be partially filled from the order book, the remaining volume that would result in a self match would be cancelled.

In short, whenever self trade occurs, the taker will be cancelled.

Enabling self trade can trigger some subtle bugs more easily...

TODO:

add a config flag: enable_self_trade: bool, default false. When this flag is set, self trade is disabled like above

lispc commented 3 years ago

https://github.com/Fluidex/dingir-exchange/pull/103

done