/ Exchanges / src / data.jl
data.jl
 1  import Data: load_ohlcv, save_ohlcv
 2  using Data: zi, PairData, ZarrInstance
 3  using .Misc: config, Iterable
 4  
 5  @doc "Loads all pairs for a given exchange and timeframe, matching the global `config` and `zi` (Zarr Instance).
 6  
 7  
 8  $(TYPEDSIGNATURES)
 9  "
10  function load_ohlcv(exc::Exchange, timeframe::AbstractString; kwargs...)
11      pairs = tickers(config.qc; as_vec=true, config.margin, config.min_vol)
12      load_ohlcv(zi, exc, pairs, timeframe; kwargs...)
13  end
14  function load_ohlcv(exc::Exchange, pair::AbstractString, timeframe; kwargs...)
15      load_ohlcv(zi, exc, (pair,), timeframe; kwargs...)
16  end
17  function load_ohlcv(exc::Exchange, pairs::Iterable, timeframe::AbstractString; kwargs...)
18      pairs = pairs isa AbstractDict ? keys(pairs) : pairs
19      load_ohlcv(zi, exc, pairs, timeframe; kwargs...)
20  end
21  @doc """Load given pairs from the global `exc` (Exchange object) and `zi` (Zarr Instance).
22  
23  $(TYPEDSIGNATURES)
24  
25  """
26  function load_ohlcv(
27      pairs::Union{AbstractArray,AbstractDict}, timeframe::AbstractString; kwargs...
28  )
29      @assert !isempty(exc)
30      load_ohlcv(zi, exc, pairs, timeframe; kwargs...)
31  end
32  @doc "Loads all pairs for a given timeframe, matching the global `exc` (Exchange object) and `config`.
33  
34  $(TYPEDSIGNATURES)
35  "
36  function load_ohlcv(timeframe::AbstractString; kwargs...)
37      @assert !isempty(exc)
38      load_ohlcv(exc, timeframe; kwargs...)
39  end
40  @doc "Load all pairs from the exchange according to the configured quote currency and timeframe.
41  
42  $(TYPEDSIGNATURES)
43  "
44  function load_ohlcv()
45      load_ohlcv(
46          tickers(config.qc; config.min_vol, as_vec=true), string(config.min_timeframe)
47      )
48  end
49  
50  function save_ohlcv(exc::Exchange, args...; kwargs...)
51      save_ohlcv(zi[], exc.name, args...; kwargs...)
52  end
53  
54  @doc "Updates pair data of the globally set Exchange instance.
55  
56  $(TYPEDSIGNATURES)
57  "
58  function save_ohlcv(pair, timeframe, data; kwargs...)
59      @assert pair ∈ keys(exc.markets) "Mismatching global exchange instance and pair. Pair not in exchange markets."
60      save_ohlcv(zi[], exc.name, pair, timeframe, data; kwargs...)
61  end
62  
63  export load_ohlcv, save_ohlcv