panifie / PingPong.jl

Cryptocurrency trading bot, and backtesting framework in julia
https://panifie.github.io/PingPong.jl/
GNU General Public License v3.0
36 stars 9 forks source link

[Help] questions about Quickstart examples. #53

Closed janckerchen closed 1 week ago

janckerchen commented 1 week ago

While studying the example code in the library documentation, I have a few questions.

  1. fetch_ohlcv and load_ohlcv come from Engine, but I didn't see these methods exported. Why not use the egn. prefix, like with st.?
  2. The implementation of load_ohlcv(s) is puzzling. The return value of Data.load_ohlcv(...) isn't used, and it seems to serve no useful purpose here.

using PingPong

@environment!
s = st.strategy(:SimpleStrategy, exchange=:binance) 

fetch_ohlcv(s, from=-1000)   #<---why not egn.fetch_ohlcv()
load_ohlcv(s)

sm.start!(s)

function load_ohlcv(
    s::Strategy; tf=s.config.min_timeframe, pairs=(raw(a) for a in assets(s))
)
    ...
    Data.load_ohlcv(exc, pairs_str, tf_str)  #<---The return value isn't used
    fill!(s)
end
panbonker commented 1 week ago

should either import all common functions such that modules prefixes are only used for the least common or just use prefixes for all the calls, do you prefer to use modules prefixes?

the call to load_ohlcv IIRC is used to load all the pairs data from storage asynchronously (they should be cached in the zarr store). TBH the fill! function over the strategy could be made async and then the load_ohlcv func can be removed

janckerchen commented 1 week ago

I prefer the approach you used without the prefix. But I don't see these symbols(load_ohlcv or fetch_ohlcv) exported anywhere in Engine, and searching with import .* fetch_ohlcv nor did I search for these symbols imported anywhere. How is it possible to call it without a prefix?

The only thing I could find was two imports in the @enviroment! macro, but they were both lower-level interfaces, not interfaces over strategy in Engine.


using .da: load_ohlcv
using .Watchers.Fetch: fetch_ohlcv
untoreh commented 1 week ago

Engine implements higher level functions for load/fetch_ohclv see: https://github.com/panifie/PingPong.jl/blob/3326d57cc8b8fcaeb66e5fc8b2d1c6a5342837dd/Engine/src/functions.jl#L5

the functions are imported from the modules that define the lower level ones (Data for load_ohlcv and Fetch for fetch_ohlcv) both in Engine and in the @environment! macro

remember that in julia import means the the methods are defined over the same function name (so using Engine: load_ohlcv, fetch_ohlcv is same as using Data: load_ohlcv; using Fetch: fetch_ohlcv

janckerchen commented 1 week ago

Thanks, for giving me some more insight into julia's dispatch mechanism. I was under the mistaken impression that dispatch only happens within the scope of the module specified by using or import.

Julia's design looks a bit surprising. Maybe adding using Engine: load_ohlcv, fetch_ohlcv to the @environment! macro would be better understood by julia newbies reading the source code.