All Projects → 10mohi6 → oanda-bot-python

10mohi6 / oanda-bot-python

Licence: MIT License
oanda-bot is a python library for automated trading bot with oanda rest api on Python 3.6 and above.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to oanda-bot-python

Devalpha Node
A stream-based approach to algorithmic trading and backtesting in Node.js
Stars: ✭ 217 (+985%)
Mutual labels:  trading, backtest
bitmex-backtest-python
bitmex-backtest is a python library for backtest with bitmex fx trade rest api on Python 3.7 and above.
Stars: ✭ 13 (-35%)
Mutual labels:  fx, backtest
Trading Backtest
A stock backtesting engine written in modern Java. And a pairs trading (cointegration) strategy implementation using a bayesian kalman filter model
Stars: ✭ 247 (+1135%)
Mutual labels:  trading, backtest
Crex
A Golang cryptocurrency trading API & Library. Support Binance, BitMEX, Deribit, Bybit, Huobi DM, OKEX Futures and more.
Stars: ✭ 166 (+730%)
Mutual labels:  trading, backtest
backtrader template
Basic template for managing Backtrader backtests.
Stars: ✭ 131 (+555%)
Mutual labels:  trading, backtest
Trading Server
A multi-asset, multi-strategy, event-driven trade execution and management platform for running many algorithms/bots at many venues simultaneously with unified risk management and reporting. Uses MongoDB for storage and Telegram for user notifications/trade consent.
Stars: ✭ 191 (+855%)
Mutual labels:  trading, backtest
Algotrading
Algorithmic trading framework for cryptocurrencies.
Stars: ✭ 249 (+1145%)
Mutual labels:  trading, backtest
Rqalpha
A extendable, replaceable Python algorithmic backtest && trading framework supporting multiple securities
Stars: ✭ 4,425 (+22025%)
Mutual labels:  trading, backtest
Heptet
Pair Trading - Reinforcement Learning - with Oanda Trading API
Stars: ✭ 51 (+155%)
Mutual labels:  trading, oanda
binance-downloader
Python tool to download Binance Candlestick (k-line) data from REST API
Stars: ✭ 44 (+120%)
Mutual labels:  trading, backtest
Strategems.jl
Quantitative systematic trading strategy development and backtesting in Julia
Stars: ✭ 106 (+430%)
Mutual labels:  trading, backtest
mt4-mql
MetaTrader MQL4 framework
Stars: ✭ 205 (+925%)
Mutual labels:  trading, backtest
Sibyl
Platform for backtesting and live-trading intraday Stock/ETF/ELW using recurrent neural networks
Stars: ✭ 32 (+60%)
Mutual labels:  trading, backtest
Gekko Backtesttool
Batch backtest, import and strategy params optimalization for Gekko Trading Bot. With one command you will run any number of backtests.
Stars: ✭ 203 (+915%)
Mutual labels:  trading, backtest
Tradinggym
Trading and Backtesting environment for training reinforcement learning agent or simple rule base algo.
Stars: ✭ 813 (+3965%)
Mutual labels:  trading, backtest
Starquant
a light-weighted, integrated trading/backtesting system/platform(综合量化交易回测系统/平台)
Stars: ✭ 250 (+1150%)
Mutual labels:  trading, backtest
Optopsy
A nimble options backtesting library for Python
Stars: ✭ 373 (+1765%)
Mutual labels:  trading, backtest
mt4-expander
DLL extension for the MetaTrader MQL4 framework
Stars: ✭ 25 (+25%)
Mutual labels:  trading, backtest
presso
Event-driven backtest/realtime quantitative trading system.
Stars: ✭ 59 (+195%)
Mutual labels:  trading, backtest
AutoTrader
A Python-based development platform for automated trading systems - from backtesting to optimisation to livetrading.
Stars: ✭ 227 (+1035%)
Mutual labels:  trading, oanda

oanda-bot

PyPI License: MIT codecov Build Status PyPI - Python Version Downloads

oanda-bot is a python library for automated trading bot with oanda rest api on Python 3.6 and above.

Installation

$ pip install oanda-bot

Usage

basic run

from oanda_bot import Bot

class MyBot(Bot):
    def strategy(self):
        fast_ma = self.sma(period=5)
        slow_ma = self.sma(period=25)
        # golden cross
        self.sell_exit = self.buy_entry = (fast_ma > slow_ma) & (
            fast_ma.shift() <= slow_ma.shift()
        )
        # dead cross
        self.buy_exit = self.sell_entry = (fast_ma < slow_ma) & (
            fast_ma.shift() >= slow_ma.shift()
        )

MyBot(
    account_id='<your practice account id>',
    access_token='<your practice access token>',
).run()

basic backtest

from oanda_bot import Bot

class MyBot(Bot):
    def strategy(self):
        fast_ma = self.sma(period=5)
        slow_ma = self.sma(period=25)
        # golden cross
        self.sell_exit = self.buy_entry = (fast_ma > slow_ma) & (
            fast_ma.shift() <= slow_ma.shift()
        )
        # dead cross
        self.buy_exit = self.sell_entry = (fast_ma < slow_ma) & (
            fast_ma.shift() >= slow_ma.shift()
        )

