Skip to content

Commit

Permalink
add a simple python example
Browse files Browse the repository at this point in the history
  • Loading branch information
xnet-Dev committed Oct 24, 2020
1 parent 9eedf15 commit 06516d1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions Examples/Python/Python_to_MT5/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.idea/
61 changes: 61 additions & 0 deletions Examples/Python/Python_to_MT5/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import sys
import clr
import time


sys.path.append(r"C:\Program Files\MtApi5")
asm = clr.AddReference("MtApi5")
import MtApi5 as mt5


def testCopyRates():
symbol = str('EURUSD')
startPos = 1
count = 100
rates = []
tf = mt5.ENUM_TIMEFRAMES.PERIOD_M5
out_dummy = []
try:
result_count, rates_out = client.CopyRates(symbol, tf, startPos, count, out_dummy)
except Exception as e:
print(e)
print('Error in CopyRates = %s\n ', e)
exit()

print("CopyRates: result_count = ", result_count)




if __name__ == '__main__':

client = mt5.MtApi5Client()
ip = str('192.168.178.15')
port = 8300
sleeps = 10
try:

while sleeps > 0:

print("Connecting...")
client.BeginConnect(ip, port)
time.sleep(1)

sleeps = sleeps - 1

if client.ConnectionState == 1:
print("Connected")
testCopyRates()
break
if client.ConnectionState == 0:
print("Connecting...")
continue
if client.ConnectionState == 4:
print("Connection failed")
break


except Exception as e:
print(e)

client.BeginDisconnect()
1 change: 1 addition & 0 deletions Examples/Python/Python_to_MT5/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pythonnet

0 comments on commit 06516d1

Please sign in to comment.