5. Data Tables

This section covers so-called data tables. They provide an overview for certain topics in tabular form.

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

5.1. Account Information

The con.get_accounts() method shows meta information for the default or multiple accounts.

In [2]:
con.get_accounts().T
Out[2]:
0
accountId 2815291
accountName 02815291
balance 463636
dayPL -66.957
equity 463595
grossPL -40.957
hedging N
mc N
mcDate
ratePrecision 0
t 6
usableMargin 461595
usableMargin3 461595
usableMargin3Perc 99.5686
usableMarginPerc 99.5686
usdMr 2000
usdMr3 2000

5.2. Offers

The fxcmpy connection object provides a number of methods to fetch current data from the API.

The con.get_offers() method retrieves and displays a table with current offers.

In [3]:
con.get_offers(kind='dataframe')
Out[3]:
buy buyTradable currency defaultSortOrder emr fractionDigits high instrumentType lmr low ... ratePrecision rollB rollS sell sellTradable spread t time valueDate volume
0 1.17255 True EUR/USD 100 0 5 1.17260 1 0 1.16745 ... 5 -1.105 0.517 1.17231 True 2.4 0 2018-07-16T11:29:38.929Z 07182018 1.00000
1 112.32900 True USD/JPY 200 0 3 112.57500 1 0 112.18800 ... 3 0.385 -0.814 112.30700 True 2.2 0 2018-07-16T11:29:40.644Z 07182018 1.00000
2 1.32858 True GBP/USD 300 0 5 1.32941 1 0 1.32236 ... 5 -0.786 0.360 1.32836 True 2.2 0 2018-07-16T11:29:38.569Z 07182018 1.00000
3 0.99735 True USD/CHF 400 0 5 1.00261 1 0 0.99710 ... 5 0.482 -1.070 0.99710 True 2.5 0 2018-07-16T11:29:40.570Z 07182018 1.00000
4 1.16930 True EUR/CHF 500 0 5 1.17160 1 0 1.16897 ... 5 0.068 -0.188 1.16908 True 2.2 0 2018-07-16T11:29:39.331Z 07182018 1.00266
5 0.74373 True AUD/USD 600 0 5 0.74436 1 0 0.74080 ... 5 0.089 -0.304 0.74352 True 2.1 0 2018-07-16T11:29:34.492Z 07182018 1.00000
6 1.31447 True USD/CAD 700 0 5 1.31674 1 0 1.31358 ... 5 0.116 -0.391 1.31423 True 2.4 0 2018-07-16T11:29:40.491Z 07182018 1.00000
7 0.67900 True NZD/USD 800 0 5 0.67943 1 0 0.67572 ... 5 -0.007 -0.020 0.67876 True 2.4 0 2018-07-16T11:29:38.360Z 07182018 1.00000
8 0.88266 True EUR/GBP 900 0 5 0.88428 1 0 0.88153 ... 5 -0.437 0.193 0.88244 True 2.2 0 2018-07-16T11:29:39.426Z 07182018 1.32846
9 131.69900 True EUR/JPY 1000 0 3 131.70900 1 0 131.07000 ... 3 -0.131 0.045 131.67300 True 2.6 0 2018-07-16T11:29:41.023Z 07182018 0.00890
10 149.22900 True GBP/JPY 1100 0 3 149.33500 1 0 148.38800 ... 3 0.134 -0.358 149.19500 True 3.4 0 2018-07-16T11:29:38.346Z 07182018 0.00890
11 112.64400 True CHF/JPY 1200 0 3 112.64800 1 0 111.92800 ... 3 -0.264 0.101 112.61500 True 2.9 0 2018-07-16T11:29:41.072Z 07182018 0.00890
12 1.32494 True GBP/CHF 1300 0 5 1.32686 1 0 1.32371 ... 5 0.278 -0.651 1.32467 True 2.7 0 2018-07-16T11:29:40.573Z 07182018 1.00266
13 1.57679 True EUR/AUD 1400 0 5 1.57711 1 0 1.57176 ... 5 -1.528 0.651 1.57653 True 2.6 0 2018-07-16T11:29:40.580Z 07182018 0.74352
14 1.54110 True EUR/CAD 1500 0 5 1.54119 1 0 1.53602 ... 5 -0.838 0.351 1.54082 True 2.8 0 2018-07-16T11:29:40.501Z 07182018 0.76093
15 0.97751 True AUD/CAD 1600 0 5 0.97820 1 0 0.97487 ... 5 0.172 -0.493 0.97722 True 2.9 0 2018-07-16T11:29:35.236Z 07182018 0.76093
16 83.53500 True AUD/JPY 1700 0 3 83.70000 1 0 83.22900 ... 3 0.353 -0.823 83.50900 True 2.6 0 2018-07-16T11:29:34.681Z 07182018 0.00890
17 85.47000 True CAD/JPY 1800 0 3 85.63900 1 0 85.18400 ... 3 0.205 -0.495 85.44400 True 2.6 0 2018-07-16T11:29:34.905Z 07182018 0.00890
18 76.26900 True NZD/JPY 1900 0 3 76.32600 1 0 75.80100 ... 3 0.258 -0.568 76.23300 True 3.6 0 2018-07-16T11:29:35.297Z 07182018 0.00890
19 1.74623 True GBP/CAD 2000 0 5 1.74709 1 0 1.73939 ... 5 -0.552 0.205 1.74588 True 3.5 0 2018-07-16T11:29:41.420Z 07182018 0.76093
20 1.95710 True GBP/NZD 2100 0 5 1.95841 1 0 1.95232 ... 5 -0.816 0.365 1.95662 True 4.8 0 2018-07-16T11:29:39.024Z 07182018 0.67888
21 1.78668 True GBP/AUD 2200 0 5 1.78750 1 0 1.77984 ... 5 -1.313 0.523 1.78634 True 3.4 0 2018-07-16T11:29:41.418Z 07182018 0.74352
22 1.09549 True AUD/NZD 2800 0 5 1.09795 1 0 1.09493 ... 5 0.044 -0.174 1.09521 True 2.8 0 2018-07-16T11:29:36.006Z 07182018 0.67888
23 8.82027 True USD/SEK 3000 0 5 8.89671 1 0 8.81707 ... 5 0.347 -1.119 8.81779 True 24.8 0 2018-07-16T11:29:38.412Z 07182018 1.00000
24 10.34100 True EUR/SEK 3200 0 5 10.38880 1 0 10.33560 ... 5 0.008 -0.065 10.33833 True 26.7 0 2018-07-16T11:29:34.960Z 07182018 0.11339
25 9.48275 True EUR/NOK 3600 0 5 9.49270 1 0 9.46834 ... 5 -0.505 0.149 9.47990 True 28.5 0 2018-07-16T11:29:39.510Z 07182018 0.12366
26 8.08820 True USD/NOK 3700 0 5 8.12669 1 0 8.08464 ... 5 0.208 -0.675 8.08553 True 26.7 0 2018-07-16T11:29:39.509Z 07182018 1.00000
27 18.79320 True USD/MXN 3800 0 5 18.92002 1 0 18.78958 ... 5 -1.983 0.846 18.79050 True 27.0 0 2018-07-16T11:29:40.691Z 07182018 1.00000
28 0.74172 True AUD/CHF 3900 0 5 0.74494 1 0 0.74127 ... 5 0.445 -1.110 0.74141 True 3.1 0 2018-07-16T11:29:40.571Z 07182018 1.00266
29 1.72720 True EUR/NZD 4000 0 5 1.72963 1 0 1.72377 ... 5 -1.127 0.521 1.72681 True 3.9 0 2018-07-16T11:29:40.579Z 07182018 0.67888
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
31 7.84913 True USD/HKD 5000 0 5 7.84923 1 0 7.84770 ... 5 0.271 -0.586 7.84846 True 6.7 0 2018-07-16T11:29:34.538Z 07182018 1.00000
32 8.53100 True ZAR/JPY 7100 0 3 8.55600 1 0 8.41900 ... 3 0.087 -0.195 8.49400 True 3.7 0 2018-07-16T11:29:40.586Z 07182018 0.00890
33 4.84870 True USD/TRY 8300 0 5 4.86673 1 0 4.82265 ... 5 -6.582 2.089 4.84729 True 14.1 0 2018-07-16T11:29:16.041Z 07182018 1.00000
34 5.68710 True EUR/TRY 8700 0 5 5.69008 1 0 5.64802 ... 5 -9.183 2.659 5.68582 True 12.8 0 2018-07-16T11:29:38.367Z 07182018 0.20624
35 0.67722 True NZD/CHF 8900 0 5 0.67927 1 0 0.67617 ... 5 0.341 -0.751 0.67678 True 4.4 0 2018-07-16T11:29:40.574Z 07182018 1.00266
36 0.75889 True CAD/CHF 9000 0 5 0.76233 1 0 0.75857 ... 5 0.304 -0.694 0.75857 True 3.2 0 2018-07-16T11:29:40.574Z 07182018 1.00266
37 0.89248 True NZD/CAD 9100 0 5 0.89287 1 0 0.88913 ... 5 0.084 -0.251 0.89207 True 4.1 0 2018-07-16T11:29:28.493Z 07182018 0.76093
38 23.17800 True TRY/JPY 9800 0 3 23.30300 1 0 22.91500 ... 3 0.613 -1.393 23.13800 True 4.0 0 2018-07-16T11:29:26.878Z 07182018 0.00890
39 6.69068 True USD/CNH 799 0 5 6.72510 1 0 6.68301 ... 5 -0.130 -0.268 6.69002 True 6.6 0 2018-07-16T11:29:27.536Z 1.00000
40 6227.76000 True AUS200 100100 0 2 6274.76000 2 0 6226.55000 ... 2 -0.070 0.000 6226.55000 True 1.2 0 2018-07-16T11:28:00.315Z 07182018 0.74352
41 9716.50000 True ESP35 100200 0 2 9785.50000 2 0 9705.00000 ... 2 -0.090 -0.070 9708.50000 True 8.0 0 2018-07-16T11:28:00.315Z 07182018 1.17240
42 5407.53000 True FRA40 100300 0 2 5439.63000 2 0 5406.23000 ... 2 -0.050 -0.040 5406.63000 True 0.9 0 2018-07-16T11:28:00.315Z 07182018 1.17240
43 12518.25000 True GER30 100400 0 2 12598.40000 2 0 12511.95000 ... 2 -0.110 -0.090 12516.80000 True 1.5 0 2018-07-16T11:28:00.315Z 07182018 1.17240
44 28524.00000 False HKG33 100500 0 2 28679.00000 2 0 28296.00000 ... 2 -0.510 0.000 28514.00000 False 10.0 0 2018-07-16T08:15:17.315Z 07182018 0.12741
45 22610.50000 True JPN225 100700 0 2 22734.50000 2 0 22573.50000 ... 2 -0.020 -0.010 22594.50000 True 16.0 0 2018-07-16T11:28:00.315Z 07182018 0.00890
46 7378.05000 True NAS100 100800 0 2 7398.75000 2 0 7375.50000 ... 2 -0.110 0.010 7377.30000 True 0.7 0 2018-07-16T11:28:00.316Z 07182018 1.00000
47 2798.90000 True SPX500 101000 0 2 2806.55000 2 0 2798.40000 ... 2 -0.420 0.030 2798.40000 True 5.0 0 2018-07-16T11:28:00.316Z 07182018 1.00000
48 7567.25000 True UK100 101200 0 2 7670.25000 2 0 7564.45000 ... 2 -0.100 -0.040 7565.95000 True 1.3 0 2018-07-16T11:28:00.316Z 07182018 1.32846
49 25034.80000 True US30 101300 0 2 25113.90000 2 0 25019.55000 ... 2 -0.370 0.020 25032.80000 True 2.0 0 2018-07-16T11:28:00.316Z 07182018 1.00000
50 2.76180 True Copper 101600 0 4 2.79870 3 0 2.74640 ... 4 0.000 0.000 2.75890 True 2.9 0 2018-07-16T11:28:00.316Z 1.00000
51 11370.00000 True CHN50 1020 0 2 11551.00000 2 0 11302.00000 ... 2 -0.170 0.010 11362.00000 True 8.0 0 2018-07-16T11:27:00.316Z 1.00000
52 3445.70000 True EUSTX50 103500 0 2 3464.70000 2 0 3444.60000 ... 2 -0.030 -0.030 3444.60000 True 1.1 0 2018-07-16T11:26:00.316Z 1.17225
53 12004.00000 True USDOLLAR 105800 0 0 12004.00000 7 0 12001.00000 ... 0 0.080 -0.310 12001.00000 True 3.0 0 2017-06-19T07:14:01.316Z 1.00000
54 69.86500 True USOil 200100 0 3 70.89500 3 0 69.71500 ... 3 0.000 0.000 69.81500 True 5.0 0 2018-07-16T11:28:00.316Z 07182018 1.00000
55 73.88500 True UKOil 200200 0 3 75.37500 3 0 73.60500 ... 3 0.000 0.000 73.83500 True 5.0 0 2018-07-16T11:28:00.316Z 07182018 1.00000
56 832.26000 True SOYF 2003 0 2 839.38000 3 0 826.12000 ... 2 0.000 0.000 831.37000 True 8.9 0 2018-07-16T11:28:00.316Z 1.00000
57 2.76800 True NGAS 201500 0 4 2.77850 3 0 2.73950 ... 4 0.000 0.000 2.75750 True 10.5 0 2018-07-16T11:28:00.316Z 1.00000
58 162.85000 True Bund 300100 0 3 162.97500 4 0 162.70500 ... 3 0.000 0.000 162.82000 True 3.0 0 2018-07-16T11:28:00.316Z 07182018 1.17240
59 1244.78000 True XAU/USD 400100 0 2 1245.80000 5 0 1239.96000 ... 2 -0.060 0.000 1244.41000 True 37.0 0 2018-07-16T11:29:40.917Z 07182018 1.00000
60 15.84100 True XAG/USD 400200 0 3 15.93900 5 0 15.65900 ... 3 -0.010 -0.002 15.79700 True 4.4 0 2018-07-16T11:29:23.861Z 07182018 1.00000

