Skip to content
This repository has been archived by the owner on Feb 9, 2022. It is now read-only.

Commit

Permalink
Remove daylight savings from Nasdaq Provider (#137)
Browse files Browse the repository at this point in the history
* Remove daylight savings

* Update index.ts
  • Loading branch information
monstrobishi authored Aug 13, 2021
1 parent 222ebeb commit 8a48d5f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ describe('multi price fetch', () => {
const prices = await priceManager.fetchAssetPrices()
expect(prices[0].asset).toStrictEqual('TSLA')
expect(prices[0].price).toStrictEqual(new BigNumber(714.63))
expect(prices[0].timestamp).toStrictEqual(new BigNumber(1628193602430))
expect(prices[0].timestamp).toStrictEqual(new BigNumber(1628197202430))
expect(prices[1].asset).toStrictEqual('AAPL')
expect(prices[1].price).toStrictEqual(new BigNumber(147.06))
expect(prices[1].timestamp).toStrictEqual(new BigNumber(1628193602286))
expect(prices[1].timestamp).toStrictEqual(new BigNumber(1628197202286))
expect(prices[2].asset).toStrictEqual('FB')
expect(prices[2].price).toStrictEqual(new BigNumber(362.97))
expect(prices[2].timestamp).toStrictEqual(new BigNumber(1628193603279))
expect(prices[2].timestamp).toStrictEqual(new BigNumber(1628197203279))
})
})
18 changes: 3 additions & 15 deletions packages/salmon-provider-nasdaq/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,10 @@ export class NasdaqPriceProvider implements PriceProvider {
) {
}

// This is slightly complex due to the fact that Eastern Time
// undergoes daylight saving
// This converts from EST (Eastern Standard Time) to UTC
processTimestamp (timestamp: string): number {
const priceDate = new Date(timestamp + 'Z')
const dateNow = new Date()
const paddMs = String(dateNow.getUTCMilliseconds()).padStart(3, '0')

// en-CA instead of en-US is needed here ('-' vs '/')
const dateNowEt = new Date(dateNow.toLocaleString('en-CA',
{
timeZone: 'America/New_York',
hour12: false
}).replace(', ', 'T') + `.${paddMs}Z`)

const timezoneOffset = dateNow.getTime() - dateNowEt.getTime()
return priceDate.getTime() + timezoneOffset
const timezoneOffset = 5 * 60 * 60 * 1000 // 5 hours
return new Date(timestamp + 'Z').getTime() + timezoneOffset
}

private async fetchAsset (symbol: string, authToken: string): Promise<AssetPrice> {
Expand Down

0 comments on commit 8a48d5f

Please sign in to comment.