2020-06-18 10:54:14 +00:00
|
|
|
package bbgo
|
|
|
|
|
|
|
|
type TradingContext struct {
|
|
|
|
KLineWindowSize int
|
|
|
|
KLineWindows map[string]KLineWindow
|
2020-07-11 03:23:48 +00:00
|
|
|
|
2020-06-18 10:54:14 +00:00
|
|
|
Symbol string
|
2020-07-11 03:23:48 +00:00
|
|
|
|
|
|
|
// Market is the market configuration of a symbol
|
2020-06-18 11:00:03 +00:00
|
|
|
Market Market
|
2020-07-11 03:23:48 +00:00
|
|
|
|
|
|
|
AverageBidPrice float64
|
|
|
|
CurrentPrice float64
|
|
|
|
|
|
|
|
ProfitAndLossCalculator *ProfitAndLossCalculator
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *TradingContext) SetCurrentPrice(price float64) {
|
|
|
|
c.CurrentPrice = price
|
|
|
|
c.ProfitAndLossCalculator.SetCurrentPrice(price)
|
2020-06-18 10:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|