In [1]:
from datetime import datetime, timedelta
import pandas as pd
import oandapy
import configparser
config = configparser.ConfigParser()
config.read('../config/config_v1.ini')
account_id = config['oanda']['account_id']
api_key = config['oanda']['api_key']
oanda = oandapy.API(environment="practice",
access_token=api_key)
In [2]:
trade_expire = datetime.now() + timedelta(days=1)
trade_expire = trade_expire.isoformat("T") + "Z"
fx_list = ["AUD_USD", "NZD_USD", "USD_JPY"]
for oo in fx_list:
response = oanda.create_order(account_id,
instrument = oo,
units=1000,
side="buy",
type="market",
expiry=trade_expire)
In [3]:
response = oanda.get_positions(account_id)
print(response)
In [4]:
pd.DataFrame(response['positions'])
Out[4]:
In [5]:
response = oanda.get_position(account_id,
instrument="USD_JPY")
print(response)
In [6]:
response = oanda.close_position(account_id,
instrument="USD_JPY")
print(response)
In [7]:
response = oanda.get_positions(account_id)
pd.DataFrame(response['positions'])
Out[7]: