coinswitch-v2
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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

Package Sidebar

Install

npm i coinswitch-v2

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

20.8 kB

Total Files

9

Last publish

Collaborators

  • madhukm