In [1]:
import pandas as pd
import oandapyV20
import oandapyV20.endpoints.orders as orders
import configparser
In [2]:
config = configparser.ConfigParser()
config.read('../config/config_v20.ini')
accountID = config['oanda']['account_id']
access_token = config['oanda']['api_key']
In [3]:
client = oandapyV20.API(access_token=access_token)
In [4]:
data = {
"order": {
"price": "1.2",
"stopLossOnFill": {
"timeInForce": "GTC",
"price": "1.22"
},
"timeInForce": "GTC",
"instrument": "EUR_USD",
"units": "-100",
"type": "LIMIT",
"positionFill": "DEFAULT"
}
}
In [5]:
r = orders.OrderCreate(accountID, data=data)
In [6]:
client.request(r)
Out[6]:
In [7]:
print(r.response)
In [8]:
pd.Series(r.response['orderCreateTransaction'])
Out[8]:
In [9]:
r = orders.OrderList(accountID)
In [10]:
client.request(r)
Out[10]:
In [11]:
print(r.response)
In [12]:
pd.Series(r.response['orders'][0])
Out[12]:
In [13]:
r = orders.OrdersPending(accountID)
In [14]:
client.request(r)
Out[14]:
In [15]:
print(r.response)
In [16]:
res = r.response['orders']
In [17]:
print(res)
In [18]:
last_order_id = res[0]['id']
In [19]:
pd.Series(r.response['orders'][0])
Out[19]:
In [20]:
r = orders.OrderDetails(accountID=accountID, orderID=last_order_id)
In [21]:
client.request(r)
Out[21]:
In [22]:
data = {
"order": {
"units": "-500000",
"instrument": "EUR_USD",
"price": "1.25000",
"type": "LIMIT"
}
}
In [23]:
r = orders.OrderReplace(accountID=accountID, orderID=last_order_id, data=data)
In [24]:
client.request(r)
Out[24]:
In [25]:
print(r.response)
In [26]:
req_id = r.response['lastTransactionID']
In [27]:
r = orders.OrderCancel(accountID=accountID, orderID=req_id)
In [28]:
client.request(r)
Out[28]:
In [29]:
print(r.response)
In [30]:
last_order_id
Out[30]:
In [31]:
data = {"order":
{"units": "100",
"instrument": "GBP_USD",
"timeInForce": "FOK",
"type": "MARKET",
"positionFill": "DEFAULT"
},
}
In [32]:
r = orders.OrderCreate(accountID, data=data)
In [33]:
client.request(r)
Out[33]:
In [34]:
print(r.response)
In [35]:
pd.Series(r.response['orderCreateTransaction'])
Out[35]:
In [36]:
pd.Series(r.response['orderFillTransaction'])
Out[36]: