{ "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0
accountId2815291
accountName02815291
amountK300
buy110
currencyUSD/JPY
currencyPoint27.2846
expireDate
isBuyTrue
isELSOrderFalse
isEntryOrderTrue
isLimitOrderFalse
isNetQuantityFalse
isStopOrderTrue
limit112
limitPegBaseType-1
limitRate112
ocoBulkId0
orderId404808930
range0
ratePrecision3
sell0
status1
stop0
stopMove0
stopPegBaseType-1
stopRate0
t3
time06072018134424598
timeInForceGTC
tradeId178167932
typeSE
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0
accountId2815291
accountName02815291
amountK500
buy114
currencyUSD/JPY
currencyPoint45.474
expireDate
isBuyTrue
isELSOrderFalse
isEntryOrderTrue
isLimitOrderFalse
isNetQuantityFalse
isStopOrderTrue
limit110
limitPegBaseType0
limitRate115.1
ocoBulkId0
orderId404808930
range0
ratePrecision3
sell0
status1
stop-1
stopMove0
stopPegBaseType1
stopRate113.968
t3
time06072018134441711
timeInForceGTC
tradeId178167932
typeSE
\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 }