[#128] Add market data details to positions query
This commit is contained in:
parent
043c733185
commit
fe29e86c74
@ -33,6 +33,9 @@ export function createClient(base?: string) {
|
||||
Instrument: {
|
||||
keyFields: false,
|
||||
},
|
||||
MarketData: {
|
||||
keyFields: ['market', ['id']],
|
||||
},
|
||||
Node: {
|
||||
keyFields: false,
|
||||
},
|
||||
|
18
libs/graphql/src/__generated__/PositionDetails.ts
generated
18
libs/graphql/src/__generated__/PositionDetails.ts
generated
@ -3,16 +3,34 @@
|
||||
// @generated
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
import { MarketTradingMode } from "./globalTypes";
|
||||
|
||||
// ====================================================
|
||||
// GraphQL fragment: PositionDetails
|
||||
// ====================================================
|
||||
|
||||
export interface PositionDetails_market_data_market {
|
||||
__typename: "Market";
|
||||
/**
|
||||
* Market ID
|
||||
*/
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface PositionDetails_market_data {
|
||||
__typename: "MarketData";
|
||||
/**
|
||||
* the mark price (actually an unsigned int)
|
||||
*/
|
||||
markPrice: string;
|
||||
/**
|
||||
* what state the market is in (auction, continuous etc)
|
||||
*/
|
||||
marketTradingMode: MarketTradingMode;
|
||||
/**
|
||||
* market id of the associated mark price
|
||||
*/
|
||||
market: PositionDetails_market_data_market;
|
||||
}
|
||||
|
||||
export interface PositionDetails_market_tradableInstrument_instrument_metadata {
|
||||
|
18
libs/graphql/src/__generated__/positionSubscribe.ts
generated
18
libs/graphql/src/__generated__/positionSubscribe.ts
generated
@ -3,16 +3,34 @@
|
||||
// @generated
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
import { MarketTradingMode } from "./globalTypes";
|
||||
|
||||
// ====================================================
|
||||
// GraphQL subscription operation: positionSubscribe
|
||||
// ====================================================
|
||||
|
||||
export interface positionSubscribe_positions_market_data_market {
|
||||
__typename: "Market";
|
||||
/**
|
||||
* Market ID
|
||||
*/
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions_market_data {
|
||||
__typename: "MarketData";
|
||||
/**
|
||||
* the mark price (actually an unsigned int)
|
||||
*/
|
||||
markPrice: string;
|
||||
/**
|
||||
* what state the market is in (auction, continuous etc)
|
||||
*/
|
||||
marketTradingMode: MarketTradingMode;
|
||||
/**
|
||||
* market id of the associated mark price
|
||||
*/
|
||||
market: positionSubscribe_positions_market_data_market;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions_market_tradableInstrument_instrument_metadata {
|
||||
|
18
libs/graphql/src/__generated__/positions.ts
generated
18
libs/graphql/src/__generated__/positions.ts
generated
@ -3,16 +3,34 @@
|
||||
// @generated
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
import { MarketTradingMode } from "./globalTypes";
|
||||
|
||||
// ====================================================
|
||||
// GraphQL query operation: positions
|
||||
// ====================================================
|
||||
|
||||
export interface positions_party_positions_market_data_market {
|
||||
__typename: "Market";
|
||||
/**
|
||||
* Market ID
|
||||
*/
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface positions_party_positions_market_data {
|
||||
__typename: "MarketData";
|
||||
/**
|
||||
* the mark price (actually an unsigned int)
|
||||
*/
|
||||
markPrice: string;
|
||||
/**
|
||||
* what state the market is in (auction, continuous etc)
|
||||
*/
|
||||
marketTradingMode: MarketTradingMode;
|
||||
/**
|
||||
* market id of the associated mark price
|
||||
*/
|
||||
market: positions_party_positions_market_data_market;
|
||||
}
|
||||
|
||||
export interface positions_party_positions_market_tradableInstrument_instrument_metadata {
|
||||
|
@ -21,6 +21,10 @@ const POSITIONS_FRAGMENT = gql`
|
||||
name
|
||||
data {
|
||||
markPrice
|
||||
marketTradingMode
|
||||
market {
|
||||
id
|
||||
}
|
||||
}
|
||||
decimalPlaces
|
||||
tradableInstrument {
|
||||
|
@ -1,6 +1,9 @@
|
||||
import { act, render, screen } from '@testing-library/react';
|
||||
import PositionsTable from './positions-table';
|
||||
import { positions_party_positions } from '@vegaprotocol/graphql';
|
||||
import {
|
||||
positions_party_positions,
|
||||
MarketTradingMode,
|
||||
} from '@vegaprotocol/graphql';
|
||||
|
||||
const singleRow: positions_party_positions = {
|
||||
realisedPNL: '5',
|
||||
@ -10,7 +13,12 @@ const singleRow: positions_party_positions = {
|
||||
market: {
|
||||
id: 'b7010da9dbe7fbab2b74d9d5642fc4a8a0ca93ef803d21fa60c2cacd0416bba0',
|
||||
name: 'UNIDAI Monthly (30 Jun 2022)',
|
||||
data: { markPrice: '1138885', __typename: 'MarketData' },
|
||||
data: {
|
||||
markPrice: '1138885',
|
||||
marketTradingMode: MarketTradingMode.Continuous,
|
||||
__typename: 'MarketData',
|
||||
market: { __typename: 'Market', id: '123' },
|
||||
},
|
||||
decimalPlaces: 5,
|
||||
tradableInstrument: {
|
||||
instrument: {
|
||||
@ -48,9 +56,7 @@ const singleRow: positions_party_positions = {
|
||||
__typename: 'Position',
|
||||
};
|
||||
const singleRowData = [singleRow];
|
||||
const onRowClicked = (marketId: string) => {
|
||||
console.log(marketId);
|
||||
};
|
||||
const onRowClicked = jest.fn;
|
||||
|
||||
test('should render successfully', async () => {
|
||||
await act(async () => {
|
||||
|
@ -10,7 +10,10 @@ import { AgGridDynamic as AgGrid } from '@vegaprotocol/ui-toolkit';
|
||||
import { AgGridColumn } from 'ag-grid-react';
|
||||
import type { AgGridReact } from 'ag-grid-react';
|
||||
import compact from 'lodash/compact';
|
||||
import { positions_party_positions } from '@vegaprotocol/graphql';
|
||||
import {
|
||||
positions_party_positions,
|
||||
MarketTradingMode,
|
||||
} from '@vegaprotocol/graphql';
|
||||
|
||||
interface PositionsTableProps {
|
||||
data: positions_party_positions[];
|
||||
@ -93,9 +96,18 @@ export const PositionsTable = forwardRef<AgGridReact, PositionsTableProps>(
|
||||
field="market.data.markPrice"
|
||||
type="rightAligned"
|
||||
cellRenderer="PriceCell"
|
||||
valueFormatter={({ value, data }: ValueFormatterParams) =>
|
||||
addDecimal(value, data.market.decimalPlaces)
|
||||
}
|
||||
valueFormatter={({
|
||||
value,
|
||||
data,
|
||||
}: PositionsTableValueFormatterParams) => {
|
||||
if (
|
||||
data.market.data?.marketTradingMode ===
|
||||
MarketTradingMode.OpeningAuction
|
||||
) {
|
||||
return '-';
|
||||
}
|
||||
return addDecimal(value, data.market.decimalPlaces);
|
||||
}}
|
||||
/>
|
||||
<AgGridColumn
|
||||
headerName="Realised PNL"
|
||||
|
Loading…
Reference in New Issue
Block a user