API
Documentation for CryptoMarketData.
Types
AbstractExchange
Every exchange is a subtype of this.
AbstractCandle
Every exchange also has a matching candle type that's a subtype of AbstractCandle. Its purpose is to capture the data given to us by the exchange.
Functions
CryptoMarketData.earliest_candle
CryptoMarketData.get_candles_for_day
CryptoMarketData.get_markets
CryptoMarketData.get_saved_markets
CryptoMarketData.load
CryptoMarketData.save!
CryptoMarketData.save_day!
CryptoMarketData.earliest_candle
— Methodearliest_candle(exchange, market)
Return the earliest candle for the given market in the 1m timeframe.
CryptoMarketData.get_candles_for_day
— Methodget_candles_for_day(exchange, market, day::Date)
Fetch all of the 1m candles for the given exchange, market, and day. The vector and candles returned is just the right size to save to the archives.
CryptoMarketData.get_markets
— Methodget_markets(exchange)
Fetch the available markets for the given exchange.
Example
julia> bitstamp = Bitstamp()
julia> markets = get_markets(bitstamp)
CryptoMarketData.get_saved_markets
— Methodget_saved_markets(; datadir)
Return a DataFrame that lists the currently saved markets.
Keyword Arguments
- datadir="./data" - directory where saved data is stored
Example
julia> saved = get_local_markets()
10×4 DataFrame
Row │ exchange market start stop
│ Any Any Any Any
─────┼───────────────────────────────────────────────────────
1 │ binance BTCUSD_240628 2023-12-29 2024-02-17
2 │ binance BTCUSD_PERP 2020-08-11 2020-08-16
3 │ bitget BTCUSD_DMCBL 2019-04-23 2024-02-16
4 │ bitget DOGEUSD_DMCBL 2024-02-01 2024-02-20
5 │ bitmex ETHUSD 2018-08-02 2024-02-19
6 │ bitstamp BTCUSD 2011-08-18 2024-02-25
7 │ bybit ADAUSD 2022-03-24 2022-04-21
8 │ bybit-inverse ADAUSD 2022-03-24 2022-04-20
9 │ bybit-linear 10000LADYSUSDT 2023-05-11 2024-03-04
10 │ pancakeswap BTCUSD 2023-03-15 2024-03-04
CryptoMarketData.load
— Methodload(exchange, market; datadir, span, tf, table)
Load candles for the given exchange and market from the file system.
Keyword Arguments
- datadir="./data" - directory where saved data is stored
- span - a
Date
span that defines what Dates to load candles. If it'smissing
, load everything. - tf - a
Period
that is used to aggregate 1m candles into higher timeframes. - table - a Tables.jl-compatible struct to load candles into. The default is
DataFrame
.
Example
julia> bitstamp = Bitstamp()
julia> btcusd4h = load!(bitstamp, "BTC/USD"; span=Date("2024-01-01"):Date("2024-02-10"), tf=Hour(4))
CryptoMarketData.save!
— Methodsave!(exchange, market; datadir, startday, endday, delay)
Download 1m candles from the given exchange and market, and save them locally.
Keyword Arguments
- datadir="./data" - directory where saved data is stored
- startday - a
Date
to start fetching candles from - endday - a
Date
to stop fetching candles - delay - a delay to be passed to
sleep()
that will pause between internal calls tosave_day!()
Example
julia> bitstamp = Bitstamp()
julia> save!(bitstamp, "BTC/USD", endday=Date("2020-08-16"))
CryptoMarketData.save_day!
— Methodsave_day!(exchange, market, candles; datadir="./data")
Save a day worth of 1m candles the caller provides for the given exchange and market.
Keyword Arguments
- datadir="./data" - directory where saved data is stored