UNPKG

bitso-bert-api

Version:

<h1 align="center">bitso-bert-api</h1>

3 lines (2 loc) 15.3 kB
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var r=t(require("crypto")),e=t(require("camelcase-keys")),n=t(require("node-fetch"));function o(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function i(t){return function(){var r=this,e=arguments;return new Promise((function(n,i){var a=t.apply(r,e);function c(t){o(a,n,i,c,u,"next",t)}function u(t){o(a,n,i,c,u,"throw",t)}c(void 0)}))}}function a(){return(a=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t}).apply(this,arguments)}var c,u=(function(t){var r=function(t){var r=Object.prototype,e=r.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{c({},"")}catch(t){c=function(t,r,e){return t[r]=e}}function u(t,r,e,n){var o=Object.create((r&&r.prototype instanceof d?r:d).prototype),i=new E(n||[]);return o._invoke=function(t,r,e){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var c=_(a,e);if(c){if(c===l)continue;return c}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===n)throw n="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n="executing";var u=s(t,r,e);if("normal"===u.type){if(n=e.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:e.done}}"throw"===u.type&&(n="completed",e.method="throw",e.arg=u.arg)}}}(t,e,i),o}function s(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l={};function d(){}function f(){}function h(){}var p={};p[o]=function(){return this};var v=Object.getPrototypeOf,y=v&&v(v(O([])));y&&y!==r&&e.call(y,o)&&(p=y);var g=h.prototype=d.prototype=Object.create(p);function m(t){["next","throw","return"].forEach((function(r){c(t,r,(function(t){return this._invoke(r,t)}))}))}function b(t,r){var n;this._invoke=function(o,i){function a(){return new r((function(n,a){!function n(o,i,a,c){var u=s(t[o],t,i);if("throw"!==u.type){var l=u.arg,d=l.value;return d&&"object"==typeof d&&e.call(d,"__await")?r.resolve(d.__await).then((function(t){n("next",t,a,c)}),(function(t){n("throw",t,a,c)})):r.resolve(d).then((function(t){l.value=t,a(l)}),(function(t){return n("throw",t,a,c)}))}c(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function _(t,r){var e=t.iterator[r.method];if(void 0===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=void 0,_(t,r),"throw"===r.method))return l;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=s(e,t.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,l;var o=n.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,l):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,l)}function w(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function x(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(w,this),this.reset(!0)}function O(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function r(){for(;++n<t.length;)if(e.call(t,n))return r.value=t[n],r.done=!1,r;return r.value=void 0,r.done=!0,r};return i.next=i}}return{next:k}}function k(){return{value:void 0,done:!0}}return f.prototype=g.constructor=h,h.constructor=f,f.displayName=c(h,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===f||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,c(t,a,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},m(b.prototype),b.prototype[i]=function(){return this},t.AsyncIterator=b,t.async=function(r,e,n,o,i){void 0===i&&(i=Promise);var a=new b(u(r,e,n,o),i);return t.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},m(g),c(g,a,"Generator"),g[o]=function(){return this},g.toString=function(){return"[object Generator]"},t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=O,E.prototype={constructor:E,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!t)for(var r in this)"t"===r.charAt(0)&&e.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function n(e,n){return a.type="throw",a.arg=t,r.next=e,n&&(r.method="next",r.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=e.call(i,"catchLoc"),u=e.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,r){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&e.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),l},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),x(e),l}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;x(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:O(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=void 0),l}},t}(t.exports);try{regeneratorRuntime=r}catch(t){Function("r","regeneratorRuntime = r")(r)}}(c={exports:{}}),c.exports),s=function(t,o){return void 0===o&&(o=!1),function(){var c=i(u.mark((function i(c,s,l){var d,f,h,p,v,y,g,m,b;return u.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:if(!o||process.env.BITSO_API_KEY&&process.env.BITSO_API_SECRET){i.next=2;break}throw new Error("[BITSO_API_KEY, BITSO_API_SECRET] enviroment variables are required for private endpoints");case 2:return d=s&&Object.keys(s).map((function(t){return encodeURIComponent(t)+"="+encodeURIComponent(s[t])})).join("&"),f="/v3"+c+"?"+d,h={method:t,headers:{"Content-Type":"application/json"}},o&&(p=(new Date).getTime(),v=p+t+f,"POST"===t&&(h.body=JSON.stringify(l||{}),v+=h.body),y=r.createHmac("sha256",process.env.BITSO_API_SECRET).update(v).digest("hex"),h.headers=a({},h.headers,{Authorization:"Bitso "+process.env.BITSO_API_KEY+":"+p+":"+y})),i.prev=6,g=""+process.env.BITSO_API_URL+f,i.next=10,n(g,h);case 10:return m=i.sent,i.next=13,m.json();case 13:if(b=i.sent,!m.ok){i.next=18;break}return i.abrupt("return",e(b.payload,{deep:!0}));case 18:return i.abrupt("return",Promise.reject(b.error));case 19:i.next=24;break;case 21:return i.prev=21,i.t0=i.catch(6),i.abrupt("return",Promise.reject(new Error(i.t0)));case 24:case"end":return i.stop()}}),i,null,[[6,21]])})));return function(t,r,e){return c.apply(this,arguments)}}()},l=function(t){return function(){var r=i(u.mark((function r(o){var i,a,c;return u.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return i={method:t,headers:{"Content-Type":"application/json"}},r.prev=1,r.next=4,n(o,i);case 4:return a=r.sent,r.next=7,a.json();case 7:if(c=r.sent,!a.ok){r.next=12;break}return r.abrupt("return",e(c,{deep:!0}));case 12:return r.abrupt("return",Promise.reject(c));case 13:r.next=18;break;case 15:return r.prev=15,r.t0=r.catch(1),r.abrupt("return",Promise.reject(new Error(r.t0)));case 18:case"end":return r.stop()}}),r,null,[[1,15]])})));return function(t){return r.apply(this,arguments)}}()},d=s("GET"),f=s("POST"),h=s("GET",!0),p=s("DELETE",!0),v=s("POST",!0),y=l("GET"),g=["btc_mxn","eth_btc","eth_mxn","xrp_btc","xrp_mxn","ltc_btc","ltc_mxn","bch_btc","bch_mxn","tusd_btc","tusd_mxn","mana_btc","mana_mxn","bat_btc","bat_mxn","btc_ars","btc_dai","dai_mxn","btc_usd","xrp_usd","eth_usd","dai_ars","btc_brl","eth_ars"],m=[{currency:"btc",allowedConversions:["mxn","eth","xrp","ltc","bch","tusd","mana","bat","ars","dai","usd","brl"]},{currency:"mxn",allowedConversions:["btc","eth","xrp","ltc","bch","tusd","mana","bat","dai"]},{currency:"eth",allowedConversions:["btc","mxn","usd","ars"]},{currency:"xrp",allowedConversions:["btc","mxn","usd"]},{currency:"ltc",allowedConversions:["btc","mxn"]},{currency:"bch",allowedConversions:["btc","mxn"]},{currency:"tusd",allowedConversions:["btc","mxn"]},{currency:"mana",allowedConversions:["btc","mxn"]},{currency:"bat",allowedConversions:["btc","mxn"]},{currency:"ars",allowedConversions:["btc","dai","eth"]},{currency:"dai",allowedConversions:["btc","mxn","ars"]},{currency:"usd",allowedConversions:["btc","xrp","eth"]},{currency:"brl",allowedConversions:["btc"]}],b=function(t,r,e){var n;if(!function(t){return g.includes(t)}(t))throw new Error("Book "+t+" unavailable");var o=t.split("_");if(e&&!o.includes(e))throw new Error("Invalid currency, must be one of ["+o.join(", ")+"]");var i,a,c,u=o[0],s=o[1],l=!e||u===e,d=l?u:s,f=l?s:u;if(i=d,a=f,!(c=m.find((function(t){return t.currency===i})))||!c.allowedConversions.includes(a))throw new Error("Transactions from "+d+" to "+f+" are not allowed");return(n={book:t})[l?"major":"minor"]=r,n},_={public:{getAvailableBooks:function(){return d("/available_books")},getTicker:function(t){return d("/ticker",{book:t})},getOrderBook:function(t,r){return d("/order_book",a({},r,{book:t}))},getTrades:function(t,r){return d("/trades",a({},r,{book:t}))}},private:{getAccountStatus:function(){return h("/account_status")},mobilePhone:{register:function(t){return v("/phone_number",void 0,{phone_number:t})},verify:function(t){return v("/phone_verification",void 0,{verification_code:t})}},getBalance:function(){return h("/balance")},getFees:function(){return h("/fees")},ledger:{getLedger:function(t){return h("/ledger",t)},getTrades:function(t){return h("/ledger/trades",t)},getFees:function(t){return h("/ledger/fees",t)},getFundings:function(t){return h("/ledger/fundings",t)},getWithdrawals:function(t){return h("/ledger/withdrawals",t)}},withdrawals:{getAll:function(t){return h("/withdrawals",t)},getByWid:function(t){return h("/withdrawals/"+t)},getByWids:function(t){return h("/withdrawals",{wids:t.join(",")})},getByOriginIds:function(t){return h("/withdrawals",{origin_ids:t.join(",")})}},fundings:{getAll:function(t){return h("/fundings",t)},getByFid:function(t){return h("/fundings/"+t)},getByFids:function(t){return h("/fundings/"+t.join("-"))}},orderTrades:{getByOid:function(t){return h("/order_trades/"+t)},getByOriginId:function(t){return h("/order_trades",{origin_id:t})}},userTrades:{getByBook:function(t,r){return h("/user_trades",a({},r,{book:t}))},getByTid:function(t){return h("/user_trades/"+t)},getByTids:function(t){return h("/user_trades/"+t.join("-"))}},getOpenOrders:function(t){return h("/open_orders",t)},lookupOrders:{getByOid:function(t){return h("/orders/"+t)},getByOids:function(t){return h("/orders",{oids:t.join(",")})},getByOriginIds:function(t){return h("/orders",{origin_ids:t.join(",")})}},cancelOrder:{cancelAll:function(){return p("/orders/all")},cancelByOid:function(t){return p("/orders/"+t)},cancelByOids:function(t){return p("/orders",{oids:t.join(",")})},cancelByOrderIds:function(t){return p("/orders",{origin_ids:t.join(",")})}},placeOrder:{buy:{market:function(t,r,e){var n=a({},b(t,r,e),{side:"buy",type:"market"});return v("/orders",void 0,n)},limit:function(t,r,e,n,o){void 0===o&&(o="goodtillcancelled");var i=a({},b(t,r,e),{side:"buy",type:"limit",price:n,time_in_force:o});return v("/orders",void 0,i)},stopLoss:function(t,r,e){var n=a({},b(t,r),{side:"buy",type:"limit",stop:e});return v("/orders",void 0,n)},stopLimit:function(t,r,e,n,o,i){void 0===i&&(i="goodtillcancelled");var c=a({},b(t,r,e),{side:"buy",type:"limit",price:n,stop:o,time_in_force:i});return v("/orders",void 0,c)}},sell:{market:function(t,r,e){var n=a({},b(t,r,e),{side:"sell",type:"market"});return v("/orders",void 0,n)},limit:function(t,r,e,n,o){void 0===o&&(o="goodtillcancelled");var i=a({},b(t,r,e),{side:"sell",type:"limit",price:n,time_in_force:o});return v("/orders",void 0,i)},stopLoss:function(t,r,e){var n=a({},b(t,r),{side:"sell",type:"limit",stop:e});return v("/orders",void 0,n)},stopLimit:function(t,r,e,n,o,i){void 0===i&&(i="goodtillcancelled");var c=a({},b(t,r,e),{side:"sell",type:"limit",price:n,stop:o,time_in_force:i});return v("/orders",void 0,c)}}},getFundingDestination:function(t){return h("/funding_destination",{fund_currency:t})},getBankCodes:function(){return h("/mx_bank_codes")}},undocumented:{charts:{getChartInfo:function(t,r,e,n){if(n<=e)throw new Error("date range is incorrect");var o=w[r],i=e.getTime(),a=n.getTime();return d("/ohlc",{book:t,time_bucket:o,start:i,end:a})},getChartTrades:function(t,r){return y("https://bitso.com/trade/chartJSON/"+t+"/"+r)}},getTickers:function(){return f("/ticker",void 0,{book:"all"})},getSettings:function(){return h("/settings")},catalogues:{availableCurrencyConversions:{public:function(){return d("/catalogues/available_currency_conversions")},private:function(){return h("/catalogues/available_currency_conversions")}},getCountries:function(){return d("/catalogues/countries")},getCurrencies:function(){return d("/catalogues/currencies")}}}},w={"1 min":60,"5 min":300,"15 min":900,"30 min":1800,"1 h":3600,"4 h":14400,"6 h":21600,"12 h":43200,"1 d":86400,"3 d":259200,"7 d":604800};if(!process.env.BITSO_API_URL)throw new Error("Check your env vars: [BITSO_API_URL] is required, and [BITSO_API_KEY, BITSO_API_SECRET] only if you need the private endpoints");exports.chartingTimeFrame=w,exports.default=_; //# sourceMappingURL=bitso-bert-api.cjs.production.min.js.map