chore: remove old type gen in positions (#1619)
* chore: remove old type gen * chore: remove old type gen - small fixes Co-authored-by: maciek <maciek@vegaprotocol.io>
This commit is contained in:
parent
50d0c45d51
commit
2bf614afd2
@ -1,14 +1,15 @@
|
|||||||
import merge from 'lodash/merge';
|
import merge from 'lodash/merge';
|
||||||
import type { PartialDeep } from 'type-fest';
|
import type { PartialDeep } from 'type-fest';
|
||||||
import type {
|
import type {
|
||||||
Positions,
|
PositionsQuery,
|
||||||
Positions_party_positionsConnection_edges_node,
|
PositionFieldsFragment,
|
||||||
|
MarginsQuery,
|
||||||
} from '@vegaprotocol/positions';
|
} from '@vegaprotocol/positions';
|
||||||
|
|
||||||
export const generatePositions = (
|
export const generatePositions = (
|
||||||
override?: PartialDeep<Positions>
|
override?: PartialDeep<PositionsQuery>
|
||||||
): Positions => {
|
): PositionsQuery => {
|
||||||
const nodes: Positions_party_positionsConnection_edges_node[] = [
|
const nodes: PositionFieldsFragment[] = [
|
||||||
{
|
{
|
||||||
__typename: 'Position',
|
__typename: 'Position',
|
||||||
realisedPNL: '0',
|
realisedPNL: '0',
|
||||||
@ -47,7 +48,7 @@ export const generatePositions = (
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const defaultResult: Positions = {
|
const defaultResult: PositionsQuery = {
|
||||||
party: {
|
party: {
|
||||||
__typename: 'Party',
|
__typename: 'Party',
|
||||||
id: Cypress.env('VEGA_PUBLIC_KEY'),
|
id: Cypress.env('VEGA_PUBLIC_KEY'),
|
||||||
@ -66,7 +67,7 @@ export const generatePositions = (
|
|||||||
return merge(defaultResult, override);
|
return merge(defaultResult, override);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const emptyPositions = () => {
|
export const emptyPositions = (): PositionsQuery => {
|
||||||
return {
|
return {
|
||||||
party: {
|
party: {
|
||||||
id: Cypress.env('VEGA_PUBLIC_KEY'),
|
id: Cypress.env('VEGA_PUBLIC_KEY'),
|
||||||
@ -76,7 +77,7 @@ export const emptyPositions = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const generateMargins = () => {
|
export const generateMargins = (): MarginsQuery => {
|
||||||
return {
|
return {
|
||||||
party: {
|
party: {
|
||||||
id: Cypress.env('VEGA_PUBLIC_KEY'),
|
id: Cypress.env('VEGA_PUBLIC_KEY'),
|
||||||
@ -119,7 +120,7 @@ export const generateMargins = () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
node: {
|
node: {
|
||||||
m_typename: 'MarginLevels',
|
__typename: 'MarginLevels',
|
||||||
maintenanceLevel: '0',
|
maintenanceLevel: '0',
|
||||||
searchLevel: '0',
|
searchLevel: '0',
|
||||||
initialLevel: '0',
|
initialLevel: '0',
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import merge from 'lodash/merge';
|
import merge from 'lodash/merge';
|
||||||
import type { PartialDeep } from 'type-fest';
|
import type { PartialDeep } from 'type-fest';
|
||||||
import type {
|
import type {
|
||||||
Positions,
|
PositionsQuery,
|
||||||
Positions_party_positionsConnection_edges_node,
|
PositionFieldsFragment,
|
||||||
Margins,
|
MarginsQuery,
|
||||||
} from '@vegaprotocol/positions';
|
} from '@vegaprotocol/positions';
|
||||||
|
|
||||||
export const generatePositions = (
|
export const generatePositions = (
|
||||||
override?: PartialDeep<Positions>
|
override?: PartialDeep<PositionsQuery>
|
||||||
): Positions => {
|
): PositionsQuery => {
|
||||||
const nodes: Positions_party_positionsConnection_edges_node[] = [
|
const nodes: PositionFieldsFragment[] = [
|
||||||
{
|
{
|
||||||
__typename: 'Position',
|
__typename: 'Position',
|
||||||
realisedPNL: '0',
|
realisedPNL: '0',
|
||||||
@ -48,7 +48,7 @@ export const generatePositions = (
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const defaultResult: Positions = {
|
const defaultResult: PositionsQuery = {
|
||||||
party: {
|
party: {
|
||||||
__typename: 'Party',
|
__typename: 'Party',
|
||||||
id: Cypress.env('VEGA_PUBLIC_KEY'),
|
id: Cypress.env('VEGA_PUBLIC_KEY'),
|
||||||
@ -67,7 +67,7 @@ export const generatePositions = (
|
|||||||
return merge(defaultResult, override);
|
return merge(defaultResult, override);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const generateMargins = (): Margins => {
|
export const generateMargins = (): MarginsQuery => {
|
||||||
return {
|
return {
|
||||||
party: {
|
party: {
|
||||||
id: Cypress.env('VEGA_PUBLIC_KEY'),
|
id: Cypress.env('VEGA_PUBLIC_KEY'),
|
||||||
|
@ -15,7 +15,7 @@ import type {
|
|||||||
MarketWithData,
|
MarketWithData,
|
||||||
} from '@vegaprotocol/market-list';
|
} from '@vegaprotocol/market-list';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||||
import type { Positions_party_positionsConnection_edges_node } from '@vegaprotocol/positions';
|
import type { PositionFieldsFragment } from '@vegaprotocol/positions';
|
||||||
import { positionsDataProvider } from '@vegaprotocol/positions';
|
import { positionsDataProvider } from '@vegaprotocol/positions';
|
||||||
import {
|
import {
|
||||||
SelectMarketTableHeader,
|
SelectMarketTableHeader,
|
||||||
@ -79,7 +79,7 @@ export const SelectAllMarketsTableBody = ({
|
|||||||
tableColumns = (market) => columns(market, onSelect, onCellClick),
|
tableColumns = (market) => columns(market, onSelect, onCellClick),
|
||||||
}: {
|
}: {
|
||||||
markets?: Market[] | null;
|
markets?: Market[] | null;
|
||||||
positions?: Positions_party_positionsConnection_edges_node[];
|
positions?: PositionFieldsFragment[];
|
||||||
title?: string;
|
title?: string;
|
||||||
onSelect: (id: string) => void;
|
onSelect: (id: string) => void;
|
||||||
onCellClick: OnCellClickHandler;
|
onCellClick: OnCellClickHandler;
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
export * from './lib/__generated__/Positions';
|
export * from './lib/__generated___/Positions';
|
||||||
export * from './lib/__generated__/Margins';
|
|
||||||
export * from './lib/__generated__/PositionsSubscription';
|
|
||||||
export * from './lib/__generated__/MarginsSubscription';
|
|
||||||
export * from './lib/positions-container';
|
export * from './lib/positions-container';
|
||||||
export * from './lib/positions-data-providers';
|
export * from './lib/positions-data-providers';
|
||||||
export * from './lib/positions-table';
|
export * from './lib/positions-table';
|
||||||
|
@ -4,38 +4,8 @@ fragment PositionFields on Position {
|
|||||||
unrealisedPNL
|
unrealisedPNL
|
||||||
averageEntryPrice
|
averageEntryPrice
|
||||||
updatedAt
|
updatedAt
|
||||||
marginsConnection {
|
|
||||||
edges {
|
|
||||||
node {
|
|
||||||
market {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
maintenanceLevel
|
|
||||||
searchLevel
|
|
||||||
initialLevel
|
|
||||||
collateralReleaseLevel
|
|
||||||
asset {
|
|
||||||
symbol
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
market {
|
market {
|
||||||
id
|
id
|
||||||
decimalPlaces
|
|
||||||
positionDecimalPlaces
|
|
||||||
tradingMode
|
|
||||||
tradableInstrument {
|
|
||||||
instrument {
|
|
||||||
name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data {
|
|
||||||
markPrice
|
|
||||||
market {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,3 +32,42 @@ subscription PositionsSubscription($partyId: ID!) {
|
|||||||
marketId
|
marketId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fragment MarginFields on MarginLevels {
|
||||||
|
maintenanceLevel
|
||||||
|
searchLevel
|
||||||
|
initialLevel
|
||||||
|
collateralReleaseLevel
|
||||||
|
asset {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
market {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
query Margins($partyId: ID!) {
|
||||||
|
party(id: $partyId) {
|
||||||
|
id
|
||||||
|
marginsConnection {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
...MarginFields
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
subscription MarginsSubscription($partyId: ID!) {
|
||||||
|
margins(partyId: $partyId) {
|
||||||
|
marketId
|
||||||
|
asset
|
||||||
|
partyId
|
||||||
|
maintenanceLevel
|
||||||
|
searchLevel
|
||||||
|
initialLevel
|
||||||
|
collateralReleaseLevel
|
||||||
|
timestamp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
89
libs/positions/src/lib/__generated__/Margins.ts
generated
89
libs/positions/src/lib/__generated__/Margins.ts
generated
@ -1,89 +0,0 @@
|
|||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
// @generated
|
|
||||||
// This file was automatically generated and should not be edited.
|
|
||||||
|
|
||||||
// ====================================================
|
|
||||||
// GraphQL query operation: Margins
|
|
||||||
// ====================================================
|
|
||||||
|
|
||||||
export interface Margins_party_marginsConnection_edges_node_market {
|
|
||||||
__typename: "Market";
|
|
||||||
/**
|
|
||||||
* Market ID
|
|
||||||
*/
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Margins_party_marginsConnection_edges_node_asset {
|
|
||||||
__typename: "Asset";
|
|
||||||
/**
|
|
||||||
* The ID of the asset
|
|
||||||
*/
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Margins_party_marginsConnection_edges_node {
|
|
||||||
__typename: "MarginLevels";
|
|
||||||
/**
|
|
||||||
* Market in which the margin is required for this party
|
|
||||||
*/
|
|
||||||
market: Margins_party_marginsConnection_edges_node_market;
|
|
||||||
/**
|
|
||||||
* Minimal margin for the position to be maintained in the network (unsigned integer)
|
|
||||||
*/
|
|
||||||
maintenanceLevel: string;
|
|
||||||
/**
|
|
||||||
* If the margin is between maintenance and search, the network will initiate a collateral search (unsigned integer)
|
|
||||||
*/
|
|
||||||
searchLevel: string;
|
|
||||||
/**
|
|
||||||
* This is the minimum margin required for a party to place a new order on the network (unsigned integer)
|
|
||||||
*/
|
|
||||||
initialLevel: string;
|
|
||||||
/**
|
|
||||||
* If the margin of the party is greater than this level, then collateral will be released from the margin account into
|
|
||||||
* the general account of the party for the given asset.
|
|
||||||
*/
|
|
||||||
collateralReleaseLevel: string;
|
|
||||||
/**
|
|
||||||
* Asset for the current margins
|
|
||||||
*/
|
|
||||||
asset: Margins_party_marginsConnection_edges_node_asset;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Margins_party_marginsConnection_edges {
|
|
||||||
__typename: "MarginEdge";
|
|
||||||
node: Margins_party_marginsConnection_edges_node;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Margins_party_marginsConnection {
|
|
||||||
__typename: "MarginConnection";
|
|
||||||
/**
|
|
||||||
* The margin levels in this connection
|
|
||||||
*/
|
|
||||||
edges: Margins_party_marginsConnection_edges[] | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Margins_party {
|
|
||||||
__typename: "Party";
|
|
||||||
/**
|
|
||||||
* Party identifier
|
|
||||||
*/
|
|
||||||
id: string;
|
|
||||||
/**
|
|
||||||
* Margin levels for a market
|
|
||||||
*/
|
|
||||||
marginsConnection: Margins_party_marginsConnection | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Margins {
|
|
||||||
/**
|
|
||||||
* An entity that is trading on the Vega network
|
|
||||||
*/
|
|
||||||
party: Margins_party | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface MarginsVariables {
|
|
||||||
partyId: string;
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
// @generated
|
|
||||||
// This file was automatically generated and should not be edited.
|
|
||||||
|
|
||||||
// ====================================================
|
|
||||||
// GraphQL subscription operation: MarginsSubscription
|
|
||||||
// ====================================================
|
|
||||||
|
|
||||||
export interface MarginsSubscription_margins {
|
|
||||||
__typename: "MarginLevelsUpdate";
|
|
||||||
/**
|
|
||||||
* Market in which the margin is required for this party
|
|
||||||
*/
|
|
||||||
marketId: string;
|
|
||||||
/**
|
|
||||||
* Asset for the current margins
|
|
||||||
*/
|
|
||||||
asset: string;
|
|
||||||
/**
|
|
||||||
* The party for this margin
|
|
||||||
*/
|
|
||||||
partyId: string;
|
|
||||||
/**
|
|
||||||
* Minimal margin for the position to be maintained in the network (unsigned integer)
|
|
||||||
*/
|
|
||||||
maintenanceLevel: string;
|
|
||||||
/**
|
|
||||||
* If the margin is between maintenance and search, the network will initiate a collateral search (unsigned integer)
|
|
||||||
*/
|
|
||||||
searchLevel: string;
|
|
||||||
/**
|
|
||||||
* This is the minimum margin required for a party to place a new order on the network (unsigned integer)
|
|
||||||
*/
|
|
||||||
initialLevel: string;
|
|
||||||
/**
|
|
||||||
* If the margin of the party is greater than this level, then collateral will be released from the margin account into
|
|
||||||
* the general account of the party for the given asset.
|
|
||||||
*/
|
|
||||||
collateralReleaseLevel: string;
|
|
||||||
/**
|
|
||||||
* RFC3339Nano time from at which this margin level was relevant
|
|
||||||
*/
|
|
||||||
timestamp: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface MarginsSubscription {
|
|
||||||
/**
|
|
||||||
* Subscribe to the margin changes
|
|
||||||
*/
|
|
||||||
margins: MarginsSubscription_margins;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface MarginsSubscriptionVariables {
|
|
||||||
partyId: string;
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
// @generated
|
|
||||||
// This file was automatically generated and should not be edited.
|
|
||||||
|
|
||||||
// ====================================================
|
|
||||||
// GraphQL fragment: PositionFields
|
|
||||||
// ====================================================
|
|
||||||
|
|
||||||
export interface PositionFields_market {
|
|
||||||
__typename: "Market";
|
|
||||||
/**
|
|
||||||
* Market ID
|
|
||||||
*/
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PositionFields {
|
|
||||||
__typename: "Position";
|
|
||||||
/**
|
|
||||||
* Realised Profit and Loss (int64)
|
|
||||||
*/
|
|
||||||
realisedPNL: string;
|
|
||||||
/**
|
|
||||||
* Open volume (uint64)
|
|
||||||
*/
|
|
||||||
openVolume: string;
|
|
||||||
/**
|
|
||||||
* Unrealised Profit and Loss (int64)
|
|
||||||
*/
|
|
||||||
unrealisedPNL: string;
|
|
||||||
/**
|
|
||||||
* Average entry price for this position
|
|
||||||
*/
|
|
||||||
averageEntryPrice: string;
|
|
||||||
/**
|
|
||||||
* RFC3339Nano time the position was updated
|
|
||||||
*/
|
|
||||||
updatedAt: string | null;
|
|
||||||
/**
|
|
||||||
* Market relating to this position
|
|
||||||
*/
|
|
||||||
market: PositionFields_market;
|
|
||||||
}
|
|
83
libs/positions/src/lib/__generated__/Positions.ts
generated
83
libs/positions/src/lib/__generated__/Positions.ts
generated
@ -1,83 +0,0 @@
|
|||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
// @generated
|
|
||||||
// This file was automatically generated and should not be edited.
|
|
||||||
|
|
||||||
// ====================================================
|
|
||||||
// GraphQL query operation: Positions
|
|
||||||
// ====================================================
|
|
||||||
|
|
||||||
export interface Positions_party_positionsConnection_edges_node_market {
|
|
||||||
__typename: "Market";
|
|
||||||
/**
|
|
||||||
* Market ID
|
|
||||||
*/
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Positions_party_positionsConnection_edges_node {
|
|
||||||
__typename: "Position";
|
|
||||||
/**
|
|
||||||
* Realised Profit and Loss (int64)
|
|
||||||
*/
|
|
||||||
realisedPNL: string;
|
|
||||||
/**
|
|
||||||
* Open volume (uint64)
|
|
||||||
*/
|
|
||||||
openVolume: string;
|
|
||||||
/**
|
|
||||||
* Unrealised Profit and Loss (int64)
|
|
||||||
*/
|
|
||||||
unrealisedPNL: string;
|
|
||||||
/**
|
|
||||||
* Average entry price for this position
|
|
||||||
*/
|
|
||||||
averageEntryPrice: string;
|
|
||||||
/**
|
|
||||||
* RFC3339Nano time the position was updated
|
|
||||||
*/
|
|
||||||
updatedAt: string | null;
|
|
||||||
/**
|
|
||||||
* Market relating to this position
|
|
||||||
*/
|
|
||||||
market: Positions_party_positionsConnection_edges_node_market;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Positions_party_positionsConnection_edges {
|
|
||||||
__typename: "PositionEdge";
|
|
||||||
/**
|
|
||||||
* The position
|
|
||||||
*/
|
|
||||||
node: Positions_party_positionsConnection_edges_node;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Positions_party_positionsConnection {
|
|
||||||
__typename: "PositionConnection";
|
|
||||||
/**
|
|
||||||
* The positions in this connection
|
|
||||||
*/
|
|
||||||
edges: Positions_party_positionsConnection_edges[] | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Positions_party {
|
|
||||||
__typename: "Party";
|
|
||||||
/**
|
|
||||||
* Party identifier
|
|
||||||
*/
|
|
||||||
id: string;
|
|
||||||
/**
|
|
||||||
* Trading positions relating to a party
|
|
||||||
*/
|
|
||||||
positionsConnection: Positions_party_positionsConnection | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Positions {
|
|
||||||
/**
|
|
||||||
* An entity that is trading on the Vega network
|
|
||||||
*/
|
|
||||||
party: Positions_party | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PositionsVariables {
|
|
||||||
partyId: string;
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
// @generated
|
|
||||||
// This file was automatically generated and should not be edited.
|
|
||||||
|
|
||||||
// ====================================================
|
|
||||||
// GraphQL subscription operation: PositionsSubscription
|
|
||||||
// ====================================================
|
|
||||||
|
|
||||||
export interface PositionsSubscription_positions {
|
|
||||||
__typename: "PositionUpdate";
|
|
||||||
/**
|
|
||||||
* Realised Profit and Loss (int64)
|
|
||||||
*/
|
|
||||||
realisedPNL: string;
|
|
||||||
/**
|
|
||||||
* Open volume (uint64)
|
|
||||||
*/
|
|
||||||
openVolume: string;
|
|
||||||
/**
|
|
||||||
* Unrealised Profit and Loss (int64)
|
|
||||||
*/
|
|
||||||
unrealisedPNL: string;
|
|
||||||
/**
|
|
||||||
* Average entry price for this position
|
|
||||||
*/
|
|
||||||
averageEntryPrice: string;
|
|
||||||
/**
|
|
||||||
* RFC3339Nano time the position was updated
|
|
||||||
*/
|
|
||||||
updatedAt: string | null;
|
|
||||||
/**
|
|
||||||
* Market relating to this position
|
|
||||||
*/
|
|
||||||
marketId: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PositionsSubscription {
|
|
||||||
/**
|
|
||||||
* Subscribe to the positions updates
|
|
||||||
*/
|
|
||||||
positions: PositionsSubscription_positions[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PositionsSubscriptionVariables {
|
|
||||||
partyId: string;
|
|
||||||
}
|
|
@ -3,14 +3,14 @@ import { Schema as Types } from '@vegaprotocol/types';
|
|||||||
import { gql } from '@apollo/client';
|
import { gql } from '@apollo/client';
|
||||||
import * as Apollo from '@apollo/client';
|
import * as Apollo from '@apollo/client';
|
||||||
const defaultOptions = {} as const;
|
const defaultOptions = {} as const;
|
||||||
export type PositionFieldsFragment = { __typename?: 'Position', realisedPNL: string, openVolume: string, unrealisedPNL: string, averageEntryPrice: string, updatedAt?: string | null, marginsConnection?: { __typename?: 'MarginConnection', edges?: Array<{ __typename?: 'MarginEdge', node: { __typename?: 'MarginLevels', maintenanceLevel: string, searchLevel: string, initialLevel: string, collateralReleaseLevel: string, market: { __typename?: 'Market', id: string }, asset: { __typename?: 'Asset', symbol: string } } }> | null } | null, market: { __typename?: 'Market', id: string, decimalPlaces: number, positionDecimalPlaces: number, tradingMode: Types.MarketTradingMode, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', name: string } }, data?: { __typename?: 'MarketData', markPrice: string, market: { __typename?: 'Market', id: string } } | null } };
|
export type PositionFieldsFragment = { __typename?: 'Position', realisedPNL: string, openVolume: string, unrealisedPNL: string, averageEntryPrice: string, updatedAt?: string | null, market: { __typename?: 'Market', id: string } };
|
||||||
|
|
||||||
export type PositionsQueryVariables = Types.Exact<{
|
export type PositionsQueryVariables = Types.Exact<{
|
||||||
partyId: Types.Scalars['ID'];
|
partyId: Types.Scalars['ID'];
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
|
|
||||||
export type PositionsQuery = { __typename?: 'Query', party?: { __typename?: 'Party', id: string, positionsConnection?: { __typename?: 'PositionConnection', edges?: Array<{ __typename?: 'PositionEdge', node: { __typename?: 'Position', realisedPNL: string, openVolume: string, unrealisedPNL: string, averageEntryPrice: string, updatedAt?: string | null, marginsConnection?: { __typename?: 'MarginConnection', edges?: Array<{ __typename?: 'MarginEdge', node: { __typename?: 'MarginLevels', maintenanceLevel: string, searchLevel: string, initialLevel: string, collateralReleaseLevel: string, market: { __typename?: 'Market', id: string }, asset: { __typename?: 'Asset', symbol: string } } }> | null } | null, market: { __typename?: 'Market', id: string, decimalPlaces: number, positionDecimalPlaces: number, tradingMode: Types.MarketTradingMode, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', name: string } }, data?: { __typename?: 'MarketData', markPrice: string, market: { __typename?: 'Market', id: string } } | null } } }> | null } | null } | null };
|
export type PositionsQuery = { __typename?: 'Query', party?: { __typename?: 'Party', id: string, positionsConnection?: { __typename?: 'PositionConnection', edges?: Array<{ __typename?: 'PositionEdge', node: { __typename?: 'Position', realisedPNL: string, openVolume: string, unrealisedPNL: string, averageEntryPrice: string, updatedAt?: string | null, market: { __typename?: 'Market', id: string } } }> | null } | null } | null };
|
||||||
|
|
||||||
export type PositionsSubscriptionSubscriptionVariables = Types.Exact<{
|
export type PositionsSubscriptionSubscriptionVariables = Types.Exact<{
|
||||||
partyId: Types.Scalars['ID'];
|
partyId: Types.Scalars['ID'];
|
||||||
@ -19,6 +19,22 @@ export type PositionsSubscriptionSubscriptionVariables = Types.Exact<{
|
|||||||
|
|
||||||
export type PositionsSubscriptionSubscription = { __typename?: 'Subscription', positions: Array<{ __typename?: 'PositionUpdate', realisedPNL: string, openVolume: string, unrealisedPNL: string, averageEntryPrice: string, updatedAt?: string | null, marketId: string }> };
|
export type PositionsSubscriptionSubscription = { __typename?: 'Subscription', positions: Array<{ __typename?: 'PositionUpdate', realisedPNL: string, openVolume: string, unrealisedPNL: string, averageEntryPrice: string, updatedAt?: string | null, marketId: string }> };
|
||||||
|
|
||||||
|
export type MarginFieldsFragment = { __typename?: 'MarginLevels', maintenanceLevel: string, searchLevel: string, initialLevel: string, collateralReleaseLevel: string, asset: { __typename?: 'Asset', id: string }, market: { __typename?: 'Market', id: string } };
|
||||||
|
|
||||||
|
export type MarginsQueryVariables = Types.Exact<{
|
||||||
|
partyId: Types.Scalars['ID'];
|
||||||
|
}>;
|
||||||
|
|
||||||
|
|
||||||
|
export type MarginsQuery = { __typename?: 'Query', party?: { __typename?: 'Party', id: string, marginsConnection?: { __typename?: 'MarginConnection', edges?: Array<{ __typename?: 'MarginEdge', node: { __typename?: 'MarginLevels', maintenanceLevel: string, searchLevel: string, initialLevel: string, collateralReleaseLevel: string, asset: { __typename?: 'Asset', id: string }, market: { __typename?: 'Market', id: string } } }> | null } | null } | null };
|
||||||
|
|
||||||
|
export type MarginsSubscriptionSubscriptionVariables = Types.Exact<{
|
||||||
|
partyId: Types.Scalars['ID'];
|
||||||
|
}>;
|
||||||
|
|
||||||
|
|
||||||
|
export type MarginsSubscriptionSubscription = { __typename?: 'Subscription', margins: { __typename?: 'MarginLevelsUpdate', marketId: string, asset: string, partyId: string, maintenanceLevel: string, searchLevel: string, initialLevel: string, collateralReleaseLevel: string, timestamp: string } };
|
||||||
|
|
||||||
export const PositionFieldsFragmentDoc = gql`
|
export const PositionFieldsFragmentDoc = gql`
|
||||||
fragment PositionFields on Position {
|
fragment PositionFields on Position {
|
||||||
realisedPNL
|
realisedPNL
|
||||||
@ -26,38 +42,22 @@ export const PositionFieldsFragmentDoc = gql`
|
|||||||
unrealisedPNL
|
unrealisedPNL
|
||||||
averageEntryPrice
|
averageEntryPrice
|
||||||
updatedAt
|
updatedAt
|
||||||
marginsConnection {
|
market {
|
||||||
edges {
|
id
|
||||||
node {
|
}
|
||||||
market {
|
}
|
||||||
id
|
`;
|
||||||
}
|
export const MarginFieldsFragmentDoc = gql`
|
||||||
maintenanceLevel
|
fragment MarginFields on MarginLevels {
|
||||||
searchLevel
|
maintenanceLevel
|
||||||
initialLevel
|
searchLevel
|
||||||
collateralReleaseLevel
|
initialLevel
|
||||||
asset {
|
collateralReleaseLevel
|
||||||
symbol
|
asset {
|
||||||
}
|
id
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
market {
|
market {
|
||||||
id
|
id
|
||||||
decimalPlaces
|
|
||||||
positionDecimalPlaces
|
|
||||||
tradingMode
|
|
||||||
tradableInstrument {
|
|
||||||
instrument {
|
|
||||||
name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data {
|
|
||||||
markPrice
|
|
||||||
market {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@ -137,4 +137,83 @@ export function usePositionsSubscriptionSubscription(baseOptions: Apollo.Subscri
|
|||||||
return Apollo.useSubscription<PositionsSubscriptionSubscription, PositionsSubscriptionSubscriptionVariables>(PositionsSubscriptionDocument, options);
|
return Apollo.useSubscription<PositionsSubscriptionSubscription, PositionsSubscriptionSubscriptionVariables>(PositionsSubscriptionDocument, options);
|
||||||
}
|
}
|
||||||
export type PositionsSubscriptionSubscriptionHookResult = ReturnType<typeof usePositionsSubscriptionSubscription>;
|
export type PositionsSubscriptionSubscriptionHookResult = ReturnType<typeof usePositionsSubscriptionSubscription>;
|
||||||
export type PositionsSubscriptionSubscriptionResult = Apollo.SubscriptionResult<PositionsSubscriptionSubscription>;
|
export type PositionsSubscriptionSubscriptionResult = Apollo.SubscriptionResult<PositionsSubscriptionSubscription>;
|
||||||
|
export const MarginsDocument = gql`
|
||||||
|
query Margins($partyId: ID!) {
|
||||||
|
party(id: $partyId) {
|
||||||
|
id
|
||||||
|
marginsConnection {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
...MarginFields
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
${MarginFieldsFragmentDoc}`;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* __useMarginsQuery__
|
||||||
|
*
|
||||||
|
* To run a query within a React component, call `useMarginsQuery` and pass it any options that fit your needs.
|
||||||
|
* When your component renders, `useMarginsQuery` 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 } = useMarginsQuery({
|
||||||
|
* variables: {
|
||||||
|
* partyId: // value for 'partyId'
|
||||||
|
* },
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
export function useMarginsQuery(baseOptions: Apollo.QueryHookOptions<MarginsQuery, MarginsQueryVariables>) {
|
||||||
|
const options = {...defaultOptions, ...baseOptions}
|
||||||
|
return Apollo.useQuery<MarginsQuery, MarginsQueryVariables>(MarginsDocument, options);
|
||||||
|
}
|
||||||
|
export function useMarginsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<MarginsQuery, MarginsQueryVariables>) {
|
||||||
|
const options = {...defaultOptions, ...baseOptions}
|
||||||
|
return Apollo.useLazyQuery<MarginsQuery, MarginsQueryVariables>(MarginsDocument, options);
|
||||||
|
}
|
||||||
|
export type MarginsQueryHookResult = ReturnType<typeof useMarginsQuery>;
|
||||||
|
export type MarginsLazyQueryHookResult = ReturnType<typeof useMarginsLazyQuery>;
|
||||||
|
export type MarginsQueryResult = Apollo.QueryResult<MarginsQuery, MarginsQueryVariables>;
|
||||||
|
export const MarginsSubscriptionDocument = gql`
|
||||||
|
subscription MarginsSubscription($partyId: ID!) {
|
||||||
|
margins(partyId: $partyId) {
|
||||||
|
marketId
|
||||||
|
asset
|
||||||
|
partyId
|
||||||
|
maintenanceLevel
|
||||||
|
searchLevel
|
||||||
|
initialLevel
|
||||||
|
collateralReleaseLevel
|
||||||
|
timestamp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* __useMarginsSubscriptionSubscription__
|
||||||
|
*
|
||||||
|
* To run a query within a React component, call `useMarginsSubscriptionSubscription` and pass it any options that fit your needs.
|
||||||
|
* When your component renders, `useMarginsSubscriptionSubscription` 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 } = useMarginsSubscriptionSubscription({
|
||||||
|
* variables: {
|
||||||
|
* partyId: // value for 'partyId'
|
||||||
|
* },
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
export function useMarginsSubscriptionSubscription(baseOptions: Apollo.SubscriptionHookOptions<MarginsSubscriptionSubscription, MarginsSubscriptionSubscriptionVariables>) {
|
||||||
|
const options = {...defaultOptions, ...baseOptions}
|
||||||
|
return Apollo.useSubscription<MarginsSubscriptionSubscription, MarginsSubscriptionSubscriptionVariables>(MarginsSubscriptionDocument, options);
|
||||||
|
}
|
||||||
|
export type MarginsSubscriptionSubscriptionHookResult = ReturnType<typeof useMarginsSubscriptionSubscription>;
|
||||||
|
export type MarginsSubscriptionSubscriptionResult = Apollo.SubscriptionResult<MarginsSubscriptionSubscription>;
|
@ -1,55 +1,21 @@
|
|||||||
import { gql } from '@apollo/client';
|
|
||||||
import produce from 'immer';
|
import produce from 'immer';
|
||||||
import { makeDataProvider } from '@vegaprotocol/react-helpers';
|
import { makeDataProvider } from '@vegaprotocol/react-helpers';
|
||||||
|
import {
|
||||||
|
MarginsSubscriptionDocument,
|
||||||
|
MarginsDocument,
|
||||||
|
} from './__generated___/Positions';
|
||||||
import type {
|
import type {
|
||||||
MarginsSubscription,
|
MarginsQuery,
|
||||||
MarginsSubscription_margins,
|
MarginsSubscriptionSubscription,
|
||||||
} from './__generated__/MarginsSubscription';
|
} from './__generated___/Positions';
|
||||||
import type { Margins, Margins_party } from './__generated__/Margins';
|
|
||||||
|
|
||||||
export const MARGINS_QUERY = gql`
|
const update = (
|
||||||
query Margins($partyId: ID!) {
|
data: MarginsQuery['party'],
|
||||||
party(id: $partyId) {
|
delta: MarginsSubscriptionSubscription['margins']
|
||||||
id
|
) => {
|
||||||
marginsConnection {
|
|
||||||
edges {
|
|
||||||
node {
|
|
||||||
market {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
maintenanceLevel
|
|
||||||
searchLevel
|
|
||||||
initialLevel
|
|
||||||
collateralReleaseLevel
|
|
||||||
asset {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const MARGINS_SUBSCRIPTION = gql`
|
|
||||||
subscription MarginsSubscription($partyId: ID!) {
|
|
||||||
margins(partyId: $partyId) {
|
|
||||||
marketId
|
|
||||||
asset
|
|
||||||
partyId
|
|
||||||
maintenanceLevel
|
|
||||||
searchLevel
|
|
||||||
initialLevel
|
|
||||||
collateralReleaseLevel
|
|
||||||
timestamp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const update = (data: Margins_party, delta: MarginsSubscription_margins) => {
|
|
||||||
return produce(data, (draft) => {
|
return produce(data, (draft) => {
|
||||||
const { marketId } = delta;
|
const { marketId } = delta;
|
||||||
if (marketId && draft.marginsConnection?.edges) {
|
if (marketId && draft?.marginsConnection?.edges) {
|
||||||
const index = draft.marginsConnection.edges.findIndex(
|
const index = draft.marginsConnection.edges.findIndex(
|
||||||
(edge) => edge.node.market.id === marketId
|
(edge) => edge.node.market.id === marketId
|
||||||
);
|
);
|
||||||
@ -86,18 +52,18 @@ const update = (data: Margins_party, delta: MarginsSubscription_margins) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getData = (responseData: Margins) => responseData.party;
|
const getData = (responseData: MarginsQuery) => responseData.party;
|
||||||
const getDelta = (subscriptionData: MarginsSubscription) =>
|
const getDelta = (subscriptionData: MarginsSubscriptionSubscription) =>
|
||||||
subscriptionData.margins;
|
subscriptionData.margins;
|
||||||
|
|
||||||
export const marginsDataProvider = makeDataProvider<
|
export const marginsDataProvider = makeDataProvider<
|
||||||
Margins,
|
MarginsQuery,
|
||||||
Margins_party,
|
MarginsQuery['party'],
|
||||||
MarginsSubscription,
|
MarginsSubscriptionSubscription,
|
||||||
MarginsSubscription_margins
|
MarginsSubscriptionSubscription['margins']
|
||||||
>({
|
>({
|
||||||
query: MARGINS_QUERY,
|
query: MarginsDocument,
|
||||||
subscriptionQuery: MARGINS_SUBSCRIPTION,
|
subscriptionQuery: MarginsSubscriptionDocument,
|
||||||
update,
|
update,
|
||||||
getData,
|
getData,
|
||||||
getDelta,
|
getDelta,
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import { AccountType, MarketTradingMode } from '@vegaprotocol/types';
|
import { AccountType, MarketTradingMode } from '@vegaprotocol/types';
|
||||||
import type { Account } from '@vegaprotocol/accounts';
|
import type { Account } from '@vegaprotocol/accounts';
|
||||||
import type { Positions } from './__generated__/Positions';
|
|
||||||
import { getMetrics, rejoinPositionData } from './positions-data-providers';
|
|
||||||
import type { MarketWithData } from '@vegaprotocol/market-list';
|
import type { MarketWithData } from '@vegaprotocol/market-list';
|
||||||
import type { Margins } from './__generated__/Margins';
|
import type { PositionsQuery, MarginsQuery } from './__generated___/Positions';
|
||||||
|
import { getMetrics, rejoinPositionData } from './positions-data-providers';
|
||||||
|
|
||||||
const accounts = [
|
const accounts = [
|
||||||
{
|
{
|
||||||
@ -64,7 +63,7 @@ const accounts = [
|
|||||||
},
|
},
|
||||||
] as Account[];
|
] as Account[];
|
||||||
|
|
||||||
const positions: Positions = {
|
const positions: PositionsQuery = {
|
||||||
party: {
|
party: {
|
||||||
__typename: 'Party',
|
__typename: 'Party',
|
||||||
id: '02eceaba4df2bef76ea10caf728d8a099a2aa846cced25737cccaa9812342f65',
|
id: '02eceaba4df2bef76ea10caf728d8a099a2aa846cced25737cccaa9812342f65',
|
||||||
@ -163,7 +162,7 @@ const marketsData = [
|
|||||||
},
|
},
|
||||||
] as MarketWithData[];
|
] as MarketWithData[];
|
||||||
|
|
||||||
const margins: Margins = {
|
const margins: MarginsQuery = {
|
||||||
party: {
|
party: {
|
||||||
id: '02eceaba4df2bef76ea10caf728d8a099a2aa846cced25737cccaa9812342f65',
|
id: '02eceaba4df2bef76ea10caf728d8a099a2aa846cced25737cccaa9812342f65',
|
||||||
marginsConnection: {
|
marginsConnection: {
|
||||||
|
@ -1,37 +1,31 @@
|
|||||||
import { gql } from '@apollo/client';
|
|
||||||
import produce from 'immer';
|
import produce from 'immer';
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
import sortBy from 'lodash/sortBy';
|
import sortBy from 'lodash/sortBy';
|
||||||
import type { Account } from '@vegaprotocol/accounts';
|
import type { Account } from '@vegaprotocol/accounts';
|
||||||
import { accountsDataProvider } from '@vegaprotocol/accounts';
|
import { accountsDataProvider } from '@vegaprotocol/accounts';
|
||||||
import { toBigNum } from '@vegaprotocol/react-helpers';
|
import { toBigNum } from '@vegaprotocol/react-helpers';
|
||||||
import type {
|
|
||||||
Positions,
|
|
||||||
Positions_party,
|
|
||||||
Positions_party_positionsConnection_edges,
|
|
||||||
} from './__generated__/Positions';
|
|
||||||
import {
|
import {
|
||||||
makeDataProvider,
|
makeDataProvider,
|
||||||
makeDerivedDataProvider,
|
makeDerivedDataProvider,
|
||||||
} from '@vegaprotocol/react-helpers';
|
} from '@vegaprotocol/react-helpers';
|
||||||
|
|
||||||
import type {
|
|
||||||
PositionsSubscription,
|
|
||||||
PositionsSubscription_positions,
|
|
||||||
} from './__generated__/PositionsSubscription';
|
|
||||||
|
|
||||||
import { AccountType } from '@vegaprotocol/types';
|
import { AccountType } from '@vegaprotocol/types';
|
||||||
import type { MarketTradingMode } from '@vegaprotocol/types';
|
import type { MarketTradingMode } from '@vegaprotocol/types';
|
||||||
import type { MarketWithData } from '@vegaprotocol/market-list';
|
import type { MarketWithData } from '@vegaprotocol/market-list';
|
||||||
import { marketsWithDataProvider } from '@vegaprotocol/market-list';
|
import { marketsWithDataProvider } from '@vegaprotocol/market-list';
|
||||||
import { marginsDataProvider } from './margin-data-provider';
|
|
||||||
import type {
|
import type {
|
||||||
Margins_party,
|
PositionsQuery,
|
||||||
Margins_party_marginsConnection_edges_node,
|
PositionsSubscriptionSubscription,
|
||||||
} from './__generated__/Margins';
|
MarginsQuery,
|
||||||
|
MarginFieldsFragment,
|
||||||
|
} from './__generated___/Positions';
|
||||||
|
import {
|
||||||
|
PositionsDocument,
|
||||||
|
PositionsSubscriptionDocument,
|
||||||
|
} from './__generated___/Positions';
|
||||||
|
import { marginsDataProvider } from './margin-data-provider';
|
||||||
|
|
||||||
type PositionMarginLevel = Pick<
|
type PositionMarginLevel = Pick<
|
||||||
Margins_party_marginsConnection_edges_node,
|
MarginFieldsFragment,
|
||||||
'maintenanceLevel' | 'searchLevel' | 'initialLevel'
|
'maintenanceLevel' | 'searchLevel' | 'initialLevel'
|
||||||
>;
|
>;
|
||||||
|
|
||||||
@ -40,7 +34,7 @@ interface PositionRejoined {
|
|||||||
openVolume: string;
|
openVolume: string;
|
||||||
unrealisedPNL: string;
|
unrealisedPNL: string;
|
||||||
averageEntryPrice: string;
|
averageEntryPrice: string;
|
||||||
updatedAt: string | null;
|
updatedAt?: string | null;
|
||||||
market: MarketWithData | null;
|
market: MarketWithData | null;
|
||||||
margins: PositionMarginLevel | null;
|
margins: PositionMarginLevel | null;
|
||||||
}
|
}
|
||||||
@ -69,52 +63,10 @@ export interface Position {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Data {
|
export interface Data {
|
||||||
party: Positions_party | null;
|
party: PositionsQuery['party'] | null;
|
||||||
positions: Position[] | null;
|
positions: Position[] | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const POSITION_FIELDS = gql`
|
|
||||||
fragment PositionFields on Position {
|
|
||||||
realisedPNL
|
|
||||||
openVolume
|
|
||||||
unrealisedPNL
|
|
||||||
averageEntryPrice
|
|
||||||
updatedAt
|
|
||||||
market {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const POSITIONS_QUERY = gql`
|
|
||||||
${POSITION_FIELDS}
|
|
||||||
query Positions($partyId: ID!) {
|
|
||||||
party(id: $partyId) {
|
|
||||||
id
|
|
||||||
positionsConnection {
|
|
||||||
edges {
|
|
||||||
node {
|
|
||||||
...PositionFields
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const POSITIONS_SUBSCRIPTION = gql`
|
|
||||||
subscription PositionsSubscription($partyId: ID!) {
|
|
||||||
positions(partyId: $partyId) {
|
|
||||||
realisedPNL
|
|
||||||
openVolume
|
|
||||||
unrealisedPNL
|
|
||||||
averageEntryPrice
|
|
||||||
updatedAt
|
|
||||||
marketId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const getMetrics = (
|
export const getMetrics = (
|
||||||
data: PositionRejoined[] | null,
|
data: PositionRejoined[] | null,
|
||||||
accounts: Account[] | null
|
accounts: Account[] | null
|
||||||
@ -221,19 +173,19 @@ export const getMetrics = (
|
|||||||
searchPrice: searchPrice
|
searchPrice: searchPrice
|
||||||
.multipliedBy(10 ** marketDecimalPlaces)
|
.multipliedBy(10 ** marketDecimalPlaces)
|
||||||
.toFixed(0),
|
.toFixed(0),
|
||||||
updatedAt: position.updatedAt,
|
updatedAt: position.updatedAt || null,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return metrics;
|
return metrics;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const update = (
|
export const update = (
|
||||||
data: Positions_party,
|
data: PositionsQuery['party'],
|
||||||
deltas: PositionsSubscription_positions[]
|
deltas: PositionsSubscriptionSubscription['positions']
|
||||||
) => {
|
) => {
|
||||||
return produce(data, (draft) => {
|
return produce(data, (draft) => {
|
||||||
deltas.forEach((delta) => {
|
deltas.forEach((delta) => {
|
||||||
if (!draft.positionsConnection?.edges || !delta) {
|
if (!draft?.positionsConnection?.edges || !delta) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const index = draft.positionsConnection.edges.findIndex(
|
const index = draft.positionsConnection.edges.findIndex(
|
||||||
@ -267,22 +219,22 @@ export const update = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const positionsDataProvider = makeDataProvider<
|
export const positionsDataProvider = makeDataProvider<
|
||||||
Positions,
|
PositionsQuery,
|
||||||
Positions_party,
|
PositionsQuery['party'],
|
||||||
PositionsSubscription,
|
PositionsSubscriptionSubscription,
|
||||||
PositionsSubscription_positions[]
|
PositionsSubscriptionSubscription['positions']
|
||||||
>({
|
>({
|
||||||
query: POSITIONS_QUERY,
|
query: PositionsDocument,
|
||||||
subscriptionQuery: POSITIONS_SUBSCRIPTION,
|
subscriptionQuery: PositionsSubscriptionDocument,
|
||||||
update,
|
update,
|
||||||
getData: (responseData: Positions) => responseData.party,
|
getData: (responseData: PositionsQuery) => responseData.party,
|
||||||
getDelta: (subscriptionData: PositionsSubscription) =>
|
getDelta: (subscriptionData: PositionsSubscriptionSubscription) =>
|
||||||
subscriptionData.positions,
|
subscriptionData.positions,
|
||||||
});
|
});
|
||||||
|
|
||||||
const upgradeMarginsConection = (
|
const upgradeMarginsConection = (
|
||||||
marketId: string,
|
marketId: string,
|
||||||
margins: Margins_party | null
|
margins: MarginsQuery['party'] | null
|
||||||
) => {
|
) => {
|
||||||
if (marketId && margins?.marginsConnection?.edges) {
|
if (marketId && margins?.marginsConnection?.edges) {
|
||||||
const index =
|
const index =
|
||||||
@ -302,26 +254,23 @@ const upgradeMarginsConection = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const rejoinPositionData = (
|
export const rejoinPositionData = (
|
||||||
positions: Positions_party | null,
|
positions: PositionsQuery['party'] | null,
|
||||||
marketsData: MarketWithData[] | null,
|
marketsData: MarketWithData[] | null,
|
||||||
margins: Margins_party | null
|
margins: MarginsQuery['party'] | null
|
||||||
): PositionRejoined[] | null => {
|
): PositionRejoined[] | null => {
|
||||||
if (positions?.positionsConnection?.edges && marketsData && margins) {
|
if (positions?.positionsConnection?.edges && marketsData && margins) {
|
||||||
return positions.positionsConnection.edges.map(
|
return positions.positionsConnection.edges.map(({ node }) => {
|
||||||
(nodes: Positions_party_positionsConnection_edges) => {
|
return {
|
||||||
return {
|
realisedPNL: node.realisedPNL,
|
||||||
realisedPNL: nodes.node.realisedPNL,
|
openVolume: node.openVolume,
|
||||||
openVolume: nodes.node.openVolume,
|
unrealisedPNL: node.unrealisedPNL,
|
||||||
unrealisedPNL: nodes.node.unrealisedPNL,
|
averageEntryPrice: node.averageEntryPrice,
|
||||||
averageEntryPrice: nodes.node.averageEntryPrice,
|
updatedAt: node.updatedAt,
|
||||||
updatedAt: nodes.node.updatedAt,
|
market:
|
||||||
market:
|
marketsData?.find((market) => market.id === node.market.id) || null,
|
||||||
marketsData?.find((market) => market.id === nodes.node.market.id) ||
|
margins: upgradeMarginsConection(node.market.id, margins),
|
||||||
null,
|
};
|
||||||
margins: upgradeMarginsConection(nodes.node.market.id, margins),
|
});
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user