├── .gitignore ├── src ├── order_status │ └── index.js └── index.js ├── .eslintrc.js ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .vscode/ -------------------------------------------------------------------------------- /src/order_status/index.js: -------------------------------------------------------------------------------- 1 | let ORDER_STATUS = { 2 | NEW: 0, 3 | WAIT: 1, 4 | COMPLETE: 2, 5 | PARTIAL: 3, 6 | CANCEL: 4 7 | } 8 | 9 | module.exports = ORDER_STATUS 10 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "env": { 3 | "browser": true, 4 | "commonjs": true, 5 | "es6": true, 6 | "node": true 7 | }, 8 | "extends": "eslint:recommended", 9 | "globals": { 10 | "Atomics": "readonly", 11 | "SharedArrayBuffer": "readonly" 12 | }, 13 | "parserOptions": { 14 | "ecmaVersion": 2018 15 | }, 16 | "rules": { 17 | "indent": ["error", 2] 18 | } 19 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bitopro-api-node", 3 | "version": "3.1.0", 4 | "description": "BitoPro node.js SDK.", 5 | "main": "src", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/bitoex/bitopro-api-node.git" 12 | }, 13 | "keywords": [ 14 | "nodejs", 15 | "bitopro", 16 | "SDK", 17 | "cryptocurrency", 18 | "exchange" 19 | ], 20 | "author": "coopermilk123@gmail.com", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/bitoex/bitopro-api-node/issues" 24 | }, 25 | "homepage": "https://github.com/bitoex/bitopro-api-node#readme", 26 | "dependencies": { 27 | "axios": "^0.21.1" 28 | }, 29 | "devDependencies": { 30 | "eslint": "^5.16.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios') 2 | const crypto = require('crypto') 3 | const assert = require('assert') 4 | 5 | class BitoPro { 6 | constructor (apiKey, apiSecret, email) { 7 | this.apiKey = apiKey 8 | this.apiSecret = apiSecret 9 | this.email = email 10 | this.orderSides = ['sell', 'buy'] 11 | this.orderTypes = ['market', 'limit'] 12 | this.baseUrl = 'https://api.bitopro.com/v3' 13 | this.mobileBaseUrl = 'https://mobile-api.bitopro.com/v3' 14 | this.sdk = 'node' 15 | } 16 | 17 | async enableWatchingPrices () { 18 | let url = this.mobileBaseUrl + '/preference/watching/price/enable' 19 | const nonce = Date.now() 20 | const body = { identity: this.email, nonce } 21 | const payload = Buffer.from(JSON.stringify(body)).toString('base64') 22 | 23 | const signature = crypto 24 | .createHmac('sha384', this.apiSecret) 25 | .update(payload) 26 | .digest('hex') 27 | 28 | const options = { 29 | headers: { 30 | 'X-BITOPRO-APIKEY': this.apiKey, 31 | 'X-BITOPRO-PAYLOAD': payload, 32 | 'X-BITOPRO-SIGNATURE': signature, 33 | 'X-BITOPRO-API': this.sdk 34 | } 35 | } 36 | 37 | let res = await axios.patch(url, body, options) 38 | return res.data 39 | } 40 | 41 | async disableWatchingPrices () { 42 | let url = this.mobileBaseUrl + '/preference/watching/price/disable' 43 | const nonce = Date.now() 44 | const body = { identity: this.email, nonce } 45 | const payload = Buffer.from(JSON.stringify(body)).toString('base64') 46 | 47 | const signature = crypto 48 | .createHmac('sha384', this.apiSecret) 49 | .update(payload) 50 | .digest('hex') 51 | 52 | const options = { 53 | headers: { 54 | 'X-BITOPRO-APIKEY': this.apiKey, 55 | 'X-BITOPRO-PAYLOAD': payload, 56 | 'X-BITOPRO-SIGNATURE': signature, 57 | 'X-BITOPRO-API': this.sdk 58 | } 59 | } 60 | 61 | let res = await axios.patch(url, body, options) 62 | return res.data 63 | } 64 | 65 | async getWatchingPrices (pair = null) { 66 | let url = this.mobileBaseUrl + '/preference/watching/price/' + pair 67 | const nonce = Date.now() 68 | const body = { identity: this.email, nonce } 69 | const payload = Buffer.from(JSON.stringify(body)).toString('base64') 70 | 71 | const signature = crypto 72 | .createHmac('sha384', this.apiSecret) 73 | .update(payload) 74 | .digest('hex') 75 | 76 | const options = { 77 | headers: { 78 | 'X-BITOPRO-APIKEY': this.apiKey, 79 | 'X-BITOPRO-PAYLOAD': payload, 80 | 'X-BITOPRO-SIGNATURE': signature, 81 | 'X-BITOPRO-API': this.sdk 82 | } 83 | } 84 | 85 | let res = await axios.get(url, options) 86 | return res.data 87 | } 88 | 89 | async addWatchingPrice (pair = null, action = null, price = null) { 90 | assert(pair, 'Please provide pair') 91 | assert(action, `Action must be 'BUY' or 'SELL'`) 92 | assert(price, 'Please provide price in string format') 93 | let url = this.mobileBaseUrl + '/preference/watching/price/' + pair 94 | const nonce = Date.now() 95 | const body = { 96 | identity: this.email, 97 | nonce: nonce, 98 | action: action.toUpperCase(), 99 | price: price.toString() 100 | } 101 | const payload = Buffer.from(JSON.stringify(body)).toString('base64') 102 | 103 | const signature = crypto 104 | .createHmac('sha384', this.apiSecret) 105 | .update(payload) 106 | .digest('hex') 107 | 108 | const options = { 109 | headers: { 110 | 'X-BITOPRO-APIKEY': this.apiKey, 111 | 'X-BITOPRO-PAYLOAD': payload, 112 | 'X-BITOPRO-SIGNATURE': signature, 113 | 'X-BITOPRO-API': this.sdk 114 | } 115 | } 116 | 117 | let res = await axios.post(url, body, options) 118 | return res.data 119 | } 120 | 121 | async removeWatchingPrice (pair = null, action = null, price = null) { 122 | assert(pair, 'Please provide pair') 123 | assert(action, `Action must be 'BUY' or 'SELL'`) 124 | assert(price, 'Please provide price in string format') 125 | let url = this.mobileBaseUrl + `/preference/watching/price/${pair}/${action}/${price}` 126 | const nonce = Date.now() 127 | const body = { 128 | identity: this.email, 129 | nonce: nonce, 130 | action: action.toUpperCase(), 131 | price: price.toString() 132 | } 133 | const payload = Buffer.from(JSON.stringify(body)).toString('base64') 134 | 135 | const signature = crypto 136 | .createHmac('sha384', this.apiSecret) 137 | .update(payload) 138 | .digest('hex') 139 | 140 | const options = { 141 | headers: { 142 | 'X-BITOPRO-APIKEY': this.apiKey, 143 | 'X-BITOPRO-PAYLOAD': payload, 144 | 'X-BITOPRO-SIGNATURE': signature, 145 | 'X-BITOPRO-API': this.sdk 146 | } 147 | } 148 | 149 | let res = await axios.delete(url, options) 150 | return res.data 151 | } 152 | 153 | async getAccountBalances () { 154 | let url = this.baseUrl + '/accounts/balance' 155 | const nonce = Date.now() 156 | const body = { identity: this.email, nonce } 157 | const payload = Buffer.from(JSON.stringify(body)).toString('base64') 158 | 159 | const signature = crypto 160 | .createHmac('sha384', this.apiSecret) 161 | .update(payload) 162 | .digest('hex') 163 | 164 | const options = { 165 | headers: { 166 | 'X-BITOPRO-APIKEY': this.apiKey, 167 | 'X-BITOPRO-PAYLOAD': payload, 168 | 'X-BITOPRO-SIGNATURE': signature, 169 | 'X-BITOPRO-API': this.sdk 170 | } 171 | } 172 | 173 | let res = await axios.get(url, options) 174 | return res.data 175 | } 176 | 177 | async getOrderBook (pair, limit = 5) { 178 | assert(pair, 'Please provide pair') 179 | let url = `${this.baseUrl}/order-book/${pair}?limit=${limit}` 180 | const options = { 181 | headers: { 182 | 'X-BITOPRO-API': this.sdk 183 | } 184 | } 185 | 186 | let res = await axios.get(url, options) 187 | return res.data 188 | } 189 | 190 | async getTickers (pair = '') { 191 | let url = this.baseUrl + '/tickers/' + pair 192 | const options = { 193 | headers: { 194 | 'X-BITOPRO-API': this.sdk 195 | } 196 | } 197 | 198 | let res = await axios.get(url, options) 199 | return res.data 200 | } 201 | 202 | async getTrades (pair) { 203 | assert(pair, 'Please provide pair') 204 | let url = this.baseUrl + '/trades/' + pair 205 | const options = { 206 | headers: { 207 | 'X-BITOPRO-API': this.sdk 208 | } 209 | } 210 | 211 | let res = await axios.get(url, options) 212 | return res.data 213 | } 214 | 215 | async getOrderHistory () { 216 | assert(this.apiKey, 'Please provide api key') 217 | assert(this.apiSecret, 'Please provide api secret') 218 | let url = this.baseUrl + '/orders/history' 219 | 220 | const nonce = Date.now() 221 | const body = { identity: this.email, nonce } 222 | const payload = Buffer.from(JSON.stringify(body)).toString('base64') 223 | 224 | const signature = crypto 225 | .createHmac('sha384', this.apiSecret) 226 | .update(payload) 227 | .digest('hex') 228 | 229 | const options = { 230 | headers: { 231 | 'X-BITOPRO-APIKEY': this.apiKey, 232 | 'X-BITOPRO-PAYLOAD': payload, 233 | 'X-BITOPRO-SIGNATURE': signature, 234 | 'X-BITOPRO-API': this.sdk 235 | } 236 | } 237 | 238 | let res = await axios.get(url, options) 239 | return res.data 240 | } 241 | 242 | async getOrders (pair, active = true, page = 1) { 243 | assert(this.apiKey, 'Please provide api key') 244 | assert(this.apiSecret, 'Please provide api secret') 245 | assert(pair, 'Please provide pair') 246 | 247 | let url = this.baseUrl + '/orders/' + pair + '?active=' + active + '&page=' + page 248 | const nonce = Date.now() 249 | const body = { identity: this.email, nonce } 250 | const payload = Buffer.from(JSON.stringify(body)).toString('base64') 251 | 252 | const signature = crypto 253 | .createHmac('sha384', this.apiSecret) 254 | .update(payload) 255 | .digest('hex') 256 | 257 | const options = { 258 | headers: { 259 | 'X-BITOPRO-APIKEY': this.apiKey, 260 | 'X-BITOPRO-PAYLOAD': payload, 261 | 'X-BITOPRO-SIGNATURE': signature, 262 | 'X-BITOPRO-API': this.sdk 263 | } 264 | } 265 | 266 | let res = await axios.get(url, options) 267 | return res.data 268 | } 269 | 270 | async getOrder (pair, orderId) { 271 | assert(this.apiKey, 'Please provide api key') 272 | assert(this.apiSecret, 'Please provide api secret') 273 | assert(pair, 'Please provide pair') 274 | assert(orderId, 'Please provide order id') 275 | let url = this.baseUrl + `/orders/${pair}/${orderId}` 276 | 277 | const nonce = Date.now() 278 | const body = { identity: this.email, nonce } 279 | const payload = Buffer.from(JSON.stringify(body)).toString('base64') 280 | 281 | const signature = crypto 282 | .createHmac('sha384', this.apiSecret) 283 | .update(payload) 284 | .digest('hex') 285 | 286 | const options = { 287 | headers: { 288 | 'X-BITOPRO-APIKEY': this.apiKey, 289 | 'X-BITOPRO-PAYLOAD': payload, 290 | 'X-BITOPRO-SIGNATURE': signature, 291 | 'X-BITOPRO-API': this.sdk 292 | } 293 | } 294 | 295 | let res = await axios.get(url, options) 296 | return res.data 297 | } 298 | 299 | async createOrder (order) { 300 | assert(this.apiKey, 'Please provide api key') 301 | assert(this.apiSecret, 'Please provide api secret') 302 | assert(order.action, 'Please provide action field(side)') 303 | assert(order.amount, 'Please provide amount') 304 | assert(order.pair, 'Please provide pair') 305 | assert(order.price, 'Please provide price') 306 | assert(order.timestamp, 'Please provide timestamp') 307 | assert(this.orderSides.includes(order.action.toLowerCase()), 'Parameter `side` must be buy or sell') 308 | assert(order.type, 'Please provide type') 309 | assert(this.orderTypes.includes(order.type.toLowerCase()), 'Parameter `type` must be market or limit') 310 | 311 | let url = this.baseUrl + '/orders/' + order.pair 312 | 313 | const payload = Buffer.from(JSON.stringify(order)).toString('base64') 314 | 315 | const signature = crypto 316 | .createHmac('sha384', this.apiSecret) 317 | .update(payload) 318 | .digest('hex') 319 | 320 | const options = { 321 | headers: { 322 | 'X-BITOPRO-APIKEY': this.apiKey, 323 | 'X-BITOPRO-PAYLOAD': payload, 324 | 'X-BITOPRO-SIGNATURE': signature, 325 | 'X-BITOPRO-API': this.sdk 326 | } 327 | } 328 | 329 | let res = await axios.post(url, order, options) 330 | return res.data 331 | } 332 | 333 | async cancelOrder (pair, id) { 334 | assert(this.apiKey, 'Please provide api key') 335 | assert(this.apiSecret, 'Please provide api secret') 336 | assert(pair, 'Please provide pair') 337 | assert(id, 'Please provide order id') 338 | 339 | const nonce = Date.now() 340 | let url = this.baseUrl + '/orders/' + pair + '/' + id 341 | const body = { identity: this.email, nonce } 342 | const payload = Buffer.from(JSON.stringify(body)).toString('base64') 343 | 344 | const signature = crypto 345 | .createHmac('sha384', this.apiSecret) 346 | .update(payload) 347 | .digest('hex') 348 | 349 | const options = { 350 | headers: { 351 | 'X-BITOPRO-APIKEY': this.apiKey, 352 | 'X-BITOPRO-PAYLOAD': payload, 353 | 'X-BITOPRO-SIGNATURE': signature, 354 | 'X-BITOPRO-API': this.sdk 355 | }, 356 | data: body 357 | } 358 | let res = await axios.delete(url, options) 359 | return res.data 360 | } 361 | } 362 | 363 | module.exports = BitoPro 364 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bitopro-api-node 2 | 3 | [![npm version](https://badge.fury.io/js/bitopro-api-node.svg)](https://badge.fury.io/js/bitopro-api-node) 4 | 5 | SDK for the [BitoPro](https://www.bitopro.com/) API. 6 | 7 | [Bitopro official API document](https://developer.bitopro.com/docs) 8 | 9 | - [bitopro-api-node](#bitopro-api-node) 10 | - [Installation](#installation) 11 | - [Getting started](#getting-started) 12 | - [Limitations](#limitations) 13 | - [Rate Limit](#rate-limit) 14 | - [Precisions](#precisions) 15 | - [Minimum order amount](#minimum-order-amount) 16 | - [Public REST Endpoints](#public-rest-endpoints) 17 | - [getOrderBook](#getorderbook) 18 | - [getTickers](#gettickers) 19 | - [getTrades](#gettrades) 20 | - [Authenticated REST Endpoints](#authenticated-rest-endpoints) 21 | - [getAccountBalances](#getaccountbalances) 22 | - [getOrderHistory](#getorderhistory) 23 | - [getOrders](#getorders) 24 | - [createOrder](#createorder) 25 | - [cancelOrder](#cancelorder) 26 | - [getOrder](#getorder) 27 | - [Contributing](#contributing) 28 | - [License](#license) 29 | 30 | ### Installation 31 | 32 | npm install bitopro-api-node 33 | 34 | ### Getting started 35 | 36 | Create BitoPro client. Pass api keys only if 37 | you are going to do authenticated calls. You can create an api key 38 | [here](https://www.bitopro.com/api). 39 | 40 | ```js 41 | const BitoPro = require('bitopro-api-node') 42 | const bitopro = new BitoPro('your_api_key', 'your_api_secret', 'your_email') 43 | ``` 44 | 45 | ### Limitations 46 | 47 | #### Rate Limit 48 | 49 | There is rate limits applied to each API, please check [API documentation](https://developer.bitopro.com/docs) for more detail. 50 | 51 | #### Precisions 52 | 53 | Both price and amount are subject to decimal restrictions, please check [official settings](https://www.bitopro.com/fees) for more detail. 54 | 55 | #### Minimum order amount 56 | 57 | Checkout the [official settings](https://www.bitopro.com/fees) of minimum amount. 58 | 59 | 60 | ### Public REST Endpoints 61 | 62 | #### getOrderBook 63 | 64 | ```js 65 | let getOrderBook = async () => { 66 | try { 67 | let book = await bitopro.getOrderBook('btc_twd') 68 | console.log(book) 69 | } catch (e) { 70 | console.log(e) 71 | } 72 | } 73 | 74 | getOrderBook() 75 | ``` 76 | 77 |
78 | Output 79 | 80 | ```js 81 | { 82 | "bids": [ 83 | { 84 | "price": "180500", 85 | "amount": "0.12817687", 86 | "count": 1, 87 | "total": "0.12817687" 88 | }, 89 | { 90 | "price": "180010", 91 | "amount": "0.32292", 92 | "count": 2, 93 | "total": "0.45109687" 94 | }, 95 | { 96 | "price": "180000", 97 | "amount": "0.24236", 98 | "count": 3, 99 | "total": "0.69345687" 100 | } 101 | ], 102 | "asks": [ 103 | { 104 | "price": "180599", 105 | "amount": "0.00326056", 106 | "count": 1, 107 | "total": "0.00326056" 108 | }, 109 | { 110 | "price": "180600", 111 | "amount": "0.04202575", 112 | "count": 1, 113 | "total": "0.04528631" 114 | } 115 | ] 116 | } 117 | ``` 118 |
119 | 120 | #### getTickers 121 | 122 | ```js 123 | let getTickers = async () => { 124 | try { 125 | // all tickers 126 | let tickers = await bitopro.getTickers() 127 | console.log(tickers) 128 | 129 | // single ticker 130 | let ticker = await bitopro.getTickers('btc_twd') 131 | console.log(ticker) 132 | } catch (e) { 133 | console.log(e) 134 | } 135 | } 136 | 137 | getTickers() 138 | ``` 139 | 140 |
141 | Output 142 | 143 | ```js 144 | // all tickers 145 | { 146 | "data": [ 147 | { 148 | "pair": "xem_btc", 149 | "lastPrice": "0.00000098", 150 | "isBuyer": false, 151 | "priceChange24hr": "0", 152 | "volume24hr": "0.00000000", 153 | "high24hr": "0.00000098", 154 | "low24hr": "0.00000098" 155 | }, 156 | { 157 | "pair": "bch_eth", 158 | "lastPrice": "0.60010000", 159 | "isBuyer": false, 160 | "priceChange24hr": "0", 161 | "volume24hr": "0.00000000", 162 | "high24hr": "0.60010000", 163 | "low24hr": "0.60010000" 164 | }, 165 | { 166 | "pair": "eth_usdt", 167 | "lastPrice": "179.22000000", 168 | "isBuyer": true, 169 | "priceChange24hr": "10.85", 170 | "volume24hr": "925.14654180", 171 | "high24hr": "182.30000000", 172 | "low24hr": "159.94000000" 173 | } 174 | ] 175 | } 176 | 177 | // single ticker 178 | { 179 | "data": { 180 | "pair": "xem_eth", 181 | "lastPrice": "0.00010800", 182 | "isBuyer": false, 183 | "priceChange24hr": "0", 184 | "volume24hr": "0.00000000", 185 | "high24hr": "0.00010800", 186 | "low24hr": "0.00010800" 187 | } 188 | } 189 | ``` 190 | 191 |
192 | 193 | #### getTrades 194 | 195 | ```js 196 | let getTrades = async () => { 197 | try { 198 | let trades = await bitopro.getTrades('btc_twd') 199 | console.log(trades) 200 | } catch (e) { 201 | console.log(e) 202 | } 203 | } 204 | 205 | getTrades() 206 | ``` 207 | 208 |
209 | Output 210 | 211 | ```js 212 | { 213 | "data": [ 214 | { 215 | "timestamp": 1557203407, 216 | "price": "180500.00000000", 217 | "amount": "0.07717687", 218 | "isBuyer": false 219 | }, 220 | { 221 | "timestamp": 1557203187, 222 | "price": "180500.00000000", 223 | "amount": "0.05100000", 224 | "isBuyer": false 225 | }, 226 | { 227 | "timestamp": 1557203053, 228 | "price": "180500.00000000", 229 | "amount": "0.01860000", 230 | "isBuyer": false 231 | }, 232 | { 233 | "timestamp": 1557202804, 234 | "price": "180500.00000000", 235 | "amount": "0.04781533", 236 | "isBuyer": false 237 | }, 238 | { 239 | "timestamp": 1557202804, 240 | "price": "180500.00000000", 241 | "amount": "0.06000000", 242 | "isBuyer": false 243 | } 244 | ] 245 | } 246 | ``` 247 | 248 |
249 | 250 | ### Authenticated REST Endpoints 251 | 252 | #### getAccountBalances 253 | 254 | ```js 255 | let getAccountBalances = async () => { 256 | try { 257 | let balances = await bitopro.getAccountBalances() 258 | console.log(balances) 259 | } catch (e) { 260 | console.log(e) 261 | } 262 | } 263 | 264 | getAccountBalances() 265 | ``` 266 | 267 |
268 | Output 269 | 270 | ```js 271 | { 272 | "data": [ 273 | { 274 | "amount": "10001", 275 | "available": "1.0", 276 | "currency": "bito", 277 | "stake": "10000" 278 | }, 279 | { 280 | "amount": "0.0", 281 | "available": "1.0", 282 | "currency": "btc", 283 | "stake": "0" 284 | }, 285 | { 286 | "amount": "3.0", 287 | "available": "0.01", 288 | "currency": "eth", 289 | "stake": "0" 290 | }, 291 | { 292 | "amount": "30000", 293 | "available": "2500", 294 | "currency": "twd", 295 | "stake": "0" 296 | } 297 | ] 298 | } 299 | ``` 300 | 301 |
302 | 303 | #### getOrderHistory 304 | 305 | ```js 306 | let getOrderHistory = async () => { 307 | try { 308 | let history = await bitopro.getOrderHistory() 309 | console.log(history) 310 | } catch (e) { 311 | console.log(e) 312 | } 313 | } 314 | 315 | getOrderHistory() 316 | ``` 317 | 318 |
319 | Output 320 | 321 | ```js 322 | { 323 | "data": [ 324 | { 325 | "action": "buy", 326 | "avgExecutionPrice": "100000.00000000", 327 | "bitoFee": "0.00000000", 328 | "executedAmount": "1.00000000", 329 | "fee": "0.00100000", 330 | "feeSymbol": "BTC", 331 | "id": "123", 332 | "originalAmount": "1.00000000", 333 | "pair": "btc_twd", 334 | "price": "100000.00000000", 335 | "remainingAmount": "0.00000000", 336 | "status": 2, 337 | "timestamp": 1508753757000, 338 | "type": "limit" 339 | }, 340 | { 341 | "action": "buy", 342 | "avgExecutionPrice": "100000.00000000", 343 | "bitoFee": "0.00000000", 344 | "executedAmount": "1.00000000", 345 | "fee": "0.00200000", 346 | "feeSymbol": "BTC", 347 | "id": "456", 348 | "originalAmount": "1.00000000", 349 | "pair": "btc_twd", 350 | "price": "100000.00000000", 351 | "remainingAmount": "0.00000000", 352 | "status": 2, 353 | "timestamp": 1508753787000, 354 | "type": "limit" 355 | } 356 | ] 357 | } 358 | ``` 359 | 360 |
361 | 362 | #### getOrders 363 | 364 | ```js 365 | let getOrders = async () => { 366 | try { 367 | // only fetch active orders 368 | let orders = await bitopro.getOrders('bito_twd') 369 | console.log(orders) 370 | 371 | // include history orders 372 | orders = await bitopro.getOrders('bito_twd', false) 373 | console.log(orders) 374 | 375 | // with page parameter 376 | orders = await bitopro.getOrders('bito_twd', false, 1) 377 | console.log(orders) 378 | } catch (e) { 379 | console.log(e) 380 | } 381 | } 382 | 383 | getOrders() 384 | ``` 385 | 386 |
387 | Output 388 | 389 | ```js 390 | { 391 | "data": [ 392 | { 393 | "action": "buy", 394 | "avgExecutionPrice": "100000.00000000", 395 | "bitoFee": "0.00000000", 396 | "executedAmount": "1.00000000", 397 | "fee": "0.00100000", 398 | "feeSymbol": "BTC", 399 | "id": "123", 400 | "originalAmount": "1.00000000", 401 | "pair": "btc_twd", 402 | "price": "100000.00000000", 403 | "remainingAmount": "0.00000000", 404 | "status": 2, 405 | "timestamp": 1508753757000, 406 | "type": "limit" 407 | }, 408 | { 409 | "action": "buy", 410 | "avgExecutionPrice": "100000.00000000", 411 | "bitoFee": "0.00000000", 412 | "executedAmount": "1.00000000", 413 | "fee": "0.00200000", 414 | "feeSymbol": "BTC", 415 | "id": "456", 416 | "originalAmount": "1.00000000", 417 | "pair": "btc_twd", 418 | "price": "100000.00000000", 419 | "remainingAmount": "0.00000000", 420 | "status": 2, 421 | "timestamp": 1508753787000, 422 | "type": "limit" 423 | } 424 | ], 425 | "page": 1, 426 | "totalPages": 10 427 | } 428 | ``` 429 | 430 |
431 | 432 | #### createOrder 433 | 434 | ```js 435 | let createOrder = async () => { 436 | try { 437 | let order = { 438 | pair: 'btc_twd', 439 | action: 'buy', 440 | amount: '250', 441 | price: '0.000075', // no need for market orders 442 | timestamp: Date.now(), 443 | type: 'limit' // 'market' for market orders 444 | } 445 | let result = await bitopro.createOrder(order) 446 | console.log(result) 447 | } catch (e) { 448 | console.log(e) 449 | } 450 | } 451 | 452 | createOrder() 453 | ``` 454 | 455 |
456 | Output 457 | 458 | ```js 459 | { 460 | "action": "buy", 461 | "amount": "0.235", 462 | "orderId": "11233456", 463 | "price": "1.0", 464 | "timestamp": 1504262258000 465 | } 466 | ``` 467 | 468 |
469 | 470 | #### cancelOrder 471 | 472 | ```js 473 | let cancelOrder = async () => { 474 | try { 475 | let orderID = 123456 476 | let result = await bitopro.cancelOrder('btc_twd', orderID) 477 | console.log(result) 478 | } catch (e) { 479 | console.log(e) 480 | } 481 | } 482 | 483 | cancelOrder() 484 | ``` 485 | 486 |
487 | Output 488 | 489 | ```js 490 | { 491 | "action": "buy", 492 | "amount": 2.3, 493 | "orderId": "12234566", 494 | "price": 1.2, 495 | "timestamp": 1504262258000 496 | } 497 | ``` 498 | 499 |
500 | 501 | #### getOrder 502 | 503 | ```js 504 | let getOrder = async () => { 505 | try { 506 | let orderID = 123 507 | let result = await bitopro.getOrder('btc_twd', orderID) 508 | console.log(result) 509 | } catch (e) { 510 | console.log(e) 511 | } 512 | } 513 | 514 | getOrder() 515 | ``` 516 | 517 |
518 | Output 519 | 520 | ```js 521 | { 522 | "action": "sell", 523 | "avgExecutionPrice": "112000.00000000", 524 | "bitoFee": "103.70370360", 525 | "executedAmount": "1.00000000", 526 | "fee": "0.00000000", 527 | "feeSymbol": "TWD", 528 | "id": "123", 529 | "originalAmount": "1.00000000", 530 | "pair": "btc_twd", 531 | "price": "112000.00000000", 532 | "remainingAmount": "0.00000000", 533 | "status": 2, 534 | "timestamp": 1508753757000, 535 | "type": "limit" 536 | } 537 | ``` 538 | 539 |
540 | 541 | ## Contributing 542 | 543 | Bug reports and pull requests are welcome on GitHub at https://github.com/bitoex/bitopro-api-node and this project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. 544 | 545 | 1. Fork it 546 | 2. Create your feature branch (```git checkout -b my-new-feature```). 547 | 3. Commit your changes (```git commit -am 'Added some feature'```) 548 | 4. Push to the branch (```git push origin my-new-feature```) 549 | 5. Create new Pull Request 550 | 551 | ## License 552 | 553 | The SDK is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). --------------------------------------------------------------------------------