@equitysim/trkd-client
Advanced tools
Comparing version 0.1.8 to 0.1.9
{ | ||
"name": "@equitysim/trkd-client", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "REST Client for TRKD API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,5 +23,5 @@ import searchFields from './field-maps/search-fields' | ||
const formatSearchItems = (responseName, trkdResponse) => { | ||
const formatSearchItems = (trkdBody) => { | ||
const result = [] | ||
const items = trkdResponse[responseName]['Result']['Hit'] | ||
const items = trkdBody['Result']['Hit'] | ||
for (const item of items) { | ||
@@ -33,8 +33,36 @@ result.push(formatSearchItem(item)) | ||
export const formatSearchAllResponse = (trkdResponse) => formatSearchItems('GetSearchall_Response_1', trkdResponse) | ||
export const formatSearchAllResponse = (trkdResponse, header) => ({ | ||
docs: formatSearchItems(trkdResponse['GetSearchall_Response_1']), | ||
...formatSearchHeader(trkdResponse['GetSearchall_Response_1'], header), | ||
}) | ||
export const formatSearchEquityQuoteResponse = (trkdResponse) => formatSearchItems('GetEquityQuote_Response_1', trkdResponse) | ||
export const formatSearchDerivativeQuote = (trkdResponse, header) => ({ | ||
docs: formatSearchItems(trkdResponse['GetDerivativeQuote_Response_1']), | ||
...formatSearchHeader(trkdResponse['GetDerivativeQuote_Response_1'], header) | ||
}) | ||
export const formatSearchFundQuoteResponse = (trkdResponse) => formatSearchItems('GetFundQuote_Response_1', trkdResponse) | ||
export const formatSearchEquityQuoteResponse = (trkdResponse, header) => ({ | ||
docs: formatSearchItems(trkdResponse['GetEquityQuote_Response_1']), | ||
... formatSearchHeader(trkdResponse['GetEquityQuote_Response_1'], header) | ||
}) | ||
export const formatSearchBondInstrumentsResponse = (trkdResponse) => formatSearchItems('GetGovCorpInst_Response_1', trkdResponse) | ||
export const formatSearchFundQuoteResponse = (trkdResponse, header) => ({ | ||
docs: formatSearchItems(trkdResponse['GetFundQuote_Response_1']), | ||
...formatSearchHeader(trkdResponse['GetEquityQuote_Response_1'], header) | ||
}) | ||
export const formatSearchBondInstrumentsResponse = (trkdResponse, header) => ({ | ||
docs: formatSearchItems(trkdResponse['GetGovCorpInst_Response_1']), | ||
...formatSearchHeader(trkdResponse['GetGovCorpInst_Response_1'], header) | ||
}) | ||
export const formatSearchHeader = (trkdBody, header) => { | ||
const limit = header['MaxCount'] | ||
const responseHeader = trkdBody['ResultHeader'] | ||
return { | ||
page: Math.floor(responseHeader['FirstHit'] / limit) + 1, | ||
pages: Math.ceil(responseHeader['TotalHits'] / limit), | ||
limit, | ||
total: responseHeader['TotalHits'], | ||
} | ||
} |
@@ -5,3 +5,4 @@ import timeseriesFields from './field-maps/timeseries-fields' | ||
const result = [] | ||
for (const values of trkdResponse['R']) { | ||
let previousClose = 0; | ||
for (const values of trkdResponse['R'] || []) { | ||
const fields = {} | ||
@@ -18,2 +19,5 @@ for (const [key, value] of Object.entries(values)) { | ||
} | ||
fields.netChange = fields.close - previousClose | ||
fields.percentChange = fields.close / previousClose - 1 | ||
previousClose = fields.close | ||
result.push(fields) | ||
@@ -49,3 +53,5 @@ } | ||
let strHours = hours.toString() | ||
if (hours > 0) { | ||
if (hours === 0) { | ||
strHours = '+' + strHours | ||
} else if (hours > 0) { | ||
if (strHours.length === 1) strHours = '0' + strHours | ||
@@ -65,3 +71,3 @@ strHours = '+' + strHours | ||
return data.map(zone => { | ||
const isSummer = zone['HasSummerTime'] && zone['SummerStart'] < today && zone['SummerEnd'] > today | ||
const isSummer = zone['HasSummerTime'] && new Date(zone['SummerStart']) < today && new Date(zone['SummerEnd']) > today | ||
const offset = formatOffset(isSummer ? zone['SummerOffset'] : zone['GMTOffset']) | ||
@@ -68,0 +74,0 @@ return { |
@@ -9,2 +9,4 @@ import { fileURLToPath } from 'url' | ||
formatSearchBondInstrumentsResponse, | ||
formatSearchDerivativeQuote, | ||
formatSearchHeader, | ||
} from '../formatting' | ||
@@ -37,3 +39,3 @@ | ||
if (!this.format) return res | ||
return formatSearchAllResponse(res) | ||
return formatSearchAllResponse(res, header) | ||
}, | ||
@@ -46,3 +48,3 @@ /** | ||
*/ | ||
async derivativeQuote(queries = Query.optionQuote, filters = {}, header = Query.header) { | ||
async derivativeQuote(queries = Query.derivativeQuote, filters = {}, header = Query.header) { | ||
const path = '/api/Search/Search.svc/REST/DerivativeQuote_1/GetDerivativeQuote_1' | ||
@@ -62,3 +64,5 @@ | ||
const res = await this._request(filename, methods.derivativeQuote, path, payload) | ||
return res | ||
if (!this.format) return res; | ||
return formatSearchDerivativeQuote(res, header) | ||
}, | ||
@@ -86,3 +90,3 @@ /** | ||
if (!this.format) return res | ||
return formatSearchEquityQuoteResponse(res) | ||
return formatSearchEquityQuoteResponse(res, header) | ||
}, | ||
@@ -111,3 +115,3 @@ /** | ||
if (!this.format) return res | ||
return formatSearchFundQuoteResponse(res) | ||
return formatSearchFundQuoteResponse(res, header) | ||
}, | ||
@@ -135,3 +139,3 @@ /** | ||
if (!this.format) return res | ||
return formatSearchBondInstrumentsResponse(res) | ||
return formatSearchBondInstrumentsResponse(res, header) | ||
}, | ||
@@ -138,0 +142,0 @@ } |
import { ValidationError } from '../dto/errors' | ||
import { formatTimeSeriesResponse, formatExchangeDataResponse, formatTimezoneResponse } from '../formatting' | ||
import { INTERDAY_INTERVAL } from '../utils/config' | ||
import { INTERDAY_INTERVAL, INTRADAY_INTERVAL } from '../utils/config' | ||
import { fileURLToPath } from 'url' | ||
@@ -25,3 +25,3 @@ import path from 'path' | ||
if (!(startTime instanceof Date) || startTime > new Date()) throw new ValidationError('startTime must be less than now', startTime) | ||
if (!(endTime instanceof Date) || endTime > new Date()) throw new ValidationError('endTime must be less than now', startTime) | ||
if (!(endTime instanceof Date) || endTime > new Date()) throw new ValidationError('endTime must be less than now', endTime) | ||
if (!intervals.includes(interval)) throw new ValidationError(`interval must be one of the following: ${intervals.toString()}`, interval) | ||
@@ -31,3 +31,3 @@ | ||
const payload = { | ||
GetIntradayTimeSeries_Request_4: { | ||
GetIntradayTimeSeries_Request_5: { | ||
Field: ['OPEN', 'HIGH', 'LOW', 'CLOSE', 'CLOSEYIELD', 'VOLUME', 'BID', 'ASK'], | ||
@@ -60,3 +60,3 @@ MetaField: ['NAME', 'QOS', 'CCY', 'NAME_LL'], | ||
if (!(startTime instanceof Date) || startTime > new Date()) throw new ValidationError('startTime must be less than now', startTime) | ||
if (!(endTime instanceof Date) || endTime > new Date()) throw new ValidationError('endTime must be less than now', startTime) | ||
if (!(endTime instanceof Date) || endTime > new Date()) throw new ValidationError('endTime must be less than now', endTime) | ||
if (!intervals.includes(interval)) throw new ValidationError(`interval must be one of the following: ${intervals.toString()}`, interval) | ||
@@ -63,0 +63,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41741
1275