-
Notifications
You must be signed in to change notification settings - Fork 0
/
fxcmpy_api.py
53 lines (34 loc) · 1.2 KB
/
fxcmpy_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pandas as pandas
import matplotlib.pyplot as plt
import enum, time, os
import fxcmpy
# fxcmpy gives bids and asks
# add as enviro variable in docker setup
fxcmpy_token=os.environ.get('FXCM_API_KEY', '')
api=fxcmpy.fxcmpy(access_token=fxcmpy_token,log_level='error')
api.get_instruments()
api.get_candles('EUR/USD')
# daily data
api.get_candles('EUR/USD', period='D1')
# minute data
api.get_candles('EUR/USD', period='m1')
# number must be between 0 and 10K
api.get_candles('EUR/USD', period='D1', number=10000)
api.get_candles('EUR/USD', start='2019-01-01',end='2020-01-01' )
# stock indexes
api.get_candles('SPX500', period='D1', number=10000)
# commodities
api.get_candles('XAU/USD', period='D1', number=10000)
#cryptos
api.get_candles('BTC/USD', period='D1', number=10000)
#streaming real time data
# the subscribe market data offers a callback as a paremeter, so this can be tied to some other process of storing the data
api.subscribe_market_data('EUR/USD')
api.get_unsubscribed_symbols()
while True:
time.sleep(1)
print(api.get_last_price('EUR/USD').name, api.get_last_prices('EUR/USD').Ask)
api.unsubscribe_market_data('EUR/USD')
api.get_subscribed_symbols()
#disconnect from api
api.close()