PushCandle

This commit is contained in:
Luke I. Wilson
2023-05-14 20:40:22 -05:00
parent c00a468249
commit 7f09664454
4 changed files with 111 additions and 15 deletions

View File

@@ -21,16 +21,22 @@ type Trader struct {
Frequency string
CandlesToKeep int
Log *log.Logger
EOF bool
data *DataFrame
sched *gocron.Scheduler
idx int
stats *DataFrame // Performance (financial) reporting and statistics.
}
func (t *Trader) Data() *DataFrame {
return t.data
}
func (t *Trader) Stats() *DataFrame {
return t.stats
}
// Run starts the trader. This is a blocking call.
func (t *Trader) Run() {
t.sched = gocron.NewScheduler(time.UTC)
@@ -71,18 +77,21 @@ func (t *Trader) Run() {
// Tick updates the current state of the market and runs the strategy.
func (t *Trader) Tick() {
t.Log.Println("Tick")
if t.idx == 0 {
t.Strategy.Init(t)
}
t.fetchData()
t.Strategy.Next(t)
t.Log.Println("Tick")
}
func (t *Trader) fetchData() {
var err error
t.data, err = t.Broker.Candles(t.Symbol, t.Frequency, t.CandlesToKeep)
if err != nil {
if err == ErrEOF {
t.Log.Println("End of data")
t.sched.Clear()
} else if err != nil {
panic(err) // TODO: implement safe shutdown procedure
}
}
@@ -105,5 +114,6 @@ func NewTrader(config TraderConfig) *Trader {
Frequency: config.Frequency,
CandlesToKeep: config.CandlesToKeep,
Log: logger,
stats: NewDataFrame(nil),
}
}