ts-crypto-cli

A handy npm cli to operate against some of the most known Crypto Exchanges


Keywords
kraken, api, btc, bitcoin, ts, typescript, binance, cryptocurrency-exchanges, hitbtc
License
CC0-1.0
Install
npm install ts-crypto-cli@0.9.7

Documentation

TS Crypto Cli

A handy npm to operate against some of the most known Crypto Exchanges

Environment Variables

# Each REST request/response is recorded to a log file
TS_CRYPTO_CLI_LOGS_PATH=D:\DESKTOP\ts-crypto-cli_logs

KRAKEN_API_KEY=<...>
KRAKEN_API_SECRET=<...>

HITBTC_API_KEY=<...>
HITBTC_API_SECRET=<...>

BINANCE_API_KEY=<...>
BINANCE_API_SECRET=<...>

Use it as a library

  • yarn add ts-crypto-cli

REST APIs

WS APIs

Handling multiple API credentials

You can handle different API keys/secrets under the same exchange. Generate the new API client instances with the following methods:

Demo

Here is a little handler to perform a 2-steps withdrawal from Kraken in 20 lines of code using the lib.

import { krakenPrivateApiRequest } from 'ts-crypto-cli';

const krakenWithdrawAsset = async (asset: string, key: string, withdrawAmount: number): Promise<void> => {

  const withdrawInfo = await krakenPrivateApiRequest({ url: 'WithdrawInfo', data: {
      asset,
      key,
      amount: withdrawAmount
  }})

  const { limit } = withdrawInfo

  if (Number(limit) < Number(withdrawAmount)) {
    throw new Error(`Can´t withdraw ${withdrawAmount} ${asset}. Max. available ${limit}`)
  }

  krakenPrivateApiRequest({ url: 'Withdraw', data: {
    asset,
    key,
    amount: withdrawAmount
  }})
};

export {
  krakenWithdrawAsset
}

Launch the REPL cli on a shell

With a .env file

Update the .env file with your own credentials and run

  • yarn start:env

Inject your keys/secrets to enable private methods

This method is more secure as you don´t persist the KEYS on the file

Powershell (windows)

  • $env:KRAKEN_API_KEY="<...>" ; $env:KRAKEN_API_SECRET="<...>" ; $env:HITBTC_API_KEY="<...>" ; etc... ; yarn start

cmd (windows)

  • set KRAKEN_API_KEY=<...> & set KRAKEN_API_SECRET=<...> & set HITBTC_API_KEY=<...> $ etc... & yarn start

Unix/OSx

  • KRAKEN_API_KEY=<...> KRAKEN_API_SECRET=<...> HITBTC_API_KEY=<...> yarn start