mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
liquiditymaker: filterAskOrders by base balance
This commit is contained in:
parent
cc5c033af7
commit
3563c0b986
|
@ -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
|
||||
//
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user