UNPKG

bot18

Version:

A high-frequency cryptocurrency trading bot by Zenbot creator @carlos8f

1 lines 19.1 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Finity=e():t.Finity=e()}(window,function(){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:o})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=17)}([function(t,e,n){"use strict";e.__esModule=!0;var o,r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=n(13),s=(o=i)&&o.__esModule?o:{default:o};var u=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.parent=e}return t.prototype.getAncestor=function(t){return this.parent?this.parent instanceof t?this.parent:this.parent.getAncestor(t):null},t.prototype.buildConfig=function(){return(0,s.default)(this.config,function e(n){return n?n instanceof t?n.buildConfig():Array.isArray(n)?n.map(e):n&&"object"===(void 0===n?"undefined":r(n))?(0,s.default)(n,e):n:n})},t}();e.default=u},function(t,e,n){"use strict";e.__esModule=!0;var o=i(n(0)),r=i(n(5));function i(t){return t&&t.__esModule?t:{default:t}}var s=function(t){function e(n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var o=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.call(this,n));return o.config={transitions:[]},o}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.transitionTo=function(t){return this.transition(t)},e.prototype.selfTransition=function(){return this.transition(null)},e.prototype.internalTransition=function(){return this.transition(null,{isInternal:!0})},e.prototype.ignore=function(){return this.transition(null,{ignore:!0})},e.prototype.transition=function(t,e){var n=new r.default(this,t,e);return this.config.transitions.push(n),n},e}(o.default);e.default=s},function(t,e,n){"use strict";e.__esModule=!0,e.default=function(t,e){return Object.keys(e).forEach(function(n){t[n]=e[n]}),t}},function(t,e,n){"use strict";e.__esModule=!0;var o=i(n(11)),r=i(n(9));function i(t){return t&&t.__esModule?t:{default:t}}var s=function(){function t(e,n,o){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.rootStateMachine=e,this.currentStateMachine=n,this.taskScheduler=o}return t.start=function(e){var n=new r.default,i=void 0;return i=new o.default(e,n,function(e){return{stateMachine:new t(i,e,n)}}),n.execute(function(){return i.start()}),new t(i,i,n)},t.prototype.getCurrentState=function(){return this.currentStateMachine.getCurrentState()},t.prototype.getSubmachine=function(){var e=this.currentStateMachine.getSubmachine();return e?new t(this.rootStateMachine,e,this.taskScheduler):null},t.prototype.getStateHierarchy=function(){return this.getStateMachines().map(function(t){return t.getCurrentState()})},t.prototype.canHandle=function(t,e){for(var n=this.getStateMachines(),o=n.length-1;o>=0;o--)if(n[o].canHandle(t,e))return!0;return!1},t.prototype.handle=function(t,e){var n=this;return this.taskScheduler.enqueue(function(){for(var o=n.getStateMachines(),r=o.length-1;r>=0;r--)if(o[r].tryHandle(t,e))return;n.currentStateMachine.handleUnhandledEvent(t,e)}),this},t.prototype.getStateMachines=function(){var t=[],e=this.rootStateMachine;do{t.push(e),e=e.getSubmachine()}while(e);return t},t.prototype.toString=function(){return"StateMachine(currentState: "+this.getCurrentState()+")"},t}();e.default=s},function(t,e,n){"use strict";e.__esModule=!0;var o=i(n(0)),r=i(n(1));function i(t){return t&&t.__esModule?t:{default:t}}var s=function(t){function e(n,o){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var i=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.call(this,n));return i.config={action:o,successTrigger:new r.default(i),failureTrigger:new r.default(i)},i}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.onSuccess=function(){return this.config.successTrigger},e.prototype.onFailure=function(){return this.config.failureTrigger},e}(o.default);e.default=s},function(t,e,n){"use strict";e.__esModule=!0;var o,r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},i=n(0);var s=function(t){function e(n,o){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var s=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.call(this,n));return s.config=r({targetState:o},i,{actions:[],condition:null}),s}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.withAction=function(t){return this.config.actions.push(t),this},e.prototype.withCondition=function(t){return this.config.condition=t,this},e}(((o=i)&&o.__esModule?o:{default:o}).default);e.default=s},function(t,e,n){"use strict";e.__esModule=!0;var o=u(n(0)),r=u(n(1)),i=u(n(12)),s=u(n(4));function u(t){return t&&t.__esModule?t:{default:t}}var a=function(t){function e(n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var o=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.call(this,n));return o.config={entryActions:[],exitActions:[],events:Object.create(null),anyEventTrigger:null,timers:[],asyncActions:[],submachine:null},o}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.onEnter=function(t){return this.config.entryActions.push(t),this},e.prototype.onExit=function(t){return this.config.exitActions.push(t),this},e.prototype.on=function(t){return this.config.events[t]||(this.config.events[t]=new r.default(this)),this.config.events[t]},e.prototype.onAny=function(){return this.config.anyEventTrigger||(this.config.anyEventTrigger=new r.default(this)),this.config.anyEventTrigger},e.prototype.onTimeout=function(t){var e=new i.default(this,t);return this.config.timers.push(e),e},e.prototype.do=function(t){var e=new s.default(this,t);return this.config.asyncActions.push(e),e},e.prototype.submachine=function(t){return this.config.submachine=t,this},e}(o.default);e.default=a},function(t,e,n){"use strict";e.__esModule=!0;var o,r=n(0);var i=function(t){function e(n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var o=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.call(this,n));return o.config={stateEnterHooks:[],stateExitHooks:[],stateChangeHooks:[],transitionHooks:[],unhandledEventHooks:[]},o}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.onStateEnter=function(t){return this.config.stateEnterHooks.push(t),this},e.prototype.onStateExit=function(t){return this.config.stateExitHooks.push(t),this},e.prototype.onStateChange=function(t){return this.config.stateChangeHooks.push(t),this},e.prototype.onTransition=function(t){return this.config.transitionHooks.push(t),this},e.prototype.onUnhandledEvent=function(t){return this.config.unhandledEventHooks.push(t),this},e}(((o=r)&&o.__esModule?o:{default:o}).default);e.default=i},function(t,e,n){"use strict";e.__esModule=!0,e.default=function(t,e){var n=t.prototype,o=e.prototype;Object.getOwnPropertyNames(o).filter(function(t){return!n[t]&&o[t]instanceof Function&&o[t]!==e}).forEach(function(t){n[t]=function(){for(var n=o[t],r=arguments.length,i=Array(r),s=0;s<r;s++)i[s]=arguments[s];return n.apply(this.getAncestor(e),i)}})}},function(t,e,n){"use strict";e.__esModule=!0;var o=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.queue=[],this.isBusy=!1}return t.prototype.enqueue=function(t){this.isBusy?this.queue.push(t):this.execute(t)},t.prototype.execute=function(t){if(this.isBusy)throw new Error("Cannot execute task because another task is already running.");this.isBusy=!0;try{for(t();this.queue.length>0;){this.queue.shift()()}}finally{this.queue.length>0&&(this.queue=[]),this.isBusy=!1}},t}();e.default=o},function(t,e,n){"use strict";e.__esModule=!0,e.default=function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];t.forEach(function(t){return t.apply(void 0,n)})}},function(t,e,n){"use strict";e.__esModule=!0;var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r=s(n(10)),i=s(n(2));function s(t){return t&&t.__esModule?t:{default:t}}var u=function(){},a=function(){function t(e,n,r){if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),void 0===e||null===e)throw new Error("Configuration must be specified.");if("object"!==(void 0===e?"undefined":o(e)))throw new Error("Configuration must be an object.");if(void 0===e.initialState||null===e.initialState)throw new Error("Initial state must be specified.");this.config=e,this.taskScheduler=n,this.contextFactory=r,this.currentState=null,this.submachines=Object.create(null),this.timerIDs=null,this.asyncActionCancelers=null,this.handleAsyncActionComplete=this.handleAsyncActionComplete.bind(this),this.handleTimeout=this.handleTimeout.bind(this)}return t.prototype.getCurrentState=function(){return this.currentState},t.prototype.canHandle=function(t,e){if(!this.isStarted())return!1;var n=this.createContextWithEvent(t,e);return!!this.getFirstAllowedTransitionForEvent(n)},t.prototype.tryHandle=function(t,e){if(!this.isStarted())return!1;var n=this.createContextWithEvent(t,e),o=this.getFirstAllowedTransitionForEvent(n);return!!o&&(this.executeTransition(o,n),!0)},t.prototype.handleUnhandledEvent=function(t,e){if(!(this.config.global.unhandledEventHooks.length>0))throw new Error("Unhandled event '"+t+"' in state '"+this.currentState+"'.");(0,r.default)(this.config.global.unhandledEventHooks,t,this.currentState,this.createContextWithEvent(t,e))},t.prototype.isStarted=function(){return null!==this.currentState},t.prototype.start=function(){this.isStarted()||this.enterState(this.config.initialState,this.createContext())},t.prototype.stop=function(){this.isStarted()&&(this.exitState(this.createContext()),this.currentState=null)},t.prototype.getSubmachine=function(){return this.isStarted()?this.submachines[this.currentState]:null},t.prototype.executeTransition=function(t,e){if(!t.ignore){t.isInternal||this.exitState(e);var n=null!==t.targetState?t.targetState:this.currentState;(0,r.default)(this.config.global.transitionHooks,this.currentState,n,e),(0,r.default)(t.actions,this.currentState,n,e),t.isInternal||this.enterState(n,e)}},t.prototype.enterState=function(t,e){(0,r.default)(this.config.global.stateEnterHooks,t,e);var n=this.config.states[t];n&&(0,r.default)(n.entryActions,t,e),null!==this.currentState&&this.currentState!==t&&(0,r.default)(this.config.global.stateChangeHooks,this.currentState,t,e);try{this.startAsyncActions(t,e),this.startTimers(t),this.startSubmachines(t)}catch(t){throw this.stopTimers(),this.cancelAsyncActions(),t}this.currentState=t},t.prototype.exitState=function(t){this.stopSubmachines(),this.stopTimers(),this.cancelAsyncActions(),(0,r.default)(this.config.global.stateExitHooks,this.currentState,t);var e=this.config.states[this.currentState];e&&(0,r.default)(e.exitActions,this.currentState,t)},t.prototype.startAsyncActions=function(t,e){var n=this,o=this.config.states[t];o&&o.asyncActions.forEach(function(o){return n.startAsyncAction(o,t,e)})},t.prototype.startAsyncAction=function(t,e,n){var o=t.action,r=t.successTrigger,i=t.failureTrigger,s=this.handleAsyncActionComplete;o(e,n).then(function(t){return s(r,{result:t})},function(t){return s(i,{error:t})}),this.asyncActionCancelers=this.asyncActionCancelers||[],this.asyncActionCancelers.push(function(){s=u})},t.prototype.cancelAsyncActions=function(){this.asyncActionCancelers&&((0,r.default)(this.asyncActionCancelers),this.asyncActionCancelers=null)},t.prototype.handleAsyncActionComplete=function(t,e){var n=(0,i.default)(this.createContext(),e);this.executeTrigger(t,n)},t.prototype.startTimers=function(t){var e=this,n=this.config.states[t];n&&n.timers.length>0&&(this.timerIDs=n.timers.map(function(t){return setTimeout(e.handleTimeout,t.timeout,t)}))},t.prototype.stopTimers=function(){this.timerIDs&&(this.timerIDs.forEach(clearTimeout),this.timerIDs=null)},t.prototype.handleTimeout=function(t){this.executeTrigger(t,this.createContext())},t.prototype.startSubmachines=function(e){var n=this.config.states[e];n&&n.submachine&&(this.submachines[e]||(this.submachines[e]=new t(n.submachine,this.taskScheduler,this.contextFactory)),this.submachines[e].start())},t.prototype.stopSubmachines=function(){var t=this.submachines[this.currentState];t&&t.stop()},t.prototype.createContext=function(){return this.contextFactory(this)},t.prototype.createContextWithEvent=function(t,e){var n=this.createContext();return n.event=t,void 0!==e&&(n.eventPayload=e),n},t.getFirstAllowedTransition=function(t,e){for(var n=0;n<t.length;n++)if(!t[n].condition||t[n].condition(e))return t[n];return null},t.prototype.getFirstAllowedTransitionForEvent=function(e){var n=this.config.states[this.currentState];if(!n)return null;var o=null,r=n.events[e.event];return r&&(o=t.getFirstAllowedTransition(r.transitions,e)),!o&&n.anyEventTrigger&&(o=t.getFirstAllowedTransition(n.anyEventTrigger.transitions,e)),o},t.prototype.executeTrigger=function(e,n){var o=this;this.taskScheduler.execute(function(){var r=t.getFirstAllowedTransition(e.transitions,n);r&&o.executeTransition(r,n)})},t}();e.default=a},function(t,e,n){"use strict";e.__esModule=!0;var o,r=n(1);var i=function(t){function e(n,o){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var r=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.call(this,n));return r.config.timeout=o,r}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e}(((o=r)&&o.__esModule?o:{default:o}).default);e.default=i},function(t,e,n){"use strict";e.__esModule=!0,e.default=function(t,e){var n=Object.getPrototypeOf(t),o=Object.create(n);return Object.keys(t).forEach(function(n){o[n]=e(t[n])}),o}},function(t,e,n){"use strict";e.__esModule=!0;var o=u(n(0)),r=u(n(7)),i=u(n(6)),s=u(n(3));function u(t){return t&&t.__esModule?t:{default:t}}var a=function(t){function e(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var n=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.call(this));return n.config={global:new r.default(n),initialState:null,states:Object.create(null)},n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.global=function(){return this.config.global},e.prototype.initialState=function(t){return this.config.initialState=t,this.state(t)},e.prototype.state=function(t){return this.config.states[t]||(this.config.states[t]=new i.default(this)),this.config.states[t]},e.prototype.getConfig=function(){return this.buildConfig()},e.prototype.start=function(){var t=this.getConfig();return s.default.start(t)},e}(o.default);e.default=a},function(t,e,n){"use strict";e.__esModule=!0,e.StateMachineConfigurator=void 0;var o=f(n(14)),r=f(n(7)),i=f(n(6)),s=f(n(1)),u=f(n(5)),a=f(n(4)),c=f(n(8));function f(t){return t&&t.__esModule?t:{default:t}}e.StateMachineConfigurator=o.default,(0,c.default)(r.default,o.default),(0,c.default)(i.default,o.default),(0,c.default)(u.default,i.default),(0,c.default)(u.default,s.default),(0,c.default)(u.default,a.default)},function(t,e,n){"use strict";e.__esModule=!0;var o,r=n(15),i=n(3),s=(o=i)&&o.__esModule?o:{default:o};var u={configure:function(){return new r.StateMachineConfigurator},start:function(t){return s.default.start(t)}};e.default=u},function(t,e,n){"use strict";var o=n(16).default;(0,n(2).default)(e,o),e.default=o}])});