All Projects → peterszombati → xapi-node

peterszombati / xapi-node

Licence: other
xStation5 Trading API for NodeJS/JS

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to xapi-node

ForEx
Using ML to create a ForEx trader to invest my personal finances to get rid of student debt
Stars: ✭ 17 (-52.78%)
Mutual labels:  trading, trading-api, forex-trading, forex-data
dukascopy-tools
✨ Download historical price tick data for Crypto, Stocks, ETFs, CFDs, Forex via CLI and Node.js ✨
Stars: ✭ 128 (+255.56%)
Mutual labels:  trading, forex, forex-data
Sequence-to-Sequence-Learning-of-Financial-Time-Series-in-Algorithmic-Trading
My bachelor's thesis—analyzing the application of LSTM-based RNNs on financial markets. 🤓
Stars: ✭ 64 (+77.78%)
Mutual labels:  trading, forex, forex-trading
Metatrader
Expert advisors, scripts, indicators and code libraries for Metatrader.
Stars: ✭ 99 (+175%)
Mutual labels:  trading, forex, forex-trading
EA31337-classes
📦📈 EA31337 framework (MQL library for writing trading Expert Advisors, indicators and scripts)
Stars: ✭ 103 (+186.11%)
Mutual labels:  trading, trading-api, forex
binaryapi
Binary.com & Deriv.com API for Python
Stars: ✭ 32 (-11.11%)
Mutual labels:  trading, forex, forex-trading
Median-and-Turbo-Renko-indicator-bundle
MQL5 header file for 'Median and Turbo renko indicator bundle' available for MT5 via MQL5 Market. The file lets you easily create a Renko EA in MT5 using the Median Renko indicator.
Stars: ✭ 68 (+88.89%)
Mutual labels:  forex, forex-trading
oanda api
A ruby client for the Oanda REST API.
Stars: ✭ 35 (-2.78%)
Mutual labels:  forex, forex-trading
mt4-expander
DLL extension for the MetaTrader MQL4 framework
Stars: ✭ 25 (-30.56%)
Mutual labels:  trading, forex
Mida
The open-source and cross-platform trading framework
Stars: ✭ 263 (+630.56%)
Mutual labels:  trading, forex
Trading Server
A multi-asset, multi-strategy, event-driven trade execution and management platform for running many algorithms/bots at many venues simultaneously with unified risk management and reporting. Uses MongoDB for storage and Telegram for user notifications/trade consent.
Stars: ✭ 191 (+430.56%)
Mutual labels:  trading, forex
gym-mtsim
A general-purpose, flexible, and easy-to-use simulator alongside an OpenAI Gym trading environment for MetaTrader 5 trading platform (Approved by OpenAI Gym)
Stars: ✭ 196 (+444.44%)
Mutual labels:  trading, forex
mt4-mql
MetaTrader MQL4 framework
Stars: ✭ 205 (+469.44%)
Mutual labels:  trading, forex
Algotrading
Algorithmic trading framework for cryptocurrencies.
Stars: ✭ 249 (+591.67%)
Mutual labels:  trading, trading-api
Jiji2
Forex algorithmic trading framework using OANDA REST API.
Stars: ✭ 211 (+486.11%)
Mutual labels:  trading, forex
ROandaAPI
R Code API for Forex Trading with OANDA Broker
Stars: ✭ 22 (-38.89%)
Mutual labels:  forex, forex-trading
Shioaji
Shioaji all new cross platform api for trading ( 跨平台證券交易API )
Stars: ✭ 203 (+463.89%)
Mutual labels:  trading, trading-api
ibkr
Interactive Brokers wrapper 🚩
Stars: ✭ 34 (-5.56%)
Mutual labels:  trading-api, forex-api
fhub
Python client for Finnhub API
Stars: ✭ 31 (-13.89%)
Mutual labels:  forex, forex-trading
hurtrade
An Open Source Forex Trading Platform
Stars: ✭ 22 (-38.89%)
Mutual labels:  trading, forex-trading

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.

Used by

Price moving

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 {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)

Buy Me A Coffee!

If you can contribute or you want to, feel free to do it at Buy me a coffee!

Be careful and donate just if it is within your possibilities, because there is no refund system. And remember that you don't need to donate, it is just a free choice for you. Thank you!
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].