chore: use queries from graphql file on orders lib (#1843)
This commit is contained in:
parent
17f93c2b7e
commit
3bc9d3386b
@ -1,5 +1,5 @@
|
||||
import type { FillsQuery, FillFieldsFragment } from '@vegaprotocol/fills';
|
||||
import { Side } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import merge from 'lodash/merge';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
|
||||
@ -17,7 +17,7 @@ export const generateFills = (
|
||||
seller: {
|
||||
id: Cypress.env('VEGA_PUBLIC_KEY'),
|
||||
},
|
||||
aggressor: Side.SIDE_SELL,
|
||||
aggressor: Schema.Side.SIDE_SELL,
|
||||
buyerFee: {
|
||||
infrastructureFee: '5000',
|
||||
},
|
||||
@ -30,11 +30,11 @@ export const generateFills = (
|
||||
seller: {
|
||||
id: Cypress.env('VEGA_PUBLIC_KEY'),
|
||||
},
|
||||
aggressor: Side.SIDE_BUY,
|
||||
aggressor: Schema.Side.SIDE_BUY,
|
||||
}),
|
||||
generateFill({
|
||||
id: '3',
|
||||
aggressor: Side.SIDE_SELL,
|
||||
aggressor: Schema.Side.SIDE_SELL,
|
||||
market: {
|
||||
id: 'market-2',
|
||||
},
|
||||
@ -80,7 +80,7 @@ export const generateFill = (override?: PartialDeep<FillFieldsFragment>) => {
|
||||
size: '50000',
|
||||
buyOrder: 'buy-order',
|
||||
sellOrder: 'sell-order',
|
||||
aggressor: Side.SIDE_BUY,
|
||||
aggressor: Schema.Side.SIDE_BUY,
|
||||
buyer: {
|
||||
__typename: 'Party',
|
||||
id: 'buyer-id',
|
||||
|
@ -1,18 +1,12 @@
|
||||
import merge from 'lodash/merge';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
import type {
|
||||
Orders,
|
||||
Orders_party_ordersConnection_edges_node,
|
||||
} from '@vegaprotocol/orders';
|
||||
import {
|
||||
OrderStatus,
|
||||
OrderTimeInForce,
|
||||
OrderType,
|
||||
Side,
|
||||
} from '@vegaprotocol/types';
|
||||
import type { OrdersQuery, OrderFieldsFragment } from '@vegaprotocol/orders';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
|
||||
export const generateOrders = (override?: PartialDeep<Orders>): Orders => {
|
||||
const orders: Orders_party_ordersConnection_edges_node[] = [
|
||||
export const generateOrders = (
|
||||
override?: PartialDeep<OrdersQuery>
|
||||
): OrdersQuery => {
|
||||
const orders: OrderFieldsFragment[] = [
|
||||
{
|
||||
__typename: 'Order',
|
||||
id: '066468C06549101DAF7BC51099E1412A0067DC08C246B7D8013C9D0CBF1E8EE7',
|
||||
@ -21,12 +15,12 @@ export const generateOrders = (override?: PartialDeep<Orders>): Orders => {
|
||||
id: 'market-0',
|
||||
},
|
||||
size: '10',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
status: OrderStatus.STATUS_FILLED,
|
||||
side: Side.SIDE_BUY,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status: Schema.OrderStatus.STATUS_FILLED,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
remaining: '0',
|
||||
price: '20000000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
createdAt: new Date(2020, 1, 30).toISOString(),
|
||||
updatedAt: null,
|
||||
expiresAt: null,
|
||||
@ -42,12 +36,12 @@ export const generateOrders = (override?: PartialDeep<Orders>): Orders => {
|
||||
id: 'market-1',
|
||||
},
|
||||
size: '1',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
status: OrderStatus.STATUS_FILLED,
|
||||
side: Side.SIDE_BUY,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status: Schema.OrderStatus.STATUS_FILLED,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
remaining: '0',
|
||||
price: '100',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
createdAt: new Date(2020, 1, 29).toISOString(),
|
||||
updatedAt: null,
|
||||
expiresAt: null,
|
||||
@ -63,12 +57,12 @@ export const generateOrders = (override?: PartialDeep<Orders>): Orders => {
|
||||
id: 'market-2',
|
||||
},
|
||||
size: '1',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
status: OrderStatus.STATUS_FILLED,
|
||||
side: Side.SIDE_BUY,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status: Schema.OrderStatus.STATUS_FILLED,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
remaining: '0',
|
||||
price: '20000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
createdAt: new Date(2020, 1, 28).toISOString(),
|
||||
updatedAt: null,
|
||||
expiresAt: null,
|
||||
@ -84,12 +78,12 @@ export const generateOrders = (override?: PartialDeep<Orders>): Orders => {
|
||||
id: 'market-3',
|
||||
},
|
||||
size: '1',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
side: Side.SIDE_BUY,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status: Schema.OrderStatus.STATUS_ACTIVE,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
remaining: '0',
|
||||
price: '100000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
createdAt: new Date(2020, 1, 27).toISOString(),
|
||||
updatedAt: null,
|
||||
expiresAt: null,
|
||||
@ -105,12 +99,12 @@ export const generateOrders = (override?: PartialDeep<Orders>): Orders => {
|
||||
id: 'market-3',
|
||||
},
|
||||
size: '10',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
status: OrderStatus.STATUS_PARTIALLY_FILLED,
|
||||
side: Side.SIDE_SELL,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status: Schema.OrderStatus.STATUS_PARTIALLY_FILLED,
|
||||
side: Schema.Side.SIDE_SELL,
|
||||
remaining: '3',
|
||||
price: '100000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
createdAt: new Date(2020, 1, 27).toISOString(),
|
||||
updatedAt: null,
|
||||
expiresAt: null,
|
||||
@ -120,7 +114,7 @@ export const generateOrders = (override?: PartialDeep<Orders>): Orders => {
|
||||
},
|
||||
];
|
||||
|
||||
const defaultResult: Orders = {
|
||||
const defaultResult: OrdersQuery = {
|
||||
party: {
|
||||
id: Cypress.env('VEGA_PUBLIC_KEY'),
|
||||
ordersConnection: {
|
||||
|
@ -38,7 +38,7 @@ import { DealTicketSize } from './deal-ticket-size';
|
||||
import MarketNameRenderer from '../simple-market-list/simple-market-renderer';
|
||||
import SideSelector, { SIDE_NAMES } from './side-selector';
|
||||
import ReviewTrade from './review-trade';
|
||||
import { Side, OrderType } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import { DealTicketSlippage } from './deal-ticket-slippage';
|
||||
|
||||
interface DealTicketMarketProps {
|
||||
@ -118,7 +118,7 @@ export const DealTicketSteps = ({ market }: DealTicketMarketProps) => {
|
||||
|
||||
const price = useMemo(() => {
|
||||
if (slippage && market?.depth?.lastTrade?.price) {
|
||||
const isLong = order.side === Side.SIDE_BUY;
|
||||
const isLong = order.side === Schema.Side.SIDE_BUY;
|
||||
const multiplier = new BigNumber(1)[isLong ? 'plus' : 'minus'](
|
||||
parseFloat(slippage) / 100
|
||||
);
|
||||
@ -182,7 +182,7 @@ export const DealTicketSteps = ({ market }: DealTicketMarketProps) => {
|
||||
(value: number) => {
|
||||
if (market?.depth?.lastTrade?.price) {
|
||||
if (value) {
|
||||
const isLong = order.side === Side.SIDE_BUY;
|
||||
const isLong = order.side === Schema.Side.SIDE_BUY;
|
||||
const multiplier = new BigNumber(1)[isLong ? 'plus' : 'minus'](
|
||||
value / 100
|
||||
);
|
||||
@ -193,11 +193,11 @@ export const DealTicketSteps = ({ market }: DealTicketMarketProps) => {
|
||||
|
||||
setValue('price', bestAskPrice);
|
||||
|
||||
if (order.type === OrderType.TYPE_MARKET) {
|
||||
setValue('type', OrderType.TYPE_LIMIT);
|
||||
if (order.type === Schema.OrderType.TYPE_MARKET) {
|
||||
setValue('type', Schema.OrderType.TYPE_LIMIT);
|
||||
}
|
||||
} else {
|
||||
setValue('type', OrderType.TYPE_MARKET);
|
||||
setValue('type', Schema.OrderType.TYPE_MARKET);
|
||||
setValue('price', market?.depth?.lastTrade?.price);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import type {
|
||||
MarketTags,
|
||||
MarketTagsVariables,
|
||||
} from './__generated__/MarketTags';
|
||||
import { Side } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import { MarketExpires } from '@vegaprotocol/market-info';
|
||||
|
||||
export const MARKET_TAGS_QUERY = gql`
|
||||
@ -72,9 +72,10 @@ export default ({
|
||||
<div
|
||||
className={classNames(
|
||||
{
|
||||
'buyButton dark:buyButtonDark': order.side === Side.SIDE_BUY,
|
||||
'buyButton dark:buyButtonDark':
|
||||
order.side === Schema.Side.SIDE_BUY,
|
||||
'sellButton dark:sellButtonDark':
|
||||
order.side === Side.SIDE_SELL,
|
||||
order.side === Schema.Side.SIDE_SELL,
|
||||
},
|
||||
'px-2 py-1 inline text-ui-small'
|
||||
)}
|
||||
|
@ -2,16 +2,16 @@ import React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { FormGroup } from '@vegaprotocol/ui-toolkit';
|
||||
import { t } from '@vegaprotocol/react-helpers';
|
||||
import { Side } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
|
||||
interface SideSelectorProps {
|
||||
value: Side;
|
||||
onSelect: (side: Side) => void;
|
||||
value: Schema.Side;
|
||||
onSelect: (side: Schema.Side) => void;
|
||||
}
|
||||
|
||||
export const SIDE_NAMES: Record<Side, string> = {
|
||||
[Side.SIDE_BUY]: t('Long'),
|
||||
[Side.SIDE_SELL]: t('Short'),
|
||||
export const SIDE_NAMES: Record<Schema.Side, string> = {
|
||||
[Schema.Side.SIDE_BUY]: t('Long'),
|
||||
[Schema.Side.SIDE_SELL]: t('Short'),
|
||||
};
|
||||
|
||||
export default ({ value, onSelect }: SideSelectorProps) => {
|
||||
@ -31,9 +31,9 @@ export default ({ value, onSelect }: SideSelectorProps) => {
|
||||
className={classNames(
|
||||
'px-8 py-2',
|
||||
'buyButton hover:buyButton dark:buyButtonDark dark:hover:buyButtonDark',
|
||||
{ selected: value === Side.SIDE_BUY }
|
||||
{ selected: value === Schema.Side.SIDE_BUY }
|
||||
)}
|
||||
onClick={() => onSelect(Side.SIDE_BUY)}
|
||||
onClick={() => onSelect(Schema.Side.SIDE_BUY)}
|
||||
>
|
||||
{t('Long')}
|
||||
</button>
|
||||
@ -43,9 +43,9 @@ export default ({ value, onSelect }: SideSelectorProps) => {
|
||||
className={classNames(
|
||||
'px-8 py-2',
|
||||
'sellButton hover:sellButton dark:sellButtonDark dark:hover:sellButtonDark',
|
||||
{ selected: value === Side.SIDE_SELL }
|
||||
{ selected: value === Schema.Side.SIDE_SELL }
|
||||
)}
|
||||
onClick={() => onSelect(Side.SIDE_SELL)}
|
||||
onClick={() => onSelect(Schema.Side.SIDE_SELL)}
|
||||
>
|
||||
{t('Short')}
|
||||
</button>
|
||||
|
@ -12,7 +12,7 @@ import {
|
||||
t,
|
||||
} from '@vegaprotocol/react-helpers';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import { Side } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
|
||||
interface Props {
|
||||
partyId: string;
|
||||
@ -118,13 +118,13 @@ const useColumnDefinitions = ({ partyId }: Props) => {
|
||||
const taker = t('Taker');
|
||||
const maker = t('Maker');
|
||||
if (data?.buyer.id === partyId) {
|
||||
if (value === Side.SIDE_BUY) {
|
||||
if (value === Schema.Side.SIDE_BUY) {
|
||||
return taker;
|
||||
} else {
|
||||
return maker;
|
||||
}
|
||||
} else if (data?.seller.id === partyId) {
|
||||
if (value === Side.SIDE_SELL) {
|
||||
if (value === Schema.Side.SIDE_SELL) {
|
||||
return taker;
|
||||
} else {
|
||||
return maker;
|
||||
|
@ -12,19 +12,16 @@ import {
|
||||
t,
|
||||
} from '@vegaprotocol/react-helpers';
|
||||
import type {
|
||||
Orders_party_ordersConnection_edges_node,
|
||||
OrderFieldsFragment,
|
||||
Order,
|
||||
CancelOrderArgs,
|
||||
} from '@vegaprotocol/orders';
|
||||
import { isOrderActive } from '@vegaprotocol/orders';
|
||||
import {
|
||||
OrderRejectionReasonMapping,
|
||||
OrderStatus,
|
||||
OrderType,
|
||||
OrderStatusMapping,
|
||||
OrderTypeMapping,
|
||||
Side,
|
||||
OrderTimeInForce,
|
||||
Schema,
|
||||
OrderTimeInForceMapping,
|
||||
} from '@vegaprotocol/types';
|
||||
|
||||
@ -60,21 +57,15 @@ const useColumnDefinitions = ({ setEditOrder, orderCancel }: Props) => {
|
||||
cellClass: 'font-mono !flex h-full items-center',
|
||||
width: 80,
|
||||
cellClassRules: {
|
||||
[positiveClassNames]: ({
|
||||
data,
|
||||
}: {
|
||||
data: Orders_party_ordersConnection_edges_node;
|
||||
}) => data?.side === Side.SIDE_BUY,
|
||||
[negativeClassNames]: ({
|
||||
data,
|
||||
}: {
|
||||
data: Orders_party_ordersConnection_edges_node;
|
||||
}) => data?.side === Side.SIDE_SELL,
|
||||
[positiveClassNames]: ({ data }: { data: OrderFieldsFragment }) =>
|
||||
data?.side === Schema.Side.SIDE_BUY,
|
||||
[negativeClassNames]: ({ data }: { data: OrderFieldsFragment }) =>
|
||||
data?.side === Schema.Side.SIDE_SELL,
|
||||
},
|
||||
valueFormatter: ({ value, data }: ValueFormatterParams) => {
|
||||
if (value && data && data.market) {
|
||||
const prefix = data
|
||||
? data.side === Side.SIDE_BUY
|
||||
? data.side === Schema.Side.SIDE_BUY
|
||||
? '+'
|
||||
: '-'
|
||||
: '';
|
||||
@ -92,8 +83,8 @@ const useColumnDefinitions = ({ setEditOrder, orderCancel }: Props) => {
|
||||
valueFormatter: ({
|
||||
value,
|
||||
}: ValueFormatterParams & {
|
||||
value?: Orders_party_ordersConnection_edges_node['type'];
|
||||
}) => OrderTypeMapping[value as OrderType],
|
||||
value?: OrderFieldsFragment['type'];
|
||||
}) => OrderTypeMapping[value as Schema.OrderType],
|
||||
},
|
||||
{
|
||||
colId: 'status',
|
||||
@ -106,7 +97,7 @@ const useColumnDefinitions = ({ setEditOrder, orderCancel }: Props) => {
|
||||
value?: StatusKey;
|
||||
}) => {
|
||||
if (value && data && data.market) {
|
||||
if (value === OrderStatus.STATUS_REJECTED) {
|
||||
if (value === Schema.OrderStatus.STATUS_REJECTED) {
|
||||
return `${OrderStatusMapping[value as StatusKey]}: ${
|
||||
data.rejectionReason &&
|
||||
OrderRejectionReasonMapping[
|
||||
@ -130,7 +121,7 @@ const useColumnDefinitions = ({ setEditOrder, orderCancel }: Props) => {
|
||||
data,
|
||||
value,
|
||||
}: ValueFormatterParams & {
|
||||
value?: Orders_party_ordersConnection_edges_node['remaining'];
|
||||
value?: OrderFieldsFragment['remaining'];
|
||||
}) => {
|
||||
if (value && data && data.market) {
|
||||
const dps = data.market.positionDecimalPlaces;
|
||||
@ -156,13 +147,13 @@ const useColumnDefinitions = ({ setEditOrder, orderCancel }: Props) => {
|
||||
value,
|
||||
data,
|
||||
}: ValueFormatterParams & {
|
||||
value?: Orders_party_ordersConnection_edges_node['price'];
|
||||
value?: OrderFieldsFragment['price'];
|
||||
}) => {
|
||||
if (
|
||||
value === undefined ||
|
||||
!data ||
|
||||
!data.market ||
|
||||
data.type === OrderType.TYPE_MARKET
|
||||
data.type === Schema.OrderType.TYPE_MARKET
|
||||
) {
|
||||
return '-';
|
||||
}
|
||||
@ -181,7 +172,7 @@ const useColumnDefinitions = ({ setEditOrder, orderCancel }: Props) => {
|
||||
}) => {
|
||||
if (value && data?.market) {
|
||||
if (
|
||||
value === OrderTimeInForce.TIME_IN_FORCE_GTT &&
|
||||
value === Schema.OrderTimeInForce.TIME_IN_FORCE_GTT &&
|
||||
data.expiresAt
|
||||
) {
|
||||
const expiry = getDateTimeFormat().format(
|
||||
@ -203,7 +194,7 @@ const useColumnDefinitions = ({ setEditOrder, orderCancel }: Props) => {
|
||||
valueFormatter: ({
|
||||
value,
|
||||
}: ValueFormatterParams & {
|
||||
value?: Orders_party_ordersConnection_edges_node['createdAt'];
|
||||
value?: OrderFieldsFragment['createdAt'];
|
||||
}) => {
|
||||
return value ? getDateTimeFormat().format(new Date(value)) : value;
|
||||
},
|
||||
@ -215,7 +206,7 @@ const useColumnDefinitions = ({ setEditOrder, orderCancel }: Props) => {
|
||||
valueFormatter: ({
|
||||
value,
|
||||
}: ValueFormatterParams & {
|
||||
value?: Orders_party_ordersConnection_edges_node['updatedAt'];
|
||||
value?: OrderFieldsFragment['updatedAt'];
|
||||
}) => {
|
||||
return value ? getDateTimeFormat().format(new Date(value)) : '-';
|
||||
},
|
||||
|
@ -6,7 +6,7 @@ import { MockedProvider } from '@apollo/client/testing';
|
||||
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
||||
import {
|
||||
BusEventType,
|
||||
Schema,
|
||||
ProposalRejectionReason,
|
||||
ProposalState,
|
||||
} from '@vegaprotocol/types';
|
||||
@ -28,7 +28,7 @@ describe('Raw proposal form', () => {
|
||||
busEvents: [
|
||||
{
|
||||
__typename: 'BusEvent',
|
||||
type: BusEventType.Proposal,
|
||||
type: Schema.BusEventType.Proposal,
|
||||
event: {
|
||||
__typename: 'Proposal',
|
||||
id: '2fca514cebf9f465ae31ecb4c5721e3a6f5f260425ded887ca50ba15b81a5d50',
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { OrderRejectionReason, OrderStatus } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import { connectVegaWallet } from '../support/vega-wallet';
|
||||
import {
|
||||
updateOrder,
|
||||
@ -19,7 +19,7 @@ const editOrderBtn = 'edit';
|
||||
describe('orders list', { tags: '@smoke' }, () => {
|
||||
before(() => {
|
||||
const subscriptionMocks = getSubscriptionMocks();
|
||||
cy.spy(subscriptionMocks, 'OrderSub');
|
||||
cy.spy(subscriptionMocks, 'OrdersUpdate');
|
||||
cy.mockTradingPage();
|
||||
cy.mockGQLSubscription(subscriptionMocks);
|
||||
cy.visit('/markets/market-0');
|
||||
@ -27,7 +27,7 @@ describe('orders list', { tags: '@smoke' }, () => {
|
||||
cy.getByTestId('tab-orders').contains('Please connect Vega wallet');
|
||||
connectVegaWallet();
|
||||
cy.wait('@Orders').then(() => {
|
||||
expect(subscriptionMocks.OrderSub).to.be.calledOnce;
|
||||
expect(subscriptionMocks.OrdersUpdate).to.be.calledOnce;
|
||||
});
|
||||
});
|
||||
it('renders orders', () => {
|
||||
@ -124,7 +124,7 @@ describe('orders list', { tags: '@smoke' }, () => {
|
||||
describe('subscribe orders', { tags: '@smoke' }, () => {
|
||||
before(() => {
|
||||
const subscriptionMocks = getSubscriptionMocks();
|
||||
cy.spy(subscriptionMocks, 'OrderSub');
|
||||
cy.spy(subscriptionMocks, 'OrdersUpdate');
|
||||
cy.mockTradingPage();
|
||||
cy.mockGQLSubscription(subscriptionMocks);
|
||||
cy.visit('/markets/market-0');
|
||||
@ -132,7 +132,7 @@ describe('subscribe orders', { tags: '@smoke' }, () => {
|
||||
cy.getByTestId('tab-orders').contains('Please connect Vega wallet');
|
||||
connectVegaWallet();
|
||||
cy.wait('@Orders').then(() => {
|
||||
expect(subscriptionMocks.OrderSub).to.be.calledOnce;
|
||||
expect(subscriptionMocks.OrdersUpdate).to.be.calledOnce;
|
||||
});
|
||||
});
|
||||
const orderId = '1234567890';
|
||||
@ -142,7 +142,7 @@ describe('subscribe orders', { tags: '@smoke' }, () => {
|
||||
// 7002-SORD-041
|
||||
updateOrder({
|
||||
id: orderId,
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
status: Schema.OrderStatus.STATUS_ACTIVE,
|
||||
});
|
||||
cy.get(`[row-id=${orderId}] [col-id=${orderStatus}]`).should(
|
||||
'have.text',
|
||||
@ -154,7 +154,7 @@ describe('subscribe orders', { tags: '@smoke' }, () => {
|
||||
// 7002-SORD-042
|
||||
updateOrder({
|
||||
id: orderId,
|
||||
status: OrderStatus.STATUS_EXPIRED,
|
||||
status: Schema.OrderStatus.STATUS_EXPIRED,
|
||||
});
|
||||
cy.get(`[row-id=${orderId}] [col-id=${orderStatus}]`).should(
|
||||
'have.text',
|
||||
@ -167,7 +167,7 @@ describe('subscribe orders', { tags: '@smoke' }, () => {
|
||||
// NOT COVERED: see the txn that cancelled it and a link to the block explorer, if cancelled by a user transaction.
|
||||
updateOrder({
|
||||
id: orderId,
|
||||
status: OrderStatus.STATUS_CANCELLED,
|
||||
status: Schema.OrderStatus.STATUS_CANCELLED,
|
||||
});
|
||||
cy.get(`[row-id=${orderId}] [col-id=${orderStatus}]`).should(
|
||||
'have.text',
|
||||
@ -180,7 +180,7 @@ describe('subscribe orders', { tags: '@smoke' }, () => {
|
||||
// NOT COVERED: see an explanation of why stopped
|
||||
updateOrder({
|
||||
id: orderId,
|
||||
status: OrderStatus.STATUS_STOPPED,
|
||||
status: Schema.OrderStatus.STATUS_STOPPED,
|
||||
});
|
||||
cy.get(`[row-id=${orderId}] [col-id=${orderStatus}]`).should(
|
||||
'have.text',
|
||||
@ -192,7 +192,7 @@ describe('subscribe orders', { tags: '@smoke' }, () => {
|
||||
// 7002-SORD-045
|
||||
updateOrder({
|
||||
id: orderId,
|
||||
status: OrderStatus.STATUS_PARTIALLY_FILLED,
|
||||
status: Schema.OrderStatus.STATUS_PARTIALLY_FILLED,
|
||||
size: '5',
|
||||
remaining: '1',
|
||||
});
|
||||
@ -211,7 +211,7 @@ describe('subscribe orders', { tags: '@smoke' }, () => {
|
||||
// NOT COVERED: Must be able to see/link to all trades that were created from this order
|
||||
updateOrder({
|
||||
id: orderId,
|
||||
status: OrderStatus.STATUS_FILLED,
|
||||
status: Schema.OrderStatus.STATUS_FILLED,
|
||||
});
|
||||
cy.get(`[row-id=${orderId}] [col-id=${orderStatus}]`).should(
|
||||
'have.text',
|
||||
@ -223,8 +223,8 @@ describe('subscribe orders', { tags: '@smoke' }, () => {
|
||||
// 7002-SORD-047
|
||||
updateOrder({
|
||||
id: orderId,
|
||||
status: OrderStatus.STATUS_REJECTED,
|
||||
rejectionReason: OrderRejectionReason.ORDER_ERROR_INTERNAL_ERROR,
|
||||
status: Schema.OrderStatus.STATUS_REJECTED,
|
||||
rejectionReason: Schema.OrderRejectionReason.ORDER_ERROR_INTERNAL_ERROR,
|
||||
});
|
||||
cy.get(`[row-id=${orderId}] [col-id=${orderStatus}]`).should(
|
||||
'have.text',
|
||||
@ -237,7 +237,7 @@ describe('subscribe orders', { tags: '@smoke' }, () => {
|
||||
// NOT COVERED: must see an explanation of why parked orders happen
|
||||
updateOrder({
|
||||
id: orderId,
|
||||
status: OrderStatus.STATUS_PARKED,
|
||||
status: Schema.OrderStatus.STATUS_PARKED,
|
||||
});
|
||||
cy.get(`[row-id=${orderId}] [col-id=${orderStatus}]`).should(
|
||||
'have.text',
|
||||
|
@ -1,5 +1,5 @@
|
||||
import type { FillsQuery, FillFieldsFragment } from '@vegaprotocol/fills';
|
||||
import { Side } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import merge from 'lodash/merge';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
|
||||
@ -17,7 +17,7 @@ export const generateFills = (
|
||||
seller: {
|
||||
id: Cypress.env('VEGA_PUBLIC_KEY'),
|
||||
},
|
||||
aggressor: Side.SIDE_SELL,
|
||||
aggressor: Schema.Side.SIDE_SELL,
|
||||
buyerFee: {
|
||||
infrastructureFee: '5000',
|
||||
},
|
||||
@ -30,11 +30,11 @@ export const generateFills = (
|
||||
seller: {
|
||||
id: Cypress.env('VEGA_PUBLIC_KEY'),
|
||||
},
|
||||
aggressor: Side.SIDE_BUY,
|
||||
aggressor: Schema.Side.SIDE_BUY,
|
||||
}),
|
||||
generateFill({
|
||||
id: '3',
|
||||
aggressor: Side.SIDE_SELL,
|
||||
aggressor: Schema.Side.SIDE_SELL,
|
||||
market: {
|
||||
id: 'market-2',
|
||||
},
|
||||
@ -80,7 +80,7 @@ export const generateFill = (override?: PartialDeep<FillFieldsFragment>) => {
|
||||
size: '50000',
|
||||
buyOrder: 'buy-order',
|
||||
sellOrder: 'sell-order',
|
||||
aggressor: Side.SIDE_BUY,
|
||||
aggressor: Schema.Side.SIDE_BUY,
|
||||
buyer: {
|
||||
__typename: 'Party',
|
||||
id: 'buyer-id',
|
||||
|
@ -1,18 +1,12 @@
|
||||
import merge from 'lodash/merge';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
import type {
|
||||
Orders,
|
||||
Orders_party_ordersConnection_edges_node,
|
||||
} from '@vegaprotocol/orders';
|
||||
import {
|
||||
OrderStatus,
|
||||
OrderTimeInForce,
|
||||
OrderType,
|
||||
Side,
|
||||
} from '@vegaprotocol/types';
|
||||
import type { OrdersQuery, OrderFieldsFragment } from '@vegaprotocol/orders';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
|
||||
export const generateOrders = (override?: PartialDeep<Orders>): Orders => {
|
||||
const orders: Orders_party_ordersConnection_edges_node[] = [
|
||||
export const generateOrders = (
|
||||
override?: PartialDeep<OrdersQuery>
|
||||
): OrdersQuery => {
|
||||
const orders: OrderFieldsFragment[] = [
|
||||
{
|
||||
__typename: 'Order',
|
||||
id: '066468C06549101DAF7BC51099E1412A0067DC08C246B7D8013C9D0CBF1E8EE7',
|
||||
@ -21,12 +15,12 @@ export const generateOrders = (override?: PartialDeep<Orders>): Orders => {
|
||||
id: 'market-0',
|
||||
},
|
||||
size: '10',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
status: OrderStatus.STATUS_FILLED,
|
||||
side: Side.SIDE_BUY,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status: Schema.OrderStatus.STATUS_FILLED,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
remaining: '0',
|
||||
price: '20000000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
createdAt: new Date(2020, 1, 30).toISOString(),
|
||||
updatedAt: null,
|
||||
expiresAt: null,
|
||||
@ -42,12 +36,12 @@ export const generateOrders = (override?: PartialDeep<Orders>): Orders => {
|
||||
id: 'market-1',
|
||||
},
|
||||
size: '1',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
status: OrderStatus.STATUS_FILLED,
|
||||
side: Side.SIDE_BUY,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status: Schema.OrderStatus.STATUS_FILLED,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
remaining: '0',
|
||||
price: '100',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
createdAt: new Date(2020, 1, 29).toISOString(),
|
||||
updatedAt: null,
|
||||
expiresAt: null,
|
||||
@ -63,12 +57,12 @@ export const generateOrders = (override?: PartialDeep<Orders>): Orders => {
|
||||
id: 'market-2',
|
||||
},
|
||||
size: '1',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
status: OrderStatus.STATUS_FILLED,
|
||||
side: Side.SIDE_BUY,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status: Schema.OrderStatus.STATUS_FILLED,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
remaining: '0',
|
||||
price: '20000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
createdAt: new Date(2020, 1, 28).toISOString(),
|
||||
updatedAt: null,
|
||||
expiresAt: null,
|
||||
@ -84,12 +78,12 @@ export const generateOrders = (override?: PartialDeep<Orders>): Orders => {
|
||||
id: 'market-3',
|
||||
},
|
||||
size: '1',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
side: Side.SIDE_BUY,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status: Schema.OrderStatus.STATUS_ACTIVE,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
remaining: '0',
|
||||
price: '100000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
createdAt: new Date(2020, 1, 27).toISOString(),
|
||||
updatedAt: null,
|
||||
expiresAt: null,
|
||||
@ -105,12 +99,12 @@ export const generateOrders = (override?: PartialDeep<Orders>): Orders => {
|
||||
id: 'market-3',
|
||||
},
|
||||
size: '10',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
status: OrderStatus.STATUS_PARTIALLY_FILLED,
|
||||
side: Side.SIDE_SELL,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status: Schema.OrderStatus.STATUS_PARTIALLY_FILLED,
|
||||
side: Schema.Side.SIDE_SELL,
|
||||
remaining: '3',
|
||||
price: '100000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
createdAt: new Date(2020, 1, 27).toISOString(),
|
||||
updatedAt: null,
|
||||
expiresAt: null,
|
||||
@ -120,7 +114,7 @@ export const generateOrders = (override?: PartialDeep<Orders>): Orders => {
|
||||
},
|
||||
];
|
||||
|
||||
const defaultResult: Orders = {
|
||||
const defaultResult: OrdersQuery = {
|
||||
party: {
|
||||
id: Cypress.env('VEGA_PUBLIC_KEY'),
|
||||
ordersConnection: {
|
||||
|
@ -1,48 +1,50 @@
|
||||
import merge from 'lodash/merge';
|
||||
import type {
|
||||
OrderSub as OrderSubData,
|
||||
OrderSubVariables,
|
||||
OrderSub_orders,
|
||||
OrdersUpdateSubscription,
|
||||
OrdersUpdateSubscriptionVariables,
|
||||
OrderUpdateFieldsFragment,
|
||||
} from '@vegaprotocol/orders';
|
||||
|
||||
import type { onMessage } from '@vegaprotocol/cypress';
|
||||
import {
|
||||
OrderStatus,
|
||||
OrderTimeInForce,
|
||||
OrderType,
|
||||
Side,
|
||||
} from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
let sendOrderUpdate: (data: OrderSubData) => void;
|
||||
const getOnOrderSub = () => {
|
||||
const onOrderSub: onMessage<OrderSubData, OrderSubVariables> = (send) => {
|
||||
let sendOrderUpdate: (data: OrdersUpdateSubscription) => void;
|
||||
const getOnOrderUpdate = () => {
|
||||
const onOrderUpdate: onMessage<
|
||||
OrdersUpdateSubscription,
|
||||
OrdersUpdateSubscriptionVariables
|
||||
> = (send) => {
|
||||
sendOrderUpdate = send;
|
||||
};
|
||||
return onOrderSub;
|
||||
return onOrderUpdate;
|
||||
};
|
||||
|
||||
export const getSubscriptionMocks = () => ({ OrderSub: getOnOrderSub() });
|
||||
export const getSubscriptionMocks = () => ({
|
||||
OrdersUpdate: getOnOrderUpdate(),
|
||||
});
|
||||
|
||||
export function updateOrder(override?: PartialDeep<OrderSub_orders>): void {
|
||||
const order: OrderSub_orders = {
|
||||
export function updateOrder(
|
||||
override?: PartialDeep<OrderUpdateFieldsFragment>
|
||||
): void {
|
||||
const order: OrderUpdateFieldsFragment = {
|
||||
__typename: 'OrderUpdate',
|
||||
id: '1234567890',
|
||||
marketId: 'market-0',
|
||||
size: '10',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
status: OrderStatus.STATUS_FILLED,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status: Schema.OrderStatus.STATUS_FILLED,
|
||||
rejectionReason: null,
|
||||
side: Side.SIDE_BUY,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
remaining: '0',
|
||||
price: '20000000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
createdAt: new Date(2020, 1, 30).toISOString(),
|
||||
updatedAt: null,
|
||||
expiresAt: null,
|
||||
liquidityProvisionId: null,
|
||||
peggedOrder: null,
|
||||
};
|
||||
const update: OrderSubData = {
|
||||
const update: OrdersUpdateSubscription = {
|
||||
orders: [merge(order, override)],
|
||||
};
|
||||
if (!sendOrderUpdate) {
|
||||
|
@ -1,24 +1,24 @@
|
||||
import { toDecimal } from '@vegaprotocol/react-helpers';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { OrderTimeInForce, OrderType, Side } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
|
||||
export const getDefaultOrder = (market: {
|
||||
id: string;
|
||||
positionDecimalPlaces: number;
|
||||
}): OrderSubmissionBody['orderSubmission'] => ({
|
||||
marketId: market.id,
|
||||
type: OrderType.TYPE_MARKET,
|
||||
side: Side.SIDE_BUY,
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_IOC,
|
||||
type: Schema.OrderType.TYPE_MARKET,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_IOC,
|
||||
size: String(toDecimal(market.positionDecimalPlaces)),
|
||||
});
|
||||
|
||||
export interface Order {
|
||||
marketId: string;
|
||||
type: OrderType;
|
||||
type: Schema.OrderType;
|
||||
size: string;
|
||||
side: Side;
|
||||
timeInForce: OrderTimeInForce;
|
||||
side: Schema.Side;
|
||||
timeInForce: Schema.OrderTimeInForce;
|
||||
price?: string;
|
||||
expiresAt?: Date;
|
||||
}
|
||||
|
@ -5,8 +5,7 @@ import {
|
||||
MarketState,
|
||||
MarketStateMapping,
|
||||
MarketTradingMode,
|
||||
OrderTimeInForce,
|
||||
OrderType,
|
||||
Schema,
|
||||
} from '@vegaprotocol/types';
|
||||
import type { ValidationProps } from './use-order-validation';
|
||||
import { marketTranslations } from './use-order-validation';
|
||||
@ -72,8 +71,8 @@ const defaultWalletContext = {
|
||||
const defaultOrder = {
|
||||
market,
|
||||
step: 0.1,
|
||||
orderType: OrderType.TYPE_MARKET,
|
||||
orderTimeInForce: OrderTimeInForce.TIME_IN_FORCE_FOK,
|
||||
orderType: Schema.OrderType.TYPE_MARKET,
|
||||
orderTimeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_FOK,
|
||||
};
|
||||
|
||||
const ERROR = {
|
||||
@ -167,7 +166,7 @@ describe('useOrderValidation', () => {
|
||||
({ tradingMode, errorMessage }) => {
|
||||
const { result } = setup({
|
||||
market: { ...defaultOrder.market, tradingMode },
|
||||
orderType: OrderType.TYPE_MARKET,
|
||||
orderType: Schema.OrderType.TYPE_MARKET,
|
||||
});
|
||||
expect(result.current.isDisabled).toBeTruthy();
|
||||
expect(result.current.message).toBe(errorMessage);
|
||||
@ -175,22 +174,22 @@ describe('useOrderValidation', () => {
|
||||
);
|
||||
|
||||
it.each`
|
||||
tradingMode | orderTimeInForce | errorMessage
|
||||
${MarketTradingMode.TRADING_MODE_BATCH_AUCTION} | ${OrderTimeInForce.TIME_IN_FORCE_FOK} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
${MarketTradingMode.TRADING_MODE_MONITORING_AUCTION} | ${OrderTimeInForce.TIME_IN_FORCE_FOK} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
${MarketTradingMode.TRADING_MODE_OPENING_AUCTION} | ${OrderTimeInForce.TIME_IN_FORCE_FOK} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
${MarketTradingMode.TRADING_MODE_BATCH_AUCTION} | ${OrderTimeInForce.TIME_IN_FORCE_IOC} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
${MarketTradingMode.TRADING_MODE_MONITORING_AUCTION} | ${OrderTimeInForce.TIME_IN_FORCE_IOC} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
${MarketTradingMode.TRADING_MODE_OPENING_AUCTION} | ${OrderTimeInForce.TIME_IN_FORCE_IOC} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
${MarketTradingMode.TRADING_MODE_BATCH_AUCTION} | ${OrderTimeInForce.TIME_IN_FORCE_GFN} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
${MarketTradingMode.TRADING_MODE_MONITORING_AUCTION} | ${OrderTimeInForce.TIME_IN_FORCE_GFN} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
${MarketTradingMode.TRADING_MODE_OPENING_AUCTION} | ${OrderTimeInForce.TIME_IN_FORCE_GFN} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
tradingMode | orderTimeInForce | errorMessage
|
||||
${MarketTradingMode.TRADING_MODE_BATCH_AUCTION} | ${Schema.OrderTimeInForce.TIME_IN_FORCE_FOK} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
${MarketTradingMode.TRADING_MODE_MONITORING_AUCTION} | ${Schema.OrderTimeInForce.TIME_IN_FORCE_FOK} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
${MarketTradingMode.TRADING_MODE_OPENING_AUCTION} | ${Schema.OrderTimeInForce.TIME_IN_FORCE_FOK} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
${MarketTradingMode.TRADING_MODE_BATCH_AUCTION} | ${Schema.OrderTimeInForce.TIME_IN_FORCE_IOC} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
${MarketTradingMode.TRADING_MODE_MONITORING_AUCTION} | ${Schema.OrderTimeInForce.TIME_IN_FORCE_IOC} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
${MarketTradingMode.TRADING_MODE_OPENING_AUCTION} | ${Schema.OrderTimeInForce.TIME_IN_FORCE_IOC} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
${MarketTradingMode.TRADING_MODE_BATCH_AUCTION} | ${Schema.OrderTimeInForce.TIME_IN_FORCE_GFN} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
${MarketTradingMode.TRADING_MODE_MONITORING_AUCTION} | ${Schema.OrderTimeInForce.TIME_IN_FORCE_GFN} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
${MarketTradingMode.TRADING_MODE_OPENING_AUCTION} | ${Schema.OrderTimeInForce.TIME_IN_FORCE_GFN} | ${ERROR.MARKET_CONTINUOUS_TIF}
|
||||
`(
|
||||
`Returns an error message when submitting a limit order with a "$orderTimeInForce" value to a "$tradingMode" market`,
|
||||
({ tradingMode, orderTimeInForce, errorMessage }) => {
|
||||
const { result } = setup({
|
||||
market: { ...defaultOrder.market, tradingMode },
|
||||
orderType: OrderType.TYPE_LIMIT,
|
||||
orderType: Schema.OrderType.TYPE_LIMIT,
|
||||
orderTimeInForce,
|
||||
});
|
||||
expect(result.current).toStrictEqual({
|
||||
@ -211,7 +210,7 @@ describe('useOrderValidation', () => {
|
||||
({ fieldName, errorType, errorMessage }) => {
|
||||
const { result } = setup({
|
||||
fieldErrors: { [fieldName]: { type: errorType } },
|
||||
orderType: OrderType.TYPE_LIMIT,
|
||||
orderType: Schema.OrderType.TYPE_LIMIT,
|
||||
});
|
||||
expect(result.current).toStrictEqual({
|
||||
isDisabled: true,
|
||||
|
@ -7,8 +7,7 @@ import {
|
||||
MarketState,
|
||||
MarketStateMapping,
|
||||
MarketTradingMode,
|
||||
OrderTimeInForce,
|
||||
OrderType,
|
||||
Schema,
|
||||
} from '@vegaprotocol/types';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { Tooltip } from '@vegaprotocol/ui-toolkit';
|
||||
@ -28,8 +27,8 @@ export const isMarketInAuction = (market: DealTicketMarketFragment) => {
|
||||
export type ValidationProps = {
|
||||
step?: number;
|
||||
market: DealTicketMarketFragment;
|
||||
orderType: OrderType;
|
||||
orderTimeInForce: OrderTimeInForce;
|
||||
orderType: Schema.OrderType;
|
||||
orderTimeInForce: Schema.OrderTimeInForce;
|
||||
fieldErrors?: FieldErrors<OrderSubmissionBody['orderSubmission']>;
|
||||
};
|
||||
|
||||
@ -94,7 +93,7 @@ export const useOrderValidation = ({
|
||||
}
|
||||
|
||||
if (isMarketInAuction(market)) {
|
||||
if (orderType === OrderType.TYPE_MARKET) {
|
||||
if (orderType === Schema.OrderType.TYPE_MARKET) {
|
||||
if (
|
||||
market.tradingMode ===
|
||||
MarketTradingMode.TRADING_MODE_MONITORING_AUCTION &&
|
||||
@ -149,11 +148,11 @@ export const useOrderValidation = ({
|
||||
};
|
||||
}
|
||||
if (
|
||||
orderType === OrderType.TYPE_LIMIT &&
|
||||
orderType === Schema.OrderType.TYPE_LIMIT &&
|
||||
[
|
||||
OrderTimeInForce.TIME_IN_FORCE_FOK,
|
||||
OrderTimeInForce.TIME_IN_FORCE_IOC,
|
||||
OrderTimeInForce.TIME_IN_FORCE_GFN,
|
||||
Schema.OrderTimeInForce.TIME_IN_FORCE_FOK,
|
||||
Schema.OrderTimeInForce.TIME_IN_FORCE_IOC,
|
||||
Schema.OrderTimeInForce.TIME_IN_FORCE_GFN,
|
||||
].includes(orderTimeInForce)
|
||||
) {
|
||||
if (
|
||||
@ -231,7 +230,7 @@ export const useOrderValidation = ({
|
||||
|
||||
if (
|
||||
fieldErrors?.price?.type === 'required' &&
|
||||
orderType !== OrderType.TYPE_MARKET
|
||||
orderType !== Schema.OrderType.TYPE_MARKET
|
||||
) {
|
||||
return {
|
||||
isDisabled: true,
|
||||
@ -241,7 +240,7 @@ export const useOrderValidation = ({
|
||||
|
||||
if (
|
||||
fieldErrors?.price?.type === 'min' &&
|
||||
orderType !== OrderType.TYPE_MARKET
|
||||
orderType !== Schema.OrderType.TYPE_MARKET
|
||||
) {
|
||||
return {
|
||||
isDisabled: true,
|
||||
|
@ -10,7 +10,7 @@ import type { DealTicketMarketFragment } from './__generated___/DealTicket';
|
||||
import { ExpirySelector } from './expiry-selector';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
||||
import { OrderTimeInForce, OrderType } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import { getDefaultOrder } from '../deal-ticket-validation';
|
||||
import {
|
||||
isMarketInAuction,
|
||||
@ -69,7 +69,7 @@ export const DealTicket = ({
|
||||
order.price && removeDecimal(order.price, market.decimalPlaces),
|
||||
size: removeDecimal(order.size, market.positionDecimalPlaces),
|
||||
expiresAt:
|
||||
order.timeInForce === OrderTimeInForce.TIME_IN_FORCE_GTT
|
||||
order.timeInForce === Schema.OrderTimeInForce.TIME_IN_FORCE_GTT
|
||||
? order.expiresAt
|
||||
: undefined,
|
||||
});
|
||||
@ -96,7 +96,7 @@ export const DealTicket = ({
|
||||
const marketPriceFormatted =
|
||||
marketPrice && addDecimal(marketPrice, market.decimalPlaces);
|
||||
useEffect(() => {
|
||||
if (marketPriceFormatted && order.type === OrderType.TYPE_MARKET) {
|
||||
if (marketPriceFormatted && order.type === Schema.OrderType.TYPE_MARKET) {
|
||||
setValue('price', marketPriceFormatted);
|
||||
}
|
||||
}, [marketPriceFormatted, order.type, setValue]);
|
||||
@ -138,8 +138,8 @@ export const DealTicket = ({
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
{order.type === OrderType.TYPE_LIMIT &&
|
||||
order.timeInForce === OrderTimeInForce.TIME_IN_FORCE_GTT && (
|
||||
{order.type === Schema.OrderType.TYPE_LIMIT &&
|
||||
order.timeInForce === Schema.OrderTimeInForce.TIME_IN_FORCE_GTT && (
|
||||
<Controller
|
||||
name="expiresAt"
|
||||
control={control}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { Side } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { useCalculateSlippage } from './use-calculate-slippage';
|
||||
|
||||
@ -82,7 +82,7 @@ describe('useCalculateSlippage Hook', () => {
|
||||
marketId: 'marketId',
|
||||
order: {
|
||||
size: '10',
|
||||
side: Side.SIDE_BUY,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
} as OrderSubmissionBody['orderSubmission'],
|
||||
}),
|
||||
{
|
||||
@ -99,7 +99,7 @@ describe('useCalculateSlippage Hook', () => {
|
||||
marketId: 'marketId',
|
||||
order: {
|
||||
size: '10',
|
||||
side: Side.SIDE_SELL,
|
||||
side: Schema.Side.SIDE_SELL,
|
||||
} as OrderSubmissionBody['orderSubmission'],
|
||||
}),
|
||||
{
|
||||
@ -125,7 +125,7 @@ describe('useCalculateSlippage Hook', () => {
|
||||
marketId: 'marketId',
|
||||
order: {
|
||||
size: '10',
|
||||
side: Side.SIDE_SELL,
|
||||
side: Schema.Side.SIDE_SELL,
|
||||
} as OrderSubmissionBody['orderSubmission'],
|
||||
}),
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useMemo } from 'react';
|
||||
import { Side } from '@vegaprotocol/types';
|
||||
import { marketDepthProvider } from '@vegaprotocol/market-depth';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import { marketProvider } from '@vegaprotocol/market-list';
|
||||
import type { SingleMarketFieldsFragment } from '@vegaprotocol/market-list';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
@ -32,7 +32,7 @@ export const useCalculateSlippage = ({ marketId, order }: Props) => {
|
||||
variables,
|
||||
});
|
||||
const volPriceArr =
|
||||
data?.depth[order.side === Side.SIDE_BUY ? 'sell' : 'buy'] || [];
|
||||
data?.depth[order.side === Schema.Side.SIDE_BUY ? 'sell' : 'buy'] || [];
|
||||
if (volPriceArr.length && market) {
|
||||
const decimals = market.decimalPlaces ?? 0;
|
||||
const positionDecimals = market.positionDecimalPlaces ?? 0;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { FeesBreakdown } from '@vegaprotocol/market-info';
|
||||
import { formatNumber, t } from '@vegaprotocol/react-helpers';
|
||||
import { Side } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import BigNumber from 'bignumber.js';
|
||||
@ -29,7 +29,7 @@ export const useFeeDealTicketDetails = (
|
||||
const estPrice = order.price || market.depth.lastTrade?.price;
|
||||
if (estPrice) {
|
||||
if (slippage && parseFloat(slippage) !== 0) {
|
||||
const isLong = order.side === Side.SIDE_BUY;
|
||||
const isLong = order.side === Schema.Side.SIDE_BUY;
|
||||
const multiplier = new BigNumber(1)[isLong ? 'plus' : 'minus'](
|
||||
parseFloat(slippage) / 100
|
||||
);
|
||||
|
@ -1,10 +1,5 @@
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import {
|
||||
AccountType,
|
||||
OrderTimeInForce,
|
||||
OrderType,
|
||||
Side,
|
||||
} from '@vegaprotocol/types';
|
||||
import { AccountType, Schema } from '@vegaprotocol/types';
|
||||
import type { PositionMargin } from './use-market-positions';
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
import { useMaximumPositionSize } from './use-maximum-position-size';
|
||||
@ -32,10 +27,10 @@ const mockAccount: Account = {
|
||||
};
|
||||
|
||||
const mockOrder: OrderSubmissionBody['orderSubmission'] = {
|
||||
type: OrderType.TYPE_MARKET,
|
||||
type: Schema.OrderType.TYPE_MARKET,
|
||||
size: '1',
|
||||
side: Side.SIDE_BUY,
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_IOC,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_IOC,
|
||||
marketId: 'market-id',
|
||||
};
|
||||
|
||||
@ -92,7 +87,7 @@ describe('useMaximumPositionSize', () => {
|
||||
|
||||
it('should return correct size when open positions and opposite side', () => {
|
||||
const price = '50';
|
||||
mockOrder.side = Side.SIDE_SELL;
|
||||
mockOrder.side = Schema.Side.SIDE_SELL;
|
||||
mockMarketPositions = defaultMockMarketPositions;
|
||||
const expected = 4001;
|
||||
const { result } = renderHook(() =>
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useMarketPositions } from './use-market-positions';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { useSettlementAccount } from './use-settlement-account';
|
||||
import { AccountType, Side } from '@vegaprotocol/types';
|
||||
import { AccountType, Schema } from '@vegaprotocol/types';
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
import type { AccountFragment as Account } from './__generated__/PartyBalance';
|
||||
|
||||
@ -47,8 +47,10 @@ export const useMaximumPositionSize = ({
|
||||
}
|
||||
|
||||
const isSameSide =
|
||||
(marketPositions.openVolume.isPositive() && order.side === Side.SIDE_BUY) ||
|
||||
(marketPositions.openVolume.isNegative() && order.side === Side.SIDE_SELL);
|
||||
(marketPositions.openVolume.isPositive() &&
|
||||
order.side === Schema.Side.SIDE_BUY) ||
|
||||
(marketPositions.openVolume.isNegative() &&
|
||||
order.side === Schema.Side.SIDE_SELL);
|
||||
|
||||
const adjustedForVolume = new BigNumber(size)[isSameSide ? 'minus' : 'plus'](
|
||||
marketPositions.openVolume
|
||||
|
@ -5,7 +5,7 @@ import { addDecimal, formatNumber } from '@vegaprotocol/react-helpers';
|
||||
import { useMarketPositions } from './use-market-positions';
|
||||
import { useMarketDataMarkPrice } from './use-market-data-mark-price';
|
||||
import { usePartyMarketDataQuery } from './__generated__/PartyMarketData';
|
||||
import { Side } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import type { DealTicketMarketFragment } from '../components/deal-ticket/__generated___/DealTicket';
|
||||
import type { PartyBalanceQuery } from './__generated__/PartyBalance';
|
||||
import { useSettlementAccount } from './use-settlement-account';
|
||||
@ -63,7 +63,7 @@ export const useOrderCloseOut = ({
|
||||
marketPositions?.openVolume.toString() || '0',
|
||||
market.positionDecimalPlaces
|
||||
)
|
||||
)[order.side === Side.SIDE_BUY ? 'plus' : 'minus'](order.size);
|
||||
)[order.side === Schema.Side.SIDE_BUY ? 'plus' : 'minus'](order.size);
|
||||
const markPrice = new BigNumber(
|
||||
addDecimal(
|
||||
markPriceData?.market?.data?.markPrice || 0,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { Side } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import { addDecimal, removeDecimal } from '@vegaprotocol/react-helpers';
|
||||
import { useMarketPositions } from './use-market-positions';
|
||||
import { useMarketDataMarkPrice } from './use-market-data-mark-price';
|
||||
@ -48,12 +48,15 @@ export const useOrderMargin = ({
|
||||
BigNumber.maximum(
|
||||
0,
|
||||
new BigNumber(marketPositions?.openVolume || 0)
|
||||
[order.side === Side.SIDE_BUY ? 'plus' : 'minus'](order.size)
|
||||
[order.side === Schema.Side.SIDE_BUY ? 'plus' : 'minus'](order.size)
|
||||
.absoluteValue()
|
||||
).toString(),
|
||||
market.positionDecimalPlaces
|
||||
),
|
||||
side: order.side === Side.SIDE_BUY ? Side.SIDE_BUY : Side.SIDE_SELL,
|
||||
side:
|
||||
order.side === Schema.Side.SIDE_BUY
|
||||
? Schema.Side.SIDE_BUY
|
||||
: Schema.Side.SIDE_SELL,
|
||||
timeInForce: order.timeInForce,
|
||||
type: order.type,
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { act, render, screen, waitFor } from '@testing-library/react';
|
||||
import { getDateTimeFormat } from '@vegaprotocol/react-helpers';
|
||||
import { Side } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
import type { Trade } from './fills-data-provider';
|
||||
|
||||
@ -74,7 +74,7 @@ describe('FillsTable', () => {
|
||||
buyer: {
|
||||
id: partyId,
|
||||
},
|
||||
aggressor: Side.SIDE_SELL,
|
||||
aggressor: Schema.Side.SIDE_SELL,
|
||||
buyerFee: {
|
||||
makerFee: '2',
|
||||
infrastructureFee: '2',
|
||||
@ -111,7 +111,7 @@ describe('FillsTable', () => {
|
||||
seller: {
|
||||
id: partyId,
|
||||
},
|
||||
aggressor: Side.SIDE_SELL,
|
||||
aggressor: Schema.Side.SIDE_SELL,
|
||||
sellerFee: {
|
||||
makerFee: '1',
|
||||
infrastructureFee: '1',
|
||||
@ -147,7 +147,7 @@ describe('FillsTable', () => {
|
||||
seller: {
|
||||
id: partyId,
|
||||
},
|
||||
aggressor: Side.SIDE_SELL,
|
||||
aggressor: Schema.Side.SIDE_SELL,
|
||||
});
|
||||
|
||||
const { rerender } = render(
|
||||
@ -166,7 +166,7 @@ describe('FillsTable', () => {
|
||||
seller: {
|
||||
id: partyId,
|
||||
},
|
||||
aggressor: Side.SIDE_BUY,
|
||||
aggressor: Schema.Side.SIDE_BUY,
|
||||
});
|
||||
|
||||
rerender(<FillsTable partyId={partyId} rowData={[makerFill]} />);
|
||||
|
@ -9,7 +9,7 @@ import {
|
||||
t,
|
||||
isNumeric,
|
||||
} from '@vegaprotocol/react-helpers';
|
||||
import { Side } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import { AgGridColumn } from 'ag-grid-react';
|
||||
import type { VegaValueFormatterParams } from '@vegaprotocol/ui-toolkit';
|
||||
import { AgGridDynamic as AgGrid } from '@vegaprotocol/ui-toolkit';
|
||||
@ -165,13 +165,13 @@ const formatRole = (partyId: string) => {
|
||||
const taker = t('Taker');
|
||||
const maker = t('Maker');
|
||||
if (data?.buyer.id === partyId) {
|
||||
if (value === Side.SIDE_BUY) {
|
||||
if (value === Schema.Side.SIDE_BUY) {
|
||||
return taker;
|
||||
} else {
|
||||
return maker;
|
||||
}
|
||||
} else if (data?.seller.id === partyId) {
|
||||
if (value === Side.SIDE_SELL) {
|
||||
if (value === Schema.Side.SIDE_SELL) {
|
||||
return taker;
|
||||
} else {
|
||||
return maker;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import merge from 'lodash/merge';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
import { MarketState, MarketTradingMode, Side } from '@vegaprotocol/types';
|
||||
import { MarketState, MarketTradingMode, Schema } from '@vegaprotocol/types';
|
||||
import type { Trade } from './fills-data-provider';
|
||||
|
||||
export const generateFill = (override?: PartialDeep<Trade>) => {
|
||||
@ -12,7 +12,7 @@ export const generateFill = (override?: PartialDeep<Trade>) => {
|
||||
size: '50000',
|
||||
buyOrder: 'buy-order',
|
||||
sellOrder: 'sell-order',
|
||||
aggressor: Side.SIDE_BUY,
|
||||
aggressor: Schema.Side.SIDE_BUY,
|
||||
buyer: {
|
||||
__typename: 'Party',
|
||||
id: 'buyer-id',
|
||||
|
@ -1,12 +1,5 @@
|
||||
import merge from 'lodash/merge';
|
||||
import {
|
||||
MarketState,
|
||||
MarketTradingMode,
|
||||
OrderStatus,
|
||||
OrderTimeInForce,
|
||||
OrderType,
|
||||
Side,
|
||||
} from '@vegaprotocol/types';
|
||||
import { MarketState, MarketTradingMode, Schema } from '@vegaprotocol/types';
|
||||
import type { Order } from '../';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
|
||||
@ -59,12 +52,12 @@ export const generateOrder = (partialOrder?: PartialDeep<Order>) => {
|
||||
tradingMode: MarketTradingMode.TRADING_MODE_CONTINUOUS,
|
||||
},
|
||||
size: '10',
|
||||
type: OrderType.TYPE_MARKET,
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
side: Side.SIDE_BUY,
|
||||
type: Schema.OrderType.TYPE_MARKET,
|
||||
status: Schema.OrderStatus.STATUS_ACTIVE,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
remaining: '5',
|
||||
price: '',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_IOC,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_IOC,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: null,
|
||||
expiresAt: null,
|
||||
@ -77,17 +70,17 @@ export const generateOrder = (partialOrder?: PartialDeep<Order>) => {
|
||||
|
||||
export const limitOrder = generateOrder({
|
||||
id: 'limit-order',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTT,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status: Schema.OrderStatus.STATUS_ACTIVE,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTT,
|
||||
createdAt: new Date(2022, 3, 3).toISOString(),
|
||||
expiresAt: new Date(2022, 3, 5).toISOString(),
|
||||
});
|
||||
|
||||
export const marketOrder = generateOrder({
|
||||
id: 'market-order',
|
||||
type: OrderType.TYPE_MARKET,
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
type: Schema.OrderType.TYPE_MARKET,
|
||||
status: Schema.OrderStatus.STATUS_ACTIVE,
|
||||
});
|
||||
|
||||
export const generateMockOrders = (): Order[] => {
|
||||
@ -99,12 +92,12 @@ export const generateMockOrders = (): Order[] => {
|
||||
id: 'c9f5acd348796011c075077e4d58d9b7f1689b7c1c8e030a5e886b83aa96923d',
|
||||
},
|
||||
size: '10',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
status: OrderStatus.STATUS_FILLED,
|
||||
side: Side.SIDE_BUY,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status: Schema.OrderStatus.STATUS_FILLED,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
remaining: '0',
|
||||
price: '20000000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
createdAt: new Date(2020, 1, 1).toISOString(),
|
||||
}),
|
||||
generateOrder({
|
||||
@ -114,12 +107,12 @@ export const generateMockOrders = (): Order[] => {
|
||||
id: '5a4b0b9e9c0629f0315ec56fcb7bd444b0c6e4da5ec7677719d502626658a376',
|
||||
},
|
||||
size: '1',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
status: OrderStatus.STATUS_FILLED,
|
||||
side: Side.SIDE_BUY,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status: Schema.OrderStatus.STATUS_FILLED,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
remaining: '0',
|
||||
price: '100',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
createdAt: new Date().toISOString(),
|
||||
}),
|
||||
generateOrder({
|
||||
@ -129,12 +122,12 @@ export const generateMockOrders = (): Order[] => {
|
||||
id: 'c6f4337b31ed57a961969c3ba10297b369d01b9e75a4cbb96db4fc62886444e6',
|
||||
},
|
||||
size: '1',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
status: OrderStatus.STATUS_FILLED,
|
||||
side: Side.SIDE_BUY,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status: Schema.OrderStatus.STATUS_FILLED,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
remaining: '0',
|
||||
price: '20000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
createdAt: new Date(2022, 5, 10).toISOString(),
|
||||
}),
|
||||
];
|
||||
|
@ -1,89 +0,0 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @generated
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
import { OrderType, Side, OrderStatus, OrderRejectionReason, OrderTimeInForce } from "@vegaprotocol/types";
|
||||
|
||||
// ====================================================
|
||||
// GraphQL subscription operation: OrderSub
|
||||
// ====================================================
|
||||
|
||||
export interface OrderSub_orders_peggedOrder {
|
||||
__typename: "PeggedOrder";
|
||||
}
|
||||
|
||||
export interface OrderSub_orders {
|
||||
__typename: "OrderUpdate";
|
||||
/**
|
||||
* Hash of the order data
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* The market the order is trading on (probably stored internally as a hash of the market details)
|
||||
*/
|
||||
marketId: string;
|
||||
/**
|
||||
* The order type
|
||||
*/
|
||||
type: OrderType | null;
|
||||
/**
|
||||
* Whether the order is to buy or sell
|
||||
*/
|
||||
side: Side;
|
||||
/**
|
||||
* Total number of units that may be bought or sold (immutable) (uint64)
|
||||
*/
|
||||
size: string;
|
||||
/**
|
||||
* The status of an order, for example 'Active'
|
||||
*/
|
||||
status: OrderStatus;
|
||||
/**
|
||||
* Why the order was rejected
|
||||
*/
|
||||
rejectionReason: OrderRejectionReason | null;
|
||||
/**
|
||||
* The worst price the order will trade at (e.g. buy for price or less, sell for price or more) (uint64)
|
||||
*/
|
||||
price: string;
|
||||
/**
|
||||
* The timeInForce of order (determines how and if it executes, and whether it persists on the book)
|
||||
*/
|
||||
timeInForce: OrderTimeInForce;
|
||||
/**
|
||||
* Number of units remaining of the total that have not yet been bought or sold (uint64)
|
||||
*/
|
||||
remaining: string;
|
||||
/**
|
||||
* Expiration time of this order (ISO-8601 RFC3339+Nano formatted date)
|
||||
*/
|
||||
expiresAt: string | null;
|
||||
/**
|
||||
* RFC3339Nano formatted date and time for when the order was created (timestamp)
|
||||
*/
|
||||
createdAt: string;
|
||||
/**
|
||||
* RFC3339Nano time the order was altered
|
||||
*/
|
||||
updatedAt: string | null;
|
||||
/**
|
||||
* The liquidity provision this order was created from
|
||||
*/
|
||||
liquidityProvisionId: string | null;
|
||||
/**
|
||||
* PeggedOrder contains the details about a pegged order
|
||||
*/
|
||||
peggedOrder: OrderSub_orders_peggedOrder | null;
|
||||
}
|
||||
|
||||
export interface OrderSub {
|
||||
/**
|
||||
* Subscribe to orders updates
|
||||
*/
|
||||
orders: OrderSub_orders[] | null;
|
||||
}
|
||||
|
||||
export interface OrderSubVariables {
|
||||
partyId: string;
|
||||
}
|
@ -1,158 +0,0 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @generated
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
import { Pagination, OrderType, Side, OrderStatus, OrderRejectionReason, OrderTimeInForce } from "@vegaprotocol/types";
|
||||
|
||||
// ====================================================
|
||||
// GraphQL query operation: Orders
|
||||
// ====================================================
|
||||
|
||||
export interface Orders_party_ordersConnection_edges_node_market {
|
||||
__typename: "Market";
|
||||
/**
|
||||
* Market ID
|
||||
*/
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface Orders_party_ordersConnection_edges_node_liquidityProvision {
|
||||
__typename: "LiquidityProvision";
|
||||
}
|
||||
|
||||
export interface Orders_party_ordersConnection_edges_node_peggedOrder {
|
||||
__typename: "PeggedOrder";
|
||||
}
|
||||
|
||||
export interface Orders_party_ordersConnection_edges_node {
|
||||
__typename: "Order";
|
||||
/**
|
||||
* Hash of the order data
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* The market the order is trading on (probably stored internally as a hash of the market details)
|
||||
*/
|
||||
market: Orders_party_ordersConnection_edges_node_market;
|
||||
/**
|
||||
* The order type
|
||||
*/
|
||||
type: OrderType | null;
|
||||
/**
|
||||
* Whether the order is to buy or sell
|
||||
*/
|
||||
side: Side;
|
||||
/**
|
||||
* Total number of units that may be bought or sold (immutable) (uint64)
|
||||
*/
|
||||
size: string;
|
||||
/**
|
||||
* The status of an order, for example 'Active'
|
||||
*/
|
||||
status: OrderStatus;
|
||||
/**
|
||||
* Why the order was rejected
|
||||
*/
|
||||
rejectionReason: OrderRejectionReason | null;
|
||||
/**
|
||||
* The worst price the order will trade at (e.g. buy for price or less, sell for price or more) (uint64)
|
||||
*/
|
||||
price: string;
|
||||
/**
|
||||
* The timeInForce of order (determines how and if it executes, and whether it persists on the book)
|
||||
*/
|
||||
timeInForce: OrderTimeInForce;
|
||||
/**
|
||||
* Number of units remaining of the total that have not yet been bought or sold (uint64)
|
||||
*/
|
||||
remaining: string;
|
||||
/**
|
||||
* Expiration time of this order (ISO-8601 RFC3339+Nano formatted date)
|
||||
*/
|
||||
expiresAt: string | null;
|
||||
/**
|
||||
* RFC3339Nano formatted date and time for when the order was created (timestamp)
|
||||
*/
|
||||
createdAt: string;
|
||||
/**
|
||||
* RFC3339Nano time the order was altered
|
||||
*/
|
||||
updatedAt: string | null;
|
||||
/**
|
||||
* The liquidity provision this order was created from
|
||||
*/
|
||||
liquidityProvision: Orders_party_ordersConnection_edges_node_liquidityProvision | null;
|
||||
/**
|
||||
* PeggedOrder contains the details about a pegged order
|
||||
*/
|
||||
peggedOrder: Orders_party_ordersConnection_edges_node_peggedOrder | null;
|
||||
}
|
||||
|
||||
export interface Orders_party_ordersConnection_edges {
|
||||
__typename: "OrderEdge";
|
||||
/**
|
||||
* The order
|
||||
*/
|
||||
node: Orders_party_ordersConnection_edges_node;
|
||||
/**
|
||||
* The cursor for this order
|
||||
*/
|
||||
cursor: string | null;
|
||||
}
|
||||
|
||||
export interface Orders_party_ordersConnection_pageInfo {
|
||||
__typename: "PageInfo";
|
||||
/**
|
||||
* The first cursor in the current page
|
||||
*/
|
||||
startCursor: string;
|
||||
/**
|
||||
* The last cursor in the current page
|
||||
*/
|
||||
endCursor: string;
|
||||
/**
|
||||
* The connection has more pages to fetch when traversing forward through the connection
|
||||
*/
|
||||
hasNextPage: boolean;
|
||||
/**
|
||||
* The connection has more pages to fetch when traversing backward through the connection
|
||||
*/
|
||||
hasPreviousPage: boolean;
|
||||
}
|
||||
|
||||
export interface Orders_party_ordersConnection {
|
||||
__typename: "OrderConnection";
|
||||
/**
|
||||
* The orders in this connection
|
||||
*/
|
||||
edges: Orders_party_ordersConnection_edges[] | null;
|
||||
/**
|
||||
* The pagination information
|
||||
*/
|
||||
pageInfo: Orders_party_ordersConnection_pageInfo | null;
|
||||
}
|
||||
|
||||
export interface Orders_party {
|
||||
__typename: "Party";
|
||||
/**
|
||||
* Party identifier
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* Orders relating to a party
|
||||
*/
|
||||
ordersConnection: Orders_party_ordersConnection | null;
|
||||
}
|
||||
|
||||
export interface Orders {
|
||||
/**
|
||||
* An entity that is trading on the Vega network
|
||||
*/
|
||||
party: Orders_party | null;
|
||||
}
|
||||
|
||||
export interface OrdersVariables {
|
||||
partyId: string;
|
||||
pagination?: Pagination | null;
|
||||
}
|
@ -0,0 +1,150 @@
|
||||
import { Schema as Types } from '@vegaprotocol/types';
|
||||
|
||||
import { gql } from '@apollo/client';
|
||||
import * as Apollo from '@apollo/client';
|
||||
const defaultOptions = {} as const;
|
||||
export type OrderFieldsFragment = { __typename?: 'Order', id: string, type?: Types.OrderType | null, side: Types.Side, size: string, status: Types.OrderStatus, rejectionReason?: Types.OrderRejectionReason | null, price: string, timeInForce: Types.OrderTimeInForce, remaining: string, expiresAt?: string | null, createdAt: string, updatedAt?: string | null, market: { __typename?: 'Market', id: string }, liquidityProvision?: { __typename: 'LiquidityProvision' } | null, peggedOrder?: { __typename: 'PeggedOrder' } | null };
|
||||
|
||||
export type OrdersQueryVariables = Types.Exact<{
|
||||
partyId: Types.Scalars['ID'];
|
||||
pagination?: Types.InputMaybe<Types.Pagination>;
|
||||
}>;
|
||||
|
||||
|
||||
export type OrdersQuery = { __typename?: 'Query', party?: { __typename?: 'Party', id: string, ordersConnection?: { __typename?: 'OrderConnection', edges?: Array<{ __typename?: 'OrderEdge', cursor?: string | null, node: { __typename?: 'Order', id: string, type?: Types.OrderType | null, side: Types.Side, size: string, status: Types.OrderStatus, rejectionReason?: Types.OrderRejectionReason | null, price: string, timeInForce: Types.OrderTimeInForce, remaining: string, expiresAt?: string | null, createdAt: string, updatedAt?: string | null, market: { __typename?: 'Market', id: string }, liquidityProvision?: { __typename: 'LiquidityProvision' } | null, peggedOrder?: { __typename: 'PeggedOrder' } | null } }> | null, pageInfo?: { __typename?: 'PageInfo', startCursor: string, endCursor: string, hasNextPage: boolean, hasPreviousPage: boolean } | null } | null } | null };
|
||||
|
||||
export type OrderUpdateFieldsFragment = { __typename?: 'OrderUpdate', id: string, marketId: string, type?: Types.OrderType | null, side: Types.Side, size: string, status: Types.OrderStatus, rejectionReason?: Types.OrderRejectionReason | null, price: string, timeInForce: Types.OrderTimeInForce, remaining: string, expiresAt?: string | null, createdAt: string, updatedAt?: string | null, liquidityProvisionId?: string | null, peggedOrder?: { __typename: 'PeggedOrder' } | null };
|
||||
|
||||
export type OrdersUpdateSubscriptionVariables = Types.Exact<{
|
||||
partyId: Types.Scalars['ID'];
|
||||
}>;
|
||||
|
||||
|
||||
export type OrdersUpdateSubscription = { __typename?: 'Subscription', orders?: Array<{ __typename?: 'OrderUpdate', id: string, marketId: string, type?: Types.OrderType | null, side: Types.Side, size: string, status: Types.OrderStatus, rejectionReason?: Types.OrderRejectionReason | null, price: string, timeInForce: Types.OrderTimeInForce, remaining: string, expiresAt?: string | null, createdAt: string, updatedAt?: string | null, liquidityProvisionId?: string | null, peggedOrder?: { __typename: 'PeggedOrder' } | null }> | null };
|
||||
|
||||
export const OrderFieldsFragmentDoc = gql`
|
||||
fragment OrderFields on Order {
|
||||
id
|
||||
market {
|
||||
id
|
||||
}
|
||||
type
|
||||
side
|
||||
size
|
||||
status
|
||||
rejectionReason
|
||||
price
|
||||
timeInForce
|
||||
remaining
|
||||
expiresAt
|
||||
createdAt
|
||||
updatedAt
|
||||
liquidityProvision {
|
||||
__typename
|
||||
}
|
||||
peggedOrder {
|
||||
__typename
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const OrderUpdateFieldsFragmentDoc = gql`
|
||||
fragment OrderUpdateFields on OrderUpdate {
|
||||
id
|
||||
marketId
|
||||
type
|
||||
side
|
||||
size
|
||||
status
|
||||
rejectionReason
|
||||
price
|
||||
timeInForce
|
||||
remaining
|
||||
expiresAt
|
||||
createdAt
|
||||
updatedAt
|
||||
liquidityProvisionId
|
||||
peggedOrder {
|
||||
__typename
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const OrdersDocument = gql`
|
||||
query Orders($partyId: ID!, $pagination: Pagination) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
ordersConnection(pagination: $pagination) {
|
||||
edges {
|
||||
node {
|
||||
...OrderFields
|
||||
}
|
||||
cursor
|
||||
}
|
||||
pageInfo {
|
||||
startCursor
|
||||
endCursor
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
${OrderFieldsFragmentDoc}`;
|
||||
|
||||
/**
|
||||
* __useOrdersQuery__
|
||||
*
|
||||
* To run a query within a React component, call `useOrdersQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useOrdersQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useOrdersQuery({
|
||||
* variables: {
|
||||
* partyId: // value for 'partyId'
|
||||
* pagination: // value for 'pagination'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useOrdersQuery(baseOptions: Apollo.QueryHookOptions<OrdersQuery, OrdersQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useQuery<OrdersQuery, OrdersQueryVariables>(OrdersDocument, options);
|
||||
}
|
||||
export function useOrdersLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<OrdersQuery, OrdersQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useLazyQuery<OrdersQuery, OrdersQueryVariables>(OrdersDocument, options);
|
||||
}
|
||||
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(partyId: $partyId) {
|
||||
...OrderUpdateFields
|
||||
}
|
||||
}
|
||||
${OrderUpdateFieldsFragmentDoc}`;
|
||||
|
||||
/**
|
||||
* __useOrdersUpdateSubscription__
|
||||
*
|
||||
* To run a query within a React component, call `useOrdersUpdateSubscription` and pass it any options that fit your needs.
|
||||
* When your component renders, `useOrdersUpdateSubscription` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the subscription, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useOrdersUpdateSubscription({
|
||||
* variables: {
|
||||
* partyId: // value for 'partyId'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useOrdersUpdateSubscription(baseOptions: Apollo.SubscriptionHookOptions<OrdersUpdateSubscription, OrdersUpdateSubscriptionVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useSubscription<OrdersUpdateSubscription, OrdersUpdateSubscriptionVariables>(OrdersUpdateDocument, options);
|
||||
}
|
||||
export type OrdersUpdateSubscriptionHookResult = ReturnType<typeof useOrdersUpdateSubscription>;
|
||||
export type OrdersUpdateSubscriptionResult = Apollo.SubscriptionResult<OrdersUpdateSubscription>;
|
@ -1,3 +1,2 @@
|
||||
export * from './__generated__/OrderSub';
|
||||
export * from './__generated__/Orders';
|
||||
export * from './__generated___/orders';
|
||||
export * from './order-data-provider';
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { update } from './order-data-provider';
|
||||
import type { OrderSub_orders, Orders_party_ordersConnection_edges } from '../';
|
||||
import type { OrderUpdateFieldsFragment, OrderFieldsFragment } from '../';
|
||||
import type { Edge } from '@vegaprotocol/react-helpers';
|
||||
describe('order data provider', () => {
|
||||
it('puts incoming data in proper place', () => {
|
||||
const data = [
|
||||
@ -16,7 +17,7 @@ describe('order data provider', () => {
|
||||
createdAt: new Date('2022-01-30').toISOString(),
|
||||
},
|
||||
},
|
||||
] as Orders_party_ordersConnection_edges[];
|
||||
] as Edge<OrderFieldsFragment>[];
|
||||
|
||||
const delta = [
|
||||
// this one should be dropped because id don't exits and it's older than newest
|
||||
@ -46,16 +47,20 @@ describe('order data provider', () => {
|
||||
updatedAt: new Date('2022-02-03').toISOString(),
|
||||
createdAt: new Date('2022-01-29').toISOString(),
|
||||
},
|
||||
] as OrderSub_orders[];
|
||||
] as OrderUpdateFieldsFragment[];
|
||||
|
||||
const updatedData = update(data, delta);
|
||||
expect(
|
||||
updatedData.findIndex((edge) => edge.node.id === delta[0].id)
|
||||
updatedData?.findIndex((edge) => edge.node.id === delta[0].id)
|
||||
).toEqual(-1);
|
||||
expect(updatedData[2].node.id).toEqual(delta[2].id);
|
||||
expect(updatedData[2].node.updatedAt).toEqual(delta[2].updatedAt);
|
||||
expect(updatedData[0].node.id).toEqual(delta[3].id);
|
||||
expect(updatedData[1].node.id).toEqual(delta[4].id);
|
||||
expect(updatedData[1].node.updatedAt).toEqual(delta[4].updatedAt);
|
||||
expect(updatedData && updatedData[2].node.id).toEqual(delta[2].id);
|
||||
expect(updatedData && updatedData[2].node.updatedAt).toEqual(
|
||||
delta[2].updatedAt
|
||||
);
|
||||
expect(updatedData && updatedData[0].node.id).toEqual(delta[3].id);
|
||||
expect(updatedData && updatedData[1].node.id).toEqual(delta[4].id);
|
||||
expect(updatedData && updatedData[1].node.updatedAt).toEqual(
|
||||
delta[4].updatedAt
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -1,5 +1,4 @@
|
||||
import produce from 'immer';
|
||||
import { gql } from '@apollo/client';
|
||||
import orderBy from 'lodash/orderBy';
|
||||
import uniqBy from 'lodash/uniqBy';
|
||||
import {
|
||||
@ -13,84 +12,33 @@ import type { Market } from '@vegaprotocol/market-list';
|
||||
import { marketsProvider } from '@vegaprotocol/market-list';
|
||||
import type { PageInfo, Edge } from '@vegaprotocol/react-helpers';
|
||||
import type {
|
||||
Orders,
|
||||
Orders_party_ordersConnection_edges,
|
||||
Orders_party_ordersConnection_edges_node,
|
||||
Orders_party_ordersConnection_edges_node_liquidityProvision,
|
||||
OrderSub,
|
||||
OrderSub_orders,
|
||||
} from '../';
|
||||
OrderFieldsFragment,
|
||||
OrdersQuery,
|
||||
OrdersUpdateSubscription,
|
||||
} from './__generated___/orders';
|
||||
import { OrdersDocument, OrdersUpdateDocument } from './__generated___/orders';
|
||||
|
||||
export const ORDERS_QUERY = gql`
|
||||
query Orders($partyId: ID!, $pagination: Pagination) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
ordersConnection(pagination: $pagination) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
market {
|
||||
id
|
||||
}
|
||||
type
|
||||
side
|
||||
size
|
||||
status
|
||||
rejectionReason
|
||||
price
|
||||
timeInForce
|
||||
remaining
|
||||
expiresAt
|
||||
createdAt
|
||||
updatedAt
|
||||
liquidityProvision {
|
||||
__typename
|
||||
}
|
||||
peggedOrder {
|
||||
__typename
|
||||
}
|
||||
}
|
||||
cursor
|
||||
}
|
||||
pageInfo {
|
||||
startCursor
|
||||
endCursor
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
export type Order = Omit<OrderFieldsFragment, 'market'> & {
|
||||
market?: Market;
|
||||
};
|
||||
export type OrderEdge = Edge<Order>;
|
||||
|
||||
export const ORDERS_SUB = gql`
|
||||
subscription OrderSub($partyId: ID!) {
|
||||
orders(partyId: $partyId) {
|
||||
id
|
||||
marketId
|
||||
type
|
||||
side
|
||||
size
|
||||
status
|
||||
rejectionReason
|
||||
price
|
||||
timeInForce
|
||||
remaining
|
||||
expiresAt
|
||||
createdAt
|
||||
updatedAt
|
||||
liquidityProvisionId
|
||||
peggedOrder {
|
||||
__typename
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
const getData = (responseData: OrdersQuery) =>
|
||||
responseData?.party?.ordersConnection?.edges || null;
|
||||
|
||||
const getDelta = (subscriptionData: OrdersUpdateSubscription) =>
|
||||
subscriptionData.orders || [];
|
||||
|
||||
const getPageInfo = (responseData: OrdersQuery): PageInfo | null =>
|
||||
responseData.party?.ordersConnection?.pageInfo || null;
|
||||
|
||||
export const update = (
|
||||
data: Orders_party_ordersConnection_edges[],
|
||||
delta: OrderSub_orders[]
|
||||
data: ReturnType<typeof getData>,
|
||||
delta: ReturnType<typeof getDelta>
|
||||
) => {
|
||||
if (!data) {
|
||||
return data;
|
||||
}
|
||||
return produce(data, (draft) => {
|
||||
// A single update can contain the same order with multiple updates, so we need to find
|
||||
// the latest version of the order and only update using that
|
||||
@ -114,12 +62,13 @@ export const update = (
|
||||
const { marketId, liquidityProvisionId, ...order } = node;
|
||||
|
||||
// If there is a liquidity provision id add the object to the resulting order
|
||||
const liquidityProvision: Orders_party_ordersConnection_edges_node_liquidityProvision | null =
|
||||
liquidityProvisionId
|
||||
? {
|
||||
__typename: 'LiquidityProvision',
|
||||
}
|
||||
: null;
|
||||
const liquidityProvision:
|
||||
| OrderFieldsFragment['liquidityProvision']
|
||||
| null = liquidityProvisionId
|
||||
? {
|
||||
__typename: 'LiquidityProvision',
|
||||
}
|
||||
: null;
|
||||
|
||||
draft.unshift({
|
||||
node: {
|
||||
@ -139,24 +88,9 @@ export const update = (
|
||||
});
|
||||
};
|
||||
|
||||
export type Order = Omit<Orders_party_ordersConnection_edges_node, 'market'> & {
|
||||
market?: Market;
|
||||
};
|
||||
export type OrderEdge = Edge<Order>;
|
||||
|
||||
const getData = (
|
||||
responseData: Orders
|
||||
): Orders_party_ordersConnection_edges[] | null =>
|
||||
responseData?.party?.ordersConnection?.edges || null;
|
||||
|
||||
const getDelta = (subscriptionData: OrderSub) => subscriptionData.orders || [];
|
||||
|
||||
const getPageInfo = (responseData: Orders): PageInfo | null =>
|
||||
responseData.party?.ordersConnection?.pageInfo || null;
|
||||
|
||||
export const ordersProvider = makeDataProvider({
|
||||
query: ORDERS_QUERY,
|
||||
subscriptionQuery: ORDERS_SUB,
|
||||
query: OrdersDocument,
|
||||
subscriptionQuery: OrdersUpdateDocument,
|
||||
update,
|
||||
getData,
|
||||
getDelta,
|
||||
@ -173,7 +107,7 @@ export const ordersWithMarketProvider = makeDerivedDataProvider<
|
||||
>(
|
||||
[ordersProvider, marketsProvider],
|
||||
(partsData): OrderEdge[] =>
|
||||
((partsData[0] as Parameters<typeof update>['0']) || []).map((edge) => ({
|
||||
((partsData[0] as ReturnType<typeof getData>) || []).map((edge) => ({
|
||||
cursor: edge.cursor,
|
||||
node: {
|
||||
...edge.node,
|
||||
|
@ -0,0 +1,69 @@
|
||||
fragment OrderFields on Order {
|
||||
id
|
||||
market {
|
||||
id
|
||||
}
|
||||
type
|
||||
side
|
||||
size
|
||||
status
|
||||
rejectionReason
|
||||
price
|
||||
timeInForce
|
||||
remaining
|
||||
expiresAt
|
||||
createdAt
|
||||
updatedAt
|
||||
liquidityProvision {
|
||||
__typename
|
||||
}
|
||||
peggedOrder {
|
||||
__typename
|
||||
}
|
||||
}
|
||||
|
||||
query Orders($partyId: ID!, $pagination: Pagination) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
ordersConnection(pagination: $pagination) {
|
||||
edges {
|
||||
node {
|
||||
...OrderFields
|
||||
}
|
||||
cursor
|
||||
}
|
||||
pageInfo {
|
||||
startCursor
|
||||
endCursor
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment OrderUpdateFields on OrderUpdate {
|
||||
id
|
||||
marketId
|
||||
type
|
||||
side
|
||||
size
|
||||
status
|
||||
rejectionReason
|
||||
price
|
||||
timeInForce
|
||||
remaining
|
||||
expiresAt
|
||||
createdAt
|
||||
updatedAt
|
||||
liquidityProvisionId
|
||||
peggedOrder {
|
||||
__typename
|
||||
}
|
||||
}
|
||||
|
||||
subscription OrdersUpdate($partyId: ID!) {
|
||||
orders(partyId: $partyId) {
|
||||
...OrderUpdateFields
|
||||
}
|
||||
}
|
@ -1,14 +1,11 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import {
|
||||
OrderRejectionReason,
|
||||
OrderRejectionReasonMapping,
|
||||
OrderStatus,
|
||||
OrderStatusMapping,
|
||||
OrderType,
|
||||
Side,
|
||||
Schema,
|
||||
} from '@vegaprotocol/types';
|
||||
import { VegaTxStatus } from '@vegaprotocol/wallet';
|
||||
import type { OrderEvent_busEvents_event_Order } from '../../order-hooks';
|
||||
import type { OrderEventFieldsFragment } from '../../order-hooks';
|
||||
import { generateOrder } from '../mocks/generate-orders';
|
||||
import type { OrderFeedbackProps } from './order-feedback';
|
||||
import { OrderFeedback } from './order-feedback';
|
||||
@ -42,12 +39,10 @@ describe('OrderFeedback', () => {
|
||||
|
||||
it('renders error reason', () => {
|
||||
const orderFields = {
|
||||
status: OrderStatus.STATUS_REJECTED,
|
||||
rejectionReason: OrderRejectionReason.ORDER_ERROR_AMEND_FAILURE,
|
||||
status: Schema.OrderStatus.STATUS_REJECTED,
|
||||
rejectionReason: Schema.OrderRejectionReason.ORDER_ERROR_AMEND_FAILURE,
|
||||
};
|
||||
const order = generateOrder(
|
||||
orderFields
|
||||
) as OrderEvent_busEvents_event_Order;
|
||||
const order = generateOrder(orderFields) as OrderEventFieldsFragment;
|
||||
render(<OrderFeedback {...props} order={order} />);
|
||||
expect(screen.getByTestId('error-reason')).toHaveTextContent(
|
||||
`${OrderRejectionReasonMapping[orderFields.rejectionReason]}`
|
||||
@ -56,15 +51,15 @@ describe('OrderFeedback', () => {
|
||||
|
||||
it('should render order details when order is placed successfully', () => {
|
||||
const order = generateOrder({
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
price: '100',
|
||||
size: '200',
|
||||
side: Side.SIDE_BUY,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
market: {
|
||||
decimalPlaces: 2,
|
||||
positionDecimalPlaces: 0,
|
||||
},
|
||||
}) as OrderEvent_busEvents_event_Order;
|
||||
}) as OrderEventFieldsFragment;
|
||||
render(<OrderFeedback {...props} order={order} />);
|
||||
expect(screen.getByTestId('order-confirmed')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('tx-block-explorer')).toHaveTextContent(
|
||||
|
@ -1,19 +1,18 @@
|
||||
import { useEnvironment } from '@vegaprotocol/environment';
|
||||
import type { OrderEvent_busEvents_event_Order } from '../../order-hooks/__generated__/OrderEvent';
|
||||
import type { OrderEventFieldsFragment } from '../../order-hooks/__generated___/OrderEvent';
|
||||
import { addDecimalsFormatNumber, Size, t } from '@vegaprotocol/react-helpers';
|
||||
import {
|
||||
OrderRejectionReasonMapping,
|
||||
OrderStatus,
|
||||
OrderStatusMapping,
|
||||
OrderTimeInForceMapping,
|
||||
OrderType,
|
||||
Schema,
|
||||
} from '@vegaprotocol/types';
|
||||
import type { VegaTxState } from '@vegaprotocol/wallet';
|
||||
import { Link } from '@vegaprotocol/ui-toolkit';
|
||||
|
||||
export interface OrderFeedbackProps {
|
||||
transaction: VegaTxState;
|
||||
order: OrderEvent_busEvents_event_Order | null;
|
||||
order: OrderEventFieldsFragment | null;
|
||||
}
|
||||
|
||||
export const OrderFeedback = ({ transaction, order }: OrderFeedbackProps) => {
|
||||
@ -36,7 +35,7 @@ export const OrderFeedback = ({ transaction, order }: OrderFeedbackProps) => {
|
||||
<p className={labelClass}>{t(`Status`)}</p>
|
||||
<p>{t(`${OrderStatusMapping[order.status]}`)}</p>
|
||||
</div>
|
||||
{order.type === OrderType.TYPE_LIMIT && order.market && (
|
||||
{order.type === Schema.OrderType.TYPE_LIMIT && order.market && (
|
||||
<div>
|
||||
<p className={labelClass}>{t(`Price`)}</p>
|
||||
<p>
|
||||
@ -82,21 +81,18 @@ export const OrderFeedback = ({ transaction, order }: OrderFeedbackProps) => {
|
||||
);
|
||||
};
|
||||
|
||||
const getRejectionReason = (
|
||||
order: OrderEvent_busEvents_event_Order
|
||||
): string | null => {
|
||||
const getRejectionReason = (order: OrderEventFieldsFragment): string | null => {
|
||||
switch (order.status) {
|
||||
case OrderStatus.STATUS_STOPPED:
|
||||
case Schema.OrderStatus.STATUS_STOPPED:
|
||||
return t(
|
||||
`Your ${
|
||||
OrderTimeInForceMapping[order.timeInForce]
|
||||
} order was not filled and it has been stopped`
|
||||
);
|
||||
case OrderStatus.STATUS_REJECTED:
|
||||
return (
|
||||
order.rejectionReason &&
|
||||
t(OrderRejectionReasonMapping[order.rejectionReason])
|
||||
);
|
||||
case Schema.OrderStatus.STATUS_REJECTED:
|
||||
return order.rejectionReason
|
||||
? t(OrderRejectionReasonMapping[order.rejectionReason])
|
||||
: null;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { OrderListManager } from './order-list-manager';
|
||||
import * as useDataProviderHook from '@vegaprotocol/react-helpers';
|
||||
import type { Orders_party_ordersConnection_edges_node } from '../';
|
||||
import type { OrderFieldsFragment } from '../';
|
||||
import * as orderListMock from '../order-list/order-list';
|
||||
import { forwardRef } from 'react';
|
||||
|
||||
@ -41,7 +41,7 @@ it('Renders the order list if orders provided', async () => {
|
||||
// avoid warnings about padding refs
|
||||
orderListMock.OrderList = forwardRef(() => <div>OrderList</div>);
|
||||
jest.spyOn(useDataProviderHook, 'useDataProvider').mockReturnValue({
|
||||
data: [{ id: '1' } as Orders_party_ordersConnection_edges_node],
|
||||
data: [{ id: '1' } as OrderFieldsFragment],
|
||||
loading: false,
|
||||
error: undefined,
|
||||
flush: jest.fn(),
|
||||
|
@ -2,14 +2,15 @@ import type { AgGridReact } from 'ag-grid-react';
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
import { renderHook, waitFor } from '@testing-library/react';
|
||||
import { useOrderListData } from './use-order-list-data';
|
||||
import type { Orders_party_ordersConnection_edges } from '../order-data-provider/__generated__/Orders';
|
||||
import type { Edge } from '@vegaprotocol/react-helpers';
|
||||
import type { OrderFieldsFragment } from '../order-data-provider/__generated___/orders';
|
||||
import type { IGetRowsParams } from 'ag-grid-community';
|
||||
|
||||
const loadMock = jest.fn();
|
||||
|
||||
let mockData = null;
|
||||
let mockDataProviderData = {
|
||||
data: mockData as (Orders_party_ordersConnection_edges | null)[] | null,
|
||||
data: mockData as (Edge<OrderFieldsFragment> | null)[] | null,
|
||||
error: undefined,
|
||||
loading: true,
|
||||
load: loadMock,
|
||||
@ -67,13 +68,13 @@ describe('useOrderListData Hook', () => {
|
||||
id: 'data_id_1',
|
||||
createdAt: 1,
|
||||
},
|
||||
} as unknown as Orders_party_ordersConnection_edges,
|
||||
} as unknown as Edge<OrderFieldsFragment>,
|
||||
{
|
||||
node: {
|
||||
id: 'data_id_2',
|
||||
createdAt: 2,
|
||||
},
|
||||
} as unknown as Orders_party_ordersConnection_edges,
|
||||
} as unknown as Edge<OrderFieldsFragment>,
|
||||
];
|
||||
mockDataProviderData = {
|
||||
...mockDataProviderData,
|
||||
@ -106,13 +107,13 @@ describe('useOrderListData Hook', () => {
|
||||
id: 'data_id_1',
|
||||
createdAt: 1,
|
||||
},
|
||||
} as unknown as Orders_party_ordersConnection_edges,
|
||||
} as unknown as Edge<OrderFieldsFragment>,
|
||||
{
|
||||
node: {
|
||||
id: 'data_id_2',
|
||||
createdAt: 2,
|
||||
},
|
||||
} as unknown as Orders_party_ordersConnection_edges,
|
||||
} as unknown as Edge<OrderFieldsFragment>,
|
||||
];
|
||||
Object.assign(mockDataProviderData, {
|
||||
data: mockData,
|
||||
@ -124,13 +125,13 @@ describe('useOrderListData Hook', () => {
|
||||
id: 'data_id_3',
|
||||
createdAt: 3,
|
||||
},
|
||||
} as unknown as Orders_party_ordersConnection_edges,
|
||||
} as unknown as Edge<OrderFieldsFragment>,
|
||||
{
|
||||
node: {
|
||||
id: 'data_id_4',
|
||||
createdAt: 4,
|
||||
},
|
||||
} as unknown as Orders_party_ordersConnection_edges,
|
||||
} as unknown as Edge<OrderFieldsFragment>,
|
||||
];
|
||||
const mockNextData = [...mockData, ...mockDelta];
|
||||
const { result } = renderHook(
|
||||
|
@ -5,7 +5,7 @@ import {
|
||||
Size,
|
||||
getDateTimeFormat,
|
||||
} from '@vegaprotocol/react-helpers';
|
||||
import { OrderType } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import {
|
||||
FormGroup,
|
||||
Input,
|
||||
@ -14,7 +14,6 @@ import {
|
||||
Dialog,
|
||||
Icon,
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import { OrderTimeInForce } from '@vegaprotocol/types';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import type { Order } from '../order-data-provider';
|
||||
|
||||
@ -65,7 +64,7 @@ export const OrderEditDialog = ({
|
||||
<p>{t(`${order.market.tradableInstrument.instrument.name}`)}</p>
|
||||
</div>
|
||||
)}
|
||||
{order.type === OrderType.TYPE_LIMIT && order.market && (
|
||||
{order.type === Schema.OrderType.TYPE_LIMIT && order.market && (
|
||||
<div>
|
||||
<p className={headerClassName}>{t(`Current price`)}</p>
|
||||
<p>
|
||||
@ -86,7 +85,7 @@ export const OrderEditDialog = ({
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{order.timeInForce === OrderTimeInForce.TIME_IN_FORCE_GTT &&
|
||||
{order.timeInForce === Schema.OrderTimeInForce.TIME_IN_FORCE_GTT &&
|
||||
order.expiresAt && (
|
||||
<div>
|
||||
<p className={headerClassName}>{t(`Expires at`)}</p>
|
||||
|
@ -1,16 +1,12 @@
|
||||
import { act, render, screen, within } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { getDateTimeFormat } from '@vegaprotocol/react-helpers';
|
||||
import { OrderTimeInForce, OrderType } from '@vegaprotocol/types';
|
||||
import {
|
||||
OrderRejectionReasonMapping,
|
||||
OrderTimeInForceMapping,
|
||||
} from '@vegaprotocol/types';
|
||||
import {
|
||||
OrderStatus,
|
||||
OrderRejectionReason,
|
||||
OrderTypeMapping,
|
||||
OrderStatusMapping,
|
||||
Schema,
|
||||
} from '@vegaprotocol/types';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
||||
@ -82,7 +78,7 @@ describe('OrderListTable', () => {
|
||||
const expectedValues: string[] = [
|
||||
marketOrder.market?.tradableInstrument.instrument.code || '',
|
||||
'+0.10',
|
||||
OrderTypeMapping[marketOrder.type as OrderType] || '',
|
||||
OrderTypeMapping[marketOrder.type as Schema.OrderType] || '',
|
||||
OrderStatusMapping[marketOrder.status],
|
||||
'5',
|
||||
'-',
|
||||
@ -105,7 +101,7 @@ describe('OrderListTable', () => {
|
||||
const expectedValues: string[] = [
|
||||
limitOrder.market?.tradableInstrument.instrument.code || '',
|
||||
'+0.10',
|
||||
OrderTypeMapping[limitOrder.type || OrderType.TYPE_LIMIT],
|
||||
OrderTypeMapping[limitOrder.type || Schema.OrderType.TYPE_LIMIT],
|
||||
OrderStatusMapping[limitOrder.status],
|
||||
'5',
|
||||
'-',
|
||||
@ -124,9 +120,9 @@ describe('OrderListTable', () => {
|
||||
it('should apply correct formatting for a rejected order', async () => {
|
||||
const rejectedOrder = {
|
||||
...marketOrder,
|
||||
status: OrderStatus.STATUS_REJECTED,
|
||||
status: Schema.OrderStatus.STATUS_REJECTED,
|
||||
rejectionReason:
|
||||
OrderRejectionReason.ORDER_ERROR_INSUFFICIENT_ASSET_BALANCE,
|
||||
Schema.OrderRejectionReason.ORDER_ERROR_INSUFFICIENT_ASSET_BALANCE,
|
||||
};
|
||||
await act(async () => {
|
||||
render(generateJsx({ rowData: [rejectedOrder] }));
|
||||
@ -144,8 +140,8 @@ describe('OrderListTable', () => {
|
||||
const mockEdit = jest.fn();
|
||||
const mockCancel = jest.fn();
|
||||
const order = generateOrder({
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
liquidityProvision: null,
|
||||
peggedOrder: null,
|
||||
});
|
||||
@ -168,8 +164,8 @@ describe('OrderListTable', () => {
|
||||
|
||||
it('shows if an order is a liquidity provision order and does not show order actions', async () => {
|
||||
const order = generateOrder({
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
liquidityProvision: { __typename: 'LiquidityProvision' },
|
||||
});
|
||||
|
||||
@ -185,8 +181,8 @@ describe('OrderListTable', () => {
|
||||
|
||||
it('shows if an order is a pegged order and does not show order actions', async () => {
|
||||
const order = generateOrder({
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
peggedOrder: {
|
||||
__typename: 'PeggedOrder',
|
||||
},
|
||||
@ -202,32 +198,32 @@ describe('OrderListTable', () => {
|
||||
expect(amendCell.queryAllByRole('button')).toHaveLength(0);
|
||||
});
|
||||
|
||||
it.each([OrderStatus.STATUS_ACTIVE, OrderStatus.STATUS_PARKED])(
|
||||
'shows buttons for %s orders',
|
||||
async (status) => {
|
||||
const order = generateOrder({
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
status,
|
||||
});
|
||||
it.each([
|
||||
Schema.OrderStatus.STATUS_ACTIVE,
|
||||
Schema.OrderStatus.STATUS_PARKED,
|
||||
])('shows buttons for %s orders', async (status) => {
|
||||
const order = generateOrder({
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status,
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
render(generateJsx({ rowData: [order] }));
|
||||
});
|
||||
await act(async () => {
|
||||
render(generateJsx({ rowData: [order] }));
|
||||
});
|
||||
|
||||
const amendCell = getAmendCell();
|
||||
expect(amendCell.getAllByRole('button')).toHaveLength(2);
|
||||
}
|
||||
);
|
||||
const amendCell = getAmendCell();
|
||||
expect(amendCell.getAllByRole('button')).toHaveLength(2);
|
||||
});
|
||||
|
||||
it.each([
|
||||
OrderStatus.STATUS_CANCELLED,
|
||||
OrderStatus.STATUS_EXPIRED,
|
||||
OrderStatus.STATUS_FILLED,
|
||||
OrderStatus.STATUS_REJECTED,
|
||||
OrderStatus.STATUS_STOPPED,
|
||||
Schema.OrderStatus.STATUS_CANCELLED,
|
||||
Schema.OrderStatus.STATUS_EXPIRED,
|
||||
Schema.OrderStatus.STATUS_FILLED,
|
||||
Schema.OrderStatus.STATUS_REJECTED,
|
||||
Schema.OrderStatus.STATUS_STOPPED,
|
||||
])('does not show buttons for %s orders', async (status) => {
|
||||
const order = generateOrder({
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
status,
|
||||
});
|
||||
|
||||
|
@ -8,13 +8,10 @@ import {
|
||||
} from '@vegaprotocol/react-helpers';
|
||||
import {
|
||||
OrderRejectionReasonMapping,
|
||||
OrderStatus,
|
||||
OrderStatusMapping,
|
||||
OrderTimeInForce,
|
||||
OrderTimeInForceMapping,
|
||||
OrderType,
|
||||
OrderTypeMapping,
|
||||
Side,
|
||||
Schema,
|
||||
} from '@vegaprotocol/types';
|
||||
import {
|
||||
AgGridDynamic as AgGrid,
|
||||
@ -143,9 +140,9 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||
type="rightAligned"
|
||||
cellClassRules={{
|
||||
[positiveClassNames]: ({ data }: { data: Order }) =>
|
||||
data?.side === Side.SIDE_BUY,
|
||||
data?.side === Schema.Side.SIDE_BUY,
|
||||
[negativeClassNames]: ({ data }: { data: Order }) =>
|
||||
data?.side === Side.SIDE_SELL,
|
||||
data?.side === Schema.Side.SIDE_SELL,
|
||||
}}
|
||||
valueFormatter={({
|
||||
value,
|
||||
@ -155,7 +152,7 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||
return '-';
|
||||
}
|
||||
const prefix = data
|
||||
? data.side === Side.SIDE_BUY
|
||||
? data.side === Schema.Side.SIDE_BUY
|
||||
? '+'
|
||||
: '-'
|
||||
: '';
|
||||
@ -182,7 +179,7 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||
value,
|
||||
data,
|
||||
}: VegaValueFormatterParams<Order, 'status'>) => {
|
||||
if (value === OrderStatus.STATUS_REJECTED) {
|
||||
if (value === Schema.OrderStatus.STATUS_REJECTED) {
|
||||
return `${OrderStatusMapping[value]}: ${
|
||||
data?.rejectionReason &&
|
||||
OrderRejectionReasonMapping[data.rejectionReason]
|
||||
@ -223,7 +220,7 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||
}: VegaValueFormatterParams<Order, 'price'>) => {
|
||||
if (
|
||||
!data?.market ||
|
||||
data.type === OrderType.TYPE_MARKET ||
|
||||
data.type === Schema.OrderType.TYPE_MARKET ||
|
||||
!isNumeric(value)
|
||||
) {
|
||||
return '-';
|
||||
@ -238,7 +235,7 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||
data,
|
||||
}: VegaValueFormatterParams<Order, 'timeInForce'>) => {
|
||||
if (
|
||||
value === OrderTimeInForce.TIME_IN_FORCE_GTT &&
|
||||
value === Schema.OrderTimeInForce.TIME_IN_FORCE_GTT &&
|
||||
data?.expiresAt
|
||||
) {
|
||||
const expiry = getDateTimeFormat().format(
|
||||
@ -303,14 +300,14 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||
/**
|
||||
* Check if an order is active to determine if it can be edited or cancelled
|
||||
*/
|
||||
export const isOrderActive = (status: OrderStatus) => {
|
||||
export const isOrderActive = (status: Schema.OrderStatus) => {
|
||||
return ![
|
||||
OrderStatus.STATUS_CANCELLED,
|
||||
OrderStatus.STATUS_REJECTED,
|
||||
OrderStatus.STATUS_EXPIRED,
|
||||
OrderStatus.STATUS_FILLED,
|
||||
OrderStatus.STATUS_STOPPED,
|
||||
OrderStatus.STATUS_PARTIALLY_FILLED,
|
||||
Schema.OrderStatus.STATUS_CANCELLED,
|
||||
Schema.OrderStatus.STATUS_REJECTED,
|
||||
Schema.OrderStatus.STATUS_EXPIRED,
|
||||
Schema.OrderStatus.STATUS_FILLED,
|
||||
Schema.OrderStatus.STATUS_STOPPED,
|
||||
Schema.OrderStatus.STATUS_PARTIALLY_FILLED,
|
||||
].includes(status);
|
||||
};
|
||||
|
||||
@ -327,28 +324,28 @@ export const isOrderAmendable = (order: Order | undefined) => {
|
||||
};
|
||||
|
||||
export const getEditDialogTitle = (
|
||||
status?: OrderStatus
|
||||
status?: Schema.OrderStatus
|
||||
): string | undefined => {
|
||||
if (!status) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case OrderStatus.STATUS_ACTIVE:
|
||||
case Schema.OrderStatus.STATUS_ACTIVE:
|
||||
return t('Order updated');
|
||||
case OrderStatus.STATUS_FILLED:
|
||||
case Schema.OrderStatus.STATUS_FILLED:
|
||||
return t('Order filled');
|
||||
case OrderStatus.STATUS_PARTIALLY_FILLED:
|
||||
case Schema.OrderStatus.STATUS_PARTIALLY_FILLED:
|
||||
return t('Order partially filled');
|
||||
case OrderStatus.STATUS_PARKED:
|
||||
case Schema.OrderStatus.STATUS_PARKED:
|
||||
return t('Order parked');
|
||||
case OrderStatus.STATUS_STOPPED:
|
||||
case Schema.OrderStatus.STATUS_STOPPED:
|
||||
return t('Order stopped');
|
||||
case OrderStatus.STATUS_EXPIRED:
|
||||
case Schema.OrderStatus.STATUS_EXPIRED:
|
||||
return t('Order expired');
|
||||
case OrderStatus.STATUS_CANCELLED:
|
||||
case Schema.OrderStatus.STATUS_CANCELLED:
|
||||
return t('Order cancelled');
|
||||
case OrderStatus.STATUS_REJECTED:
|
||||
case Schema.OrderStatus.STATUS_REJECTED:
|
||||
return t('Order rejected');
|
||||
default:
|
||||
return t('Order amendment failed');
|
||||
@ -356,14 +353,14 @@ export const getEditDialogTitle = (
|
||||
};
|
||||
|
||||
export const getCancelDialogIntent = (
|
||||
status?: OrderStatus
|
||||
status?: Schema.OrderStatus
|
||||
): Intent | undefined => {
|
||||
if (!status) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case OrderStatus.STATUS_CANCELLED:
|
||||
case Schema.OrderStatus.STATUS_CANCELLED:
|
||||
return Intent.Success;
|
||||
default:
|
||||
return Intent.Danger;
|
||||
@ -371,14 +368,14 @@ export const getCancelDialogIntent = (
|
||||
};
|
||||
|
||||
export const getCancelDialogTitle = (
|
||||
status?: OrderStatus
|
||||
status?: Schema.OrderStatus
|
||||
): string | undefined => {
|
||||
if (!status) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case OrderStatus.STATUS_CANCELLED:
|
||||
case Schema.OrderStatus.STATUS_CANCELLED:
|
||||
return t('Order cancelled');
|
||||
default:
|
||||
return t('Order cancellation failed');
|
||||
|
33
libs/orders/src/lib/order-hooks/OrderEvent.graphql
Normal file
33
libs/orders/src/lib/order-hooks/OrderEvent.graphql
Normal file
@ -0,0 +1,33 @@
|
||||
fragment OrderEventFields on Order {
|
||||
type
|
||||
id
|
||||
status
|
||||
rejectionReason
|
||||
createdAt
|
||||
size
|
||||
price
|
||||
timeInForce
|
||||
expiresAt
|
||||
side
|
||||
market {
|
||||
id
|
||||
decimalPlaces
|
||||
positionDecimalPlaces
|
||||
tradableInstrument {
|
||||
instrument {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subscription OrderEvent($partyId: ID!) {
|
||||
busEvents(partyId: $partyId, batchSize: 0, types: [Order]) {
|
||||
type
|
||||
event {
|
||||
... on Order {
|
||||
...OrderEventFields
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
fragment OrderFields on Order {
|
||||
id
|
||||
market {
|
||||
id
|
||||
decimalPlaces
|
||||
positionDecimalPlaces
|
||||
tradableInstrument {
|
||||
instrument {
|
||||
id
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
type
|
||||
side
|
||||
size
|
||||
status
|
||||
rejectionReason
|
||||
price
|
||||
timeInForce
|
||||
remaining
|
||||
expiresAt
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
|
||||
query Orders($partyId: ID!, $pagination: Pagination) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
ordersConnection(pagination: $pagination) {
|
||||
edges {
|
||||
node {
|
||||
...OrderFields
|
||||
}
|
||||
cursor
|
||||
}
|
||||
pageInfo {
|
||||
startCursor
|
||||
endCursor
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subscription OrderSub($partyId: ID!) {
|
||||
orders(partyId: $partyId) {
|
||||
id
|
||||
price
|
||||
timeInForce
|
||||
side
|
||||
marketId
|
||||
size
|
||||
remaining
|
||||
partyId
|
||||
createdAt
|
||||
expiresAt
|
||||
status
|
||||
reference
|
||||
type
|
||||
rejectionReason
|
||||
version
|
||||
updatedAt
|
||||
peggedOrder {
|
||||
reference
|
||||
offset
|
||||
}
|
||||
liquidityProvisionId
|
||||
}
|
||||
}
|
||||
|
||||
subscription OrderEvent($partyId: ID!) {
|
||||
busEvents(partyId: $partyId, batchSize: 0, types: [Order]) {
|
||||
type
|
||||
event {
|
||||
... on Order {
|
||||
type
|
||||
id
|
||||
status
|
||||
rejectionReason
|
||||
createdAt
|
||||
size
|
||||
price
|
||||
timeInForce
|
||||
expiresAt
|
||||
side
|
||||
market {
|
||||
id
|
||||
decimalPlaces
|
||||
positionDecimalPlaces
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,139 +0,0 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @generated
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
import { BusEventType, OrderType, OrderStatus, OrderRejectionReason, OrderTimeInForce, Side } from "@vegaprotocol/types";
|
||||
|
||||
// ====================================================
|
||||
// GraphQL subscription operation: OrderEvent
|
||||
// ====================================================
|
||||
|
||||
export interface OrderEvent_busEvents_event_TimeUpdate {
|
||||
__typename: "TimeUpdate" | "MarketEvent" | "TransferResponses" | "PositionResolution" | "Trade" | "Account" | "Party" | "MarginLevels" | "Proposal" | "Vote" | "MarketData" | "NodeSignature" | "LossSocialization" | "SettlePosition" | "Market" | "Asset" | "MarketTick" | "SettleDistressed" | "AuctionEvent" | "RiskFactor" | "Deposit" | "Withdrawal" | "OracleSpec" | "LiquidityProvision" | "TransactionResult";
|
||||
}
|
||||
|
||||
export interface OrderEvent_busEvents_event_Order_market_tradableInstrument_instrument {
|
||||
__typename: "Instrument";
|
||||
/**
|
||||
* Full and fairly descriptive name for the instrument
|
||||
*/
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface OrderEvent_busEvents_event_Order_market_tradableInstrument {
|
||||
__typename: "TradableInstrument";
|
||||
/**
|
||||
* An instance of, or reference to, a fully specified instrument.
|
||||
*/
|
||||
instrument: OrderEvent_busEvents_event_Order_market_tradableInstrument_instrument;
|
||||
}
|
||||
|
||||
export interface OrderEvent_busEvents_event_Order_market {
|
||||
__typename: "Market";
|
||||
/**
|
||||
* Market ID
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* An instance of, or reference to, a tradable instrument.
|
||||
*/
|
||||
tradableInstrument: OrderEvent_busEvents_event_Order_market_tradableInstrument;
|
||||
/**
|
||||
* The number of decimal places that an integer must be shifted by in order to get a correct
|
||||
* number denominated in the currency of the market. (uint64)
|
||||
*
|
||||
* Examples:
|
||||
* Currency Balance decimalPlaces Real Balance
|
||||
* GBP 100 0 GBP 100
|
||||
* GBP 100 2 GBP 1.00
|
||||
* GBP 100 4 GBP 0.01
|
||||
* GBP 1 4 GBP 0.0001 ( 0.01p )
|
||||
*
|
||||
* GBX (pence) 100 0 GBP 1.00 (100p )
|
||||
* GBX (pence) 100 2 GBP 0.01 ( 1p )
|
||||
* GBX (pence) 100 4 GBP 0.0001 ( 0.01p )
|
||||
* GBX (pence) 1 4 GBP 0.000001 ( 0.0001p)
|
||||
*/
|
||||
decimalPlaces: number;
|
||||
/**
|
||||
* The number of decimal places that an integer must be shifted in order to get a correct size (uint64).
|
||||
* i.e. 0 means there are no fractional orders for the market, and order sizes are always whole sizes.
|
||||
* 2 means sizes given as 10^2 * desired size, e.g. a desired size of 1.23 is represented as 123 in this market.
|
||||
* This sets how big the smallest order / position on the market can be.
|
||||
*/
|
||||
positionDecimalPlaces: number;
|
||||
}
|
||||
|
||||
export interface OrderEvent_busEvents_event_Order {
|
||||
__typename: "Order";
|
||||
/**
|
||||
* The order type
|
||||
*/
|
||||
type: OrderType | null;
|
||||
/**
|
||||
* Hash of the order data
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* The status of an order, for example 'Active'
|
||||
*/
|
||||
status: OrderStatus;
|
||||
/**
|
||||
* Why the order was rejected
|
||||
*/
|
||||
rejectionReason: OrderRejectionReason | null;
|
||||
/**
|
||||
* RFC3339Nano formatted date and time for when the order was created (timestamp)
|
||||
*/
|
||||
createdAt: string;
|
||||
/**
|
||||
* Total number of units that may be bought or sold (immutable) (uint64)
|
||||
*/
|
||||
size: string;
|
||||
/**
|
||||
* The worst price the order will trade at (e.g. buy for price or less, sell for price or more) (uint64)
|
||||
*/
|
||||
price: string;
|
||||
/**
|
||||
* The timeInForce of order (determines how and if it executes, and whether it persists on the book)
|
||||
*/
|
||||
timeInForce: OrderTimeInForce;
|
||||
/**
|
||||
* Expiration time of this order (ISO-8601 RFC3339+Nano formatted date)
|
||||
*/
|
||||
expiresAt: string | null;
|
||||
/**
|
||||
* Whether the order is to buy or sell
|
||||
*/
|
||||
side: Side;
|
||||
/**
|
||||
* The market the order is trading on (probably stored internally as a hash of the market details)
|
||||
*/
|
||||
market: OrderEvent_busEvents_event_Order_market;
|
||||
}
|
||||
|
||||
export type OrderEvent_busEvents_event = OrderEvent_busEvents_event_TimeUpdate | OrderEvent_busEvents_event_Order;
|
||||
|
||||
export interface OrderEvent_busEvents {
|
||||
__typename: "BusEvent";
|
||||
/**
|
||||
* The type of event
|
||||
*/
|
||||
type: BusEventType;
|
||||
/**
|
||||
* The payload - the wrapped event
|
||||
*/
|
||||
event: OrderEvent_busEvents_event;
|
||||
}
|
||||
|
||||
export interface OrderEvent {
|
||||
/**
|
||||
* Subscribe to event data from the event bus
|
||||
*/
|
||||
busEvents: OrderEvent_busEvents[] | null;
|
||||
}
|
||||
|
||||
export interface OrderEventVariables {
|
||||
partyId: string;
|
||||
}
|
73
libs/orders/src/lib/order-hooks/__generated___/OrderEvent.ts
Normal file
73
libs/orders/src/lib/order-hooks/__generated___/OrderEvent.ts
Normal file
@ -0,0 +1,73 @@
|
||||
import { Schema as Types } from '@vegaprotocol/types';
|
||||
|
||||
import { gql } from '@apollo/client';
|
||||
import * as Apollo from '@apollo/client';
|
||||
const defaultOptions = {} as const;
|
||||
export type OrderEventFieldsFragment = { __typename?: 'Order', type?: Types.OrderType | null, id: string, status: Types.OrderStatus, rejectionReason?: Types.OrderRejectionReason | null, createdAt: string, size: string, price: string, timeInForce: Types.OrderTimeInForce, expiresAt?: string | null, side: Types.Side, market: { __typename?: 'Market', id: string, decimalPlaces: number, positionDecimalPlaces: number, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', name: string } } } };
|
||||
|
||||
export type OrderEventSubscriptionVariables = Types.Exact<{
|
||||
partyId: Types.Scalars['ID'];
|
||||
}>;
|
||||
|
||||
|
||||
export type OrderEventSubscription = { __typename?: 'Subscription', busEvents?: Array<{ __typename?: 'BusEvent', type: Types.BusEventType, event: { __typename?: 'Account' } | { __typename?: 'Asset' } | { __typename?: 'AuctionEvent' } | { __typename?: 'Deposit' } | { __typename?: 'LiquidityProvision' } | { __typename?: 'LossSocialization' } | { __typename?: 'MarginLevels' } | { __typename?: 'Market' } | { __typename?: 'MarketData' } | { __typename?: 'MarketEvent' } | { __typename?: 'MarketTick' } | { __typename?: 'NodeSignature' } | { __typename?: 'OracleSpec' } | { __typename?: 'Order', type?: Types.OrderType | null, id: string, status: Types.OrderStatus, rejectionReason?: Types.OrderRejectionReason | null, createdAt: string, size: string, price: string, timeInForce: Types.OrderTimeInForce, expiresAt?: string | null, side: Types.Side, market: { __typename?: 'Market', id: string, decimalPlaces: number, positionDecimalPlaces: number, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', name: string } } } } | { __typename?: 'Party' } | { __typename?: 'PositionResolution' } | { __typename?: 'Proposal' } | { __typename?: 'RiskFactor' } | { __typename?: 'SettleDistressed' } | { __typename?: 'SettlePosition' } | { __typename?: 'TimeUpdate' } | { __typename?: 'Trade' } | { __typename?: 'TransactionResult' } | { __typename?: 'TransferResponses' } | { __typename?: 'Vote' } | { __typename?: 'Withdrawal' } }> | null };
|
||||
|
||||
export const OrderEventFieldsFragmentDoc = gql`
|
||||
fragment OrderEventFields on Order {
|
||||
type
|
||||
id
|
||||
status
|
||||
rejectionReason
|
||||
createdAt
|
||||
size
|
||||
price
|
||||
timeInForce
|
||||
expiresAt
|
||||
side
|
||||
market {
|
||||
id
|
||||
decimalPlaces
|
||||
positionDecimalPlaces
|
||||
tradableInstrument {
|
||||
instrument {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const OrderEventDocument = gql`
|
||||
subscription OrderEvent($partyId: ID!) {
|
||||
busEvents(partyId: $partyId, batchSize: 0, types: [Order]) {
|
||||
type
|
||||
event {
|
||||
... on Order {
|
||||
...OrderEventFields
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
${OrderEventFieldsFragmentDoc}`;
|
||||
|
||||
/**
|
||||
* __useOrderEventSubscription__
|
||||
*
|
||||
* To run a query within a React component, call `useOrderEventSubscription` and pass it any options that fit your needs.
|
||||
* When your component renders, `useOrderEventSubscription` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the subscription, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useOrderEventSubscription({
|
||||
* variables: {
|
||||
* partyId: // value for 'partyId'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useOrderEventSubscription(baseOptions: Apollo.SubscriptionHookOptions<OrderEventSubscription, OrderEventSubscriptionVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useSubscription<OrderEventSubscription, OrderEventSubscriptionVariables>(OrderEventDocument, options);
|
||||
}
|
||||
export type OrderEventSubscriptionHookResult = ReturnType<typeof useOrderEventSubscription>;
|
||||
export type OrderEventSubscriptionResult = Apollo.SubscriptionResult<OrderEventSubscription>;
|
@ -1,205 +0,0 @@
|
||||
import { Schema as Types } from '@vegaprotocol/types';
|
||||
|
||||
import { gql } from '@apollo/client';
|
||||
import * as Apollo from '@apollo/client';
|
||||
const defaultOptions = {} as const;
|
||||
export type OrderFieldsFragment = { __typename?: 'Order', id: string, type?: Types.OrderType | null, side: Types.Side, size: string, status: Types.OrderStatus, rejectionReason?: Types.OrderRejectionReason | null, price: string, timeInForce: Types.OrderTimeInForce, remaining: string, expiresAt?: string | null, createdAt: string, updatedAt?: string | null, market: { __typename?: 'Market', id: string, decimalPlaces: number, positionDecimalPlaces: number, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', id: string, code: string } } } };
|
||||
|
||||
export type OrdersQueryVariables = Types.Exact<{
|
||||
partyId: Types.Scalars['ID'];
|
||||
pagination?: Types.InputMaybe<Types.Pagination>;
|
||||
}>;
|
||||
|
||||
|
||||
export type OrdersQuery = { __typename?: 'Query', party?: { __typename?: 'Party', id: string, ordersConnection?: { __typename?: 'OrderConnection', edges?: Array<{ __typename?: 'OrderEdge', cursor?: string | null, node: { __typename?: 'Order', id: string, type?: Types.OrderType | null, side: Types.Side, size: string, status: Types.OrderStatus, rejectionReason?: Types.OrderRejectionReason | null, price: string, timeInForce: Types.OrderTimeInForce, remaining: string, expiresAt?: string | null, createdAt: string, updatedAt?: string | null, market: { __typename?: 'Market', id: string, decimalPlaces: number, positionDecimalPlaces: number, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', id: string, code: string } } } } }> | null, pageInfo?: { __typename?: 'PageInfo', startCursor: string, endCursor: string, hasNextPage: boolean, hasPreviousPage: boolean } | null } | null } | null };
|
||||
|
||||
export type OrderSubSubscriptionVariables = Types.Exact<{
|
||||
partyId: Types.Scalars['ID'];
|
||||
}>;
|
||||
|
||||
|
||||
export type OrderSubSubscription = { __typename?: 'Subscription', orders?: Array<{ __typename?: 'OrderUpdate', id: string, price: string, timeInForce: Types.OrderTimeInForce, side: Types.Side, marketId: string, size: string, remaining: string, partyId: string, createdAt: string, expiresAt?: string | null, status: Types.OrderStatus, reference: string, type?: Types.OrderType | null, rejectionReason?: Types.OrderRejectionReason | null, version: string, updatedAt?: string | null, liquidityProvisionId?: string | null, peggedOrder?: { __typename?: 'PeggedOrder', reference: Types.PeggedReference, offset: string } | null }> | null };
|
||||
|
||||
export type OrderEventSubscriptionVariables = Types.Exact<{
|
||||
partyId: Types.Scalars['ID'];
|
||||
}>;
|
||||
|
||||
|
||||
export type OrderEventSubscription = { __typename?: 'Subscription', busEvents?: Array<{ __typename?: 'BusEvent', type: Types.BusEventType, event: { __typename?: 'Account' } | { __typename?: 'Asset' } | { __typename?: 'AuctionEvent' } | { __typename?: 'Deposit' } | { __typename?: 'LiquidityProvision' } | { __typename?: 'LossSocialization' } | { __typename?: 'MarginLevels' } | { __typename?: 'Market' } | { __typename?: 'MarketData' } | { __typename?: 'MarketEvent' } | { __typename?: 'MarketTick' } | { __typename?: 'NodeSignature' } | { __typename?: 'OracleSpec' } | { __typename?: 'Order', type?: Types.OrderType | null, id: string, status: Types.OrderStatus, rejectionReason?: Types.OrderRejectionReason | null, createdAt: string, size: string, price: string, timeInForce: Types.OrderTimeInForce, expiresAt?: string | null, side: Types.Side, market: { __typename?: 'Market', id: string, decimalPlaces: number, positionDecimalPlaces: number } } | { __typename?: 'Party' } | { __typename?: 'PositionResolution' } | { __typename?: 'Proposal' } | { __typename?: 'RiskFactor' } | { __typename?: 'SettleDistressed' } | { __typename?: 'SettlePosition' } | { __typename?: 'TimeUpdate' } | { __typename?: 'Trade' } | { __typename?: 'TransactionResult' } | { __typename?: 'TransferResponses' } | { __typename?: 'Vote' } | { __typename?: 'Withdrawal' } }> | null };
|
||||
|
||||
export const OrderFieldsFragmentDoc = gql`
|
||||
fragment OrderFields on Order {
|
||||
id
|
||||
market {
|
||||
id
|
||||
decimalPlaces
|
||||
positionDecimalPlaces
|
||||
tradableInstrument {
|
||||
instrument {
|
||||
id
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
type
|
||||
side
|
||||
size
|
||||
status
|
||||
rejectionReason
|
||||
price
|
||||
timeInForce
|
||||
remaining
|
||||
expiresAt
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
`;
|
||||
export const OrdersDocument = gql`
|
||||
query Orders($partyId: ID!, $pagination: Pagination) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
ordersConnection(pagination: $pagination) {
|
||||
edges {
|
||||
node {
|
||||
...OrderFields
|
||||
}
|
||||
cursor
|
||||
}
|
||||
pageInfo {
|
||||
startCursor
|
||||
endCursor
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
${OrderFieldsFragmentDoc}`;
|
||||
|
||||
/**
|
||||
* __useOrdersQuery__
|
||||
*
|
||||
* To run a query within a React component, call `useOrdersQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useOrdersQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useOrdersQuery({
|
||||
* variables: {
|
||||
* partyId: // value for 'partyId'
|
||||
* pagination: // value for 'pagination'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useOrdersQuery(baseOptions: Apollo.QueryHookOptions<OrdersQuery, OrdersQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useQuery<OrdersQuery, OrdersQueryVariables>(OrdersDocument, options);
|
||||
}
|
||||
export function useOrdersLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<OrdersQuery, OrdersQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useLazyQuery<OrdersQuery, OrdersQueryVariables>(OrdersDocument, options);
|
||||
}
|
||||
export type OrdersQueryHookResult = ReturnType<typeof useOrdersQuery>;
|
||||
export type OrdersLazyQueryHookResult = ReturnType<typeof useOrdersLazyQuery>;
|
||||
export type OrdersQueryResult = Apollo.QueryResult<OrdersQuery, OrdersQueryVariables>;
|
||||
export const OrderSubDocument = gql`
|
||||
subscription OrderSub($partyId: ID!) {
|
||||
orders(partyId: $partyId) {
|
||||
id
|
||||
price
|
||||
timeInForce
|
||||
side
|
||||
marketId
|
||||
size
|
||||
remaining
|
||||
partyId
|
||||
createdAt
|
||||
expiresAt
|
||||
status
|
||||
reference
|
||||
type
|
||||
rejectionReason
|
||||
version
|
||||
updatedAt
|
||||
peggedOrder {
|
||||
reference
|
||||
offset
|
||||
}
|
||||
liquidityProvisionId
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* __useOrderSubSubscription__
|
||||
*
|
||||
* To run a query within a React component, call `useOrderSubSubscription` and pass it any options that fit your needs.
|
||||
* When your component renders, `useOrderSubSubscription` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the subscription, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useOrderSubSubscription({
|
||||
* variables: {
|
||||
* partyId: // value for 'partyId'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useOrderSubSubscription(baseOptions: Apollo.SubscriptionHookOptions<OrderSubSubscription, OrderSubSubscriptionVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useSubscription<OrderSubSubscription, OrderSubSubscriptionVariables>(OrderSubDocument, options);
|
||||
}
|
||||
export type OrderSubSubscriptionHookResult = ReturnType<typeof useOrderSubSubscription>;
|
||||
export type OrderSubSubscriptionResult = Apollo.SubscriptionResult<OrderSubSubscription>;
|
||||
export const OrderEventDocument = gql`
|
||||
subscription OrderEvent($partyId: ID!) {
|
||||
busEvents(partyId: $partyId, batchSize: 0, types: [Order]) {
|
||||
type
|
||||
event {
|
||||
... on Order {
|
||||
type
|
||||
id
|
||||
status
|
||||
rejectionReason
|
||||
createdAt
|
||||
size
|
||||
price
|
||||
timeInForce
|
||||
expiresAt
|
||||
side
|
||||
market {
|
||||
id
|
||||
decimalPlaces
|
||||
positionDecimalPlaces
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* __useOrderEventSubscription__
|
||||
*
|
||||
* To run a query within a React component, call `useOrderEventSubscription` and pass it any options that fit your needs.
|
||||
* When your component renders, `useOrderEventSubscription` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the subscription, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useOrderEventSubscription({
|
||||
* variables: {
|
||||
* partyId: // value for 'partyId'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useOrderEventSubscription(baseOptions: Apollo.SubscriptionHookOptions<OrderEventSubscription, OrderEventSubscriptionVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useSubscription<OrderEventSubscription, OrderEventSubscriptionVariables>(OrderEventDocument, options);
|
||||
}
|
||||
export type OrderEventSubscriptionHookResult = ReturnType<typeof useOrderEventSubscription>;
|
||||
export type OrderEventSubscriptionResult = Apollo.SubscriptionResult<OrderEventSubscription>;
|
@ -1,5 +1,4 @@
|
||||
export * from './__generated__/OrderEvent';
|
||||
export * from './order-event-query';
|
||||
export * from './__generated___/OrderEvent';
|
||||
export * from './use-order-cancel';
|
||||
export * from './use-order-submit';
|
||||
export * from './use-order-edit';
|
||||
|
@ -1,33 +0,0 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const ORDER_EVENT_SUB = gql`
|
||||
subscription OrderEvent($partyId: ID!) {
|
||||
busEvents(partyId: $partyId, batchSize: 0, types: [Order]) {
|
||||
type
|
||||
event {
|
||||
... on Order {
|
||||
type
|
||||
id
|
||||
status
|
||||
rejectionReason
|
||||
createdAt
|
||||
size
|
||||
price
|
||||
timeInForce
|
||||
expiresAt
|
||||
side
|
||||
market {
|
||||
id
|
||||
tradableInstrument {
|
||||
instrument {
|
||||
name
|
||||
}
|
||||
}
|
||||
decimalPlaces
|
||||
positionDecimalPlaces
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
@ -5,15 +5,9 @@ import type { ReactNode } from 'react';
|
||||
import { VegaTxStatus, VegaWalletContext } from '@vegaprotocol/wallet';
|
||||
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
||||
import { useOrderCancel } from './use-order-cancel';
|
||||
import type { OrderEvent } from './';
|
||||
import { ORDER_EVENT_SUB } from './order-event-query';
|
||||
import {
|
||||
BusEventType,
|
||||
OrderStatus,
|
||||
OrderTimeInForce,
|
||||
OrderType,
|
||||
Side,
|
||||
} from '@vegaprotocol/types';
|
||||
import type { OrderEventSubscription } from './';
|
||||
import { OrderEventDocument } from './';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
|
||||
const defaultWalletContext = {
|
||||
pubKey: null,
|
||||
@ -26,9 +20,9 @@ const defaultWalletContext = {
|
||||
};
|
||||
|
||||
function setup(context?: Partial<VegaWalletContextShape>) {
|
||||
const mocks: MockedResponse<OrderEvent> = {
|
||||
const mocks: MockedResponse<OrderEventSubscription> = {
|
||||
request: {
|
||||
query: ORDER_EVENT_SUB,
|
||||
query: OrderEventDocument,
|
||||
variables: {
|
||||
partyId: context?.pubKey || '',
|
||||
},
|
||||
@ -37,18 +31,18 @@ function setup(context?: Partial<VegaWalletContextShape>) {
|
||||
data: {
|
||||
busEvents: [
|
||||
{
|
||||
type: BusEventType.Order,
|
||||
type: Schema.BusEventType.Order,
|
||||
event: {
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
id: '9c70716f6c3698ac7bbcddc97176025b985a6bb9a0c4507ec09c9960b3216b62',
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
status: Schema.OrderStatus.STATUS_ACTIVE,
|
||||
rejectionReason: null,
|
||||
createdAt: '2022-07-05T14:25:47.815283706Z',
|
||||
expiresAt: '2022-07-05T14:25:47.815283706Z',
|
||||
size: '10',
|
||||
price: '300000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Side.SIDE_BUY,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
market: {
|
||||
id: 'market-id',
|
||||
decimalPlaces: 5,
|
||||
@ -70,9 +64,9 @@ function setup(context?: Partial<VegaWalletContextShape>) {
|
||||
},
|
||||
},
|
||||
};
|
||||
const filterMocks: MockedResponse<OrderEvent> = {
|
||||
const filterMocks: MockedResponse<OrderEventSubscription> = {
|
||||
request: {
|
||||
query: ORDER_EVENT_SUB,
|
||||
query: OrderEventDocument,
|
||||
variables: {
|
||||
partyId: context?.pubKey || '',
|
||||
},
|
||||
@ -81,18 +75,18 @@ function setup(context?: Partial<VegaWalletContextShape>) {
|
||||
data: {
|
||||
busEvents: [
|
||||
{
|
||||
type: BusEventType.Order,
|
||||
type: Schema.BusEventType.Order,
|
||||
event: {
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
id: '9c70716f6c3698ac7bbcddc97176025b985a6bb9a0c4507ec09c9960b3216b62',
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
status: Schema.OrderStatus.STATUS_ACTIVE,
|
||||
rejectionReason: null,
|
||||
createdAt: '2022-07-05T14:25:47.815283706Z',
|
||||
expiresAt: '2022-07-05T14:25:47.815283706Z',
|
||||
size: '10',
|
||||
price: '300000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Side.SIDE_BUY,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
market: {
|
||||
id: 'market-id',
|
||||
decimalPlaces: 5,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useVegaWallet, useVegaTransaction } from '@vegaprotocol/wallet';
|
||||
import type { OrderEvent_busEvents_event_Order } from './';
|
||||
import type { OrderEventFieldsFragment } from './';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import { useOrderEvent } from './use-order-event';
|
||||
|
||||
@ -13,7 +13,7 @@ export const useOrderCancel = () => {
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
const [cancelledOrder, setCancelledOrder] =
|
||||
useState<OrderEvent_busEvents_event_Order | null>(null);
|
||||
useState<OrderEventFieldsFragment | null>(null);
|
||||
|
||||
const {
|
||||
send,
|
||||
|
@ -3,19 +3,13 @@ import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
||||
import { VegaTxStatus, VegaWalletContext } from '@vegaprotocol/wallet';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useOrderEdit } from './use-order-edit';
|
||||
import type { OrderEvent } from './';
|
||||
import { ORDER_EVENT_SUB } from './order-event-query';
|
||||
import type { OrderEventSubscription } from './__generated___/OrderEvent';
|
||||
import { OrderEventDocument } from './__generated___/OrderEvent';
|
||||
import type { MockedResponse } from '@apollo/client/testing';
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
import type { Order } from '../components';
|
||||
import { generateOrder } from '../components';
|
||||
import {
|
||||
OrderStatus,
|
||||
OrderType,
|
||||
OrderTimeInForce,
|
||||
Side,
|
||||
BusEventType,
|
||||
} from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
|
||||
const defaultWalletContext = {
|
||||
pubKey: null,
|
||||
@ -28,9 +22,9 @@ const defaultWalletContext = {
|
||||
};
|
||||
|
||||
function setup(order: Order, context?: Partial<VegaWalletContextShape>) {
|
||||
const mocks: MockedResponse<OrderEvent> = {
|
||||
const mocks: MockedResponse<OrderEventSubscription> = {
|
||||
request: {
|
||||
query: ORDER_EVENT_SUB,
|
||||
query: OrderEventDocument,
|
||||
variables: {
|
||||
partyId: context?.pubKey || '',
|
||||
},
|
||||
@ -39,18 +33,18 @@ function setup(order: Order, context?: Partial<VegaWalletContextShape>) {
|
||||
data: {
|
||||
busEvents: [
|
||||
{
|
||||
type: BusEventType.Order,
|
||||
type: Schema.BusEventType.Order,
|
||||
event: {
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
id: '9c70716f6c3698ac7bbcddc97176025b985a6bb9a0c4507ec09c9960b3216b62',
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
status: Schema.OrderStatus.STATUS_ACTIVE,
|
||||
rejectionReason: null,
|
||||
createdAt: '2022-07-05T14:25:47.815283706Z',
|
||||
expiresAt: '2022-07-05T14:25:47.815283706Z',
|
||||
size: '10',
|
||||
price: '300000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Side.SIDE_BUY,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
market: {
|
||||
id: 'market-id',
|
||||
decimalPlaces: 5,
|
||||
@ -72,9 +66,9 @@ function setup(order: Order, context?: Partial<VegaWalletContextShape>) {
|
||||
},
|
||||
},
|
||||
};
|
||||
const filterMocks: MockedResponse<OrderEvent> = {
|
||||
const filterMocks: MockedResponse<OrderEventSubscription> = {
|
||||
request: {
|
||||
query: ORDER_EVENT_SUB,
|
||||
query: OrderEventDocument,
|
||||
variables: {
|
||||
partyId: context?.pubKey || '',
|
||||
},
|
||||
@ -83,18 +77,18 @@ function setup(order: Order, context?: Partial<VegaWalletContextShape>) {
|
||||
data: {
|
||||
busEvents: [
|
||||
{
|
||||
type: BusEventType.Order,
|
||||
type: Schema.BusEventType.Order,
|
||||
event: {
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
id: '9c70716f6c3698ac7bbcddc97176025b985a6bb9a0c4507ec09c9960b3216b62',
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
status: Schema.OrderStatus.STATUS_ACTIVE,
|
||||
rejectionReason: null,
|
||||
createdAt: '2022-07-05T14:25:47.815283706Z',
|
||||
expiresAt: '2022-07-05T14:25:47.815283706Z',
|
||||
size: '10',
|
||||
price: '300000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Side.SIDE_BUY,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
market: {
|
||||
id: 'market-id',
|
||||
decimalPlaces: 5,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { removeDecimal, toNanoSeconds } from '@vegaprotocol/react-helpers';
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useVegaTransaction, useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import type { OrderEvent_busEvents_event_Order } from './';
|
||||
import type { OrderEventFieldsFragment } from './';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import type { Order } from '../components';
|
||||
import { useOrderEvent } from './use-order-event';
|
||||
@ -15,7 +15,7 @@ export const useOrderEdit = (order: Order | null) => {
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
const [updatedOrder, setUpdatedOrder] =
|
||||
useState<OrderEvent_busEvents_event_Order | null>(null);
|
||||
useState<OrderEventFieldsFragment | null>(null);
|
||||
|
||||
const {
|
||||
send,
|
||||
|
@ -1,19 +1,19 @@
|
||||
import { useApolloClient } from '@apollo/client';
|
||||
import { useCallback, useEffect, useRef } from 'react';
|
||||
import { ORDER_EVENT_SUB } from './order-event-query';
|
||||
import { OrderEventDocument } from './__generated___/OrderEvent';
|
||||
import type {
|
||||
OrderEvent,
|
||||
OrderEventVariables,
|
||||
OrderEvent_busEvents_event_Order,
|
||||
} from './';
|
||||
OrderEventSubscription,
|
||||
OrderEventSubscriptionVariables,
|
||||
OrderEventFieldsFragment,
|
||||
} from './__generated___/OrderEvent';
|
||||
import type { Subscription } from 'zen-observable-ts';
|
||||
import type { VegaTxState } from '@vegaprotocol/wallet';
|
||||
import { BusEventType } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
|
||||
type WaitFunc = (
|
||||
orderId: string,
|
||||
partyId: string
|
||||
) => Promise<OrderEvent_busEvents_event_Order>;
|
||||
) => Promise<OrderEventFieldsFragment>;
|
||||
|
||||
export const useOrderEvent = (transaction: VegaTxState) => {
|
||||
const client = useApolloClient();
|
||||
@ -23,8 +23,8 @@ export const useOrderEvent = (transaction: VegaTxState) => {
|
||||
(id: string, partyId: string) => {
|
||||
return new Promise((resolve) => {
|
||||
subRef.current = client
|
||||
.subscribe<OrderEvent, OrderEventVariables>({
|
||||
query: ORDER_EVENT_SUB,
|
||||
.subscribe<OrderEventSubscription, OrderEventSubscriptionVariables>({
|
||||
query: OrderEventDocument,
|
||||
variables: { partyId },
|
||||
})
|
||||
.subscribe(({ data }) => {
|
||||
@ -34,7 +34,7 @@ export const useOrderEvent = (transaction: VegaTxState) => {
|
||||
|
||||
// No types available for the subscription result
|
||||
const matchingOrderEvent = data.busEvents.find((e) => {
|
||||
if (e.event.__typename !== BusEventType.Order) {
|
||||
if (e.event.__typename !== Schema.BusEventType.Order) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ export const useOrderEvent = (transaction: VegaTxState) => {
|
||||
|
||||
if (
|
||||
matchingOrderEvent &&
|
||||
matchingOrderEvent.event.__typename === BusEventType.Order
|
||||
matchingOrderEvent.event.__typename === Schema.BusEventType.Order
|
||||
) {
|
||||
resolve(matchingOrderEvent.event);
|
||||
subRef.current?.unsubscribe();
|
||||
|
@ -1,20 +1,12 @@
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
import type { PubKey, VegaWalletContextShape } from '@vegaprotocol/wallet';
|
||||
import { VegaTxStatus, VegaWalletContext } from '@vegaprotocol/wallet';
|
||||
import {
|
||||
BusEventType,
|
||||
MarketState,
|
||||
MarketTradingMode,
|
||||
OrderStatus,
|
||||
OrderTimeInForce,
|
||||
OrderType,
|
||||
Side,
|
||||
} from '@vegaprotocol/types';
|
||||
import { MarketState, MarketTradingMode, Schema } from '@vegaprotocol/types';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { useOrderSubmit } from './use-order-submit';
|
||||
import type { OrderEvent } from './';
|
||||
import { ORDER_EVENT_SUB } from './order-event-query';
|
||||
import type { OrderEventSubscription } from './';
|
||||
import { OrderEventDocument } from './';
|
||||
import type { MockedResponse } from '@apollo/client/testing';
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
import { toNanoSeconds } from '@vegaprotocol/react-helpers';
|
||||
@ -56,9 +48,9 @@ const defaultWalletContext = {
|
||||
};
|
||||
|
||||
function setup(context?: Partial<VegaWalletContextShape>) {
|
||||
const mocks: MockedResponse<OrderEvent> = {
|
||||
const mocks: MockedResponse<OrderEventSubscription> = {
|
||||
request: {
|
||||
query: ORDER_EVENT_SUB,
|
||||
query: OrderEventDocument,
|
||||
variables: {
|
||||
partyId: context?.pubKey || '',
|
||||
},
|
||||
@ -67,18 +59,18 @@ function setup(context?: Partial<VegaWalletContextShape>) {
|
||||
data: {
|
||||
busEvents: [
|
||||
{
|
||||
type: BusEventType.Order,
|
||||
type: Schema.BusEventType.Order,
|
||||
event: {
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
id: '9c70716f6c3698ac7bbcddc97176025b985a6bb9a0c4507ec09c9960b3216b62',
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
status: Schema.OrderStatus.STATUS_ACTIVE,
|
||||
rejectionReason: null,
|
||||
createdAt: '2022-07-05T14:25:47.815283706Z',
|
||||
expiresAt: '2022-07-05T14:25:47.815283706Z',
|
||||
size: '10',
|
||||
price: '300000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Side.SIDE_BUY,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
market: {
|
||||
id: 'market-id',
|
||||
decimalPlaces: 5,
|
||||
@ -100,9 +92,9 @@ function setup(context?: Partial<VegaWalletContextShape>) {
|
||||
},
|
||||
},
|
||||
};
|
||||
const filterMocks: MockedResponse<OrderEvent> = {
|
||||
const filterMocks: MockedResponse<OrderEventSubscription> = {
|
||||
request: {
|
||||
query: ORDER_EVENT_SUB,
|
||||
query: OrderEventDocument,
|
||||
variables: {
|
||||
partyId: context?.pubKey || '',
|
||||
},
|
||||
@ -111,18 +103,18 @@ function setup(context?: Partial<VegaWalletContextShape>) {
|
||||
data: {
|
||||
busEvents: [
|
||||
{
|
||||
type: BusEventType.Order,
|
||||
type: Schema.BusEventType.Order,
|
||||
event: {
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
id: '9c70716f6c3698ac7bbcddc97176025b985a6bb9a0c4507ec09c9960b3216b62',
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
status: Schema.OrderStatus.STATUS_ACTIVE,
|
||||
rejectionReason: null,
|
||||
createdAt: '2022-07-05T14:25:47.815283706Z',
|
||||
expiresAt: '2022-07-05T14:25:47.815283706Z',
|
||||
size: '10',
|
||||
price: '300000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Side.SIDE_BUY,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
market: {
|
||||
id: 'market-id',
|
||||
decimalPlaces: 5,
|
||||
@ -168,10 +160,10 @@ describe('useOrderSubmit', () => {
|
||||
});
|
||||
|
||||
const order = {
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
size: '10',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTT,
|
||||
side: Side.SIDE_BUY,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTT,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
price: '123456789',
|
||||
expiresAt: new Date('2022-01-01').toISOString(),
|
||||
};
|
||||
@ -181,11 +173,11 @@ describe('useOrderSubmit', () => {
|
||||
|
||||
expect(mockSendTx).toHaveBeenCalledWith(pubKey, {
|
||||
orderSubmission: {
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
marketId: defaultMarket.id,
|
||||
size: '10',
|
||||
side: Side.SIDE_BUY,
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTT,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTT,
|
||||
price: '123456789',
|
||||
expiresAt: toNanoSeconds(order.expiresAt),
|
||||
},
|
||||
@ -205,10 +197,10 @@ describe('useOrderSubmit', () => {
|
||||
});
|
||||
|
||||
const order = {
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
size: '10',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Side.SIDE_BUY,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
price: '123456789',
|
||||
expiresAt: new Date('2022-01-01').toISOString(),
|
||||
};
|
||||
@ -218,11 +210,11 @@ describe('useOrderSubmit', () => {
|
||||
|
||||
expect(mockSendTx).toHaveBeenCalledWith(publicKeyObj.publicKey, {
|
||||
orderSubmission: {
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
type: Schema.OrderType.TYPE_LIMIT,
|
||||
marketId: defaultMarket.id,
|
||||
size: '10',
|
||||
side: Side.SIDE_BUY,
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
price: '123456789',
|
||||
expiresAt: undefined,
|
||||
},
|
||||
|
@ -1,40 +1,39 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { OrderEvent_busEvents_event_Order } from './__generated__/OrderEvent';
|
||||
import type { OrderEventFieldsFragment } from './__generated___/OrderEvent';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { toNanoSeconds } from '@vegaprotocol/react-helpers';
|
||||
import { useVegaTransaction, determineId } from '@vegaprotocol/wallet';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import { useOrderEvent } from './use-order-event';
|
||||
import { OrderTimeInForce } from '@vegaprotocol/types';
|
||||
import { OrderType, OrderStatus } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import { Icon, Intent } from '@vegaprotocol/ui-toolkit';
|
||||
import { t } from '@vegaprotocol/react-helpers';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
|
||||
export const getOrderDialogTitle = (
|
||||
status?: OrderStatus
|
||||
status?: Schema.OrderStatus
|
||||
): string | undefined => {
|
||||
if (!status) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case OrderStatus.STATUS_ACTIVE:
|
||||
case Schema.OrderStatus.STATUS_ACTIVE:
|
||||
return t('Order submitted');
|
||||
case OrderStatus.STATUS_FILLED:
|
||||
case Schema.OrderStatus.STATUS_FILLED:
|
||||
return t('Order filled');
|
||||
case OrderStatus.STATUS_PARTIALLY_FILLED:
|
||||
case Schema.OrderStatus.STATUS_PARTIALLY_FILLED:
|
||||
return t('Order partially filled');
|
||||
case OrderStatus.STATUS_PARKED:
|
||||
case Schema.OrderStatus.STATUS_PARKED:
|
||||
return t('Order parked');
|
||||
case OrderStatus.STATUS_STOPPED:
|
||||
case Schema.OrderStatus.STATUS_STOPPED:
|
||||
return t('Order stopped');
|
||||
case OrderStatus.STATUS_CANCELLED:
|
||||
case Schema.OrderStatus.STATUS_CANCELLED:
|
||||
return t('Order cancelled');
|
||||
case OrderStatus.STATUS_EXPIRED:
|
||||
case Schema.OrderStatus.STATUS_EXPIRED:
|
||||
return t('Order expired');
|
||||
case OrderStatus.STATUS_REJECTED:
|
||||
case Schema.OrderStatus.STATUS_REJECTED:
|
||||
return t('Order rejected');
|
||||
default:
|
||||
return t('Submission failed');
|
||||
@ -42,22 +41,22 @@ export const getOrderDialogTitle = (
|
||||
};
|
||||
|
||||
export const getOrderDialogIntent = (
|
||||
status?: OrderStatus
|
||||
status?: Schema.OrderStatus
|
||||
): Intent | undefined => {
|
||||
if (!status) {
|
||||
return;
|
||||
}
|
||||
switch (status) {
|
||||
case OrderStatus.STATUS_PARKED:
|
||||
case OrderStatus.STATUS_EXPIRED:
|
||||
case OrderStatus.STATUS_PARTIALLY_FILLED:
|
||||
case Schema.OrderStatus.STATUS_PARKED:
|
||||
case Schema.OrderStatus.STATUS_EXPIRED:
|
||||
case Schema.OrderStatus.STATUS_PARTIALLY_FILLED:
|
||||
return Intent.Warning;
|
||||
case OrderStatus.STATUS_REJECTED:
|
||||
case OrderStatus.STATUS_STOPPED:
|
||||
case OrderStatus.STATUS_CANCELLED:
|
||||
case Schema.OrderStatus.STATUS_REJECTED:
|
||||
case Schema.OrderStatus.STATUS_STOPPED:
|
||||
case Schema.OrderStatus.STATUS_CANCELLED:
|
||||
return Intent.Danger;
|
||||
case OrderStatus.STATUS_FILLED:
|
||||
case OrderStatus.STATUS_ACTIVE:
|
||||
case Schema.OrderStatus.STATUS_FILLED:
|
||||
case Schema.OrderStatus.STATUS_ACTIVE:
|
||||
return Intent.Success;
|
||||
default:
|
||||
return;
|
||||
@ -65,19 +64,19 @@ export const getOrderDialogIntent = (
|
||||
};
|
||||
|
||||
export const getOrderDialogIcon = (
|
||||
status?: OrderStatus
|
||||
status?: Schema.OrderStatus
|
||||
): ReactNode | undefined => {
|
||||
if (!status) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case OrderStatus.STATUS_PARKED:
|
||||
case OrderStatus.STATUS_EXPIRED:
|
||||
case Schema.OrderStatus.STATUS_PARKED:
|
||||
case Schema.OrderStatus.STATUS_EXPIRED:
|
||||
return <Icon name="warning-sign" size={16} />;
|
||||
case OrderStatus.STATUS_REJECTED:
|
||||
case OrderStatus.STATUS_STOPPED:
|
||||
case OrderStatus.STATUS_CANCELLED:
|
||||
case Schema.OrderStatus.STATUS_REJECTED:
|
||||
case Schema.OrderStatus.STATUS_STOPPED:
|
||||
case Schema.OrderStatus.STATUS_CANCELLED:
|
||||
return <Icon name="error" size={16} />;
|
||||
default:
|
||||
return;
|
||||
@ -98,7 +97,7 @@ export const useOrderSubmit = () => {
|
||||
const waitForOrderEvent = useOrderEvent(transaction);
|
||||
|
||||
const [finalizedOrder, setFinalizedOrder] =
|
||||
useState<OrderEvent_busEvents_event_Order | null>(null);
|
||||
useState<OrderEventFieldsFragment | null>(null);
|
||||
|
||||
const reset = useCallback(() => {
|
||||
resetTransaction();
|
||||
@ -118,12 +117,12 @@ export const useOrderSubmit = () => {
|
||||
orderSubmission: {
|
||||
...order,
|
||||
price:
|
||||
order.type === OrderType.TYPE_LIMIT && order.price
|
||||
order.type === Schema.OrderType.TYPE_LIMIT && order.price
|
||||
? order.price
|
||||
: undefined,
|
||||
expiresAt:
|
||||
order.expiresAt &&
|
||||
order.timeInForce === OrderTimeInForce.TIME_IN_FORCE_GTT
|
||||
order.timeInForce === Schema.OrderTimeInForce.TIME_IN_FORCE_GTT
|
||||
? toNanoSeconds(order.expiresAt) // Wallet expects timestamp in nanoseconds
|
||||
: undefined,
|
||||
},
|
||||
|
@ -1,20 +1,20 @@
|
||||
import { t } from '@vegaprotocol/react-helpers';
|
||||
import { OrderTimeInForce } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
|
||||
// More detail in https://docs.vega.xyz/docs/mainnet/graphql/enums/order-time-in-force
|
||||
export const timeInForceLabel = (tif: string) => {
|
||||
switch (tif) {
|
||||
case OrderTimeInForce.TIME_IN_FORCE_GTC:
|
||||
case Schema.OrderTimeInForce.TIME_IN_FORCE_GTC:
|
||||
return t(`Good 'til Cancelled (GTC)`);
|
||||
case OrderTimeInForce.TIME_IN_FORCE_IOC:
|
||||
case Schema.OrderTimeInForce.TIME_IN_FORCE_IOC:
|
||||
return t('Immediate or Cancel (IOC)');
|
||||
case OrderTimeInForce.TIME_IN_FORCE_FOK:
|
||||
case Schema.OrderTimeInForce.TIME_IN_FORCE_FOK:
|
||||
return t('Fill or Kill (FOK)');
|
||||
case OrderTimeInForce.TIME_IN_FORCE_GTT:
|
||||
case Schema.OrderTimeInForce.TIME_IN_FORCE_GTT:
|
||||
return t(`Good 'til Time (GTT)`);
|
||||
case OrderTimeInForce.TIME_IN_FORCE_GFN:
|
||||
case Schema.OrderTimeInForce.TIME_IN_FORCE_GFN:
|
||||
return t('Good for Normal (GFN)');
|
||||
case OrderTimeInForce.TIME_IN_FORCE_GFA:
|
||||
case Schema.OrderTimeInForce.TIME_IN_FORCE_GFA:
|
||||
return t('Good for Auction (GFA)');
|
||||
default:
|
||||
return t(tif);
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useEnvironment } from '@vegaprotocol/environment';
|
||||
import type { OrderEvent_busEvents_event_Order } from '@vegaprotocol/orders';
|
||||
import type { OrderEventFieldsFragment } from '@vegaprotocol/orders';
|
||||
import { t, truncateByChars } from '@vegaprotocol/react-helpers';
|
||||
import { OrderRejectionReasonMapping, OrderStatus } from '@vegaprotocol/types';
|
||||
import { OrderRejectionReasonMapping, Schema } from '@vegaprotocol/types';
|
||||
import { Link } from '@vegaprotocol/ui-toolkit';
|
||||
import type { TransactionResult, VegaTxState } from '@vegaprotocol/wallet';
|
||||
import type { ClosingOrder as IClosingOrder } from '../use-close-position';
|
||||
@ -13,7 +13,7 @@ interface CompleteProps {
|
||||
transaction: VegaTxState;
|
||||
transactionResult?: TransactionResult;
|
||||
closingOrder?: IClosingOrder;
|
||||
closingOrderResult?: OrderEvent_busEvents_event_Order;
|
||||
closingOrderResult?: OrderEventFieldsFragment;
|
||||
}
|
||||
|
||||
export const Complete = ({
|
||||
@ -29,7 +29,7 @@ export const Complete = ({
|
||||
|
||||
return (
|
||||
<>
|
||||
{closingOrderResult.status === OrderStatus.STATUS_FILLED &&
|
||||
{closingOrderResult.status === Schema.OrderStatus.STATUS_FILLED &&
|
||||
transactionResult.status ? (
|
||||
<Success partyId={partyId} order={closingOrder} />
|
||||
) : (
|
||||
@ -89,7 +89,7 @@ const Error = ({
|
||||
closingOrderResult,
|
||||
}: {
|
||||
transactionResult: TransactionResult;
|
||||
closingOrderResult: OrderEvent_busEvents_event_Order;
|
||||
closingOrderResult: OrderEventFieldsFragment;
|
||||
}) => {
|
||||
const reason =
|
||||
closingOrderResult.rejectionReason &&
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { render, screen, within } from '@testing-library/react';
|
||||
import { OrderTimeInForce, OrderType, Side } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import * as dataHook from '../use-request-close-position-data';
|
||||
import { Requested } from './requested';
|
||||
|
||||
@ -10,19 +10,19 @@ describe('Close position dialog - Request', () => {
|
||||
partyId: 'party-id',
|
||||
order: {
|
||||
marketId: 'market-id',
|
||||
type: OrderType.TYPE_MARKET as const,
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_FOK as const,
|
||||
side: Side.SIDE_BUY,
|
||||
type: Schema.OrderType.TYPE_MARKET as const,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_FOK as const,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
size: '10',
|
||||
},
|
||||
};
|
||||
|
||||
it('loading state', async () => {
|
||||
jest.spyOn(dataHook, 'useRequestClosePositionData').mockReturnValue({
|
||||
loading: false,
|
||||
market: null,
|
||||
marketData: null,
|
||||
orders: [],
|
||||
loading: false,
|
||||
});
|
||||
render(<Requested {...props} />);
|
||||
expect(screen.getByText('Loading...')).toBeInTheDocument();
|
||||
@ -33,14 +33,14 @@ describe('Close position dialog - Request', () => {
|
||||
{
|
||||
size: '200',
|
||||
price: '999',
|
||||
side: Side.SIDE_BUY,
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Schema.Side.SIDE_BUY,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
},
|
||||
{
|
||||
size: '300',
|
||||
price: '888',
|
||||
side: Side.SIDE_SELL,
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Schema.Side.SIDE_SELL,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
},
|
||||
];
|
||||
jest.spyOn(dataHook, 'useRequestClosePositionData').mockReturnValue({
|
||||
|
@ -2,14 +2,7 @@ import type { ReactNode } from 'react';
|
||||
import type { MockedResponse } from '@apollo/client/testing';
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
import { renderHook, waitFor } from '@testing-library/react';
|
||||
import {
|
||||
BusEventType,
|
||||
OrderStatus,
|
||||
OrderTimeInForce,
|
||||
OrderType,
|
||||
Schema as Types,
|
||||
Side,
|
||||
} from '@vegaprotocol/types';
|
||||
import { Schema as Types } from '@vegaprotocol/types';
|
||||
import { useClosePosition } from './use-close-position';
|
||||
import { VegaTxStatus, VegaWalletContext } from '@vegaprotocol/wallet';
|
||||
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
||||
@ -17,8 +10,8 @@ import { initialState } from '@vegaprotocol/wallet';
|
||||
import type { TransactionEventSubscription } from '@vegaprotocol/wallet';
|
||||
import { TransactionEventDocument } from '@vegaprotocol/wallet';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import type { OrderEvent } from '@vegaprotocol/orders';
|
||||
import { ORDER_EVENT_SUB } from '@vegaprotocol/orders';
|
||||
import type { OrderEventSubscription } from '@vegaprotocol/orders';
|
||||
import { OrderEventDocument } from '@vegaprotocol/orders';
|
||||
|
||||
const pubKey = 'test-pubkey';
|
||||
const defaultWalletContext = {
|
||||
@ -58,9 +51,9 @@ function setup(context?: Partial<VegaWalletContextShape>) {
|
||||
},
|
||||
},
|
||||
};
|
||||
const mockOrderResult: MockedResponse<OrderEvent> = {
|
||||
const mockOrderResult: MockedResponse<OrderEventSubscription> = {
|
||||
request: {
|
||||
query: ORDER_EVENT_SUB,
|
||||
query: OrderEventDocument,
|
||||
variables: {
|
||||
partyId: context?.pubKey || '',
|
||||
},
|
||||
@ -69,18 +62,18 @@ function setup(context?: Partial<VegaWalletContextShape>) {
|
||||
data: {
|
||||
busEvents: [
|
||||
{
|
||||
type: BusEventType.Order,
|
||||
type: Types.BusEventType.Order,
|
||||
event: {
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
type: Types.OrderType.TYPE_LIMIT,
|
||||
id: '2fca514cebf9f465ae31ecb4c5721e3a6f5f260425ded887ca50ba15b81a5d50',
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
status: Types.OrderStatus.STATUS_ACTIVE,
|
||||
rejectionReason: null,
|
||||
createdAt: '2022-07-05T14:25:47.815283706Z',
|
||||
expiresAt: '2022-07-05T14:25:47.815283706Z',
|
||||
size: '10',
|
||||
price: '300000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Side.SIDE_BUY,
|
||||
timeInForce: Types.OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Types.Side.SIDE_BUY,
|
||||
market: {
|
||||
id: 'market-id',
|
||||
decimalPlaces: 5,
|
||||
@ -164,9 +157,9 @@ describe('useClosePosition', () => {
|
||||
submissions: [
|
||||
{
|
||||
marketId,
|
||||
type: OrderType.TYPE_MARKET,
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_FOK,
|
||||
side: Side.SIDE_SELL,
|
||||
type: Types.OrderType.TYPE_MARKET,
|
||||
timeInForce: Types.OrderTimeInForce.TIME_IN_FORCE_FOK,
|
||||
side: Types.Side.SIDE_SELL,
|
||||
size: openVolume,
|
||||
},
|
||||
],
|
||||
@ -208,9 +201,9 @@ describe('useClosePosition', () => {
|
||||
submissions: [
|
||||
{
|
||||
marketId,
|
||||
type: OrderType.TYPE_MARKET,
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_FOK,
|
||||
side: Side.SIDE_BUY,
|
||||
type: Types.OrderType.TYPE_MARKET,
|
||||
timeInForce: Types.OrderTimeInForce.TIME_IN_FORCE_FOK,
|
||||
side: Types.Side.SIDE_BUY,
|
||||
size: openVolume.replace('-', ''),
|
||||
},
|
||||
],
|
||||
|
@ -4,15 +4,15 @@ import { determineId } from '@vegaprotocol/wallet';
|
||||
import { useVegaWallet, useTransactionResult } from '@vegaprotocol/wallet';
|
||||
import { useVegaTransaction } from '@vegaprotocol/wallet';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import { OrderTimeInForce, OrderType, Side } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import { useOrderEvent } from '@vegaprotocol/orders';
|
||||
import type { OrderEvent_busEvents_event_Order } from '@vegaprotocol/orders';
|
||||
import type { OrderEventFieldsFragment } from '@vegaprotocol/orders';
|
||||
|
||||
export interface ClosingOrder {
|
||||
marketId: string;
|
||||
type: OrderType.TYPE_MARKET;
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_FOK;
|
||||
side: Side;
|
||||
type: Schema.OrderType.TYPE_MARKET;
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_FOK;
|
||||
side: Schema.Side;
|
||||
size: string;
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ export const useClosePosition = () => {
|
||||
const { send, transaction, setComplete, Dialog } = useVegaTransaction();
|
||||
const [closingOrder, setClosingOrder] = useState<ClosingOrder>();
|
||||
const [closingOrderResult, setClosingOrderResult] =
|
||||
useState<OrderEvent_busEvents_event_Order>();
|
||||
useState<OrderEventFieldsFragment>();
|
||||
const [transactionResult, setTransactionResult] =
|
||||
useState<TransactionResult>();
|
||||
const waitForTransactionResult = useTransactionResult();
|
||||
@ -45,15 +45,15 @@ export const useClosePosition = () => {
|
||||
try {
|
||||
// figure out if opsition is long or short and make side the opposite
|
||||
const side = openVolume.startsWith('-')
|
||||
? Side.SIDE_BUY
|
||||
: Side.SIDE_SELL;
|
||||
? Schema.Side.SIDE_BUY
|
||||
: Schema.Side.SIDE_SELL;
|
||||
|
||||
// volume could be prefixed with '-' if position is short, remove it
|
||||
const size = openVolume.replace('-', '');
|
||||
const closingOrder = {
|
||||
marketId: marketId,
|
||||
type: OrderType.TYPE_MARKET as const,
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_FOK as const,
|
||||
type: Schema.OrderType.TYPE_MARKET as const,
|
||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_FOK as const,
|
||||
side,
|
||||
size,
|
||||
};
|
||||
|
@ -7,7 +7,7 @@ import type {
|
||||
} from '@apollo/client';
|
||||
import type { Subscription } from 'zen-observable-ts';
|
||||
import isEqual from 'lodash/isEqual';
|
||||
import type { Pagination as PaginationWithoutSkip } from '@vegaprotocol/types';
|
||||
import type { Schema } from '@vegaprotocol/types';
|
||||
|
||||
export interface UpdateDelta<Delta> {
|
||||
delta?: Delta;
|
||||
@ -35,7 +35,7 @@ export interface Load<Data> {
|
||||
(start?: number, end?: number): Promise<Data | null>;
|
||||
}
|
||||
|
||||
type Pagination = PaginationWithoutSkip & {
|
||||
type Pagination = Schema.Pagination & {
|
||||
skip?: number;
|
||||
};
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Side } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import type { ICellRendererParams } from 'ag-grid-community';
|
||||
import classNames from 'classnames';
|
||||
import { addDecimalsFormatNumber } from '../format';
|
||||
@ -9,18 +9,23 @@ export const Size = ({
|
||||
positionDecimalPlaces = 0,
|
||||
}: {
|
||||
value: string;
|
||||
side: Side;
|
||||
side: Schema.Side;
|
||||
positionDecimalPlaces?: number;
|
||||
}) => {
|
||||
return (
|
||||
<span
|
||||
data-testid="size"
|
||||
className={classNames('text-right', {
|
||||
'text-vega-green-dark dark:text-vega-green': side === Side.SIDE_BUY,
|
||||
'text-vega-red-dark dark:text-vega-red': side === Side.SIDE_SELL,
|
||||
'text-vega-green-dark dark:text-vega-green':
|
||||
side === Schema.Side.SIDE_BUY,
|
||||
'text-vega-red-dark dark:text-vega-red': side === Schema.Side.SIDE_SELL,
|
||||
})}
|
||||
>
|
||||
{side === Side.SIDE_BUY ? '+' : side === Side.SIDE_SELL ? '-' : ''}
|
||||
{side === Schema.Side.SIDE_BUY
|
||||
? '+'
|
||||
: side === Schema.Side.SIDE_SELL
|
||||
? '-'
|
||||
: ''}
|
||||
{addDecimalsFormatNumber(value, positionDecimalPlaces)}
|
||||
</span>
|
||||
);
|
||||
|
130
libs/types/src/__generated__/globalTypes.ts
generated
130
libs/types/src/__generated__/globalTypes.ts
generated
@ -44,36 +44,6 @@ export enum AuctionTrigger {
|
||||
AUCTION_TRIGGER_UNSPECIFIED = "AUCTION_TRIGGER_UNSPECIFIED",
|
||||
}
|
||||
|
||||
export enum BusEventType {
|
||||
Account = "Account",
|
||||
Asset = "Asset",
|
||||
Auction = "Auction",
|
||||
Deposit = "Deposit",
|
||||
LiquidityProvision = "LiquidityProvision",
|
||||
LossSocialization = "LossSocialization",
|
||||
MarginLevels = "MarginLevels",
|
||||
Market = "Market",
|
||||
MarketCreated = "MarketCreated",
|
||||
MarketData = "MarketData",
|
||||
MarketTick = "MarketTick",
|
||||
MarketUpdated = "MarketUpdated",
|
||||
NodeSignature = "NodeSignature",
|
||||
OracleSpec = "OracleSpec",
|
||||
Order = "Order",
|
||||
Party = "Party",
|
||||
PositionResolution = "PositionResolution",
|
||||
Proposal = "Proposal",
|
||||
RiskFactor = "RiskFactor",
|
||||
SettleDistressed = "SettleDistressed",
|
||||
SettlePosition = "SettlePosition",
|
||||
TimeUpdate = "TimeUpdate",
|
||||
Trade = "Trade",
|
||||
TransactionResult = "TransactionResult",
|
||||
TransferResponses = "TransferResponses",
|
||||
Vote = "Vote",
|
||||
Withdrawal = "Withdrawal",
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator describes the type of comparison.
|
||||
*/
|
||||
@ -139,88 +109,6 @@ export enum OracleSpecStatus {
|
||||
STATUS_DEACTIVATED = "STATUS_DEACTIVATED",
|
||||
}
|
||||
|
||||
/**
|
||||
* Why the order was rejected by the core node
|
||||
*/
|
||||
export enum OrderRejectionReason {
|
||||
ORDER_ERROR_AMEND_FAILURE = "ORDER_ERROR_AMEND_FAILURE",
|
||||
ORDER_ERROR_BUY_CANNOT_REFERENCE_BEST_ASK_PRICE = "ORDER_ERROR_BUY_CANNOT_REFERENCE_BEST_ASK_PRICE",
|
||||
ORDER_ERROR_CANNOT_AMEND_FROM_GFA_OR_GFN = "ORDER_ERROR_CANNOT_AMEND_FROM_GFA_OR_GFN",
|
||||
ORDER_ERROR_CANNOT_AMEND_PEGGED_ORDER_DETAILS_ON_NON_PEGGED_ORDER = "ORDER_ERROR_CANNOT_AMEND_PEGGED_ORDER_DETAILS_ON_NON_PEGGED_ORDER",
|
||||
ORDER_ERROR_CANNOT_AMEND_TO_FOK_OR_IOC = "ORDER_ERROR_CANNOT_AMEND_TO_FOK_OR_IOC",
|
||||
ORDER_ERROR_CANNOT_AMEND_TO_GFA_OR_GFN = "ORDER_ERROR_CANNOT_AMEND_TO_GFA_OR_GFN",
|
||||
ORDER_ERROR_CANNOT_AMEND_TO_GTT_WITHOUT_EXPIRYAT = "ORDER_ERROR_CANNOT_AMEND_TO_GTT_WITHOUT_EXPIRYAT",
|
||||
ORDER_ERROR_CANNOT_HAVE_GTC_AND_EXPIRYAT = "ORDER_ERROR_CANNOT_HAVE_GTC_AND_EXPIRYAT",
|
||||
ORDER_ERROR_CANNOT_SEND_FOK_ORDER_DURING_AUCTION = "ORDER_ERROR_CANNOT_SEND_FOK_ORDER_DURING_AUCTION",
|
||||
ORDER_ERROR_CANNOT_SEND_IOC_ORDER_DURING_AUCTION = "ORDER_ERROR_CANNOT_SEND_IOC_ORDER_DURING_AUCTION",
|
||||
ORDER_ERROR_EDIT_NOT_ALLOWED = "ORDER_ERROR_EDIT_NOT_ALLOWED",
|
||||
ORDER_ERROR_EXPIRYAT_BEFORE_CREATEDAT = "ORDER_ERROR_EXPIRYAT_BEFORE_CREATEDAT",
|
||||
ORDER_ERROR_GFA_ORDER_DURING_CONTINUOUS_TRADING = "ORDER_ERROR_GFA_ORDER_DURING_CONTINUOUS_TRADING",
|
||||
ORDER_ERROR_GFN_ORDER_DURING_AN_AUCTION = "ORDER_ERROR_GFN_ORDER_DURING_AN_AUCTION",
|
||||
ORDER_ERROR_INSUFFICIENT_ASSET_BALANCE = "ORDER_ERROR_INSUFFICIENT_ASSET_BALANCE",
|
||||
ORDER_ERROR_INSUFFICIENT_FUNDS_TO_PAY_FEES = "ORDER_ERROR_INSUFFICIENT_FUNDS_TO_PAY_FEES",
|
||||
ORDER_ERROR_INTERNAL_ERROR = "ORDER_ERROR_INTERNAL_ERROR",
|
||||
ORDER_ERROR_INVALID_EXPIRATION_DATETIME = "ORDER_ERROR_INVALID_EXPIRATION_DATETIME",
|
||||
ORDER_ERROR_INVALID_MARKET_ID = "ORDER_ERROR_INVALID_MARKET_ID",
|
||||
ORDER_ERROR_INVALID_ORDER_ID = "ORDER_ERROR_INVALID_ORDER_ID",
|
||||
ORDER_ERROR_INVALID_ORDER_REFERENCE = "ORDER_ERROR_INVALID_ORDER_REFERENCE",
|
||||
ORDER_ERROR_INVALID_PARTY_ID = "ORDER_ERROR_INVALID_PARTY_ID",
|
||||
ORDER_ERROR_INVALID_PERSISTENCE = "ORDER_ERROR_INVALID_PERSISTENCE",
|
||||
ORDER_ERROR_INVALID_REMAINING_SIZE = "ORDER_ERROR_INVALID_REMAINING_SIZE",
|
||||
ORDER_ERROR_INVALID_SIZE = "ORDER_ERROR_INVALID_SIZE",
|
||||
ORDER_ERROR_INVALID_TIME_IN_FORCE = "ORDER_ERROR_INVALID_TIME_IN_FORCE",
|
||||
ORDER_ERROR_INVALID_TYPE = "ORDER_ERROR_INVALID_TYPE",
|
||||
ORDER_ERROR_MARGIN_CHECK_FAILED = "ORDER_ERROR_MARGIN_CHECK_FAILED",
|
||||
ORDER_ERROR_MARKET_CLOSED = "ORDER_ERROR_MARKET_CLOSED",
|
||||
ORDER_ERROR_MISSING_GENERAL_ACCOUNT = "ORDER_ERROR_MISSING_GENERAL_ACCOUNT",
|
||||
ORDER_ERROR_MUST_BE_GTT_OR_GTC = "ORDER_ERROR_MUST_BE_GTT_OR_GTC",
|
||||
ORDER_ERROR_MUST_BE_LIMIT_ORDER = "ORDER_ERROR_MUST_BE_LIMIT_ORDER",
|
||||
ORDER_ERROR_NON_PERSISTENT_ORDER_OUT_OF_PRICE_BOUNDS = "ORDER_ERROR_NON_PERSISTENT_ORDER_OUT_OF_PRICE_BOUNDS",
|
||||
ORDER_ERROR_NOT_FOUND = "ORDER_ERROR_NOT_FOUND",
|
||||
ORDER_ERROR_OFFSET_MUST_BE_GREATER_OR_EQUAL_TO_ZERO = "ORDER_ERROR_OFFSET_MUST_BE_GREATER_OR_EQUAL_TO_ZERO",
|
||||
ORDER_ERROR_OFFSET_MUST_BE_GREATER_THAN_ZERO = "ORDER_ERROR_OFFSET_MUST_BE_GREATER_THAN_ZERO",
|
||||
ORDER_ERROR_OUT_OF_SEQUENCE = "ORDER_ERROR_OUT_OF_SEQUENCE",
|
||||
ORDER_ERROR_REMOVAL_FAILURE = "ORDER_ERROR_REMOVAL_FAILURE",
|
||||
ORDER_ERROR_SELF_TRADING = "ORDER_ERROR_SELF_TRADING",
|
||||
ORDER_ERROR_SELL_CANNOT_REFERENCE_BEST_BID_PRICE = "ORDER_ERROR_SELL_CANNOT_REFERENCE_BEST_BID_PRICE",
|
||||
ORDER_ERROR_TIME_FAILURE = "ORDER_ERROR_TIME_FAILURE",
|
||||
ORDER_ERROR_UNABLE_TO_AMEND_PRICE_ON_PEGGED_ORDER = "ORDER_ERROR_UNABLE_TO_AMEND_PRICE_ON_PEGGED_ORDER",
|
||||
ORDER_ERROR_UNABLE_TO_REPRICE_PEGGED_ORDER = "ORDER_ERROR_UNABLE_TO_REPRICE_PEGGED_ORDER",
|
||||
ORDER_ERROR_WITHOUT_REFERENCE_PRICE = "ORDER_ERROR_WITHOUT_REFERENCE_PRICE",
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid order statuses, these determine several states for an order that cannot be expressed with other fields in Order.
|
||||
*/
|
||||
export enum OrderStatus {
|
||||
STATUS_ACTIVE = "STATUS_ACTIVE",
|
||||
STATUS_CANCELLED = "STATUS_CANCELLED",
|
||||
STATUS_EXPIRED = "STATUS_EXPIRED",
|
||||
STATUS_FILLED = "STATUS_FILLED",
|
||||
STATUS_PARKED = "STATUS_PARKED",
|
||||
STATUS_PARTIALLY_FILLED = "STATUS_PARTIALLY_FILLED",
|
||||
STATUS_REJECTED = "STATUS_REJECTED",
|
||||
STATUS_STOPPED = "STATUS_STOPPED",
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid order types, these determine what happens when an order is added to the book
|
||||
*/
|
||||
export enum OrderTimeInForce {
|
||||
TIME_IN_FORCE_FOK = "TIME_IN_FORCE_FOK",
|
||||
TIME_IN_FORCE_GFA = "TIME_IN_FORCE_GFA",
|
||||
TIME_IN_FORCE_GFN = "TIME_IN_FORCE_GFN",
|
||||
TIME_IN_FORCE_GTC = "TIME_IN_FORCE_GTC",
|
||||
TIME_IN_FORCE_GTT = "TIME_IN_FORCE_GTT",
|
||||
TIME_IN_FORCE_IOC = "TIME_IN_FORCE_IOC",
|
||||
}
|
||||
|
||||
export enum OrderType {
|
||||
TYPE_LIMIT = "TYPE_LIMIT",
|
||||
TYPE_MARKET = "TYPE_MARKET",
|
||||
TYPE_NETWORK = "TYPE_NETWORK",
|
||||
}
|
||||
|
||||
/**
|
||||
* Type describes the type of properties that are supported by the oracle
|
||||
* engine.
|
||||
@ -296,14 +184,6 @@ export enum ProposalState {
|
||||
STATE_WAITING_FOR_NODE_VOTE = "STATE_WAITING_FOR_NODE_VOTE",
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the placer of an order is aiming to buy or sell on the market
|
||||
*/
|
||||
export enum Side {
|
||||
SIDE_BUY = "SIDE_BUY",
|
||||
SIDE_SELL = "SIDE_SELL",
|
||||
}
|
||||
|
||||
/**
|
||||
* The status of the stake linking
|
||||
*/
|
||||
@ -333,16 +213,6 @@ export enum WithdrawalStatus {
|
||||
STATUS_REJECTED = "STATUS_REJECTED",
|
||||
}
|
||||
|
||||
/**
|
||||
* Pagination constructs to support cursor based pagination in the API
|
||||
*/
|
||||
export interface Pagination {
|
||||
first?: number | null;
|
||||
after?: string | null;
|
||||
last?: number | null;
|
||||
before?: string | null;
|
||||
}
|
||||
|
||||
//==============================================================
|
||||
// END Enums and Input Objects
|
||||
//==============================================================
|
||||
|
@ -1,9 +1,4 @@
|
||||
import type {
|
||||
OrderTimeInForce,
|
||||
OrderType,
|
||||
Side,
|
||||
VoteValue,
|
||||
} from '@vegaprotocol/types';
|
||||
import type { Schema, VoteValue } from '@vegaprotocol/types';
|
||||
|
||||
export interface DelegateSubmissionBody {
|
||||
delegateSubmission: {
|
||||
@ -23,9 +18,9 @@ export interface UndelegateSubmissionBody {
|
||||
interface OrderSubmission {
|
||||
marketId: string;
|
||||
reference?: string;
|
||||
type: OrderType;
|
||||
side: Side;
|
||||
timeInForce: OrderTimeInForce;
|
||||
type: Schema.OrderType;
|
||||
side: Schema.Side;
|
||||
timeInForce: Schema.OrderTimeInForce;
|
||||
size: string;
|
||||
price?: string;
|
||||
expiresAt?: string;
|
||||
@ -40,7 +35,7 @@ interface OrderAmendment {
|
||||
marketId: string;
|
||||
orderId: string;
|
||||
reference?: string;
|
||||
timeInForce: OrderTimeInForce;
|
||||
timeInForce: Schema.OrderTimeInForce;
|
||||
sizeDelta?: number;
|
||||
price?: string;
|
||||
expiresAt?: string;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { useApolloClient } from '@apollo/client';
|
||||
import { BusEventType } from '@vegaprotocol/types';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import { useCallback, useEffect, useRef } from 'react';
|
||||
import type { Subscription } from 'zen-observable-ts';
|
||||
import type {
|
||||
@ -43,7 +43,9 @@ export const useTransactionResult = () => {
|
||||
}
|
||||
|
||||
const matchingTransaction = data.busEvents.find((e) => {
|
||||
if (e.event.__typename !== BusEventType.TransactionResult) {
|
||||
if (
|
||||
e.event.__typename !== Schema.BusEventType.TransactionResult
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -53,7 +55,7 @@ export const useTransactionResult = () => {
|
||||
if (
|
||||
matchingTransaction &&
|
||||
matchingTransaction.event.__typename ===
|
||||
BusEventType.TransactionResult
|
||||
Schema.BusEventType.TransactionResult
|
||||
) {
|
||||
resolve(matchingTransaction.event as TransactionResult);
|
||||
subRef.current?.unsubscribe();
|
||||
|
Loading…
Reference in New Issue
Block a user