Skip to content

Commit

Permalink
fix(server): undefined market status preventing update
Browse files Browse the repository at this point in the history
  • Loading branch information
fcote committed Feb 27, 2023
1 parent 45842a3 commit 3dbd5a1
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions server/src/links/seekingAlpha/link.seekingAlpha.quote.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isNull } from 'lodash'

import {
SeekingAlphaQuote,
SeekingAlphaLink,
Expand All @@ -6,12 +8,16 @@ import { SecurityQuoteResult } from '@links/types'
import { logger } from '@logger'
import { SecurityMarketStatus } from '@models/security'

const getMarketStatus = (quote: SeekingAlphaQuote): SecurityMarketStatus => {
const getMarketStatus = (
quote: SeekingAlphaQuote
): SecurityMarketStatus | null => {
switch (quote.ext_market) {
case 'pre':
return SecurityMarketStatus.preMarket
case 'post':
return SecurityMarketStatus.afterHours
default:
return null
}
}

Expand All @@ -22,15 +28,12 @@ const toSecurityQuoteResult = (
const quoteChangePercent = (quote.ext_price / quote.last - 1) * 100
const marketStatus = getMarketStatus(quote)

const base: Partial<SecurityQuoteResult> = [
SecurityMarketStatus.afterHours,
SecurityMarketStatus.preMarket,
].includes(marketStatus)
? {
const base: Partial<SecurityQuoteResult> = isNull(marketStatus)
? { extendedHoursPrice: null, extendedHoursChangePercentage: null }
: {
extendedHoursPrice: quotePrice,
extendedHoursChangePercentage: quoteChangePercent,
}
: { extendedHoursPrice: null, extendedHoursChangePercentage: null }

return {
symbol: quote.symbol,
Expand Down

0 comments on commit 3dbd5a1

Please sign in to comment.