8. The fxcm_order Class

This section introduces the fxcm_order class which is created by different operations.

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

The methods fxcm.create_entry_order(), fxcm.create_market_sell_order(), fxcm.create_market_buy_order() and fxcm.open_trade() return an instance of the fxcm_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 fxcm_order class.

8.1. Order Ids

The ids of existing orders are returned by con.get_order_ids():

In [2]:
order_ids = con.get_order_ids()
print(order_ids)
[96279769, 96277464]

The last order id:

In [3]:
order_id = order_ids[-1]

fxcm.orders is a dict object with the order ids as keys and the order object as value.

In [4]:
con.orders
Out[4]:
{96277464: <fxcm.fxcm_order at 0x7fafab36a780>,
 96279769: <fxcm.fxcm_order at 0x7fafab36ad68>}

8.2. Order Objects

To get an existing order object, one can use con.get_order().

In [5]:
order = con.get_order(order_id)
In [6]:
print(order)
accountId:        2815291
accountName:      02815291
amountK:          400
buy:              0
currency:         USD/JPY
currencyPoint:    35.92664
isBuy:            False
isELSOrder:       False
isEntryOrder:     True
isLimitOrder:     False
isNetQuantity:    False
isStopOrder:      True
limit:            0
limitPegBaseType: -1
limitRate:        0
ocoBulkId:        0
orderId:          96277464
range:            0
sell:             110
status:           Waiting
stop:             111
stopMove:         0
stopPegBaseType:  -1
stopRate:         111
time:             2018-01-11 13:41:32
timeInForce:      GTC
type:             SE

8.3. Get and Set

The fxcm_order class has get methods for all attributes, for example:

In [7]:
order.get_amount()
Out[7]:
400
In [8]:
order.get_isBuy()
Out[8]:
False
In [9]:
order.get_sell()
Out[9]:
110

Moreover, the class has set methods for the following attributes:

  • amount: set_amount()
  • limit: set_limit_rate()
  • range: set_range()
  • rate: set_rate()
  • stop: set_stop_rate()
  • trailing_step: set_trailing_step()
In [10]:
order.set_amount(600)
In [11]:
order.set_stop_rate(111, is_in_pips=False)
In [12]:
con.get_orders().T
Out[12]:
0 1
accountId 2815291 2815291
accountName 02815291 02815291
amountK 500 600
buy 0 0
currency USD/JPY USD/JPY
currencyPoint 44.901 53.8813
expireDate
isBuy False False
isELSOrder False False
isEntryOrder True True
isLimitOrder False False
isNetQuantity False False
isStopOrder True True
limit 109 0
limitPegBaseType -1 -1
limitRate 109 0
ocoBulkId 0 0
orderId 96279769 96277464
range 0 0
ratePrecision 3 3
sell 110 110
status 1 1
stop 0 111
stopMove 0 0
stopPegBaseType -1 -1
stopRate 0 111
t 3 3
time 01112018134215 01112018154002315
timeInForce GTC GTC
tradeId 96279770 96277465
type SE SE

8.4. Status and Deletion

A fxcm_order object has its own delete method.

In [13]:
order.get_status()
Out[13]:
'Waiting'
In [14]:
order.delete()
In [15]:
order.get_status()
Out[15]:
'Canceled'

8.5. Canceled Orders

The canceled order can still be found in the old_orders attribute.

In [16]:
con.old_orders
Out[16]:
{96277464: <fxcm.fxcm_order at 0x7fafab36a780>}