{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# The `fxcmpy_order` Class\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This section introduces the `fxcmpy_order` class which is created by different operations." ] }, { "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": [ "The methods `fxcmpy.create_entry_order()`, `fxcmpy.create_market_sell_order()`, `fxcmpy.create_market_buy_order()` and `fxcmpy.open_trade()` return an instance of the `fxcmpy_order` class. Existing orders are stored in the attribute `orders`, canceled or executed orders are stored in the attribute `old_orders`, both as instance of the `fxcmpy_order` class." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Order Ids" ] }, { "cell_type": "code", "execution_count": 2, "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": "markdown", "metadata": {}, "source": [ "The `ids` of existing orders are returned by `con.get_order_ids()`:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[404809369]\n" ] } ], "source": [ "order_ids = con.get_order_ids()\n", "print(order_ids)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The last order id:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "order_id = order_ids[-1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`fxcmpy.orders` is a `dict` object with the order `ids` as keys and the order object as value." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "{404809369: }" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con.orders" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Order Objects" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To get an existing order object, one can use `con.get_order()`." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ "order = con.get_order(order_id)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "accountId: 2815291\n", "accountName: 02815291\n", "amountK: 300\n", "buy: 110\n", "currency: USD/JPY\n", "currencyPoint: 27.2726\n", "isBuy: True\n", "isELSOrder: False\n", "isEntryOrder: True\n", "isLimitOrder: True\n", "isNetQuantity: False\n", "isStopOrder: False\n", "limit: 112\n", "limitPegBaseType: -1\n", "limitRate: 112\n", "ocoBulkId: 0\n", "orderId: 404809369\n", "range: 0\n", "sell: 0\n", "status: Waiting\n", "stop: 0\n", "stopMove: 0\n", "stopPegBaseType: -1\n", "stopRate: 0\n", "time: 2018-06-07 13:52:30.579000\n", "timeInForce: GTC\n", "type: LE\n", "\n" ] } ], "source": [ "print(order)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get and Set" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `fxcmpy_order` class has **get methods** for all attributes, for example: " ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "300" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "order.get_amount()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "order.get_isBuy()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "order.get_sell()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Moreover, the class has **set methods** for the following attributes:\n", "\n", "* `amount`: `set_amount()`\n", "* `limit`: `set_limit_rate()`\n", "* `range`: `set_range()`\n", "* `rate`: `set_rate()`\n", "* `stop`: `set_stop_rate()`\n", "* `trailing_step`: `set_trailing_step()`" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": true }, "outputs": [], "source": [ "order.set_amount(600)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [], "source": [ "order.set_stop_rate(108, is_in_pips=False)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "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
amountK600
buy110
currencyUSD/JPY
currencyPoint54.5303
expireDate
isBuyTrue
isELSOrderFalse
isEntryOrderTrue
isLimitOrderTrue
isNetQuantityFalse
isStopOrderFalse
limit0
limitPegBaseType-1
limitRate112
ocoBulkId0
orderId404809369
range0
ratePrecision3
sell0
status1
stop108
stopMove0
stopPegBaseType-1
stopRate108
t3
time06072018135425810
timeInForceGTC
tradeId178168067
typeLE
\n", "
" ], "text/plain": [ " 0\n", "accountId 2815291\n", "accountName 02815291\n", "amountK 600\n", "buy 110\n", "currency USD/JPY\n", "currencyPoint 54.5303\n", "expireDate \n", "isBuy True\n", "isELSOrder False\n", "isEntryOrder True\n", "isLimitOrder True\n", "isNetQuantity False\n", "isStopOrder False\n", "limit 0\n", "limitPegBaseType -1\n", "limitRate 112\n", "ocoBulkId 0\n", "orderId 404809369\n", "range 0\n", "ratePrecision 3\n", "sell 0\n", "status 1\n", "stop 108\n", "stopMove 0\n", "stopPegBaseType -1\n", "stopRate 108\n", "t 3\n", "time 06072018135425810\n", "timeInForce GTC\n", "tradeId 178168067\n", "type LE" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con.get_orders().T" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Status and Deletion" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A `fxcmpy_order` object has its own `delete` method." ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'Waiting'" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "order.get_status()" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": true }, "outputs": [], "source": [ "order.delete()" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'Canceled'" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "order.get_status()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Canceled Orders" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The **canceled order** can still be found in the `old_orders` attribute." ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "{404809369: ,\n", " 404809502: }" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con.old_orders" ] }, { "cell_type": "code", "execution_count": 19, "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.3" } }, "nbformat": 4, "nbformat_minor": 2 }