MyBot(
    account_id='<your practice account id>',
    access_token='<your practice access token>',
).backtest()

basic report

from oanda_bot import Bot

Bot(
    account_id='<your practice account id>',
    access_token='<your practice access token>',
).report()

advanced run

from oanda_bot import Bot

class MyBot(Bot):
    def strategy(self):
        rsi = self.rsi(period=10)
        ema = self.ema(period=20)
        lower = ema - (ema * 0.001)
        upper = ema + (ema * 0.001)
        self.buy_entry = (rsi < 30) & (self.df.C < lower)
        self.sell_entry = (rsi > 70) & (self.df.C > upper)
        self.sell_exit = ema > self.df.C
        self.buy_exit = ema < self.df.C
        self.units = 1000 # currency unit (default=10000)
        self.take_profit = 50 # take profit pips (default=0 take profit none)
        self.stop_loss = 20 # stop loss pips (default=0 stop loss none)

MyBot(
    account_id='<your practice account id>',
    access_token='<your practice access token>',
    # trading environment (default=practice)
    environment='practice',
    # trading currency (default=EUR_USD)
    instrument='USD_JPY',
    # 1 minute candlesticks (default=D)
    granularity='M1',
    # trading time (default=Bot.SUMMER_TIME)
    trading_time=Bot.WINTER_TIME,
    # Slack notification when an error occurs
    slack_webhook_url='<your slack webhook url>',
    # Line notification when an error occurs
    line_notify_token='<your line notify token>',
    # Discord notification when an error occurs
    discord_webhook_url='<your discord webhook url>',
).run()

advanced backtest

from oanda_bot import Bot

class MyBot(Bot):
    def strategy(self):
        rsi = self.rsi(period=10)
        ema = self.ema(period=20)
        lower = ema - (ema * 0.001)
        upper = ema + (ema * 0.001)
        self.buy_entry = (rsi < 30) & (self.df.C < lower)
        self.sell_entry = (rsi > 70) & (self.df.C > upper)
        self.sell_exit = ema > self.df.C
        self.buy_exit = ema < self.df.C
        self.units = 1000 # currency unit (default=10000)
        self.take_profit = 50 # take profit pips (default=0 take profit none)
        self.stop_loss = 20 # stop loss pips (default=0 stop loss none)

MyBot(
    account_id='<your practice account id>',
    access_token='<your practice access token>',
    instrument='USD_JPY',
    granularity='S15', # 15 second candlestick
).backtest(from_date="2020-7-7", to_date="2020-7-13", filename="backtest.png")
total profit        3910.000
total trades         374.000
win rate              59.091
profit factor          1.115
maximum drawdown    4220.000
recovery factor        0.927
riskreward ratio       0.717
sharpe ratio           0.039
average return         9.787
stop loss              0.000
take profit            0.000

backtest.png

advanced report

from oanda_bot import Bot

Bot(
    account_id='<your practice account id>',
    access_token='<your practice access token>',
    instrument='USD_JPY',
    granularity='S15', # 15 second candlestick
).report(filename="report.png", days=-7) # from 7 days ago to now
total profit        -4960.000
total trades          447.000
win rate               59.284
profit factor          -0.887
maximum drawdown    10541.637
recovery factor        -0.471
riskreward ratio       -0.609
sharpe ratio           -0.043
average return        -10.319

report.png

live run

from oanda_bot import Bot

class MyBot(Bot):
    def atr(self, *, period: int = 14, price: str = "C"):
        a = (self.df.H - self.df.L).abs()
        b = (self.df.H - self.df[price].shift()).abs()
        c = (self.df.L - self.df[price].shift()).abs()

        df = pd.concat([a, b, c], axis=1).max(axis=1)
        return df.ewm(span=period).mean()

    def strategy(self):
        rsi = self.rsi(period=10)
        ema = self.ema(period=20)
        atr = self.atr(period=20)
        lower = ema - atr
        upper = ema + atr
        self.buy_entry = (rsi < 30) & (self.df.C < lower)
        self.sell_entry = (rsi > 70) & (self.df.C > upper)
        self.sell_exit = ema > self.df.C
        self.buy_exit = ema < self.df.C
        self.units = 1000

MyBot(
    account_id='<your live account id>',
    access_token='<your live access token>',
    environment='live',
    instrument='EUR_GBP',
    granularity='H12', # 12 hour candlesticks
    trading_time=Bot.WINTER_TIME,
    slack_webhook_url='<your slack webhook url>',
).run()

Supported indicators

  • Simple Moving Average 'sma'
  • Exponential Moving Average 'ema'
  • Moving Average Convergence Divergence 'macd'
  • Relative Strenght Index 'rsi'
  • Bollinger Bands 'bbands'
  • Market Momentum 'mom'
  • Stochastic Oscillator 'stoch'
  • Awesome Oscillator 'ao'

Getting started

For help getting started with OANDA REST API, view our online documentation.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].