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 461993
dayPL 3458.12
equity 467394
grossPL 5401
hedging N
mc N
mcDate
ratePrecision 0
t 6
usableMargin 466094
usableMargin3 466094
usableMargin3Perc 99.7219
usableMarginPerc 99.7219
usdMr 1300
usdMr3 1300

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.17743 True EUR/USD 100 0 5 1.17761 1 0 1.17095 ... 5 -2.934 1.404 1.17719 True 2.4 0 2018-06-06T10:26:17.203Z 06082018 1.00000
1 110.18700 True USD/JPY 200 0 3 110.19800 1 0 109.76100 ... 3 1.035 -2.226 110.16500 True 2.2 0 2018-06-06T10:26:17.255Z 06082018 1.00000
2 1.34336 True GBP/USD 300 0 5 1.34395 1 0 1.33860 ... 5 -2.214 0.906 1.34313 True 2.3 0 2018-06-06T10:26:17.819Z 06082018 1.00000
3 0.98674 True USD/CHF 400 0 5 0.98756 1 0 0.98345 ... 5 1.437 -3.138 0.98651 True 2.3 0 2018-06-06T10:26:17.939Z 06082018 1.00000
4 1.16171 True EUR/CHF 500 0 5 1.16228 1 0 1.15273 ... 5 0.219 -0.570 1.16145 True 2.6 0 2018-06-06T10:26:17.199Z 06082018 1.01349
5 0.76563 True AUD/USD 600 0 5 0.76738 1 0 0.76111 ... 5 -0.255 0.105 0.76540 True 2.3 0 2018-06-06T10:26:17.890Z 06082018 1.00000
6 1.29235 True USD/CAD 700 0 5 1.29775 1 0 1.29197 ... 5 0.264 -0.717 1.29215 True 2.0 0 2018-06-06T10:26:17.870Z 06082018 1.00000
7 0.70482 True NZD/USD 800 0 5 0.70615 1 0 0.70190 ... 5 0.015 -0.105 0.70458 True 2.4 0 2018-06-06T10:26:17.190Z 06082018 1.00000
8 0.87659 True EUR/GBP 900 0 5 0.87696 1 0 0.87365 ... 5 -1.311 0.579 0.87636 True 2.3 0 2018-06-06T10:26:17.201Z 06082018 1.34281
9 129.72400 True EUR/JPY 1000 0 3 129.76100 1 0 128.57900 ... 3 -0.519 0.210 129.69800 True 2.6 0 2018-06-06T10:26:18.072Z 06082018 0.00908
10 148.01200 True GBP/JPY 1100 0 3 148.02400 1 0 146.96000 ... 3 0.483 -1.122 147.97300 True 3.9 0 2018-06-06T10:26:14.614Z 06082018 0.00908
11 84.35500 True AUD/JPY 1700 0 3 84.38400 1 0 83.56600 ... 3 0.660 -1.494 84.32700 True 2.8 0 2018-06-06T10:26:18.034Z 06082018 0.00908
12 1.75487 True GBP/AUD 2200 0 5 1.76073 1 0 1.74761 ... 5 -1.605 0.678 1.75449 True 3.8 0 2018-06-06T10:26:17.614Z 06082018 0.76527
13 6.38420 True USD/CNH 799 0 5 6.40429 1 0 6.37897 ... 5 -0.399 0.060 6.38340 True 8.0 0 2018-06-06T10:26:17.226Z 1.00000
14 5463.86000 True FRA40 100300 0 2 5481.36000 2 0 5456.23000 ... 2 -0.050 -0.040 5462.76000 True 1.1 0 2018-06-06T10:26:15.898Z 06082018 1.17674
15 12835.07000 True GER30 100400 0 2 12870.71000 2 0 12760.01000 ... 2 -0.110 -0.100 12833.97000 True 1.1 0 2018-06-06T10:26:18.351Z 06082018 1.17674
16 7715.50000 True UK100 101200 0 2 7725.50000 2 0 7670.59000 ... 2 -0.100 -0.040 7713.70000 True 1.8 0 2018-06-06T10:26:18.323Z 06082018 1.34281
17 24908.25000 True US30 101300 0 2 24913.20000 2 0 24804.70000 ... 2 -0.370 0.020 24906.00000 True 2.2 0 2018-06-06T10:26:02.786Z 06082018 1.00000
18 11933.00000 True USDOLLAR 105800 0 0 11954.00000 7 0 11928.00000 ... 0 0.210 -0.460 11931.00000 True 2.0 0 2018-06-06T10:26:16.904Z 1.00000
19 1295.32000 True XAU/USD 400100 0 2 1299.67000 5 0 1294.09000 ... 2 -0.180 0.000 1294.96000 True 36.0 0 2018-06-06T10:26:17.277Z 06082018 1.00000
20 16.57400 True XAG/USD 400200 0 3 16.61000 5 0 16.43800 ... 3 -0.030 -0.006 16.53000 True 4.4 0 2018-06-06T10:26:17.220Z 06082018 1.00000

