Finance APIs: FXCM | ||
---|---|---|
| FXCM Online | Account Login | |
Evan Marie online: | EvanMarie.com| EvanMarie@Proton.me | Linked In | GitHub | Hugging Face | Mastadon | Jovian.ai | TikTok | CodeWars | Discord ⇨ ✨ EvanMarie ✨#6114 | |
Pros and Cons of FXCM |
---|
Cons:
from helpers_mardi_gras import *
import fxcmpy
import_all()
plt.style.use('mardi_gras.mplstyle')
%%html
<style>
a:link {color: #FFB83C !important; font-weight: 600 !important;}
a:visited {color: #FFB83C !important; font-weight: 600 !important;}
</style>
FXCM: First Steps |
---|
api_key = ''
api = fxcmpy.fxcmpy(access_token = api_key, log_level = 'error')
# api is an fxcmpy object |
---|
api
<fxcmpy.fxcmpy.fxcmpy at 0x7fdcfaba2b90>
# api.get_instruments() - trading instruments |
---|
pretty('api.get_instruments')
help(api.get_instruments)
api.get_instruments |
Help on method get_instruments in module fxcmpy.fxcmpy: get_instruments() method of fxcmpy.fxcmpy.fxcmpy instance Return the tradeable instruments of FXCM as a list.
trading_instruments = pd.Series(api.get_instruments())
see(trading_instruments.sample(10), '10 samples of trading instrumentsv')
10 samples of trading instrumentsv |
0 | |
---|---|
266 | BTC/USD |
151 | CON.de |
240 | SPOT.us |
49 | CAD/CHF |
203 | BIDU.hk |
40 | BILI.us |
44 | USD/TRY |
180 | BABA.us |
72 | FLAT.hk |
269 | LTC/USD |
api.close()- disconnect from the server |
---|
# api.close()
pretty('api.get_candles()')
help(api.get_candles)
api.get_candles() |
Help on method get_candles in module fxcmpy.fxcmpy: get_candles(instrument='', offer_id=None, period='H1', number=10, start=None, end=None, with_index=True, columns=[], stop=None) method of fxcmpy.fxcmpy.fxcmpy instance Return historical data from the fxcm database as pandas.DataFrame. Arguments: instrument: string (default ''): the instrument for which data is requested. For a list of all available instruments for historical data, use get_instruments_for_candles(). If the value is equal to '' (default), offer_id must have a value. If both, instrument and offer_id are given, the value of instrument is used. offer_id: integer (default None): the id of the instrument for which data is requested as given in the offer trading table as given by get_offers(). If offer_id is equal to None (default), the parameter instrument must have a value. If both, instrument and offer_id are given, the value of instrument is used. period: string, the granularity of the data. Must be one of 'm1', 'm5', 'm15', 'm30', 'H1', 'H2', 'H3', 'H4', 'H6', 'H8', 'D1', 'W1', or 'M1'. number: integer (default 10), the number of candles to receive. start: datetime.datetime, datetime.date or string (defaut None), the first date to receive data for. end: datetime.datetime, datetime.date or string (default None), the last date to receive data for. with_index: boolean (default True), whether the column 'date' should server as index in the resulting pandas.DataFrame. columns: list (default list()), a list of column labels the result should include. If empty, all columns are returned. Available column labels are 'date', 'bidopen', 'bidclose', 'bidhigh', 'bidlow', 'askopen', 'askclose', 'askhigh', 'asklow', 'tickqty'. Also available is 'asks' as shortcut for all ask related columns and 'bids' for all bid related columns, respectively. The column 'date' is always included. Returns: A pandas DataFrame containing the requested data.
# hourly data by default |
---|
pretty("api.get_candles('EUR/USD')")
api.get_candles('EUR/USD').head(5).style.format(precision = 4)
api.get_candles('EUR/USD') |
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2023-02-10 12:00:00 | 1.0698 | 1.0682 | 1.0700 | 1.0681 | 1.0699 | 1.0684 | 1.0701 | 1.0682 | 13552 |
2023-02-10 13:00:00 | 1.0682 | 1.0695 | 1.0699 | 1.0681 | 1.0684 | 1.0696 | 1.0700 | 1.0682 | 22645 |
2023-02-10 14:00:00 | 1.0695 | 1.0696 | 1.0706 | 1.0686 | 1.0696 | 1.0698 | 1.0708 | 1.0687 | 24374 |
2023-02-10 15:00:00 | 1.0696 | 1.0676 | 1.0706 | 1.0674 | 1.0698 | 1.0678 | 1.0708 | 1.0675 | 37516 |
2023-02-10 16:00:00 | 1.0676 | 1.0668 | 1.0686 | 1.0667 | 1.0678 | 1.0669 | 1.0688 | 1.0669 | 17770 |
pretty("api.get_candles('USD/JPY')")
api.get_candles('USD/JPY').head(5).style.format(precision = 4)
api.get_candles('USD/JPY') |
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2023-02-10 12:00:00 | 130.8250 | 130.9250 | 131.0650 | 130.7510 | 130.8430 | 130.9440 | 131.0840 | 130.7650 | 17851 |
2023-02-10 13:00:00 | 130.9280 | 130.7100 | 130.9460 | 130.5720 | 130.9440 | 130.7280 | 130.9650 | 130.5880 | 34571 |
2023-02-10 14:00:00 | 130.7080 | 130.9960 | 131.0900 | 130.6220 | 130.7280 | 131.0100 | 131.1090 | 130.6420 | 38187 |
2023-02-10 15:00:00 | 131.0010 | 131.3200 | 131.3970 | 131.0010 | 131.0130 | 131.3390 | 131.4140 | 131.0130 | 44088 |
2023-02-10 16:00:00 | 131.3210 | 131.5020 | 131.5690 | 131.2910 | 131.3400 | 131.5170 | 131.5830 | 131.3080 | 24394 |
pretty("api.get_candles('GBP/USD')")
api.get_candles('GBP/USD').head(5).style.format(precision = 4)
api.get_candles('GBP/USD') |
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2023-02-10 12:00:00 | 1.2108 | 1.2091 | 1.2111 | 1.2086 | 1.2109 | 1.2092 | 1.2113 | 1.2087 | 21900 |
2023-02-10 13:00:00 | 1.2091 | 1.2111 | 1.2121 | 1.2088 | 1.2092 | 1.2113 | 1.2123 | 1.2090 | 34786 |
2023-02-10 14:00:00 | 1.2111 | 1.2111 | 1.2130 | 1.2106 | 1.2113 | 1.2113 | 1.2131 | 1.2107 | 38244 |
2023-02-10 15:00:00 | 1.2111 | 1.2075 | 1.2121 | 1.2069 | 1.2113 | 1.2077 | 1.2123 | 1.2071 | 50437 |
2023-02-10 16:00:00 | 1.2075 | 1.2059 | 1.2087 | 1.2058 | 1.2077 | 1.2060 | 1.2089 | 1.2060 | 28630 |
# api = fxcmpy.fxcmpy(access_token = api_key, log_level = 'error')
pretty("api.get_candles('EUR/USD', period = 'D1'")
api.get_candles('EUR/USD', period = 'D1').head(5).style.format(precision = 4)
api.get_candles('EUR/USD', period = 'D1' |
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2023-01-30 22:00:00 | 1.0865 | 1.0848 | 1.0913 | 1.0838 | 1.0869 | 1.0852 | 1.0914 | 1.0840 | 266787 |
2023-01-31 22:00:00 | 1.0848 | 1.0860 | 1.0874 | 1.0801 | 1.0852 | 1.0867 | 1.0876 | 1.0803 | 300547 |
2023-02-01 22:00:00 | 1.0860 | 1.0988 | 1.1001 | 1.0852 | 1.0867 | 1.0994 | 1.1002 | 1.0853 | 372545 |
2023-02-02 22:00:00 | 1.0987 | 1.0908 | 1.1032 | 1.0885 | 1.0994 | 1.0910 | 1.1034 | 1.0886 | 415139 |
2023-02-03 22:00:00 | 1.0908 | 1.0792 | 1.0940 | 1.0792 | 1.0911 | 1.0795 | 1.0941 | 1.0793 | 397630 |
pretty("api.get_candles('EUR/USD', period = 'm1')")
api.get_candles('EUR/USD', period = 'm1').head(5).style.format(precision = 4)
api.get_candles('EUR/USD', period = 'm1') |
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2023-02-10 21:48:00 | 1.0676 | 1.0677 | 1.0677 | 1.0675 | 1.0678 | 1.0679 | 1.0679 | 1.0677 | 43 |
2023-02-10 21:49:00 | 1.0677 | 1.0677 | 1.0677 | 1.0676 | 1.0679 | 1.0679 | 1.0679 | 1.0678 | 29 |
2023-02-10 21:50:00 | 1.0677 | 1.0677 | 1.0677 | 1.0676 | 1.0679 | 1.0679 | 1.0679 | 1.0678 | 95 |
2023-02-10 21:51:00 | 1.0677 | 1.0678 | 1.0678 | 1.0677 | 1.0679 | 1.0679 | 1.0679 | 1.0679 | 22 |
2023-02-10 21:52:00 | 1.0678 | 1.0678 | 1.0678 | 1.0677 | 1.0679 | 1.0679 | 1.0679 | 1.0679 | 32 |
import random
instrument = random.choice(trading_instruments)
pretty(f"api.get_candles('Copper', period = 'H3')")
api.get_candles('Copper', period = 'H3').head(5).style.format(precision = 4)
api.get_candles('Copper', period = 'H3') |
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2023-02-09 16:00:00 | 4.0646 | 4.0801 | 4.1096 | 4.0538 | 4.0688 | 4.0843 | 4.1144 | 4.0580 | 10767 |
2023-02-09 19:00:00 | 4.0800 | 4.0662 | 4.0841 | 4.0611 | 4.0842 | 4.0704 | 4.0883 | 4.0653 | 4955 |
2023-02-09 22:00:00 | 4.0718 | 4.0589 | 4.0718 | 4.0606 | 4.0760 | 4.0631 | 4.0760 | 4.0648 | 1065 |
2023-02-10 01:00:00 | 4.0648 | 4.0446 | 4.0717 | 4.0437 | 4.0690 | 4.0488 | 4.0759 | 4.0479 | 6980 |
2023-02-10 04:00:00 | 4.0449 | 4.0541 | 4.0629 | 4.0292 | 4.0491 | 4.0583 | 4.0671 | 4.0334 | 5969 |
Defining time with number |
---|
# daily data, number = 10000 (maxiumum number possible) |
---|
api.get_candles('EUR/USD',
period = 'D1',
number = 10000)
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2001-09-09 21:00:00 | 0.91 | 0.90 | 0.91 | 0.90 | 0.91 | 0.90 | 0.91 | 0.90 | 0 |
2001-09-10 21:00:00 | 0.90 | 0.91 | 0.91 | 0.90 | 0.90 | 0.91 | 0.92 | 0.90 | 0 |
2001-09-11 21:00:00 | 0.91 | 0.91 | 0.92 | 0.90 | 0.91 | 0.91 | 0.92 | 0.90 | 0 |
2001-09-12 21:00:00 | 0.91 | 0.91 | 0.91 | 0.90 | 0.91 | 0.91 | 0.91 | 0.91 | 0 |
2001-09-13 21:00:00 | 0.91 | 0.92 | 0.92 | 0.91 | 0.91 | 0.92 | 0.93 | 0.91 | 0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-02-05 22:00:00 | 1.08 | 1.07 | 1.08 | 1.07 | 1.08 | 1.07 | 1.08 | 1.07 | 293847 |
2023-02-06 22:00:00 | 1.07 | 1.07 | 1.08 | 1.07 | 1.07 | 1.07 | 1.08 | 1.07 | 406035 |
2023-02-07 22:00:00 | 1.07 | 1.07 | 1.08 | 1.07 | 1.07 | 1.07 | 1.08 | 1.07 | 267334 |
2023-02-08 22:00:00 | 1.07 | 1.07 | 1.08 | 1.07 | 1.07 | 1.07 | 1.08 | 1.07 | 285708 |
2023-02-09 22:00:00 | 1.07 | 1.07 | 1.08 | 1.07 | 1.07 | 1.07 | 1.08 | 1.07 | 316647 |
6213 rows × 9 columns
^ passed 10,000, but received 6,213, because that is the most available |
---|
Defining time with start & end (daily data) |
---|
api.get_candles('EUR/USD',
period = 'D1',
start = '2001-01-01',
end = '2023-02-10')
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2001-09-09 21:00:00 | 0.91 | 0.90 | 0.91 | 0.90 | 0.91 | 0.90 | 0.91 | 0.90 | 0 |
2001-09-10 21:00:00 | 0.90 | 0.91 | 0.91 | 0.90 | 0.90 | 0.91 | 0.92 | 0.90 | 0 |
2001-09-11 21:00:00 | 0.91 | 0.91 | 0.92 | 0.90 | 0.91 | 0.91 | 0.92 | 0.90 | 0 |
2001-09-12 21:00:00 | 0.91 | 0.91 | 0.91 | 0.90 | 0.91 | 0.91 | 0.91 | 0.91 | 0 |
2001-09-13 21:00:00 | 0.91 | 0.92 | 0.92 | 0.91 | 0.91 | 0.92 | 0.93 | 0.91 | 0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-02-05 22:00:00 | 1.08 | 1.07 | 1.08 | 1.07 | 1.08 | 1.07 | 1.08 | 1.07 | 293847 |
2023-02-06 22:00:00 | 1.07 | 1.07 | 1.08 | 1.07 | 1.07 | 1.07 | 1.08 | 1.07 | 406035 |
2023-02-07 22:00:00 | 1.07 | 1.07 | 1.08 | 1.07 | 1.07 | 1.07 | 1.08 | 1.07 | 267334 |
2023-02-08 22:00:00 | 1.07 | 1.07 | 1.08 | 1.07 | 1.07 | 1.07 | 1.08 | 1.07 | 285708 |
2023-02-09 22:00:00 | 1.07 | 1.07 | 1.08 | 1.07 | 1.07 | 1.07 | 1.08 | 1.07 | 316647 |
6213 rows × 9 columns
Getting hourly data |
---|
api.get_candles('EUR/USD',
period = 'H1',
number = 10000)
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2021-07-16 14:00:00 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 14956 |
2021-07-16 15:00:00 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 9403 |
2021-07-16 16:00:00 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 4586 |
2021-07-16 17:00:00 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 4946 |
2021-07-16 18:00:00 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 1.18 | 6476 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-02-10 17:00:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 12466 |
2023-02-10 18:00:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 7181 |
2023-02-10 19:00:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 7876 |
2023-02-10 20:00:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 6375 |
2023-02-10 21:00:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 2782 |
10000 rows × 9 columns
Getting hourly data with start and end - was able to get more than 10,000 - this is the exact date range it would allow, no more - this is a trial and error process, how to maximize the time period |
---|
api.get_candles('EUR/USD',
period = 'H1',
start = '2021-05-28',
end = '2023-02-10')
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2021-05-28 00:00:00 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 5405 |
2021-05-28 01:00:00 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 6388 |
2021-05-28 02:00:00 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 3819 |
2021-05-28 03:00:00 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 4609 |
2021-05-28 04:00:00 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 1.22 | 2541 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-02-09 20:00:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 12351 |
2023-02-09 21:00:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 3114 |
2023-02-09 22:00:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 2487 |
2023-02-09 23:00:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 2019 |
2023-02-10 00:00:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 6311 |
10844 rows × 9 columns
Getting data by the minute |
---|
api.get_candles('EUR/USD',
period = 'm1',
number = 10000)
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2023-02-01 22:24:00 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 4 |
2023-02-01 22:25:00 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 4 |
2023-02-01 22:26:00 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 6 |
2023-02-01 22:27:00 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 4 |
2023-02-01 22:28:00 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 1.10 | 2 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-02-10 21:53:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 33 |
2023-02-10 21:54:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 35 |
2023-02-10 21:55:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 102 |
2023-02-10 21:56:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 122 |
2023-02-10 21:57:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 72 |
10000 rows × 9 columns
Getting data by the minute with start and end - was able to get close to 16,000 records - this is again the exact date range it would allow, no more - this is more data than yfinance or Alpha Vantage allowed |
---|
api.get_candles('EUR/USD',
period = 'm1',
start = '2023-01-26',
end = '2023-02-10')
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2023-01-26 00:00:00 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 73 |
2023-01-26 00:01:00 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 93 |
2023-01-26 00:02:00 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 149 |
2023-01-26 00:03:00 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 65 |
2023-01-26 00:04:00 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 1.09 | 68 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-02-09 23:56:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 74 |
2023-02-09 23:57:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 21 |
2023-02-09 23:58:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 134 |
2023-02-09 23:59:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 53 |
2023-02-10 00:00:00 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 1.07 | 172 |
15804 rows × 9 columns
Selecting specific columns to import |
---|
api.get_candles('EUR/USD',
period = 'D1',
start = '2001-01-01',
end = '2023-02-10',
columns = ['bidclose', 'askclose'])
bidclose | askclose | |
---|---|---|
date | ||
2001-09-09 21:00:00 | 0.90 | 0.90 |
2001-09-10 21:00:00 | 0.91 | 0.91 |
2001-09-11 21:00:00 | 0.91 | 0.91 |
2001-09-12 21:00:00 | 0.91 | 0.91 |
2001-09-13 21:00:00 | 0.92 | 0.92 |
... | ... | ... |
2023-02-05 22:00:00 | 1.07 | 1.07 |
2023-02-06 22:00:00 | 1.07 | 1.07 |
2023-02-07 22:00:00 | 1.07 | 1.07 |
2023-02-08 22:00:00 | 1.07 | 1.07 |
2023-02-09 22:00:00 | 1.07 | 1.07 |
6213 rows × 2 columns
instruments = pd.Series(list(api.get_instruments()))
index_mask = instruments.str.contains(r'\d')
indexes_available = pd.Series(instruments.loc[index_mask]).reset_index()
head_tail_horz(indexes_available, 12, 'Indexes Available on FXCM')
Indexes Available on FXCM |
index | 0 | |
---|---|---|
0 | 11 | EUSTX50 |
1 | 29 | US2000 |
2 | 153 | DB1.de |
3 | 163 | TUI1.de |
4 | 223 | A2M.au |
5 | 226 | Z1P.au |
6 | 300 | TOM2.nl |
7 | 302 | 5USNote |
8 | 303 | 10USNote |
9 | 304 | 2USNote |
10 | 309 | FED30D |
11 | 311 | EURIBOR3M |
index | 0 | |
---|---|---|
12 | 312 | SONIA3M |
13 | 322 | AUS200 |
14 | 323 | ESP35 |
15 | 324 | FRA40 |
16 | 325 | GER30 |
17 | 326 | HKG33 |
18 | 327 | JPN225 |
19 | 328 | NAS100 |
20 | 331 | SPX500 |
21 | 332 | UK100 |
22 | 333 | US30 |
23 | 336 | CHN50 |
SPX500: daily data, last 10,000 days - returns price index and not total return index - this is the more commonly used index - price return - just the change in price - total return accounts for dividends and the reinvestment thereof |
---|
api.get_candles('SPX500',
period = 'D1',
number = 10000)
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2001-09-10 00:00:00 | 1,085.78 | 1,092.54 | 1,096.94 | 1,073.15 | 1,085.78 | 1,092.54 | 1,096.94 | 1,073.15 | 0 |
2001-09-17 00:00:00 | 1,092.54 | 1,038.77 | 1,092.54 | 1,037.46 | 1,092.54 | 1,038.77 | 1,092.54 | 1,037.46 | 0 |
2001-09-18 00:00:00 | 1,038.77 | 1,032.74 | 1,046.42 | 1,029.25 | 1,038.77 | 1,032.74 | 1,046.42 | 1,029.25 | 0 |
2001-09-19 00:00:00 | 1,032.74 | 1,016.10 | 1,038.91 | 984.62 | 1,032.74 | 1,016.10 | 1,038.91 | 984.62 | 0 |
2001-09-20 00:00:00 | 1,016.10 | 984.54 | 1,016.10 | 984.49 | 1,016.10 | 984.54 | 1,016.10 | 984.49 | 0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-02-05 22:00:00 | 4,124.12 | 4,112.85 | 4,132.61 | 4,093.90 | 4,124.72 | 4,113.45 | 4,133.21 | 4,094.40 | 192597 |
2023-02-06 22:00:00 | 4,114.08 | 4,156.83 | 4,178.52 | 4,088.76 | 4,114.68 | 4,157.23 | 4,179.02 | 4,089.26 | 336170 |
2023-02-07 22:00:00 | 4,157.61 | 4,123.33 | 4,169.75 | 4,111.91 | 4,158.21 | 4,123.73 | 4,170.35 | 4,112.41 | 194720 |
2023-02-08 22:00:00 | 4,122.78 | 4,088.38 | 4,161.05 | 4,069.08 | 4,123.38 | 4,088.78 | 4,161.65 | 4,069.58 | 209966 |
2023-02-09 22:00:00 | 4,088.54 | 4,089.93 | 4,094.96 | 4,051.16 | 4,089.14 | 4,090.53 | 4,095.46 | 4,051.76 | 217261 |
5533 rows × 9 columns
Dow Jones Industrial Average: daily data, last 10,000 days |
---|
api.get_candles('US30',
period = 'D1',
number = 10000)
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2001-09-10 00:00:00 | 9,603.36 | 9,605.51 | 9,671.80 | 9,493.55 | 9,603.36 | 9,605.51 | 9,671.80 | 9,493.55 | 0 |
2001-09-17 00:00:00 | 9,580.32 | 8,920.70 | 9,580.32 | 8,883.40 | 9,580.32 | 8,920.70 | 9,580.32 | 8,883.40 | 0 |
2001-09-18 00:00:00 | 8,922.70 | 8,903.40 | 9,022.06 | 8,861.05 | 8,922.70 | 8,903.40 | 9,022.06 | 8,861.05 | 0 |
2001-09-19 00:00:00 | 8,903.54 | 8,759.13 | 8,945.47 | 8,480.21 | 8,903.54 | 8,759.13 | 8,945.47 | 8,480.21 | 0 |
2001-09-20 00:00:00 | 8,748.61 | 8,376.21 | 8,748.82 | 8,375.72 | 8,748.61 | 8,376.21 | 8,748.82 | 8,375.72 | 0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-02-05 22:00:00 | 33,843.20 | 33,871.70 | 33,967.90 | 33,643.10 | 33,854.70 | 33,873.20 | 33,970.10 | 33,646.90 | 457177 |
2023-02-06 22:00:00 | 33,878.70 | 34,106.20 | 34,244.90 | 33,624.40 | 33,884.20 | 34,107.70 | 34,247.10 | 33,626.60 | 680590 |
2023-02-07 22:00:00 | 34,111.80 | 34,010.30 | 34,176.70 | 33,886.00 | 34,118.40 | 34,011.80 | 34,181.50 | 33,888.20 | 481016 |
2023-02-08 22:00:00 | 33,998.90 | 33,712.10 | 34,245.20 | 33,586.20 | 34,003.70 | 33,713.60 | 34,247.40 | 33,588.40 | 471943 |
2023-02-09 22:00:00 | 33,720.10 | 33,864.60 | 33,885.90 | 33,504.10 | 33,724.90 | 33,868.40 | 33,888.10 | 33,507.90 | 506106 |
5540 rows × 9 columns
GER30: hourly data, May 28, 2021 to current - this is a total return index, not price return |
---|
api.get_candles('GER30',
period = 'H1',
start = '2021-05-28',
end = '2023-02-10')
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2021-05-28 00:00:00 | 15,428.93 | 15,462.56 | 15,471.50 | 15,458.56 | 15,430.03 | 15,469.07 | 15,473.07 | 15,460.97 | 320 |
2021-05-28 01:00:00 | 15,462.56 | 15,469.50 | 15,475.74 | 15,460.56 | 15,469.07 | 15,470.80 | 15,477.04 | 15,463.47 | 701 |
2021-05-28 02:00:00 | 15,469.50 | 15,465.67 | 15,470.74 | 15,456.56 | 15,470.80 | 15,466.97 | 15,473.07 | 15,459.07 | 583 |
2021-05-28 03:00:00 | 15,465.67 | 15,470.67 | 15,471.83 | 15,464.56 | 15,466.97 | 15,471.97 | 15,474.07 | 15,466.47 | 521 |
2021-05-28 04:00:00 | 15,470.67 | 15,478.83 | 15,479.74 | 15,461.45 | 15,471.97 | 15,480.13 | 15,481.04 | 15,462.75 | 413 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-02-09 17:00:00 | 15,513.50 | 15,501.60 | 15,534.60 | 15,469.50 | 15,515.50 | 15,503.60 | 15,536.60 | 15,471.50 | 7646 |
2023-02-09 18:00:00 | 15,501.00 | 15,481.50 | 15,509.50 | 15,470.00 | 15,503.00 | 15,483.50 | 15,511.50 | 15,472.00 | 11274 |
2023-02-09 19:00:00 | 15,481.00 | 15,450.50 | 15,487.50 | 15,444.50 | 15,483.00 | 15,452.50 | 15,489.50 | 15,446.50 | 8850 |
2023-02-09 20:00:00 | 15,450.10 | 15,433.80 | 15,450.60 | 15,403.50 | 15,452.10 | 15,435.30 | 15,452.60 | 15,405.50 | 9611 |
2023-02-10 00:00:00 | 15,396.40 | 15,412.40 | 15,415.40 | 15,395.40 | 15,400.40 | 15,416.40 | 15,419.40 | 15,399.40 | 332 |
8920 rows × 9 columns
US Oil: daily, max results |
---|
api.get_candles('USOil',
period = 'D1',
number = 10000)
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2001-09-10 00:00:00 | 27.95 | 27.63 | 28.00 | 27.57 | 27.95 | 27.63 | 28.00 | 27.57 | 0 |
2001-09-11 00:00:00 | 27.65 | 27.77 | 27.77 | 27.53 | 27.65 | 27.77 | 27.77 | 27.53 | 0 |
2001-09-17 00:00:00 | 29.00 | 28.81 | 29.25 | 28.30 | 29.00 | 28.81 | 29.25 | 28.30 | 0 |
2001-09-18 00:00:00 | 28.80 | 27.70 | 28.86 | 27.60 | 28.80 | 27.70 | 28.86 | 27.60 | 0 |
2001-09-19 00:00:00 | 27.67 | 26.72 | 27.95 | 25.80 | 27.67 | 26.72 | 27.95 | 25.80 | 0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-02-05 22:00:00 | 73.22 | 74.42 | 74.50 | 72.23 | 73.26 | 74.45 | 74.54 | 72.27 | 132901 |
2023-02-06 22:00:00 | 74.53 | 77.57 | 77.57 | 74.33 | 74.59 | 77.60 | 77.61 | 74.37 | 140385 |
2023-02-07 22:00:00 | 77.45 | 78.47 | 78.55 | 77.07 | 77.51 | 78.50 | 78.59 | 77.11 | 118053 |
2023-02-08 22:00:00 | 78.42 | 77.64 | 78.83 | 76.49 | 78.46 | 77.67 | 78.86 | 76.53 | 113971 |
2023-02-09 22:00:00 | 77.66 | 79.81 | 80.31 | 77.45 | 77.70 | 79.84 | 80.35 | 77.49 | 133209 |
5525 rows × 9 columns
Gold in USD: daily data, max results |
---|
api.get_candles('XAU/USD',
period = 'D1',
number = 10000)
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2001-09-09 21:00:00 | 273.25 | 271.75 | 273.60 | 270.95 | 273.25 | 271.75 | 273.60 | 270.95 | 0 |
2001-09-10 21:00:00 | 271.75 | 286.25 | 292.50 | 271.30 | 271.75 | 286.25 | 292.50 | 271.30 | 0 |
2001-09-11 21:00:00 | 286.75 | 278.25 | 292.50 | 276.75 | 286.75 | 278.25 | 292.50 | 276.75 | 0 |
2001-09-12 21:00:00 | 278.25 | 281.25 | 282.00 | 278.00 | 278.25 | 281.25 | 282.00 | 278.00 | 0 |
2001-09-13 21:00:00 | 281.25 | 285.55 | 290.00 | 279.00 | 281.25 | 285.55 | 290.00 | 279.00 | 0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-02-05 22:00:00 | 1,860.83 | 1,867.24 | 1,881.23 | 1,860.36 | 1,861.89 | 1,867.54 | 1,881.55 | 1,861.36 | 439702 |
2023-02-06 22:00:00 | 1,866.84 | 1,871.79 | 1,884.31 | 1,864.85 | 1,868.56 | 1,872.09 | 1,884.68 | 1,865.22 | 484418 |
2023-02-07 22:00:00 | 1,872.39 | 1,875.35 | 1,886.23 | 1,868.91 | 1,873.94 | 1,875.65 | 1,886.59 | 1,869.28 | 359629 |
2023-02-08 22:00:00 | 1,875.36 | 1,861.70 | 1,890.17 | 1,858.78 | 1,875.98 | 1,862.00 | 1,890.53 | 1,859.11 | 375300 |
2023-02-09 22:00:00 | 1,861.18 | 1,865.26 | 1,872.07 | 1,852.59 | 1,862.72 | 1,865.91 | 1,872.45 | 1,852.98 | 409643 |
5560 rows × 9 columns
Siver in USD: daily data, max results |
---|
api.get_candles('XAG/USD',
period = 'D1',
number = 10000)
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
1950-02-27 21:00:00 | 0.73 | 0.73 | 0.73 | 0.73 | 0.73 | 0.73 | 0.73 | 0.73 | 0 |
1950-03-30 21:00:00 | 0.73 | 0.73 | 0.73 | 0.73 | 0.73 | 0.73 | 0.73 | 0.73 | 0 |
1950-04-27 21:00:00 | 0.72 | 0.72 | 0.72 | 0.72 | 0.72 | 0.72 | 0.72 | 0.72 | 0 |
1950-05-30 21:00:00 | 0.73 | 0.73 | 0.73 | 0.73 | 0.73 | 0.73 | 0.73 | 0.73 | 0 |
1950-09-28 21:00:00 | 0.73 | 0.73 | 0.73 | 0.73 | 0.73 | 0.73 | 0.73 | 0.73 | 0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-02-05 22:00:00 | 22.22 | 22.07 | 22.60 | 22.07 | 22.27 | 22.34 | 22.63 | 22.16 | 126839 |
2023-02-06 22:00:00 | 22.05 | 22.16 | 22.44 | 22.03 | 22.36 | 22.20 | 22.48 | 22.07 | 155153 |
2023-02-07 22:00:00 | 22.11 | 22.27 | 22.52 | 22.11 | 22.47 | 22.37 | 22.55 | 22.20 | 108466 |
2023-02-08 22:00:00 | 22.05 | 21.96 | 22.58 | 21.89 | 22.38 | 22.00 | 22.61 | 21.93 | 118493 |
2023-02-09 22:00:00 | 21.94 | 21.98 | 22.29 | 21.64 | 22.06 | 22.04 | 22.33 | 21.85 | 134826 |
5601 rows × 9 columns
Natural Gas: hourly data, max results |
---|
api.get_candles('NGAS',
period = 'H1',
number = 10000)
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2021-06-04 12:00:00 | 3.06 | 3.04 | 3.07 | 3.04 | 3.07 | 3.06 | 3.08 | 3.06 | 1214 |
2021-06-04 13:00:00 | 3.04 | 3.04 | 3.06 | 3.03 | 3.06 | 3.05 | 3.07 | 3.04 | 1464 |
2021-06-04 14:00:00 | 3.04 | 3.04 | 3.05 | 3.02 | 3.05 | 3.05 | 3.06 | 3.03 | 984 |
2021-06-04 15:00:00 | 3.04 | 3.04 | 3.05 | 3.03 | 3.05 | 3.05 | 3.06 | 3.04 | 784 |
2021-06-04 16:00:00 | 3.04 | 3.10 | 3.11 | 3.04 | 3.05 | 3.12 | 3.13 | 3.05 | 2243 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-02-10 17:00:00 | 2.50 | 2.51 | 2.55 | 2.49 | 2.51 | 2.52 | 2.56 | 2.50 | 2761 |
2023-02-10 18:00:00 | 2.51 | 2.48 | 2.52 | 2.48 | 2.52 | 2.49 | 2.53 | 2.49 | 1673 |
2023-02-10 19:00:00 | 2.48 | 2.54 | 2.54 | 2.47 | 2.49 | 2.55 | 2.56 | 2.48 | 2900 |
2023-02-10 20:00:00 | 2.54 | 2.57 | 2.58 | 2.54 | 2.55 | 2.58 | 2.59 | 2.55 | 1342 |
2023-02-10 21:00:00 | 2.57 | 2.57 | 2.58 | 2.55 | 2.58 | 2.58 | 2.59 | 2.56 | 640 |
10000 rows × 9 columns
Soy Futures: hourly data, max results |
---|
api.get_candles('SOYF',
period = 'H1',
number = 10000)
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2020-12-30 14:00:00 | 1,289.12 | 1,292.39 | 1,294.68 | 1,286.11 | 1,290.05 | 1,293.50 | 1,295.89 | 1,287.24 | 12147 |
2020-12-30 15:00:00 | 1,292.39 | 1,295.60 | 1,297.93 | 1,289.84 | 1,293.50 | 1,296.33 | 1,299.09 | 1,290.87 | 13485 |
2020-12-30 16:00:00 | 1,295.60 | 1,297.48 | 1,304.25 | 1,294.06 | 1,296.33 | 1,298.20 | 1,305.39 | 1,295.22 | 13203 |
2020-12-30 17:00:00 | 1,297.48 | 1,293.25 | 1,297.95 | 1,289.76 | 1,298.20 | 1,293.99 | 1,298.97 | 1,290.86 | 9320 |
2020-12-30 18:00:00 | 1,293.25 | 1,303.45 | 1,303.93 | 1,292.36 | 1,293.99 | 1,304.42 | 1,304.89 | 1,293.53 | 8445 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-02-10 15:00:00 | 1,520.26 | 1,529.11 | 1,530.26 | 1,516.99 | 1,521.52 | 1,530.37 | 1,531.52 | 1,518.25 | 5645 |
2023-02-10 16:00:00 | 1,529.00 | 1,521.86 | 1,529.51 | 1,519.49 | 1,530.26 | 1,523.12 | 1,530.77 | 1,520.75 | 4305 |
2023-02-10 17:00:00 | 1,521.88 | 1,528.88 | 1,529.26 | 1,521.01 | 1,523.14 | 1,530.14 | 1,530.52 | 1,522.27 | 3010 |
2023-02-10 18:00:00 | 1,529.01 | 1,531.26 | 1,532.26 | 1,527.24 | 1,530.27 | 1,532.52 | 1,533.52 | 1,528.50 | 2371 |
2023-02-10 19:00:00 | 1,531.12 | 1,532.76 | 1,533.26 | 1,530.99 | 1,532.38 | 1,534.02 | 1,534.52 | 1,532.25 | 1063 |
10000 rows × 9 columns
Bitcoin: daily data, start and end dates |
---|
api.get_candles('BTC/USD',
period = 'D1',
start = '2002-01-01',
end = '2023-02-10')
bidopen | bidclose | bidhigh | bidlow | askopen | askclose | askhigh | asklow | tickqty | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2017-12-15 22:00:00 | 19,900.00 | 19,900.00 | 19,900.00 | 19,900.00 | 19,901.00 | 19,901.00 | 19,901.00 | 19,901.00 | 0 |
2017-12-18 22:00:00 | 19,900.00 | 19,705.00 | 20,040.00 | 19,300.00 | 19,901.00 | 19,706.00 | 20,041.00 | 19,301.00 | 0 |
2017-12-19 22:00:00 | 19,705.00 | 18,555.00 | 19,340.00 | 19,310.00 | 19,706.00 | 18,556.00 | 19,341.00 | 19,311.00 | 0 |
2017-12-20 22:00:00 | 18,555.00 | 17,275.00 | 17,300.00 | 17,275.00 | 18,556.00 | 17,276.00 | 17,301.00 | 17,276.00 | 0 |
2017-12-21 22:00:00 | 17,275.00 | 15,680.00 | 16,330.00 | 15,915.00 | 17,276.00 | 15,681.00 | 16,331.00 | 15,916.00 | 0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-02-06 22:00:00 | 22,975.30 | 22,893.80 | 23,133.50 | 22,621.50 | 23,015.30 | 22,933.80 | 23,173.50 | 22,661.50 | 50536 |
2023-02-07 22:00:00 | 22,894.30 | 23,177.80 | 23,330.50 | 22,621.50 | 22,934.30 | 23,217.80 | 23,370.50 | 22,661.50 | 68856 |
2023-02-08 22:00:00 | 23,178.30 | 22,939.40 | 23,430.50 | 22,654.50 | 23,218.30 | 22,979.40 | 23,470.50 | 22,690.00 | 59518 |
2023-02-09 22:00:00 | 22,939.00 | 21,839.30 | 22,992.20 | 21,678.20 | 22,979.00 | 21,879.30 | 23,032.20 | 21,718.20 | 83253 |
2023-02-10 22:00:00 | 21,839.80 | 21,530.10 | 21,939.10 | 21,458.40 | 21,879.80 | 21,564.10 | 21,979.10 | 21,498.40 | 67891 |
1345 rows × 9 columns
api.subscribe_market_data() |
---|
help(api.subscribe_market_data)
Help on method subscribe_market_data in module fxcmpy.fxcmpy: subscribe_market_data(symbol='', add_callbacks=()) method of fxcmpy.fxcmpy.fxcmpy instance Stream the prices of an instrument. Arguments: symbol: string, the symbol of the instrument in question as given by get_instruments(). add_callbacks: list of callables, all methods in that list will be called for every incoming dataset of the instrument. Such a method has to accept two positional arguments, data and dataframe, say. The first should be a json like object with the new price data received by the stream and the second should be a Pandas DataFrame with the collected price data as given by get_prices().
Subscribe to EUR/USD exchange data |
---|
api.subscribe_market_data('EUR/USD')
api.get_subscribed_symbols() - get the current open subscriptions |
---|
help(api.get_subscribed_symbols)
Help on method get_subscribed_symbols in module fxcmpy.fxcmpy: get_subscribed_symbols() method of fxcmpy.fxcmpy.fxcmpy instance Returns a list of symbols for the subscribed instruments.
api.get_subscribed_symbols()
['EUR/USD']
api.get_last_price() - get the last reported price for a symbol |
---|
help(api.get_last_price)
Help on method get_last_price in module fxcmpy.fxcmpy: get_last_price(symbol) method of fxcmpy.fxcmpy.fxcmpy instance Return the last prices of a given subscribed instrument. Arguments: symbol: string, the symbol of the instrument as given by get_instruments().
pretty('The most recent price data for EUR/USD')
api.get_last_price('EUR/USD')
The most recent price data for EUR/USD |
Bid 1.07 Ask 1.07 High 1.08 Low 1.07 Name: 2023-02-10 21:57:59.544000, dtype: float64
api.get_prices() - get all available data for a subscription since the subscription was started |
---|
help(api.get_prices)
Help on method get_prices in module fxcmpy.fxcmpy: get_prices(symbol) method of fxcmpy.fxcmpy.fxcmpy instance Return the prices of a given subscribed instrument. Arguments: symbol: string, the symbol of the instrument as given by get_instruments().
api.get_prices('EUR/USD')
Bid | Ask | High | Low | |
---|---|---|---|---|
2023-02-10 21:57:59.544 | 1.07 | 1.07 | 1.08 | 1.07 |
Subscribing to Bitcoin also, because Euro is not updating |
---|
api.subscribe_market_data('BTC/USD')
api.get_last_price('EUR/USD')
Bid 1.07 Ask 1.07 High 1.08 Low 1.07 Name: 2023-02-10 21:57:59.544000, dtype: float64
api.get_prices('BTC/USD')
Bid | Ask | High | Low | |
---|---|---|---|---|
2023-02-10 21:58:30.932 | 21530 | 21564 | 23,470.50 | 21,458.25 |
Stream live data: |
---|
import time
count = 0
pretty('Streaming EUR/USD data:')
while count < 10:
time.sleep(1)
print(api.get_last_price('EUR/USD').name, api.get_last_price('EUR/USD').Ask)
count += 1
Streaming EUR/USD data: |
2023-02-10 21:57:59.544000 1.06803 2023-02-10 21:57:59.544000 1.06803 2023-02-10 21:57:59.544000 1.06803 2023-02-10 21:57:59.544000 1.06803 2023-02-10 21:57:59.544000 1.06803 2023-02-10 21:57:59.544000 1.06803 2023-02-10 21:57:59.544000 1.06803 2023-02-10 21:57:59.544000 1.06803 2023-02-10 21:57:59.544000 1.06803 2023-02-10 21:57:59.544000 1.06803
pretty('time.sleep()')
help(time.sleep)
time.sleep() |
Help on built-in function sleep in module time: sleep(...) sleep(seconds) Delay execution for a given number of seconds. The argument may be a floating point number for subsecond precision.
Function to stream the current ask price |
---|
def stream_data(ticker, delay = 1, reps = 10):
api.subscribe_market_data(ticker)
import time
pretty(f'Streaming {ticker} data:')
count = 0
while count < reps:
time.sleep(delay)
price = api.get_last_price(ticker).Ask
timestamp = api.get_last_price(ticker).name
pretty(f"{price:,.3f}", timestamp, fontsize = 3)
count += 1
api.subscribe_market_data(ticker)
pretty(f'Transmission complete.')
stream_data('EUR/USD', delay = 1, reps = 3)
Streaming EUR/USD data: |
2023-02-10 21:57:59.544000 |
1.068 |
2023-02-10 21:57:59.544000 |
1.068 |
2023-02-10 21:57:59.544000 |
1.068 |
Transmission complete. |
stream_data('BTC/USD', delay = 1, reps = 3)
Streaming BTC/USD data: |
2023-02-10 21:58:30.932000 |
21,564.000 |
2023-02-10 21:58:30.932000 |
21,564.000 |
2023-02-10 21:58:30.932000 |
21,564.000 |
Transmission complete. |
Unsubscribe from market data |
---|
api.get_subscribed_symbols()
['EUR/USD', 'BTC/USD']
stream_data('LCattleF', delay = 1, reps = 3)
Streaming LCattleF data: |
2023-02-10 19:04:55.811000 |
164.110 |
2023-02-10 19:04:55.811000 |
164.110 |
2023-02-10 19:04:55.811000 |
164.110 |
Transmission complete. |
api.unsubscribe_market_data('EUR/USD')
api.unsubscribe_market_data('BTC/USD')
api.close()