UNPKG

@activfinancial/cg-api-json

Version:

Implementations of some cg-api interfaces using JSON data.

3 lines (2 loc) 12 kB
import{isAsioErrorCode as e,AsioError as s,StatusCodeError as t,Date as n,FieldType as a,DateTime as o,Time as i,Rational as r,TRational as l}from"@activfinancial/middleware";import{IterableResponse as d,makeNotFoundField as c}from"@activfinancial/cg-api-common";var u;function p(e){return"toJSON"in e?e.toJSON():e}function h(n){return e(n)?new s(n):"statusCode"in n?new t(n.statusCode):n}!function(e){e[e.connect=0]="connect",e[e.disconnect=1]="disconnect",e[e.onBreak=2]="onBreak",e[e.onError=3]="onError",e[e.onServerMessage=4]="onServerMessage",e[e.onAliasUpdate=5]="onAliasUpdate",e[e.onFeedConflationUpdate=6]="onFeedConflationUpdate",e[e.onHeartbeat=7]="onHeartbeat",e[e.setSessionConflationParameters=8]="setSessionConflationParameters",e[e.onStreamingImage=9]="onStreamingImage",e[e.onStreamingUpdate=10]="onStreamingUpdate",e[e.onNewsStory=11]="onNewsStory",e[e.onNewsUpdate=12]="onNewsUpdate",e[e.onTimeSeriesResponse=13]="onTimeSeriesResponse",e[e.onContentGatewayInfo=14]="onContentGatewayInfo",e[e.onSymbolDirectoryResponse=15]="onSymbolDirectoryResponse",e[e.delete=16]="delete",e[e.isComplete=17]="isComplete",e[e.setRequestConflationParameters=18]="setRequestConflationParameters",e[e.onDynamicConflationUpdate=19]="onDynamicConflationUpdate"}(u||(u={}));var m=Object.freeze({__proto__:null,ContentGatewayInfoRequestHandle:class extends d{isEmptyResponse(e){return!1}isRecordAvailable(){return 0===this.recordIndex}makeNextIteratorResult(){return++this.recordIndex,{done:!1,value:this.currentResponse}}processJsonResponse(e){switch(e.messageType){case u.onContentGatewayInfo:this.processResponse(e.message);break;case u.onError:this.isComplete=!0,this.processError(h(e.message));break;default:console.warn(`Unknown json response ${JSON.stringify(e)}`)}}},contentGatewayInfoToJSON:function(e){const s=e.systemInfo;return Object.assign(Object.assign({},e),{systemInfo:Object.assign(Object.assign({},s),{processorInfoList:[...s.processorInfoList]}),permissionLevelList:[...e.permissionLevelList],conflationTypeList:[...e.conflationTypeList],conflationIntervalList:[...e.conflationIntervalList],isDynamicConflationAvailable:e.isDynamicConflationAvailable,feedConflationInfoList:[...e.feedConflationInfoList]})},exchangeInfoFromJSON:function(e){return e.holidayDates=e.holidayDates.map(e=>new n(e)),e}});class f{constructor(e){switch(this.id=e.id,this.statusCode=e.statusCode,this.doesUpdateLastValue=e.doesUpdateLastValue,this.type=e.type,e.type){case a.tRational:this.value=l.fromJSON(e.value);break;case a.rational:this.value=r.fromJSON(e.value);break;case a.time:this.value=i.fromJSON(e.value);break;case a.dateTime:this.value=o.fromJSON(e.value);break;case a.date:this.value=n.fromJSON(e.value);break;case a.binaryArray:case a.binaryString:case a.blob:case a.crcBlob:this.value=Uint8Array.from(e.value);break;default:this.value=e.value}}}class y{constructor(e){this[Symbol.iterator]=()=>this.fields.values(),this.fields=new Map;for(let s of e){const e=new f(s);this.fields.set(e.id,e)}}get(e){const s=this.fields.get(e);return null!=s?s:c(e)}}function g(e){let s;switch(e.type){case a.rational:case a.tRational:case a.time:case a.dateTime:case a.date:s=e.value.toJSON();break;case a.binaryArray:case a.binaryString:case a.blob:case a.crcBlob:s=[...e.value];break;default:s=e.value}return{id:e.id,statusCode:e.statusCode,doesUpdateLastValue:e.doesUpdateLastValue,type:e.type,value:s}}function b(e){let s=[];for(const t of e)s.push(g(t));return s}class S{constructor(e){this.newsSymbol=e.newsSymbol,this.permissionIdList=e.permissionIdList,this.fieldData=new y(e.fieldData)}getField(e){return this.fieldData.get(e)}}class I extends S{constructor(e){super(e),this.updateId=e.updateId,this.isNewRecord=e.isNewRecord,this.isDelete=e.isDelete}isDeleted(){return!1}delete(){}}function O(e){return{newsSymbol:e.newsSymbol,permissionIdList:[...e.permissionIdList],fieldData:b(e.fieldData)}}var C=Object.freeze({__proto__:null,storyToJSON:O,updateToJSON:function(e){return Object.assign(Object.assign({},O(e)),{updateId:e.updateId,isNewRecord:e.isNewRecord,isDelete:e.isDelete})},RequestHandle:class extends d{constructor(e){super(null!=e.updateHandler),this.isSubscription&&(this.updateHandler=e.updateHandler),this.requestParameters=function(e){const s=Object.assign({},e);return null!=e.updateHandler&&(s.updateHandler=!0),s}(e)}isEmptyResponse(e){return"isComplete"in e}isRecordAvailable(){return 0===this.recordIndex}makeNextIteratorResult(){return++this.recordIndex,{done:!1,value:this.currentResponse}}processJsonResponse(e){switch(e.messageType){case u.onNewsUpdate:this.processUpdate(e.message);break;case u.onNewsStory:this.processStory(e.message);break;case u.isComplete:this.isComplete=!0,this.processResponse({isComplete:!0});break;case u.onError:this.isComplete=!0,this.processError(h(e.message));break;default:console.warn(`Unknown json response ${JSON.stringify(e)}`)}}processStory(e){this.processResponse(new S(e))}processUpdate(e){null!=this.updateHandler&&this.updateHandler(new I(e))}}});class R{constructor(e){this.isNewRecord=e.isNewRecord,this.isDelete=e.isDelete,this.isAliasKey=e.isAliasKey,this.isStale=e.isStale,this.streamId=e.streamId,this.permissionId=e.permissionId,this.permissionLevel=e.permissionLevel,this.delayPeriod=e.delayPeriod,this.relationshipId=e.relationshipId,this.requestedKey=e.requestedKey,this.resolvedKey=e.resolvedKey,this.responseKey=e.responseKey,this.fieldData=new y(e.fieldData)}getField(e){return this.fieldData.get(e)}}class w extends R{constructor(e){super(e),this.statusCode=e.statusCode}}class v extends R{constructor(e){super(e),this.eventType=e.eventType,this.isConflated=e.isConflated,this.isDeferred=e.isDeferred,this.updateId=e.updateId}isDeleted(){return!1}delete(){}}function N(e){return{isNewRecord:e.isNewRecord,isDelete:e.isDelete,isAliasKey:e.isAliasKey,isStale:e.isStale,streamId:e.streamId,permissionId:e.permissionId,permissionLevel:e.permissionLevel,delayPeriod:e.delayPeriod,relationshipId:e.relationshipId,requestedKey:e.requestedKey,resolvedKey:e.resolvedKey,responseKey:e.responseKey,fieldData:b(e.fieldData)}}var T=Object.freeze({__proto__:null,imageToJSON:function(e){return Object.assign(Object.assign({},N(e)),{statusCode:e.statusCode})},updateToJSON:function(e){return Object.assign(Object.assign({},N(e)),{eventType:e.eventType,isConflated:e.isConflated,isDeferred:e.isDeferred,updateId:e.updateId})},RequestHandle:class extends d{constructor(e){super(null!=e.subscription),this.streamUpdateHandlers={},this.shouldEnableDynamicConflation=!1,null!=e.subscription&&(this.updateHandler=e.subscription.updateHandler,delete e.subscription.updateHandler,null!=e.subscription.conflation&&null!=e.subscription.conflation.dynamicConflationHandler&&(this.dynamicConflationHandler=e.subscription.conflation.dynamicConflationHandler,delete e.subscription.conflation.dynamicConflationHandler,this.shouldEnableDynamicConflation=!0))}setUpdateHandler(e,s){return null!=this.streamUpdateHandlers[e]&&(this.streamUpdateHandlers[e]=s,!0)}isEmptyResponse(e){return"isComplete"in e}isRecordAvailable(){return 0===this.recordIndex}makeNextIteratorResult(){return++this.recordIndex,{done:!1,value:this.currentResponse}}processJsonResponse(e){switch(e.messageType){case u.onStreamingUpdate:this.processUpdate(e.message);break;case u.onStreamingImage:this.processImage(e.message);break;case u.isComplete:this.isComplete=!0,this.processResponse({isComplete:!0});break;case u.onDynamicConflationUpdate:this.processDynamicConflationUpdate(e.message);break;case u.onError:this.isComplete=!0,this.processError(h(e.message));break;default:console.warn(`Unknown json response ${JSON.stringify(e)}`)}}processImage(e){null!=this.updateHandler&&(this.streamUpdateHandlers[e.streamId]=this.updateHandler),this.processResponse(new w(e))}processUpdate(e){(this.streamUpdateHandlers[e.streamId]||this.updateHandler)(new v(e))}processDynamicConflationUpdate(e){null!=this.dynamicConflationHandler&&this.dynamicConflationHandler(e)}}});var k=Object.freeze({__proto__:null,symbolResponseToJSON:function(e){return{symbolId:e.symbolId,matchData:e.matchData,entityType:e.entityType}},RequestHandle:class extends d{constructor(){super(!1)}isEmptyResponse(e){return"isComplete"in e}isRecordAvailable(){return 0===this.recordIndex}makeNextIteratorResult(){return++this.recordIndex,{done:!1,value:this.currentResponse}}processJsonResponse(e){switch(e.messageType){case u.onSymbolDirectoryResponse:this.processResponse(e.message);break;case u.isComplete:this.isComplete=!0,this.processResponse({isComplete:!0});break;case u.onError:this.isComplete=!0,this.processError(h(e.message));break;default:console.warn(`Unknown json response ${JSON.stringify(e)}`)}}}});class D{constructor(e){this.symbolId=e.symbolId,this.dateTime=new Date(e.dateTime)}}class J extends D{constructor(e){super(e),this.open=null!=e.open?r.fromJSON(e.open):null,this.high=null!=e.high?r.fromJSON(e.high):null,this.low=null!=e.low?r.fromJSON(e.low):null,this.close=null!=e.close?r.fromJSON(e.close):null,this.totalVolume=e.totalVolume,this.totalPrice=null!=e.totalPrice?r.fromJSON(e.totalPrice):null,this.totalValue=null!=e.totalValue?r.fromJSON(e.totalValue):null,this.tickCount=e.tickCount}}function x(e){return{symbolId:e.symbolId,dateTime:e.dateTime}}function H(e){return Object.assign(Object.assign({},x(e)),{open:null!=e.open?e.open.toJSON():null,high:null!=e.high?e.high.toJSON():null,low:null!=e.low?e.low.toJSON():null,close:null!=e.close?e.close.toJSON():null,totalVolume:e.totalVolume,totalPrice:null!=e.totalPrice?e.totalPrice.toJSON():null,totalValue:null!=e.totalValue?e.totalValue.toJSON():null,tickCount:e.tickCount})}var U=Object.freeze({__proto__:null,HistoryBar:class extends J{constructor(e){super(e),this.openInterest=e.openInterest}},IntradayBar:class extends J{constructor(e){super(e),this.altTotalVolume=e.altTotalVolume,this.hasRegularTrade=e.hasRegularTrade,this.hasOhlc=e.hasOhlc}},Tick:class extends D{constructor(e){super(e),this.isLuld=e.isLuld,this.luldHighPrice=e.luldHighPrice,this.luldLowPrice=e.luldLowPrice,this.isTradingStatus=e.isTradingStatus,this.tradingStatus=e.tradingStatus,this.tradingStatusReason=e.tradingStatusReason,this.tickType=e.tickType,this.updateId=e.updateId,this.price=e.price,this.size=e.size,this.conditions=e.conditions,this.exchange=e.exchange,this.buyerId=e.buyerId,this.sellerId=e.sellerId,this.tradeThroughExemptFlag=e.tradeThroughExemptFlag,this.isOutOfSequence=e.isOutOfSequence}},historyBarToJSON:function(e){return Object.assign(Object.assign({},H(e)),{openInterest:e.openInterest})},intradayBarToJSON:function(e){return Object.assign(Object.assign({},H(e)),{altTotalVolume:e.altTotalVolume,hasRegularTrade:e.hasRegularTrade,hasOhlc:e.hasOhlc})},tickToJSON:function(e){return Object.assign(Object.assign({},x(e)),{tickType:e.tickType,updateId:e.updateId,price:null!=e.price?e.price.toJSON():null,size:e.size,conditions:e.conditions,exchange:e.exchange,buyerId:e.buyerId,sellerId:e.sellerId,tradeThroughExemptFlag:e.tradeThroughExemptFlag,isOutOfSequence:e.isOutOfSequence,isLuld:e.isLuld,luldHighPrice:e.luldHighPrice,luldLowPrice:e.luldLowPrice,isTradingStatus:e.isTradingStatus,tradingStatus:e.tradingStatus,tradingStatusReason:e.tradingStatusReason})},RequestHandle:class extends d{constructor(e){super(!1),this.fieldSetConstructor=e}isEmptyResponse(e){return"isComplete"in e}isRecordAvailable(){return 0===this.recordIndex}makeNextIteratorResult(){return++this.recordIndex,{done:!1,value:this.currentResponse}}processJsonResponse(e){switch(e.messageType){case u.onTimeSeriesResponse:this.processResponse(new this.fieldSetConstructor(e.message));break;case u.isComplete:this.isComplete=!0,this.processResponse({isComplete:!0});break;case u.onError:this.isComplete=!0,this.processError(h(e.message));break;default:console.warn(`Unknown json response ${JSON.stringify(e)}`)}}}});export{u as JsonMessageType,m as MetaData,C as News,T as Streaming,k as SymbolDirectory,U as TimeSeries,h as maybeErrorFromJSON,p as maybeToJSON}; //# sourceMappingURL=index.esm.js.map