-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfxcm_rest_client_sample.py
37 lines (34 loc) · 1.33 KB
/
fxcm_rest_client_sample.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
import json
import fxcm_rest_api_token as fxcm_rest_api
import time
trader = fxcm_rest_api.Trader('YOUR_TOKEN', 'demo') # demo for demo
trader.login()
try:
print("Logged in, now getting Account details")
while len(trader.account_list) < 1:
time.sleep(0.1)
account_id = trader.account_list[0]
print(trader.account_id == account_id)
print("Opening a trade now -USD/JPY 10 lots on %s" % account_id)
response = trader.open_trade(account_id, "USD/JPY", True, 10)
print(response)
if response['status'] is True:
orderId = response['data']['orderId']
tradeId = trader.get_tradeId(orderId)
print("TradeID: ", tradeId)
print("Open trade response: ", response)
positions = trader.get_model("OpenPosition")
print("Positions: ", positions)
response = trader.close_all_for_symbol("USD/JPY")
print("Close All result:\n\n", response['status'], response, "\n\n")
positions = trader.get_model("OpenPosition")
print("Positions: ", positions)
c = trader.candles("EUR/USD", "m15", 15, dt_fmt="%Y/%m/%d %H:%M:%S")['candles']
print(len(c))
for candle in c:
print(candle)
c = trader.get_candles("USD/JPY", "M1", 10)
for candle in c['candles']:
print(candle)
except Exception as e:
print(str(e))