Skip to content

Commit

Permalink
feat: add experimental expiryTimestamp support in l3 data
Browse files Browse the repository at this point in the history
  • Loading branch information
thaaddeus committed May 2, 2022
1 parent 821077f commit a000470
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
27 changes: 19 additions & 8 deletions src/data_mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
PerpEventLayout,
PerpEventQueueHeaderLayout,
PerpMarket,
PerpOrder
PerpOrder,
U64_MAX_BN,
ZERO_BN
} from '@blockworks-foundation/mango-client'
import BN from 'bn.js'
import { CircularBuffer } from './helpers'
Expand Down Expand Up @@ -146,7 +148,8 @@ export class DataMapper {
size: fillOrderWithoutOpenOrder.size,
account: fillOrderWithoutOpenOrder.account,
accountSlot: fillOrderWithoutOpenOrder.accountSlot,
eventTimestamp: fillOrderWithoutOpenOrder.eventTimestamp
eventTimestamp: fillOrderWithoutOpenOrder.eventTimestamp,
expiryTimestamp: undefined
}

l3Diff.push(openMessage)
Expand Down Expand Up @@ -626,7 +629,8 @@ export class DataMapper {
size: item.size,
account: item.account,
accountSlot: item.accountSlot,
eventTimestamp: item.eventTimestamp
eventTimestamp: item.eventTimestamp,
expiryTimestamp: item.expiryTimestamp
})
}

Expand Down Expand Up @@ -902,7 +906,7 @@ export class DataMapper {
}

private _mapToOrderMessage(
{ orderId, clientId, side, price, account, accountSlot, eventTimestamp }: OrderItem,
{ orderId, clientId, side, price, account, accountSlot, eventTimestamp, expiryTimestamp }: OrderItem,
type: 'open' | 'change',
size: string,
timestamp: string,
Expand All @@ -922,7 +926,8 @@ export class DataMapper {
size,
account,
accountSlot,
eventTimestamp
eventTimestamp,
expiryTimestamp
}
} else {
return {
Expand All @@ -937,7 +942,8 @@ export class DataMapper {
price,
size,
account,
accountSlot
accountSlot,
expiryTimestamp
}
}
}
Expand All @@ -950,7 +956,8 @@ export class DataMapper {
size,
owner,
openOrdersSlot,
timestamp
timestamp,
expiryTimestamp
}: PerpOrder) => {
const orderItem: OrderItem = {
orderId: orderId.toString(),
Expand All @@ -960,7 +967,11 @@ export class DataMapper {
size: size.toFixed(this._options.sizeDecimalPlaces),
account: owner.toBase58(),
accountSlot: openOrdersSlot,
eventTimestamp: new Date(timestamp.toNumber() * 1000).toISOString()
eventTimestamp: new Date(timestamp.toNumber() * 1000).toISOString(),
expiryTimestamp:
expiryTimestamp.eq(ZERO_BN) || expiryTimestamp.eq(U64_MAX_BN)
? undefined
: new Date(expiryTimestamp.toNumber() * 1000).toISOString()
}

return orderItem
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export interface Trade extends DataMessage, WithEventTimestamp {
readonly makerFeeCost: number
}

export interface Fill extends DataMessage, OrderItem {
export interface Fill extends DataMessage, Omit<OrderItem, 'expiryTimestamp'> {
readonly type: 'fill'
readonly maker: boolean
readonly feeCost: number
Expand All @@ -82,6 +82,7 @@ export type OrderItem = {
readonly clientId: string
readonly account: string
readonly accountSlot: number
readonly expiryTimestamp: string | undefined
} & WithEventTimestamp

export interface Open extends DataMessage, OrderItem {
Expand Down

0 comments on commit a000470

Please sign in to comment.