Package: oanda-bot
oanda-botoanda-bot is a python library for automated trading bot with oanda rest api on Python 3.6 and above.Installation$ pip install oanda-botUsagebasic runfromoanda_botimportBotclassMyBot(Bot):defstrategy(self):fast_ma=self.sma(period=5)slow_ma=self.sma(period=25)# golden crossself.sell_exit=self.buy_entry=(fast_ma>slow_ma)&(fast_ma.shift()<=slow_ma.shift())# dead crossself.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 backtestfromoanda_botimportBotclassMyBot(Bot):defstrategy(self):fast_ma=self.sma(period=5)slow_ma=self.sma(period=25)# golden crossself.sell_exit=self.buy_entry=(fast_ma>slow_ma)&(fast_ma.shift()<=slow_ma.shift())# dead crossself.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 reportfromoanda_botimportBotBot(account_id='<your practice account id>',access_token='<your practice access token>',).report()advanced runfromoanda_botimportBotclassMyBot(Bot):defstrategy(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.Cself.buy_exit=ema<self.df.Cself.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 occursslack_webhook_url='<your slack webhook url>',# Line notification when an error occursline_notify_token='<your line notify token>',# Discord notification when an error occursdiscord_webhook_url='<your discord webhook url>',).run()advanced backtestfromoanda_botimportBotclassMyBot(Bot):defstrategy(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.Cself.buy_exit=ema<self.df.Cself.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")totalprofit3910.000totaltrades374.000winrate59.091profitfactor1.115maximumdrawdown4220.000recoveryfactor0.927riskrewardratio0.717sharperatio0.039averagereturn9.787stoploss0.000takeprofit0.000advanced reportfromoanda_botimportBotBot(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 nowtotalprofit-4960.000totaltrades447.000winrate59.284profitfactor-0.887maximumdrawdown10541.637recoveryfactor-0.471riskrewardratio-0.609sharperatio-0.043averagereturn-10.319live runfromoanda_botimportBotclassMyBot(Bot):defatr(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)returndf.ewm(span=period).mean()defstrategy(self):rsi=self.rsi(period=10)ema=self.ema(period=20)atr=self.atr(period=20)lower=ema-atrupper=ema+atrself.buy_entry=(rsi<30)&(self.df.C<lower)self.sell_entry=(rsi>70)&(self.df.C>upper)self.sell_exit=ema>self.df.Cself.buy_exit=ema<self.df.Cself.units=1000MyBot(account_id='<your live account id>',access_token='<your live access token>',environment='live',instrument='EUR_GBP',granularity='H12',# 12 hour candlestickstrading_time=Bot.WINTER_TIME,slack_webhook_url='<your slack webhook url>',).run()Supported indicatorsSimple 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 startedFor help getting started with OANDA REST API, view our onlinedocumentation.ContributingFork itCreate your feature branch (git checkout -b my-new-feature)Commit your changes (git commit -am 'Add some feature')Push to the branch (git push origin my-new-feature)Create new Pull Request