How to use binance-api-node - 10 common examples

To help you get started, we’ve selected a few binance-api-node examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jsappme / node-binance-trader / trader.js View on Github external
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////

const app = express()
app.get('/', (req, res) => res.send(""))
app.listen(process.env.PORT || 8003, () => console.log('NBT auto trader running.'.grey))

//////////////////////////////////////////////////////////////////////////////////

let trading_pairs = {}
let buy_prices = {}
let user_payload = []

//////////////////////////////////////////////////////////////////////////////////

const binance_client = binance({
    apiKey: 'replace_with_your_Binance_apiKey',
    apiSecret: 'replace_with_your_Binance_apiSecret',
})

//////////////////////////////////////////////////////////////////////////////////
const nbt_vers = "0.2.0"
// Retrieve previous open trades //
axios.get('https://bitcoinvsaltcoins.com/api/useropentradedsignals?key=' + bva_key )
.then( (response) => {
    response.data.rows.map( s => {
        trading_pairs[s.pair+s.stratid] = true
        buy_prices[s.pair+s.stratid] = new BigNumber(s.buy_price)
    })
    console.log("Open Trades:", _.values(trading_pairs).length)
})
.catch( (e) => {
github stockmlbot / DataSynchronizer / src / exchange / ws_exchanges / binance_ws.js View on Github external
"use strict"

const util = require("../../utils")
const Emitter = require("../../emitter/emitter")

// Binance things
const exchange_name = "binance"
const default_interval = 60

const Binance = require("binance-api-node").default
const client = new Binance()
// Binance things

const open_socket = async (symbol, interval = default_interval) => {
  interval = util.interval_toString(interval)

  let socket_candle = await client.ws.candles(symbol, interval, (candle) => {
    Emitter.emit("CandleUpdate", exchange_name, interval, candle)

    if (candle.isFinal == true) {
      Emitter.emit("CandleUpdateFinal", exchange_name, interval, candle)
    }
  })

  let socket_trades = await client.ws.aggTrades(symbol, (trade) => {
    trade = {
      time: trade.eventTime,
github jsappme / node-binance-trader / index.js View on Github external
let stop_price = 0.00
let loss_price = 0.00
let sell_price = 0.00
let buy_amount = 0.00
let stepSize = 0
let tickSize = 8
let tot_cancel = 0
let pair = ""
let buying_method = ""
let selling_method = ""
let init_buy_filled = false

//////////////////////////////////////////////////////////////////////////////////

// Binance API initialization //
const client = binance({apiKey: APIKEY, apiSecret: APISECRET, useServerTime: true})

const conf = new Configstore('nbt')
let base_currency = conf.get('nbt.base_currency')?conf.get('nbt.base_currency'):"USDT"
let budget = conf.get('nbt.budget')?parseFloat(conf.get('nbt.budget')):1.00
let fixed_buy_price = conf.get('nbt.fixed_buy_price')?parseFloat(conf.get('nbt.fixed_buy_price')):0.00
let currency_to_buy = conf.get('nbt.currency_to_buy')?conf.get('nbt.currency_to_buy'):"BTC"
let profit_pourcent = conf.get('nbt.profit_pourcent')?conf.get('nbt.profit_pourcent'):0.80
let loss_pourcent = conf.get('nbt.loss_pourcent')?conf.get('nbt.loss_pourcent'):0.40
let trailing_pourcent = conf.get('nbt.trailing_pourcent')?conf.get('nbt.trailing_pourcent'):0.40

clear()

console.log(chalk.yellow(figlet.textSync('_N_B_T_', { horizontalLayout: 'fitted' })))
console.log(' ')
console.log(" 🐬 ".padEnd(10) + '                   ' + " 🐬 ".padStart(11))
console.log(" 🐬 ".padEnd(10) + chalk.bold.underline.cyan('Node Binance Trader') + " 🐬 ".padStart(11))
github andrewmahoneyf / CryptoBot / api / binance.js View on Github external
import 'dotenv/config';
import Binance from 'binance-api-node';

/* Authenticated client, can make signed calls */
export const client = Binance({
  apiKey: process.env.API_KEY,
  apiSecret: process.env.API_SECRET,
});

/* Public REST Endpoints */

// Get the current exchange trading rules and symbol information.
export const exchangeInfo = client.exchangeInfo();
// Get the order book for a symbol.
export const book = (symbol, limit = 5) => client
  .book({ symbol, limit })
  .then(res => res)
  .catch(error => error);
// Retrieves Candlestick for a symbol. Candlesticks are uniquely identified by their open time.
export const candles = (symbol, interval = '1h', limit = 500) => client
  .candles({ symbol, interval, limit })
github jsappme / node-binance-trader / server.js View on Github external
console.log("Connecting to the Postgresql db...")
    pg_client = new Client({
        ssl: pg_connectionSSL,
        connectionString: pg_connectionString,
    })
    pg_client.connect()
}
//////////////////////////////////////////////////////////////////////////////////

const server = express()
    .use((req, res) => res.sendFile(INDEX) )
    .listen(PORT, () => console.log(`NBT server running on port ${ PORT }`))

//////////////////////////////////////////////////////////////////////////////////

const binance_client = binance()

//////////////////////////////////////////////////////////////////////////////////

async function run() {
    //pairs = await get_pairs()
    //pairs = pairs.slice(0, tracked_max)
    pairs.unshift('BTCUSDT')
    pairs.unshift('ETHBTC')
    console.log(" ")
    console.log("Total pairs: " + pairs.length)
    console.log(" ")
    console.log(JSON.stringify(pairs))
    console.log(" ")
    await sleep(wait_time)
    await trackData()
}
github cryptocontrol / algo-trading-server / dist / exchanges / Binance.js View on Github external
startListening() {
        const client = binance_api_node_1.default();
        client.ws.trades(['BTCUSDT'], trade => this.onPriceUpdate('BTCUSDT', Number(trade.price)));
    }
}
github passabilities / crypto-exchange / src / exchanges / binance.js View on Github external
constructor({key, secret}) {
    this.binance = Api({
      apiKey: key,
      apiSecret: secret
    })

  }
github tony-ho / binance-oco / src / binance-oco.ts View on Github external
throw result.error;
  }

  const { pair, cancelPrice, nonBnbFees } = options;

  let {
    amount,
    buyPrice,
    buyLimitPrice,
    stopPrice,
    stopLimitPrice,
    targetPrice,
    scaleOutAmount
  } = options;

  const binance = Binance({
    apiKey: process.env.APIKEY || "",
    apiSecret: process.env.APISECRET || ""
  });

  let isCancelling = false;

  const cancelOrderAsync = async (
    symbol: string,
    orderId: number
  ): Promise => {
    if (!isCancelling) {
      isCancelling = true;
      try {
        const response = await binance.cancelOrder({ symbol, orderId });

        debug("Cancel response: %o", response);

binance-api-node

A node API wrapper for Binance

MIT
Latest version published 1 year ago

Package Health Score

54 / 100
Full package analysis

Popular binance-api-node functions

Similar packages