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

@fraserdarwent/xapi-node

v1.0.0

Published

This project is made possible to get data from Forex market, execute market or limit order with NodeJS/JS through WebSocket connection

Downloads

8

Readme

Logo

Logo

xapi-node

This project is made 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.

Getting started

1. Install via npm

npm i xapi-node

2. Example usage

Authentication

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

Authentication only for XTB accounts

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

placing buy limit on BITCOIN [CFD]

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

placing buy limit on US30 (Dow Jones Industrial Average)

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

get live EURUSD price data changing

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
...
*/

get EURUSD M1 price history

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

market buy EURUSD (1.0 lot / 100000 EUR)

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

modify open position (for example set new stop loss)

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

How to use other log modules than Logger4

import Logger4 from 'logger4';

const logger = new Logger4({
    printEnabled: false,
    path: null,
    directorySizeLimitMB: null
});

const x = new XAPI({...loginConfig, logger});

x.logger.on((tag, log, type, params) => {
    // You can bind your log module here
    console.log({
        tag,
        log,
        type,
        params
    });
});

Donation

Now you can donate these projects with Bitcoin, HUF, USD

USD IBAN bank account: HU77 1201 1069 0166 6164 0020 0000 (SWIFT: UBRTHUHB)

HUF IBAN bank account: HU12 1177 3339 0142 1172 0000 0000 (SWIFT: OTPVHUHB)

BTC: 3Kng1TWvE8qzuoqYqeA2KmMcGucPZFJ75F www.blockchain.com