-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33fc1f7
commit 13c94ec
Showing
9 changed files
with
216 additions
and
116 deletions.
There are no files selected for viewing
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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,84 @@ | ||
#!/usr/bin/env bash | ||
|
||
. ../lib/utils.sh # run `make deps` first | ||
. ../lib/utils.sh | ||
|
||
. api_urls.sh | ||
. klines.sh | ||
. ./symbols.sh # fix: find out why awk won't interpret 'symbols.sh' | ||
declare -Ag API_URLS | ||
|
||
API_URLS=( | ||
[spot]=https://api.binance.com/api/v3 | ||
[cm]=https://dapi.binance.com/dapi/v1 # COIN-M Futures | ||
[um]=https://fapi.binance.com/fapi/v1 # USD-M Futures | ||
) | ||
|
||
####################################### | ||
# Retrieves available symbols for a given product. | ||
# Globals: | ||
# API_URLS (associative array of API URLs per product) | ||
# Arguments: | ||
# product (string): Product key used to select base URL. | ||
# Outputs: | ||
# A list of symbols in plain text, one per line. | ||
# Returns: | ||
# 0 on success, non-zero on error. | ||
####################################### | ||
symbols() { | ||
local product base_url | ||
|
||
product=${1:?missing required <product> argument} | ||
|
||
base_url=${API_URLS[$product]:?API URL is not set} | ||
|
||
# todo: check response before passing to jq | ||
http.get "${base_url}/exchangeInfo" | jq -r .symbols[].symbol | ||
} | ||
|
||
####################################### | ||
# Retrieves kline (candlestick) data for a specific symbol and interval. | ||
# Globals: | ||
# API_URLS (associative array of API URLs per product) | ||
# Arguments: | ||
# product (string): Product key used to select base URL. | ||
# symbol (string): Trading symbol (e.g., BTCUSDT). | ||
# interval (string): Kline interval (e.g., 1m, 1h, 1d). | ||
# start_time (string, optional): Start date in format 'YYYY-MM-DD'. | ||
# end_time (string, optional): End date in format 'YYYY-MM-DD'. | ||
# Outputs: | ||
# JSON array of kline data. | ||
# Returns: | ||
# 0 on success, non-zero on error. | ||
####################################### | ||
klines() { | ||
local product symbol interval start_time end_time | ||
local base_url query_string | ||
local start_time_ms end_time_ms | ||
|
||
product=${1:?missing required <product> argument} | ||
symbol=${2:?missing required <symbol> argument} | ||
interval=${3:?missing required <interval> argument} | ||
start_time=${4:-} | ||
end_time=${5:-} | ||
|
||
base_url=${API_URLS[$product]:?API URL is not set} | ||
query_string="symbol=${symbol}&interval=${interval}&limit=1000" | ||
|
||
if is_set "$start_time"; then | ||
if ! is_date "$start_time"; then | ||
fail "<start_time> must be valid date" | ||
fi | ||
|
||
start_time_ms=$(date_to_ms "$start_time") | ||
query_string+="&startTime=${start_time_ms}" | ||
fi | ||
|
||
if is_set "$end_time"; then | ||
if ! is_date "$end_time"; then | ||
fail "<end_time> must be valid date" | ||
fi | ||
|
||
end_time_ms=$(date_to_ms "$end_time") | ||
query_string+="&endTime=${end_time_ms}" | ||
fi | ||
|
||
# todo: check response before passing to jq | ||
http.get "${base_url}/klines?${query_string}" | jq -r . | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.