liquiditymaker: filterAskOrders by base balance

This commit is contained in:
c9s 2023-11-08 20:19:05 +08:00
parent cc5c033af7
commit 3563c0b986
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 17 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import (
//
// totalLiquidityAmount = priceAsk1 * scale(1) * f + priceAsk2 * scale(2) * f + priceAsk3 * scale(3) * f + ....
// totalLiquidityAmount = f * (priceAsk1 * scale(1) + priceAsk2 * scale(2) + priceAsk3 * scale(3) + ....)
// f = totalLiquidityAmount / (priceAsk1 * scale(1) + priceAsk2 * scale(2) + priceAsk3 * scale(3) + ....)
//
// when side == buy
//

View File

@ -299,6 +299,8 @@ func (s *Strategy) placeLiquidityOrders(ctx context.Context) {
s.NumOfLiquidityLayers,
s.liquidityScale)
askOrders = filterAskOrders(askOrders, baseBal.Available)
orderForms := append(bidOrders, askOrders...)
createdOrders, err := s.OrderExecutor.SubmitOrders(ctx, orderForms...)
@ -331,6 +333,20 @@ func profitProtectedPrice(
return price
}
func filterAskOrders(askOrders []types.SubmitOrder, available fixedpoint.Value) (out []types.SubmitOrder) {
usedBase := fixedpoint.Zero
for _, askOrder := range askOrders {
if usedBase.Add(askOrder.Quantity).Compare(available) > 0 {
return out
}
usedBase = usedBase.Add(askOrder.Quantity)
out = append(out, askOrder)
}
return out
}
func logErr(err error, msgAndArgs ...interface{}) bool {
if err == nil {
return false