How to use ccxt - 10 common examples

To help you get started, we’ve selected a few ccxt 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 michnovka / ccxt-trading-cp / config-reader.js View on Github external
if(config_object.exchanges_unencrypted[i].inactive)
                        module.exports.exchanges_inactive[exchange_id] = exchange;
                    else
                        module.exports.exchanges[exchange_id] = exchange;
                }
            }
        }

        let default_exchange_for_fiat = 'okcoinusd';

        if(config_object.hasOwnProperty('exchange_for_fiat'))
            default_exchange_for_fiat = config_object.exchange_for_fiat;

        module.exports.exchange_for_fiat = new ccxt[default_exchange_for_fiat]();

        module.exports.coinmarketcap = new ccxt.coinmarketcap();

    }catch (e){
        // invalid config file
        console.log(e);
        process.exit();
    }

    return true;

}
github atanasster / crypto-grommet / server / models / exchanges.js View on Github external
import ccxt from 'ccxt';
import { sleep } from '../api/utils';

export const exchanges = ccxt.exchanges.map((exchangeId) => {
  const exchange = new ccxt[exchangeId]();
  exchange.loadMarkets()
  // eslint-disable-next-line no-unused-vars
    .then((markets) => {
      // console.log(markets);
    })
    .catch(() => {
      console.log('ERROR : loadMarkets', exchangeId);
      return sleep();
    });
  return exchange;
});

