feat: refactor balance_history
lispc opened this issue · comments
Zhang Zhuo commented
I will explain this issue more detailly later
- move business id as a column in balance_history table, type: int
- 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
- 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:
- besides, 'Trade' should be added here?
pub enum BalanceUpdateType {
Deposit,
Withdraw,
Transfer,
}
- 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.
- maybe BalanceUpdateController / BalanceManager needs some refactor?