fluidex / dingir-exchange

A high performance crypto trading engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feat: refactor balance_history

lispc opened this issue · comments

I will explain this issue more detailly later

  1. move business id as a column in balance_history table, type: int
  2. balance updates triggered by trades should be recorded into balance_history table. we should use balance_controller rather than balance_manager in market/mod.rs. Use 'trade' as 'business' and trade_id as business id. Every update to balance should be recorded into this table. So, we need to check whether we write this table in 'transfer' request
  3. add a column call 'price', price of that asset. We can use price of last trade of the asset. ( so we should record price of last trade as a struct member into market struct? )

In the future: i think we should not provide an endpoint called 'update_balance'. Every update should have a reason/business and an business_id!!! We should have apis called deposit/withdraw rather than update_balance!!

some details:

  1. besides, 'Trade' should be added here?
pub enum BalanceUpdateType {
    Deposit,
    Withdraw,
    Transfer,
}
  1. add a const bool called 'PERSIST_ZERO_BALANCE_UPDATE' ( current set to false ) in update_controller.rs. If false, skip persisting balance update of 0 change into db.
  2. maybe BalanceUpdateController / BalanceManager needs some refactor?