const baseExchangeInfo = (exchange) => {
  const countries = typeof exchange.countries === 'string' ? [exchange.countries] : exchange.countries;
  return {
github atanasster / grommet-nextjs / server / graphql / crypto / models / exchanges.js View on Github external
id: exchange.id,
      name: exchange.name,
      logo: exchange.urls ? exchange.urls.logo : null,
      url,
      hasOrderBook: exchange.has.fetchOrderBook,
      countries: countries.map(c => (c === 'UK' ? 'GB' : c)),
      fees,
      currencies: exchange.currencies ? Object.keys(exchange.currencies).map(key =>
        (exchange.currencies[key])) : [],
      markets: exchange.markets ?
        Object.keys(exchange.markets).map(key => (exchange.markets[key])) : [],
    };
  };

  const exchanges = [];
  ccxt.exchanges.forEach((exchangeId) => {
    const exchange = new ccxt[exchangeId]();
    exchange.loadMarkets()
    // eslint-disable-next-line no-unused-vars
      .then((markets) => {
        exchanges.push(baseExchangeInfo(exchange));
      })
      .catch(() => {
        console.log('ERROR : loadMarkets', exchangeId);
        return sleep();
      });
  });
  exchanges.push({ id: 'CCCAGG', name: 'CCCAGG', countries: [] });
  module.exports.exchangeObj = (exchange) => {
    const exch = exchanges.find(item => item.name === exchange);
    if (exch) {
      return new ccxt[exch.id]();
github pRoy24 / tokencaps / models / APIStorage / Exchange / ExchangeList.js View on Github external
getMarketExchangeByToken() {
    let exchangeNormalizedArray = [];

    function marketCallback(responseData) {
      return responseData;
    }

    ccxt.exchanges.forEach(function (exchangeName, exIdx, exchangeArr) {
      try {
        let currentExchange = markets.getExchangeInstance(exchangeName);
        currentExchange.fetchMarkets().then(function (exchangeMarket) {
          let exchangeRows = [];
          let timeStamp = Date.now();
          Object.keys(exchangeMarket).forEach(function (marketKey) {
            exchangeRows.push({
              "base": exchangeMarket[marketKey].base, "quote": exchangeMarket[marketKey].quote,
              "symbol": exchangeMarket[marketKey].symbol, "market": exchangeName,
              "timestamp": timeStamp
            })
          });
          exchangeNormalizedArray = exchangeNormalizedArray.concat(MarketUtils.mergeQuotesForBaseInExchange(exchangeRows));
          // console.log(exchangeNormalizedArray.length);
          if (exIdx === exchangeArr.length - 1) {
            marketCallback(MarketUtils.groupCoinByMarketMaps(exchangeNormalizedArray));
github ccxt / ccxt / example.js View on Github external
let ccxt = require ('ccxt')

// all examples are here: https://github.com/ccxt/ccxt/tree/master/examples
// this is for the runkit: https://npm.runkit.com/ccxt

let exchange = new ccxt.bitfinex ({
    apiKey: '4FlEDtxDl35gdEiobnfZ72vJeZteE4Bb7JdvqzjIjHq',
    secret: 'D4DXM8DZdHuAq9YptUsb42aWT1XBnGlIJgLi8a7tzFH',
})

await exchange.loadMarkets ()
console.log (exchange.symbols)

let symbol = exchange.symbols[0]
console.log (symbol)

let ticker = await exchange.fetchTicker (symbol)
console.log (ticker)

let orderbook = await exchange.fetchOrderBook (symbol)
console.log (orderbook)
github magic8bot / magic8bot / src / seed / chaos.exchange.ts View on Github external
public async cancelOrder(orderId: string) {
    const order = this.orders.get(Number(orderId))
    if (!order) return null
    if (order.status === 'canceled' || order.status === 'closed') throw new OrderNotFound('Nah.')

    await this.checkOrderCompletion(order)

    const updatedOrder = this.orders.get(Number(orderId))
    if (updatedOrder.status === 'closed') throw new OrderNotFound('Nah.')

    const [a, c] = updatedOrder.symbol.split('/')
    if (updatedOrder.side === 'bid') {
      const cost = updatedOrder.remaining * order.price
      const currency = this.balances.get(c)
      this.balances.set(c, currency + cost)
    } else {
      const asset = this.balances.get(a)

      this.balances.set(a, asset + updatedOrder.remaining)
    }

    const canceledOrder: Order = { ...updatedOrder, status: 'canceled' }
    this.orders.set(order.id, canceledOrder)

    // @ts-ignore
github pRoy24 / tokencaps / models / ExchangeModels.js View on Github external
listExchangeMetadata: function() {
    var actions = ccxt.exchanges.map(getExchangeMetadata);
    var results = Promise.all(actions); // pass array of promises
    return results.then(function(response){
      return response;
    }).catch(function(err){
      return err;
    });
  },
github mxaddict / mmaker / src / engine.js View on Github external
async start () {
    // Check exchange
    if (!ccxt.exchanges.includes(this.exchange)) {
      log.bright.red.error(`Exchange "${this.exchange}" is not supported YET`)
      return false
    }

    // Load the exchange
    log.cyan(`Using Exchange "${this.exchange}"`)
    this.exchange = new ccxt[this.exchange](config.get(this.exchange))

    // Save the markets and marketsInfo
    this.marketsInfo = await this.exchange.loadMarkets()
    this.markets = Object.keys(this.marketsInfo)

    // Check if we selected a market/pair that is valid
    if (!this.markets.includes(this.market)) {
      log.bright.red.error(`Market "${this.market}" is not supported YET`)
      return false
github pRoy24 / tokencaps / models / ExchangeModels.js View on Github external
getExchangeDetailsList: function() {
    var actions = ccxt.exchanges.map(getExchangeDetails);
    var results = Promise.all(actions); // pass array of promises
    return results.then(function(response){
      return response;
    });
  },
github Pyeskyhigh / DACP / balanceDataset.js View on Github external
async function findPriceUSD(exchange, coinName){

  //Preset the Bitfinex access
  let bitfinexExchange = new ccxt ['bitfinex'] ({
    apiKey: eval(`process.env.` + 'bitfinex' + `_apiKey`),
    secret: eval(`process.env.` + 'bitfinex' + `_secret`)
  });

  path = [];
  symbol = coinName + '/USD';
  allSymbols = await findSymbols(exchange);
  found = false;

  // If the asset is USD (Should check if in other currency as well)
  if(coinName === 'USD'){ // Should not be necessary
    path.push('USD');
    return await findBalance(exchange, 'USD');
  }

  //Checks if there is a connection straight to USD