fix binance test, outptu for support and xgap strategies

This commit is contained in:
zenix 2022-02-09 19:48:40 +09:00
parent 05521a98b6
commit fad85d0992
7 changed files with 33 additions and 25 deletions

View File

@ -144,11 +144,11 @@ func (b *LocalActiveOrderBook) orderUpdateHandler(order types.Order) {
func (b *LocalActiveOrderBook) Print() {
for _, o := range b.Bids.Orders() {
log.Infof("%s bid order: %d @ %f -> %s", o.Symbol, o.OrderID, o.Price, o.Status)
log.Infof("%s bid order: %d @ %v -> %s", o.Symbol, o.OrderID, o.Price, o.Status)
}
for _, o := range b.Asks.Orders() {
log.Infof("%s ask order: %d @ %f -> %s", o.Symbol, o.OrderID, o.Price, o.Status)
log.Infof("%s ask order: %d @ %v -> %s", o.Symbol, o.OrderID, o.Price, o.Status)
}
}

View File

@ -497,7 +497,7 @@ func (session *ExchangeSession) initSymbol(ctx context.Context, environ *Environ
}
}
log.Infof("%s last price: %f", symbol, session.lastPrices[symbol])
log.Infof("%s last price: %v", symbol, session.lastPrices[symbol])
session.initializedSymbols[symbol] = struct{}{}
return nil

View File

@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/fixedpoint"
)
func TestTradeCollector_ShouldNotCountDuplicatedTrade(t *testing.T) {
@ -19,9 +20,9 @@ func TestTradeCollector_ShouldNotCountDuplicatedTrade(t *testing.T) {
ID: 1,
OrderID: 399,
Exchange: types.ExchangeBinance,
Price: 40000.0,
Quantity: 1.0,
QuoteQuantity: 40000.0,
Price: fixedpoint.NewFromInt(40000),
Quantity: fixedpoint.One,
QuoteQuantity: fixedpoint.NewFromInt(40000),
Symbol: "BTCUSDT",
Side: types.SideTypeBuy,
IsBuyer: true,
@ -34,13 +35,13 @@ func TestTradeCollector_ShouldNotCountDuplicatedTrade(t *testing.T) {
Symbol: "BTCUSDT",
Side: types.SideTypeBuy,
Type: types.OrderTypeLimit,
Quantity: 1.0,
Price: 40000.0,
Quantity: fixedpoint.One,
Price: fixedpoint.NewFromInt(40000),
},
Exchange: types.ExchangeBinance,
OrderID: 399,
Status: types.OrderStatusFilled,
ExecutedQuantity: 1.0,
ExecutedQuantity: fixedpoint.One,
IsWorking: false,
})
@ -52,9 +53,9 @@ func TestTradeCollector_ShouldNotCountDuplicatedTrade(t *testing.T) {
ID: 1,
OrderID: 399,
Exchange: types.ExchangeBinance,
Price: 40000.0,
Quantity: 1.0,
QuoteQuantity: 40000.0,
Price: fixedpoint.NewFromInt(40000),
Quantity: fixedpoint.One,
QuoteQuantity: fixedpoint.NewFromInt(40000),
Symbol: "BTCUSDT",
Side: types.SideTypeBuy,
IsBuyer: true,

View File

@ -1005,7 +1005,14 @@ func (v *Value) UnmarshalJSON(data []byte) error {
*v = Zero
return nil
}
if len(data) == 0 {
*v = Zero
return nil
}
var err error
if data[0] == '"' {
data = data[1:len(data)-1]
}
if *v, err = NewFromBytes(data); err != nil {
return err
}

View File

@ -320,16 +320,16 @@ func (s *Strategy) calculateQuantity(session *bbgo.ExchangeSession, side types.S
if s.MinQuoteAssetBalance.Sign() > 0 &&
quoteBalance.Available.Sub(notional).Compare(s.MinQuoteAssetBalance) < 0 {
log.Warnf("modifying quantity %s according to the min quote asset balance %s %s",
quantity.String(),
quoteBalance.Available.String(),
log.Warnf("modifying quantity %v according to the min quote asset balance %v %s",
quantity,
quoteBalance.Available,
s.Market.QuoteCurrency)
quota := quoteBalance.Available.Sub(s.MinQuoteAssetBalance)
quantity = bbgo.AdjustQuantityByMinAmount(quantity, closePrice, quota)
} else if notional.Compare(quoteBalance.Available) > 0 {
log.Warnf("modifying quantity %f according to the quote asset balance %f %s",
quantity.String(),
quoteBalance.Available.String(),
log.Warnf("modifying quantity %v according to the quote asset balance %v %s",
quantity,
quoteBalance.Available,
s.Market.QuoteCurrency)
quantity = bbgo.AdjustQuantityByMaxAmount(quantity, closePrice, quoteBalance.Available)
}

View File

@ -289,8 +289,8 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
// if the spread is less than 100 ticks (100 pips), skip
if spread.Compare(s.tradingMarket.TickSize.MulExp(2)) < 0 {
log.Warnf("spread too small, we can't place orders: spread=%s bid=%s ask=%s",
spread.String(), bestBid.Price.String(), bestAsk.Price.String())
log.Warnf("spread too small, we can't place orders: spread=%v bid=%v ask=%v",
spread, bestBid.Price, bestAsk.Price)
continue
}
@ -306,15 +306,15 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
var spread = bestAsk.Price.Sub(bestBid.Price)
var spreadPercentage = spread.Div(bestAsk.Price)
log.Infof("spread=%s %s ask=%s bid=%s",
spread.String(), spreadPercentage.Percentage(),
bestAsk.Price.String(), bestBid.Price.String())
log.Infof("spread=%v %s ask=%v bid=%v",
spread, spreadPercentage.Percentage(),
bestAsk.Price, bestBid.Price)
// var spreadPercentage = spread.Float64() / bestBid.Price.Float64()
var midPrice = bestAsk.Price.Add(bestBid.Price).Div(Two)
var price = midPrice
log.Infof("mid price %f", midPrice.String())
log.Infof("mid price %v", midPrice)
var balances = s.tradingSession.Account.Balances()
var quantity = s.tradingMarket.MinQuantity

View File

@ -325,7 +325,7 @@ func (a *Account) UnlockBalance(currency string, unlocked fixedpoint.Value) erro
return fmt.Errorf("trying to unlocked inexisted balance: %s", currency)
}
if unlocked.Compare(balance.Locked) >= 0 {
if unlocked.Compare(balance.Locked) > 0 {
return fmt.Errorf("trying to unlocked more than locked %s: locked %v < want to unlock %v", currency, balance.Locked, unlocked)
}