Skip to Content
DevelopersMarket MakersSwift Order Feed

Swift Order Feed

Swift MM: receive signed taker orders off-chain over this websocket feed (before the order hits the JIT auction), then place-and-make on-chain. Makers can inspect the order (direction/size/auction params) and decide how to fill it.

Subscribe to Swift orders

import { SwiftOrderSubscriber } from "@drift-labs/sdk";
Class SwiftOrderSubscriberReference ↗
NameTypeDefault
configany
heartbeatTimeoutany
heartbeatIntervalMsany
wsany
driftClientany
userAccountGetterAccountGetter
onOrder(orderMessageRaw: SwiftOrderMessage, signedMessage: SignedMsgOrderParamsMessage | SignedMsgOrderParamsDelegateMessage, isDelegateSigner?: boolean | undefined) => Promise<...>
subscribedboolean
unsubscribe() => void
getSymbolForMarketIndex(marketIndex: number) => string
generateChallengeResponse(nonce: string) => string
handleAuthMessage(message: any) => void
subscribe(onOrder: (orderMessageRaw: SwiftOrderMessage, signedMessage: SignedMsgOrderParamsMessage | SignedMsgOrderParamsDelegateMessage, isDelegateSigner?: boolean | undefined) => Promise<...>, acceptSanitized?: boolean | undefined, acceptDepositTrade?: boolean | undefined) => Promise<...>
getPlaceAndMakeSignedMsgOrderIxs(orderMessageRaw: SwiftOrderMessage, signedMsgOrderParamsMessage: SignedMsgOrderParamsMessage | SignedMsgOrderParamsDelegateMessage, makerOrderParams: OptionalOrderParams) => Promise<...>
startHeartbeatTimerany
reconnectany
await swiftOrderSubscriber.subscribe(async (orderMessageRaw, signedMessage, isDelegateSigner) => { // inspect signedMessage.signedMsgOrderParams });
Method SwiftOrderSubscriber.subscribeReference ↗
Parameters:
NameTypeDefault
onOrder(orderMessageRaw: SwiftOrderMessage, signedMessage: SignedMsgOrderParamsMessage | SignedMsgOrderParamsDelegateMessage, isDelegateSigner?: boolean | undefined) => Promise<...>
acceptSanitizedboolean
acceptDepositTradeboolean
Returns:
Promise<void>

Account getter (optional)

If you want to derive the taker’s UserAccount for downstream instructions, you can provide a userAccountGetter implementation to the subscriber (e.g. backed by UserMap).

import { UserMap } from "@drift-labs/sdk";
Class UserMapReference ↗
NameTypeDefault
userMapany
driftClientDriftClient
eventEmitterStrictEventEmitter<EventEmitter, UserEvents>
connectionany
commitmentany
includeIdleany
filterByPoolIdany
additionalFiltersany
disableSyncOnTotalAccountsChangeany
lastNumberOfSubAccountsany
subscriptionany
stateAccountUpdateCallbackany
decodeany
mostRecentSlotany
syncConfigany
syncPromiseany
syncPromiseResolverany
throwOnFailedSyncany
subscribe() => Promise<void>
addPubkey(userAccountPublicKey: PublicKey, userAccount?: UserAccount | undefined, slot?: number | undefined, accountSubscription?: UserSubscriptionConfig | undefined) => Promise<...>
has(key: string) => boolean
get(key: string) => User | undefined

gets the User for a particular userAccountPublicKey, if no User exists, undefined is returned

getWithSlot(key: string) => DataAndSlot<User> | undefined
mustGet(key: string, accountSubscription?: UserSubscriptionConfig | undefined) => Promise<User>

gets the User for a particular userAccountPublicKey, if no User exists, new one is created

mustGetWithSlot(key: string, accountSubscription?: UserSubscriptionConfig | undefined) => Promise<DataAndSlot<User>>
mustGetUserAccount(key: string) => Promise<UserAccount>
getUserAuthority(key: string) => PublicKey | undefined

gets the Authority for a particular userAccountPublicKey, if no User exists, undefined is returned

getDLOB(slot: number, protectedMakerParamsMap?: ProtectMakerParamsMap | undefined) => Promise<DLOB>

implements the DLOBSource interface create a DLOB from all the subscribed users

updateWithOrderRecord(record: OrderRecord) => Promise<void>
updateWithEventRecord(record: any) => Promise<void>
values() => IterableIterator<User>
valuesWithSlot() => IterableIterator<DataAndSlot<User>>
entries() => IterableIterator<[string, User]>
entriesWithSlot() => IterableIterator<[string, DataAndSlot<User>]>
size() => number
getUniqueAuthorities(filterCriteria?: UserAccountFilterCriteria | undefined) => PublicKey[]

Returns a unique list of authorities for all users in the UserMap that meet the filter criteria

sync() => Promise<void>
getFiltersany
defaultSyncany

Syncs the UserMap using the default sync method (single getProgramAccounts call with filters). This method may fail when drift has too many users. (nodejs response size limits)

paginatedSyncany

Syncs the UserMap using the paginated sync method (multiple getMultipleAccounts calls with filters). This method is more reliable when drift has many users.

unsubscribe() => Promise<void>
updateUserAccount(key: string, userAccount: UserAccount, slot: number) => Promise<void>
updateLatestSlot(slot: number) => void
getSlot() => number
Last updated on