Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
xoh-xapi
Advanced tools
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 1 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.