Merge pull request #1373 from c9s/narumi/xalign/max-amounts

FEATURE: [xalign] adjust quantity by max amount
This commit is contained in:
なるみ 2023-10-27 18:00:08 +08:00 committed by GitHub
commit db1de0efb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View File

@ -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

View File

@ -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,