7. Entry Orders

This section covers entry orders.

In [1]:
import fxcmpy
import pandas as pd
import datetime as dt
con = fxcmpy.fxcmpy(config_file='fxcm.cfg')

7.1. Existing Orders

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.

In [2]:
con.get_orders().T  # returns DataFrame by default
Out[2]:
In [3]:
con.get_orders(kind='list')  #  returns a list
Out[3]:
[]

Each order has a unique order_id, these ids are returned by con.get_order_ids().

In [4]:
con.get_order_ids()
Out[4]:
[]

7.2. Placing Entry Orders

Entry orders are placed via the con.create_entry_order() method. For a detailed description of the parameters refer to the FXCM API documentation.

In [5]:
order = con.create_entry_order(symbol='USD/JPY', is_buy=True,
                               amount=300, limit=112,
                               is_in_pips = False,
                               time_in_force='GTC', rate=110,
                               stop=None, trailing_step=None)
In [6]:
con.get_orders().T
Out[6]:
0
accountId 2815291
accountName 02815291
amountK 300
buy 110
currency USD/JPY
currencyPoint 27.2846
expireDate
isBuy True
isELSOrder False
isEntryOrder True
isLimitOrder False
isNetQuantity False
isStopOrder True
limit 112
limitPegBaseType -1
limitRate 112
ocoBulkId 0
orderId 404808930
range 0
ratePrecision 3
sell 0
status 1
stop 0
stopMove 0
stopPegBaseType -1
stopRate 0
t 3
time 06072018134424598
timeInForce GTC
tradeId 178167932
type SE

7.3. Changing Orders

There are two methods to change entry orders:

  • change_order_stop_limit() to change an order’s stop or limit rate.
  • change_order() to change an order’s amount, rate, order range and/or trailing step.
In [7]:
order_id = con.get_order_ids()[-1]
In [8]:
order_id
Out[8]:
404808930
In [9]:
con.change_order_stop_limit(order_id=order_id, is_stop_in_pips=True,
                            is_limit_in_pips=True, limit=110, stop=-1)
In [10]:
con.change_order(order_id=order_id, amount=500, rate=114)

The order is changed accordingly.

In [11]:
con.get_orders().T
Out[11]:
0
accountId 2815291
accountName 02815291
amountK 500
buy 114
currency USD/JPY
currencyPoint 45.474
expireDate
isBuy True
isELSOrder False
isEntryOrder True
isLimitOrder False
isNetQuantity False
isStopOrder True
limit 110
limitPegBaseType 0
limitRate 115.1
ocoBulkId 0
orderId 404808930
range 0
ratePrecision 3
sell 0
status 1
stop -1
stopMove 0
stopPegBaseType 1
stopRate 113.968
t 3
time 06072018134441711
timeInForce GTC
tradeId 178167932
type SE

7.4. Deleting Orders

Orders can be deleted through the method con.delete_orders().

In [12]:
con.get_order_ids()
Out[12]:
[404808930]
In [13]:
con.delete_order(order_id)
In [14]:
con.get_orders().T
Out[14]:

Deleted or executed orders of the current session are stored in the attribute old_orders as an fxcm_order object.

In [15]:
con.old_orders
Out[15]:
{404808930: <fxcmpy.fxcmpy_order.fxcmpy_order at 0x7fd7c215ccc0>}
In [16]:
con.close()