functions.jl
1 import .LiveMode.Watchers.Fetch: fetch_ohlcv, propagate_ohlcv!, update_ohlcv! 2 import .Processing.Data: load_ohlcv 3 using .Exchanges: exchangeid, account 4 using .Exchanges.ExchangeTypes: params 5 6 function fetch_ohlcv( 7 s::Strategy; 8 sandbox=false, 9 tf=s.config.min_timeframe, 10 pairs=(raw(a) for a in assets(s)), 11 fetch_kwargs..., 12 ) 13 exc = getexchange!(exchangeid(s), params(exc); sandbox, account=account(exc)) 14 tf_str = string(tf) 15 pairs_str = collect(pairs) 16 fetch_ohlcv(exc, tf_str, pairs_str; fetch_kwargs...) 17 end 18 19 function load_ohlcv( 20 s::Strategy; tf=s.config.min_timeframe, pairs=(raw(a) for a in assets(s)) 21 ) 22 exc = exchange(s) 23 tf_str = string(tf) 24 pairs_str = collect(pairs) 25 Data.load_ohlcv(exc, pairs_str, tf_str) 26 fill!(s) 27 end 28 29 function fetch_ohlcv!(s::Strategy) 30 @sync for ai in s.universe 31 @async begin 32 exc = exchange(ai) 33 sym = raw(ai) 34 v = fetch_ohlcv(exc, s.timeframe, sym, from=-2000) 35 ai.data[s.timeframe] = v[sym].data 36 propagate_ohlcv!(ai.data, raw(ai), exc) 37 end 38 end 39 end 40 41 function update_ohlcv!(s::Strategy; kwargs...) 42 tf = s.timeframe 43 @sync for ai in s.universe 44 @async begin 45 exc = exchange(ai) 46 sym = raw(ai) 47 update_ohlcv!(ohlcv(ai, tf), sym, exc, tf; kwargs...) 48 propagate_ohlcv!(ai.data, sym, exc) 49 end 50 end 51 end