Browser and Node.js Coinswitch.co API v2 client
Easily exchange crypto coins with few lines of code.
npm install --save coinswitch-v2
/** 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: "..."}
Get your api-key from the coinswitch API page.
For more examples look into the __tests__
folder on GitHub.
npm test
The snippet of test coverage of all the Dynamic APIs is seen below:
MIT