| 182 | } |
| 183 | |
| 184 | const reqHandler = cb => (error, response, body) => { |
| 185 | Binance.info.lastRequest = new Date().getTime(); |
| 186 | if (response) { |
| 187 | Binance.info.statusCode = response.statusCode || 0; |
| 188 | if (response.request) Binance.info.lastURL = response.request.uri.href; |
| 189 | if (response.headers) { |
| 190 | Binance.info.usedWeight = response.headers['x-mbx-used-weight-1m'] || 0; |
| 191 | Binance.info.orderCount1s = response.headers['x-mbx-order-count-1s'] || 0; |
| 192 | Binance.info.orderCount1m = response.headers['x-mbx-order-count-1m'] || 0; |
| 193 | Binance.info.orderCount1h = response.headers['x-mbx-order-count-1h'] || 0; |
| 194 | Binance.info.orderCount1d = response.headers['x-mbx-order-count-1d'] || 0; |
| 195 | } |
| 196 | } |
| 197 | if (!cb) return; |
| 198 | if (error) return cb(error, {}); |
| 199 | if (response && response.statusCode !== 200) return cb(response, {}); |
| 200 | return cb(null, JSONbig.parse(body)); |
| 201 | } |
| 202 | |
| 203 | const proxyRequest = (opt, cb) => { |
| 204 | const req = request(addProxy(opt), reqHandler(cb)).on('error', (err) => { cb(err, {}) }); |