Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StartTime/EndTime on KlinesRequests are not applying on response #8

Open
amir-the-h opened this issue Feb 15, 2021 · 3 comments
Open

Comments

@amir-the-h
Copy link

Hey @rootpd, this is Amir.

I installed your package from the official fork of Binance's GitHub account but when I'm trying to fetch all historical klines of BTCUSDT for example, it seems StartTime and EndTime are not working properly.

I will put my fetcher part code here for more technical knowledge.

for startTime.Before(lastCandle) {
	batchSize := BatchSize(duration, interval)
	fmt.Printf("Fetching %s from %s with size of %d\n", symbol, startTime, batchSize)
	klines, err := binanceWrapper.Klines(binance.KlinesRequest{
		Symbol:    symbol,
		Interval:  interval,
		Limit:     batchSize,
		StartTime: startTime.Unix(),
	})

	if err != nil {
		panic(err)
	}
	for _, kline := range klines {
		fmt.Println(kline)
	}
	startTime = startTime.Add(duration)
}

The first problem is when I'm increasing my startTime the result is not changing. See my result as well:

Fetching BTCUSDT from 2017-08-17 08:30:00 +0430 +0430 with size of 4
&{2017-08-17 08:30:00 +0430 +0430 4261.48 4280.56 4261.48 4261.48 2.189061 2017-08-17 08:44:59.999 +0430 +0430 9333.6209622 9 0.489061 2089.1049622}
&{2017-08-17 08:45:00 +0430 +0430 4261.48 4270.41 4261.32 4261.45 9.119865 2017-08-17 08:59:59.999 +0430 +0430 38891.13304617 40 3.447113 14703.93499548}
&{2017-08-17 09:00:00 +0430 +0430 4280 4310.07 4267.99 4310.07 21.923552 2017-08-17 09:14:59.999 +0430 +0430 94080.91756819 58 20.421317 87620.97787639}
&{2017-08-17 09:15:00 +0430 +0430 4310.07 4313.62 4291.37 4308.83 13.948531 2017-08-17 09:29:59.999 +0430 +0430 60060.46681648 64 10.803012 46538.46010897}
Fetching BTCUSDT from 2017-08-17 09:30:00 +0430 +0430 with size of 4
&{2017-08-17 08:30:00 +0430 +0430 4261.48 4280.56 4261.48 4261.48 2.189061 2017-08-17 08:44:59.999 +0430 +0430 9333.6209622 9 0.489061 2089.1049622}
&{2017-08-17 08:45:00 +0430 +0430 4261.48 4270.41 4261.32 4261.45 9.119865 2017-08-17 08:59:59.999 +0430 +0430 38891.13304617 40 3.447113 14703.93499548}
&{2017-08-17 09:00:00 +0430 +0430 4280 4310.07 4267.99 4310.07 21.923552 2017-08-17 09:14:59.999 +0430 +0430 94080.91756819 58 20.421317 87620.97787639}
&{2017-08-17 09:15:00 +0430 +0430 4310.07 4313.62 4291.37 4308.83 13.948531 2017-08-17 09:29:59.999 +0430 +0430 60060.46681648 64 10.803012 46538.46010897}
Fetching BTCUSDT from 2017-08-17 10:30:00 +0430 +0430 with size of 4
&{2017-08-17 08:30:00 +0430 +0430 4261.48 4280.56 4261.48 4261.48 2.189061 2017-08-17 08:44:59.999 +0430 +0430 9333.6209622 9 0.489061 2089.1049622}
&{2017-08-17 08:45:00 +0430 +0430 4261.48 4270.41 4261.32 4261.45 9.119865 2017-08-17 08:59:59.999 +0430 +0430 38891.13304617 40 3.447113 14703.93499548}
&{2017-08-17 09:00:00 +0430 +0430 4280 4310.07 4267.99 4310.07 21.923552 2017-08-17 09:14:59.999 +0430 +0430 94080.91756819 58 20.421317 87620.97787639}
&{2017-08-17 09:15:00 +0430 +0430 4310.07 4313.62 4291.37 4308.83 13.948531 2017-08-17 09:29:59.999 +0430 +0430 60060.46681648 64 10.803012 46538.46010897}
Fetching BTCUSDT from 2017-08-17 11:30:00 +0430 +0430 with size of 4
&{2017-08-17 08:30:00 +0430 +0430 4261.48 4280.56 4261.48 4261.48 2.189061 2017-08-17 08:44:59.999 +0430 +0430 9333.6209622 9 0.489061 2089.1049622}
&{2017-08-17 08:45:00 +0430 +0430 4261.48 4270.41 4261.32 4261.45 9.119865 2017-08-17 08:59:59.999 +0430 +0430 38891.13304617 40 3.447113 14703.93499548}
&{2017-08-17 09:00:00 +0430 +0430 4280 4310.07 4267.99 4310.07 21.923552 2017-08-17 09:14:59.999 +0430 +0430 94080.91756819 58 20.421317 87620.97787639}
&{2017-08-17 09:15:00 +0430 +0430 4310.07 4313.62 4291.37 4308.83 13.948531 2017-08-17 09:29:59.999 +0430 +0430 60060.46681648 64 10.803012 46538.46010897}

Now if you try to reverse the loop statement the result would be the same:

