mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
pkg/exchange: types.kline end time should -1 time.Millisecond
This commit is contained in:
parent
755ea5e427
commit
eb04eaeea4
|
@ -346,6 +346,8 @@ func toGlobalBalanceMap(balances []Balance) types.BalanceMap {
|
|||
func toGlobalKLines(symbol string, interval types.Interval, kLines v2.KLineResponse) []types.KLine {
|
||||
gKLines := make([]types.KLine, len(kLines))
|
||||
for i, kline := range kLines {
|
||||
// follow the binance rule, to avoid endTime overlapping with the next startTime. So we subtract -1 time.Millisecond
|
||||
// on endTime.
|
||||
endTime := types.Time(kline.Ts.Time().Add(interval.Duration() - time.Millisecond))
|
||||
gKLines[i] = types.KLine{
|
||||
Exchange: types.ExchangeBitget,
|
||||
|
|
|
@ -368,7 +368,7 @@ func toLocalInterval(interval types.Interval) (string, error) {
|
|||
func toGlobalKLines(symbol string, interval types.Interval, klines []bybitapi.KLine) []types.KLine {
|
||||
gKLines := make([]types.KLine, len(klines))
|
||||
for i, kline := range klines {
|
||||
endTime := types.Time(kline.StartTime.Time().Add(interval.Duration()))
|
||||
endTime := types.Time(kline.StartTime.Time().Add(interval.Duration() - time.Millisecond))
|
||||
gKLines[i] = types.KLine{
|
||||
Exchange: types.ExchangeBybit,
|
||||
Symbol: symbol,
|
||||
|
|
|
@ -836,7 +836,7 @@ func Test_toGlobalKLines(t *testing.T) {
|
|||
Exchange: types.ExchangeBybit,
|
||||
Symbol: resp.Symbol,
|
||||
StartTime: types.Time(resp.List[0].StartTime.Time()),
|
||||
EndTime: types.Time(resp.List[0].StartTime.Time().Add(interval.Duration())),
|
||||
EndTime: types.Time(resp.List[0].StartTime.Time().Add(interval.Duration() - time.Millisecond)),
|
||||
Interval: interval,
|
||||
Open: fixedpoint.NewFromFloat(29045.3),
|
||||
Close: fixedpoint.NewFromFloat(29228.56),
|
||||
|
@ -850,7 +850,7 @@ func Test_toGlobalKLines(t *testing.T) {
|
|||
Exchange: types.ExchangeBybit,
|
||||
Symbol: resp.Symbol,
|
||||
StartTime: types.Time(resp.List[1].StartTime.Time()),
|
||||
EndTime: types.Time(resp.List[1].StartTime.Time().Add(interval.Duration())),
|
||||
EndTime: types.Time(resp.List[1].StartTime.Time().Add(interval.Duration() - time.Millisecond)),
|
||||
Interval: interval,
|
||||
Open: fixedpoint.NewFromFloat(29167.33),
|
||||
Close: fixedpoint.NewFromFloat(29045.3),
|
||||
|
|
|
@ -54,7 +54,9 @@ type KLine struct {
|
|||
Symbol string `json:"symbol" db:"symbol"`
|
||||
|
||||
StartTime Time `json:"startTime" db:"start_time"`
|
||||
EndTime Time `json:"endTime" db:"end_time"`
|
||||
// EndTime follows the binance rule, to avoid endTime overlapping with the next startTime. So if your end time (2023-01-01 01:00:00)
|
||||
// are overlapping with next start time interval (2023-01-01 01:00:00), you should subtract -1 time.millisecond on EndTime.
|
||||
EndTime Time `json:"endTime" db:"end_time"`
|
||||
|
||||
Interval Interval `json:"interval" db:"interval"`
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user