2.2.0 • Published 2 years ago

@reiryoku/ctrader-layer v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

cTrader Layer

Image Image

A Node.js communication layer for cTrader Open API. This implementation is created and maintained by Reiryoku Technologies and its contributors.

Installation

npm install @reiryoku/ctrader-layer

Usage

For the cTrader Open API usage refer to the Open API Documentation.

How to establish a connection

const { CTraderConnection } = require("@reiryoku/ctrader-layer");

const connection = new CTraderConnection({
    host: "demo.ctraderapi.com",
    port: 5035,
});

await connection.open();

How to send commands

You can use the sendCommand method to send a command with payload to the server. The method returns a Promise resolved only when a response from the server is received. If the response to the command contains an error code then the returned Promise is rejected.

await connection.sendCommand("PayloadName", {
    foo: "bar",
});

How to authenticate an application

await connection.sendCommand("ProtoOAApplicationAuthReq", {
    clientId: "foo",
    clientSecret: "bar",
});

How to authenticate a trading account

You can get the access token to use your account from Open API Applications. First, you have to authenticate the application, then you can authenticate your trading accounts as follows.

await connection.sendCommand("ProtoOAAccountAuthReq", {
    accessToken: "foo",
    ctidTraderAccountId: "bar",
});

How to keep connection alive

You can send a heartbeat message every 25 seconds to keep the connection alive.

setInterval(() => connection.sendHeartbeat(), 25000);

How to listen events from server

connection.on("EventName", (event) => {
    console.log(event);
});

How to get the access token profile information

Through HTTP request.

console.log(await CTraderConnection.getAccessTokenProfile("access-token"));

How to get the access token accounts

Through HTTP request.

console.log(await CTraderConnection.getAccessTokenAccounts("access-token"));

Contribution

You can create a PR or open an issue for bug reports or ideas.

2.2.0

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago