fix(orders): restore filter by marketId (#3342)
This commit is contained in:
parent
861760b4f9
commit
381d9011a0
@ -32,12 +32,16 @@ query OrderById($orderId: ID!) {
|
||||
|
||||
query Orders(
|
||||
$partyId: ID!
|
||||
$marketIds: [ID!]
|
||||
$pagination: Pagination
|
||||
$filter: OrderByMarketIdsFilter
|
||||
$filter: OrderFilter
|
||||
) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
ordersConnection(pagination: $pagination, filter: $filter) {
|
||||
ordersConnection(
|
||||
pagination: $pagination
|
||||
filter: { order: $filter, marketIds: $marketIds }
|
||||
) {
|
||||
edges {
|
||||
node {
|
||||
...OrderFields
|
||||
@ -74,8 +78,8 @@ fragment OrderUpdateFields on OrderUpdate {
|
||||
}
|
||||
}
|
||||
|
||||
subscription OrdersUpdate($partyId: ID!) {
|
||||
orders(filter: { partyIds: [$partyId] }) {
|
||||
subscription OrdersUpdate($partyId: ID!, $marketIds: [ID!]) {
|
||||
orders(filter: { partyIds: [$partyId], marketIds: $marketIds }) {
|
||||
...OrderUpdateFields
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,9 @@ export type OrderByIdQuery = { __typename?: 'Query', orderByID: { __typename?: '
|
||||
|
||||
export type OrdersQueryVariables = Types.Exact<{
|
||||
partyId: Types.Scalars['ID'];
|
||||
marketIds?: Types.InputMaybe<Array<Types.Scalars['ID']> | Types.Scalars['ID']>;
|
||||
pagination?: Types.InputMaybe<Types.Pagination>;
|
||||
filter?: Types.InputMaybe<Types.OrderByMarketIdsFilter>;
|
||||
filter?: Types.InputMaybe<Types.OrderFilter>;
|
||||
}>;
|
||||
|
||||
|
||||
@ -25,6 +26,7 @@ export type OrderUpdateFieldsFragment = { __typename?: 'OrderUpdate', id: string
|
||||
|
||||
export type OrdersUpdateSubscriptionVariables = Types.Exact<{
|
||||
partyId: Types.Scalars['ID'];
|
||||
marketIds?: Types.InputMaybe<Array<Types.Scalars['ID']> | Types.Scalars['ID']>;
|
||||
}>;
|
||||
|
||||
|
||||
@ -114,10 +116,13 @@ 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, $filter: OrderByMarketIdsFilter) {
|
||||
query Orders($partyId: ID!, $marketIds: [ID!], $pagination: Pagination, $filter: OrderFilter) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
ordersConnection(pagination: $pagination, filter: $filter) {
|
||||
ordersConnection(
|
||||
pagination: $pagination
|
||||
filter: {order: $filter, marketIds: $marketIds}
|
||||
) {
|
||||
edges {
|
||||
node {
|
||||
...OrderFields
|
||||
@ -148,6 +153,7 @@ export const OrdersDocument = gql`
|
||||
* const { data, loading, error } = useOrdersQuery({
|
||||
* variables: {
|
||||
* partyId: // value for 'partyId'
|
||||
* marketIds: // value for 'marketIds'
|
||||
* pagination: // value for 'pagination'
|
||||
* filter: // value for 'filter'
|
||||
* },
|
||||
@ -165,8 +171,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!) {
|
||||
orders(filter: {partyIds: [$partyId]}) {
|
||||
subscription OrdersUpdate($partyId: ID!, $marketIds: [ID!]) {
|
||||
orders(filter: {partyIds: [$partyId], marketIds: $marketIds}) {
|
||||
...OrderUpdateFields
|
||||
}
|
||||
}
|
||||
@ -185,6 +191,7 @@ export const OrdersUpdateDocument = gql`
|
||||
* const { data, loading, error } = useOrdersUpdateSubscription({
|
||||
* variables: {
|
||||
* partyId: // value for 'partyId'
|
||||
* marketIds: // value for 'marketIds'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
|
@ -112,9 +112,7 @@ describe('order data provider', () => {
|
||||
const updatedData = update(data, delta, () => null, {
|
||||
partyId: '0x123',
|
||||
filter: {
|
||||
order: {
|
||||
dateRange: { end: new Date('2022-02-01').toISOString() },
|
||||
},
|
||||
dateRange: { end: new Date('2022-02-01').toISOString() },
|
||||
},
|
||||
});
|
||||
expect(
|
||||
|
@ -35,45 +35,40 @@ const orderMatchFilters = (
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
variables?.filter?.order?.status &&
|
||||
!(order.status && variables.filter.order.status.includes(order.status))
|
||||
variables?.filter?.status &&
|
||||
!(order.status && variables.filter.status.includes(order.status))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
variables?.filter?.order?.types &&
|
||||
!(order.type && variables.filter.order.types.includes(order.type))
|
||||
variables?.filter?.types &&
|
||||
!(order.type && variables.filter.types.includes(order.type))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
variables?.filter?.order?.timeInForce &&
|
||||
!variables.filter.order.timeInForce.includes(order.timeInForce)
|
||||
variables?.filter?.timeInForce &&
|
||||
!variables.filter.timeInForce.includes(order.timeInForce)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
variables?.filter?.order?.excludeLiquidity &&
|
||||
order.liquidityProvisionId
|
||||
) {
|
||||
if (variables?.filter?.excludeLiquidity && order.liquidityProvisionId) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
variables?.filter?.order?.dateRange?.start &&
|
||||
variables?.filter?.dateRange?.start &&
|
||||
!(
|
||||
(order.updatedAt || order.createdAt) &&
|
||||
variables.filter.order.dateRange.start <
|
||||
(order.updatedAt || order.createdAt)
|
||||
variables.filter.dateRange.start < (order.updatedAt || order.createdAt)
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
variables?.filter?.order?.dateRange?.end &&
|
||||
variables?.filter?.dateRange?.end &&
|
||||
!(
|
||||
(order.updatedAt || order.createdAt) &&
|
||||
variables.filter.order.dateRange.end >
|
||||
(order.updatedAt || order.createdAt)
|
||||
variables.filter.dateRange.end > (order.updatedAt || order.createdAt)
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
@ -243,18 +238,17 @@ export const hasActiveOrderProvider = makeDerivedDataProvider<
|
||||
{ partyId: string; marketId?: string }
|
||||
>(
|
||||
[
|
||||
(callback, client, variables) =>
|
||||
(callback, client, { partyId, marketId }) =>
|
||||
hasActiveOrderProviderInternal(callback, client, {
|
||||
marketIds: marketId ? [marketId] : undefined,
|
||||
filter: {
|
||||
order: {
|
||||
status: [OrderStatus.STATUS_ACTIVE],
|
||||
excludeLiquidity: true,
|
||||
},
|
||||
status: [OrderStatus.STATUS_ACTIVE],
|
||||
excludeLiquidity: true,
|
||||
},
|
||||
pagination: {
|
||||
first: 1,
|
||||
},
|
||||
...variables,
|
||||
partyId,
|
||||
} as OrdersQueryVariables),
|
||||
],
|
||||
(parts) => parts[0]
|
||||
|
@ -72,12 +72,10 @@ export const useOrderListData = ({
|
||||
const allVars: OrdersQueryVariables & OrdersUpdateSubscriptionVariables = {
|
||||
partyId,
|
||||
filter: {
|
||||
order: {
|
||||
dateRange: filter?.updatedAt?.value,
|
||||
status: filter?.status?.value,
|
||||
timeInForce: filter?.timeInForce?.value,
|
||||
types: filter?.type?.value,
|
||||
},
|
||||
dateRange: filter?.updatedAt?.value,
|
||||
status: filter?.status?.value,
|
||||
timeInForce: filter?.timeInForce?.value,
|
||||
types: filter?.type?.value,
|
||||
},
|
||||
pagination: {
|
||||
first: 1000,
|
||||
|
@ -53,14 +53,12 @@ export const useActiveOrdersVolumeAndMargin = (
|
||||
update,
|
||||
variables: {
|
||||
partyId: partyId || '',
|
||||
marketIds: [marketId],
|
||||
filter: {
|
||||
marketIds: [marketId],
|
||||
order: {
|
||||
status: [
|
||||
OrderStatus.STATUS_ACTIVE,
|
||||
OrderStatus.STATUS_PARTIALLY_FILLED,
|
||||
],
|
||||
},
|
||||
status: [
|
||||
OrderStatus.STATUS_ACTIVE,
|
||||
OrderStatus.STATUS_PARTIALLY_FILLED,
|
||||
],
|
||||
},
|
||||
},
|
||||
skip: !partyId,
|
||||
|
@ -1,5 +1,5 @@
|
||||
import type { MarketData, Market } from '@vegaprotocol/market-list';
|
||||
import type { Order } from '@vegaprotocol/orders';
|
||||
import type { OrderFieldsFragment } from '@vegaprotocol/orders';
|
||||
import { timeInForceLabel } from '@vegaprotocol/orders';
|
||||
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
@ -50,7 +50,7 @@ export const ActiveOrders = ({
|
||||
orders,
|
||||
}: {
|
||||
market: Market;
|
||||
orders: Order[];
|
||||
orders: OrderFieldsFragment[];
|
||||
}) => {
|
||||
const asset = market.tradableInstrument.instrument.product.settlementAsset;
|
||||
|
||||
|
@ -349,16 +349,15 @@ export const volumeAndMarginProvider = makeDerivedDataProvider<
|
||||
PositionsQueryVariables & MarketDataQueryVariables
|
||||
>(
|
||||
[
|
||||
(callback, client, variables) =>
|
||||
(callback, client, { partyId, marketId }) =>
|
||||
ordersProvider(callback, client, {
|
||||
...variables,
|
||||
partyId,
|
||||
marketIds: [marketId],
|
||||
filter: {
|
||||
order: {
|
||||
status: [
|
||||
OrderStatus.STATUS_ACTIVE,
|
||||
OrderStatus.STATUS_PARTIALLY_FILLED,
|
||||
],
|
||||
},
|
||||
status: [
|
||||
OrderStatus.STATUS_ACTIVE,
|
||||
OrderStatus.STATUS_PARTIALLY_FILLED,
|
||||
],
|
||||
},
|
||||
}),
|
||||
(callback, client, variables) =>
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { marketDataProvider, marketProvider } from '@vegaprotocol/market-list';
|
||||
import { isOrderActive, ordersWithMarketProvider } from '@vegaprotocol/orders';
|
||||
import { isOrderActive, ordersProvider } from '@vegaprotocol/orders';
|
||||
import type { OrdersQueryVariables } from '@vegaprotocol/orders';
|
||||
import { useDataProvider } from '@vegaprotocol/react-helpers';
|
||||
import { useMemo } from 'react';
|
||||
@ -13,8 +13,11 @@ export const useRequestClosePositionData = (
|
||||
[marketId]
|
||||
);
|
||||
const orderVariables = useMemo<OrdersQueryVariables>(
|
||||
() => ({ partyId: partyId || '' }),
|
||||
[partyId]
|
||||
() => ({
|
||||
partyId: partyId || '',
|
||||
marketIds: marketId ? [marketId] : undefined,
|
||||
}),
|
||||
[partyId, marketId]
|
||||
);
|
||||
const { data: market, loading: marketLoading } = useDataProvider({
|
||||
dataProvider: marketProvider,
|
||||
@ -26,7 +29,7 @@ export const useRequestClosePositionData = (
|
||||
variables: marketVariables,
|
||||
});
|
||||
const { data: orderData, loading: orderDataLoading } = useDataProvider({
|
||||
dataProvider: ordersWithMarketProvider,
|
||||
dataProvider: ordersProvider,
|
||||
variables: orderVariables,
|
||||
skip: !partyId,
|
||||
});
|
||||
@ -35,23 +38,7 @@ export const useRequestClosePositionData = (
|
||||
if (!orderData || !market) return [];
|
||||
return (
|
||||
orderData
|
||||
.filter((o) => {
|
||||
// Filter out orders not on market for position
|
||||
if (
|
||||
!o ||
|
||||
!o.node ||
|
||||
!o.node.market ||
|
||||
o.node.market.id !== market.id
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isOrderActive(o.node.status)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
||||
.filter((o) => o?.node && isOrderActive(o.node.status))
|
||||
// @ts-ignore o is never null as its been filtered out above
|
||||
.map((o) => o.node)
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user