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

xoh-xapi

v2.0.7

Published

X Open Hub API

Downloads

21

Readme

xoh-xapi

regulation-xtb

xoh-xapi

XTB and X Open Hub API

This Javascript/Typescript API can be used to communicate with Forex Trading servers of XTB and X Open Hub for various purposes including, but not limited to

  • Opening and Closing Positions
  • Getting Market Data and Candlestick Data
  • Fetching Market News & Calendar
  • Many more........

Give that capability, xoh-xapi is a great tool for creating Trading Bots and Indicators to help making right decisions in Forex, Crypto and Stock Trading

How to install

This API works for both browser and non-browser javascript environments. Install it by running npm install xoh-xapi Then Import it in your Project by running import Xapi from 'xoh-xapi'

How to use

First you must create an instance of Xapi by:

let x = new Xapi({
    accountId: "<your_account_id>", //you can get a demo account ID from XTB
    password: "<your_password>", //Your account password
    type: "<acc_type>", //account type, can be 'demo' or 'real'
    broker: "<broker>", // your broker, currently only 'xtb' (for XTB) and 'xoh' for X Open Hub are supported
  });

After creating an instance of xoh-xapi you must initialize it before you can use it otherwise it'll throw websocket exceptions. The initialization performs login process automatically so no need to call Xapi.login() method explicitly. You can initialize it in two ways. Either by using x.init() or by using x.onReady(successCallback(), failureCallback());. Let's see both ways below.

Initializing with Xapi.init()

Note x is our Xapi instance here and this API is Promise Based. So you initialize it like below..

(
  async () => {
    await x.init();

    //then you can use it like this
    await x.getAllSymbols().then((symbols) => {
      console.log('symbols data...');
      console.log(symbols[0]);
    })
  }
)();

Initializing with Xapi.onReady( success(), fail( error))

This is the most recomended way to initialize this API because it gives you more control on how to handle Startup errors. Note x is our Xapi instance here. So you initialize it like below..

x.onReady(async () => {
  console.log("welcome....");
  await x.getCalendar().then((cal) => {
    console.log('calendar data');
    console.log(cal[0]);
  })
}, (error) => {
  //error is an instance of JS Error Object
  console.log("error: "+error.message);
})

After initialization you can perform all actions using the api as described here

STreaming commands (Get Real time data as it arrive on the server)

In order to do this you must first initialize the streamer of Xapi instance by Xapi.streamer.init() as follows. Note: the initialization method is a Promise-based function

x.onReady(async () => {
  console.log("welcome....");
  await x.streamer.init(); //streamer initialized here.

  x.streamer.getKeepAlive({
    listener: (data) => {
      console.log('it works....');
      console.log(data);
    }
  })

}, (error) => {
  console.log("error: "+error.message);
})

There are various streaming functions like Xapi.streamer.getKeepAlive(), Xapi.streamer.getCandles() and many others as described here. But something is common for all of these functions. Firstly they are not promise based (except the init() function) and they all take an object as a parameter consisting of a listener filed that references the function which should be run whenever new streaming data is sent from the server. Other object fields may be for symbols and other function specific parameters.

Format of Response Data:

This API replies with Purely Javascript Objects, so there's no need to Parse, you may only Stringfy the response data if you want to have them as JSON instead. Consider the example below.

x.onReady(async () => {
  console.log("welcome....");
  await x.streamer.init(); //remember to init streamer before using it
  await x.getCalendar().then((cal) => {
    //here cal holds array of Objects extending CALENDAR_RECORD interface( found in data-formats/CalendarRecord.ts)
    console.log('calendar data');
    console.log(cal[0]); //logging first calendar event
    console.log(cal[0].title); //getting title of the first calendar event
  })
}, (error) => {
  console.log("error: "+error.message);
})

The same way is also used in streaming commands

Features:

  • Typescript support
  • Persists connection to the server behind the scenes untill user calls Xapi.logout() method, no need to manually ping in order to stay connected to the server
  • Promise Based API
  • With manual communication to XTB or X Open Hub Servers some streaming commands do not work without triggering (eg getCandles), But this API handles everything behind the scenes so user can just call any streaming and non-streaming command with ease and without worrying about such issues.
  • The project is under constant development
  • Easy to use!

Whats next?

Currently I'm working on integrating some kind of storage so that Apps using this API can opt to save data and process it later offline.

Contribution.

Welcome to open Issues and submit PRs.