This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# uses the date_to_milliseconds and interval_to_milliseconds functions | |
# https://gist.github.com/sammchardy/3547cfab1faf78e385b3fcb83ad86395 | |
# https://gist.github.com/sammchardy/fcbb2b836d1f694f39bddd569d1c16fe | |
from binance.client import Client | |
import time | |
def get_historical_klines(symbol, interval, start_str, end_str=None): | |
"""Get Historical Klines from Binance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def interval_to_milliseconds(interval): | |
"""Convert a Binance interval string to milliseconds | |
:param interval: Binance interval string 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w | |
:type interval: str | |
:return: | |
None if unit not one of m, h, d or w | |
None if string not in correct format | |
int value of interval in milliseconds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# requires dateparser package | |
import dateparser | |
import pytz | |
from datetime import datetime | |
def date_to_milliseconds(date_str): | |
"""Convert UTC date to milliseconds | |
If using offset strings add "UTC" to date string e.g. "now UTC", "11 hours ago UTC" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ninj0r admin, [Oct 20, 2017, 9:18:55 AM]: | |
It's a three step process: | |
1) Start listening to the stream and buffering the messages | |
2) Get a depth snapshot | |
3) replay the buffered messages and the live messges. | |
Depth updates have two variables, u and U | |
U is the initial updateId, and u is the final updateId. There can be multiple updates "compressed" into a single update that comes out via the web socket stream. |