-
Notifications
You must be signed in to change notification settings - Fork 2
/
client_example.py
51 lines (41 loc) · 1.6 KB
/
client_example.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
from metatrader.client import MetaTrader
from metatrader.constants import TIME_FRAMES, ACTION_TYPE
if __name__ == "__main__":
meta_trader = MetaTrader(authorization_code="123456")
# Connect to the server
meta_trader.connect()
# Send a request to the server
print(meta_trader.accountInfo())
# print(meta_trader.balance())
# print(meta_trader.get_orders())
# while True:
# print(meta_trader.get_current_price("Step Index"))
# time.sleep(3)
# print(
# meta_trader.get_historical_data(
# symbol="Step Index",
# time_frame=TIME_FRAMES.D1,
# action_type=ACTION_TYPE.PRICE,
# from_date="13-02-2022 00:00:00",
# to_date="13-02-2024 00:00:00",
# )
# )
# current_price = meta_trader.get_current_price("Step Index")
# print(current_price)
# pips = 100
# stop_level = 0.1
# normalized_pips = pips * stop_level
# BUY
# stoploss = float(current_price["data"]["tick"][1]) - normalized_pips
# takeprofit = float(current_price["data"]["tick"][1]) + normalized_pips
# print(stoploss, takeprofit)
# print(meta_trader.buy("Step Index", 0.1, stoploss, takeprofit))
# SELL
# stoploss = float(current_price["data"]["tick"][2]) + normalized_pips
# takeprofit = float(current_price["data"]["tick"][2]) - normalized_pips
# print(stoploss, takeprofit)
# print(meta_trader.sell("Step Index", 0.5, stoploss, takeprofit))
# Positions & Manipulation
# positions = meta_trader.get_positions()
# print(positions)
# print(meta_trader.close_all_positions())