mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
core: setting.InitializeConverter could return a nil converter object
This commit is contained in:
parent
098de2245c
commit
3d7453f18c
|
@ -43,14 +43,15 @@ type ConverterManager struct {
|
|||
|
||||
func (c *ConverterManager) Initialize() error {
|
||||
for _, setting := range c.ConverterSettings {
|
||||
|
||||
converter, err := setting.InitializeConverter()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if converter != nil {
|
||||
c.AddConverter(converter)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -9,6 +9,28 @@ import (
|
|||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
func TestTradeCollector_NilConvertManager(t *testing.T) {
|
||||
symbol := "BTCUSDT"
|
||||
position := types.NewPosition(symbol, "BTC", "USDT")
|
||||
orderStore := NewOrderStore(symbol)
|
||||
collector := NewTradeCollector(symbol, position, orderStore)
|
||||
|
||||
trade := types.Trade{
|
||||
ID: 1,
|
||||
OrderID: 399,
|
||||
Exchange: types.ExchangeBinance,
|
||||
Price: fixedpoint.NewFromInt(40000),
|
||||
Quantity: fixedpoint.One,
|
||||
QuoteQuantity: fixedpoint.NewFromInt(40000),
|
||||
Symbol: "BTCUSDT",
|
||||
Side: types.SideTypeBuy,
|
||||
IsBuyer: true,
|
||||
}
|
||||
|
||||
trade = collector.ConvertTrade(trade)
|
||||
assert.Equal(t, "BTCUSDT", trade.Symbol)
|
||||
}
|
||||
|
||||
func TestTradeCollector_ShouldNotCountDuplicatedTrade(t *testing.T) {
|
||||
symbol := "BTCUSDT"
|
||||
position := types.NewPosition(symbol, "BTC", "USDT")
|
||||
|
|
|
@ -190,6 +190,7 @@ func (p *Position) NewMarketCloseOrder(percentage fixedpoint.Value) *SubmitOrder
|
|||
}
|
||||
}
|
||||
|
||||
// IsDust checks if the position is dust, the first argument is the price to calculate the dust quantity
|
||||
func (p *Position) IsDust(a ...fixedpoint.Value) bool {
|
||||
price := p.AverageCost
|
||||
if len(a) > 0 {
|
||||
|
@ -448,6 +449,7 @@ func (p *Position) String() string {
|
|||
)
|
||||
}
|
||||
|
||||
// BindStream binds the trade update callback and update the position
|
||||
func (p *Position) BindStream(stream Stream) {
|
||||
stream.OnTradeUpdate(func(trade Trade) {
|
||||
if p.Symbol == trade.Symbol {
|
||||
|
|
Loading…
Reference in New Issue
Block a user