21 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': 100,
  'close': 1.17731,
  'com': 0,
  'currency': 'EUR/USD',
  'currencyPoint': 10,
  'grossPL': 5425,
  'isBuy': False,
  'isDisabled': False,
  'limit': 0,
  'open': 1.23156,
  'ratePrecision': 5,
  'roll': 286.36,
  'stop': 0,
  'stopMove': 0,
  't': 1,
  'time': '04092018133045',
  'tradeId': '167729381',
  'usedMargin': 1300,
  'valueDate': '',
  'visiblePL': 542.5}]

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 1 2 3
accountName 02815291 02815291 02815291 02815291
amountK 300 300 300 300
close 1.34273 1.34273 1.34273 1.34273
closeTime 06062018101450 06062018101450 06062018101450 06062018101450
com 0 0 0 0
currency GBP/USD GBP/USD GBP/USD GBP/USD
currencyPoint 30 30 30 30
grossPL -5181 -5181 -5181 -5181
isBuy True True True True
open 1.36 1.36 1.36 1.36
openTime 05012018145207 05012018145207 05012018145207 05012018145207
ratePrecision 5 5 5 5
roll -821.85 -821.85 -821.85 -821.85
t 2 2 2 2
tradeId 144240844 97729921 97601524 97599708
valueDate
visiblePL -172.7 -172.7 -172.7 -172.7

5.5. Open Orders

Open orders are retrieved via con.get_orders().

In [6]:
con.get_orders().T
Out[6]:
0
accountId 2815291
accountName 02815291
amountK 30
buy 1.11
currency EUR/USD
currencyPoint 3
expireDate
isBuy True
isELSOrder False
isEntryOrder True
isLimitOrder True
isNetQuantity False
isStopOrder False
limit 1.13
limitPegBaseType -1
limitRate 1.13
ocoBulkId 0
orderId 337894215
range 0
ratePrecision 5
sell 0
status 1
stop 1.1
stopMove 0
stopPegBaseType -1
stopRate 1.1
t 3
time 03012018165137
timeInForce GTC
tradeId 144240834
type LE

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 100
close 0
com 0
currency EUR/USD
currencyPoint 0
grossPL 5431
isBuy False
isDisabled False
isTotal True
limit 0
open 0
ratePrecision 0
roll 286.36
stop 0
stopMove 0
t 1
time None
tradeId
usedMargin 0
valueDate
visiblePL 543.1
In [8]:
con.get_closed_positions_summary().T
Out[8]:
0
accountName
amountK 1200
close 0
closeTime None
com 0
currency GBP/USD
currencyPoint 0
grossPL -20724
isBuy False
isTotal True
open 0
openTime None
ratePrecision 0
roll -3287.4
t 2
tradeId
valueDate
visiblePL -690.8
In [9]:
con.get_accounts_summary().T
Out[9]:
0
accountId
accountName
balance 461993
dayPL 3486.12
equity 467422
grossPL 5429
hedging
isTotal True
mc
mcDate None
ratePrecision 0
t 6
usableMargin 466122
usableMargin3 466122
usableMargin3Perc 99.7219
usableMarginPerc 99.7219
usdMr 1300
usdMr3 1300
In [10]:
con.get_summary().T
Out[10]:
0
amountK -100
amountKBuy 0
amountKSell 100
avgBuy 0
avgSell 1.23156
closeBuy 1.17724
closeSell 0
currency EUR/USD
currencyPoint -10
grossPL 5432
isBuyDisabled True
isSellDisabled False
netLimit 0
netPL 5718.36
netStop 0
netStopMove 0
offerId 1
plBuy 0
plSell 5432
ratePrecision 5
rollSum 286.36
t 5
usedMargin 1300
usedMarginBuy 0
usedMarginSell 1300
In [11]:
con.close()