超簡単PythonでFX自動売買(OANDA BOT)
PythonでOANDA REST API利用して超簡単にFX自動売買OANDA BOT
1. OANDAへ行ってデモ口座作成
無料で、証拠金300万円スタート
2. API アクセストークン発行
3. ツールインストール
$ pip install oanda-bot
4. ファイル作成
bot.py
from oanda_bot import Bot
class MyBot(Bot):
def strategy(self):
fast_ma = self.sma(period=5)
slow_ma = self.sma(period=25)
# 5日と25日移動平均ゴールデンクロスで買い
self.sell_exit = self.buy_entry = (fast_ma > slow_ma) & (
fast_ma.shift() <= slow_ma.shift()
)
# 5日と25日移動平均デッドクロスで売り
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()
5. 実行
$ python oanda.py
以上、超簡単!
実行前にバックテストも
backtest.py
from oanda_bot import Bot
class MyBot(Bot):
def strategy(self):
fast_ma = self.sma(period=5)
slow_ma = self.sma(period=25)
# 5日と25日移動平均ゴールデンクロスで買い
self.sell_exit = self.buy_entry = (fast_ma > slow_ma) & (
fast_ma.shift() <= slow_ma.shift()
)
# 5日と25日移動平均デッドクロスで売り
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()
詳細は以下を参照