
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
xapi-node
Advanced tools
This project makes it possible to get data from Forex market, execute market or limit order with NodeJS/JS through WebSocket connection
This project makes it possible to get data from Forex market, execute market or limit order with NodeJS/JS through WebSocket connection
This module may can be used for BFB Capital and X-Trade Brokers xStation5 accounts
WebSocket protocol description: https://peterszombati.github.io/xapi-node/
This module is usable on Front-end too.
npm i xapi-node
// TypeScript
import XAPI from 'xapi-node'
const x = new XAPI({
accountId: '(xStation5) accountID',
password: '(xStation5) password',
type: 'real' // or demo
})
x.connect()
x.onReady(() => {
console.log('Connection is ready')
// Disconnect
x.disconnect().then(() => console.log('Disconnected'))
})
x.onReject((e) => {
console.error(e)
})
// TypeScript
import XAPI from 'xapi-node'
const x = new XAPI({
accountId: '(xStation5) accountID',
password: '(xStation5) password',
host: 'ws.xtb.com', // only for XTB accounts
type: 'real' // or demo
})
x.connect()
x.onReady(() => {
console.log('Connection is ready')
// Disconnect
x.disconnect().then(() => console.log('Disconnected'))
})
x.onReject((e) => {
console.error(e)
})
x.Socket.send.tradeTransaction({
cmd: CMD_FIELD.BUY_LIMIT,
customComment: null,
expiration: new Date().getTime() + 60000 * 60 * 24 * 365,
offset: 0,
order: 0,
price: 100,
sl: 0,
symbol: 'BITCOIN',
tp: 8000,
type: TYPE_FIELD.OPEN,
volume: 10
}).then(({order}) => {
console.log('Success ' + order)
}).catch(e => {
console.error('Failed')
console.error(e)
})
x.Socket.send.tradeTransaction({
cmd: CMD_FIELD.BUY_LIMIT,
customComment: null,
expiration: new Date().getTime() + 60000 * 60 * 24 * 365,
offset: 0,
order: 0,
price: 21900,
sl: 0,
symbol: 'US30',
tp: 26500,
type: TYPE_FIELD.OPEN,
volume: 0.2
}).then(({order}) => {
console.log('Success ' + order)
}).catch(e => {
console.error('Failed')
console.error(e)
})
x.Stream.listen.getTickPrices((data) => {
console.log(data.symbol + ': ' + data.ask + ' | ' + data.askVolume + ' volume | ' + data.level + ' level' )
})
x.onReady(() => {
x.Stream.subscribe.getTickPrices('EURUSD')
.catch(() => { console.error('subscribe for EURUSD failed')})
})
/* output
EURUSD: 1.10912 | 500000 volume | 0 level
EURUSD: 1.10913 | 1000000 volume | 1 level
EURUSD: 1.10916 | 1000000 volume | 2 level
EURUSD: 1.10922 | 3000000 volume | 3 level
EURUSD: 1.10931 | 3500000 volume | 4 level
...
*/
x.onReady(() => {
x.getPriceHistory({
symbol:'EURUSD',
period: PERIOD_FIELD.PERIOD_M1
}).then(({candles, digits}) => {
console.log(candles.length)
console.log(candles[0])
console.log('digits = ' + digits)
})
})
x.onReady(() => {
x.Socket.send.tradeTransaction({
cmd: CMD_FIELD.BUY,
customComment: null,
expiration: x.serverTime + 5000,
offset: 0,
order: 0,
price: 1,
symbol: 'EURUSD',
tp: 0,
sl: 0,
type: TYPE_FIELD.OPEN,
volume: 1
}).then(({order}) => {
console.log('Success ' + order)
}).catch(e => {
console.error('Failed')
console.error(e)
})
})
x.onReady(() => {
x.Socket.send.tradeTransaction({
order: 1234, // position number you can find it in (x.positions)
type: TYPE_FIELD.MODIFY,
sl: 1.05, // new stop loss level
}).then(({order}) => {
console.log('Success ' + order)
}).catch(e => {
console.error('Failed')
console.error(e)
})
})
import {Logger4V2} from 'logger4'
const x = new XAPI({...loginConfig, logger: new Logger4V2()})
const info = new Writable()
info._write = ((chunk, encoding, next) => {
// you can bind 'info' logger
console.log(chunk.toString())
next()
})
x.logger.onStream('info', info)
const error = new Writable()
error._write = ((chunk, encoding, next) => {
// you can bind 'error' logger
console.error(chunk.toString())
next()
})
x.logger.onStream('error', error)
const debug = new Writable()
debug._write = ((chunk, encoding, next) => {
// you can bind 'debug' logger
console.log(chunk.toString())
next()
})
x.logger.onStream('debug', debug)
If you can contribute or you want to, feel free to do it at Buy me a coffee! :coffee:
FAQs
This project makes it possible to get data from Forex market, execute market or limit order with NodeJS/JS through WebSocket connection
The npm package xapi-node receives a total of 20 weekly downloads. As such, xapi-node popularity was classified as not popular.
We found that xapi-node demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.