From ef0e4ee3501b418e6b29becd92db991e66aec5fb Mon Sep 17 00:00:00 2001 From: Alexander Hagen Date: Tue, 27 Feb 2024 11:52:57 +0000 Subject: [PATCH] Fix otherQuery requests. Change throw Error to throw Object --- lib/privateApi.js | 463 ++++++++-------------------------------------- lib/publicApi.js | 96 ++-------- package-lock.json | 4 +- package.json | 5 +- 4 files changed, 102 insertions(+), 466 deletions(-) diff --git a/lib/privateApi.js b/lib/privateApi.js index 32caa65..f2cb0de 100755 --- a/lib/privateApi.js +++ b/lib/privateApi.js @@ -17,7 +17,11 @@ var privateApi = module.exports = function(api) { HitbtcPrivate.prototype.query = async function(options) { var query="",sep="?"; - Object.keys(options.param).forEach(key => { query+=sep+key+"="+options.param[key];sep="&"; }); + + switch(options.method) { + case "GET": Object.keys(options.param).forEach(key => { query+=sep+key+"="+options.param[key];sep="&"; }); break; + default: break; + }; const stamp=Date.now().toString(), @@ -88,12 +92,7 @@ HitbtcPrivate.prototype.otherQuery = async function(method, path, query) { HitbtcPrivate.prototype.getSpotBalance = async function() { const path="/api/3/spot/balance"; const result=await this.getQuery(path,{}); - if(result.error) { - var err=result; -// var err=new Error(result.error); -// Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -101,77 +100,49 @@ HitbtcPrivate.prototype.getSpotOrders = async function(options={}) { var path="/api/3/spot/order",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.getSpotOrder = async function(order_id) { const path="/api/3/spot/order/" + order_id; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.createSpotOrder = async function(options={}) { var path="/api/3/spot/order"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.createSpotOrderList = async function(options={}) { var path="/api/3/spot/order/list"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.replaceSpotOrder = async function(order_id, options={}) { var path="/api/3/spot/order/" + order_id; const result=await this.otherQuery("PATCH",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.cancelSpotOrders = async function() { const path="/api/3/spot/order"; const result=await this.otherQuery("DELETE",path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.cancelSpotOrder = async function(order_id) { const path="/api/3/spot/order/" + order_id; const result=await this.otherQuery("DELETE",path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -179,11 +150,7 @@ HitbtcPrivate.prototype.getSpotFee = async function(symbol) { var path="/api/3/spot/fee"; if(symbol) { path+="/"+symbol; }; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -195,11 +162,7 @@ HitbtcPrivate.prototype.getSpotOrderHistory = async function(options={}) { var path="/api/3/spot/history/order",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -207,11 +170,7 @@ HitbtcPrivate.prototype.getSpotTradeHistory = async function(options={}) { var path="/api/3/spot/history/trade",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -222,44 +181,28 @@ HitbtcPrivate.prototype.getSpotTradeHistory = async function(options={}) { HitbtcPrivate.prototype.getMarginAccounts = async function() { const path="/api/3/margin/account"; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.getMarginAccount = async function(symbol) { const path="/api/3/margin/account/isolated/" + symbol; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.getCrossMarginAccount = async function(symbol) { const path="/api/3/margin/account/cross/" + symbol; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.createUpdateMarginAccount = async function(mode, instrument, options={}) { const path="/api/3/margin/account/"+mode+"/"+instrument; const result=await this.otherQuery("PUT",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -267,22 +210,14 @@ HitbtcPrivate.prototype.createUpdateMarginAccount = async function(mode, instrum HitbtcPrivate.prototype.closeMarginPositions = async function() { const path="/api/3/margin/position"; const result=await this.otherQuery("DELETE",path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.closeMarginPosition = async function(symbol,options={}) { const path="/api/3/margin/position/isolated/" + symbol; const result=await this.otherQuery("DELETE",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -290,88 +225,56 @@ HitbtcPrivate.prototype.getMarginOrders = async function(options={}) { var path="/api/3/margin/order",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.getMarginOrder = async function(order_id) { const path="/api/3/margin/order/" + order_id; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.createMarginOrder = async function(options={}) { const path="/api/3/margin/order"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.createMarginOrderList = async function(options={}) { const path="/api/3/margin/order/list"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.replaceMarginOrder = async function(order_id, options={}) { const path="/api/3/margin/order/" + order_id; const result=await this.otherQuery("PATCH",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.cancelMarginOrders = async function() { const path="/api/3/margin/order"; const result=await this.otherQuery("DELETE",path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.cancelMarginOrder = async function(order_id) { const path="/api/3/margin/order/" + order_id; const result=await this.otherQuery("DELETE",path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.getMarginConfig = async function() { const path="/api/3/margin/config"; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -383,11 +286,7 @@ HitbtcPrivate.prototype.getMarginOrderHistory = async function(options={}) { var path="/api/3/margin/history/order",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -395,11 +294,7 @@ HitbtcPrivate.prototype.getMarginTradeHistory = async function(options={}) { var path="/api/3/margin/history/trade",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -407,11 +302,7 @@ HitbtcPrivate.prototype.getMarginPositionsHistory = async function(options={}) { var path="/api/3/margin/history/positions",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -419,11 +310,7 @@ HitbtcPrivate.prototype.getMarginClearingDetails = async function(options={}) { var path="/api/3/margin/history/clearing",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -434,77 +321,49 @@ HitbtcPrivate.prototype.getMarginClearingDetails = async function(options={}) { HitbtcPrivate.prototype.getFuturesBalance = async function() { const path="/api/3/futures/balance"; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.getFuturesAccounts = async function() { const path="/api/3/futures/account"; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.getFuturesAccount = async function(symbol) { const path="/api/3/futures/account/isolated/" + symbol; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.getFuturesCrossAccount = async function(symbol) { const path="/api/3/futures/account/cross/" + symbol; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.createUpdateFuturesAccount = async function(mode,symbol,options={}) { const path="/api/3/futures/account/"+mode+"/"+symbol; const result=await this.otherQuery("PUT",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.closeFuturesPositions = async function() { const path="/api/3/futures/position"; const result=await this.otherQuery("DELETE",path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.closeFuturesPosition = async function(symbol,options={}) { const path="/api/3/futures/position/isolated/" + symbol; const result=await this.otherQuery("DELETE",path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -512,88 +371,56 @@ HitbtcPrivate.prototype.getFuturesOrders = async function(options={}) { var path="/api/3/futures/order",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.getFuturesOrder = async function(order_id) { const path="/api/3/futures/order/" + order_id; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.createFuturesOrder = async function(options={}) { const path="/api/3/futures/order"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.createFuturesOrderList = async function(options={}) { const path="/api/3/futures/order/list"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.replaceFuturesOrder = async function(order_id, options={}) { const path="/api/3/futures/order/" + order_id; const result=await this.otherQuery("PATCH",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.cancelFuturesOrders = async function() { const path="/api/3/futures/order"; const result=await this.otherQuery("DELETE",path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.cancelFuturesOrder = async function(order_id) { const path="/api/3/futures/order/" + order_id; const result=await this.otherQuery("DELETE",path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.getFuturesConfig = async function() { const path="/api/3/futures/config"; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -601,11 +428,7 @@ HitbtcPrivate.prototype.getFuturesFee = async function(symbol) { var path="/api/3/futures/fee"; if(symbol) { path+="/"+symbol; }; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -617,11 +440,7 @@ HitbtcPrivate.prototype.getFuturesOrderHistory = async function(options={}) { var path="/api/3/futures/history/order",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -629,11 +448,7 @@ HitbtcPrivate.prototype.getFuturesTradeHistory = async function(options={}) { var path="/api/3/futures/history/trade",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -641,11 +456,7 @@ HitbtcPrivate.prototype.getFuturesPositionsHistory = async function(options={}) var path="/api/3/futures/history/positions",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -653,11 +464,7 @@ HitbtcPrivate.prototype.getFuturesClearingDetails = async function(options={}) { var path="/api/3/futures/history/clearing",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -668,11 +475,7 @@ HitbtcPrivate.prototype.getFuturesClearingDetails = async function(options={}) { HitbtcPrivate.prototype.getWalletBalance = async function() { const path="/api/3/wallet/balance"; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -680,22 +483,14 @@ HitbtcPrivate.prototype.getDepositAddress = async function(options={}) { var path="/api/3/wallet/crypto/address",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.createDepositAddress = async function(options={}) { const path="/api/3/wallet/crypto/address"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -703,11 +498,7 @@ HitbtcPrivate.prototype.getRecentDepositAddresses = async function(options) { var path="/api/3/wallet/crypto/address/recent-deposit",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -715,88 +506,56 @@ HitbtcPrivate.prototype.getRecentWithdrawAddresses = async function(options) { var path="/api/3/wallet/crypto/address/recent-withdraw",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.withdrawCrypto = async function(options={}) { const path="/api/3/wallet/crypto/withdraw"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.convertCrypto = async function(options={}) { const path="/api/3/wallet/crypto/withdraw"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.withdrawCommit = async function(id) { const path="/api/3/wallet/crypto/withdraw/" + id; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.withdrawRollback = async function(id) { const path="/api/3/wallet/crypto/withdraw/" + id; const result=await this.otherQuery("DELETE",path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.checkMine = async function(addr) { const path="/api/3/wallet/crypto/address/check-mine/" + addr; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.transferExchange = async function(options={}) { const path="/api/3/wallet/transfer"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.transferInternal = async function(options={}) { const path="/api/3/wallet/internal/withdraw"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -804,44 +563,28 @@ HitbtcPrivate.prototype.getTransactions = async function(options={}) { var path="/api/3/wallet/transactions",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.getTransaction = async function(id) { const path="/api/3/wallet/transactions/" + id; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.checkOffchainAvailable = async function(options) { const path="/api/3/wallet/crypto/check-offchain-available"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.getWithdrawFees = async function(options) { const path="/api/3/wallet/crypto/fees/estimate"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -849,11 +592,7 @@ HitbtcPrivate.prototype.getWithdrawFee = async function(options) { var path="/api/3/wallet/crypto/fee/estimate",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -861,11 +600,7 @@ HitbtcPrivate.prototype.getAirDrops = async function(options={}) { var path="/api/3/wallet/airdrops",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -873,11 +608,7 @@ HitbtcPrivate.prototype.getAmountLocks = async function(options={}) { var path="/api/3/wallet/amount-locks",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -888,44 +619,28 @@ HitbtcPrivate.prototype.getAmountLocks = async function(options={}) { HitbtcPrivate.prototype.getSubaccounts = async function() { const path="/api/3/sub-account"; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.freezeSubaccount = async function(options={}) { const path="/api/3/sub-account/freeze"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.activateSubaccount = async function(options={}) { const path="/api/3/sub-account/activate"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.transferFunds = async function(options={}) { const path="/api/3/sub-account/transfer"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -933,43 +648,27 @@ HitbtcPrivate.prototype.getACL = async function(options={}) { var path="/api/3/sub-account/acl",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.changeACL = async function(options) { const path="/api/3/sub-account/acl"; const result=await this.otherQuery("POST",path,options); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.getSubaccountBalance = async function(id) { const path="/api/3/sub-account/balance/" + id; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; HitbtcPrivate.prototype.getSubaccountAddress = async function(id, currency) { var path="/api/3/sub-account/crypto/address/" + id + "/" + currency; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; diff --git a/lib/publicApi.js b/lib/publicApi.js index 0678d5f..1c91c3e 100755 --- a/lib/publicApi.js +++ b/lib/publicApi.js @@ -51,11 +51,7 @@ HitbtcPublic.prototype.getCurrency = async function(currencies) { var path="/public/currency"; if (currencies !== undefined) { path+="/"+currencies; }; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -66,11 +62,7 @@ HitbtcPublic.prototype.getSymbol = async function(symbols) { var path="/public/symbol"; if (symbols !== undefined) { path+="/"+symbols; }; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -81,11 +73,7 @@ HitbtcPublic.prototype.getTicker = async function(symbols) { var path="/public/ticker"; if (symbols !== undefined) { path+="/"+symbols; }; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -95,11 +83,7 @@ HitbtcPublic.prototype.getPrices = async function(options) { var path="/public/price/rate",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -109,11 +93,7 @@ HitbtcPublic.prototype.getPricesHistory = async function(options) { var path="/public/price/history",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -124,11 +104,7 @@ HitbtcPublic.prototype.getTickerLastPrices = async function(symbols) { var path="/public/price/ticker" ; if (symbols !== undefined) { path+="/"+symbols; }; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -140,11 +116,7 @@ HitbtcPublic.prototype.getTrades = async function(symbols,options={}) { if (symbols !== undefined) { path+="/"+symbols; }; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -156,11 +128,7 @@ HitbtcPublic.prototype.getOrderBook = async function(symbols,options={}) { if(symbols) { path+="/"+symbols; }; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -172,11 +140,7 @@ HitbtcPublic.prototype.getCandles = async function(symbols,options={}) { if(symbols) { path+="/"+symbols; }; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -188,11 +152,7 @@ HitbtcPublic.prototype.getConvertedCandles = async function(symbols,options={}) if(symbols) { path+="/"+symbols; }; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -203,11 +163,7 @@ HitbtcPublic.prototype.getFuturesInformation = async function(symbols) { var path="/public/futures/info"; if (symbols !== undefined) { path+="?symbols="+symbols; }; const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -218,11 +174,7 @@ HitbtcPublic.prototype.getFundingHistory = async function(options={}) { var path="/public/futures/history/funding",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -233,11 +185,7 @@ HitbtcPublic.prototype.getIndexPriceCandles = async function(options={}) { var path="/public/futures/candles/index_price",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -248,11 +196,7 @@ HitbtcPublic.prototype.getMarkPriceCandles = async function(options={}) { var path="/public/futures/candles/mark_price",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -263,11 +207,7 @@ HitbtcPublic.prototype.getPremiumIndexCandles = async function(options={}) { var path="/public/futures/candles/premium_index",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; @@ -278,11 +218,7 @@ HitbtcPublic.prototype.getOpenInterestCandles = async function(options={}) { var path="/public/futures/candles/open_interest",sep="?"; Object.keys(options).forEach(key => { path+=sep+key+"="+options[key]; sep="&"; }); const result=await this.getQuery(path,{}); - if(result.error) { - var err=new Error(result.error); - Object.assign(err,result); - throw err; - }; + if(result.error) { throw result; }; return result; }; diff --git a/package-lock.json b/package-lock.json index f23cd23..f1c988d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "node-api-hitbtc", - "version": "1.2.9", + "version": "1.2.10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "node-api-hitbtc", - "version": "1.2.9", + "version": "1.2.10", "license": "MIT", "dependencies": { "axios": "^1.6.7", diff --git a/package.json b/package.json index 0c0147c..5cae019 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-api-hitbtc", - "version": "1.2.9", + "version": "1.2.10", "description": "Non-official implementation of HitBTC's API's", "main": "index.js", "directories": { @@ -8,7 +8,8 @@ "lib": "lib" }, "scripts": { - "test": "jest --coverage --passWithNoTests --verbose" + "test": "jest --coverage --passWithNoTests --verbose", + "patch": "npm version patch --no-git-tag-version" }, "repository": { "type": "git",