A Node.js communication layer for the cTrader Open API.
This implementation is created and maintained by Reiryoku Technologies and its contributors.
npm install @reiryoku/ctrader-layer
For the cTrader Open API usage refer to the Open API Documentation.
const { CTraderConnection } = require("@reiryoku/ctrader-layer");
const connection = new CTraderConnection({
host: "demo.ctraderapi.com",
port: 5035,
});
await connection.open();
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",
});
await connection.sendCommand("ProtoOAApplicationAuthReq", {
clientId: "foo",
clientSecret: "bar",
});
You can send a heartbeat message every 25 seconds to keep the connection alive.
setInterval(() => connection.sendHeartbeat(), 25000);
connection.on("EventName", (event) => {
console.log(event);
});
Through HTTP request.
console.log(await CTraderConnection.getAccessTokenProfile("access-token"));
Through HTTP request.
console.log(await CTraderConnection.getAccessTokenAccounts("access-token"));
You can create a PR or open an issue for bug reports or ideas.