[#128] Add market data details to positions query

This commit is contained in:
Bartłomiej Głownia 2022-03-29 18:36:20 +02:00
parent 043c733185
commit fe29e86c74
7 changed files with 88 additions and 9 deletions

View File

@ -33,6 +33,9 @@ export function createClient(base?: string) {
Instrument: { Instrument: {
keyFields: false, keyFields: false,
}, },
MarketData: {
keyFields: ['market', ['id']],
},
Node: { Node: {
keyFields: false, keyFields: false,
}, },

View File

@ -3,16 +3,34 @@
// @generated // @generated
// This file was automatically generated and should not be edited. // This file was automatically generated and should not be edited.
import { MarketTradingMode } from "./globalTypes";
// ==================================================== // ====================================================
// GraphQL fragment: PositionDetails // GraphQL fragment: PositionDetails
// ==================================================== // ====================================================
export interface PositionDetails_market_data_market {
__typename: "Market";
/**
* Market ID
*/
id: string;
}
export interface PositionDetails_market_data { export interface PositionDetails_market_data {
__typename: "MarketData"; __typename: "MarketData";
/** /**
* the mark price (actually an unsigned int) * the mark price (actually an unsigned int)
*/ */
markPrice: string; 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 { export interface PositionDetails_market_tradableInstrument_instrument_metadata {

View File

@ -3,16 +3,34 @@
// @generated // @generated
// This file was automatically generated and should not be edited. // This file was automatically generated and should not be edited.
import { MarketTradingMode } from "./globalTypes";
// ==================================================== // ====================================================
// GraphQL subscription operation: positionSubscribe // GraphQL subscription operation: positionSubscribe
// ==================================================== // ====================================================
export interface positionSubscribe_positions_market_data_market {
__typename: "Market";
/**
* Market ID
*/
id: string;
}
export interface positionSubscribe_positions_market_data { export interface positionSubscribe_positions_market_data {
__typename: "MarketData"; __typename: "MarketData";
/** /**
* the mark price (actually an unsigned int) * the mark price (actually an unsigned int)
*/ */
markPrice: string; 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 { export interface positionSubscribe_positions_market_tradableInstrument_instrument_metadata {

View File

@ -3,16 +3,34 @@
// @generated // @generated
// This file was automatically generated and should not be edited. // This file was automatically generated and should not be edited.
import { MarketTradingMode } from "./globalTypes";
// ==================================================== // ====================================================
// GraphQL query operation: positions // 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 { export interface positions_party_positions_market_data {
__typename: "MarketData"; __typename: "MarketData";
/** /**
* the mark price (actually an unsigned int) * the mark price (actually an unsigned int)
*/ */
markPrice: string; 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 { export interface positions_party_positions_market_tradableInstrument_instrument_metadata {

View File

@ -21,6 +21,10 @@ const POSITIONS_FRAGMENT = gql`
name name
data { data {
markPrice markPrice
marketTradingMode
market {
id
}
} }
decimalPlaces decimalPlaces
tradableInstrument { tradableInstrument {

View File

@ -1,6 +1,9 @@
import { act, render, screen } from '@testing-library/react'; import { act, render, screen } from '@testing-library/react';
import PositionsTable from './positions-table'; 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 = { const singleRow: positions_party_positions = {
realisedPNL: '5', realisedPNL: '5',
@ -10,7 +13,12 @@ const singleRow: positions_party_positions = {
market: { market: {
id: 'b7010da9dbe7fbab2b74d9d5642fc4a8a0ca93ef803d21fa60c2cacd0416bba0', id: 'b7010da9dbe7fbab2b74d9d5642fc4a8a0ca93ef803d21fa60c2cacd0416bba0',
name: 'UNIDAI Monthly (30 Jun 2022)', 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, decimalPlaces: 5,
tradableInstrument: { tradableInstrument: {
instrument: { instrument: {
@ -48,9 +56,7 @@ const singleRow: positions_party_positions = {
__typename: 'Position', __typename: 'Position',
}; };
const singleRowData = [singleRow]; const singleRowData = [singleRow];
const onRowClicked = (marketId: string) => { const onRowClicked = jest.fn;
console.log(marketId);
};
test('should render successfully', async () => { test('should render successfully', async () => {
await act(async () => { await act(async () => {

View File

@ -10,7 +10,10 @@ import { AgGridDynamic as AgGrid } from '@vegaprotocol/ui-toolkit';
import { AgGridColumn } from 'ag-grid-react'; import { AgGridColumn } from 'ag-grid-react';
import type { AgGridReact } from 'ag-grid-react'; import type { AgGridReact } from 'ag-grid-react';
import compact from 'lodash/compact'; import compact from 'lodash/compact';
import { positions_party_positions } from '@vegaprotocol/graphql'; import {
positions_party_positions,
MarketTradingMode,
} from '@vegaprotocol/graphql';
interface PositionsTableProps { interface PositionsTableProps {
data: positions_party_positions[]; data: positions_party_positions[];
@ -93,9 +96,18 @@ export const PositionsTable = forwardRef<AgGridReact, PositionsTableProps>(
field="market.data.markPrice" field="market.data.markPrice"
type="rightAligned" type="rightAligned"
cellRenderer="PriceCell" cellRenderer="PriceCell"
valueFormatter={({ value, data }: ValueFormatterParams) => valueFormatter={({
addDecimal(value, data.market.decimalPlaces) value,
} data,
}: PositionsTableValueFormatterParams) => {
if (
data.market.data?.marketTradingMode ===
MarketTradingMode.OpeningAuction
) {
return '-';
}
return addDecimal(value, data.market.decimalPlaces);
}}
/> />
<AgGridColumn <AgGridColumn
headerName="Realised PNL" headerName="Realised PNL"