@ -93,9 +93,10 @@ function makeCalendarDatabase(): CalendarDatabase {
getClosingPrice : async ( {
getClosingPrice : async ( {
key : { symbol , strike , type , frontExpirationDate , backExpirationDate } ,
key : { symbol , strike , type , frontExpirationDate , backExpirationDate } ,
} ) = > {
} ) = > {
// get unix timestamp, in milliseconds, of the start of the last hour, which is 03:30PM in the `America/New_York` timezone on the front expiration date:
const startOfLastHourUnix = new Date (
const startOfLastHourUnix = new Date (
` ${ frontExpirationDate } T 00:00:00Z` ,
` ${ frontExpirationDate } T 19:30:00Z`
) . valueOf ( ) ;
) . getTime ( ) ;
const endOfLastHourUnix = startOfLastHourUnix + 3600 * 1000 ;
const endOfLastHourUnix = startOfLastHourUnix + 3600 * 1000 ;
const frontOptionContractAggregates = (
const frontOptionContractAggregates = (
await optionContractDatabase . getAggregates ( {
await optionContractDatabase . getAggregates ( {
@ -104,7 +105,7 @@ function makeCalendarDatabase(): CalendarDatabase {
} )
} )
) . filter (
) . filter (
( { tsStart } ) = >
( { tsStart } ) = >
tsStart >= startOfLastHourUnix && tsStart < endOfLastHourUnix ,
tsStart >= startOfLastHourUnix && tsStart < endOfLastHourUnix
) ;
) ;
const backOptionContractAggregates = (
const backOptionContractAggregates = (
await optionContractDatabase . getAggregates ( {
await optionContractDatabase . getAggregates ( {
@ -113,7 +114,7 @@ function makeCalendarDatabase(): CalendarDatabase {
} )
} )
) . filter (
) . filter (
( { tsStart } ) = >
( { tsStart } ) = >
tsStart >= startOfLastHourUnix && tsStart < endOfLastHourUnix ,
tsStart >= startOfLastHourUnix && tsStart < endOfLastHourUnix
) ;
) ;
let i = 0 ;
let i = 0 ;
let j = 0 ;
let j = 0 ;
@ -128,7 +129,7 @@ function makeCalendarDatabase(): CalendarDatabase {
) {
) {
const calendarClosePrice =
const calendarClosePrice =
backOptionContractAggregates [ j ] . close -
backOptionContractAggregates [ j ] . close -
frontOptionContractAggregates [ j ] . close ;
frontOptionContractAggregates [ i ] . close ;
if ( calendarClosePrice < minPrice || minPrice === 0 ) {
if ( calendarClosePrice < minPrice || minPrice === 0 ) {
minPrice = calendarClosePrice ;
minPrice = calendarClosePrice ;
}
}