1.0.2 • Published 3 years ago

coinswitch-v2 v1.0.2

Weekly downloads
105
License
MIT
Repository
github
Last release
3 years ago

coinswitch-v2 GitHub license GitHub top language David

Browser and Node.js Coinswitch.co API v2 client

Easily exchange crypto coins with few lines of code.

Install

npm install --save coinswitch-v2

Usage

/** import { CoinSwitchDynamic } from 'coinswitch-v2' */ // Typescript import
const { CoinSwitchDynamic } = require('coinswitch-v2')

;(async () => {
  const cs = new CoinSwitchDynamic({
    apiKey: '<YOUR API KEY>',
    userIP: '<YOUR IP>' // Default is 1.1.1.1
  })

  // Get all coins you can trade
  const coins = await cs.getCoins()
  console.log(coins)

  // Generate an exchange offer for for a coin pair
  const rate = await cs.getExchangeRate({
    depositCoin: 'btc',
    destinationCoin: 'eth',
    depositCoinAmount: 0.03
  })
  console.log(rate)

  // Make a trade order
  const order = await cs.createOrder({
    depositCoin: 'btc',
    destinationCoin: 'eth',
    depositCoinAmount: 0.03,
    destinationAddress: {
      address: '0xcc1bf6b0625bc23895a47f4991fdb7862e34a563'
    },
    refundAddress: {
      address: '0xcc1bf6b0625bc23895a47f4991fdb7862e34a563'
    }
  })

  console.log(order)
})()

NB: Addresses must be specified as a JS Object like {address: "...", tag: "..."}

API KEY

Get your api-key from the coinswitch API page.

Example

For more examples look into the __tests__ folder on GitHub.

Test

npm test

License

MIT