mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
Merge pull request #436 from jessy1092/ftx/correct-poll-klines
ftx: Separate the lastClosed record for different interval
This commit is contained in:
commit
a8c5a80357
|
@ -133,16 +133,16 @@ func (s *Stream) Subscribe(channel types.Channel, symbol string, option types.Su
|
||||||
|
|
||||||
func (s *Stream) pollKLines(ctx context.Context) {
|
func (s *Stream) pollKLines(ctx context.Context) {
|
||||||
|
|
||||||
lastClosed := time.Time{}
|
lastClosed := map[types.Interval]time.Time{}
|
||||||
// get current kline candle
|
// get current kline candle
|
||||||
for _, sub := range s.klineSubscriptions {
|
for _, sub := range s.klineSubscriptions {
|
||||||
klines := getLast2KLine(s.exchange, ctx, sub.symbol, sub.interval)
|
klines := getLast2KLine(s.exchange, ctx, sub.symbol, sub.interval)
|
||||||
if len(klines) > 0 {
|
if len(klines) > 0 {
|
||||||
// handle mutiple klines, get the latest one
|
// handle mutiple klines, get the latest one
|
||||||
if lastClosed.Unix() < klines[0].StartTime.Unix() {
|
if lastClosed[sub.interval].Unix() < klines[0].StartTime.Unix() {
|
||||||
s.EmitKLine(klines[0])
|
s.EmitKLine(klines[0])
|
||||||
s.EmitKLineClosed(klines[0])
|
s.EmitKLineClosed(klines[0])
|
||||||
lastClosed = klines[0].StartTime.Time()
|
lastClosed[sub.interval] = klines[0].StartTime.Time()
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(klines) > 1 {
|
if len(klines) > 1 {
|
||||||
|
@ -174,10 +174,10 @@ func (s *Stream) pollKLines(ctx context.Context) {
|
||||||
|
|
||||||
if len(klines) > 0 {
|
if len(klines) > 0 {
|
||||||
// handle mutiple klines, get the latest one
|
// handle mutiple klines, get the latest one
|
||||||
if lastClosed.Unix() < klines[0].StartTime.Unix() {
|
if lastClosed[sub.interval].Unix() < klines[0].StartTime.Unix() {
|
||||||
s.EmitKLine(klines[0])
|
s.EmitKLine(klines[0])
|
||||||
s.EmitKLineClosed(klines[0])
|
s.EmitKLineClosed(klines[0])
|
||||||
lastClosed = klines[0].StartTime.Time()
|
lastClosed[sub.interval] = klines[0].StartTime.Time()
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(klines) > 1 {
|
if len(klines) > 1 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user