mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-23 07:15:15 +00:00
33 lines
683 B
Go
33 lines
683 B
Go
package bbgo
|
|
|
|
import "time"
|
|
|
|
type TradingContext struct {
|
|
KLineWindowSize int
|
|
KLineWindows map[string]KLineWindow
|
|
AverageBidPrice float64
|
|
Stock float64
|
|
Profit float64
|
|
CurrentPrice float64
|
|
Trades []Trade
|
|
TradeStartTime time.Time
|
|
Symbol string
|
|
Market Market
|
|
}
|
|
|
|
func (c *TradingContext) AddKLine(kline KLine) KLineWindow {
|
|
var klineWindow = c.KLineWindows[kline.Interval]
|
|
klineWindow.Add(kline)
|
|
|
|
if c.KLineWindowSize > 0 {
|
|
klineWindow.Truncate(c.KLineWindowSize)
|
|
}
|
|
|
|
return klineWindow
|
|
}
|
|
|
|
func (c *TradingContext) UpdatePnL() {
|
|
c.AverageBidPrice, c.Stock, c.Profit, _ = CalculateCostAndProfit(c.Trades, c.CurrentPrice)
|
|
}
|
|
|