diff --git a/libs/orders/src/lib/components/order-data-provider/Orders.graphql b/libs/orders/src/lib/components/order-data-provider/Orders.graphql index 7a0f5130b..08a06fa6f 100644 --- a/libs/orders/src/lib/components/order-data-provider/Orders.graphql +++ b/libs/orders/src/lib/components/order-data-provider/Orders.graphql @@ -31,18 +31,11 @@ query OrderById($orderId: ID!) { query Orders( $partyId: ID! $pagination: Pagination - $dateRange: DateRange - $filter: OrderFilter - $marketId: ID + $filter: OrderByMarketIdsFilter ) { party(id: $partyId) { id - ordersConnection( - pagination: $pagination - dateRange: $dateRange - filter: $filter - marketId: $marketId - ) { + ordersConnection(pagination: $pagination, filter: $filter) { edges { node { ...OrderFields @@ -79,8 +72,8 @@ fragment OrderUpdateFields on OrderUpdate { } } -subscription OrdersUpdate($partyId: ID!, $marketId: ID) { - orders(partyId: $partyId, marketId: $marketId) { +subscription OrdersUpdate($partyId: ID!) { + orders(filter: { partyIds: [$partyId] }) { ...OrderUpdateFields } } diff --git a/libs/orders/src/lib/components/order-data-provider/__generated__/Orders.ts b/libs/orders/src/lib/components/order-data-provider/__generated__/Orders.ts index 878b23d48..6b89f9412 100644 --- a/libs/orders/src/lib/components/order-data-provider/__generated__/Orders.ts +++ b/libs/orders/src/lib/components/order-data-provider/__generated__/Orders.ts @@ -15,9 +15,7 @@ export type OrderByIdQuery = { __typename?: 'Query', orderByID: { __typename?: ' export type OrdersQueryVariables = Types.Exact<{ partyId: Types.Scalars['ID']; pagination?: Types.InputMaybe; - dateRange?: Types.InputMaybe; - filter?: Types.InputMaybe; - marketId?: Types.InputMaybe; + filter?: Types.InputMaybe; }>; @@ -27,7 +25,6 @@ export type OrderUpdateFieldsFragment = { __typename?: 'OrderUpdate', id: string export type OrdersUpdateSubscriptionVariables = Types.Exact<{ partyId: Types.Scalars['ID']; - marketId?: Types.InputMaybe; }>; @@ -115,15 +112,10 @@ export type OrderByIdQueryHookResult = ReturnType; export type OrderByIdLazyQueryHookResult = ReturnType; export type OrderByIdQueryResult = Apollo.QueryResult; export const OrdersDocument = gql` - query Orders($partyId: ID!, $pagination: Pagination, $dateRange: DateRange, $filter: OrderFilter, $marketId: ID) { + query Orders($partyId: ID!, $pagination: Pagination, $filter: OrderByMarketIdsFilter) { party(id: $partyId) { id - ordersConnection( - pagination: $pagination - dateRange: $dateRange - filter: $filter - marketId: $marketId - ) { + ordersConnection(pagination: $pagination, filter: $filter) { edges { node { ...OrderFields @@ -155,9 +147,7 @@ export const OrdersDocument = gql` * variables: { * partyId: // value for 'partyId' * pagination: // value for 'pagination' - * dateRange: // value for 'dateRange' * filter: // value for 'filter' - * marketId: // value for 'marketId' * }, * }); */ @@ -173,8 +163,8 @@ export type OrdersQueryHookResult = ReturnType; export type OrdersLazyQueryHookResult = ReturnType; export type OrdersQueryResult = Apollo.QueryResult; export const OrdersUpdateDocument = gql` - subscription OrdersUpdate($partyId: ID!, $marketId: ID) { - orders(partyId: $partyId, marketId: $marketId) { + subscription OrdersUpdate($partyId: ID!) { + orders(filter: {partyIds: [$partyId]}) { ...OrderUpdateFields } } @@ -193,7 +183,6 @@ export const OrdersUpdateDocument = gql` * const { data, loading, error } = useOrdersUpdateSubscription({ * variables: { * partyId: // value for 'partyId' - * marketId: // value for 'marketId' * }, * }); */ diff --git a/libs/orders/src/lib/components/order-data-provider/order-data-provider.spec.ts b/libs/orders/src/lib/components/order-data-provider/order-data-provider.spec.ts index c630e0241..436967f77 100644 --- a/libs/orders/src/lib/components/order-data-provider/order-data-provider.spec.ts +++ b/libs/orders/src/lib/components/order-data-provider/order-data-provider.spec.ts @@ -1,6 +1,7 @@ import { update } from './order-data-provider'; import type { OrderUpdateFieldsFragment, OrderFieldsFragment } from '../'; import type { Edge } from '@vegaprotocol/utils'; + describe('order data provider', () => { it('puts incoming data in proper place', () => { const data = [ @@ -110,7 +111,11 @@ describe('order data provider', () => { const updatedData = update(data, delta, () => null, { partyId: '0x123', - dateRange: { end: new Date('2022-02-01').toISOString() }, + filter: { + order: { + dateRange: { end: new Date('2022-02-01').toISOString() }, + }, + }, }); expect( updatedData?.findIndex((edge) => edge.node.id === delta[0].id) diff --git a/libs/orders/src/lib/components/order-data-provider/order-data-provider.ts b/libs/orders/src/lib/components/order-data-provider/order-data-provider.ts index 65520e833..7065782a1 100644 --- a/libs/orders/src/lib/components/order-data-provider/order-data-provider.ts +++ b/libs/orders/src/lib/components/order-data-provider/order-data-provider.ts @@ -35,40 +35,45 @@ const orderMatchFilters = ( return true; } if ( - variables?.filter?.status && - !(order.status && variables.filter.status.includes(order.status)) + variables?.filter?.order?.status && + !(order.status && variables.filter.order.status.includes(order.status)) ) { return false; } if ( - variables?.filter?.types && - !(order.type && variables.filter.types.includes(order.type)) + variables?.filter?.order?.types && + !(order.type && variables.filter.order.types.includes(order.type)) ) { return false; } if ( - variables?.filter?.timeInForce && - !variables.filter.timeInForce.includes(order.timeInForce) + variables?.filter?.order?.timeInForce && + !variables.filter.order.timeInForce.includes(order.timeInForce) ) { return false; } - if (variables?.filter?.excludeLiquidity && order.liquidityProvisionId) { + if ( + variables?.filter?.order?.excludeLiquidity && + order.liquidityProvisionId + ) { return false; } if ( - variables?.dateRange?.start && + variables?.filter?.order?.dateRange?.start && !( (order.updatedAt || order.createdAt) && - variables.dateRange.start < (order.updatedAt || order.createdAt) + variables.filter.order.dateRange.start < + (order.updatedAt || order.createdAt) ) ) { return false; } if ( - variables?.dateRange?.end && + variables?.filter?.order?.dateRange?.end && !( (order.updatedAt || order.createdAt) && - variables.dateRange.end > (order.updatedAt || order.createdAt) + variables.filter.order.dateRange.end > + (order.updatedAt || order.createdAt) ) ) { return false; @@ -241,8 +246,10 @@ export const hasActiveOrderProvider = makeDerivedDataProvider< (callback, client, variables) => hasActiveOrderProviderInternal(callback, client, { filter: { - status: [OrderStatus.STATUS_ACTIVE], - excludeLiquidity: true, + order: { + status: [OrderStatus.STATUS_ACTIVE], + excludeLiquidity: true, + }, }, pagination: { first: 1, diff --git a/libs/orders/src/lib/components/order-list-manager/use-order-list-data.ts b/libs/orders/src/lib/components/order-list-manager/use-order-list-data.ts index 4a5200284..00e16c27e 100644 --- a/libs/orders/src/lib/components/order-list-manager/use-order-list-data.ts +++ b/libs/orders/src/lib/components/order-list-manager/use-order-list-data.ts @@ -67,24 +67,25 @@ export const useOrderListData = ({ } }, []); - const variables = useMemo< - OrdersQueryVariables & OrdersUpdateSubscriptionVariables - >( - () => ({ + const variables = useMemo(() => { + // define variable as const to get type safety, using generic with useMemo resulted in lost type safety + const allVars: OrdersQueryVariables & OrdersUpdateSubscriptionVariables = { partyId, - dateRange: filter?.updatedAt?.value, - marketId, filter: { - status: filter?.status?.value, - timeInForce: filter?.timeInForce?.value, - types: filter?.type?.value, + order: { + dateRange: filter?.updatedAt?.value, + status: filter?.status?.value, + timeInForce: filter?.timeInForce?.value, + types: filter?.type?.value, + }, }, pagination: { first: 1000, }, - }), - [partyId, marketId, filter] - ); + }; + + return allVars; + }, [partyId, filter]); const addNewRows = useCallback(() => { if (newRows.current === 0) { diff --git a/libs/orders/src/lib/order-hooks/OrdersSubscription.graphql b/libs/orders/src/lib/order-hooks/OrdersSubscription.graphql index 9b7477bd3..1766d8674 100644 --- a/libs/orders/src/lib/order-hooks/OrdersSubscription.graphql +++ b/libs/orders/src/lib/order-hooks/OrdersSubscription.graphql @@ -13,7 +13,7 @@ fragment OrderSubFields on OrderUpdate { } subscription OrderSub($partyId: ID!) { - orders(partyId: $partyId) { + orders(filter: { partyIds: [$partyId] }) { ...OrderSubFields } } diff --git a/libs/orders/src/lib/order-hooks/__generated__/OrdersSubscription.ts b/libs/orders/src/lib/order-hooks/__generated__/OrdersSubscription.ts index aa0709229..b5d7885c3 100644 --- a/libs/orders/src/lib/order-hooks/__generated__/OrdersSubscription.ts +++ b/libs/orders/src/lib/order-hooks/__generated__/OrdersSubscription.ts @@ -29,7 +29,7 @@ export const OrderSubFieldsFragmentDoc = gql` `; export const OrderSubDocument = gql` subscription OrderSub($partyId: ID!) { - orders(partyId: $partyId) { + orders(filter: {partyIds: [$partyId]}) { ...OrderSubFields } } diff --git a/libs/orders/src/lib/order-hooks/use-pending-orders-volume.ts b/libs/orders/src/lib/order-hooks/use-pending-orders-volume.ts index cdc0d2047..efcb3513d 100644 --- a/libs/orders/src/lib/order-hooks/use-pending-orders-volume.ts +++ b/libs/orders/src/lib/order-hooks/use-pending-orders-volume.ts @@ -53,12 +53,14 @@ export const useActiveOrdersVolumeAndMargin = ( update, variables: { partyId: partyId || '', - marketId, filter: { - status: [ - OrderStatus.STATUS_ACTIVE, - OrderStatus.STATUS_PARTIALLY_FILLED, - ], + marketIds: [marketId], + order: { + status: [ + OrderStatus.STATUS_ACTIVE, + OrderStatus.STATUS_PARTIALLY_FILLED, + ], + }, }, }, skip: !partyId, diff --git a/libs/positions/src/lib/positions-data-providers.ts b/libs/positions/src/lib/positions-data-providers.ts index a25e66892..660a749ce 100644 --- a/libs/positions/src/lib/positions-data-providers.ts +++ b/libs/positions/src/lib/positions-data-providers.ts @@ -353,10 +353,12 @@ export const volumeAndMarginProvider = makeDerivedDataProvider< ordersProvider(callback, client, { ...variables, filter: { - status: [ - OrderStatus.STATUS_ACTIVE, - OrderStatus.STATUS_PARTIALLY_FILLED, - ], + order: { + status: [ + OrderStatus.STATUS_ACTIVE, + OrderStatus.STATUS_PARTIALLY_FILLED, + ], + }, }, }), (callback, client, variables) => diff --git a/libs/types/src/__generated__/types.ts b/libs/types/src/__generated__/types.ts index 5b198dcfc..aa926b374 100644 --- a/libs/types/src/__generated__/types.ts +++ b/libs/types/src/__generated__/types.ts @@ -1513,6 +1513,7 @@ export type MarketdepthArgs = { /** Represents a product & associated parameters that can be traded on Vega, has an associated OrderBook and Trade history */ export type MarketliquidityProvisionsConnectionArgs = { + live?: InputMaybe; pagination?: InputMaybe; partyId?: InputMaybe; }; @@ -1520,8 +1521,7 @@ export type MarketliquidityProvisionsConnectionArgs = { /** Represents a product & associated parameters that can be traded on Vega, has an associated OrderBook and Trade history */ export type MarketordersConnectionArgs = { - dateRange?: InputMaybe; - filter?: InputMaybe; + filter?: InputMaybe; pagination?: InputMaybe; }; @@ -2193,8 +2193,12 @@ export type Order = { party: Party; /** PeggedOrder contains the details about a pegged order */ peggedOrder?: Maybe; + /** Is this a post only order */ + postOnly?: Maybe; /** The worst price the order will trade at (e.g. buy for price or less, sell for price or more) (uint64) */ price: Scalars['String']; + /** Is this a reduce only order */ + reduceOnly?: Maybe; /** The external reference (if available) for the order */ reference: Scalars['String']; /** Why the order was rejected */ @@ -2226,6 +2230,22 @@ export type OrdertradesConnectionArgs = { pagination?: InputMaybe; }; +export type OrderByMarketAndPartyIdsFilter = { + marketIds?: InputMaybe>; + order?: InputMaybe; + partyIds?: InputMaybe>; +}; + +export type OrderByMarketIdsFilter = { + marketIds?: InputMaybe>; + order?: InputMaybe; +}; + +export type OrderByPartyIdsFilter = { + order?: InputMaybe; + partyIds?: InputMaybe>; +}; + /** Connection type for retrieving cursor-based paginated order information */ export type OrderConnection = { __typename?: 'OrderConnection'; @@ -2256,6 +2276,8 @@ export type OrderEstimate = { }; export type OrderFilter = { + /** Date range to retrieve orders from/to. Start and end time should be expressed as an integer value of nano-seconds past the Unix epoch */ + dateRange?: InputMaybe; excludeLiquidity?: InputMaybe; status?: InputMaybe>; timeInForce?: InputMaybe>; @@ -2539,6 +2561,7 @@ export type PartydepositsConnectionArgs = { /** Represents a party on Vega, could be an ethereum wallet address in the future */ export type PartyliquidityProvisionsConnectionArgs = { + live?: InputMaybe; marketId?: InputMaybe; pagination?: InputMaybe; reference?: InputMaybe; @@ -2554,9 +2577,7 @@ export type PartymarginsConnectionArgs = { /** Represents a party on Vega, could be an ethereum wallet address in the future */ export type PartyordersConnectionArgs = { - dateRange?: InputMaybe; - filter?: InputMaybe; - marketId?: InputMaybe; + filter?: InputMaybe; pagination?: InputMaybe; }; @@ -4050,8 +4071,7 @@ export type SubscriptionmarketsDepthUpdateArgs = { /** Subscriptions allow a caller to receive new information as it is available from the Vega network. */ export type SubscriptionordersArgs = { - marketId?: InputMaybe; - partyId?: InputMaybe; + filter?: InputMaybe; }; diff --git a/libs/wallet/src/TransactionResult.graphql b/libs/wallet/src/TransactionResult.graphql index 8dc34a38a..11c763c24 100644 --- a/libs/wallet/src/TransactionResult.graphql +++ b/libs/wallet/src/TransactionResult.graphql @@ -68,7 +68,7 @@ fragment OrderTxUpdateFields on OrderUpdate { } subscription OrderTxUpdate($partyId: ID!) { - orders(partyId: $partyId) { + orders(filter: { partyIds: [$partyId] }) { ...OrderTxUpdateFields } } diff --git a/libs/wallet/src/__generated__/TransactionResult.ts b/libs/wallet/src/__generated__/TransactionResult.ts index c76008861..97d4b9449 100644 --- a/libs/wallet/src/__generated__/TransactionResult.ts +++ b/libs/wallet/src/__generated__/TransactionResult.ts @@ -176,7 +176,7 @@ export type WithdrawalBusEventSubscriptionHookResult = ReturnType; export const OrderTxUpdateDocument = gql` subscription OrderTxUpdate($partyId: ID!) { - orders(partyId: $partyId) { + orders(filter: {partyIds: [$partyId]}) { ...OrderTxUpdateFields } }