chore(orders): update orders filters (#3277)

Co-authored-by: maciek <maciek@vegaprotocol.io>
This commit is contained in:
Matthew Russell 2023-03-29 04:12:29 -07:00 committed by GitHub
parent 351583ce8f
commit 5f7e60d22f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 92 additions and 73 deletions

View File

@ -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
}
}

View File

@ -15,9 +15,7 @@ export type OrderByIdQuery = { __typename?: 'Query', orderByID: { __typename?: '
export type OrdersQueryVariables = Types.Exact<{
partyId: Types.Scalars['ID'];
pagination?: Types.InputMaybe<Types.Pagination>;
dateRange?: Types.InputMaybe<Types.DateRange>;
filter?: Types.InputMaybe<Types.OrderFilter>;
marketId?: Types.InputMaybe<Types.Scalars['ID']>;
filter?: Types.InputMaybe<Types.OrderByMarketIdsFilter>;
}>;
@ -27,7 +25,6 @@ export type OrderUpdateFieldsFragment = { __typename?: 'OrderUpdate', id: string
export type OrdersUpdateSubscriptionVariables = Types.Exact<{
partyId: Types.Scalars['ID'];
marketId?: Types.InputMaybe<Types.Scalars['ID']>;
}>;
@ -115,15 +112,10 @@ export type OrderByIdQueryHookResult = ReturnType<typeof useOrderByIdQuery>;
export type OrderByIdLazyQueryHookResult = ReturnType<typeof useOrderByIdLazyQuery>;
export type OrderByIdQueryResult = Apollo.QueryResult<OrderByIdQuery, OrderByIdQueryVariables>;
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<typeof useOrdersQuery>;
export type OrdersLazyQueryHookResult = ReturnType<typeof useOrdersLazyQuery>;
export type OrdersQueryResult = Apollo.QueryResult<OrdersQuery, OrdersQueryVariables>;
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'
* },
* });
*/

View File

@ -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)

View File

@ -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,

View File

@ -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) {

View File

@ -13,7 +13,7 @@ fragment OrderSubFields on OrderUpdate {
}
subscription OrderSub($partyId: ID!) {
orders(partyId: $partyId) {
orders(filter: { partyIds: [$partyId] }) {
...OrderSubFields
}
}

View File

@ -29,7 +29,7 @@ export const OrderSubFieldsFragmentDoc = gql`
`;
export const OrderSubDocument = gql`
subscription OrderSub($partyId: ID!) {
orders(partyId: $partyId) {
orders(filter: {partyIds: [$partyId]}) {
...OrderSubFields
}
}

View File

@ -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,

View File

@ -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) =>

View File

@ -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<Scalars['Boolean']>;
pagination?: InputMaybe<Pagination>;
partyId?: InputMaybe<Scalars['ID']>;
};
@ -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<DateRange>;
filter?: InputMaybe<OrderFilter>;
filter?: InputMaybe<OrderByPartyIdsFilter>;
pagination?: InputMaybe<Pagination>;
};
@ -2193,8 +2193,12 @@ export type Order = {
party: Party;
/** PeggedOrder contains the details about a pegged order */
peggedOrder?: Maybe<PeggedOrder>;
/** Is this a post only order */
postOnly?: Maybe<Scalars['Boolean']>;
/** 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<Scalars['Boolean']>;
/** 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<Pagination>;
};
export type OrderByMarketAndPartyIdsFilter = {
marketIds?: InputMaybe<Array<Scalars['ID']>>;
order?: InputMaybe<OrderFilter>;
partyIds?: InputMaybe<Array<Scalars['ID']>>;
};
export type OrderByMarketIdsFilter = {
marketIds?: InputMaybe<Array<Scalars['ID']>>;
order?: InputMaybe<OrderFilter>;
};
export type OrderByPartyIdsFilter = {
order?: InputMaybe<OrderFilter>;
partyIds?: InputMaybe<Array<Scalars['ID']>>;
};
/** 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<DateRange>;
excludeLiquidity?: InputMaybe<Scalars['Boolean']>;
status?: InputMaybe<Array<OrderStatus>>;
timeInForce?: InputMaybe<Array<OrderTimeInForce>>;
@ -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<Scalars['Boolean']>;
marketId?: InputMaybe<Scalars['ID']>;
pagination?: InputMaybe<Pagination>;
reference?: InputMaybe<Scalars['String']>;
@ -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<DateRange>;
filter?: InputMaybe<OrderFilter>;
marketId?: InputMaybe<Scalars['ID']>;
filter?: InputMaybe<OrderByMarketIdsFilter>;
pagination?: InputMaybe<Pagination>;
};
@ -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<Scalars['ID']>;
partyId?: InputMaybe<Scalars['ID']>;
filter?: InputMaybe<OrderByMarketAndPartyIdsFilter>;
};

View File

@ -68,7 +68,7 @@ fragment OrderTxUpdateFields on OrderUpdate {
}
subscription OrderTxUpdate($partyId: ID!) {
orders(partyId: $partyId) {
orders(filter: { partyIds: [$partyId] }) {
...OrderTxUpdateFields
}
}

View File

@ -176,7 +176,7 @@ export type WithdrawalBusEventSubscriptionHookResult = ReturnType<typeof useWith
export type WithdrawalBusEventSubscriptionResult = Apollo.SubscriptionResult<WithdrawalBusEventSubscription>;
export const OrderTxUpdateDocument = gql`
subscription OrderTxUpdate($partyId: ID!) {
orders(partyId: $partyId) {
orders(filter: {partyIds: [$partyId]}) {
...OrderTxUpdateFields
}
}