Coder Social home page Coder Social logo

pymt4's Introduction

PyMT4 - Python bindings for the Metatrader 4 trading platform ( rmawatson [ at ] hotmail. com )

Overview -

This project provides bindings for using the Metatrader4 MQL API in python.

The bindings are provided through a tcp connection with the metatrader 4 client via pymt4_host.mq4 using boost::asio. The python session connects to the host, and can then make API calls natively in python. An experimental OnTick handler is provided to register charts to notify the python session of new ticks.

A simple example in python:

Prerequisites:

  • Metatrader has a chart running pymt4_host.mq4, allowing execution of dll calls.

  • PyMT4.pyd is available on PYTHONPATH

    from PyMT4 import *

    Connect() RegisterOnOrderHandler(OnOrderHandler)

    while(True): time.sleep(0.5)

    We will never get here, but Disconnect() should be called when

    we want to disconnect the current session.

    Disconnect()

The PyMT4 module contains most of the API. Custom Indicators are not yet supported, but should be simple enough to add in the future.

The network port is currently hard coded in pymt4_common.h and can be changed here. This will require a compile of both the Client and Server, and should be made configurable at both ends (simple do to), as is the address the client listens on (localhost).

The bindings are written such that they could easily be exposed to any other language. pymt4_client_command.cpp contains the stub functions for the currently exposed API. This could be called directly by including the header in a C++ application (and linking to the dll), or wrapped for some other scripting language.

This is exposed to Python using boost::python in pymt4_client_module.cpp including the OnTickHandler implementation.

Compiling -

This project uses boost heavily and you will need to optain a copy from www.boost.org. It was originally built using Visual Studio 2010, and most of customisation of your paths should be limited to modifying the PyMT4_Properties.props property sheet.

Other thoughts -

For me, the ideal soliution would be to keep python for the glue logic and utility of the mass of code out there and speed of development, but allow exposing custom routines that prove too slow to proxy (too many MQL calls), in addition to the raw API. And allow these routines to be dynamically exposed to Python via this framework. This would only be of use if the routine in question actually needed to make a significant amount of MQL api calls.

The command execution rate was extremely good the last time I measured it, in the high thousands of commands per second.

The precompiled samples are 64bit and compiled against Python 2.7

Good luck. Give me a shout if there are any (real) problems.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.