diff --git a/bbgo/context.go b/bbgo/context.go index 5da525d84..56234d743 100644 --- a/bbgo/context.go +++ b/bbgo/context.go @@ -20,7 +20,7 @@ type Context struct { Balances map[string]types.Balance ProfitAndLossCalculator *accounting.ProfitAndLossCalculator - StockManager *StockManager + StockManager *StockDistribution } func (c *Context) SetCurrentPrice(price float64) { diff --git a/bbgo/stock.go b/bbgo/stock.go index 0c7fdc842..7584d7e41 100644 --- a/bbgo/stock.go +++ b/bbgo/stock.go @@ -51,7 +51,7 @@ func (slice StockSlice) Quantity() (total float64) { return round(total) } -type StockManager struct { +type StockDistribution struct { mu sync.Mutex Symbol string @@ -60,15 +60,15 @@ type StockManager struct { PendingSells StockSlice } -type Distribution struct { +type DistributionStats struct { PriceLevels []string `json:"priceLevels"` TotalQuantity float64 `json:"totalQuantity"` Quantities map[string]float64 `json:"quantities"` Stocks map[string]StockSlice `json:"stocks"` } -func (m *StockManager) Distribution(level int) *Distribution { - var d = Distribution{ +func (m *StockDistribution) DistributionStats(level int) *DistributionStats { + var d = DistributionStats{ Quantities: map[string]float64{}, Stocks: map[string]StockSlice{}, } @@ -101,14 +101,14 @@ func (m *StockManager) Distribution(level int) *Distribution { return &d } -func (m *StockManager) stock(stock Stock) error { +func (m *StockDistribution) stock(stock Stock) error { m.mu.Lock() m.Stocks = append(m.Stocks, stock) m.mu.Unlock() return m.flushPendingSells() } -func (m *StockManager) squash() { +func (m *StockDistribution) squash() { m.mu.Lock() defer m.mu.Unlock() @@ -121,7 +121,7 @@ func (m *StockManager) squash() { m.Stocks = squashed } -func (m *StockManager) flushPendingSells() error { +func (m *StockDistribution) flushPendingSells() error { if len(m.Stocks) == 0 || len(m.PendingSells) == 0 { return nil } @@ -138,7 +138,7 @@ func (m *StockManager) flushPendingSells() error { return nil } -func (m *StockManager) consume(sell Stock) error { +func (m *StockDistribution) consume(sell Stock) error { m.mu.Lock() defer m.mu.Unlock() @@ -193,7 +193,7 @@ func (m *StockManager) consume(sell Stock) error { return nil } -func (m *StockManager) AddTrades(trades []types.Trade) (checkpoints []int, err error) { +func (m *StockDistribution) AddTrades(trades []types.Trade) (checkpoints []int, err error) { feeSymbol := strings.HasPrefix(m.Symbol, m.TradingFeeCurrency) for idx, trade := range trades { // for other market trades diff --git a/bbgo/stock_test.go b/bbgo/stock_test.go index a73cdeaec..0c25a21b2 100644 --- a/bbgo/stock_test.go +++ b/bbgo/stock_test.go @@ -21,7 +21,7 @@ func TestStockManager(t *testing.T) { err = json.Unmarshal(out, &trades) assert.NoError(t, err) - var stockManager = &StockManager{ + var stockManager = &StockDistribution{ TradingFeeCurrency: "BNB", Symbol: "BTCUSDT", } @@ -42,7 +42,7 @@ func TestStockManager(t *testing.T) { {Symbol: "BTCUSDT", Price: 9200.0, Quantity: 0.01, IsBuyer: false}, } - var stockManager = &StockManager{ + var stockManager = &StockDistribution{ TradingFeeCurrency: "BNB", Symbol: "BTCUSDT", } @@ -75,7 +75,7 @@ func TestStockManager(t *testing.T) { {Symbol: "BTCUSDT", Price: 9200.0, Quantity: 0.05, IsBuyer: false}, } - var stockManager = &StockManager{ + var stockManager = &StockDistribution{ TradingFeeCurrency: "BNB", Symbol: "BTCUSDT", } @@ -93,7 +93,7 @@ func TestStockManager(t *testing.T) { {Symbol: "BTCUSDT", Price: 9200.0, Quantity: 0.05, IsBuyer: false}, } - var stockManager = &StockManager{ + var stockManager = &StockDistribution{ TradingFeeCurrency: "BNB", Symbol: "BTCUSDT", } @@ -111,7 +111,7 @@ func TestStockManager(t *testing.T) { {Symbol: "BTCUSDT", Price: 8000.0, Quantity: 0.01, IsBuyer: false}, } - var stockManager = &StockManager{ + var stockManager = &StockDistribution{ TradingFeeCurrency: "BNB", Symbol: "BTCUSDT", } @@ -136,7 +136,7 @@ func TestStockManager(t *testing.T) { {Symbol: "BTCUSDT", Price: 9100.0, Quantity: 0.05, IsBuyer: true}, } - var stockManager = &StockManager{ + var stockManager = &StockDistribution{ TradingFeeCurrency: "BNB", Symbol: "BTCUSDT", } @@ -161,7 +161,7 @@ func TestStockManager(t *testing.T) { {Symbol: "BTCUSDT", Price: 9100.0, Quantity: 0.05, IsBuyer: true}, } - var stockManager = &StockManager{ + var stockManager = &StockDistribution{ TradingFeeCurrency: "BNB", Symbol: "BTCUSDT", } diff --git a/bbgo/trader.go b/bbgo/trader.go index 3bd76855b..ac67faae6 100644 --- a/bbgo/trader.go +++ b/bbgo/trader.go @@ -163,7 +163,7 @@ func (trader *Trader) Connect(ctx context.Context) (err error) { } session.Trades[symbol] = trades - stockManager := &StockManager{ + stockManager := &StockDistribution{ Symbol: symbol, TradingFeeCurrency: tradingFeeCurrency, } @@ -211,7 +211,7 @@ func (trader *Trader) Initialize(ctx context.Context, startTime time.Time) error log.Infof("%d trades loaded", len(trades)) - stockManager := &StockManager{ + stockManager := &StockDistribution{ Symbol: trader.Symbol, TradingFeeCurrency: tradingFeeCurrency, }