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