61 rows × 25 columns

5.3. Open Positions

The con.get_open_positions() method retrieves and shows the open positions for the default account.

In [4]:
con.get_open_positions(kind='list')
Out[4]:
[{'accountId': '2815291',
  'accountName': '02815291',
  'amountK': 200,
  'close': 112.307,
  'com': 0,
  'currency': 'USD/JPY',
  'currencyPoint': 17.80666,
  'grossPL': -51.64415,
  'isBuy': True,
  'isDisabled': False,
  'limit': 0,
  'open': 112.336,
  'ratePrecision': 3,
  'roll': 0,
  'stop': 0,
  'stopMove': 0,
  't': 1,
  'time': '07162018112746',
  'tradeId': '187518554',
  'usedMargin': 2000,
  'valueDate': '',
  'visiblePL': -2.9}]

5.4. Closed Positions

Similarly, the con.get_closed_positions() method retrieves and presents the closed positions.

The parameter kind has to be dataframe (default) or list.

In [5]:
con.get_closed_positions(kind='dataframe').T
Out[5]:
0
accountName 02815291
amountK 100
close 1.17254
closeTime 07162018112750
com 0
currency EUR/USD
currencyPoint 10
grossPL -26
isBuy False
open 1.17228
openTime 07162018112734
ratePrecision 5
roll 0
t 2
tradeId 187518509
valueDate
visiblePL -2.6

