panifie / PingPong.jl

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

Pluto notebook #18

Open untoreh opened 1 year ago

untoreh commented 1 year ago

Write a pluto notebook to showcase features

femtotrader commented 5 months ago

I'd be pleased to help on this when I will understand PingPong.jl features.

Here is what I did to have a Pluto notebook running with PingPong and a Docker configuration (thanks to #19)

I created a custom/Dockerfile file like so

FROM docker.io/panifie/pingpong-precomp-interactive
RUN julia -e 'using Pkg; Pkg.add("Pluto")' 
ENTRYPOINT [ "julia", "-e", "using Pluto; Pluto.run(; host=\"0.0.0.0\")"]

I create a docker-compose.yml like so

services:
  pingpong:
    #image: pingpong-precomp-interactive
    build:
      context: custom
      dockerfile: Dockerfile
    #restart: unless-stopped
    volumes:
      - ./user:/pingpong/user
    ports:
      - 127.0.0.1:1234:1234

I ran this container using

docker compose up

I looked at logs, browsed to http://127.0.0.1:1234/?secret=XXXXXX and created a new notebook with the following content

begin
    import Pkg
    # activate a temporary environment
    #Pkg.activate(mktempdir())
    Pkg.activate("/pingpong")
    #Pkg.add("Term")
    Pkg.instantiate()
end

unfortunately

using PingPong

raised

ArgumentError: Package PingPong not found in current path.

- Run `import Pkg; Pkg.add("PingPong")` to install the PingPong package.
panbonker commented 5 months ago

/pingpong is the main repo path. Package directories are camel cased, so you want to do

begin
    import Pkg
    Pkg.activate("/pingpong/PingPongInteractive") # or "/pingpong/PingPong"
    using PingPongInteractive
end
femtotrader commented 5 months ago

Thanks @panbonker .

Can't understand why I didn't found that myself! Thanks

Here's a work in progress

# v0.19.41

using Markdown
using InteractiveUtils

# ╔═╡ 24d485ab-9bc8-4110-aaa4-cc084324efc3
begin
    import Pkg
    Pkg.activate("/pingpong/PingPongInteractive")
    Pkg.instantiate()
end

# ╔═╡ b1830dda-6bc8-4f30-a36e-81406010dd58
begin
    using PingPong
    using Strategies: Strategies as st
    using Scrapers: Scrapers as scr
    using Data: Data as data
    using SimMode: SimMode as sm
    using Instruments: Instruments as ins
    using Data: Data as da
end

# ╔═╡ 3ed5e59a-ca10-4a13-aa6d-41752b34f8f5
s = st.strategy(:Example) # `st` is the `Strategies` module

# ╔═╡ 74a70750-d11c-47da-b090-9567c541af68
begin
    pairs = ins.raw.(s.universe.data.asset) # `ins` is the Instruments module
    const bn = scr.BinanceData  # `scr` is the Scrapers module
    bn.binancedownload(pairs)
end

# ╔═╡ b616952e-7756-4918-b9e5-2e56879eaba2
let data = bn.binanceload(pairs)
    da.stub!(s.universe, data) # `da` is the `Data` module
end

# ╔═╡ Cell order:
# ╠═24d485ab-9bc8-4110-aaa4-cc084324efc3
# ╠═b1830dda-6bc8-4f30-a36e-81406010dd58
# ╠═3ed5e59a-ca10-4a13-aa6d-41752b34f8f5
# ╠═74a70750-d11c-47da-b090-9567c541af68
# ╠═b616952e-7756-4918-b9e5-2e56879eaba2

but #33 is blocking

femtotrader commented 5 months ago

My opinion it that a very basic notebook with a simple strategy such as MA cross with one symbol, no margin should be written. Ideally this strategy should be exchange independant and use simply daily data from an exchange which provide enough data.

panbonker commented 5 months ago

you can pass a different exchange (and any other config) with st.strategy(:Example, exchange=:exc but a real exchange is always necessary because there is tight integration with information which is exchange specific, like precision, limits, leverage tiers, fees...

if you really wanted, you could use an exchange built with an empty symbol (getexchange!(Symbol())), try to run a backtest, and specialize functions with arbitrary default value until it stops throwing method errors...the exchange api is not well packed in one module currently

in absence of a specific exchange there are also api wrappers for coingecko/coinpaprika for getting ohlcv data

anyway I have updated the docs with the 1D strategy SimpleStrategy