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

@reiryoku/ctrader-layer

v2.2.0

Published

A Node.js communication layer for cTrader Open API

Downloads

219

Readme

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.