DEV Community

Cover image for I Created XOH-XAPI, a JavaSCript/TypeScript Library For Trading Financial Markets
Peter Ndomano
Peter Ndomano

Posted on

I Created XOH-XAPI, a JavaSCript/TypeScript Library For Trading Financial Markets

Hello there...

I created XOH-XAPI, a Javascript/Typescript version of XTB and X Open Hub API For Trading Financial markets. It works for both non-browser and browser based Javascript Environments, handling all the heavy-lifting for fetching market data, maintaining connection with the server, streaming real-time trading data as well as opening and closing positions.

It's a useful tool for those who want to create their own trading bots and indicators using Javascript. It's available on github - XOH-XAPI

You can get a free demo account on XTB to experiment with your scripts.

Run npm install xoh-xapi to install and import it by import Xapi from 'xoh-xapi'

Then initialize it and run it as follows

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
  });

x.onReady(() => {

  //now you can communicate to the Trading server, retrieve candles, stream real-time data etc....

}, (error) => {
  //error is an instance of JS Error Object, this function is called when Xapi cannot connect to the server
  console.log("error: "+error.message);
})
Enter fullscreen mode Exit fullscreen mode

Read Detailed start guide on github.

Image description

This project is under constant development so welcome to use, test and submit issues. PRs are welcome too. Don't forget to star XOH-XAPI on GitHub and follow me on github for more exciting stuffs to come. Thanks for reading to this far. Stay safe..

Top comments (0)