{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Entry Orders"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This section covers **entry orders**."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import fxcmpy\n",
"import pandas as pd\n",
"import datetime as dt\n",
"con = fxcmpy.fxcmpy(config_file='fxcm.cfg')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Existing Orders"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"After connecting the FXCM Server, `fxcmpy` collects all existing orders. `list` or `DataFrame` object of the existing orders is returned by the `con.get_orders()` method."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
"
\n",
"
"
],
"text/plain": [
"Empty DataFrame\n",
"Columns: []\n",
"Index: []"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"con.get_orders().T # returns DataFrame by default"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"con.get_orders(kind='list') # returns a list"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Each order has a unique `order_id`, these `ids` are returned by `con.get_order_ids()`. "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"con.get_order_ids()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Placing Entry Orders"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Entry orders are placed via the `con.create_entry_order()` method. For a detailed description of the parameters refer to the FXCM API documentation."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"order = con.create_entry_order(symbol='USD/JPY', is_buy=True, \n",
" amount=300, limit=112, \n",
" is_in_pips = False,\n",
" time_in_force='GTC', rate=110, \n",
" stop=None, trailing_step=None)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 0 | \n",
"
\n",
" \n",
" \n",
" \n",
" accountId | \n",
" 2815291 | \n",
"
\n",
" \n",
" accountName | \n",
" 02815291 | \n",
"
\n",
" \n",
" amountK | \n",
" 300 | \n",
"
\n",
" \n",
" buy | \n",
" 110 | \n",
"
\n",
" \n",
" currency | \n",
" USD/JPY | \n",
"
\n",
" \n",
" currencyPoint | \n",
" 27.2846 | \n",
"
\n",
" \n",
" expireDate | \n",
" | \n",
"
\n",
" \n",
" isBuy | \n",
" True | \n",
"
\n",
" \n",
" isELSOrder | \n",
" False | \n",
"
\n",
" \n",
" isEntryOrder | \n",
" True | \n",
"
\n",
" \n",
" isLimitOrder | \n",
" False | \n",
"
\n",
" \n",
" isNetQuantity | \n",
" False | \n",
"
\n",
" \n",
" isStopOrder | \n",
" True | \n",
"
\n",
" \n",
" limit | \n",
" 112 | \n",
"
\n",
" \n",
" limitPegBaseType | \n",
" -1 | \n",
"
\n",
" \n",
" limitRate | \n",
" 112 | \n",
"
\n",
" \n",
" ocoBulkId | \n",
" 0 | \n",
"
\n",
" \n",
" orderId | \n",
" 404808930 | \n",
"
\n",
" \n",
" range | \n",
" 0 | \n",
"
\n",
" \n",
" ratePrecision | \n",
" 3 | \n",
"
\n",
" \n",
" sell | \n",
" 0 | \n",
"
\n",
" \n",
" status | \n",
" 1 | \n",
"
\n",
" \n",
" stop | \n",
" 0 | \n",
"
\n",
" \n",
" stopMove | \n",
" 0 | \n",
"
\n",
" \n",
" stopPegBaseType | \n",
" -1 | \n",
"
\n",
" \n",
" stopRate | \n",
" 0 | \n",
"
\n",
" \n",
" t | \n",
" 3 | \n",
"
\n",
" \n",
" time | \n",
" 06072018134424598 | \n",
"
\n",
" \n",
" timeInForce | \n",
" GTC | \n",
"
\n",
" \n",
" tradeId | \n",
" 178167932 | \n",
"
\n",
" \n",
" type | \n",
" SE | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" 0\n",
"accountId 2815291\n",
"accountName 02815291\n",
"amountK 300\n",
"buy 110\n",
"currency USD/JPY\n",
"currencyPoint 27.2846\n",
"expireDate \n",
"isBuy True\n",
"isELSOrder False\n",
"isEntryOrder True\n",
"isLimitOrder False\n",
"isNetQuantity False\n",
"isStopOrder True\n",
"limit 112\n",
"limitPegBaseType -1\n",
"limitRate 112\n",
"ocoBulkId 0\n",
"orderId 404808930\n",
"range 0\n",
"ratePrecision 3\n",
"sell 0\n",
"status 1\n",
"stop 0\n",
"stopMove 0\n",
"stopPegBaseType -1\n",
"stopRate 0\n",
"t 3\n",
"time 06072018134424598\n",
"timeInForce GTC\n",
"tradeId 178167932\n",
"type SE"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"con.get_orders().T"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Changing Orders "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are two methods to change entry orders:\n",
" \n",
"* `change_order_stop_limit()` to change an order's stop or limit rate.\n",
"* `change_order()` to change an order's amount, rate, order range and/or trailing step."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"order_id = con.get_order_ids()[-1]"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"404808930"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"order_id"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"con.change_order_stop_limit(order_id=order_id, is_stop_in_pips=True, \n",
" is_limit_in_pips=True, limit=110, stop=-1)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"con.change_order(order_id=order_id, amount=500, rate=114)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The order is changed accordingly."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 0 | \n",
"
\n",
" \n",
" \n",
" \n",
" accountId | \n",
" 2815291 | \n",
"
\n",
" \n",
" accountName | \n",
" 02815291 | \n",
"
\n",
" \n",
" amountK | \n",
" 500 | \n",
"
\n",
" \n",
" buy | \n",
" 114 | \n",
"
\n",
" \n",
" currency | \n",
" USD/JPY | \n",
"
\n",
" \n",
" currencyPoint | \n",
" 45.474 | \n",
"
\n",
" \n",
" expireDate | \n",
" | \n",
"
\n",
" \n",
" isBuy | \n",
" True | \n",
"
\n",
" \n",
" isELSOrder | \n",
" False | \n",
"
\n",
" \n",
" isEntryOrder | \n",
" True | \n",
"
\n",
" \n",
" isLimitOrder | \n",
" False | \n",
"
\n",
" \n",
" isNetQuantity | \n",
" False | \n",
"
\n",
" \n",
" isStopOrder | \n",
" True | \n",
"
\n",
" \n",
" limit | \n",
" 110 | \n",
"
\n",
" \n",
" limitPegBaseType | \n",
" 0 | \n",
"
\n",
" \n",
" limitRate | \n",
" 115.1 | \n",
"
\n",
" \n",
" ocoBulkId | \n",
" 0 | \n",
"
\n",
" \n",
" orderId | \n",
" 404808930 | \n",
"
\n",
" \n",
" range | \n",
" 0 | \n",
"
\n",
" \n",
" ratePrecision | \n",
" 3 | \n",
"
\n",
" \n",
" sell | \n",
" 0 | \n",
"
\n",
" \n",
" status | \n",
" 1 | \n",
"
\n",
" \n",
" stop | \n",
" -1 | \n",
"
\n",
" \n",
" stopMove | \n",
" 0 | \n",
"
\n",
" \n",
" stopPegBaseType | \n",
" 1 | \n",
"
\n",
" \n",
" stopRate | \n",
" 113.968 | \n",
"
\n",
" \n",
" t | \n",
" 3 | \n",
"
\n",
" \n",
" time | \n",
" 06072018134441711 | \n",
"
\n",
" \n",
" timeInForce | \n",
" GTC | \n",
"
\n",
" \n",
" tradeId | \n",
" 178167932 | \n",
"
\n",
" \n",
" type | \n",
" SE | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" 0\n",
"accountId 2815291\n",
"accountName 02815291\n",
"amountK 500\n",
"buy 114\n",
"currency USD/JPY\n",
"currencyPoint 45.474\n",
"expireDate \n",
"isBuy True\n",
"isELSOrder False\n",
"isEntryOrder True\n",
"isLimitOrder False\n",
"isNetQuantity False\n",
"isStopOrder True\n",
"limit 110\n",
"limitPegBaseType 0\n",
"limitRate 115.1\n",
"ocoBulkId 0\n",
"orderId 404808930\n",
"range 0\n",
"ratePrecision 3\n",
"sell 0\n",
"status 1\n",
"stop -1\n",
"stopMove 0\n",
"stopPegBaseType 1\n",
"stopRate 113.968\n",
"t 3\n",
"time 06072018134441711\n",
"timeInForce GTC\n",
"tradeId 178167932\n",
"type SE"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"con.get_orders().T"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Deleting Orders"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Orders can be **deleted** through the method `con.delete_orders()`."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[404808930]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"con.get_order_ids()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"con.delete_order(order_id)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
"
\n",
"
"
],
"text/plain": [
"Empty DataFrame\n",
"Columns: []\n",
"Index: []"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"con.get_orders().T"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Deleted or executed orders of the current session are stored in the attribute `old_orders` as an `fxcm_order` object."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{404808930: }"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"con.old_orders"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"con.close()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}