clean up legacy code

This commit is contained in:
c9s 2020-11-10 16:56:30 +08:00
parent 04a7c7a2cc
commit 4ab402a188
2 changed files with 2 additions and 90 deletions

View File

@ -13,94 +13,6 @@ var (
ErrAssetBalanceLevelTooHigh = errors.New("asset balance level too high")
)
/*
tradingCtx := p.OrderExecutor.Context
currentPrice := tradingCtx.CurrentPrice
market := order.Market
quantity := order.Quantity
tradingCtx.Lock()
defer tradingCtx.Unlock()
switch order.Side {
case types.SideTypeBuy:
if balance, ok := tradingCtx.Balances[market.QuoteCurrency]; ok {
if balance.Available < p.MinQuoteBalance {
return errors.Wrapf(ErrQuoteBalanceLevelTooLow, "quote balance level is too low: %s < %s",
types.USD.FormatMoneyFloat64(balance.Available),
types.USD.FormatMoneyFloat64(p.MinQuoteBalance))
}
if baseBalance, ok := tradingCtx.Balances[market.BaseCurrency]; ok {
if util.NotZero(p.MaxBaseAssetBalance) && baseBalance.Available > p.MaxBaseAssetBalance {
return errors.Wrapf(ErrAssetBalanceLevelTooHigh, "asset balance level is too high: %f > %f", baseBalance.Available, p.MaxBaseAssetBalance)
}
}
available := math.Max(0.0, balance.Available-p.MinQuoteBalance)
if available < market.MinAmount {
return errors.Wrapf(ErrInsufficientQuoteBalance, "insufficient quote balance: %f < min amount %f", available, market.MinAmount)
}
quantity = adjustQuantityByMinAmount(quantity, currentPrice, market.MinAmount*1.01)
quantity = adjustQuantityByMaxAmount(quantity, currentPrice, available)
amount := quantity * currentPrice
if amount < market.MinAmount {
return fmt.Errorf("amount too small: %f < min amount %f", amount, market.MinAmount)
}
}
case types.SideTypeSell:
if balance, ok := tradingCtx.Balances[market.BaseCurrency]; ok {
if util.NotZero(p.MinBaseAssetBalance) && balance.Available < p.MinBaseAssetBalance {
return errors.Wrapf(ErrAssetBalanceLevelTooLow, "asset balance level is too low: %f > %f", balance.Available, p.MinBaseAssetBalance)
}
quantity = adjustQuantityByMinAmount(quantity, currentPrice, market.MinNotional*1.01)
available := balance.Available
quantity = math.Min(quantity, available)
if quantity < market.MinQuantity {
return errors.Wrapf(ErrInsufficientAssetBalance, "insufficient asset balance: %f > minimal quantity %f", available, market.MinQuantity)
}
notional := quantity * currentPrice
if notional < tradingCtx.Market.MinNotional {
return fmt.Errorf("notional %f < min notional: %f", notional, market.MinNotional)
}
// price tick10
// 2 -> 0.01 -> 0.1
// 4 -> 0.0001 -> 0.001
tick10 := math.Pow10(-market.PricePrecision + 1)
minProfitSpread := math.Max(p.MinProfitSpread, tick10)
estimatedFee := currentPrice * 0.0015 * 2 // double the fee
targetPrice := currentPrice - estimatedFee - minProfitSpread
stockQuantity := tradingCtx.StockManager.Stocks.QuantityBelowPrice(targetPrice)
if math.Round(stockQuantity*1e8) == 0.0 {
return fmt.Errorf("profitable stock not found: target price %f, profit spread: %f", targetPrice, minProfitSpread)
}
quantity = math.Min(quantity, stockQuantity)
if quantity < market.MinLot {
return fmt.Errorf("quantity %f less than min lot %f", quantity, market.MinLot)
}
notional = quantity * currentPrice
if notional < tradingCtx.Market.MinNotional {
return fmt.Errorf("notional %f < min notional: %f", notional, market.MinNotional)
}
}
}
order.Quantity = quantity
order.QuantityString = market.FormatVolume(quantity)
*/
// adjustQuantityByMinAmount adjusts the quantity to make the amount greater than the given minAmount
func adjustQuantityByMinAmount(quantity, currentPrice, minAmount float64) float64 {
// modify quantity for the min amount

View File

@ -63,7 +63,7 @@ type Strategy struct {
// e.g., 0.001, so that your orders will be submitted at price like 0.127, 0.128, 0.129, 0.130
GridPips fixedpoint.Value `json:"gridPips"`
MinProfitSpread fixedpoint.Value `json:"minProfitSpread"`
ProfitSpread fixedpoint.Value `json:"profitSpread"`
// GridNum is the grid number, how many orders you want to post on the orderbook.
GridNum int `json:"gridNumber"`
@ -165,7 +165,7 @@ func (s *Strategy) updateAskOrders(orderExecutor bbgo.OrderExecutor, session *bb
func (s *Strategy) updateOrders(orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) {
// skip order updates if up-band - down-band < min profit spread
if (s.boll.LastUpBand() - s.boll.LastDownBand()) <= s.MinProfitSpread.Float64() {
if (s.boll.LastUpBand() - s.boll.LastDownBand()) <= s.ProfitSpread.Float64() {
log.Infof("boll: down band price == up band price, skipping...")
return
}