5.5. Open Orders

Open orders are retrieved via con.get_orders().

In [6]:
con.get_orders().T
Out[6]:
0 1
accountId 2815291 2815291
accountName 02815291 02815291
amountK 300 30
buy 110 0
currency USD/JPY EUR/USD
currencyPoint 26.712 3
expireDate 12012018110000 10112018000000
isBuy True False
isELSOrder False False
isEntryOrder True True
isLimitOrder True False
isNetQuantity False False
isStopOrder False True
limit 112 1.12
limitPegBaseType -1 -1
limitRate 112 1.12
ocoBulkId 0 423235902
orderId 422719537 423235903
range 0 0
ratePrecision 3 5
sell 0 1.13
status 1 1
stop 0 1.15
stopMove 0 0
stopPegBaseType -1 -1
stopRate 0 1.15
t 3 3
time 07122018091708 07122018143856
timeInForce GTD GTD
tradeId 186558353 186829211
type LE SE

5.6. Summaries

A summary can be created over all open or closed positions, over an account or over “everything”.

In [7]:
con.get_open_positions_summary().T
Out[7]:
0
accountId
accountName
amountK 200
close 0
com 0
currency USD/JPY
currencyPoint 0
grossPL -67.6771
isBuy False
isDisabled False
isTotal True
limit 0
open 0
ratePrecision 0
roll 0
stop 0
stopMove 0
t 1
time None
tradeId
usedMargin 0
valueDate
visiblePL -3.8
In [8]:
con.get_closed_positions_summary().T
Out[8]:
0
accountName
amountK 100
close 0
closeTime None
com 0
currency EUR/USD
currencyPoint 0
grossPL -26
isBuy False
isTotal True
open 0
openTime None
ratePrecision 0
roll 0
t 2
tradeId
valueDate
visiblePL -2.6
In [9]:
con.get_accounts_summary().T
Out[9]:
0
accountId
accountName
balance 463636
dayPL -91.8955
equity 463570
grossPL -65.8955
hedging
isTotal True
mc
mcDate None
ratePrecision 0
t 6
usableMargin 461570
usableMargin3 461570
usableMargin3Perc 99.5686
usableMarginPerc 99.5686
usdMr 2000
usdMr3 2000
In [10]:
con.get_summary().T
Out[10]:
0
amountK 200
amountKBuy 200
amountKSell 0
avgBuy 112.336
avgSell 0
closeBuy 0
closeSell 112.299
currency USD/JPY
currencyPoint 17.8078
grossPL -65.8955
isBuyDisabled False
isSellDisabled True
netLimit 0
netPL -65.8955
netStop 0
netStopMove 0
offerId 2
plBuy -65.8955
plSell 0
ratePrecision 3
rollSum 0
t 5
usedMargin 2000
usedMarginBuy 2000
usedMarginSell 0
In [11]:
con.close()