Skip to content

Instantly share code, notes, and snippets.

@slapglif
Created July 5, 2018 13:07
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save slapglif/b84ce24d4dfe5002b0b2d30b655b60a1 to your computer and use it in GitHub Desktop.
Save slapglif/b84ce24d4dfe5002b0b2d30b655b60a1 to your computer and use it in GitHub Desktop.
def generate_nonce(length=8):
"""Generate pseudorandom number."""
return ''.join([str(random.randint(0, 9)) for i in range(length)])
def trade(signal,volume,pair):
try:
trade = 'TRADE|OPEN|' + signal + '|' + pair + '|0|0|0|IcarusBot Trade|' + generate_nonce() + '|' + volume
s.send_string(trade, encoding='utf-8')
print("Waiting for metatrader to respond...")
logging.info("Waiting for metatrader to respond...")
m = s.recv()
print("Reply from server ", m)
except Exception as e:
print(e)
logging.info(e)
@tkifelew
Copy link

tkifelew commented Feb 7, 2019

premium content

@qkum
Copy link

qkum commented Jun 11, 2021

Thanks a lot for sharing.

Please in the future write a little description + imports.

I'm pro at trading but not at programming yet.

I have never seen his python syntax style before.

What is the random number used for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment