Skip to content

Commit

Permalink
core: actions: getOpenOrders, getOrderMetadata: use new response shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
akirillo committed Oct 22, 2024
1 parent ea540af commit 3a29cac
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
10 changes: 2 additions & 8 deletions packages/core/src/actions/getOpenOrders.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { ADMIN_OPEN_ORDERS_ROUTE } from '../constants.js'
import type { Config } from '../createConfig.js'
import { BaseError, type BaseErrorType } from '../errors/base.js'
import type { OpenOrder } from '../types/order.js'
import { getRelayerWithAdmin } from '../utils/http.js'

export type GetOpenOrdersParams = {
matchingPool?: string
includeFillable?: boolean
}

export type GetOpenOrdersReturnType = Map<string, OpenOrder>
export type GetOpenOrdersReturnType = string[]

export type GetOpenOrdersErrorType = BaseErrorType

Expand All @@ -25,14 +23,10 @@ export async function getOpenOrders(
url.searchParams.set('matching_pool', parameters.matchingPool)
}

if (parameters.includeFillable) {
url.searchParams.set('include_fillable', String(true))
}

const res = await getRelayerWithAdmin(config, url.toString())

if (!res.orders) {
throw new BaseError('No orders found')
}
return new Map(res.orders.map((order: OpenOrder) => [order.order.id, order]))
return res.orders
}
20 changes: 13 additions & 7 deletions packages/core/src/actions/getOrderMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { ADMIN_ORDER_METADATA_ROUTE } from '../constants.js'
import type { Config } from '../createConfig.js'
import { BaseError, type BaseErrorType } from '../errors/base.js'
import type { OrderMetadata } from '../types/order.js'
import type { AdminOrderMetadata } from '../types/order.js'
import { getRelayerWithAdmin } from '../utils/http.js'

export type GetOrderMetadataParameters = { id: string }
export type GetOrderMetadataParameters = {
id: string
includeFillable?: boolean
}

export type GetOrderMetadataReturnType = OrderMetadata
export type GetOrderMetadataReturnType = AdminOrderMetadata

export type GetOrderMetadataErrorType = BaseErrorType

Expand All @@ -17,10 +20,13 @@ export async function getOrderMetadata(
const { id } = parameters
const { getRelayerBaseUrl } = config

const res = await getRelayerWithAdmin(
config,
getRelayerBaseUrl(ADMIN_ORDER_METADATA_ROUTE(id)),
)
const url = new URL(getRelayerBaseUrl(ADMIN_ORDER_METADATA_ROUTE(id)))

if (parameters.includeFillable) {
url.searchParams.set('include_fillable', String(true))
}

const res = await getRelayerWithAdmin(config, url.toString())

if (!res.order) {
throw new BaseError('No order found')
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type TimestampedPrice = {
timestamp: bigint
}

export type OpenOrder = {
export type AdminOrderMetadata = {
order: OrderMetadata
wallet_id: string
fillable?: bigint
Expand Down

0 comments on commit 3a29cac

Please sign in to comment.