UNPKG

@umerx/alpaca

Version:

A TypeScript Node.js library for the https://alpaca.markets REST API and WebSocket streams.

1 lines 120 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("util")):"function"==typeof define&&define.amd?define(["exports","util"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).alpaca={},e.require$$0$3)}(this,(function(exports,require$$0$3){"use strict";function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var require$$0__default=_interopDefaultLegacy(require$$0$3),shams=function(){if("function"!=typeof Symbol||"function"!=typeof Object.getOwnPropertySymbols)return!1;if("symbol"==typeof Symbol.iterator)return!0;var e={},t=Symbol("test"),r=Object(t);if("string"==typeof t)return!1;if("[object Symbol]"!==Object.prototype.toString.call(t))return!1;if("[object Symbol]"!==Object.prototype.toString.call(r))return!1;for(t in e[t]=42,e)return!1;if("function"==typeof Object.keys&&0!==Object.keys(e).length)return!1;if("function"==typeof Object.getOwnPropertyNames&&0!==Object.getOwnPropertyNames(e).length)return!1;var n=Object.getOwnPropertySymbols(e);if(1!==n.length||n[0]!==t)return!1;if(!Object.prototype.propertyIsEnumerable.call(e,t))return!1;if("function"==typeof Object.getOwnPropertyDescriptor){var i=Object.getOwnPropertyDescriptor(e,t);if(42!==i.value||!0!==i.enumerable)return!1}return!0},origSymbol="undefined"!=typeof Symbol&&Symbol,hasSymbols$1=function(){return"function"==typeof origSymbol&&("function"==typeof Symbol&&("symbol"==typeof origSymbol("foo")&&("symbol"==typeof Symbol("bar")&&shams())))},ERROR_MESSAGE="Function.prototype.bind called on incompatible ",slice=Array.prototype.slice,toStr$1=Object.prototype.toString,funcType="[object Function]",implementation=function(e){var t=this;if("function"!=typeof t||toStr$1.call(t)!==funcType)throw new TypeError(ERROR_MESSAGE+t);for(var r,n=slice.call(arguments,1),i=function(){if(this instanceof r){var i=t.apply(this,n.concat(slice.call(arguments)));return Object(i)===i?i:this}return t.apply(e,n.concat(slice.call(arguments)))},s=Math.max(0,t.length-n.length),o=[],a=0;a<s;a++)o.push("$"+a);if(r=Function("binder","return function ("+o.join(",")+"){ return binder.apply(this,arguments); }")(i),t.prototype){var c=function(){};c.prototype=t.prototype,r.prototype=new c,c.prototype=null}return r},functionBind=Function.prototype.bind||implementation,src=functionBind.call(Function.call,Object.prototype.hasOwnProperty),undefined$1,$SyntaxError=SyntaxError,$Function=Function,$TypeError$1=TypeError,getEvalledConstructor=function(e){try{return $Function('"use strict"; return ('+e+").constructor;")()}catch(e){}},$gOPD=Object.getOwnPropertyDescriptor;if($gOPD)try{$gOPD({},"")}catch(e){$gOPD=null}var throwTypeError=function(){throw new $TypeError$1},ThrowTypeError=$gOPD?function(){try{return throwTypeError}catch(e){try{return $gOPD(arguments,"callee").get}catch(e){return throwTypeError}}}():throwTypeError,hasSymbols=hasSymbols$1(),getProto=Object.getPrototypeOf||function(e){return e.__proto__},needsEval={},TypedArray="undefined"==typeof Uint8Array?undefined$1:getProto(Uint8Array),INTRINSICS={"%AggregateError%":"undefined"==typeof AggregateError?undefined$1:AggregateError,"%Array%":Array,"%ArrayBuffer%":"undefined"==typeof ArrayBuffer?undefined$1:ArrayBuffer,"%ArrayIteratorPrototype%":hasSymbols?getProto([][Symbol.iterator]()):undefined$1,"%AsyncFromSyncIteratorPrototype%":undefined$1,"%AsyncFunction%":needsEval,"%AsyncGenerator%":needsEval,"%AsyncGeneratorFunction%":needsEval,"%AsyncIteratorPrototype%":needsEval,"%Atomics%":"undefined"==typeof Atomics?undefined$1:Atomics,"%BigInt%":"undefined"==typeof BigInt?undefined$1:BigInt,"%Boolean%":Boolean,"%DataView%":"undefined"==typeof DataView?undefined$1:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":Error,"%eval%":eval,"%EvalError%":EvalError,"%Float32Array%":"undefined"==typeof Float32Array?undefined$1:Float32Array,"%Float64Array%":"undefined"==typeof Float64Array?undefined$1:Float64Array,"%FinalizationRegistry%":"undefined"==typeof FinalizationRegistry?undefined$1:FinalizationRegistry,"%Function%":$Function,"%GeneratorFunction%":needsEval,"%Int8Array%":"undefined"==typeof Int8Array?undefined$1:Int8Array,"%Int16Array%":"undefined"==typeof Int16Array?undefined$1:Int16Array,"%Int32Array%":"undefined"==typeof Int32Array?undefined$1:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":hasSymbols?getProto(getProto([][Symbol.iterator]())):undefined$1,"%JSON%":"object"==typeof JSON?JSON:undefined$1,"%Map%":"undefined"==typeof Map?undefined$1:Map,"%MapIteratorPrototype%":"undefined"!=typeof Map&&hasSymbols?getProto((new Map)[Symbol.iterator]()):undefined$1,"%Math%":Math,"%Number%":Number,"%Object%":Object,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":"undefined"==typeof Promise?undefined$1:Promise,"%Proxy%":"undefined"==typeof Proxy?undefined$1:Proxy,"%RangeError%":RangeError,"%ReferenceError%":ReferenceError,"%Reflect%":"undefined"==typeof Reflect?undefined$1:Reflect,"%RegExp%":RegExp,"%Set%":"undefined"==typeof Set?undefined$1:Set,"%SetIteratorPrototype%":"undefined"!=typeof Set&&hasSymbols?getProto((new Set)[Symbol.iterator]()):undefined$1,"%SharedArrayBuffer%":"undefined"==typeof SharedArrayBuffer?undefined$1:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":hasSymbols?getProto(""[Symbol.iterator]()):undefined$1,"%Symbol%":hasSymbols?Symbol:undefined$1,"%SyntaxError%":$SyntaxError,"%ThrowTypeError%":ThrowTypeError,"%TypedArray%":TypedArray,"%TypeError%":$TypeError$1,"%Uint8Array%":"undefined"==typeof Uint8Array?undefined$1:Uint8Array,"%Uint8ClampedArray%":"undefined"==typeof Uint8ClampedArray?undefined$1:Uint8ClampedArray,"%Uint16Array%":"undefined"==typeof Uint16Array?undefined$1:Uint16Array,"%Uint32Array%":"undefined"==typeof Uint32Array?undefined$1:Uint32Array,"%URIError%":URIError,"%WeakMap%":"undefined"==typeof WeakMap?undefined$1:WeakMap,"%WeakRef%":"undefined"==typeof WeakRef?undefined$1:WeakRef,"%WeakSet%":"undefined"==typeof WeakSet?undefined$1:WeakSet},doEval=function e(t){var r;if("%AsyncFunction%"===t)r=getEvalledConstructor("async function () {}");else if("%GeneratorFunction%"===t)r=getEvalledConstructor("function* () {}");else if("%AsyncGeneratorFunction%"===t)r=getEvalledConstructor("async function* () {}");else if("%AsyncGenerator%"===t){var n=e("%AsyncGeneratorFunction%");n&&(r=n.prototype)}else if("%AsyncIteratorPrototype%"===t){var i=e("%AsyncGenerator%");i&&(r=getProto(i.prototype))}return INTRINSICS[t]=r,r},LEGACY_ALIASES={"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},$concat=functionBind.call(Function.call,Array.prototype.concat),$spliceApply=functionBind.call(Function.apply,Array.prototype.splice),$replace=functionBind.call(Function.call,String.prototype.replace),$strSlice=functionBind.call(Function.call,String.prototype.slice),rePropName=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,reEscapeChar=/\\(\\)?/g,stringToPath=function(e){var t=$strSlice(e,0,1),r=$strSlice(e,-1);if("%"===t&&"%"!==r)throw new $SyntaxError("invalid intrinsic syntax, expected closing `%`");if("%"===r&&"%"!==t)throw new $SyntaxError("invalid intrinsic syntax, expected opening `%`");var n=[];return $replace(e,rePropName,(function(e,t,r,i){n[n.length]=r?$replace(i,reEscapeChar,"$1"):t||e})),n},getBaseIntrinsic=function(e,t){var r,n=e;if(src(LEGACY_ALIASES,n)&&(n="%"+(r=LEGACY_ALIASES[n])[0]+"%"),src(INTRINSICS,n)){var i=INTRINSICS[n];if(i===needsEval&&(i=doEval(n)),void 0===i&&!t)throw new $TypeError$1("intrinsic "+e+" exists, but is not available. Please file an issue!");return{alias:r,name:n,value:i}}throw new $SyntaxError("intrinsic "+e+" does not exist!")},getIntrinsic=function(e,t){if("string"!=typeof e||0===e.length)throw new $TypeError$1("intrinsic name must be a non-empty string");if(arguments.length>1&&"boolean"!=typeof t)throw new $TypeError$1('"allowMissing" argument must be a boolean');var r=stringToPath(e),n=r.length>0?r[0]:"",i=getBaseIntrinsic("%"+n+"%",t),s=i.name,o=i.value,a=!1,c=i.alias;c&&(n=c[0],$spliceApply(r,$concat([0,1],c)));for(var l=1,u=!0;l<r.length;l+=1){var p=r[l],d=$strSlice(p,0,1),h=$strSlice(p,-1);if(('"'===d||"'"===d||"`"===d||'"'===h||"'"===h||"`"===h)&&d!==h)throw new $SyntaxError("property names with quotes must have matching quotes");if("constructor"!==p&&u||(a=!0),src(INTRINSICS,s="%"+(n+="."+p)+"%"))o=INTRINSICS[s];else if(null!=o){if(!(p in o)){if(!t)throw new $TypeError$1("base intrinsic for "+e+" exists, but the property is not available.");return}if($gOPD&&l+1>=r.length){var y=$gOPD(o,p);o=(u=!!y)&&"get"in y&&!("originalValue"in y.get)?y.get:o[p]}else u=src(o,p),o=o[p];u&&!a&&(INTRINSICS[s]=o)}}return o},commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function getAugmentedNamespace(e){if(e.__esModule)return e;var t=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach((function(r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})})),t}function createCommonjsModule(e){var t={exports:{}};return e(t,t.exports),t.exports}var callBind=createCommonjsModule((function(e){var t=getIntrinsic("%Function.prototype.apply%"),r=getIntrinsic("%Function.prototype.call%"),n=getIntrinsic("%Reflect.apply%",!0)||functionBind.call(r,t),i=getIntrinsic("%Object.getOwnPropertyDescriptor%",!0),s=getIntrinsic("%Object.defineProperty%",!0),o=getIntrinsic("%Math.max%");if(s)try{s({},"a",{value:1})}catch(e){s=null}e.exports=function(e){var t=n(functionBind,r,arguments);if(i&&s){var a=i(t,"length");a.configurable&&s(t,"length",{value:1+o(0,e.length-(arguments.length-1))})}return t};var a=function(){return n(functionBind,t,arguments)};s?s(e.exports,"apply",{value:a}):e.exports.apply=a})),$indexOf=callBind(getIntrinsic("String.prototype.indexOf")),callBound=function(e,t){var r=getIntrinsic(e,!!t);return"function"==typeof r&&$indexOf(e,".prototype.")>-1?callBind(r):r},util_inspect=require$$0__default.default.inspect,hasMap="function"==typeof Map&&Map.prototype,mapSizeDescriptor=Object.getOwnPropertyDescriptor&&hasMap?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,mapSize=hasMap&&mapSizeDescriptor&&"function"==typeof mapSizeDescriptor.get?mapSizeDescriptor.get:null,mapForEach=hasMap&&Map.prototype.forEach,hasSet="function"==typeof Set&&Set.prototype,setSizeDescriptor=Object.getOwnPropertyDescriptor&&hasSet?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,setSize=hasSet&&setSizeDescriptor&&"function"==typeof setSizeDescriptor.get?setSizeDescriptor.get:null,setForEach=hasSet&&Set.prototype.forEach,hasWeakMap="function"==typeof WeakMap&&WeakMap.prototype,weakMapHas=hasWeakMap?WeakMap.prototype.has:null,hasWeakSet="function"==typeof WeakSet&&WeakSet.prototype,weakSetHas=hasWeakSet?WeakSet.prototype.has:null,hasWeakRef="function"==typeof WeakRef&&WeakRef.prototype,weakRefDeref=hasWeakRef?WeakRef.prototype.deref:null,booleanValueOf=Boolean.prototype.valueOf,objectToString=Object.prototype.toString,functionToString=Function.prototype.toString,match=String.prototype.match,bigIntValueOf="function"==typeof BigInt?BigInt.prototype.valueOf:null,gOPS=Object.getOwnPropertySymbols,symToString="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?Symbol.prototype.toString:null,hasShammedSymbols="function"==typeof Symbol&&"object"==typeof Symbol.iterator,isEnumerable=Object.prototype.propertyIsEnumerable,gPO=("function"==typeof Reflect?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null),inspectCustom=util_inspect.custom,inspectSymbol=inspectCustom&&isSymbol(inspectCustom)?inspectCustom:null,toStringTag="function"==typeof Symbol&&void 0!==Symbol.toStringTag?Symbol.toStringTag:null,objectInspect=function e(t,r,n,i){var s=r||{};if(has$3(s,"quoteStyle")&&"single"!==s.quoteStyle&&"double"!==s.quoteStyle)throw new TypeError('option "quoteStyle" must be "single" or "double"');if(has$3(s,"maxStringLength")&&("number"==typeof s.maxStringLength?s.maxStringLength<0&&s.maxStringLength!==1/0:null!==s.maxStringLength))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var o=!has$3(s,"customInspect")||s.customInspect;if("boolean"!=typeof o&&"symbol"!==o)throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(has$3(s,"indent")&&null!==s.indent&&"\t"!==s.indent&&!(parseInt(s.indent,10)===s.indent&&s.indent>0))throw new TypeError('options "indent" must be "\\t", an integer > 0, or `null`');if(void 0===t)return"undefined";if(null===t)return"null";if("boolean"==typeof t)return t?"true":"false";if("string"==typeof t)return inspectString(t,s);if("number"==typeof t)return 0===t?1/0/t>0?"0":"-0":String(t);if("bigint"==typeof t)return String(t)+"n";var a=void 0===s.depth?5:s.depth;if(void 0===n&&(n=0),n>=a&&a>0&&"object"==typeof t)return isArray$3(t)?"[Array]":"[Object]";var c=getIndent(s,n);if(void 0===i)i=[];else if(indexOf(i,t)>=0)return"[Circular]";function l(t,r,o){if(r&&(i=i.slice()).push(r),o){var a={depth:s.depth};return has$3(s,"quoteStyle")&&(a.quoteStyle=s.quoteStyle),e(t,a,n+1,i)}return e(t,s,n+1,i)}if("function"==typeof t){var u=nameOf(t),p=arrObjKeys(t,l);return"[Function"+(u?": "+u:" (anonymous)")+"]"+(p.length>0?" { "+p.join(", ")+" }":"")}if(isSymbol(t)){var d=hasShammedSymbols?String(t).replace(/^(Symbol\(.*\))_[^)]*$/,"$1"):symToString.call(t);return"object"!=typeof t||hasShammedSymbols?d:markBoxed(d)}if(isElement(t)){for(var h="<"+String(t.nodeName).toLowerCase(),y=t.attributes||[],f=0;f<y.length;f++)h+=" "+y[f].name+"="+wrapQuotes(quote(y[f].value),"double",s);return h+=">",t.childNodes&&t.childNodes.length&&(h+="..."),h+="</"+String(t.nodeName).toLowerCase()+">"}if(isArray$3(t)){if(0===t.length)return"[]";var _=arrObjKeys(t,l);return c&&!singleLineValues(_)?"["+indentedJoin(_,c)+"]":"[ "+_.join(", ")+" ]"}if(isError(t)){var m=arrObjKeys(t,l);return 0===m.length?"["+String(t)+"]":"{ ["+String(t)+"] "+m.join(", ")+" }"}if("object"==typeof t&&o){if(inspectSymbol&&"function"==typeof t[inspectSymbol])return t[inspectSymbol]();if("symbol"!==o&&"function"==typeof t.inspect)return t.inspect()}if(isMap(t)){var g=[];return mapForEach.call(t,(function(e,r){g.push(l(r,t,!0)+" => "+l(e,t))})),collectionOf("Map",mapSize.call(t),g,c)}if(isSet(t)){var v=[];return setForEach.call(t,(function(e){v.push(l(e,t))})),collectionOf("Set",setSize.call(t),v,c)}if(isWeakMap(t))return weakCollectionOf("WeakMap");if(isWeakSet(t))return weakCollectionOf("WeakSet");if(isWeakRef(t))return weakCollectionOf("WeakRef");if(isNumber(t))return markBoxed(l(Number(t)));if(isBigInt(t))return markBoxed(l(bigIntValueOf.call(t)));if(isBoolean(t))return markBoxed(booleanValueOf.call(t));if(isString(t))return markBoxed(l(String(t)));if(!isDate(t)&&!isRegExp$1(t)){var b=arrObjKeys(t,l),w=gPO?gPO(t)===Object.prototype:t instanceof Object||t.constructor===Object,$=t instanceof Object?"":"null prototype",S=!w&&toStringTag&&Object(t)===t&&toStringTag in t?toStr(t).slice(8,-1):$?"Object":"",k=(w||"function"!=typeof t.constructor?"":t.constructor.name?t.constructor.name+" ":"")+(S||$?"["+[].concat(S||[],$||[]).join(": ")+"] ":"");return 0===b.length?k+"{}":c?k+"{"+indentedJoin(b,c)+"}":k+"{ "+b.join(", ")+" }"}return String(t)};function wrapQuotes(e,t,r){var n="double"===(r.quoteStyle||t)?'"':"'";return n+e+n}function quote(e){return String(e).replace(/"/g,"&quot;")}function isArray$3(e){return!("[object Array]"!==toStr(e)||toStringTag&&"object"==typeof e&&toStringTag in e)}function isDate(e){return!("[object Date]"!==toStr(e)||toStringTag&&"object"==typeof e&&toStringTag in e)}function isRegExp$1(e){return!("[object RegExp]"!==toStr(e)||toStringTag&&"object"==typeof e&&toStringTag in e)}function isError(e){return!("[object Error]"!==toStr(e)||toStringTag&&"object"==typeof e&&toStringTag in e)}function isString(e){return!("[object String]"!==toStr(e)||toStringTag&&"object"==typeof e&&toStringTag in e)}function isNumber(e){return!("[object Number]"!==toStr(e)||toStringTag&&"object"==typeof e&&toStringTag in e)}function isBoolean(e){return!("[object Boolean]"!==toStr(e)||toStringTag&&"object"==typeof e&&toStringTag in e)}function isSymbol(e){if(hasShammedSymbols)return e&&"object"==typeof e&&e instanceof Symbol;if("symbol"==typeof e)return!0;if(!e||"object"!=typeof e||!symToString)return!1;try{return symToString.call(e),!0}catch(e){}return!1}function isBigInt(e){if(!e||"object"!=typeof e||!bigIntValueOf)return!1;try{return bigIntValueOf.call(e),!0}catch(e){}return!1}var hasOwn=Object.prototype.hasOwnProperty||function(e){return e in this};function has$3(e,t){return hasOwn.call(e,t)}function toStr(e){return objectToString.call(e)}function nameOf(e){if(e.name)return e.name;var t=match.call(functionToString.call(e),/^function\s*([\w$]+)/);return t?t[1]:null}function indexOf(e,t){if(e.indexOf)return e.indexOf(t);for(var r=0,n=e.length;r<n;r++)if(e[r]===t)return r;return-1}function isMap(e){if(!mapSize||!e||"object"!=typeof e)return!1;try{mapSize.call(e);try{setSize.call(e)}catch(e){return!0}return e instanceof Map}catch(e){}return!1}function isWeakMap(e){if(!weakMapHas||!e||"object"!=typeof e)return!1;try{weakMapHas.call(e,weakMapHas);try{weakSetHas.call(e,weakSetHas)}catch(e){return!0}return e instanceof WeakMap}catch(e){}return!1}function isWeakRef(e){if(!weakRefDeref||!e||"object"!=typeof e)return!1;try{return weakRefDeref.call(e),!0}catch(e){}return!1}function isSet(e){if(!setSize||!e||"object"!=typeof e)return!1;try{setSize.call(e);try{mapSize.call(e)}catch(e){return!0}return e instanceof Set}catch(e){}return!1}function isWeakSet(e){if(!weakSetHas||!e||"object"!=typeof e)return!1;try{weakSetHas.call(e,weakSetHas);try{weakMapHas.call(e,weakMapHas)}catch(e){return!0}return e instanceof WeakSet}catch(e){}return!1}function isElement(e){return!(!e||"object"!=typeof e)&&("undefined"!=typeof HTMLElement&&e instanceof HTMLElement||"string"==typeof e.nodeName&&"function"==typeof e.getAttribute)}function inspectString(e,t){if(e.length>t.maxStringLength){var r=e.length-t.maxStringLength,n="... "+r+" more character"+(r>1?"s":"");return inspectString(e.slice(0,t.maxStringLength),t)+n}return wrapQuotes(e.replace(/(['\\])/g,"\\$1").replace(/[\x00-\x1f]/g,lowbyte),"single",t)}function lowbyte(e){var t=e.charCodeAt(0),r={8:"b",9:"t",10:"n",12:"f",13:"r"}[t];return r?"\\"+r:"\\x"+(t<16?"0":"")+t.toString(16).toUpperCase()}function markBoxed(e){return"Object("+e+")"}function weakCollectionOf(e){return e+" { ? }"}function collectionOf(e,t,r,n){return e+" ("+t+") {"+(n?indentedJoin(r,n):r.join(", "))+"}"}function singleLineValues(e){for(var t=0;t<e.length;t++)if(indexOf(e[t],"\n")>=0)return!1;return!0}function getIndent(e,t){var r;if("\t"===e.indent)r="\t";else{if(!("number"==typeof e.indent&&e.indent>0))return null;r=Array(e.indent+1).join(" ")}return{base:r,prev:Array(t+1).join(r)}}function indentedJoin(e,t){if(0===e.length)return"";var r="\n"+t.prev+t.base;return r+e.join(","+r)+"\n"+t.prev}function arrObjKeys(e,t){var r=isArray$3(e),n=[];if(r){n.length=e.length;for(var i=0;i<e.length;i++)n[i]=has$3(e,i)?t(e[i],e):""}var s,o="function"==typeof gOPS?gOPS(e):[];if(hasShammedSymbols){s={};for(var a=0;a<o.length;a++)s["$"+o[a]]=o[a]}for(var c in e)has$3(e,c)&&(r&&String(Number(c))===c&&c<e.length||hasShammedSymbols&&s["$"+c]instanceof Symbol||(/[^\w$]/.test(c)?n.push(t(c,e)+": "+t(e[c],e)):n.push(c+": "+t(e[c],e))));if("function"==typeof gOPS)for(var l=0;l<o.length;l++)isEnumerable.call(e,o[l])&&n.push("["+t(o[l])+"]: "+t(e[o[l]],e));return n}var $TypeError=getIntrinsic("%TypeError%"),$WeakMap=getIntrinsic("%WeakMap%",!0),$Map=getIntrinsic("%Map%",!0),$weakMapGet=callBound("WeakMap.prototype.get",!0),$weakMapSet=callBound("WeakMap.prototype.set",!0),$weakMapHas=callBound("WeakMap.prototype.has",!0),$mapGet=callBound("Map.prototype.get",!0),$mapSet=callBound("Map.prototype.set",!0),$mapHas=callBound("Map.prototype.has",!0),listGetNode=function(e,t){for(var r,n=e;null!==(r=n.next);n=r)if(r.key===t)return n.next=r.next,r.next=e.next,e.next=r,r},listGet=function(e,t){var r=listGetNode(e,t);return r&&r.value},listSet=function(e,t,r){var n=listGetNode(e,t);n?n.value=r:e.next={key:t,next:e.next,value:r}},listHas=function(e,t){return!!listGetNode(e,t)},sideChannel=function(){var e,t,r,n={assert:function(e){if(!n.has(e))throw new $TypeError("Side channel does not contain "+objectInspect(e))},get:function(n){if($WeakMap&&n&&("object"==typeof n||"function"==typeof n)){if(e)return $weakMapGet(e,n)}else if($Map){if(t)return $mapGet(t,n)}else if(r)return listGet(r,n)},has:function(n){if($WeakMap&&n&&("object"==typeof n||"function"==typeof n)){if(e)return $weakMapHas(e,n)}else if($Map){if(t)return $mapHas(t,n)}else if(r)return listHas(r,n);return!1},set:function(n,i){$WeakMap&&n&&("object"==typeof n||"function"==typeof n)?(e||(e=new $WeakMap),$weakMapSet(e,n,i)):$Map?(t||(t=new $Map),$mapSet(t,n,i)):(r||(r={key:{},next:null}),listSet(r,n,i))}};return n},replace=String.prototype.replace,percentTwenties=/%20/g,Format={RFC1738:"RFC1738",RFC3986:"RFC3986"},formats={default:Format.RFC3986,formatters:{RFC1738:function(e){return replace.call(e,percentTwenties,"+")},RFC3986:function(e){return String(e)}},RFC1738:Format.RFC1738,RFC3986:Format.RFC3986},has$2=Object.prototype.hasOwnProperty,isArray$2=Array.isArray,hexTable=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),compactQueue=function(e){for(;e.length>1;){var t=e.pop(),r=t.obj[t.prop];if(isArray$2(r)){for(var n=[],i=0;i<r.length;++i)void 0!==r[i]&&n.push(r[i]);t.obj[t.prop]=n}}},arrayToObject=function(e,t){for(var r=t&&t.plainObjects?Object.create(null):{},n=0;n<e.length;++n)void 0!==e[n]&&(r[n]=e[n]);return r},merge=function e(t,r,n){if(!r)return t;if("object"!=typeof r){if(isArray$2(t))t.push(r);else{if(!t||"object"!=typeof t)return[t,r];(n&&(n.plainObjects||n.allowPrototypes)||!has$2.call(Object.prototype,r))&&(t[r]=!0)}return t}if(!t||"object"!=typeof t)return[t].concat(r);var i=t;return isArray$2(t)&&!isArray$2(r)&&(i=arrayToObject(t,n)),isArray$2(t)&&isArray$2(r)?(r.forEach((function(r,i){if(has$2.call(t,i)){var s=t[i];s&&"object"==typeof s&&r&&"object"==typeof r?t[i]=e(s,r,n):t.push(r)}else t[i]=r})),t):Object.keys(r).reduce((function(t,i){var s=r[i];return has$2.call(t,i)?t[i]=e(t[i],s,n):t[i]=s,t}),i)},assign=function(e,t){return Object.keys(t).reduce((function(e,r){return e[r]=t[r],e}),e)},decode=function(e,t,r){var n=e.replace(/\+/g," ");if("iso-8859-1"===r)return n.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(n)}catch(e){return n}},encode=function(e,t,r,n,i){if(0===e.length)return e;var s=e;if("symbol"==typeof e?s=Symbol.prototype.toString.call(e):"string"!=typeof e&&(s=String(e)),"iso-8859-1"===r)return escape(s).replace(/%u[0-9a-f]{4}/gi,(function(e){return"%26%23"+parseInt(e.slice(2),16)+"%3B"}));for(var o="",a=0;a<s.length;++a){var c=s.charCodeAt(a);45===c||46===c||95===c||126===c||c>=48&&c<=57||c>=65&&c<=90||c>=97&&c<=122||i===formats.RFC1738&&(40===c||41===c)?o+=s.charAt(a):c<128?o+=hexTable[c]:c<2048?o+=hexTable[192|c>>6]+hexTable[128|63&c]:c<55296||c>=57344?o+=hexTable[224|c>>12]+hexTable[128|c>>6&63]+hexTable[128|63&c]:(a+=1,c=65536+((1023&c)<<10|1023&s.charCodeAt(a)),o+=hexTable[240|c>>18]+hexTable[128|c>>12&63]+hexTable[128|c>>6&63]+hexTable[128|63&c])}return o},compact=function(e){for(var t=[{obj:{o:e},prop:"o"}],r=[],n=0;n<t.length;++n)for(var i=t[n],s=i.obj[i.prop],o=Object.keys(s),a=0;a<o.length;++a){var c=o[a],l=s[c];"object"==typeof l&&null!==l&&-1===r.indexOf(l)&&(t.push({obj:s,prop:c}),r.push(l))}return compactQueue(t),e},isRegExp=function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},isBuffer=function(e){return!(!e||"object"!=typeof e)&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},combine=function(e,t){return[].concat(e,t)},maybeMap=function(e,t){if(isArray$2(e)){for(var r=[],n=0;n<e.length;n+=1)r.push(t(e[n]));return r}return t(e)},utils={arrayToObject:arrayToObject,assign:assign,combine:combine,compact:compact,decode:decode,encode:encode,isBuffer:isBuffer,isRegExp:isRegExp,maybeMap:maybeMap,merge:merge},has$1=Object.prototype.hasOwnProperty,arrayPrefixGenerators={brackets:function(e){return e+"[]"},comma:"comma",indices:function(e,t){return e+"["+t+"]"},repeat:function(e){return e}},isArray$1=Array.isArray,split=String.prototype.split,push=Array.prototype.push,pushToArray=function(e,t){push.apply(e,isArray$1(t)?t:[t])},toISO=Date.prototype.toISOString,defaultFormat=formats.default,defaults$1={addQueryPrefix:!1,allowDots:!1,charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encoder:utils.encode,encodeValuesOnly:!1,format:defaultFormat,formatter:formats.formatters[defaultFormat],indices:!1,serializeDate:function(e){return toISO.call(e)},skipNulls:!1,strictNullHandling:!1},isNonNullishPrimitive=function(e){return"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"symbol"==typeof e||"bigint"==typeof e},sentinel={},stringify=function e(t,r,n,i,s,o,a,c,l,u,p,d,h,y,f){for(var _=t,m=f,g=0,v=!1;void 0!==(m=m.get(sentinel))&&!v;){var b=m.get(t);if(g+=1,void 0!==b){if(b===g)throw new RangeError("Cyclic object value");v=!0}void 0===m.get(sentinel)&&(g=0)}if("function"==typeof a?_=a(r,_):_ instanceof Date?_=u(_):"comma"===n&&isArray$1(_)&&(_=utils.maybeMap(_,(function(e){return e instanceof Date?u(e):e}))),null===_){if(i)return o&&!h?o(r,defaults$1.encoder,y,"key",p):r;_=""}if(isNonNullishPrimitive(_)||utils.isBuffer(_)){if(o){var w=h?r:o(r,defaults$1.encoder,y,"key",p);if("comma"===n&&h){for(var $=split.call(String(_),","),S="",k=0;k<$.length;++k)S+=(0===k?"":",")+d(o($[k],defaults$1.encoder,y,"value",p));return[d(w)+"="+S]}return[d(w)+"="+d(o(_,defaults$1.encoder,y,"value",p))]}return[d(r)+"="+d(String(_))]}var E,O=[];if(void 0===_)return O;if("comma"===n&&isArray$1(_))E=[{value:_.length>0?_.join(",")||null:void 0}];else if(isArray$1(a))E=a;else{var T=Object.keys(_);E=c?T.sort(c):T}for(var R=0;R<E.length;++R){var x=E[R],A="object"==typeof x&&void 0!==x.value?x.value:_[x];if(!s||null!==A){var P=isArray$1(_)?"function"==typeof n?n(r,x):r:r+(l?"."+x:"["+x+"]");f.set(t,g);var I=sideChannel();I.set(sentinel,f),pushToArray(O,e(A,P,n,i,s,o,a,c,l,u,p,d,h,y,I))}}return O},normalizeStringifyOptions=function(e){if(!e)return defaults$1;if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var t=e.charset||defaults$1.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=formats.default;if(void 0!==e.format){if(!has$1.call(formats.formatters,e.format))throw new TypeError("Unknown format option provided.");r=e.format}var n=formats.formatters[r],i=defaults$1.filter;return("function"==typeof e.filter||isArray$1(e.filter))&&(i=e.filter),{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:defaults$1.addQueryPrefix,allowDots:void 0===e.allowDots?defaults$1.allowDots:!!e.allowDots,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:defaults$1.charsetSentinel,delimiter:void 0===e.delimiter?defaults$1.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:defaults$1.encode,encoder:"function"==typeof e.encoder?e.encoder:defaults$1.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:defaults$1.encodeValuesOnly,filter:i,format:r,formatter:n,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:defaults$1.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:defaults$1.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:defaults$1.strictNullHandling}},stringify_1=function(e,t){var r,n=e,i=normalizeStringifyOptions(t);"function"==typeof i.filter?n=(0,i.filter)("",n):isArray$1(i.filter)&&(r=i.filter);var s,o=[];if("object"!=typeof n||null===n)return"";s=t&&t.arrayFormat in arrayPrefixGenerators?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices";var a=arrayPrefixGenerators[s];r||(r=Object.keys(n)),i.sort&&r.sort(i.sort);for(var c=sideChannel(),l=0;l<r.length;++l){var u=r[l];i.skipNulls&&null===n[u]||pushToArray(o,stringify(n[u],u,a,i.strictNullHandling,i.skipNulls,i.encode?i.encoder:null,i.filter,i.sort,i.allowDots,i.serializeDate,i.format,i.formatter,i.encodeValuesOnly,i.charset,c))}var p=o.join(i.delimiter),d=!0===i.addQueryPrefix?"?":"";return i.charsetSentinel&&("iso-8859-1"===i.charset?d+="utf8=%26%2310003%3B&":d+="utf8=%E2%9C%93&"),p.length>0?d+p:""},has=Object.prototype.hasOwnProperty,isArray=Array.isArray,defaults={allowDots:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decoder:utils.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},interpretNumericEntities=function(e){return e.replace(/&#(\d+);/g,(function(e,t){return String.fromCharCode(parseInt(t,10))}))},parseArrayValue=function(e,t){return e&&"string"==typeof e&&t.comma&&e.indexOf(",")>-1?e.split(","):e},isoSentinel="utf8=%26%2310003%3B",charsetSentinel="utf8=%E2%9C%93",parseValues=function(e,t){var r,n={},i=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,s=t.parameterLimit===1/0?void 0:t.parameterLimit,o=i.split(t.delimiter,s),a=-1,c=t.charset;if(t.charsetSentinel)for(r=0;r<o.length;++r)0===o[r].indexOf("utf8=")&&(o[r]===charsetSentinel?c="utf-8":o[r]===isoSentinel&&(c="iso-8859-1"),a=r,r=o.length);for(r=0;r<o.length;++r)if(r!==a){var l,u,p=o[r],d=p.indexOf("]="),h=-1===d?p.indexOf("="):d+1;-1===h?(l=t.decoder(p,defaults.decoder,c,"key"),u=t.strictNullHandling?null:""):(l=t.decoder(p.slice(0,h),defaults.decoder,c,"key"),u=utils.maybeMap(parseArrayValue(p.slice(h+1),t),(function(e){return t.decoder(e,defaults.decoder,c,"value")}))),u&&t.interpretNumericEntities&&"iso-8859-1"===c&&(u=interpretNumericEntities(u)),p.indexOf("[]=")>-1&&(u=isArray(u)?[u]:u),has.call(n,l)?n[l]=utils.combine(n[l],u):n[l]=u}return n},parseObject=function(e,t,r,n){for(var i=n?t:parseArrayValue(t,r),s=e.length-1;s>=0;--s){var o,a=e[s];if("[]"===a&&r.parseArrays)o=[].concat(i);else{o=r.plainObjects?Object.create(null):{};var c="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,l=parseInt(c,10);r.parseArrays||""!==c?!isNaN(l)&&a!==c&&String(l)===c&&l>=0&&r.parseArrays&&l<=r.arrayLimit?(o=[])[l]=i:"__proto__"!==c&&(o[c]=i):o={0:i}}i=o}return i},parseKeys=function(e,t,r,n){if(e){var i=r.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,s=/(\[[^[\]]*])/g,o=r.depth>0&&/(\[[^[\]]*])/.exec(i),a=o?i.slice(0,o.index):i,c=[];if(a){if(!r.plainObjects&&has.call(Object.prototype,a)&&!r.allowPrototypes)return;c.push(a)}for(var l=0;r.depth>0&&null!==(o=s.exec(i))&&l<r.depth;){if(l+=1,!r.plainObjects&&has.call(Object.prototype,o[1].slice(1,-1))&&!r.allowPrototypes)return;c.push(o[1])}return o&&c.push("["+i.slice(o.index)+"]"),parseObject(c,t,r,n)}},normalizeParseOptions=function(e){if(!e)return defaults;if(null!==e.decoder&&void 0!==e.decoder&&"function"!=typeof e.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var t=void 0===e.charset?defaults.charset:e.charset;return{allowDots:void 0===e.allowDots?defaults.allowDots:!!e.allowDots,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:defaults.allowPrototypes,allowSparse:"boolean"==typeof e.allowSparse?e.allowSparse:defaults.allowSparse,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:defaults.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:defaults.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:defaults.comma,decoder:"function"==typeof e.decoder?e.decoder:defaults.decoder,delimiter:"string"==typeof e.delimiter||utils.isRegExp(e.delimiter)?e.delimiter:defaults.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:defaults.depth,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:defaults.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:defaults.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:defaults.plainObjects,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:defaults.strictNullHandling}},parse$1=function(e,t){var r=normalizeParseOptions(t);if(""===e||null==e)return r.plainObjects?Object.create(null):{};for(var n="string"==typeof e?parseValues(e,r):e,i=r.plainObjects?Object.create(null):{},s=Object.keys(n),o=0;o<s.length;++o){var a=s[o],c=parseKeys(a,n[a],r,"string"==typeof e);i=utils.merge(i,c,r)}return!0===r.allowSparse?i:utils.compact(i)},lib$1={formats:formats,parse:parse$1,stringify:stringify_1};function account(e){if(e)try{return{...e,raw:()=>e,buying_power:number(e.buying_power),regt_buying_power:number(e.regt_buying_power),daytrading_buying_power:number(e.daytrading_buying_power),cash:number(e.cash),created_at:new Date(e.created_at),portfolio_value:number(e.portfolio_value),multiplier:number(e.multiplier),equity:number(e.equity),last_equity:number(e.last_equity),long_market_value:number(e.long_market_value),short_market_value:number(e.short_market_value),initial_margin:number(e.initial_margin),maintenance_margin:number(e.maintenance_margin),last_maintenance_margin:number(e.last_maintenance_margin),sma:number(e.sma),status:e.status}}catch(e){throw new Error(`Account parsing failed. ${e.message}`)}}function clock(e){if(e)try{return{raw:()=>e,timestamp:new Date(e.timestamp),is_open:e.is_open,next_open:new Date(e.next_open),next_close:new Date(e.next_close)}}catch(e){throw new Error(`Order parsing failed. ${e.message}`)}}function latestTrade(e){if(e)try{return{...e,raw:()=>e,trade:{...e.trade,t:new Date(e.trade.t)}}}catch(e){throw new Error(`Latest trade parsing failed. ${e.message}`)}}function order(e){if(e)try{return{...e,raw:()=>e,created_at:new Date(e.created_at),updated_at:new Date(e.updated_at),submitted_at:new Date(e.submitted_at),filled_at:new Date(e.filled_at),expired_at:new Date(e.expired_at),canceled_at:new Date(e.canceled_at),failed_at:new Date(e.failed_at),replaced_at:new Date(e.replaced_at),qty:number(e.qty),filled_qty:number(e.filled_qty),type:e.type,side:e.side,time_in_force:e.time_in_force,limit_price:number(e.limit_price),stop_price:number(e.stop_price),filled_avg_price:number(e.filled_avg_price),status:e.status,legs:orders(e.legs),trail_price:number(e.trail_price),trail_percent:number(e.trail_percent),hwm:number(e.hwm),order_class:e.order_class}}catch(e){throw new Error(`Order parsing failed. ${e.message}`)}}function orders(e){return e?e.map((e=>order(e))):void 0}function canceled_order(e){if(!e)return;let t=e.body;delete e.body;try{return{...e,order:{...t,raw:()=>t,created_at:new Date(t.created_at),updated_at:new Date(t.updated_at),submitted_at:new Date(t.submitted_at),filled_at:new Date(t.filled_at),expired_at:new Date(t.expired_at),canceled_at:new Date(t.canceled_at),failed_at:new Date(t.failed_at),replaced_at:new Date(t.replaced_at),qty:number(t.qty),filled_qty:number(t.filled_qty),type:t.type,side:t.side,time_in_force:t.time_in_force,limit_price:number(t.limit_price),stop_price:number(t.stop_price),filled_avg_price:number(t.filled_avg_price),status:t.status,legs:orders(t.legs),trail_price:number(t.trail_price),trail_percent:number(t.trail_percent),hwm:number(t.hwm),order_class:t.order_class}}}catch(e){throw new Error(`Order parsing failed. ${e.message}`)}}function canceled_orders(e){return e?e.map((e=>canceled_order(e))):void 0}function position(e){if(e)try{return{...e,raw:()=>e,avg_entry_price:number(e.avg_entry_price),qty:number(e.qty),side:e.side,market_value:number(e.market_value),cost_basis:number(e.cost_basis),unrealized_pl:number(e.unrealized_pl),unrealized_plpc:number(e.unrealized_plpc),unrealized_intraday_pl:number(e.unrealized_intraday_pl),unrealized_intraday_plpc:number(e.unrealized_intraday_plpc),current_price:number(e.current_price),lastday_price:number(e.lastday_price),change_today:number(e.change_today)}}catch(e){throw new Error(`Position parsing failed. ${e.message}`)}}function positions(e){return e?e.map((e=>position(e))):void 0}function tradeActivity(e){if(e)try{return{...e,raw:()=>e,cum_qty:number(e.cum_qty),leaves_qty:number(e.leaves_qty),price:number(e.price),qty:number(e.qty),side:e.side,type:e.type}}catch(e){throw new Error(`TradeActivity parsing failed. ${e.message}`)}}function nonTradeActivity(e){if(e)try{return{...e,raw:()=>e,net_amount:number(e.net_amount),qty:number(e.qty),per_share_amount:number(e.per_share_amount)}}catch(e){throw new Error(`NonTradeActivity parsing failed. ${e.message}`)}}function activities(e){if(e)try{return e.map((e=>"FILL"===e.activity_type?tradeActivity(e):nonTradeActivity(e)))}catch(e){throw new Error(`Activity parsing failed. ${e.message}`)}}function pageOfTrades(e){if(e)try{return{raw:()=>e,trades:(null==e.trades?[]:e.trades).map((e=>({raw:()=>e,...e,t:new Date(e.t)}))),symbol:e.symbol,next_page_token:e.next_page_token}}catch(e){throw new Error(`PageOfTrades parsing failed "${e.message}"`)}}function pageOfQuotes(e){if(e)try{return{raw:()=>e,quotes:(null==e.quotes?[]:e.quotes).map((e=>({raw:()=>e,...e,t:new Date(e.t)}))),symbol:e.symbol,next_page_token:e.next_page_token}}catch(e){throw new Error(`PageOfTrades parsing failed "${e.message}"`)}}function pageOfBars(e){if(e)try{return{raw:()=>e,bars:(null==e.bars?[]:e.bars).map((e=>({raw:()=>e,...e,t:new Date(e.t)}))),symbol:e.symbol,next_page_token:e.next_page_token}}catch(e){throw new Error(`PageOfTrades parsing failed "${e.message}"`)}}function snapshot(e){if(e)try{return{...e,raw:()=>e,latestTrade:e.latestTrade?{...e.latestTrade,t:new Date(e.latestTrade.t)}:null,latestQuote:e.latestQuote?{...e.latestQuote,t:new Date(e.latestQuote.t)}:null,minuteBar:e.minuteBar?{...e.minuteBar,t:new Date(e.minuteBar.t)}:null,dailyBar:e.dailyBar?{...e.dailyBar,t:new Date(e.dailyBar.t)}:null,prevDailyBar:e.prevDailyBar?{...e.prevDailyBar,t:new Date(e.prevDailyBar.t)}:null}}catch(e){throw new Error(`Snapshot parsing failed "${e.message}"`)}}function snapshots(e){let t={};for(let[r,n]of Object.entries(e))t[r]=snapshot(n);return t}function number(e){if(void 0===e||null==e)return e;const t=parseFloat(e);return Number.isNaN(t)?null:t}function trade_update(e){if(e)return{raw:()=>e,event:e.event,execution_id:e.execution_id,order:order(e.order),...e.event_id&&{event_id:number(e.event_id)},...e.at&&{at:new Date(e.at)},...e.timestamp&&{timestamp:new Date(e.timestamp)},...e.position_qty&&{position_qty:number(e.position_qty)},...e.price&&{price:number(e.price)},...e.qty&&{qty:number(e.qty)}}}var parse={account:account,activities:activities,clock:clock,nonTradeActivity:nonTradeActivity,order:order,orders:orders,canceled_orders:canceled_orders,position:position,positions:positions,tradeActivity:tradeActivity,pageOfTrades:pageOfTrades,pageOfQuotes:pageOfQuotes,pageOfBars:pageOfBars,snapshot:snapshot,snapshots:snapshots,trade_update:trade_update,latestTrade:latestTrade};function unfetch_module(e,t){return t=t||{},new Promise((function(r,n){var i=new XMLHttpRequest,s=[],o=[],a={},c=function(){return{ok:2==(i.status/100|0),statusText:i.statusText,status:i.status,url:i.responseURL,text:function(){return Promise.resolve(i.responseText)},json:function(){return Promise.resolve(i.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([i.response]))},clone:c,headers:{keys:function(){return s},entries:function(){return o},get:function(e){return a[e.toLowerCase()]},has:function(e){return e.toLowerCase()in a}}}};for(var l in i.open(t.method||"get",e,!0),i.onload=function(){i.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(e,t,r){s.push(t=t.toLowerCase()),o.push([t,r]),a[t]=a[t]?a[t]+","+r:r})),r(c())},i.onerror=n,i.withCredentials="include"==t.credentials,t.headers)i.setRequestHeader(l,t.headers[l]);i.send(t.body||null)}))}var unfetch_module$1=Object.freeze({__proto__:null,default:unfetch_module}),require$$0$2=getAugmentedNamespace(unfetch_module$1),browser$1=self.fetch||(self.fetch=require$$0$2.default||require$$0$2);const endpoints={rest:{beta:"https://data.alpaca.markets/v1beta1",account:"https://api.alpaca.markets/v2",market_data_v2:"https://data.alpaca.markets/v2",market_data_v1:"https://data.alpaca.markets/v1"},websocket:{account:"wss://api.alpaca.markets/stream",market_data:(e="iex")=>`wss://stream.data.alpaca.markets/v2/${e}`}};var load=function(e,t,r={}){var n,i,s;for(n in t)s=t[n],r[n]=null!=(i=e[n])?i:s;return r},overwrite=function(e,t,r={}){var n,i;for(n in e)i=e[n],void 0!==t[n]&&(r[n]=i);return r},parser$8={load:load,overwrite:overwrite},DLList$2;DLList$2=class{constructor(e,t){this.incr=e,this.decr=t,this._first=null,this._last=null,this.length=0}push(e){var t;this.length++,"function"==typeof this.incr&&this.incr(),t={value:e,prev:this._last,next:null},null!=this._last?(this._last.next=t,this._last=t):this._first=this._last=t}shift(){var e;if(null!=this._first)return this.length--,"function"==typeof this.decr&&this.decr(),e=this._first.value,null!=(this._first=this._first.next)?this._first.prev=null:this._last=null,e}first(){if(null!=this._first)return this._first.value}getArray(){var e,t,r;for(e=this._first,r=[];null!=e;)r.push((t=e,e=e.next,t.value));return r}forEachShift(e){var t;for(t=this.shift();null!=t;)e(t),t=this.shift()}debug(){var e,t,r,n,i;for(e=this._first,i=[];null!=e;)i.push((t=e,e=e.next,{value:t.value,prev:null!=(r=t.prev)?r.value:void 0,next:null!=(n=t.next)?n.value:void 0}));return i}};var DLList_1=DLList$2,Events$6;function asyncGeneratorStep$8(e,t,r,n,i,s,o){try{var a=e[s](o),c=a.value}catch(e){return void r(e)}a.done?t(c):Promise.resolve(c).then(n,i)}function _asyncToGenerator$8(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var s=e.apply(t,r);function o(e){asyncGeneratorStep$8(s,n,i,o,a,"next",e)}function a(e){asyncGeneratorStep$8(s,n,i,o,a,"throw",e)}o(void 0)}))}}Events$6=class{constructor(e){if(this.instance=e,this._events={},null!=this.instance.on||null!=this.instance.once||null!=this.instance.removeAllListeners)throw new Error("An Emitter already exists for this object");this.instance.on=(e,t)=>this._addListener(e,"many",t),this.instance.once=(e,t)=>this._addListener(e,"once",t),this.instance.removeAllListeners=(e=null)=>null!=e?delete this._events[e]:this._events={}}_addListener(e,t,r){var n;return null==(n=this._events)[e]&&(n[e]=[]),this._events[e].push({cb:r,status:t}),this.instance}listenerCount(e){return null!=this._events[e]?this._events[e].length:0}trigger(e,...t){var r=this;return _asyncToGenerator$8((function*(){var n,i;try{if("debug"!==e&&r.trigger("debug",`Event triggered: ${e}`,t),null==r._events[e])return;return r._events[e]=r._events[e].filter((function(e){return"none"!==e.status})),i=r._events[e].map(function(){var e=_asyncToGenerator$8((function*(e){var n,i;if("none"!==e.status){"once"===e.status&&(e.status="none");try{return"function"==typeof(null!=(i="function"==typeof e.cb?e.cb(...t):void 0)?i.then:void 0)?yield i:i}catch(e){return n=e,r.trigger("error",n),null}}}));return function(t){return e.apply(this,arguments)}}()),(yield Promise.all(i)).find((function(e){return null!=e}))}catch(e){return n=e,r.trigger("error",n),null}}))()}};var Events_1=Events$6,DLList$1,Events$5,Queues$1;DLList$1=DLList_1,Events$5=Events_1,Queues$1=class{constructor(e){this.Events=new Events$5(this),this._length=0,this._lists=function(){var t,r,n;for(n=[],t=1,r=e;1<=r?t<=r:t>=r;1<=r?++t:--t)n.push(new DLList$1((()=>this.incr()),(()=>this.decr())));return n}.call(this)}incr(){if(0==this._length++)return this.Events.trigger("leftzero")}decr(){if(0==--this._length)return this.Events.trigger("zero")}push(e){return this._lists[e.options.priority].push(e)}queued(e){return null!=e?this._lists[e].length:this._length}shiftAll(e){return this._lists.forEach((function(t){return t.forEachShift(e)}))}getFirst(e=this._lists){var t,r,n;for(t=0,r=e.length;t<r;t++)if((n=e[t]).length>0)return n;return[]}shiftLastFrom(e){return this.getFirst(this._lists.slice(e).reverse()).shift()}};var Queues_1=Queues$1,BottleneckError$4;BottleneckError$4=class extends Error{};var BottleneckError_1=BottleneckError$4,BottleneckError$3,DEFAULT_PRIORITY$1,Job$1,NUM_PRIORITIES$1,parser$7;function asyncGeneratorStep$7(e,t,r,n,i,s,o){try{var a=e[s](o),c=a.value}catch(e){return void r(e)}a.done?t(c):Promise.resolve(c).then(n,i)}function _asyncToGenerator$7(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var s=e.apply(t,r);function o(e){asyncGeneratorStep$7(s,n,i,o,a,"next",e)}function a(e){asyncGeneratorStep$7(s,n,i,o,a,"throw",e)}o(void 0)}))}}NUM_PRIORITIES$1=10,DEFAULT_PRIORITY$1=5,parser$7=parser$8,BottleneckError$3=BottleneckError_1,Job$1=class{constructor(e,t,r,n,i,s,o,a){this.task=e,this.args=t,this.rejectOnDrop=i,this.Events=s,this._states=o,this.Promise=a,this.options=parser$7.load(r,n),this.options.priority=this._sanitizePriority(this.options.priority),this.options.id===n.id&&(this.options.id=`${this.options.id}-${this._randomIndex()}`),this.promise=new this.Promise(((e,t)=>{this._resolve=e,this._reject=t})),this.retryCount=0}_sanitizePriority(e){var t;return(t=~~e!==e?DEFAULT_PRIORITY$1:e)<0?0:t>NUM_PRIORITIES$1-1?NUM_PRIORITIES$1-1:t}_randomIndex(){return Math.random().toString(36).slice(2)}doDrop({error:e,message:t="This job has been dropped by Bottleneck"}={}){return!!this._states.remove(this.options.id)&&(this.rejectOnDrop&&this._reject(null!=e?e:new BottleneckError$3(t)),this.Events.trigger("dropped",{args:this.args,options:this.options,task:this.task,promise:this.promise}),!0)}_assertStatus(e){var t;if((t=this._states.jobStatus(this.options.id))!==e&&("DONE"!==e||null!==t))throw new BottleneckError$3(`Invalid job status ${t}, expected ${e}. Please open an issue at https://github.com/SGrondin/bottleneck/issues`)}doReceive(){return this._states.start(this.options.id),this.Events.trigger("received",{args:this.args,options:this.options})}doQueue(e,t){return this._assertStatus("RECEIVED"),this._states.next(this.options.id),this.Events.trigger("queued",{args:this.args,options:this.options,reachedHWM:e,blocked:t})}doRun(){return 0===this.retryCount?(this._assertStatus("QUEUED"),this._states.next(this.options.id)):this._assertStatus("EXECUTING"),this.Events.trigger("scheduled",{args:this.args,options:this.options})}doExecute(e,t,r,n){var i=this;return _asyncToGenerator$7((function*(){var s,o,a;0===i.retryCount?(i._assertStatus("RUNNING"),i._states.next(i.options.id)):i._assertStatus("EXECUTING"),o={args:i.args,options:i.options,retryCount:i.retryCount},i.Events.trigger("executing",o);try{if(a=yield null!=e?e.schedule(i.options,i.task,...i.args):i.task(...i.args),t())return i.doDone(o),yield n(i.options,o),i._assertStatus("DONE"),i._resolve(a)}catch(e){return s=e,i._onFailure(s,o,t,r,n)}}))()}doExpire(e,t,r){var