Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
xoh-xapi
Advanced tools
X Open Hub API
Weekly downloads
Readme
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
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
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'
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.
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]);
})
}
)();
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
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.
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
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.
Welcome to open Issues and submit PRs.
FAQs
X Open Hub API
The npm package xoh-xapi receives a total of 0 weekly downloads. As such, xoh-xapi popularity was classified as not popular.
We found that xoh-xapi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.