{"id":24496850,"url":"https://github.com/10mohi6/oanda-bot-python","last_synced_at":"2025-04-14T04:14:21.141Z","repository":{"id":37675396,"uuid":"274152476","full_name":"10mohi6/oanda-bot-python","owner":"10mohi6","description":"oanda-bot is a python library for automated trading bot with oanda rest api on Python 3.6 and above.","archived":false,"fork":false,"pushed_at":"2022-12-08T07:45:17.000Z","size":87,"stargazers_count":35,"open_issues_count":9,"forks_count":18,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-14T04:14:15.509Z","etag":null,"topics":["api","automated","backtest","bot","fx","oanda","python","trading"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/10mohi6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-22T13:59:27.000Z","updated_at":"2025-03-05T02:28:28.000Z","dependencies_parsed_at":"2022-09-05T05:01:06.246Z","dependency_job_id":null,"html_url":"https://github.com/10mohi6/oanda-bot-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10mohi6%2Foanda-bot-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10mohi6%2Foanda-bot-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10mohi6%2Foanda-bot-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10mohi6%2Foanda-bot-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/10mohi6","download_url":"https://codeload.github.com/10mohi6/oanda-bot-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248819408,"owners_count":21166477,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","automated","backtest","bot","fx","oanda","python","trading"],"created_at":"2025-01-21T21:19:06.861Z","updated_at":"2025-04-14T04:14:21.121Z","avatar_url":"https://github.com/10mohi6.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# oanda-bot\n\n[![PyPI](https://img.shields.io/pypi/v/oanda-bot)](https://pypi.org/project/oanda-bot/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![codecov](https://codecov.io/gh/10mohi6/oanda-bot-python/branch/master/graph/badge.svg)](https://codecov.io/gh/10mohi6/oanda-bot-python)\n[![Build Status](https://travis-ci.com/10mohi6/oanda-bot-python.svg?branch=master)](https://travis-ci.com/10mohi6/oanda-bot-python)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/oanda-bot)](https://pypi.org/project/oanda-bot/)\n[![Downloads](https://pepy.tech/badge/oanda-bot)](https://pepy.tech/project/oanda-bot)\n\noanda-bot is a python library for automated trading bot with oanda rest api on Python 3.6 and above.\n\n\n## Installation\n\n    $ pip install oanda-bot\n\n## Usage\n\n### basic run\n```python\nfrom oanda_bot import Bot\n\nclass MyBot(Bot):\n    def strategy(self):\n        fast_ma = self.sma(period=5)\n        slow_ma = self.sma(period=25)\n        # golden cross\n        self.sell_exit = self.buy_entry = (fast_ma \u003e slow_ma) \u0026 (\n            fast_ma.shift() \u003c= slow_ma.shift()\n        )\n        # dead cross\n        self.buy_exit = self.sell_entry = (fast_ma \u003c slow_ma) \u0026 (\n            fast_ma.shift() \u003e= slow_ma.shift()\n        )\n\nMyBot(\n    account_id='\u003cyour practice account id\u003e',\n    access_token='\u003cyour practice access token\u003e',\n).run()\n```\n\n### basic backtest\n```python\nfrom oanda_bot import Bot\n\nclass MyBot(Bot):\n    def strategy(self):\n        fast_ma = self.sma(period=5)\n        slow_ma = self.sma(period=25)\n        # golden cross\n        self.sell_exit = self.buy_entry = (fast_ma \u003e slow_ma) \u0026 (\n            fast_ma.shift() \u003c= slow_ma.shift()\n        )\n        # dead cross\n        self.buy_exit = self.sell_entry = (fast_ma \u003c slow_ma) \u0026 (\n            fast_ma.shift() \u003e= slow_ma.shift()\n        )\n\nMyBot(\n    account_id='\u003cyour practice account id\u003e',\n    access_token='\u003cyour practice access token\u003e',\n).backtest()\n```\n\n### basic report\n```python\nfrom oanda_bot import Bot\n\nBot(\n    account_id='\u003cyour practice account id\u003e',\n    access_token='\u003cyour practice access token\u003e',\n).report()\n```\n\n### advanced run\n```python\nfrom oanda_bot import Bot\n\nclass MyBot(Bot):\n    def strategy(self):\n        rsi = self.rsi(period=10)\n        ema = self.ema(period=20)\n        lower = ema - (ema * 0.001)\n        upper = ema + (ema * 0.001)\n        self.buy_entry = (rsi \u003c 30) \u0026 (self.df.C \u003c lower)\n        self.sell_entry = (rsi \u003e 70) \u0026 (self.df.C \u003e upper)\n        self.sell_exit = ema \u003e self.df.C\n        self.buy_exit = ema \u003c self.df.C\n        self.units = 1000 # currency unit (default=10000)\n        self.take_profit = 50 # take profit pips (default=0 take profit none)\n        self.stop_loss = 20 # stop loss pips (default=0 stop loss none)\n\nMyBot(\n    account_id='\u003cyour practice account id\u003e',\n    access_token='\u003cyour practice access token\u003e',\n    # trading environment (default=practice)\n    environment='practice',\n    # trading currency (default=EUR_USD)\n    instrument='USD_JPY',\n    # 1 minute candlesticks (default=D)\n    granularity='M1',\n    # trading time (default=Bot.SUMMER_TIME)\n    trading_time=Bot.WINTER_TIME,\n    # Slack notification when an error occurs\n    slack_webhook_url='\u003cyour slack webhook url\u003e',\n    # Line notification when an error occurs\n    line_notify_token='\u003cyour line notify token\u003e',\n    # Discord notification when an error occurs\n    discord_webhook_url='\u003cyour discord webhook url\u003e',\n).run()\n```\n\n### advanced backtest\n```python\nfrom oanda_bot import Bot\n\nclass MyBot(Bot):\n    def strategy(self):\n        rsi = self.rsi(period=10)\n        ema = self.ema(period=20)\n        lower = ema - (ema * 0.001)\n        upper = ema + (ema * 0.001)\n        self.buy_entry = (rsi \u003c 30) \u0026 (self.df.C \u003c lower)\n        self.sell_entry = (rsi \u003e 70) \u0026 (self.df.C \u003e upper)\n        self.sell_exit = ema \u003e self.df.C\n        self.buy_exit = ema \u003c self.df.C\n        self.units = 1000 # currency unit (default=10000)\n        self.take_profit = 50 # take profit pips (default=0 take profit none)\n        self.stop_loss = 20 # stop loss pips (default=0 stop loss none)\n\nMyBot(\n    account_id='\u003cyour practice account id\u003e',\n    access_token='\u003cyour practice access token\u003e',\n    instrument='USD_JPY',\n    granularity='S15', # 15 second candlestick\n).backtest(from_date=\"2020-7-7\", to_date=\"2020-7-13\", filename=\"backtest.png\")\n```\n```python\ntotal profit        3910.000\ntotal trades         374.000\nwin rate              59.091\nprofit factor          1.115\nmaximum drawdown    4220.000\nrecovery factor        0.927\nriskreward ratio       0.717\nsharpe ratio           0.039\naverage return         9.787\nstop loss              0.000\ntake profit            0.000\n```\n![backtest.png](https://raw.githubusercontent.com/10mohi6/oanda-bot-python/master/tests/backtest.png)\n\n### advanced report\n```python\nfrom oanda_bot import Bot\n\nBot(\n    account_id='\u003cyour practice account id\u003e',\n    access_token='\u003cyour practice access token\u003e',\n    instrument='USD_JPY',\n    granularity='S15', # 15 second candlestick\n).report(filename=\"report.png\", days=-7) # from 7 days ago to now\n```\n```python\ntotal profit        -4960.000\ntotal trades          447.000\nwin rate               59.284\nprofit factor          -0.887\nmaximum drawdown    10541.637\nrecovery factor        -0.471\nriskreward ratio       -0.609\nsharpe ratio           -0.043\naverage return        -10.319\n```\n![report.png](https://raw.githubusercontent.com/10mohi6/oanda-bot-python/master/tests/report.png)\n\n### live run\n```python\nfrom oanda_bot import Bot\n\nclass MyBot(Bot):\n    def atr(self, *, period: int = 14, price: str = \"C\"):\n        a = (self.df.H - self.df.L).abs()\n        b = (self.df.H - self.df[price].shift()).abs()\n        c = (self.df.L - self.df[price].shift()).abs()\n\n        df = pd.concat([a, b, c], axis=1).max(axis=1)\n        return df.ewm(span=period).mean()\n\n    def strategy(self):\n        rsi = self.rsi(period=10)\n        ema = self.ema(period=20)\n        atr = self.atr(period=20)\n        lower = ema - atr\n        upper = ema + atr\n        self.buy_entry = (rsi \u003c 30) \u0026 (self.df.C \u003c lower)\n        self.sell_entry = (rsi \u003e 70) \u0026 (self.df.C \u003e upper)\n        self.sell_exit = ema \u003e self.df.C\n        self.buy_exit = ema \u003c self.df.C\n        self.units = 1000\n\nMyBot(\n    account_id='\u003cyour live account id\u003e',\n    access_token='\u003cyour live access token\u003e',\n    environment='live',\n    instrument='EUR_GBP',\n    granularity='H12', # 12 hour candlesticks\n    trading_time=Bot.WINTER_TIME,\n    slack_webhook_url='\u003cyour slack webhook url\u003e',\n).run()\n```\n\n## Supported indicators\n- Simple Moving Average 'sma'\n- Exponential Moving Average 'ema'\n- Moving Average Convergence Divergence 'macd'\n- Relative Strenght Index 'rsi'\n- Bollinger Bands 'bbands'\n- Market Momentum 'mom'\n- Stochastic Oscillator 'stoch'\n- Awesome Oscillator 'ao'\n\n\n## Getting started\n\nFor help getting started with OANDA REST API, view our online [documentation](https://developer.oanda.com/rest-live-v20/introduction/).\n\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F10mohi6%2Foanda-bot-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F10mohi6%2Foanda-bot-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F10mohi6%2Foanda-bot-python/lists"}