mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
rename stock distribution
This commit is contained in:
parent
978dc4be67
commit
1552feb57c
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user