Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/roccomuso/coinswitch
Coinswitch.co fully tested node and browser API client
https://github.com/roccomuso/coinswitch
api assets bitcoin btc client coinswitch exchange javascript js nodejs
Last synced: 17 days ago
JSON representation
Coinswitch.co fully tested node and browser API client
- Host: GitHub
- URL: https://github.com/roccomuso/coinswitch
- Owner: roccomuso
- License: mit
- Created: 2018-11-16T16:09:19.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-04-28T21:14:48.000Z (over 2 years ago)
- Last Synced: 2024-10-24T13:50:28.999Z (21 days ago)
- Topics: api, assets, bitcoin, btc, client, coinswitch, exchange, javascript, js, nodejs
- Language: JavaScript
- Homepage:
- Size: 229 KB
- Stars: 17
- Watchers: 4
- Forks: 4
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# coinswitch [![NPM Version](https://img.shields.io/npm/v/coinswitch.svg)](https://www.npmjs.com/package/coinswitch) ![node](https://img.shields.io/node/v/coinswitch.svg) [![Dependency Status](https://david-dm.org/roccomuso/coinswitch.png)](https://david-dm.org/roccomuso/coinswitch) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) [](https://github.com/roccomuso/coinswitch)
> Browser and Node.js [Coinswitch.co](https://coinswitch.com) API client
Easily exchange assets with few lines of code.
## Install
npm install --save coinswitch
## Usage
```javascript
const Coinswitch = require('coinswitch');(async () => {
const cs = new Coinswitch({
apiKey: '',
userIP: '1.1.1.1'
})const coinsList = await cs.getCoins()
console.log(coinsList)
/*
[
{
"symbol": "btc",
"name": "Bitcoin",
"isActive": true
},
{
"symbol": "ltc",
"name": "Litecoin",
"isActive": true
},
{
"symbol": "bch",
"name": "Bitcoin Cash",
"isActive": true
},
...
]
*/
})()
```### Make an exchange order
```javascript
const cs = new Coinswitch({
apiKey: '',
userIP: '1.1.1.1'
})const {
offerReferenceId,
depositCoinAmount,
destinationCoinAmount
} = await cs.generateOffer('btc', 'ltc', 0.03)const {
orderId,
exchangeAddress: { address }
} = await cs.makeOrder({
depositCoin: 'btc',
destinationCoin: 'ltc',
depositCoinAmount,
offerReferenceId,
userReferenceId: 'test-user',
destinationAddress: { address: 'LXdmzmqSALB1DbJyA43b6prQCXKn1J6SdV' },
refundAddress: { address: '1KcuzqzcvkpY3K8eoNgmKbqhFvoeQXAoPa' }
})console.log(`
=========
Order ID: ${orderId}
Deposit: BTC (${depositCoinAmount})
Receive: LTC (${destinationCoinAmount})
Exchange Address: ${address}
=========
`)
```**NB**: Addresses must be specified as a JS Object like `{address: "...", tag: "..."}`
### Methods
**Get your *api-key* from the [coinswitch API page](https://coinswitch.co/site/api)**.
- `new CoinSwitch()`: The class constructor requires an Object like `{ apiKey: "...", userIP: "..."}`.
|Method Name|Return|Description|
|:-----|:-----:|-----------|
|`.version()`|`String`|Return API version being used|
|`.getCoins()`|`Array`|Get list of supported coins as obj `{symbol, name, isActive}`|
|`.isCoinActive()`|`Boolean`|Given a symbol (ex. `btc`) return `true`/`false` wether the coin is active or not|
|`.getDestinationCoins()`|`Array`|Return list of available destination coins for the one provided|
|`.getDepositCoins()`|`Array`|Return list of depositable coins for the one provided|
|`.getExchangeLimit(, )`|`Object`|Get exchange limits for a depositCoin and destinationCoin|
|`.generateOffer(, , )`|`Object`|Generate an exchange offer for a coin pair|
|`.makeOrder(*)`|`Object`|Creates a new tx for an offer. It will return transaction object with an `order_id` field to track the tx status.|
|`.getOrder()`|`Object`|Get status of the given Order ID string.|`*` makeOrder input object sample:
```js
{
depositCoin: 'btc',
destinationCoin: 'ltc',
depositCoinAmount: 0.03,
offerReferenceId: "...", // get it from generateOffer(..)
userReferenceId: 'test-user',
destinationAddress: { address: 'LXdmzmqSALB1DbJyA43b6prQCXKn1J6SdV' },
refundAddress: { address: '1KcuzqzcvkpY3K8eoNgmKbqhFvoeQXAoPa' }
}
```## Example
For more examples look at the unit `test/` folder.
## Test
> npm test
## Debug
To enable debug set the env var `DEBUG=coinswitch`
# License
MIT