UNPKG

blinktrade

Version:

BlinkTrade client for node.js

2 lines 60.4 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.blinktrade={})}(this,function(exports){"use strict";var BROKERS={VBTC:3,TESTNET:5,URDUBIT:8,CHILEBIT:9,BITCAMBIO:11};function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(e){_defineProperty(t,e,r[e])})}return t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _objectWithoutPropertiesLoose(e,t){if(null==e)return{};var r,n,i={},s=Object.keys(e);for(n=0;n<s.length;n++)t.indexOf(r=s[n])<0&&(i[r]=e[r]);return i}function _objectWithoutProperties(e,t){if(null==e)return{};var r,n,i=_objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(n=0;n<s.length;n++)t.indexOf(r=s[n])<0&&Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?_assertThisInitialized(e):t}function _superPropBase(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=_getPrototypeOf(e)););return e}function _get(e,t,r){return(_get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,r){var n=_superPropBase(e,t);if(n){var i=Object.getOwnPropertyDescriptor(n,t);return i.get?i.get.call(r):i.value}})(e,t,r||e)}var os={},isPromise_1=isPromise,nextTick;function isPromise(e){return e&&"function"==typeof e.then}nextTick="function"==typeof setImediate?setImediate:"object"===("undefined"==typeof process?"undefined":_typeof(process))&&process&&process.nextTick?process.nextTick:function(e){setTimeout(e,0)};var extensions=[],promise=Promise$1,nextTick$1;function Promise$1(n){if(!(this instanceof Promise$1))return"function"==typeof n?new Promise$1(n):defer();var o,a=!1,c=!1,t=[],r=!1;function u(e){t.length?(r=!0,t.shift()(e||!1)):r=!1}this.then=function(i,s){return new Promise$1(function(n){t.push(function(e){var t=c?i:s;if("function"==typeof t){var r=function(){var e;try{e=t(o)}catch(e){return n.reject(e),u()}n.fulfill(e),u(!0)};e?r():nextTick(r)}else c?n.fulfill(o):n.reject(o),u(e)}),a&&!r&&u()})},function(){function r(e){a||(c=!(a=!0),o=e,u())}for(var t={fulfill:function e(t){a||(isPromise_1(t)?t.then(e,r):(a=c=!0,o=t,u()))},reject:r},e=0;e<extensions.length;e++)extensions[e](this,t);if("function"==typeof n)try{n(t)}catch(e){t.reject(e)}}()}function defer(){var t,e=new Promise$1(function(e){t=e});return{resolver:t,promise:e}}Promise$1.use=function(e){extensions.push(e)},nextTick$1="function"==typeof setImmediate?setImmediate:"object"===("undefined"==typeof process?"undefined":_typeof(process))&&process&&process.nextTick?process.nextTick:function(e){setTimeout(e,0)};var nodeify_1=nodeify;function nodeify(e,t){return"function"!=typeof t?e:e.then(function(e){nextTick$1(function(){t(null,e)})},function(e){nextTick$1(function(){t(e)})})}function nodeifyThis(e){return nodeify(this,e)}function extend(e){if(e&&isPromise_1(e)){e.nodeify=nodeifyThis;var t=e.then;return e.then=function(){return extend(t.apply(this,arguments))},e}"function"==typeof e?e.prototype.nodeify=nodeifyThis:promise.prototype.nodeify=nodeifyThis}function NodeifyPromise(e){if(!(this instanceof NodeifyPromise))return new NodeifyPromise(e);promise.call(this,e),extend(this)}nodeify.extend=extend,nodeify.Promise=NodeifyPromise,NodeifyPromise.prototype=Object.create(promise.prototype),NodeifyPromise.prototype.constructor=NodeifyPromise;var commonjsGlobal="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function createCommonjsModule(e,t){return e(t={exports:{}},t.exports),t.exports}var eventemitter2=createCommonjsModule(function(n,e){!function(u){var h=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},t=10;function c(){this._events={},this._conf&&r.call(this,this._conf)}function r(e){e?((this._conf=e).delimiter&&(this.delimiter=e.delimiter),this._maxListeners=e.maxListeners!==u?e.maxListeners:t,e.wildcard&&(this.wildcard=e.wildcard),e.newListener&&(this._newListener=e.newListener),e.removeListener&&(this._removeListener=e.removeListener),e.verboseMemoryLeak&&(this.verboseMemoryLeak=e.verboseMemoryLeak),this.wildcard&&(this.listenerTree={})):this._maxListeners=t}function o(e,t){var r="(node) warning: possible EventEmitter memory leak detected. "+e+" listeners added. Use emitter.setMaxListeners() to increase limit.";if(this.verboseMemoryLeak&&(r+=" Event name: "+t+"."),"undefined"!=typeof process&&process.emitWarning){var n=Error(r);n.name="MaxListenersExceededWarning",n.emitter=this,n.count=e,process.emitWarning(n)}else console.error(r),console.trace&&console.trace()}function e(e){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,r.call(this,e)}function y(e,t,r,n){if(!r)return[];var i,s,o,a,c,u,h,l=[],f=t.length,d=t[n],p=t[n+1];if(n===f&&r._listeners){if("function"==typeof r._listeners)return e&&e.push(r._listeners),[r];for(i=0,s=r._listeners.length;i<s;i++)e&&e.push(r._listeners[i]);return[r]}if("*"===d||"**"===d||r[d]){if("*"===d){for(o in r)"_listeners"!==o&&r.hasOwnProperty(o)&&(l=l.concat(y(e,t,r[o],n+1)));return l}if("**"===d){for(o in(h=n+1===f||n+2===f&&"*"===p)&&r._listeners&&(l=l.concat(y(e,t,r,f))),r)"_listeners"!==o&&r.hasOwnProperty(o)&&(l="*"===o||"**"===o?(r[o]._listeners&&!h&&(l=l.concat(y(e,t,r[o],f))),l.concat(y(e,t,r[o],n))):l.concat(y(e,t,r[o],o===p?n+2:n)));return l}l=l.concat(y(e,t,r[d],n+1))}if((a=r["*"])&&y(e,t,a,n+1),c=r["**"])if(n<f)for(o in c._listeners&&y(e,t,c,f),c)"_listeners"!==o&&c.hasOwnProperty(o)&&(o===p?y(e,t,c[o],n+2):o===d?y(e,t,c[o],n+1):((u={})[o]=c[o],y(e,t,{"**":u},n+1)));else c._listeners?y(e,t,c,f):c["*"]&&c["*"]._listeners&&y(e,t,c["*"],f);return l}(e.EventEmitter2=e).prototype.delimiter=".",e.prototype.setMaxListeners=function(e){e!==u&&(this._maxListeners=e,this._conf||(this._conf={}),this._conf.maxListeners=e)},e.prototype.event="",e.prototype.once=function(e,t){return this._once(e,t,!1)},e.prototype.prependOnceListener=function(e,t){return this._once(e,t,!0)},e.prototype._once=function(e,t,r){return this._many(e,1,t,r),this},e.prototype.many=function(e,t,r){return this._many(e,t,r,!1)},e.prototype.prependMany=function(e,t,r){return this._many(e,t,r,!0)},e.prototype._many=function(e,t,r,n){var i=this;if("function"!=typeof r)throw Error("many only accepts instances of Function");function s(){return 0==--t&&i.off(e,s),r.apply(this,arguments)}return s._origin=r,this._on(e,s,n),i},e.prototype.emit=function(){this._events||c.call(this);var e=arguments[0];if("newListener"===e&&!this._newListener&&!this._events.newListener)return!1;var t,r,n,i,s,o=arguments.length;if(this._all&&this._all.length){if(s=this._all.slice(),3<o)for(t=Array(o),i=0;i<o;i++)t[i]=arguments[i];for(n=0,r=s.length;n<r;n++)switch(this.event=e,o){case 1:s[n].call(this,e);break;case 2:s[n].call(this,e,arguments[1]);break;case 3:s[n].call(this,e,arguments[1],arguments[2]);break;default:s[n].apply(this,t)}}if(this.wildcard){y(s=[],"string"==typeof e?e.split(this.delimiter):e.slice(),this.listenerTree,0)}else{if("function"==typeof(s=this._events[e])){switch(this.event=e,o){case 1:s.call(this);break;case 2:s.call(this,arguments[1]);break;case 3:s.call(this,arguments[1],arguments[2]);break;default:for(t=Array(o-1),i=1;i<o;i++)t[i-1]=arguments[i];s.apply(this,t)}return!0}s&&(s=s.slice())}if(s&&s.length){if(3<o)for(t=Array(o-1),i=1;i<o;i++)t[i-1]=arguments[i];for(n=0,r=s.length;n<r;n++)switch(this.event=e,o){case 1:s[n].call(this);break;case 2:s[n].call(this,arguments[1]);break;case 3:s[n].call(this,arguments[1],arguments[2]);break;default:s[n].apply(this,t)}return!0}if(!this._all&&"error"===e)throw arguments[1]instanceof Error?arguments[1]:Error("Uncaught, unspecified 'error' event.");return!!this._all},e.prototype.emitAsync=function(){this._events||c.call(this);var e=arguments[0];if("newListener"===e&&!this._newListener&&!this._events.newListener)return Promise.resolve([!1]);var t,r,n,i,s,o=[],a=arguments.length;if(this._all){if(3<a)for(t=Array(a),i=1;i<a;i++)t[i]=arguments[i];for(n=0,r=this._all.length;n<r;n++)switch(this.event=e,a){case 1:o.push(this._all[n].call(this,e));break;case 2:o.push(this._all[n].call(this,e,arguments[1]));break;case 3:o.push(this._all[n].call(this,e,arguments[1],arguments[2]));break;default:o.push(this._all[n].apply(this,t))}}this.wildcard?y(s=[],"string"==typeof e?e.split(this.delimiter):e.slice(),this.listenerTree,0):s=this._events[e];if("function"==typeof s)switch(this.event=e,a){case 1:o.push(s.call(this));break;case 2:o.push(s.call(this,arguments[1]));break;case 3:o.push(s.call(this,arguments[1],arguments[2]));break;default:for(t=Array(a-1),i=1;i<a;i++)t[i-1]=arguments[i];o.push(s.apply(this,t))}else if(s&&s.length){if(s=s.slice(),3<a)for(t=Array(a-1),i=1;i<a;i++)t[i-1]=arguments[i];for(n=0,r=s.length;n<r;n++)switch(this.event=e,a){case 1:o.push(s[n].call(this));break;case 2:o.push(s[n].call(this,arguments[1]));break;case 3:o.push(s[n].call(this,arguments[1],arguments[2]));break;default:o.push(s[n].apply(this,t))}}else if(!this._all&&"error"===e)return arguments[1]instanceof Error?Promise.reject(arguments[1]):Promise.reject("Uncaught, unspecified 'error' event.");return Promise.all(o)},e.prototype.on=function(e,t){return this._on(e,t,!1)},e.prototype.prependListener=function(e,t){return this._on(e,t,!0)},e.prototype.onAny=function(e){return this._onAny(e,!1)},e.prototype.prependAny=function(e){return this._onAny(e,!0)},e.prototype.addListener=e.prototype.on,e.prototype._onAny=function(e,t){if("function"!=typeof e)throw Error("onAny only accepts instances of Function");return this._all||(this._all=[]),t?this._all.unshift(e):this._all.push(e),this},e.prototype._on=function(e,t,r){if("function"==typeof e)return this._onAny(e,t),this;if("function"!=typeof t)throw Error("on only accepts instances of Function");return this._events||c.call(this),this._newListener&&this.emit("newListener",e,t),this.wildcard?function(e,t){for(var r=0,n=(e="string"==typeof e?e.split(this.delimiter):e.slice()).length;r+1<n;r++)if("**"===e[r]&&"**"===e[r+1])return;for(var i=this.listenerTree,s=e.shift();s!==u;){if(i[s]||(i[s]={}),i=i[s],0===e.length)return i._listeners?("function"==typeof i._listeners&&(i._listeners=[i._listeners]),i._listeners.push(t),!i._listeners.warned&&0<this._maxListeners&&this._maxListeners<i._listeners.length&&(i._listeners.warned=!0,o.call(this,i._listeners.length,s))):i._listeners=t,!0;s=e.shift()}return!0}.call(this,e,t):this._events[e]?("function"==typeof this._events[e]&&(this._events[e]=[this._events[e]]),r?this._events[e].unshift(t):this._events[e].push(t),!this._events[e].warned&&0<this._maxListeners&&this._maxListeners<this._events[e].length&&(this._events[e].warned=!0,o.call(this,this._events[e].length,e))):this._events[e]=t,this},e.prototype.off=function(e,t){if("function"!=typeof t)throw Error("removeListener only takes instances of Function");var r,n=[];if(this.wildcard){n=y(null,"string"==typeof e?e.split(this.delimiter):e.slice(),this.listenerTree,0)}else{if(!this._events[e])return this;n.push({_listeners:r=this._events[e]})}for(var i=0;i<n.length;i++){var s=n[i];if(h(r=s._listeners)){for(var o=-1,a=0,c=r.length;a<c;a++)if(r[a]===t||r[a].listener&&r[a].listener===t||r[a]._origin&&r[a]._origin===t){o=a;break}if(o<0)continue;return this.wildcard?s._listeners.splice(o,1):this._events[e].splice(o,1),0===r.length&&(this.wildcard?delete s._listeners:delete this._events[e]),this._removeListener&&this.emit("removeListener",e,t),this}(r===t||r.listener&&r.listener===t||r._origin&&r._origin===t)&&(this.wildcard?delete s._listeners:delete this._events[e],this._removeListener&&this.emit("removeListener",e,t))}return function e(t){if(t!==u){var r=Object.keys(t);for(var n in r){var i=r[n],s=t[i];s instanceof Function||"object"!==_typeof(s)||null===s||(0<Object.keys(s).length&&e(t[i]),0===Object.keys(s).length&&delete t[i])}}}(this.listenerTree),this},e.prototype.offAny=function(e){var t,r=0,n=0;if(e&&this._all&&0<this._all.length){for(r=0,n=(t=this._all).length;r<n;r++)if(e===t[r])return t.splice(r,1),this._removeListener&&this.emit("removeListenerAny",e),this}else{if(t=this._all,this._removeListener)for(r=0,n=t.length;r<n;r++)this.emit("removeListenerAny",t[r]);this._all=[]}return this},e.prototype.removeListener=e.prototype.off,e.prototype.removeAllListeners=function(e){if(e===u)return!this._events||c.call(this),this;if(this.wildcard)for(var t=y(null,"string"==typeof e?e.split(this.delimiter):e.slice(),this.listenerTree,0),r=0;r<t.length;r++){t[r]._listeners=null}else this._events&&(this._events[e]=null);return this},e.prototype.listeners=function(e){if(this.wildcard){var t=[];return y(t,"string"==typeof e?e.split(this.delimiter):e.slice(),this.listenerTree,0),t}return this._events||c.call(this),this._events[e]||(this._events[e]=[]),h(this._events[e])||(this._events[e]=[this._events[e]]),this._events[e]},e.prototype.eventNames=function(){return Object.keys(this._events)},e.prototype.listenerCount=function(e){return this.listeners(e).length},e.prototype.listenersAny=function(){return this._all?this._all:[]},"function"==typeof u&&u.amd?u(function(){return e}):n.exports=e}()}),TestReqID="TestReqID",UserReqID="UserReqID",SecurityReqID="SecurityReqID",DepositReqID="DepositReqID",WithdrawReqID="WithdrawReqID",BalanceReqID="BalanceReqID",OrdersReqID="OrdersReqID",DepositMethodReqID="DepositMethodReqID",WithdrawListReqID="WithdrawListReqID",WithdrawCancelReqID="WithdrawCancelReqID",BrokerListReqID="BrokerListReqID",DepositListReqID="DepositListReqID",TradeHistoryReqID="TradeHistoryReqID",LedgerListReqID="LedgerListReqID",PositionReqID="PositionReqID",SecurityStatusReqID="SecurityStatusReqID",ProcessDepositReqID="ProcessDepositReqID",CustomerListReqID="CustomerListReqID",CustomerReqID="CustomerReqID",ProcessWithdrawReqID="ProcessWithdrawReqID",VerifyCustomerReqID="VerifyCustomerReqID",MDReqID="MDReqID",ClOrdID="ClOrdID",HEARTBEAT="HEARTBEAT",BROKER_LIST="BROKER_LIST",SECURITY_LIST="SECURITY_LIST",SECURITY_STATUS_SUBSCRIBE="SECURITY_STATUS_SUBSCRIBE",MD_INCREMENT="MD_INCREMENT",MD_FULL_REFRESH="MD_FULL_REFRESH",EXECUTION_REPORT="EXECUTION_REPORT",ORDER_HISTORY="ORDER_HISTORY",ORDER_SEND="ORDER_SEND",ORDER_CANCEL="ORDER_CANCEL",TRADE_HISTORY="TRADE_HISTORY",LOGIN="LOGIN",BALANCE="BALANCE",POSITIONS="POSITIONS",CUSTOMER_LIST="CUSTOMER_LIST",CUSTOMER_REFRESH="CUSTOMER_REFRESH",KYC_VERIFY="KYC_VERIFY",KYC_REQUEST="KYC_REQUEST",WITHDRAW_LIST="WITHDRAW_LIST",WITHDRAW_CANCEL="WITHDRAW_CANCEL",WITHDRAW_REFRESH="WITHDRAW_REFRESH",WITHDRAW_PROCESS="WITHDRAW_PROCESS",WITHDRAW_CONFIRM="WITHDRAW_CONFIRM",WITHDRAW_COMMENT="WITHDRAW_COMMENT",WITHDRAW_REQUEST="WITHDRAW_REQUEST",DEPOSIT_LIST="DEPOSIT_LIST",DEPOSIT_REFRESH="DEPOSIT_REFRESH",DEPOSIT_PROCESS="DEPOSIT_PROCESS",DEPOSIT_REQUEST="DEPOSIT_REQUEST",DEPOSIT_METHODS="DEPOSIT_METHODS",LEDGER_LIST="LEDGER_LIST",zipColumns=function(e,n){return e.reduce(function(e,t,r){return e[n[r]]=t,e},{})},msgToAction=function(e){return Object.entries(e).reduce(function(e,t){return e[t[1][0]]=t[0],e},{})},formatColumns=function(r,n){return function(t){if(2!==n)return Promise.resolve(t);var e=t[r].map(function(e){return zipColumns(e,t.Columns)});return Promise.resolve(_objectSpread({},t,_defineProperty({},r,e)))}},formatBrokerList=function(r){return function(t){if(2!==r)return Promise.resolve(t);var e=t.BrokerListGrp.map(function(e){return zipColumns(e,t.Columns)}).reduce(function(e,t){return e[t.BrokerID]=t,e},{});return Promise.resolve(_objectSpread({},t,{BrokerListGrp:e}))}},formatTradeHistory=function(r){return function(t){if(2!==r)return Promise.resolve(t);var e=t.TradeHistoryGrp.map(function(e){return zipColumns(e,t.Columns)}).reduce(function(e,t){return(e[t.Market]=e[t.Market]||[]).push(t),e},{});return Promise.resolve(_objectSpread({},t,{TradeHistoryGrp:e}))}},formatOrderBook=function(e,t){if(2!==t)return e;var r=e.MDFullGrp.filter(function(e){return"0"===e.MDEntryType||"1"===e.MDEntryType}).reduce(function(e,t){var r="0"===t.MDEntryType?"bids":"asks";return(e[r]||(e[r]=[])).push(t),e},[]);return _objectSpread({},e,{MDFullGrp:_defineProperty({},e.Symbol,{bids:r.bids||[],asks:r.asks||[]})})},MsgActionReq={1:[HEARTBEAT,TestReqID],BE:[LOGIN,UserReqID],V:[MD_FULL_REFRESH,MDReqID],x:[SECURITY_LIST,SecurityReqID],e:[SECURITY_STATUS_SUBSCRIBE,SecurityStatusReqID],D:[ORDER_SEND,ClOrdID],F:[ORDER_CANCEL,ClOrdID],U2:[BALANCE,BalanceReqID],U6:[WITHDRAW_REQUEST,WithdrawReqID],U4:[ORDER_HISTORY,OrdersReqID],U18:[DEPOSIT_REQUEST,DepositReqID],U20:[DEPOSIT_METHODS,DepositMethodReqID],U24:[WITHDRAW_CONFIRM,WithdrawReqID],U26:[WITHDRAW_LIST,WithdrawListReqID],U28:[BROKER_LIST,BrokerListReqID],U30:[DEPOSIT_LIST,DepositListReqID],U32:[TRADE_HISTORY,TradeHistoryReqID],U34:[LEDGER_LIST,LedgerListReqID],U42:[POSITIONS,PositionReqID],U70:[WITHDRAW_CANCEL,WithdrawCancelReqID],B0:[DEPOSIT_PROCESS,ProcessDepositReqID],B2:[CUSTOMER_LIST,CustomerListReqID],B4:[KYC_REQUEST,CustomerReqID],B6:[WITHDRAW_PROCESS,ProcessWithdrawReqID],B8:[KYC_VERIFY,VerifyCustomerReqID]},MsgActionRes={0:[HEARTBEAT,TestReqID],BF:[LOGIN,UserReqID],W:[MD_FULL_REFRESH,MDReqID],X:[MD_INCREMENT,MDReqID],8:[EXECUTION_REPORT,ClOrdID],y:[SECURITY_LIST,SecurityReqID],f:[SECURITY_STATUS_SUBSCRIBE,SecurityStatusReqID],U3:[BALANCE,BalanceReqID],U7:[WITHDRAW_REQUEST,WithdrawReqID],U5:[ORDER_HISTORY,OrdersReqID],U9:[WITHDRAW_REFRESH,ClOrdID],U19:[DEPOSIT_REQUEST,DepositReqID],U21:[DEPOSIT_METHODS,DepositMethodReqID],U23:[DEPOSIT_REFRESH,ClOrdID],U25:[WITHDRAW_CONFIRM,WithdrawReqID],U27:[WITHDRAW_LIST,WithdrawListReqID],U29:[BROKER_LIST,BrokerListReqID],U31:[DEPOSIT_LIST,DepositListReqID],U33:[TRADE_HISTORY,TradeHistoryReqID],U35:[LEDGER_LIST,LedgerListReqID],U43:[POSITIONS,PositionReqID],U71:[WITHDRAW_CANCEL,WithdrawCancelReqID],U79:[WITHDRAW_COMMENT,WithdrawReqID],B1:[DEPOSIT_PROCESS,ProcessDepositReqID],B3:[CUSTOMER_LIST,CustomerListReqID],B5:[KYC_REQUEST,CustomerReqID],B9:[KYC_VERIFY,VerifyCustomerReqID],B7:[WITHDRAW_PROCESS,ProcessWithdrawReqID],B11:[CUSTOMER_REFRESH,""]},ActionMsgReq=msgToAction(MsgActionReq),ActionMsgRes=msgToAction(MsgActionRes),reqs=new Map;function generateRequestId(){return parseInt(1e7*Math.random()+"",10)}function getKey(e,t){var r=e[t.MsgType][1];return r+":"+t[r]}function getRequest(e){return reqs.get(getKey(MsgActionRes,e))}function setRequest(e,t){reqs.set(getKey(MsgActionReq,e),t)}function deleteRequest(e){reqs.delete(getKey(MsgActionRes,e))}var ORDER_BOOK_TRADE_NEW="TRADE_NEW",ORDER_BOOK_NEW_ORDER="NEW_ORDER",ORDER_BOOK_UPDATE_ORDER="UPDATE_ORDER",ORDER_BOOK_DELETE_ORDER="DELETE_ORDER",ORDER_BOOK_DELETE_ORDERS_THRU="DELETE_ORDERS_THRU",EXECUTION_REPORT_NEW$1="NEW",EXECUTION_REPORT_PARTIAL$1="PARTIAL",EXECUTION_REPORT_EXECUTION$1="EXECUTION",EXECUTION_REPORT_CANCELED$1="CANCELED",EXECUTION_REPORT_REJECTED$1="REJECTED",EVENTS={ORDERBOOK:{0:ORDER_BOOK_NEW_ORDER,1:ORDER_BOOK_UPDATE_ORDER,2:ORDER_BOOK_DELETE_ORDER,3:ORDER_BOOK_DELETE_ORDERS_THRU},TRADES:{0:ORDER_BOOK_TRADE_NEW},EXECUTION_REPORT:{0:EXECUTION_REPORT_NEW$1,1:EXECUTION_REPORT_PARTIAL$1,2:EXECUTION_REPORT_EXECUTION$1,4:EXECUTION_REPORT_CANCELED$1,8:EXECUTION_REPORT_REJECTED$1}},ORDER_TYPE={MARKET:"1",LIMIT:"2",STOP:"3",STOP_LIMIT:"4"},ORDER_SIDE={BUY:"1",SELL:"2"},TradeBase=function(){function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};_classCallCheck(this,t),this.level=void 0===e.level?2:e.level,this.brokerId=e.brokerId||4}return _createClass(t,[{key:"changeBrokerId",value:function(e){this.brokerId=e}},{key:"balance",value:function(e,t){var r={MsgType:ActionMsgReq.BALANCE,BalanceReqID:generateRequestId()};return e&&(r.ClientID=e),nodeify_1.extend(this.send(r)).nodeify(t)}},{key:"myOrders",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.page,r=void 0===t?0:t,n=e.pageSize,i=void 0===n?40:n,s=e.filter,o=1<arguments.length?arguments[1]:void 0,a={MsgType:ActionMsgReq.ORDER_HISTORY,OrdersReqID:generateRequestId(),Page:r,PageSize:i};s&&"all"!==s&&(a.Filter="open"===s?["has_leaves_qty eq 1"]:"filled"===s?["has_cum_qty eq 1"]:"cancelled"===s?["has_cxl_qty eq 1"]:s);var c=formatColumns("OrdListGrp",this.level);return nodeify_1.extend(this.send(a).then(c)).nodeify(o)}},{key:"sendOrder",value:function(e,t){var r=e.type,n=e.side,i=e.amount,s=e.price,o=e.stopPrice,a=e.symbol,c=e.postOnly,u={MsgType:ActionMsgReq.ORDER_SEND,ClOrdID:e.clientId||""+generateRequestId(),Side:ORDER_SIDE[n]||n,OrdType:ORDER_TYPE[r]||ORDER_TYPE.LIMIT,Symbol:a,OrderQty:i,BrokerID:this.brokerId};return s&&(u.Price=s),o&&(u.StopPx=o),c&&(u.ExecInst="6"),nodeify_1.extend(this.send(u)).nodeify(t)}},{key:"cancelOrder",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=1<arguments.length?arguments[1]:void 0,r=e.orderId?e.orderId:e,n={MsgType:ActionMsgReq.ORDER_CANCEL};return e.clientId&&(n.ClOrdID=e.clientId),e.orderId&&(n.OrderID=r),nodeify_1.extend(this.send(n)).nodeify(t)}},{key:"requestWithdrawList",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.filter,r=e.clientId,n=e.page,i=void 0===n?0:n,s=e.pageSize,o=void 0===s?20:s,a=e.status,c=void 0===a?["1","2","4","8"]:a,u=1<arguments.length?arguments[1]:void 0,h={MsgType:ActionMsgReq.WITHDRAW_LIST,WithdrawListReqID:generateRequestId(),Page:i,PageSize:o,StatusList:c};t&&t.length&&(h.Filter=t),r&&(h.ClientID=r);var l=formatColumns("WithdrawListGrp",this.level);return nodeify_1.extend(this.send(h).then(l)).nodeify(u)}},{key:"requestWithdraw",value:function(e,t){var r=e.amount,n=e.data,i=e.currency,s=void 0===i?"BTC":i,o=e.method,a=void 0===o?"bitcoin":o,c=generateRequestId();return nodeify_1.extend(this.send({MsgType:ActionMsgReq.WITHDRAW_REQUEST,WithdrawReqID:c,ClOrdID:c,Method:a,Amount:r,Currency:s,Data:n})).nodeify(t)}},{key:"confirmWithdraw",value:function(e,t){var r=e.withdrawId,n=e.confirmationToken,i=e.secondFactor,s={MsgType:ActionMsgReq.WITHDRAW_CONFIRM,WithdrawReqID:generateRequestId(),WithdrawID:r};return n&&(s.ConfirmationToken=n),i&&(s.SecondFactor=i),nodeify_1.extend(this.send(s)).nodeify(t)}},{key:"cancelWithdraw",value:function(e,t){var r=generateRequestId();return nodeify_1.extend(this.send({MsgType:ActionMsgReq.WITHDRAW_CANCEL,WithdrawCancelReqID:r,ClOrdID:r,WithdrawID:e})).nodeify(t)}},{key:"requestDepositList",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.page,r=void 0===t?0:t,n=e.pageSize,i=void 0===n?20:n,s=e.status,o=void 0===s?["1","2","4","8"]:s,a=e.filter,c=e.clientId,u=1<arguments.length?arguments[1]:void 0,h={MsgType:ActionMsgReq.DEPOSIT_LIST,DepositListReqID:generateRequestId(),Page:r,PageSize:i,StatusList:o};a&&a.length&&(h.Filter=a),c&&(h.ClientID=c);var l=formatColumns("DepositListGrp",this.level);return nodeify_1.extend(this.send(h).then(l)).nodeify(u)}},{key:"requestDeposit",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.currency,r=void 0===t?"BTC":t,n=e.value,i=e.depositMethodId,s=1<arguments.length?arguments[1]:void 0,o=generateRequestId(),a={MsgType:ActionMsgReq.DEPOSIT_REQUEST,DepositReqID:o,ClOrdID:o,Currency:r,BrokerID:this.brokerId};return"BTC"!==r&&(a.DepositMethodID=i,a.Value=n),nodeify_1.extend(this.send(a)).nodeify(s)}},{key:"requestDepositMethods",value:function(e){var t={MsgType:ActionMsgReq.DEPOSIT_METHODS,DepositMethodReqID:generateRequestId(),BrokerID:this.brokerId};return nodeify_1.extend(this.send(t)).nodeify(e)}},{key:"requestBrokerList",value:function(e){var t={MsgType:ActionMsgReq.BROKER_LIST,BrokerListReqID:generateRequestId(),Page:0,PageSize:20,StatusList:["1"]},r=formatBrokerList(this.level);return nodeify_1.extend(this.send(t).then(r)).nodeify(e)}},{key:"requestLedger",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.page,r=void 0===t?0:t,n=e.pageSize,i=void 0===n?20:n,s=e.brokerId,o=e.clientId,a=e.currency,c=1<arguments.length?arguments[1]:void 0,u={MsgType:ActionMsgReq.LEDGER_LIST,LedgerListReqID:generateRequestId(),BrokerID:this.brokerId,Page:r,PageSize:i};s&&(u.BrokerID=s),a&&(u.Currency=a),o&&(u.ClientID=o);var h=formatColumns("LedgerListGrp",this.level);return nodeify_1.extend(this.send(u).then(h)).nodeify(c)}}]),t}(),WS={};function getMac(){}var sha256=createCommonjsModule(function(module){!function(){var ERROR="input is invalid type",WINDOW="object"===("undefined"==typeof window?"undefined":_typeof(window)),root=WINDOW?window:{};root.JS_SHA256_NO_WINDOW&&(WINDOW=!1);var WEB_WORKER=!WINDOW&&"object"===("undefined"==typeof self?"undefined":_typeof(self)),NODE_JS=!root.JS_SHA256_NO_NODE_JS&&"object"===("undefined"==typeof process?"undefined":_typeof(process))&&process.versions&&process.versions.node;NODE_JS?root=commonjsGlobal:WEB_WORKER&&(root=self);var COMMON_JS=!root.JS_SHA256_NO_COMMON_JS&&module.exports,ARRAY_BUFFER=!root.JS_SHA256_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,HEX_CHARS="0123456789abcdef".split(""),EXTRA=[-2147483648,8388608,32768,128],SHIFT=[24,16,8,0],K=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],OUTPUT_TYPES=["hex","array","digest","arrayBuffer"],blocks=[];!root.JS_SHA256_NO_NODE_JS&&Array.isArray||(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)}),!ARRAY_BUFFER||!root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(e){return"object"===_typeof(e)&&e.buffer&&e.buffer.constructor===ArrayBuffer});var createOutputMethod=function(t,r){return function(e){return new Sha256(r,!0).update(e)[t]()}},createMethod=function(e){var t=createOutputMethod("hex",e);NODE_JS&&(t=nodeWrap(t,e)),t.create=function(){return new Sha256(e)},t.update=function(e){return t.create().update(e)};for(var r=0;r<OUTPUT_TYPES.length;++r){var n=OUTPUT_TYPES[r];t[n]=createOutputMethod(n,e)}return t},nodeWrap=function nodeWrap(method,is224){var crypto=eval("require('crypto')"),Buffer=eval("require('buffer').Buffer"),algorithm=is224?"sha224":"sha256",nodeMethod=function(e){if("string"==typeof e)return crypto.createHash(algorithm).update(e,"utf8").digest("hex");if(null==e)throw Error(ERROR);return e.constructor===ArrayBuffer&&(e=new Uint8Array(e)),Array.isArray(e)||ArrayBuffer.isView(e)||e.constructor===Buffer?crypto.createHash(algorithm).update(new Buffer(e)).digest("hex"):method(e)};return nodeMethod},createHmacOutputMethod=function(r,n){return function(e,t){return new HmacSha256(e,n,!0).update(t)[r]()}},createHmacMethod=function(t){var r=createHmacOutputMethod("hex",t);r.create=function(e){return new HmacSha256(e,t)},r.update=function(e,t){return r.create(e).update(t)};for(var e=0;e<OUTPUT_TYPES.length;++e){var n=OUTPUT_TYPES[e];r[n]=createHmacOutputMethod(n,t)}return r};function Sha256(e,t){this.blocks=t?(blocks[0]=blocks[16]=blocks[1]=blocks[2]=blocks[3]=blocks[4]=blocks[5]=blocks[6]=blocks[7]=blocks[8]=blocks[9]=blocks[10]=blocks[11]=blocks[12]=blocks[13]=blocks[14]=blocks[15]=0,blocks):[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],this.h7=e?(this.h0=3238371032,this.h1=914150663,this.h2=812702999,this.h3=4144912697,this.h4=4290775857,this.h5=1750603025,this.h6=1694076839,3204075428):(this.h0=1779033703,this.h1=3144134277,this.h2=1013904242,this.h3=2773480762,this.h4=1359893119,this.h5=2600822924,this.h6=528734635,1541459225),this.block=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0,this.is224=e}function HmacSha256(e,t,r){var n,i=_typeof(e);if("string"===i){var s,o=[],a=e.length,c=0;for(n=0;n<a;++n)s=e.charCodeAt(n),o[c++]=s<128?s:(o[c++]=s<2048?192|s>>6:(o[c++]=s<55296||57344<=s?224|s>>12:(s=65536+((1023&s)<<10|1023&e.charCodeAt(++n)),o[c++]=240|s>>18,128|s>>12&63),128|s>>6&63),128|63&s);e=o}else{if("object"!==i)throw Error(ERROR);if(null===e)throw Error(ERROR);if(ARRAY_BUFFER&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||ARRAY_BUFFER&&ArrayBuffer.isView(e)))throw Error(ERROR)}64<e.length&&(e=new Sha256(t,!0).update(e).array());var u=[],h=[];for(n=0;n<64;++n){var l=e[n]||0;u[n]=92^l,h[n]=54^l}Sha256.call(this,t,r),this.update(h),this.oKeyPad=u,this.inner=!0,this.sharedMemory=r}Sha256.prototype.update=function(e){if(!this.finalized){var t,r=_typeof(e);if("string"!==r){if("object"!==r)throw Error(ERROR);if(null===e)throw Error(ERROR);if(ARRAY_BUFFER&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||ARRAY_BUFFER&&ArrayBuffer.isView(e)))throw Error(ERROR);t=!0}for(var n,i,s=0,o=e.length,a=this.blocks;s<o;){if(this.hashed&&(this.hashed=!1,a[0]=this.block,a[16]=a[1]=a[2]=a[3]=a[4]=a[5]=a[6]=a[7]=a[8]=a[9]=a[10]=a[11]=a[12]=a[13]=a[14]=a[15]=0),t)for(i=this.start;s<o&&i<64;++s)a[i>>2]|=e[s]<<SHIFT[3&i++];else for(i=this.start;s<o&&i<64;++s)(n=e.charCodeAt(s))<128?a[i>>2]|=n<<SHIFT[3&i++]:(n<2048?a[i>>2]|=(192|n>>6)<<SHIFT[3&i++]:(n<55296||57344<=n?a[i>>2]|=(224|n>>12)<<SHIFT[3&i++]:(n=65536+((1023&n)<<10|1023&e.charCodeAt(++s)),a[i>>2]|=(240|n>>18)<<SHIFT[3&i++],a[i>>2]|=(128|n>>12&63)<<SHIFT[3&i++]),a[i>>2]|=(128|n>>6&63)<<SHIFT[3&i++]),a[i>>2]|=(128|63&n)<<SHIFT[3&i++]);this.lastByteIndex=i,this.bytes+=i-this.start,i<64?this.start=i:(this.block=a[16],this.start=i-64,this.hash(),this.hashed=!0)}return 4294967295<this.bytes&&(this.hBytes+=this.bytes/4294967296<<0,this.bytes=this.bytes%4294967296),this}},Sha256.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,t=this.lastByteIndex;e[16]=this.block,e[t>>2]|=EXTRA[3&t],this.block=e[16],t<56||(this.hashed||this.hash(),e[0]=this.block,e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0),e[14]=this.hBytes<<3|this.bytes>>>29,e[15]=this.bytes<<3,this.hash()}},Sha256.prototype.hash=function(){var e,t,r,n,i,s,o=this.h0,a=this.h1,c=this.h2,u=this.h3,h=this.h4,l=this.h5,f=this.h6,d=this.h7,p=this.blocks;for(e=16;e<64;++e)p[e]=p[e-16]+(((t=p[e-15])>>>7|t<<25)^(t>>>18|t<<14)^t>>>3)+p[e-7]+(((t=p[e-2])>>>17|t<<15)^(t>>>19|t<<13)^t>>>10)<<0;for(s=a&c,e=0;e<64;e+=4)this.first?(u=this.is224?(r=300032,d=(t=p[0]-1413257819)-150054599<<0,t+24177077<<0):(r=704751109,d=(t=p[0]-210244248)-1521486534<<0,t+143694565<<0),this.first=!1):(d=u+(t=d+((h>>>6|h<<26)^(h>>>11|h<<21)^(h>>>25|h<<7))+(h&l^~h&f)+K[e]+p[e])<<0,u=t+(((o>>>2|o<<30)^(o>>>13|o<<19)^(o>>>22|o<<10))+((r=o&a)^o&c^s))<<0),f=c+(t=f+((d>>>6|d<<26)^(d>>>11|d<<21)^(d>>>25|d<<7))+(d&h^~d&l)+K[e+1]+p[e+1])<<0,c=t+(((u>>>2|u<<30)^(u>>>13|u<<19)^(u>>>22|u<<10))+((n=u&o)^u&a^r))<<0,l=a+(t=l+((f>>>6|f<<26)^(f>>>11|f<<21)^(f>>>25|f<<7))+(f&d^~f&h)+K[e+2]+p[e+2])<<0,a=t+(((c>>>2|c<<30)^(c>>>13|c<<19)^(c>>>22|c<<10))+((i=c&u)^c&o^n))<<0,h=o+(t=h+((l>>>6|l<<26)^(l>>>11|l<<21)^(l>>>25|l<<7))+(l&f^~l&d)+K[e+3]+p[e+3])<<0,o=t+(((a>>>2|a<<30)^(a>>>13|a<<19)^(a>>>22|a<<10))+((s=a&c)^a&u^i))<<0;this.h0=this.h0+o<<0,this.h1=this.h1+a<<0,this.h2=this.h2+c<<0,this.h3=this.h3+u<<0,this.h4=this.h4+h<<0,this.h5=this.h5+l<<0,this.h6=this.h6+f<<0,this.h7=this.h7+d<<0},Sha256.prototype.hex=function(){this.finalize();var e=this.h0,t=this.h1,r=this.h2,n=this.h3,i=this.h4,s=this.h5,o=this.h6,a=this.h7,c=HEX_CHARS[e>>28&15]+HEX_CHARS[e>>24&15]+HEX_CHARS[e>>20&15]+HEX_CHARS[e>>16&15]+HEX_CHARS[e>>12&15]+HEX_CHARS[e>>8&15]+HEX_CHARS[e>>4&15]+HEX_CHARS[15&e]+HEX_CHARS[t>>28&15]+HEX_CHARS[t>>24&15]+HEX_CHARS[t>>20&15]+HEX_CHARS[t>>16&15]+HEX_CHARS[t>>12&15]+HEX_CHARS[t>>8&15]+HEX_CHARS[t>>4&15]+HEX_CHARS[15&t]+HEX_CHARS[r>>28&15]+HEX_CHARS[r>>24&15]+HEX_CHARS[r>>20&15]+HEX_CHARS[r>>16&15]+HEX_CHARS[r>>12&15]+HEX_CHARS[r>>8&15]+HEX_CHARS[r>>4&15]+HEX_CHARS[15&r]+HEX_CHARS[n>>28&15]+HEX_CHARS[n>>24&15]+HEX_CHARS[n>>20&15]+HEX_CHARS[n>>16&15]+HEX_CHARS[n>>12&15]+HEX_CHARS[n>>8&15]+HEX_CHARS[n>>4&15]+HEX_CHARS[15&n]+HEX_CHARS[i>>28&15]+HEX_CHARS[i>>24&15]+HEX_CHARS[i>>20&15]+HEX_CHARS[i>>16&15]+HEX_CHARS[i>>12&15]+HEX_CHARS[i>>8&15]+HEX_CHARS[i>>4&15]+HEX_CHARS[15&i]+HEX_CHARS[s>>28&15]+HEX_CHARS[s>>24&15]+HEX_CHARS[s>>20&15]+HEX_CHARS[s>>16&15]+HEX_CHARS[s>>12&15]+HEX_CHARS[s>>8&15]+HEX_CHARS[s>>4&15]+HEX_CHARS[15&s]+HEX_CHARS[o>>28&15]+HEX_CHARS[o>>24&15]+HEX_CHARS[o>>20&15]+HEX_CHARS[o>>16&15]+HEX_CHARS[o>>12&15]+HEX_CHARS[o>>8&15]+HEX_CHARS[o>>4&15]+HEX_CHARS[15&o];return this.is224||(c+=HEX_CHARS[a>>28&15]+HEX_CHARS[a>>24&15]+HEX_CHARS[a>>20&15]+HEX_CHARS[a>>16&15]+HEX_CHARS[a>>12&15]+HEX_CHARS[a>>8&15]+HEX_CHARS[a>>4&15]+HEX_CHARS[15&a]),c},Sha256.prototype.toString=Sha256.prototype.hex,Sha256.prototype.digest=function(){this.finalize();var e=this.h0,t=this.h1,r=this.h2,n=this.h3,i=this.h4,s=this.h5,o=this.h6,a=this.h7,c=[e>>24&255,e>>16&255,e>>8&255,255&e,t>>24&255,t>>16&255,t>>8&255,255&t,r>>24&255,r>>16&255,r>>8&255,255&r,n>>24&255,n>>16&255,n>>8&255,255&n,i>>24&255,i>>16&255,i>>8&255,255&i,s>>24&255,s>>16&255,s>>8&255,255&s,o>>24&255,o>>16&255,o>>8&255,255&o];return this.is224||c.push(a>>24&255,a>>16&255,a>>8&255,255&a),c},Sha256.prototype.array=Sha256.prototype.digest,Sha256.prototype.arrayBuffer=function(){this.finalize();var e=new ArrayBuffer(this.is224?28:32),t=new DataView(e);return t.setUint32(0,this.h0),t.setUint32(4,this.h1),t.setUint32(8,this.h2),t.setUint32(12,this.h3),t.setUint32(16,this.h4),t.setUint32(20,this.h5),t.setUint32(24,this.h6),this.is224||t.setUint32(28,this.h7),e},HmacSha256.prototype=new Sha256,HmacSha256.prototype.finalize=function(){if(Sha256.prototype.finalize.call(this),this.inner){this.inner=!1;var e=this.array();Sha256.call(this,this.is224,this.sharedMemory),this.update(this.oKeyPad),this.update(e),Sha256.prototype.finalize.call(this)}};var exports=createMethod();exports.sha256=exports,exports.sha224=createMethod(!0),exports.sha256.hmac=createHmacMethod(),exports.sha224.hmac=createHmacMethod(!0),COMMON_JS?module.exports=exports:(root.sha256=exports.sha256,root.sha224=exports.sha224)}()}),SEED32=314159265,CONSTANT32=-1640531527,mix32_=function(e){var t=e.a,r=e.b,n=e.c;return t-=r,t-=n,r-=n,r-=t^=n>>>13,n-=t,n-=r^=t<<8,t-=r,t-=n^=r>>>13,r-=n,r-=t^=n>>>12,n-=t,n-=r^=t<<16,t-=r,t-=n^=r>>>5,r-=n,r-=t^=n>>>3,n-=t,n-=r^=t<<10,n^=r>>>15,e.a=t,e.b=r,e.c=n},toSigned_=function(e){return 127<e?e-256:e},wordAt_=function(e,t){return toSigned_(e[t+0])+(toSigned_(e[t+1])<<8)+(toSigned_(e[t+2])<<16)+(toSigned_(e[t+3])<<24)};function encodeByteArray(e){var t,r=0,n=e.length,i={a:CONSTANT32,b:CONSTANT32,c:SEED32};for(t=n;12<=t;t-=12,r+=12)i.a+=wordAt_(e,r),i.b+=wordAt_(e,r+4),i.c+=wordAt_(e,r+8),mix32_(i);switch(i.c+=n,t){case 11:i.c+=e[r+10]<<24;case 10:i.c+=(255&e[r+9])<<16;case 9:i.c+=(255&e[r+8])<<8;case 8:i.b+=wordAt_(e,r+4),i.a+=wordAt_(e,r);break;case 7:i.b+=(255&e[r+6])<<16;case 6:i.b+=(255&e[r+5])<<8;case 5:i.b+=255&e[r+4];case 4:i.a+=wordAt_(e,r);break;case 3:i.a+=(255&e[r+2])<<16;case 2:i.a+=(255&e[r+1])<<8;case 1:i.a+=255&e[r+0]}return mix32_(i)}function getFingerPrint(){var e=[];e.push(window.navigator.userAgent),e.push(window.screen.colorDepth),e.push(window.navigator.language),Array.isArray(window.navigator.languages)?e.push(window.navigator.languages.join("x")):e.push("undefined");var t=window.screen.height>window.screen.width?[window.screen.height,window.screen.width]:[window.screen.width,window.screen.height];e.push(t.join("x")),e.push((new Date).getTimezoneOffset()),e.push(void 0!==window.sessionStorage),e.push(void 0!==window.localStorage),e.push(!!window.indexedDB),document.body?e.push(_typeof(window.document.body.addBehavior)):e.push("undefined"),e.push(_typeof(window.openDatabase)),e.push(window.navigator.cpuClass),e.push(window.navigator.platform),e.push(window.navigator.doNotTrack);var r=[];Array.from(window.navigator.plugins).forEach(function(e){var t=[];Object.values(e).forEach(function(e){t.push([e.type,e.suffixes].join("~"))}),r.push([e.name,e.description,t.join(",")].join("::"))}),e.push(r.join(";"));var n=document.createElement("canvas");if(n.getContext&&n.getContext("2d")){var i=n.getContext("2d"),s="http://valve.github.io";i.textBaseline="top",i.font="14px 'Arial'",i.textBaseline="alphabetic",i.fillStyle="#f60",i.fillRect(125,1,62,20),i.fillStyle="#069",i.fillText(s,2,15),i.fillStyle="rgba(102, 204, 0, 0.7)",i.fillText(s,4,17),e.push(n.toDataURL())}var o=sha256.digest(e.join("###")),a=parseInt(encodeByteArray(o));return a<0&&(a*=-1),a}var common={prod:{ws:"wss://ws.blinktrade.com/trade/",wsBitcambio:"wss://bitcambio_api.blinktrade.com/trade/",rest:"https://api.blinktrade.com/",restBitcambio:"https://bitcambio_api.blinktrade.com/"},testnet:{ws:"wss://api_testnet.blinktrade.com/trade/",wsBitcambio:"wss://api_testnet.blinktrade.com/trade/",rest:"https://api_testnet.blinktrade.com/",restBitcambio:"https://api_testnet.blinktrade.com/"}},IS_NODE="undefined"==typeof window,IS_BROWSER="undefined"!=typeof document,Transport=function e(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},r=1<arguments.length?arguments[1]:void 0;_classCallCheck(this,e),this.endpoint=t.url?t.url:t.prod?common.prod[r]:common.testnet[r]},RECONNECT_INTERVAL=5e3,WebSocketTransport=function(e){function r(){var e,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return _classCallCheck(this,r),(e=_possibleConstructorReturn(this,_getPrototypeOf(r).call(this,t,t.brokerId===BROKERS.BITCAMBIO?"wsBitcambio":"ws"))).stun={local:null,public:[]},e.getFingerPrint(t.fingerPrint),e.headers=t.headers,e.autoReconnect=t.reconnect||!1,e.reconnectInterval=t.reconnectInterval||RECONNECT_INTERVAL,e.eventEmitter=new eventemitter2({wildcard:!0,delimiter:":"}),e}return _inherits(r,Transport),_createClass(r,[{key:"connect",value:function(e){var n=this;return nodeify_1.extend(new Promise(function(e,t){n.connection={resolve:e,reject:t};var r=IS_NODE?WS:window.WebSocket;n.getStun(),n.socket=new r(n.endpoint,[],n.headers),n.socket.onopen=n.onOpen.bind(n),n.socket.onclose=n.onClose.bind(n),n.socket.onerror=n.onError.bind(n),n.socket.onmessage=n.onMessage.bind(n)})).nodeify(e)}},{key:"disconnect",value:function(){this.socket.close(),this.closeStun()}},{key:"onOpen",value:function(e){this.eventEmitter.emit("OPEN",e),this.connection.resolve({connected:!0})}},{key:"onClose",value:function(e){this.eventEmitter.emit("CLOSE",e,this.lastMessageSent),this.closeStun(),this.reconnect()}},{key:"onError",value:function(e){this.eventEmitter.emit("ERROR",e,this.lastMessageSent)}},{key:"reconnect",value:function(){var e=this;this.autoReconnect&&setTimeout(function(){return e.connect()},this.reconnectInterval)}},{key:"sendMessage",value:function(e){if(1===this.socket.readyState){var t=e;t.STUNTIP=this.stun,t.FingerPrint=this.fingerPrint,this.lastMessageSent=t,this.eventEmitter.emit("send",t),this.socket.send(JSON.stringify(t))}}},{key:"sendMessageAsPromise",value:function(r){var n=this;return new Promise(function(e,t){n.lastPromise={resolve:e,reject:t},setRequest(r,{resolve:e,reject:t}),n.sendMessage(r)})}},{key:"onMessage",value:function(e){var t=JSON.parse(e.data);this.eventEmitter.emit("receive",t),MsgActionRes[t.MsgType]?(this.dispatchPromise(t),this.dispatchEventEmitters(t)):"ERROR"===t.MsgType&&this.eventEmitter.emit("ERROR",t,this.lastMessageSent)}},{key:"dispatchPromise",value:function(e){var t=getRequest(e);if(t&&t.resolve)return deleteRequest(e),t.resolve(e)}},{key:"dispatchEventEmitters",value:function(e){var t=e.MsgType,r=MsgActionRes[t][1];this.eventEmitter.emit(t,e),e[r]&&this.eventEmitter.emit(t+":"+e[r],e)}},{key:"getFingerPrint",value:function(e){var t=this;if(IS_NODE)return getMac(function(e){t.fingerPrint=e});if(IS_BROWSER)this.fingerPrint=getFingerPrint();else{if(!e)throw Error("FingerPrint not provided");this.fingerPrint=e}}},{key:"getStun",value:function(){}},{key:"closeStun",value:function(){}},{key:"emitterPromise",value:function(n,e){var i=this;return n.on=function(e,t){return i.eventEmitter.on(e,t),n},n.onAny=function(e){return i.eventEmitter.onAny(e),n},n.offAny=function(e){return i.eventEmitter.offAny(e),n},n.once=function(e,t){return i.eventEmitter.once(e,t),n},n.many=function(e,t,r){return i.eventEmitter.many(e,t,r),n},n.removeListener=function(e,t){return i.eventEmitter.removeListener(e,t),n},n.removeAllListeners=function(e){return i.eventEmitter.removeAllListeners(e),n},nodeify_1.extend(n).nodeify(e)}}]),r}(),BlinkTradeWS=function(e){function h(){var e,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return _classCallCheck(this,h),(e=_possibleConstructorReturn(this,_getPrototypeOf(h).call(this,t))).transport=t.transport||new WebSocketTransport(t),e.session={},e.orderbook={},e.isOrderBookSynced=!1,e.syncReqId=0,e}return _inherits(h,TradeBase),_createClass(h,[{key:"connect",value:function(e){return this.emitterPromise(this.transport.connect(e))}},{key:"disconnect",value:function(){return this.transport.disconnect()}},{key:"send",value:function(e){return this.transport.sendMessageAsPromise(e)}},{key:"on",value:function(e,t){if(this.transport.eventEmitter)return this.transport.eventEmitter.on(e,t)}},{key:"emit",value:function(e,t){if(this.transport.eventEmitter)return this.transport.eventEmitter.emit(e,t)}},{key:"emitterPromise",value:function(e,t){return this.transport.emitterPromise?this.transport.emitterPromise(e,t):e}},{key:"heartbeat",value:function(e){var r=this,t=new Date,n={MsgType:ActionMsgReq.HEARTBEAT,TestReqID:t.getTime(),SendTime:t.getTime()};return nodeify_1.extend(new Promise(function(t,e){return r.send(n).then(function(e){return t(_objectSpread({},e,{Latency:new Date(Date.now())-e.SendTime}))}).catch(e)})).nodeify(e)}},{key:"login",value:function(e,t){var r,n=this,i=e.username,s=e.password,o=e.secondFactor,a=e.cancelOnDisconnect,c=e.brokerId,u=_objectWithoutProperties(e,["username","password","secondFactor","cancelOnDisconnect","brokerId"]);r=IS_NODE?{UserAgent:"".concat(os.type()," ").concat(os.release()),UserAgentLanguage:"en_US",UserAgentPlatform:"".concat(os.platform()," (").concat(os.arch(),")"),UserAgentTimezoneOffset:(new Date).getTimezoneOffset()}:{UserAgent:window.navigator.userAgent,UserAgentLanguage:window.navigator.language,UserAgentPlatform:window.navigator.platform,UserAgentTimezoneOffset:(new Date).getTimezoneOffset()};var h=_objectSpread({MsgType:ActionMsgReq.LOGIN,UserReqID:generateRequestId(),BrokerID:c||this.brokerId,Username:i,Password:s,UserReqTyp:"1",CancelOnDisconnect:a?"1":"0"},r,u);return o&&(h.SecondFactor=o),nodeify_1.extend(new Promise(function(t,r){return n.send(h).then(function(e){return 1===e.UserStatus?t(n.session=e):r(e)}).catch(r)})).nodeify(t)}},{key:"logout",value:function(e){var t={MsgType:ActionMsgReq.LOGIN,BrokerID:this.brokerId,UserReqID:generateRequestId(),Username:this.session.Username,UserReqTyp:"2"};return nodeify_1.extend(this.send(t)).nodeify(e)}},{key:"profile",value:function(e){var t=this.session.Profile,r=_objectWithoutProperties(t,["VerificationData"]);return nodeify_1.extend(Promise.resolve(r)).nodeify(e)}},{key:"balance",value:function(r,n){var i=this;return this.emitterPromise(new Promise(function(t,e){return _get(_getPrototypeOf(h.prototype),"balance",i).call(i,r,n).then(function(e){return i.on(ActionMsgRes.BALANCE,function(e){return n&&n(null,e),i.emit(BALANCE,e)}),t(e)}).catch(e)}))}},{key:"onBalanceUpdate",value:function(e){return this.on(ActionMsgRes.BALANCE,e)}},{key:"subscribeTicker",value:function(e,r){var n=this,i={MsgType:ActionMsgReq.SECURITY_STATUS_SUBSCRIBE,SecurityStatusReqID:generateRequestId(),SubscriptionRequestType:"1",Instruments:e},s=function(e){return _objectSpread({},e,{SellVolume:e.SellVolume/1e8,LowPx:e.LowPx/1e8,LastPx:e.LastPx/1e8,BestAsk:e.BestAsk/1e8,HighPx:e.HighPx/1e8,BuyVolume:e.BuyVolume/1e8,BestBid:e.BestBid/1e8})};return this.emitterPromise(new Promise(function(t,e){return n.send(i).then(function(e){return n.on(ActionMsgRes.SECURITY_STATUS_SUBSCRIBE+":"+e.SecurityStatusReqID,function(e){var t=s(e);return r&&r(null,t),n.emit("".concat(e.Market,":").concat(e.Symbol),t)}),t(s(e))}).catch(e)}),r)}},{key:"unSubscribeTicker",value:function(e){return this.transport.sendMessage({MsgType:ActionMsgReq.SECURITY_STATUS_SUBSCRIBE,SubscriptionRequestType:"2",SecurityStatusReqID:e}),e}},{key:"subscribeOrderbook",value:function(e,t){return console.warn("Warning: subscribeOrderbook is DEPRECATED, use subscribeMarketData instead"),this.subscribeMarketData(e,t)}},{key:"subscribeMarketData",value:function(e,o){var a=this,n={MsgType:ActionMsgReq.MD_FULL_REFRESH,MDReqID:generateRequestId(),SubscriptionRequestType:"1",MarketDepth:0,MDUpdateType:"1",MDEntryTypes:["0","1"],BrokerID:this.brokerId};Array.isArray(e)?n.Instruments=e:(n.Instruments=e.instruments,n.MDEntryTypes=e.entryTypes||n.MDEntryTypes,n.MarketDepth=e.marketDepth||n.MarketDepth),e.columns&&(n.Columns=e.columns);var i=Array.isArray(e)||void 0===e.level?this.level:e.level,s=function(s){"3"===s.MDBkTyp&&s.MDIncGrp.map(function(e){switch(e.MDEntryType){case"0":case"1":var t="OB:".concat(EVENTS.ORDERBOOK[e.MDUpdateAction]),r=_objectSpread({},e,{MDReqID:s.MDReqID,type:t});return o&&o(null,r),a.emit(t,r);case"2":var n="OB:".concat(EVENTS.TRADES[e.MDUpdateAction]),i=_objectSpread({},e,{type:n});return o&&o(null,i),a.emit(n,i);case"4":break;default:return null}return null})};return this.emitterPromise(new Promise(function(t,r){return a.send(n).then(function(e){return a.on(ActionMsgRes.MD_INCREMENT+":"+e.MDReqID,s),t(formatOrderBook(e,i))}).catch(function(e){return r(e)})}),o)}},{key:"syncOrderbook",value:function(e){var t=this;if(this.isOrderBookSynced)return Promise.resolve(this.orderbook);this.isOrderBookSynced=!0;var r={0:"bids",1:"asks"};return this.subscribeMarketData({instruments:Array.isArray(e)?e:e.instruments,level:2}).on("OB:NEW_ORDER",function(e){e.MDReqID===t.syncReqId&&t.orderbook[e.Symbol][r[e.MDEntryType]].splice(e.MDEntryPositionNo-1,0,e)}).on("OB:UPDATE_ORDER",function(e){e.MDReqID===t.syncReqId&&t.orderbook[e.Symbol][r[e.MDEntryType]].splice(e.MDEntryPositionNo-1,1,e)}).on("OB:DELETE_ORDER",function(e){e.MDReqID===t.syncReqId&&t.orderbook[e.Symbol][r[e.MDEntryType]].splice(e.MDEntryPositionNo-1,1)}).on("OB:DELETE_ORDERS_THRU",function(e){e.MDReqID===t.syncReqId&&t.orderbook[e.Symbol][r[e.MDEntryType]].splice(0,e.MDEntryPositionNo)}).then(function(e){return t.syncReqId=e.MDReqID,t.orderbook=e.MDFullGrp,t.orderbook})}},{key:"unSubscribeOrderbook",value:function(e){return this.transport.sendMessage({MsgType:ActionMsgReq.MD_FULL_REFRESH,MDReqID:e,MarketDepth:0,SubscriptionRequestType:"2"}),e}},{key:"executionReport",value:function(r){var n=this;return this.on(ActionMsgRes.EXECUTION_REPORT,function(e){r&&r(e);var t=EVENTS.EXECUTION_REPORT[e.ExecType];return n.emit("".concat(EXECUTION_REPORT,":").concat(t),e)})}},{key:"tradeHistory",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.since,r=e.symbols,n=e.page,i=void 0===n?0:n,s=e.pageSize,o=void 0===s?100:s,a=1<arguments.length?arguments[1]:void 0,c={MsgType:ActionMsgReq.TRADE_HISTORY,TradeHistoryReqID:generateRequestId(),Page:i,PageSize:o};r&&0<r.length&&(c.SymbolList=r),t&&"number"==typeof t&&(c.Since=t);var u=formatTradeHistory(this.level);return nodeify_1.extend(this.send(c).then(u)).nodeify(a)}},{key:"requestDeposit",value:function(){var r=this,e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.currency,n=void 0===t?"BTC":t,i=e.value,s=e.depositMethodId,o=1<arguments.length?arguments[1]:void 0,a=function(e){return o&&o(null,e),r.emit(DEPOSIT_REFRESH,e)};return this.emitterPromise(new Promise(function(t,e){return _get(_getPrototypeOf(h.prototype),"requestDeposit",r).call(r,{currency:n,value:i,depositMethodId:s}).then(function(e){return r.on(ActionMsgRes.DEPOSIT_REFRESH+":"+e.ClOrdID,a),t(e)}).catch(e)}),o)}},{key:"onDepositRefresh",value:function(e){return this.on(ActionMsgRes.DEPOSIT_REFRESH,e)}},{key:"requestWithdraw",value:function(e,t){var r=this,n=e.amount,i=e.data,s=e.currency,o=void 0===s?"BTC":s,a=e.method,c=void 0===a?"bitcoin":a,u=function(e){return t&&t(null,e),r.emit(WITHDRAW_REFRESH,e)};return this.emitterPromise(new Promise(function(t,e){return _get(_getPrototypeOf(h.prototype),"requestWithdraw",r).call(r,{amount:n,data:i,currency:o,method:c}).then(function(e){return r.on(ActionMsgRes.WITHDRAW_REFRESH+":"+e.ClOrdID,u),t(e)}).catch(e)}),t)}},{key:"onWithdrawRefresh",value:function(e){return this.on(ActionMsgRes.WITHDRAW_REFRESH,e)}}]),h}(),invariant=function(e,t,r,n,i,s,o,a){if("production"!==process.env.NODE_ENV&&void 0===t)throw Error("invariant requires an error message argument");if(!e){var c;if(void 0===t)c=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[r,n,i,s,o,a],h=0;(c=Error(t.replace(/%s/g,function(){return u[h++]}))).name="Invariant Violation"}throw c.framesToPop=1,c}},browser=invariant,fetchBrowser=createCommonjsModule(function(e,t){var r;r="undefined"!=typeof self?self:commonjsGlobal,e.exports=function(e){var I=e&&e.Promise||r.Promise,D=e&&e.XMLHttpRequest||r.XMLHttpRequest,t=r;return function(){var e=Object.create(t,{fetch:{value:void 0,writable:!0}});return function(e){if(!e.fetch){var t="URLSearchParams"in e,r="Symbol"in e&&"iterator"in Symbol,o="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),n="FormData"in e,i="ArrayBuffer"in e;if(i)var s=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],a=function(e){return e&&DataView.prototype.isPrototypeOf(e)},c=ArrayBuffer.isView||function(e){return e&&-1<s.indexOf(Object.prototype.toString.call(e))};p.prototype.append=function(e,t){e=l(e),t=f(t);var r=this.map[e];this.map[e]=r?r+","+t:t},p.prototype.delete=function(e){delete this.map[l(e)]},p.prototype.get=function(e){return e=l(e),this.has(e)?this.map[e]:null},p.prototype.has=function(e){return this.map.hasOwnProperty(l(e))},p.prototype.set=function(e,t){this.map[l(e)]=f(t)},p.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},p.prototype.keys=function(){var r=[];return this.forEach(function(e,t){r.push(t)}),d(r)},p.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),d(t)},p.prototype.entries=function(){var r=[];return this.forEach(function(e,t){r.push([t,e])}),d(r)},r&&(p.prototype[Symbol.iterator]=p.prototype.entries);var u=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];T.prototype.clone=function(){return new T(this,{body:this._bodyInit})},v.call(T.prototype),v.call(m.prototype),m.prototype.clone=function(){return new m(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new p(this.headers),url:this.url})},m.error=function(){var e=new m(null,{status:0,statusText:""});return e.type="error",e};var h=[301,302,303,307,308];m.redirect=function(e,t){if(-1==h.indexOf(t))throw new RangeError("Invalid status code");return new m(null,{status:t,headers:{location:e}})},e.Headers=p,e.Request=T,e.Response=m,e.fetch=function(i,s){return new I(function(r,e){var t=new T(i,s),n=new D;n.onload=function(){var e,i,t={status:n.status,statusText:n.statusText,headers:(e=n.getAllResponseHeaders()||"",i=new p,e.split(/\r?\n/).forEach(function(e){var t=e.split(":"),r=t.shift().trim();if(r){var n=t.join(":").trim();i.append(r,n)}}),i)};t.url="responseURL"in n?n.responseURL:t.headers.get("X-Request-URL"),r(new m("response"in n?n.response:n.responseText,t))},n.onerror=function(){e(new TypeError("Network request failed"))},n.ontimeout=function(){e(new TypeError("Network request failed"))},n.open(t.method,t.url,!0),"include"===t.credentials&&(n.withCredentials=!0),"responseType"in n&&o&&(n.responseType="blob"),t.headers.forEach(function(e,t){n.setRequestHeader(t,e)}),n.send(void 0===t._bodyInit?null:t._bodyInit)})},e.fetch.polyfill=!0}function l(e){if("string"!=typeof e&&(e+=""),/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function f(e){return"string"!=typeof e&&(e+=""),e}function d(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return r&&(e[Symbol.iterator]=function(){return e}),e}function p(t){this.map={},t instanceof p?t.forEach(function(e,t){this.append(t,e)},this):Array.isArray(t)?t.forEach(function(e){this.append(e[0],e[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}function y(e){if(e.bodyUsed)return I.reject(new TypeError("Already read"));e.bodyUsed=!0}function R(r){return new I(function(e,t){r.onload=function(){e(r.result)},r.onerror=function(){t(r.error)}})}function _(e){var t=new FileReader,r=R(t);return t.readAsArrayBuffer(e),r}function E(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(e){if(this._bodyInit=e)if("string"==typeof e)this._bodyText=e;else if(o&&Blob.prototype.isPrototypeOf(e))this._bodyBlob=e;else if(n&&FormData.prototype.isPrototypeOf(e))this._bodyFormData=e;else if(t&&URLSearchParams.prototype.isPrototypeOf(e))this._bodyText=""+e;else if(i&&o&&a(e))this._bodyArrayBuffer=E(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!i||!ArrayBuffer.prototype.isPrototypeOf(e)&&!c(e))throw Error("unsupported BodyInit type");this._bodyArrayBuffer=E(e)}else this._bodyText="";this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):t&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},o&&(this.blob=function(){var e=y(this);if(e)return e;if(this._bodyBlob)return I.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return I.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw Error("could not read FormData body as blob");return I.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?y(this)||I.resolve(this._bodyArrayBuffer):this.blob().then(_)}),this.text=function(){var e,t,r,n=y(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=R(t),t.readAsText(e),r;if(this._bodyArrayBuffer)return I.resolve(function(e){for(var t=new Uint8Array(e),r=Array(t.length),n=0;n<t.length;n++)r[n]=String.fromCharCode(t[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw Error("could not read FormData body as text");return I.resolve(this._bodyText)},n&&(this.formData=function(){return this.text().then(S)}),this.json=function(){return this.text().then(JSON.parse)},this}function T(e,t){var r,n,i=(t=t||{}).body;if(e instanceof T){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new p(e.headers)),this.method=e.method,this.mode=e.mode,i||null==e._bodyInit||(i=e._bodyInit,e.bodyUsed=!0)}else this.url=e+"";if(this.credentials=t.credentials||this.credentials||"omit",!t.headers&&this.headers||(this.headers=new p(t.headers)),this.method=(n=(r=t.method||this.method||"GET").toUpperCase(),-1<u.indexOf(n)?n:r),this.mode=t.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&i)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(i)}function S(e){var i=new FormData;return e.trim().split("&").forEach(function(e){if(e){var t=e.split("="),r=t.shift().replace(/\+/g," "),n=t.join("=").replace(/\+/g," ");i.append(decodeURIComponent(r),decodeURIComponent(n))}}),i}function m(e,t){t||(t={}),this.type="default",this.status="status"in t?t.status:200,this.ok=200<=this.status&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new p(t.headers),this.url=t.url||"",this._initBody(e)}}(void 0!==e?e:this),{fetch:e.fetch,Headers:e.Headers,Request:e.Request,Response:e.Response}}()}}),_fetchPonyfill=fetchBrowser({Promise:Promise}),_fetch=_fetchPonyfill.fetch,RestTransport=function(e){function r(){var e,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return _classCallCheck(this,r),(e=_possibleConstructorReturn(this,_getPrototypeOf(r).call(this,t,t.brokerId===BROKERS.BITCAMBIO?"restBitcambio":"rest"))).key=t.key,e.secret=t.secret,e.currency=t.currency||"BRL",e}return _inherits(r,Transport),_createClass(r,[{key:"headers",value:function(e,t){var r=""+Date.now(),n=sha256.hmac.create(this.secret).update(r).hex();return{method:e,headers:{"Content-Type":"application/json",Nonce:r,APIKey:this.key,Signature:n},body:JSON.stringify(t)}}},{key:"fetch",value:function(e){return _fetch(this.endpoint+e,1<arguments.length&&void 0!==arguments[1]?arguments[1]:{}).then(function(e){return e.json()})}},{key:"fetchPublic",value:function(e){return this.fetch("api/v1/".concat(this.currency,"/").concat(e))}},{key:"fetchTrade",value:function(e){browser(this.key&&this.secret,"Key or Secret not provided");var t=this.headers("POST",e);return this.fetch("tapi/v1/message",t).then(function(e){return 500===e.Status?Promise.reject(e):e.Responses}).then(function(e){return 1===e.length?e[0]:e})}}]),r}(),BlinkTradeRest=function(e){function r(){var e,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return _classCallCheck(this,r),(e=_possibleConstructorReturn(this,_getPrototypeOf(r).call(this,t))).transport=t.transport||new RestTransport(t),e}return _inherits(r,TradeBase),_createClass(r,[{key:"send",value:function(e){return this.transport.fetchTrade(e)}},{key:"fetchPublic",value:function(e){return this.transport.fetchPublic(e)}},{key:"ticker",value:function(e){return nodeify_1.extend(this.fetchPublic("ticker")).nodeify(e)}},{key:"trades",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.limit,r=e.since,n=void 0===r?0:r,i=1<arguments.length?arguments[1]:void 0;return nodeify_1.extend(this.fetchPublic("trades?limit=".concat(void 0===t?100:t,"&since=").concat(n))).nodeify(i)}},{key:"orderbook",value:function(e){return nodeify_1.extend(this.fetchPublic("orderbook")).nodeify(e)}}]),r}();exports.Brokers=BROKERS,exports.BlinkTradeWS=BlinkTradeWS,exports.BlinkTradeRest=BlinkTradeRest,Object.defineProperty(exports,"__esModule",{value:!0})});