Giter Club home page Giter Club logo

Comments (2)

panbonker avatar panbonker commented on July 22, 2024 1

The bot doesn't manage data for you, see here #16

To access ohlcv data from a strategy you can do so from an AssetInstance variable:
ai.data is a dict where keys are timeframes and values are dataframes of ohlcv data. The first pair should always be the smallest timeframe of the strategy, which is the one you monitor for updates (during paper and live mode). The rest of the dataframes in the dict (if any) should be resampled (downsampled) from the smaller one.
For convenience the "main" timeframe of the asset instance (and strategy) can be accessed with the ohlcv property (ai.ohlcv).

During backtest you need to pre populate the dataframes your self. There are utilities in the bot to download data in different ways.
see here a function to load data from the Scrapers module https://github.com/panifie/PingPong.jl/blob/master/PingPong/test/env.jl
and here a function to load a strategy, and fill its assets with stub data https://github.com/panifie/PingPong.jl/blob/master/PingPong/test/env_strat.jl

During paper/live you create a Watcher from the Watchers module and use the watcher view which is a dict of dataframes (ohlcv) and use those dataframes in your strategy universe, see here where we create the watcher and fill the strategy universe with the data monitored by the watcher

if s isa Union{PaperStrategy,LiveStrategy}
stub!(s.universe, s[:tickers_watcher].view; fromfiat=false)
end

If you want to execute something at specified interval the simplest approach is to just track timestamps:

isstale15m(s, ts) = ts - attr(s, :job_15m, DateTime(0)) > tf"15m"
job15m(s, ts, ats) = (println("Running job every 15m"); setattr!(s, :job_15m, ts))

function ping!(s, ts::DateTime, args...)
    ats = available(ts)
    isstale15m(s, ts) && job15m(s, ts, ats)
end

A fancier approach would involve using either Rocket.jl or DiscreteEvents.jl but I don't think that's necessary, If I implement it it would be more like an optional feature where you can call a pong! function and get a virtual clock to which you can subscribe functions that run at a particular time, and that clock would be replaced with a realtime clock in paper/live mode.

from pingpong.jl.

c0indev3l avatar c0indev3l commented on July 22, 2024

An important concept in Trality bots is the concept of "handler" https://docs.trality.com/trality-code-editor/core-concepts/overview
See for example https://gist.github.com/c0indev3l/855381f07865dfca079e8252e736ae35#file-two_intervals-py
Functions are schedule to be run periodically (every hour for one and every 15 minutes for an other one).
My guess is that their bot is composed of several parts. When live trading, one part is probably simply receiving price data and storing them into a database (maybe a TSDB). An other part is responsible of scheduling what function will have to be executed in the future. A third one is responsible of executing scheduled function at expected time. What is your opinion about that ?

from pingpong.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.