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, fxcm.py 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]:
0
accountId 2815291
accountName 02815291
amountK 100
buy 1.18
currency EUR/USD
currencyPoint 10
expireDate
isBuy True
isELSOrder False
isEntryOrder True
isLimitOrder True
isNetQuantity False
isStopOrder False
limit 1.2
limitPegBaseType -1
limitRate 1.2
ocoBulkId 0
orderId 96257004
range 0
ratePrecision 5
sell 0
status 1
stop 0
stopMove 0
stopPegBaseType -1
stopRate 0
t 3
time 01112018103438
timeInForce GTC
tradeId 96257005
type LE
In [3]:
con.get_orders(kind='list')  #  returns a list
Out[3]:
[{'accountId': '2815291',
  'accountName': '02815291',
  'amountK': 100,
  'buy': 1.18,
  'currency': 'EUR/USD',
  'currencyPoint': 10,
  'expireDate': '',
  'isBuy': True,
  'isELSOrder': False,
  'isEntryOrder': True,
  'isLimitOrder': True,
  'isNetQuantity': False,
  'isStopOrder': False,
  'limit': 1.2,
  'limitPegBaseType': -1,
  'limitRate': 1.2,
  'ocoBulkId': 0,
  'orderId': '96257004',
  'range': 0,
  'ratePrecision': 5,
  'sell': 0,
  'status': 1,
  'stop': 0,
  'stopMove': 0,
  'stopPegBaseType': -1,
  'stopRate': 0,
  't': 3,
  'time': '01112018103438',
  'timeInForce': 'GTC',
  'tradeId': '96257005',
  'type': 'LE'}]

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

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

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 1
accountId 2815291 2815291
accountName 02815291 02815291
amountK 100 300
buy 1.18 110
currency EUR/USD USD/JPY
currencyPoint 10 26.8773
expireDate
isBuy True True
isELSOrder False False
isEntryOrder True True
isLimitOrder True True
isNetQuantity False False
isStopOrder False False
limit 1.2 112
limitPegBaseType -1 -1
limitRate 1.2 112
ocoBulkId 0 0
orderId 96257004 96266380
range 0 0
ratePrecision 5 3
sell 0 0
status 1 1
stop 0 0
stopMove 0 0
stopPegBaseType -1 -1
stopRate 0 0
t 3 3
time 01112018103438 01112018121455984
timeInForce GTC GTC
tradeId 96257005 96266381
type LE LE

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]:
96266380
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=100)

The order is changed accordingly.

In [11]:
con.get_orders().T
Out[11]:
0 1
accountId 2815291 2815291
accountName 02815291 02815291
amountK 100 500
buy 1.18 100
currency EUR/USD USD/JPY
currencyPoint 10 44.79
expireDate
isBuy True True
isELSOrder False False
isEntryOrder True True
isLimitOrder True True
isNetQuantity False False
isStopOrder False False
limit 1.2 110
limitPegBaseType -1 0
limitRate 1.2 101.1
ocoBulkId 0 0
orderId 96257004 96266380
range 0 0
ratePrecision 5 3
sell 0 0
status 1 1
stop 0 -1
stopMove 0 0
stopPegBaseType -1 1
stopRate 0 99.968
t 3 3
time 01112018103438 01112018121511947
timeInForce GTC GTC
tradeId 96257005 96266381
type LE LE

7.4. Deleting Orders

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

In [12]:
con.get_order_ids()
Out[12]:
[96257004, 96266380]
In [13]:
con.delete_order(order_id)
In [14]:
con.get_orders().T
Out[14]:
0
accountId 2815291
accountName 02815291
amountK 100
buy 1.18
currency EUR/USD
currencyPoint 10
expireDate
isBuy True
isELSOrder False
isEntryOrder True
isLimitOrder True
isNetQuantity False
isStopOrder False
limit 1.2
limitPegBaseType -1
limitRate 1.2
ocoBulkId 0
orderId 96257004
range 0
ratePrecision 5
sell 0
status 1
stop 0
stopMove 0
stopPegBaseType -1
stopRate 0
t 3
time 01112018103438
timeInForce GTC
tradeId 96257005
type LE

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]:
{96266380: <fxcm.fxcm_order at 0x7f5d481ceb70>}