From 2e2afc6bd0a31457bd3dc898f63aa39702d69cc5 Mon Sep 17 00:00:00 2001 From: Azulinho Date: Sun, 14 May 2023 13:03:52 +0100 Subject: [PATCH] Add flag -u for unit of klines to pull add -u so that we can pull different intervals from binance. Use as: -u 1m -u 5m -u 1h -u 1d it is possible to 'extract' these larger intervals from the 1min logs through some grepping into newer files. This might be a better approach to obtain all these different interval files, and then simply use this .py to pull the latest day files every night --- utils/pull_klines.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/utils/pull_klines.py b/utils/pull_klines.py index f7f9e4c..6f2331d 100644 --- a/utils/pull_klines.py +++ b/utils/pull_klines.py @@ -20,7 +20,7 @@ def get_all_tickers(): return sorted(_tickers) -def pull_klines(k_symbol, k_start, k_end, limit=720): +def pull_klines(k_symbol, k_start, k_end, _unit, limit=720): """returns klines for a particular day and ticker""" k_results = [] print(f"start: {k_start} end: {k_end}") @@ -28,7 +28,7 @@ def pull_klines(k_symbol, k_start, k_end, limit=720): print(f"fetching chunk {k_start} <-> {k_start + (limit * 60000)}") klines = client.get_klines( symbol=k_symbol, - interval="1m", + interval=_unit, limit=limit, startTime=int(k_start), endTime=int(k_start + (limit * 60000)), @@ -99,6 +99,9 @@ def generate_index(log_dir="log"): parser.add_argument( "-e", "--end", help="end day to fetch klines for", required=False ) + parser.add_argument( + "-u", "--unit", help="Unit to use 1m/5m/1h/1d", default="1m" + ) args = parser.parse_args() s = args.start @@ -108,6 +111,7 @@ def generate_index(log_dir="log"): else: e = s + unit = args.unit start_dt = datetime.strptime(s, "%Y%m%d") end_dt = datetime.strptime(e, "%Y%m%d") @@ -148,7 +152,7 @@ def generate_index(log_dir="log"): print(f"getting klines for {ticker} on {day}") ticker_klines: list = [] - for line in pull_klines(ticker, start, end): + for line in pull_klines(ticker, start, end, unit): ticker_klines.append(line) if not ticker_klines: