hedgequantx 2.9.153 → 2.9.154

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,705 @@
1
- const _0x1746f9=_0x67cf;(function(_0x3d2fd7,_0x154471){const _0x25dbb9=_0x67cf,_0x17daf6=_0x3d2fd7();while(!![]){try{const _0x3ecd46=parseInt(_0x25dbb9(0x1b9))/0x1*(-parseInt(_0x25dbb9(0x192))/0x2)+parseInt(_0x25dbb9(0x1e0))/0x3+parseInt(_0x25dbb9(0x1b0))/0x4*(parseInt(_0x25dbb9(0x18e))/0x5)+-parseInt(_0x25dbb9(0x19d))/0x6+parseInt(_0x25dbb9(0x1be))/0x7+-parseInt(_0x25dbb9(0x191))/0x8+-parseInt(_0x25dbb9(0x1ed))/0x9*(parseInt(_0x25dbb9(0x1a1))/0xa);if(_0x3ecd46===_0x154471)break;else _0x17daf6['push'](_0x17daf6['shift']());}catch(_0x28cf95){_0x17daf6['push'](_0x17daf6['shift']());}}}(_0x36db,0xe7252));function _0x36db(){const _0x5b2c86=['trades','6\x20(Z-Score,\x20VPIN,\x20Kyle,\x20Kalman,\x20Vol,\x20OFI)','zscoreExitThreshold','info','toFixed','_computeZScore','slice','5893218ncQZzu','zscoreThreshold','recordTradeResult','generateSignal','emit','vpinWindow','breakevenTicks','profitLockPct','size','_applyKalmanFilter','split','low','length','BID','short','25OZDKzR','_calculateATR','volumeBuffer','2443744qfUzyb','1018738PNRkSH','\x20|\x20Z:','normal','kalmanStates','/50\x20bars','winStreak','close','pow','_computeVPIN','baseTargetTicks',',\x20VPIN=','1653240cioaZy','\x20@\x20','_computeOrderFlowImbalance','set','10CcprOf',':\x20tick=','shift','uuid','processTick','log','kalmanMeasurementNoise','max','min','tickValue','barHistory','baseStopTicks','volume','_computeKyleLambda','volatility','1474392uPFCED','errorCovariance','side','buy','pnl','exports','processBar','ofi','now','2jBdAge','config','atrHistory','getBarHistory','%,\x20OFI=','8413090OfENgV','round','stats','tickSize','vpin','HQX_ULTRA_SCALPING_6MODELS','LOSS','ASK','high','\x20|\x20Conf:','minConfidence','stopMultiplier','lossStreak','onTick','signal','WIN','get','%\x20Kyle:','open','reset','push','kalman','weights','targetMultiplier','estimate','priceBuffer','ofiLookback','recentTrades','reduce','lastSignalTime','long','abs','toUpperCase','initialize','469374upPcCM','strategy','timestamp','symbol','getAnalysisState','contractId'];_0x36db=function(){return _0x5b2c86;};return _0x36db();}const EventEmitter=require('events'),{v4:uuidv4}=require(_0x1746f9(0x1a4)),OrderSide={'BID':0x0,'ASK':0x1},SignalStrength={'WEAK':0x1,'MODERATE':0x2,'STRONG':0x3,'VERY_STRONG':0x4};function _0x67cf(_0xb85477,_0x2bd4ab){_0xb85477=_0xb85477-0x18e;const _0x36db92=_0x36db();let _0x67cfa1=_0x36db92[_0xb85477];return _0x67cfa1;}class HQXUltraScalping extends EventEmitter{constructor(_0x5a43ad={}){const _0x258b23=_0x1746f9;super(),this[_0x258b23(0x1c1)]=_0x5a43ad['tickSize']||0.25,this['tickValue']=_0x5a43ad[_0x258b23(0x1aa)]||0x5,this['zscoreEntryThreshold']=1.5,this[_0x258b23(0x1e8)]=0.5,this['vpinWindow']=0x32,this['vpinToxicThreshold']=0.7,this['kalmanProcessNoise']=0.01,this[_0x258b23(0x1a7)]=0.1,this['volatilityLookback']=0x64,this[_0x258b23(0x1d8)]=0x14,this[_0x258b23(0x1ac)]=0x8,this[_0x258b23(0x19b)]=0x10,this['breakevenTicks']=0x4,this['profitLockPct']=0.5,this[_0x258b23(0x1c8)]=0.55,this[_0x258b23(0x1d4)]={'zscore':0.3,'ofi':0.2,'vpin':0.15,'kalman':0.15,'kyleLambda':0.1,'volatility':0.1},this['barHistory']=new Map(),this[_0x258b23(0x1d7)]=new Map(),this['volumeBuffer']=new Map(),this['kalmanStates']=new Map(),this[_0x258b23(0x1bb)]=new Map(),this['recentTrades']=[],this['winStreak']=0x0,this[_0x258b23(0x1ca)]=0x0,this['lastSignalTime']=0x0,this['cooldownMs']=0x7530,this['minHoldTimeMs']=0x2710,this[_0x258b23(0x1c0)]={'signals':0x0,'trades':0x0,'wins':0x0,'losses':0x0,'pnl':0x0};}[_0x1746f9(0x1df)](_0x2b546b,_0x5e5fd0=0.25,_0x65b5b3=0x5){const _0x2e3fff=_0x1746f9;this[_0x2e3fff(0x1c1)]=_0x5e5fd0,this[_0x2e3fff(0x1aa)]=_0x65b5b3,this['barHistory']['set'](_0x2b546b,[]),this['priceBuffer'][_0x2e3fff(0x1a0)](_0x2b546b,[]),this[_0x2e3fff(0x190)][_0x2e3fff(0x1a0)](_0x2b546b,[]),this[_0x2e3fff(0x1bb)]['set'](_0x2b546b,[]),this[_0x2e3fff(0x195)][_0x2e3fff(0x1a0)](_0x2b546b,{'estimate':0x0,'errorCovariance':0x1}),this['emit']('log',{'type':'info','message':'[HQX-UltraScalping]\x20Initialized\x20for\x20'+_0x2b546b+_0x2e3fff(0x1a2)+_0x5e5fd0+',\x20value='+_0x65b5b3}),this['emit'](_0x2e3fff(0x1a6),{'type':'info','message':'[HQX-UltraScalping]\x206\x20Models:\x20Z-Score(30%),\x20OFI(20%),\x20VPIN(15%),\x20Kalman(15%),\x20Kyle(10%),\x20Vol(10%)'});}['processTick'](_0x448e59){const _0x429bba=_0x1746f9,{contractId:_0x4215b2,price:_0x15b794,volume:_0x9b4f4a,side:_0x395d45,timestamp:_0x4f9c45}=_0x448e59,_0x3f02ad={'timestamp':_0x4f9c45||Date[_0x429bba(0x1b8)](),'open':_0x15b794,'high':_0x15b794,'low':_0x15b794,'close':_0x15b794,'volume':_0x9b4f4a||0x1};return this['processBar'](_0x4215b2,_0x3f02ad);}['onTick'](_0x32092f){const _0x3092f9=_0x1746f9;return this[_0x3092f9(0x1a5)](_0x32092f);}['onTrade'](_0x42cbc9){const _0x368754=_0x1746f9;return this['processTick']({'contractId':_0x42cbc9[_0x368754(0x1e5)]||_0x42cbc9[_0x368754(0x1e3)],'price':_0x42cbc9['price'],'volume':_0x42cbc9[_0x368754(0x1f5)]||_0x42cbc9['volume']||0x1,'side':_0x42cbc9[_0x368754(0x1b2)],'timestamp':_0x42cbc9[_0x368754(0x1e2)]||Date['now']()});}[_0x1746f9(0x1b6)](_0x100e21,_0x77e2f7){const _0x33a552=_0x1746f9;let _0xed9fba=this['barHistory']['get'](_0x100e21);!_0xed9fba&&(this['initialize'](_0x100e21),_0xed9fba=this['barHistory'][_0x33a552(0x1ce)](_0x100e21));_0xed9fba[_0x33a552(0x1d2)](_0x77e2f7);if(_0xed9fba['length']>0x1f4)_0xed9fba[_0x33a552(0x1a3)]();const _0x21bc76=this[_0x33a552(0x1d7)][_0x33a552(0x1ce)](_0x100e21);_0x21bc76[_0x33a552(0x1d2)](_0x77e2f7['close']);if(_0x21bc76['length']>0xc8)_0x21bc76[_0x33a552(0x1a3)]();const _0x537280=this[_0x33a552(0x190)][_0x33a552(0x1ce)](_0x100e21),_0x3fc573=_0x77e2f7['high']-_0x77e2f7['low'];let _0x322235=_0x77e2f7['volume']*0.5,_0x42a157=_0x77e2f7['volume']*0.5;if(_0x3fc573>0x0){const _0x53dc8f=(_0x77e2f7[_0x33a552(0x198)]-_0x77e2f7['low'])/_0x3fc573;_0x322235=_0x77e2f7['volume']*_0x53dc8f,_0x42a157=_0x77e2f7[_0x33a552(0x1ad)]*(0x1-_0x53dc8f);}_0x537280[_0x33a552(0x1d2)]({'buy':_0x322235,'sell':_0x42a157});if(_0x537280[_0x33a552(0x1f9)]>0x64)_0x537280['shift']();if(_0xed9fba['length']<0x32)return null;const _0x190dba=this[_0x33a552(0x1eb)](_0x21bc76),_0x26aa2f=this['_computeVPIN'](_0x537280),_0x45b15a=this[_0x33a552(0x1ae)](_0xed9fba),_0xbca683=this[_0x33a552(0x1f6)](_0x100e21,_0x77e2f7[_0x33a552(0x198)]),{regime:_0x309920,params:_0x56501b}=this['_detectVolatilityRegime'](_0x100e21,_0xed9fba),_0x1c97e4=this['_computeOrderFlowImbalance'](_0xed9fba);return this['_generateSignal'](_0x100e21,_0x77e2f7['close'],_0x190dba,_0x26aa2f,_0x45b15a,_0xbca683,_0x309920,_0x56501b,_0x1c97e4,_0xed9fba);}[_0x1746f9(0x1eb)](_0x3fa3ee,_0x48ee30=0x32){const _0x17d5ec=_0x1746f9;if(_0x3fa3ee['length']<_0x48ee30)return 0x0;const _0x1d457c=_0x3fa3ee['slice'](-_0x48ee30),_0x26aab8=_0x1d457c['reduce']((_0x138d6b,_0x2050a6)=>_0x138d6b+_0x2050a6,0x0)/_0x48ee30,_0x36e196=_0x1d457c[_0x17d5ec(0x1da)]((_0xe3681d,_0x3383c6)=>_0xe3681d+Math['pow'](_0x3383c6-_0x26aab8,0x2),0x0)/_0x48ee30,_0xd496a6=Math['sqrt'](_0x36e196);if(_0xd496a6<0.0001)return 0x0;const _0x2ac490=_0x3fa3ee[_0x3fa3ee[_0x17d5ec(0x1f9)]-0x1];return(_0x2ac490-_0x26aab8)/_0xd496a6;}['_computeVPIN'](_0x5c82d6){const _0x1070f4=_0x1746f9;if(_0x5c82d6['length']<this['vpinWindow'])return 0.5;const _0x2fb113=_0x5c82d6['slice'](-this[_0x1070f4(0x1f2)]);let _0x4bef7c=0x0,_0x1a10bd=0x0;for(const _0x3443d7 of _0x2fb113){_0x4bef7c+=_0x3443d7['buy'],_0x1a10bd+=_0x3443d7['sell'];}const _0x42b0e8=_0x4bef7c+_0x1a10bd;if(_0x42b0e8<0x1)return 0.5;return Math[_0x1070f4(0x1dd)](_0x4bef7c-_0x1a10bd)/_0x42b0e8;}[_0x1746f9(0x1ae)](_0x5806b8){const _0x2fa6fd=_0x1746f9;if(_0x5806b8[_0x2fa6fd(0x1f9)]<0x14)return 0x0;const _0x2fa503=_0x5806b8[_0x2fa6fd(0x1ec)](-0x14),_0x5c27c5=[],_0x464fcd=[];for(let _0x48ad11=0x1;_0x48ad11<_0x2fa503['length'];_0x48ad11++){_0x5c27c5['push'](_0x2fa503[_0x48ad11][_0x2fa6fd(0x198)]-_0x2fa503[_0x48ad11-0x1][_0x2fa6fd(0x198)]),_0x464fcd['push'](_0x2fa503[_0x48ad11][_0x2fa6fd(0x1ad)]);}const _0x52bb5c=_0x5c27c5[_0x2fa6fd(0x1da)]((_0x1760a4,_0xf2b971)=>_0x1760a4+_0xf2b971,0x0)/_0x5c27c5['length'],_0x3d4396=_0x464fcd['reduce']((_0x350f2b,_0x4a3fa2)=>_0x350f2b+_0x4a3fa2,0x0)/_0x464fcd[_0x2fa6fd(0x1f9)];let _0x29ede4=0x0,_0x173362=0x0;for(let _0x458871=0x0;_0x458871<_0x5c27c5[_0x2fa6fd(0x1f9)];_0x458871++){_0x29ede4+=(_0x5c27c5[_0x458871]-_0x52bb5c)*(_0x464fcd[_0x458871]-_0x3d4396),_0x173362+=Math[_0x2fa6fd(0x199)](_0x464fcd[_0x458871]-_0x3d4396,0x2);}_0x29ede4/=_0x5c27c5['length'],_0x173362/=_0x5c27c5['length'];if(_0x173362<0.0001)return 0x0;return Math['abs'](_0x29ede4/_0x173362);}[_0x1746f9(0x1f6)](_0x3520b3,_0x1f7107){const _0x4f81bc=_0x1746f9;let _0x441306=this[_0x4f81bc(0x195)]['get'](_0x3520b3);if(!_0x441306)return _0x441306={'estimate':_0x1f7107,'errorCovariance':0x1},this[_0x4f81bc(0x195)]['set'](_0x3520b3,_0x441306),_0x1f7107;const _0x2404ec=_0x441306['estimate'],_0x2bb5c9=_0x441306[_0x4f81bc(0x1b1)]+this['kalmanProcessNoise'],_0x1f7a65=_0x2bb5c9/(_0x2bb5c9+this['kalmanMeasurementNoise']),_0xc20102=_0x2404ec+_0x1f7a65*(_0x1f7107-_0x2404ec),_0x12c715=(0x1-_0x1f7a65)*_0x2bb5c9;return _0x441306[_0x4f81bc(0x1d6)]=_0xc20102,_0x441306['errorCovariance']=_0x12c715,_0xc20102;}['_detectVolatilityRegime'](_0x2f8a88,_0x4ac355){const _0xbc41f3=_0x1746f9,_0x339988=this[_0xbc41f3(0x18f)](_0x4ac355),_0x5f24be=_0x339988/this[_0xbc41f3(0x1c1)];let _0x279952=this[_0xbc41f3(0x1bb)][_0xbc41f3(0x1ce)](_0x2f8a88);!_0x279952&&(_0x279952=[],this[_0xbc41f3(0x1bb)]['set'](_0x2f8a88,_0x279952));_0x279952['push'](_0x339988);if(_0x279952['length']>0x1f4)_0x279952['shift']();let _0x524aa7=0.5;_0x279952['length']>=0x14&&(_0x524aa7=_0x279952['filter'](_0x474dda=>_0x474dda<=_0x339988)[_0xbc41f3(0x1f9)]/_0x279952[_0xbc41f3(0x1f9)]);let _0x1b333b,_0x5c07e8;if(_0x524aa7<0.25)_0x1b333b=_0xbc41f3(0x1f8),_0x5c07e8={'stopMultiplier':0.8,'targetMultiplier':0.9,'zscoreThreshold':1.2,'confidenceBonus':0.05};else _0x524aa7<0.75?(_0x1b333b='normal',_0x5c07e8={'stopMultiplier':0x1,'targetMultiplier':0x1,'zscoreThreshold':1.5,'confidenceBonus':0x0}):(_0x1b333b='high',_0x5c07e8={'stopMultiplier':1.3,'targetMultiplier':1.2,'zscoreThreshold':0x2,'confidenceBonus':-0.05});return{'regime':_0x1b333b,'params':_0x5c07e8};}[_0x1746f9(0x18f)](_0x4d91e8,_0x4c7029=0xe){const _0x8a4551=_0x1746f9;if(_0x4d91e8[_0x8a4551(0x1f9)]<_0x4c7029+0x1)return 2.5;const _0x19725f=[];for(let _0x10b591=_0x4d91e8['length']-_0x4c7029;_0x10b591<_0x4d91e8[_0x8a4551(0x1f9)];_0x10b591++){const _0x1ed810=_0x4d91e8[_0x10b591],_0x1b4fa9=_0x4d91e8[_0x10b591-0x1][_0x8a4551(0x198)],_0x4d5246=Math[_0x8a4551(0x1a8)](_0x1ed810['high']-_0x1ed810['low'],Math['abs'](_0x1ed810[_0x8a4551(0x1c6)]-_0x1b4fa9),Math['abs'](_0x1ed810['low']-_0x1b4fa9));_0x19725f['push'](_0x4d5246);}return _0x19725f['reduce']((_0x5a31af,_0x24e199)=>_0x5a31af+_0x24e199,0x0)/_0x19725f['length'];}[_0x1746f9(0x19f)](_0xecd442){const _0x4cc928=_0x1746f9;if(_0xecd442['length']<this['ofiLookback'])return 0x0;const _0x338ca2=_0xecd442['slice'](-this[_0x4cc928(0x1d8)]);let _0x31544c=0x0,_0x3a324d=0x0;for(const _0x25422f of _0x338ca2){const _0x20f7d6=_0x25422f['high']-_0x25422f[_0x4cc928(0x1f8)];if(_0x20f7d6>0x0){const _0x242e63=(_0x25422f[_0x4cc928(0x198)]-_0x25422f['low'])/_0x20f7d6;_0x31544c+=_0x242e63*_0x25422f['volume'],_0x3a324d+=(0x1-_0x242e63)*_0x25422f['volume'];}}const _0x53a73b=_0x31544c+_0x3a324d;if(_0x53a73b<0x1)return 0x0;return(_0x31544c-_0x3a324d)/_0x53a73b;}['_generateSignal'](_0x520adb,_0x335e18,_0x3f79c6,_0x469f2b,_0x590dc4,_0x22d515,_0x1ea5ce,_0x58b603,_0x48c458,_0x35cb52){const _0x234464=_0x1746f9,_0x42c7eb=Math['abs'](_0x3f79c6);if(_0x42c7eb<_0x58b603['zscoreThreshold'])return null;if(_0x469f2b>this['vpinToxicThreshold'])return null;let _0x2b818f;if(_0x3f79c6<-_0x58b603[_0x234464(0x1ee)])_0x2b818f=_0x234464(0x1dc);else{if(_0x3f79c6>_0x58b603['zscoreThreshold'])_0x2b818f=_0x234464(0x1fb);else return null;}const _0x46de4e=_0x2b818f===_0x234464(0x1dc)&&_0x48c458>0.1||_0x2b818f===_0x234464(0x1fb)&&_0x48c458<-0.1,_0xb7c0e=_0x335e18-_0x22d515,_0x32fefd=_0x2b818f===_0x234464(0x1dc)&&_0xb7c0e<0x0||_0x2b818f===_0x234464(0x1fb)&&_0xb7c0e>0x0,_0x47a9bb={'zscore':Math[_0x234464(0x1a9)](0x1,_0x42c7eb/0x4),'vpin':0x1-_0x469f2b,'kyleLambda':_0x590dc4>0.001?0.5:0.8,'kalman':_0x32fefd?0.8:0.4,'volatility':_0x1ea5ce===_0x234464(0x194)?0.8:_0x1ea5ce==='low'?0.7:0.6,'ofi':_0x46de4e?0.9:0.5,'composite':0x0};_0x47a9bb['composite']=_0x47a9bb['zscore']*this[_0x234464(0x1d4)]['zscore']+_0x47a9bb[_0x234464(0x1c2)]*this['weights']['vpin']+_0x47a9bb['kyleLambda']*this[_0x234464(0x1d4)]['kyleLambda']+_0x47a9bb['kalman']*this[_0x234464(0x1d4)][_0x234464(0x1d3)]+_0x47a9bb['volatility']*this['weights'][_0x234464(0x1af)]+_0x47a9bb['ofi']*this['weights'][_0x234464(0x1b7)];const _0x3fadc8=Math['min'](0x1,_0x47a9bb['composite']+_0x58b603['confidenceBonus']);if(_0x3fadc8<this['minConfidence'])return null;if(Date[_0x234464(0x1b8)]()-this['lastSignalTime']<this['cooldownMs'])return null;const _0x1274b=Math['round'](this['baseStopTicks']*_0x58b603[_0x234464(0x1c9)]),_0x19e244=Math[_0x234464(0x1bf)](this[_0x234464(0x19b)]*_0x58b603[_0x234464(0x1d5)]),_0x498c63=Math['max'](0x6,Math[_0x234464(0x1a9)](0xc,_0x1274b)),_0x248400=Math[_0x234464(0x1a8)](_0x498c63*1.5,Math['min'](0x18,_0x19e244));let _0x810d1b,_0xd2df88,_0x905f77,_0x3b7432;_0x2b818f===_0x234464(0x1dc)?(_0x810d1b=_0x335e18-_0x498c63*this['tickSize'],_0xd2df88=_0x335e18+_0x248400*this['tickSize'],_0x905f77=_0x335e18+this[_0x234464(0x1f3)]*this['tickSize'],_0x3b7432=_0x335e18+_0x248400*this['profitLockPct']*this[_0x234464(0x1c1)]):(_0x810d1b=_0x335e18+_0x498c63*this['tickSize'],_0xd2df88=_0x335e18-_0x248400*this['tickSize'],_0x905f77=_0x335e18-this[_0x234464(0x1f3)]*this['tickSize'],_0x3b7432=_0x335e18-_0x248400*this[_0x234464(0x1f4)]*this['tickSize']);const _0x3c2a2f=_0x248400/_0x498c63,_0x3678eb=Math['round'](_0x248400*0.5),_0x36cd4d=Math[_0x234464(0x1bf)](_0x498c63*0.4);let _0x458abf=SignalStrength['MODERATE'];if(_0x3fadc8>=0.85)_0x458abf=SignalStrength['VERY_STRONG'];else{if(_0x3fadc8>=0.75)_0x458abf=SignalStrength['STRONG'];else{if(_0x3fadc8<0.6)_0x458abf=SignalStrength['WEAK'];}}const _0x31fdb7=0.5+(_0x3fadc8-0.5)*0.4,_0x4dbc1d=_0x31fdb7*Math[_0x234464(0x1dd)](_0xd2df88-_0x335e18)-(0x1-_0x31fdb7)*Math[_0x234464(0x1dd)](_0x335e18-_0x810d1b);this[_0x234464(0x1db)]=Date['now'](),this['stats']['signals']++;const _0xd35aa3={'id':uuidv4(),'timestamp':Date[_0x234464(0x1b8)](),'symbol':_0x520adb[_0x234464(0x1f7)]('.')[0x0]||_0x520adb,'contractId':_0x520adb,'side':_0x2b818f===_0x234464(0x1dc)?OrderSide[_0x234464(0x1fa)]:OrderSide[_0x234464(0x1c5)],'direction':_0x2b818f,'strategy':_0x234464(0x1c3),'strength':_0x458abf,'edge':_0x4dbc1d,'confidence':_0x3fadc8,'entry':_0x335e18,'entryPrice':_0x335e18,'stopLoss':_0x810d1b,'takeProfit':_0xd2df88,'riskReward':_0x3c2a2f,'stopTicks':_0x498c63,'targetTicks':_0x248400,'trailTriggerTicks':_0x3678eb,'trailDistanceTicks':_0x36cd4d,'beBreakeven':_0x905f77,'profitLockLevel':_0x3b7432,'zScore':_0x3f79c6,'zScoreExit':this['zscoreExitThreshold'],'vpinValue':_0x469f2b,'kyleLambda':_0x590dc4,'kalmanEstimate':_0x22d515,'volatilityRegime':_0x1ea5ce,'ofiValue':_0x48c458,'models':_0x47a9bb,'orderFlowConfirmed':_0x46de4e,'kalmanConfirmed':_0x32fefd,'expires':Date['now']()+0xea60};return this['emit'](_0x234464(0x1cc),{'side':_0x2b818f==='long'?_0x234464(0x1b3):'sell','action':_0x234464(0x1d0),'reason':'Z='+_0x3f79c6['toFixed'](0x2)+_0x234464(0x19c)+(_0x469f2b*0x64)[_0x234464(0x1ea)](0x0)+_0x234464(0x1bd)+(_0x48c458*0x64)['toFixed'](0x0)+'%,\x20cf='+(_0x3fadc8*0x64)['toFixed'](0x0)+'%',..._0xd35aa3}),this['emit']('log',{'type':_0x234464(0x1e9),'message':'[HQX]\x20SIGNAL:\x20'+_0x2b818f[_0x234464(0x1de)]()+_0x234464(0x19e)+_0x335e18['toFixed'](0x2)+_0x234464(0x193)+_0x3f79c6['toFixed'](0x2)+'\x20VPIN:'+(_0x469f2b*0x64)[_0x234464(0x1ea)](0x0)+'%\x20OFI:'+(_0x48c458*0x64)[_0x234464(0x1ea)](0x0)+_0x234464(0x1cf)+_0x590dc4[_0x234464(0x1ea)](0x5)+'\x20Regime:'+_0x1ea5ce+_0x234464(0x1c7)+(_0x3fadc8*0x64)[_0x234464(0x1ea)](0x0)+'%'}),_0xd35aa3;}['shouldExitByZScore'](_0x29427c){const _0x2e24f5=_0x1746f9,_0x1954c8=this[_0x2e24f5(0x1d7)]['get'](_0x29427c);if(!_0x1954c8||_0x1954c8['length']<0x32)return![];const _0xfe7f7d=this[_0x2e24f5(0x1eb)](_0x1954c8);return Math['abs'](_0xfe7f7d)<this[_0x2e24f5(0x1e8)];}['getModelValues'](_0x32e4ba){const _0x804109=_0x1746f9,_0x4e24c7=this['priceBuffer']['get'](_0x32e4ba),_0x46623b=this[_0x804109(0x190)]['get'](_0x32e4ba),_0x492ce1=this[_0x804109(0x1ab)][_0x804109(0x1ce)](_0x32e4ba);if(!_0x4e24c7||!_0x46623b||!_0x492ce1||_0x492ce1['length']<0x32)return null;const _0x2fc56e=this['_computeZScore'](_0x4e24c7),_0xeda654=this[_0x804109(0x19a)](_0x46623b),_0x49b3e5=this['_computeKyleLambda'](_0x492ce1),_0x36f353=this[_0x804109(0x19f)](_0x492ce1);return{'zscore':Math[_0x804109(0x1a9)](0x1,Math[_0x804109(0x1dd)](_0x2fc56e)/0x4),'vpin':0x1-_0xeda654,'kyleLambda':_0x49b3e5>0.001?0.5:0.8,'kalman':0.7,'volatility':0.7,'ofi':Math[_0x804109(0x1dd)](_0x36f353)>0.1?0.8:0.5,'composite':0.7,'raw':{'zscore':_0x2fc56e,'vpin':_0xeda654,'kyleLambda':_0x49b3e5,'ofi':_0x36f353}};}[_0x1746f9(0x1e4)](_0x3ad9bf,_0x5ac53e){const _0x187fa3=_0x1746f9,_0x25bc3b=this[_0x187fa3(0x1ab)]['get'](_0x3ad9bf)||[];if(_0x25bc3b[_0x187fa3(0x1f9)]<0x32)return{'ready':![],'message':'Collecting\x20data...\x20'+_0x25bc3b[_0x187fa3(0x1f9)]+_0x187fa3(0x196)};const _0x6917d0=this['priceBuffer'][_0x187fa3(0x1ce)](_0x3ad9bf)||[],_0x5a9bd0=this[_0x187fa3(0x190)][_0x187fa3(0x1ce)](_0x3ad9bf)||[],_0x3a5335=this['_computeZScore'](_0x6917d0),_0x486926=this[_0x187fa3(0x19a)](_0x5a9bd0),_0x1ec2f1=this[_0x187fa3(0x19f)](_0x25bc3b),_0x1e61b5=this[_0x187fa3(0x1ae)](_0x25bc3b),{regime:_0x557940,params:_0x377daa}=this['_detectVolatilityRegime'](_0x3ad9bf,_0x25bc3b);return{'ready':!![],'zScore':_0x3a5335,'vpin':_0x486926,'ofi':_0x1ec2f1,'kyleLambda':_0x1e61b5,'regime':_0x557940,'stopTicks':Math[_0x187fa3(0x1bf)](this[_0x187fa3(0x1ac)]*_0x377daa['stopMultiplier']),'targetTicks':Math[_0x187fa3(0x1bf)](this['baseTargetTicks']*_0x377daa['targetMultiplier']),'threshold':_0x377daa['zscoreThreshold'],'barsProcessed':_0x25bc3b[_0x187fa3(0x1f9)],'models':_0x187fa3(0x1e7)};}['recordTradeResult'](_0x2744c7){const _0x573aef=_0x1746f9;this['recentTrades'][_0x573aef(0x1d2)]({'netPnl':_0x2744c7,'timestamp':Date['now']()});if(this[_0x573aef(0x1d9)][_0x573aef(0x1f9)]>0x64)this[_0x573aef(0x1d9)]['shift']();_0x2744c7>0x0?(this[_0x573aef(0x197)]++,this['lossStreak']=0x0,this['stats']['wins']++):(this['lossStreak']++,this[_0x573aef(0x197)]=0x0,this['stats']['losses']++),this[_0x573aef(0x1c0)][_0x573aef(0x1e6)]++,this[_0x573aef(0x1c0)][_0x573aef(0x1b4)]+=_0x2744c7,this[_0x573aef(0x1f1)](_0x573aef(0x1a6),{'type':'debug','message':'[HQX]\x20Trade\x20result:\x20'+(_0x2744c7>0x0?_0x573aef(0x1cd):_0x573aef(0x1c4))+'\x20$'+_0x2744c7[_0x573aef(0x1ea)](0x2)+',\x20streak:\x20'+(_0x2744c7>0x0?this['winStreak']:-this['lossStreak'])});}[_0x1746f9(0x1bc)](_0x4928ce){const _0xfdb719=_0x1746f9;return this[_0xfdb719(0x1ab)]['get'](_0x4928ce)||[];}['getStats'](){return this['stats'];}['reset'](_0x22ee62){const _0x5a6b14=_0x1746f9;this['barHistory'][_0x5a6b14(0x1a0)](_0x22ee62,[]),this['priceBuffer'][_0x5a6b14(0x1a0)](_0x22ee62,[]),this['volumeBuffer'][_0x5a6b14(0x1a0)](_0x22ee62,[]),this[_0x5a6b14(0x1bb)]['set'](_0x22ee62,[]),this[_0x5a6b14(0x195)][_0x5a6b14(0x1a0)](_0x22ee62,{'estimate':0x0,'errorCovariance':0x1}),this['emit']('log',{'type':'info','message':'[HQX-UltraScalping]\x20Reset\x20state\x20for\x20'+_0x22ee62});}}class UltraScalpingStrategy extends EventEmitter{constructor(_0x1a6888={}){const _0x17f7d5=_0x1746f9;super(),this[_0x17f7d5(0x1ba)]=_0x1a6888,this['strategy']=new HQXUltraScalping(_0x1a6888),this[_0x17f7d5(0x1e1)]['on']('signal',_0xde3f73=>this['emit']('signal',_0xde3f73)),this[_0x17f7d5(0x1e1)]['on']('log',_0x428e4f=>this[_0x17f7d5(0x1f1)](_0x17f7d5(0x1a6),_0x428e4f));}[_0x1746f9(0x1a5)](_0x56e7f0){const _0x344bc2=_0x1746f9;return this[_0x344bc2(0x1e1)][_0x344bc2(0x1a5)](_0x56e7f0);}[_0x1746f9(0x1cb)](_0x367642){return this['strategy']['onTick'](_0x367642);}['onTrade'](_0xaf0fd7){return this['strategy']['onTrade'](_0xaf0fd7);}[_0x1746f9(0x1b6)](_0x57daa5,_0x421f13){return this['strategy']['processBar'](_0x57daa5,_0x421f13);}['initialize'](_0x9f4b2d,_0x4b3240,_0x5e4246){const _0x1c46f3=_0x1746f9;return this[_0x1c46f3(0x1e1)]['initialize'](_0x9f4b2d,_0x4b3240,_0x5e4246);}[_0x1746f9(0x1e4)](_0x8c3608,_0x48c423){const _0x31b05a=_0x1746f9;return this[_0x31b05a(0x1e1)]['getAnalysisState'](_0x8c3608,_0x48c423);}[_0x1746f9(0x1ef)](_0x772829){const _0xca4138=_0x1746f9;return this['strategy'][_0xca4138(0x1ef)](_0x772829);}['reset'](_0x4b9f24){const _0x53f6b2=_0x1746f9;return this[_0x53f6b2(0x1e1)][_0x53f6b2(0x1d1)](_0x4b9f24);}['getStats'](){return this['strategy']['getStats']();}['getBarHistory'](_0x51fefb){const _0x2e3ee4=_0x1746f9;return this['strategy'][_0x2e3ee4(0x1bc)](_0x51fefb);}['getModelValues'](_0x3b8e36){return this['strategy']['getModelValues'](_0x3b8e36);}['shouldExitByZScore'](_0x5224c3){return this['strategy']['shouldExitByZScore'](_0x5224c3);}[_0x1746f9(0x1f0)](_0x5c5181){return null;}}module[_0x1746f9(0x1b5)]={'HQXUltraScalping':HQXUltraScalping,'UltraScalpingStrategy':UltraScalpingStrategy,'M1':UltraScalpingStrategy,'S1':HQXUltraScalping,'OrderSide':OrderSide,'SignalStrength':SignalStrength};
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
+ };
5
+
6
+ // ultra-scalping/config.js
7
+ var require_config = __commonJS({
8
+ "ultra-scalping/config.js"(exports2, module2) {
9
+ var DEFAULT_CONFIG = {
10
+ // Model Parameters
11
+ zscoreEntryThreshold: 1.5,
12
+ // Live trading threshold (backtest: 2.5)
13
+ zscoreExitThreshold: 0.5,
14
+ vpinWindow: 50,
15
+ vpinToxicThreshold: 0.7,
16
+ // Skip if VPIN > 0.7
17
+ volatilityLookback: 100,
18
+ ofiLookback: 20,
19
+ // Trade Parameters
20
+ baseStopTicks: 8,
21
+ // $40
22
+ baseTargetTicks: 16,
23
+ // $80
24
+ breakevenTicks: 4,
25
+ // Move to BE at +4 ticks
26
+ profitLockPct: 0.5,
27
+ // Lock 50% of profit
28
+ minConfidence: 0.55,
29
+ // Minimum composite confidence
30
+ cooldownMs: 3e4,
31
+ // 30 seconds between signals
32
+ minHoldTimeMs: 1e4,
33
+ // Minimum 10 seconds hold
34
+ // Model Weights (from Python backtest)
35
+ weights: {
36
+ zscore: 0.3,
37
+ // 30%
38
+ ofi: 0.2,
39
+ // 20%
40
+ vpin: 0.15,
41
+ // 15%
42
+ kalman: 0.15,
43
+ // 15%
44
+ kyleLambda: 0.1,
45
+ // 10%
46
+ volatility: 0.1
47
+ // 10%
48
+ },
49
+ // Session (Futures Market Hours - Sunday 18:00 to Friday 17:00 EST)
50
+ session: {
51
+ enabled: false,
52
+ // Trade anytime markets are open
53
+ timezone: "America/New_York"
54
+ }
55
+ };
56
+ module2.exports = { DEFAULT_CONFIG };
57
+ }
58
+ });
59
+
60
+ // common/types.js
61
+ var require_types = __commonJS({
62
+ "common/types.js"(exports2, module2) {
63
+ var OrderSide2 = { BID: 0, ASK: 1 };
64
+ var SignalStrength2 = { WEAK: 1, MODERATE: 2, STRONG: 3, VERY_STRONG: 4 };
65
+ module2.exports = { OrderSide: OrderSide2, SignalStrength: SignalStrength2 };
66
+ }
67
+ });
68
+
69
+ // ultra-scalping/signal.js
70
+ var require_signal = __commonJS({
71
+ "ultra-scalping/signal.js"(exports2, module2) {
72
+ var { v4: uuidv4 } = require("uuid");
73
+ var { OrderSide: OrderSide2, SignalStrength: SignalStrength2 } = require_types();
74
+ function generateSignal(params) {
75
+ const {
76
+ contractId,
77
+ currentPrice,
78
+ zscore,
79
+ vpin,
80
+ kyleLambda,
81
+ kalmanEstimate,
82
+ regime,
83
+ volParams,
84
+ ofi,
85
+ config,
86
+ tickSize
87
+ } = params;
88
+ const absZscore = Math.abs(zscore);
89
+ if (absZscore < volParams.zscoreThreshold) {
90
+ return null;
91
+ }
92
+ if (vpin > config.vpinToxicThreshold) {
93
+ return null;
94
+ }
95
+ let direction;
96
+ if (zscore < -volParams.zscoreThreshold) {
97
+ direction = "long";
98
+ } else if (zscore > volParams.zscoreThreshold) {
99
+ direction = "short";
100
+ } else {
101
+ return null;
102
+ }
103
+ const ofiConfirms = direction === "long" && ofi > 0.1 || direction === "short" && ofi < -0.1;
104
+ const kalmanDiff = currentPrice - kalmanEstimate;
105
+ const kalmanConfirms = direction === "long" && kalmanDiff < 0 || direction === "short" && kalmanDiff > 0;
106
+ const scores = {
107
+ zscore: Math.min(1, absZscore / 4),
108
+ // Normalize to 0-1
109
+ vpin: 1 - vpin,
110
+ // Lower VPIN = better
111
+ kyleLambda: kyleLambda > 1e-3 ? 0.5 : 0.8,
112
+ // Moderate lambda is good
113
+ kalman: kalmanConfirms ? 0.8 : 0.4,
114
+ volatility: regime === "normal" ? 0.8 : regime === "low" ? 0.7 : 0.6,
115
+ ofi: ofiConfirms ? 0.9 : 0.5,
116
+ composite: 0
117
+ // Calculated below
118
+ };
119
+ scores.composite = scores.zscore * config.weights.zscore + // 30%
120
+ scores.vpin * config.weights.vpin + // 15%
121
+ scores.kyleLambda * config.weights.kyleLambda + // 10%
122
+ scores.kalman * config.weights.kalman + // 15%
123
+ scores.volatility * config.weights.volatility + // 10%
124
+ scores.ofi * config.weights.ofi;
125
+ const confidence = Math.min(1, scores.composite + volParams.confidenceBonus);
126
+ if (confidence < config.minConfidence) {
127
+ return null;
128
+ }
129
+ const stopTicks = Math.round(config.baseStopTicks * volParams.stopMultiplier);
130
+ const targetTicks = Math.round(config.baseTargetTicks * volParams.targetMultiplier);
131
+ const actualStopTicks = Math.max(6, Math.min(12, stopTicks));
132
+ const actualTargetTicks = Math.max(actualStopTicks * 1.5, Math.min(24, targetTicks));
133
+ let stopLoss, takeProfit, beBreakeven, profitLockLevel;
134
+ if (direction === "long") {
135
+ stopLoss = currentPrice - actualStopTicks * tickSize;
136
+ takeProfit = currentPrice + actualTargetTicks * tickSize;
137
+ beBreakeven = currentPrice + config.breakevenTicks * tickSize;
138
+ profitLockLevel = currentPrice + actualTargetTicks * config.profitLockPct * tickSize;
139
+ } else {
140
+ stopLoss = currentPrice + actualStopTicks * tickSize;
141
+ takeProfit = currentPrice - actualTargetTicks * tickSize;
142
+ beBreakeven = currentPrice - config.breakevenTicks * tickSize;
143
+ profitLockLevel = currentPrice - actualTargetTicks * config.profitLockPct * tickSize;
144
+ }
145
+ const riskReward = actualTargetTicks / actualStopTicks;
146
+ const trailTriggerTicks = Math.round(actualTargetTicks * 0.5);
147
+ const trailDistanceTicks = Math.round(actualStopTicks * 0.4);
148
+ let strength = SignalStrength2.MODERATE;
149
+ if (confidence >= 0.85) strength = SignalStrength2.VERY_STRONG;
150
+ else if (confidence >= 0.75) strength = SignalStrength2.STRONG;
151
+ else if (confidence < 0.6) strength = SignalStrength2.WEAK;
152
+ const winProb = 0.5 + (confidence - 0.5) * 0.4;
153
+ const edge = winProb * Math.abs(takeProfit - currentPrice) - (1 - winProb) * Math.abs(currentPrice - stopLoss);
154
+ return {
155
+ id: uuidv4(),
156
+ timestamp: Date.now(),
157
+ symbol: contractId.split(".")[0] || contractId,
158
+ contractId,
159
+ side: direction === "long" ? OrderSide2.BID : OrderSide2.ASK,
160
+ direction,
161
+ strategy: "HQX_ULTRA_SCALPING_6MODELS",
162
+ strength,
163
+ edge,
164
+ confidence,
165
+ entry: currentPrice,
166
+ entryPrice: currentPrice,
167
+ stopLoss,
168
+ takeProfit,
169
+ riskReward,
170
+ stopTicks: actualStopTicks,
171
+ targetTicks: actualTargetTicks,
172
+ trailTriggerTicks,
173
+ trailDistanceTicks,
174
+ beBreakeven,
175
+ profitLockLevel,
176
+ // Model values for debugging/monitoring
177
+ zScore: zscore,
178
+ zScoreExit: config.zscoreExitThreshold,
179
+ vpinValue: vpin,
180
+ kyleLambda,
181
+ kalmanEstimate,
182
+ volatilityRegime: regime,
183
+ ofiValue: ofi,
184
+ models: scores,
185
+ // Order flow confirmation flag
186
+ orderFlowConfirmed: ofiConfirms,
187
+ kalmanConfirmed: kalmanConfirms,
188
+ expires: Date.now() + 6e4
189
+ };
190
+ }
191
+ module2.exports = { generateSignal };
192
+ }
193
+ });
194
+
195
+ // ultra-scalping/models/zscore.js
196
+ var require_zscore = __commonJS({
197
+ "ultra-scalping/models/zscore.js"(exports2, module2) {
198
+ function computeZScore(prices, window = 50) {
199
+ if (prices.length < window) return 0;
200
+ const recentPrices = prices.slice(-window);
201
+ const mean = recentPrices.reduce((a, b) => a + b, 0) / window;
202
+ const variance = recentPrices.reduce((sum, p) => sum + Math.pow(p - mean, 2), 0) / window;
203
+ const std = Math.sqrt(variance);
204
+ if (std < 1e-4) return 0;
205
+ const currentPrice = prices[prices.length - 1];
206
+ return (currentPrice - mean) / std;
207
+ }
208
+ module2.exports = { computeZScore };
209
+ }
210
+ });
211
+
212
+ // ultra-scalping/models/vpin.js
213
+ var require_vpin = __commonJS({
214
+ "ultra-scalping/models/vpin.js"(exports2, module2) {
215
+ function computeVPIN(volumes, vpinWindow = 50) {
216
+ if (volumes.length < vpinWindow) return 0.5;
217
+ const recentVolumes = volumes.slice(-vpinWindow);
218
+ let totalBuy = 0;
219
+ let totalSell = 0;
220
+ for (const v of recentVolumes) {
221
+ totalBuy += v.buy;
222
+ totalSell += v.sell;
223
+ }
224
+ const totalVolume = totalBuy + totalSell;
225
+ if (totalVolume < 1) return 0.5;
226
+ return Math.abs(totalBuy - totalSell) / totalVolume;
227
+ }
228
+ module2.exports = { computeVPIN };
229
+ }
230
+ });
231
+
232
+ // ultra-scalping/models/kyle.js
233
+ var require_kyle = __commonJS({
234
+ "ultra-scalping/models/kyle.js"(exports2, module2) {
235
+ function computeKyleLambda(bars) {
236
+ if (bars.length < 20) return 0;
237
+ const recentBars = bars.slice(-20);
238
+ const priceChanges = [];
239
+ const volumes = [];
240
+ for (let i = 1; i < recentBars.length; i++) {
241
+ priceChanges.push(recentBars[i].close - recentBars[i - 1].close);
242
+ volumes.push(recentBars[i].volume);
243
+ }
244
+ const meanPrice = priceChanges.reduce((a, b) => a + b, 0) / priceChanges.length;
245
+ const meanVol = volumes.reduce((a, b) => a + b, 0) / volumes.length;
246
+ let covariance = 0;
247
+ let varianceVol = 0;
248
+ for (let i = 0; i < priceChanges.length; i++) {
249
+ covariance += (priceChanges[i] - meanPrice) * (volumes[i] - meanVol);
250
+ varianceVol += Math.pow(volumes[i] - meanVol, 2);
251
+ }
252
+ covariance /= priceChanges.length;
253
+ varianceVol /= priceChanges.length;
254
+ if (varianceVol < 1e-4) return 0;
255
+ return Math.abs(covariance / varianceVol);
256
+ }
257
+ module2.exports = { computeKyleLambda };
258
+ }
259
+ });
260
+
261
+ // ultra-scalping/models/kalman.js
262
+ var require_kalman = __commonJS({
263
+ "ultra-scalping/models/kalman.js"(exports2, module2) {
264
+ var KALMAN_PROCESS_NOISE = 0.01;
265
+ var KALMAN_MEASUREMENT_NOISE = 0.1;
266
+ function applyKalmanFilter(state, measurement) {
267
+ if (!state || state.estimate === 0) {
268
+ return {
269
+ estimate: measurement,
270
+ errorCovariance: 1,
271
+ newEstimate: measurement
272
+ };
273
+ }
274
+ const predictedEstimate = state.estimate;
275
+ const predictedCovariance = state.errorCovariance + KALMAN_PROCESS_NOISE;
276
+ const kalmanGain = predictedCovariance / (predictedCovariance + KALMAN_MEASUREMENT_NOISE);
277
+ const newEstimate = predictedEstimate + kalmanGain * (measurement - predictedEstimate);
278
+ const newCovariance = (1 - kalmanGain) * predictedCovariance;
279
+ return {
280
+ estimate: newEstimate,
281
+ errorCovariance: newCovariance,
282
+ newEstimate
283
+ };
284
+ }
285
+ function createKalmanState() {
286
+ return {
287
+ estimate: 0,
288
+ errorCovariance: 1
289
+ };
290
+ }
291
+ module2.exports = {
292
+ applyKalmanFilter,
293
+ createKalmanState,
294
+ KALMAN_PROCESS_NOISE,
295
+ KALMAN_MEASUREMENT_NOISE
296
+ };
297
+ }
298
+ });
299
+
300
+ // ultra-scalping/models/volatility.js
301
+ var require_volatility = __commonJS({
302
+ "ultra-scalping/models/volatility.js"(exports2, module2) {
303
+ function calculateATR(bars, period = 14) {
304
+ if (bars.length < period + 1) return 2.5;
305
+ const trValues = [];
306
+ for (let i = bars.length - period; i < bars.length; i++) {
307
+ const bar = bars[i];
308
+ const prevClose = bars[i - 1].close;
309
+ const tr = Math.max(
310
+ bar.high - bar.low,
311
+ Math.abs(bar.high - prevClose),
312
+ Math.abs(bar.low - prevClose)
313
+ );
314
+ trValues.push(tr);
315
+ }
316
+ return trValues.reduce((a, b) => a + b, 0) / trValues.length;
317
+ }
318
+ function detectVolatilityRegime(atr, atrHistory, tickSize) {
319
+ let atrPercentile = 0.5;
320
+ if (atrHistory.length >= 20) {
321
+ atrPercentile = atrHistory.filter((a) => a <= atr).length / atrHistory.length;
322
+ }
323
+ let regime, params;
324
+ if (atrPercentile < 0.25) {
325
+ regime = "low";
326
+ params = {
327
+ stopMultiplier: 0.8,
328
+ targetMultiplier: 0.9,
329
+ zscoreThreshold: 1.2,
330
+ confidenceBonus: 0.05
331
+ };
332
+ } else if (atrPercentile < 0.75) {
333
+ regime = "normal";
334
+ params = {
335
+ stopMultiplier: 1,
336
+ targetMultiplier: 1,
337
+ zscoreThreshold: 1.5,
338
+ confidenceBonus: 0
339
+ };
340
+ } else {
341
+ regime = "high";
342
+ params = {
343
+ stopMultiplier: 1.3,
344
+ targetMultiplier: 1.2,
345
+ zscoreThreshold: 2,
346
+ confidenceBonus: -0.05
347
+ };
348
+ }
349
+ return { regime, params, atrPercentile };
350
+ }
351
+ module2.exports = { calculateATR, detectVolatilityRegime };
352
+ }
353
+ });
354
+
355
+ // ultra-scalping/models/ofi.js
356
+ var require_ofi = __commonJS({
357
+ "ultra-scalping/models/ofi.js"(exports2, module2) {
358
+ function computeOrderFlowImbalance(bars, lookback = 20) {
359
+ if (bars.length < lookback) return 0;
360
+ const recentBars = bars.slice(-lookback);
361
+ let totalBuyPressure = 0;
362
+ let totalSellPressure = 0;
363
+ for (const bar of recentBars) {
364
+ const barRange = bar.high - bar.low;
365
+ if (barRange > 0) {
366
+ const closePosition = (bar.close - bar.low) / barRange;
367
+ totalBuyPressure += closePosition * bar.volume;
368
+ totalSellPressure += (1 - closePosition) * bar.volume;
369
+ }
370
+ }
371
+ const totalPressure = totalBuyPressure + totalSellPressure;
372
+ if (totalPressure < 1) return 0;
373
+ return (totalBuyPressure - totalSellPressure) / totalPressure;
374
+ }
375
+ module2.exports = { computeOrderFlowImbalance };
376
+ }
377
+ });
378
+
379
+ // ultra-scalping/models/index.js
380
+ var require_models = __commonJS({
381
+ "ultra-scalping/models/index.js"(exports2, module2) {
382
+ var { computeZScore } = require_zscore();
383
+ var { computeVPIN } = require_vpin();
384
+ var { computeKyleLambda } = require_kyle();
385
+ var { applyKalmanFilter, createKalmanState } = require_kalman();
386
+ var { calculateATR, detectVolatilityRegime } = require_volatility();
387
+ var { computeOrderFlowImbalance } = require_ofi();
388
+ module2.exports = {
389
+ computeZScore,
390
+ computeVPIN,
391
+ computeKyleLambda,
392
+ applyKalmanFilter,
393
+ createKalmanState,
394
+ calculateATR,
395
+ detectVolatilityRegime,
396
+ computeOrderFlowImbalance
397
+ };
398
+ }
399
+ });
400
+
401
+ // ultra-scalping/core.js
402
+ var require_core = __commonJS({
403
+ "ultra-scalping/core.js"(exports2, module2) {
404
+ var EventEmitter2 = require("events");
405
+ var { DEFAULT_CONFIG } = require_config();
406
+ var { generateSignal } = require_signal();
407
+ var {
408
+ computeZScore,
409
+ computeVPIN,
410
+ computeKyleLambda,
411
+ applyKalmanFilter,
412
+ createKalmanState,
413
+ calculateATR,
414
+ detectVolatilityRegime,
415
+ computeOrderFlowImbalance
416
+ } = require_models();
417
+ var HQXUltraScalping2 = class extends EventEmitter2 {
418
+ constructor(config = {}) {
419
+ super();
420
+ this.tickSize = config.tickSize || 0.25;
421
+ this.tickValue = config.tickValue || 5;
422
+ this.config = { ...DEFAULT_CONFIG, ...config };
423
+ this.barHistory = /* @__PURE__ */ new Map();
424
+ this.priceBuffer = /* @__PURE__ */ new Map();
425
+ this.volumeBuffer = /* @__PURE__ */ new Map();
426
+ this.kalmanStates = /* @__PURE__ */ new Map();
427
+ this.atrHistory = /* @__PURE__ */ new Map();
428
+ this.recentTrades = [];
429
+ this.winStreak = 0;
430
+ this.lossStreak = 0;
431
+ this.lastSignalTime = 0;
432
+ this.stats = { signals: 0, trades: 0, wins: 0, losses: 0, pnl: 0 };
433
+ }
434
+ initialize(contractId, tickSize = 0.25, tickValue = 5) {
435
+ this.tickSize = tickSize;
436
+ this.tickValue = tickValue;
437
+ this.barHistory.set(contractId, []);
438
+ this.priceBuffer.set(contractId, []);
439
+ this.volumeBuffer.set(contractId, []);
440
+ this.atrHistory.set(contractId, []);
441
+ this.kalmanStates.set(contractId, createKalmanState());
442
+ this.emit("log", {
443
+ type: "info",
444
+ message: `[HQX-UltraScalping] Initialized for ${contractId}: tick=${tickSize}, value=${tickValue}`
445
+ });
446
+ this.emit("log", {
447
+ type: "info",
448
+ message: `[HQX-UltraScalping] 6 Models: Z-Score(30%), OFI(20%), VPIN(15%), Kalman(15%), Kyle(10%), Vol(10%)`
449
+ });
450
+ }
451
+ processTick(tick) {
452
+ const { contractId, price, volume, timestamp } = tick;
453
+ const bar = {
454
+ timestamp: timestamp || Date.now(),
455
+ open: price,
456
+ high: price,
457
+ low: price,
458
+ close: price,
459
+ volume: volume || 1
460
+ };
461
+ return this.processBar(contractId, bar);
462
+ }
463
+ onTick(tick) {
464
+ return this.processTick(tick);
465
+ }
466
+ onTrade(trade) {
467
+ return this.processTick({
468
+ contractId: trade.contractId || trade.symbol,
469
+ price: trade.price,
470
+ volume: trade.size || trade.volume || 1,
471
+ side: trade.side,
472
+ timestamp: trade.timestamp || Date.now()
473
+ });
474
+ }
475
+ processBar(contractId, bar) {
476
+ let bars = this.barHistory.get(contractId);
477
+ if (!bars) {
478
+ this.initialize(contractId);
479
+ bars = this.barHistory.get(contractId);
480
+ }
481
+ bars.push(bar);
482
+ if (bars.length > 500) bars.shift();
483
+ const prices = this.priceBuffer.get(contractId);
484
+ prices.push(bar.close);
485
+ if (prices.length > 200) prices.shift();
486
+ const volumes = this.volumeBuffer.get(contractId);
487
+ const barRange = bar.high - bar.low;
488
+ let buyVol = bar.volume * 0.5;
489
+ let sellVol = bar.volume * 0.5;
490
+ if (barRange > 0) {
491
+ const closePosition = (bar.close - bar.low) / barRange;
492
+ buyVol = bar.volume * closePosition;
493
+ sellVol = bar.volume * (1 - closePosition);
494
+ }
495
+ volumes.push({ buy: buyVol, sell: sellVol });
496
+ if (volumes.length > 100) volumes.shift();
497
+ if (bars.length < 50) return null;
498
+ const zscore = computeZScore(prices);
499
+ const vpin = computeVPIN(volumes, this.config.vpinWindow);
500
+ const kyleLambda = computeKyleLambda(bars);
501
+ const kalmanState = this.kalmanStates.get(contractId);
502
+ const kalmanResult = applyKalmanFilter(kalmanState, bar.close);
503
+ this.kalmanStates.set(contractId, {
504
+ estimate: kalmanResult.estimate,
505
+ errorCovariance: kalmanResult.errorCovariance
506
+ });
507
+ const kalmanEstimate = kalmanResult.newEstimate;
508
+ const atr = calculateATR(bars);
509
+ const atrHist = this.atrHistory.get(contractId);
510
+ atrHist.push(atr);
511
+ if (atrHist.length > 500) atrHist.shift();
512
+ const { regime, params: volParams } = detectVolatilityRegime(atr, atrHist, this.tickSize);
513
+ const ofi = computeOrderFlowImbalance(bars, this.config.ofiLookback);
514
+ if (Date.now() - this.lastSignalTime < this.config.cooldownMs) {
515
+ return null;
516
+ }
517
+ const signal = generateSignal({
518
+ contractId,
519
+ currentPrice: bar.close,
520
+ zscore,
521
+ vpin,
522
+ kyleLambda,
523
+ kalmanEstimate,
524
+ regime,
525
+ volParams,
526
+ ofi,
527
+ config: this.config,
528
+ tickSize: this.tickSize
529
+ });
530
+ if (signal) {
531
+ this.lastSignalTime = Date.now();
532
+ this.stats.signals++;
533
+ this.emit("signal", {
534
+ side: signal.direction === "long" ? "buy" : "sell",
535
+ action: "open",
536
+ reason: `Z=${zscore.toFixed(2)}, VPIN=${(vpin * 100).toFixed(0)}%, OFI=${(ofi * 100).toFixed(0)}%, cf=${(signal.confidence * 100).toFixed(0)}%`,
537
+ ...signal
538
+ });
539
+ this.emit("log", {
540
+ type: "info",
541
+ message: `[HQX] SIGNAL: ${signal.direction.toUpperCase()} @ ${bar.close.toFixed(2)} | Z:${zscore.toFixed(2)} VPIN:${(vpin * 100).toFixed(0)}% OFI:${(ofi * 100).toFixed(0)}% Kyle:${kyleLambda.toFixed(5)} Regime:${regime} | Conf:${(signal.confidence * 100).toFixed(0)}%`
542
+ });
543
+ }
544
+ return signal;
545
+ }
546
+ shouldExitByZScore(contractId) {
547
+ const prices = this.priceBuffer.get(contractId);
548
+ if (!prices || prices.length < 50) return false;
549
+ const zscore = computeZScore(prices);
550
+ return Math.abs(zscore) < this.config.zscoreExitThreshold;
551
+ }
552
+ getModelValues(contractId) {
553
+ const prices = this.priceBuffer.get(contractId);
554
+ const volumes = this.volumeBuffer.get(contractId);
555
+ const bars = this.barHistory.get(contractId);
556
+ if (!prices || !volumes || !bars || bars.length < 50) {
557
+ return null;
558
+ }
559
+ const zscore = computeZScore(prices);
560
+ const vpin = computeVPIN(volumes, this.config.vpinWindow);
561
+ const kyleLambda = computeKyleLambda(bars);
562
+ const ofi = computeOrderFlowImbalance(bars, this.config.ofiLookback);
563
+ return {
564
+ zscore: Math.min(1, Math.abs(zscore) / 4),
565
+ vpin: 1 - vpin,
566
+ kyleLambda: kyleLambda > 1e-3 ? 0.5 : 0.8,
567
+ kalman: 0.7,
568
+ volatility: 0.7,
569
+ ofi: Math.abs(ofi) > 0.1 ? 0.8 : 0.5,
570
+ composite: 0.7,
571
+ raw: { zscore, vpin, kyleLambda, ofi }
572
+ };
573
+ }
574
+ getAnalysisState(contractId, currentPrice) {
575
+ const bars = this.barHistory.get(contractId) || [];
576
+ if (bars.length < 50) {
577
+ return { ready: false, message: `Collecting data... ${bars.length}/50 bars` };
578
+ }
579
+ const prices = this.priceBuffer.get(contractId) || [];
580
+ const volumes = this.volumeBuffer.get(contractId) || [];
581
+ const atrHist = this.atrHistory.get(contractId) || [];
582
+ const zscore = computeZScore(prices);
583
+ const vpin = computeVPIN(volumes, this.config.vpinWindow);
584
+ const ofi = computeOrderFlowImbalance(bars, this.config.ofiLookback);
585
+ const kyleLambda = computeKyleLambda(bars);
586
+ const atr = calculateATR(bars);
587
+ const { regime, params } = detectVolatilityRegime(atr, atrHist, this.tickSize);
588
+ return {
589
+ ready: true,
590
+ zScore: zscore,
591
+ vpin,
592
+ ofi,
593
+ kyleLambda,
594
+ regime,
595
+ stopTicks: Math.round(this.config.baseStopTicks * params.stopMultiplier),
596
+ targetTicks: Math.round(this.config.baseTargetTicks * params.targetMultiplier),
597
+ threshold: params.zscoreThreshold,
598
+ barsProcessed: bars.length,
599
+ models: "6 (Z-Score, VPIN, Kyle, Kalman, Vol, OFI)"
600
+ };
601
+ }
602
+ recordTradeResult(pnl) {
603
+ this.recentTrades.push({ netPnl: pnl, timestamp: Date.now() });
604
+ if (this.recentTrades.length > 100) this.recentTrades.shift();
605
+ if (pnl > 0) {
606
+ this.winStreak++;
607
+ this.lossStreak = 0;
608
+ this.stats.wins++;
609
+ } else {
610
+ this.lossStreak++;
611
+ this.winStreak = 0;
612
+ this.stats.losses++;
613
+ }
614
+ this.stats.trades++;
615
+ this.stats.pnl += pnl;
616
+ this.emit("log", {
617
+ type: "debug",
618
+ message: `[HQX] Trade result: ${pnl > 0 ? "WIN" : "LOSS"} $${pnl.toFixed(2)}, streak: ${pnl > 0 ? this.winStreak : -this.lossStreak}`
619
+ });
620
+ }
621
+ getBarHistory(contractId) {
622
+ return this.barHistory.get(contractId) || [];
623
+ }
624
+ getStats() {
625
+ return this.stats;
626
+ }
627
+ reset(contractId) {
628
+ this.barHistory.set(contractId, []);
629
+ this.priceBuffer.set(contractId, []);
630
+ this.volumeBuffer.set(contractId, []);
631
+ this.atrHistory.set(contractId, []);
632
+ this.kalmanStates.set(contractId, createKalmanState());
633
+ this.emit("log", {
634
+ type: "info",
635
+ message: `[HQX-UltraScalping] Reset state for ${contractId}`
636
+ });
637
+ }
638
+ };
639
+ module2.exports = { HQXUltraScalping: HQXUltraScalping2 };
640
+ }
641
+ });
642
+
643
+ // ultra-scalping/index.js
644
+ var EventEmitter = require("events");
645
+ var { HQXUltraScalping } = require_core();
646
+ var { OrderSide, SignalStrength } = require_types();
647
+ var UltraScalpingStrategy = class extends EventEmitter {
648
+ constructor(config = {}) {
649
+ super();
650
+ this.config = config;
651
+ this.strategy = new HQXUltraScalping(config);
652
+ this.strategy.on("signal", (sig) => this.emit("signal", sig));
653
+ this.strategy.on("log", (log) => this.emit("log", log));
654
+ }
655
+ // Interface methods (compatible with M1)
656
+ processTick(tick) {
657
+ return this.strategy.processTick(tick);
658
+ }
659
+ onTick(tick) {
660
+ return this.strategy.onTick(tick);
661
+ }
662
+ onTrade(trade) {
663
+ return this.strategy.onTrade(trade);
664
+ }
665
+ processBar(contractId, bar) {
666
+ return this.strategy.processBar(contractId, bar);
667
+ }
668
+ initialize(contractId, tickSize, tickValue) {
669
+ return this.strategy.initialize(contractId, tickSize, tickValue);
670
+ }
671
+ getAnalysisState(contractId, price) {
672
+ return this.strategy.getAnalysisState(contractId, price);
673
+ }
674
+ recordTradeResult(pnl) {
675
+ return this.strategy.recordTradeResult(pnl);
676
+ }
677
+ reset(contractId) {
678
+ return this.strategy.reset(contractId);
679
+ }
680
+ getStats() {
681
+ return this.strategy.getStats();
682
+ }
683
+ getBarHistory(contractId) {
684
+ return this.strategy.getBarHistory(contractId);
685
+ }
686
+ getModelValues(contractId) {
687
+ return this.strategy.getModelValues(contractId);
688
+ }
689
+ shouldExitByZScore(contractId) {
690
+ return this.strategy.shouldExitByZScore(contractId);
691
+ }
692
+ generateSignal(params) {
693
+ return null;
694
+ }
695
+ // Signals come from processBar
696
+ };
697
+ module.exports = {
698
+ HQXUltraScalping,
699
+ UltraScalpingStrategy,
700
+ // Aliases for backward compatibility
701
+ M1: UltraScalpingStrategy,
702
+ S1: HQXUltraScalping,
703
+ OrderSide,
704
+ SignalStrength
705
+ };