mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
adjust quantity by max amount
This commit is contained in:
parent
c4f1af00d7
commit
e8c9801535
|
@ -27,7 +27,6 @@ persistence:
|
|||
db: 0
|
||||
|
||||
crossExchangeStrategies:
|
||||
|
||||
- xalign:
|
||||
interval: 1m
|
||||
sessions:
|
||||
|
@ -41,4 +40,10 @@ crossExchangeStrategies:
|
|||
sell: [USDT]
|
||||
expectedBalances:
|
||||
BTC: 0.0440
|
||||
|
||||
useTakerOrder: false
|
||||
dryRun: true
|
||||
balanceToleranceRange: 10%
|
||||
maxAmounts:
|
||||
USDT: 100
|
||||
USDC: 100
|
||||
TWD: 3000
|
||||
|
|
|
@ -45,6 +45,7 @@ type Strategy struct {
|
|||
DryRun bool `json:"dryRun"`
|
||||
BalanceToleranceRange fixedpoint.Value `json:"balanceToleranceRange"`
|
||||
Duration types.Duration `json:"for"`
|
||||
MaxAmounts map[string]fixedpoint.Value `json:"maxAmounts"`
|
||||
|
||||
faultBalanceRecords map[string][]TimeBalance
|
||||
|
||||
|
@ -156,7 +157,7 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
|
|||
switch side {
|
||||
|
||||
case types.SideTypeBuy:
|
||||
price := ticker.Sell
|
||||
var price fixedpoint.Value
|
||||
if taker {
|
||||
price = ticker.Sell
|
||||
} else if spread.Compare(market.TickSize) > 0 {
|
||||
|
@ -177,6 +178,12 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
|
|||
continue
|
||||
}
|
||||
|
||||
maxAmount, ok := s.MaxAmounts[market.QuoteCurrency]
|
||||
if ok {
|
||||
requiredQuoteAmount = bbgo.AdjustQuantityByMaxAmount(requiredQuoteAmount, price, maxAmount)
|
||||
log.Infof("adjusted quantity %f %s by max amount %f %s", requiredQuoteAmount.Float64(), market.BaseCurrency, maxAmount.Float64(), market.QuoteCurrency)
|
||||
}
|
||||
|
||||
if quantity, ok := market.GreaterThanMinimalOrderQuantity(side, price, requiredQuoteAmount); ok {
|
||||
return session, &types.SubmitOrder{
|
||||
Symbol: symbol,
|
||||
|
@ -190,7 +197,7 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
|
|||
}
|
||||
|
||||
case types.SideTypeSell:
|
||||
price := ticker.Buy
|
||||
var price fixedpoint.Value
|
||||
if taker {
|
||||
price = ticker.Buy
|
||||
} else if spread.Compare(market.TickSize) > 0 {
|
||||
|
@ -209,6 +216,12 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
|
|||
continue
|
||||
}
|
||||
|
||||
maxAmount, ok := s.MaxAmounts[market.QuoteCurrency]
|
||||
if ok {
|
||||
q = bbgo.AdjustQuantityByMaxAmount(q, price, maxAmount)
|
||||
log.Infof("adjusted quantity %f %s by max amount %f %s", q.Float64(), market.BaseCurrency, maxAmount.Float64(), market.QuoteCurrency)
|
||||
}
|
||||
|
||||
if quantity, ok := market.GreaterThanMinimalOrderQuantity(side, price, q); ok {
|
||||
return session, &types.SubmitOrder{
|
||||
Symbol: symbol,
|
||||
|
|
Loading…
Reference in New Issue
Block a user