Skip to content

Commit

Permalink
Add flag -u for unit of klines to pull
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Azulinho committed May 14, 2023
1 parent 7518131 commit 2e2afc6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions utils/pull_klines.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ 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}")
while k_start <= k_end:
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)),
Expand Down Expand Up @@ -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
Expand All @@ -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")

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 2e2afc6

Please sign in to comment.