Skip to main content

Backtesting framework of the OctoBot Ecosystem

Project description

OctoBot-Script 0.0.26

PyPI Downloads Dockerhub Github-Action-CI

OctoBot-Script Community

Telegram Chat Discord Twitter

OctoBot Script is the Quant framework by OctoBot

OctoBot Script is in alpha version

Documentation available at octobot.cloud/en/guides/octobot-script

Install OctoBot Script from pip

OctoBot Script requires Python 3.10

python3 -m pip install OctoBot wheel appdirs==1.4.4
python3 -m pip install octobot-script

Example of a backtesting script

Script

import asyncio
import tulipy    # Can be any TA library.
import octobot_script as obs


async def rsi_test():
    async def strategy(ctx):
        # Will be called at each candle.
        if run_data["entries"] is None:
            # Compute entries only once per backtest.
            closes = await obs.Close(ctx, max_history=True)
            times = await obs.Time(ctx, max_history=True, use_close_time=True)
            rsi_v = tulipy.rsi(closes, period=ctx.tentacle.trading_config["period"])
            delta = len(closes) - len(rsi_v)
            # Populate entries with timestamps of candles where RSI is
            # bellow the "rsi_value_buy_threshold" configuration.
            run_data["entries"] = {
                times[index + delta]
                for index, rsi_val in enumerate(rsi_v)
                if rsi_val < ctx.tentacle.trading_config["rsi_value_buy_threshold"]
            }
            await obs.plot_indicator(ctx, "RSI", times[delta:], rsi_v, run_data["entries"])
        if obs.current_live_time(ctx) in run_data["entries"]:
            # Uses pre-computed entries times to enter positions when relevant.
            # Also, instantly set take profits and stop losses.
            # Position exists could also be set separately.
            await obs.market(ctx, "buy", amount="10%", stop_loss_offset="-15%", take_profit_offset="25%")

    # Configuration that will be passed to each run.
    # It will be accessible under "ctx.tentacle.trading_config".
    config = {
        "period": 10,
        "rsi_value_buy_threshold": 28,
    }

    # Read and cache candle data to make subsequent backtesting runs faster.
    data = await obs.get_data("BTC/USDT", "1d", start_timestamp=1505606400)
    run_data = {
        "entries": None,
    }
    # Run a backtest using the above data, strategy and configuration.
    res = await obs.run(data, strategy, config)
    print(res.describe())
    # Generate and open report including indicators plots 
    await res.plot(show=True)
    # Stop data to release local databases.
    await data.stop()


# Call the execution of the script inside "asyncio.run" as
# OctoBot-Script runs using the python asyncio framework.
asyncio.run(rsi_test())

Generated report

report-p1

Join the community

We recently created a telegram channel dedicated to OctoBot Script.

Telegram News

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

OctoBot-Script-0.0.26.tar.gz (36.5 kB view details)

Uploaded Source

File details

Details for the file OctoBot-Script-0.0.26.tar.gz.

File metadata

  • Download URL: OctoBot-Script-0.0.26.tar.gz
  • Upload date:
  • Size: 36.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.17

File hashes

Hashes for OctoBot-Script-0.0.26.tar.gz
Algorithm Hash digest
SHA256 f09bd4ff8dc94a5d19b262ec7f96baa0df7755ab61b19b582b1a4175e2c8a6e0
MD5 b5b7925ad2aee8b07f9ab9aac2e7cfd5
BLAKE2b-256 b494b1ca5c9010bc7e6c587149cd0e3f9cb53cc9ec8e1d3bd6821bd432fa020e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page