for startTime.After(lastCandle) {
	batchSize := BatchSize(duration, interval)
	fmt.Printf("Fetching %s from %s with size of %d\n", symbol, endTime, batchSize)
	klines, err := binanceWrapper.Klines(binance.KlinesRequest{
		Symbol:    symbol,
		Interval:  interval,
		Limit:     batchSize,
		EndTime:   endTime.UnixNano(),
	})

	if err != nil {
		panic(err)
	}
	for _, kline := range klines {
		fmt.Println(kline)
	}
	startTime = startTime.Add(duration * -1)
}

result:

Fetching BTCUSDT from 2021-02-15 18:45:00 +0330 +0330 with size of 4
&{2021-02-15 18:00:00 +0330 +0330 47829.99 47879.42 47588.2 47722.01 773.050003 2021-02-15 18:14:59.999 +0330 +0330 3.689826173343654e+07 25429 344.385209 1.643913508366174e+07}
&{2021-02-15 18:15:00 +0330 +0330 47722.01 47832.81 47472.92 47564.16 870.013722 2021-02-15 18:29:59.999 +0330 +0330 4.150251455301177e+07 22309 378.439068 1.805503041406599e+07}
&{2021-02-15 18:30:00 +0330 +0330 47563.58 47847.82 47536.15 47734.85 634.439984 2021-02-15 18:44:59.999 +0330 +0330 3.028078616675128e+07 21891 325.635573 1.554297327532211e+07}
&{2021-02-15 18:45:00 +0330 +0330 47734.84 47796.37 47600 47693.89 143.030794 2021-02-15 18:59:59.999 +0330 +0330 6.82348336983094e+06 5308 64.963625 3.09997511370434e+06}
Fetching BTCUSDT from 2021-02-15 17:45:00 +0330 +0330 with size of 4
&{2021-02-15 18:00:00 +0330 +0330 47829.99 47879.42 47588.2 47722.01 773.050003 2021-02-15 18:14:59.999 +0330 +0330 3.689826173343654e+07 25429 344.385209 1.643913508366174e+07}
&{2021-02-15 18:15:00 +0330 +0330 47722.01 47832.81 47472.92 47564.16 870.013722 2021-02-15 18:29:59.999 +0330 +0330 4.150251455301177e+07 22309 378.439068 1.805503041406599e+07}
&{2021-02-15 18:30:00 +0330 +0330 47563.58 47847.82 47536.15 47734.85 634.439984 2021-02-15 18:44:59.999 +0330 +0330 3.028078616675128e+07 21891 325.635573 1.554297327532211e+07}
&{2021-02-15 18:45:00 +0330 +0330 47734.84 47796.37 47600 47677.76 143.414877 2021-02-15 18:59:59.999 +0330 +0330 6.84179821018066e+06 5323 65.105217 3.10672763575182e+06}
Fetching BTCUSDT from 2021-02-15 16:45:00 +0330 +0330 with size of 4
&{2021-02-15 18:00:00 +0330 +0330 47829.99 47879.42 47588.2 47722.01 773.050003 2021-02-15 18:14:59.999 +0330 +0330 3.689826173343654e+07 25429 344.385209 1.643913508366174e+07}
&{2021-02-15 18:15:00 +0330 +0330 47722.01 47832.81 47472.92 47564.16 870.013722 2021-02-15 18:29:59.999 +0330 +0330 4.150251455301177e+07 22309 378.439068 1.805503041406599e+07}
&{2021-02-15 18:30:00 +0330 +0330 47563.58 47847.82 47536.15 47734.85 634.439984 2021-02-15 18:44:59.999 +0330 +0330 3.028078616675128e+07 21891 325.635573 1.554297327532211e+07}
&{2021-02-15 18:45:00 +0330 +0330 47734.84 47796.37 47600 47691.66 143.669924 2021-02-15 18:59:59.999 +0330 +0330 6.85396098111705e+06 5333 65.360264 3.11889040668821e+06}
Fetching BTCUSDT from 2021-02-15 15:45:00 +0330 +0330 with size of 4
&{2021-02-15 18:00:00 +0330 +0330 47829.99 47879.42 47588.2 47722.01 773.050003 2021-02-15 18:14:59.999 +0330 +0330 3.689826173343654e+07 25429 344.385209 1.643913508366174e+07}
&{2021-02-15 18:15:00 +0330 +0330 47722.01 47832.81 47472.92 47564.16 870.013722 2021-02-15 18:29:59.999 +0330 +0330 4.150251455301177e+07 22309 378.439068 1.805503041406599e+07}
&{2021-02-15 18:30:00 +0330 +0330 47563.58 47847.82 47536.15 47734.85 634.439984 2021-02-15 18:44:59.999 +0330 +0330 3.028078616675128e+07 21891 325.635573 1.554297327532211e+07}
&{2021-02-15 18:45:00 +0330 +0330 47734.84 47796.37 47600 47698.1 143.893576 2021-02-15 18:59:59.999 +0330 +0330 6.86462833040235e+06 5345 65.498498 3.12548348052189e+06}

PS: The EndTime will only work with UnixNano() not Unix().

@amir-the-h
Copy link
Author

Any updates here @rootpd

@rootpd
Copy link
Owner

rootpd commented Mar 23, 2021

Hi, I haven't used the library for quite some time. Maybe I'll look at it in the near future, but at this point I'm out of the capacity :/.

@amir-the-h
Copy link
Author

Thanks for your response and hope to hear more soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants