From 783bb739dac2a05bde68baa9b679a2c947a695a5 Mon Sep 17 00:00:00 2001 From: joakimhellum Date: Tue, 3 Dec 2024 13:31:54 +0100 Subject: [PATCH] klines: handle empty array --- lib/binance.sh | 5 +++++ src/klines.sh | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/lib/binance.sh b/lib/binance.sh index 6b0f997..d98848d 100644 --- a/lib/binance.sh +++ b/lib/binance.sh @@ -673,6 +673,11 @@ klines() { fail "Failed to get valid data from API: $response" fi + length=$(json_length "$response") + if (( length == 0 )); then + break + fi + klines=$(echo "$klines" "$response" | jq -s 'add') # todo: add max_iterations and check start_time to avoid infinite loop start_time_ms=$(echo "$response" | jq -r '.[-1][6]') # get last close time diff --git a/src/klines.sh b/src/klines.sh index 3520225..2926a5a 100644 --- a/src/klines.sh +++ b/src/klines.sh @@ -40,6 +40,11 @@ klines() { fail "Failed to get valid data from API: $response" fi + length=$(json_length "$response") + if (( length == 0 )); then + break + fi + klines=$(echo "$klines" "$response" | jq -s 'add') # todo: add max_iterations and check start_time to avoid infinite loop start_time_ms=$(echo "$response" | jq -r '.[-1][6]') # get last close time