npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mt4-zmq-bridge

v1.2.0

Published

Node.js and MetaTrader 4 communication bridge with ZeroMQ.

Downloads

10

Readme

node-mt4-zmq-bridge

Node.js and MetaTrader 4 communication bridge with ZeroMQ.

This module depends on this MetaTrader 4 Expert Advisor. Please introduce with it thoroughly before using this module.

Installation

npm install --save mt4-zmq-bridge

Usage

const mt4zmqBridge = require('mt4-zmq-bridge');

mt4zmqBridge objects contain multiple enum properties and connect function.

Please refer to mentioned MetaTrader 4 Expert Advisor for enum types.

mt4zmqBridge.connect

A function accepting two arguments:
    reqUrl URL to REQ server
    pullUrl URL to PULL server

Example
const zmqBridge = mt4zmqBridge.connect('tcp://127.0.0.1:5555', 'tcp://127.0.0.1:5556');

It returns connection bridge object.

zmqBridge.request

A function used to send requests to MetaTrader 4 Expert Advisor.

It accepts any number of arguments. Request messages will be queued and have a timeout of 15 seconds by default. Timeout value can be set with zmqBridge.setRequestTimeoutValue.

The first argument is always request type. The rest of the arguments must match with used request type (check API).

A response can be returned either by a Callback or a Promise. To use Callback response, please provide a function as the last argument. Otherwise, a Promise will be returned.

Successfully returned response is an array (e.g. [ '110.522000', '110.542000', 'USDJPY' ]). Error response will return error object (e.g. Error('Invalid price.')).

Examples

Callback type "USDJPY" rates request:

zmqBridge.request(mt4zmqBridge.REQUEST_RATES, 'USDJPY', (err, res) => {
  console.log(res);     // [ '110.522000', '110.542000', 'USDJPY' ]
  console.log(res[0]);  // '110.522000' - market bid
  console.log(res[1]);  // '110.542000' - market ask
});

Promise type "USDJPY" rates request:

zmqBridge.request(mt4zmqBridge.REQUEST_RATES, 'USDJPY')
  .then(res => {
    console.log(res);   // [ '110.522000', '110.542000', 'USDJPY' ]
  })
  .catch(err => {})

Buy limit order for 'USDJPY'.

zmqBridge.request(
  mt4zmqBridge.REQUEST_TRADE_OPEN,  // request type
  'USDJPY',                         // market symbol
  mt4zmqBridge.OP_BUYLIMIT,         // order type
  1.2,                              // volume
  105.23,                           // price
  0,                                // slippage
  100.10,                           // stop loss
  110.76,                           // take profit
  'evening trade',                  // comment
  0,                                // magic number
  mt4zmqBridge.UNIT_CONTRACTS       // unit type
, (err, res) => {
  console.log(res); // [ '140734412' ]
});

Cancel pending order.

zmqBridge.request(mt4zmqBridge.REQUEST_TRADE_DELETE, 140734412).then(res => {
  console.log(res); // [ '140734412' ]
});

More examples can be found in index.spec.js.

zmqBridge.onReqMessage

A function handling messages from REQ server. It is an empty function by default.

zmqBridge.onPullMessage

A function handling messages from PULL server. It is an empty function by default.

zmqBridge.isWaitingForResponse

A bool telling us whether a request with a specific id is still waiting for the response.

zmqBridge.reqConnected

A bool telling us whether a connection with REQ server is open or not.

zmqBridge.pullConnected

A bool telling us whether a connection with PULL server is open or not.

zmqBridge.reqSocket

An object containing ZeroMQ REQ connection object. Used mostly internally.

zmqBridge.pullSocket

An object containing ZeroMQ PULL connection object. Used mostly internally.

zmqBridge.setRequestTimeoutValue

function allowing to set a request timeout in miliseconds. The default request timeout is 15 seconds.

zmqBridge.setRequestTimeoutValue(30000);

Test

IMPORTANT: Some tests will open real market orders. Work with tests only on demo accounts!

npm run test

Changelog

CHANGELOG.md

License

MIT