[#128] Add positions data provider
This commit is contained in:
parent
95f66ccd9b
commit
936ed3f9e7
@ -4,6 +4,6 @@ module.exports = {
|
||||
name: 'vega',
|
||||
url: process.env.NX_VEGA_URL,
|
||||
},
|
||||
includes: ['../../{apps,lib}/**/*.{ts,tsx,js,jsx,graphql}'],
|
||||
includes: ['../../{apps,libs}/**/*.{ts,tsx,js,jsx,graphql}'],
|
||||
},
|
||||
};
|
||||
|
149
libs/graphql/src/__generated__/PositionDetails.ts
generated
Normal file
149
libs/graphql/src/__generated__/PositionDetails.ts
generated
Normal file
@ -0,0 +1,149 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @generated
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
// ====================================================
|
||||
// GraphQL fragment: PositionDetails
|
||||
// ====================================================
|
||||
|
||||
export interface PositionDetails_market_data {
|
||||
__typename: "MarketData";
|
||||
/**
|
||||
* the mark price (actually an unsigned int)
|
||||
*/
|
||||
markPrice: string;
|
||||
}
|
||||
|
||||
export interface PositionDetails_market_tradableInstrument_instrument_metadata {
|
||||
__typename: "InstrumentMetadata";
|
||||
/**
|
||||
* An arbitrary list of tags to associated to associate to the Instrument (string list)
|
||||
*/
|
||||
tags: string[] | null;
|
||||
}
|
||||
|
||||
export interface PositionDetails_market_tradableInstrument_instrument_product_settlementAsset {
|
||||
__typename: "Asset";
|
||||
/**
|
||||
* The id of the asset
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* The symbol of the asset (e.g: GBP)
|
||||
*/
|
||||
symbol: string;
|
||||
/**
|
||||
* The full name of the asset (e.g: Great British Pound)
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* The precision of the asset
|
||||
*/
|
||||
decimals: number;
|
||||
}
|
||||
|
||||
export interface PositionDetails_market_tradableInstrument_instrument_product {
|
||||
__typename: "Future";
|
||||
/**
|
||||
* The name of the asset (string)
|
||||
*/
|
||||
settlementAsset: PositionDetails_market_tradableInstrument_instrument_product_settlementAsset;
|
||||
/**
|
||||
* String representing the quote (e.g. BTCUSD -> USD is quote)
|
||||
*/
|
||||
quoteName: string;
|
||||
}
|
||||
|
||||
export interface PositionDetails_market_tradableInstrument_instrument {
|
||||
__typename: "Instrument";
|
||||
/**
|
||||
* Uniquely identify an instrument across all instruments available on Vega (string)
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* Full and fairly descriptive name for the instrument
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Metadata for this instrument
|
||||
*/
|
||||
metadata: PositionDetails_market_tradableInstrument_instrument_metadata;
|
||||
/**
|
||||
* A short non necessarily unique code used to easily describe the instrument (e.g: FX:BTCUSD/DEC18) (string)
|
||||
*/
|
||||
code: string;
|
||||
/**
|
||||
* A reference to or instance of a fully specified product, including all required product parameters for that product (Product union)
|
||||
*/
|
||||
product: PositionDetails_market_tradableInstrument_instrument_product;
|
||||
}
|
||||
|
||||
export interface PositionDetails_market_tradableInstrument {
|
||||
__typename: "TradableInstrument";
|
||||
/**
|
||||
* An instance of or reference to a fully specified instrument.
|
||||
*/
|
||||
instrument: PositionDetails_market_tradableInstrument_instrument;
|
||||
}
|
||||
|
||||
export interface PositionDetails_market {
|
||||
__typename: "Market";
|
||||
/**
|
||||
* Market ID
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* Market full name
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* marketData for the given market
|
||||
*/
|
||||
data: PositionDetails_market_data | null;
|
||||
/**
|
||||
* decimalPlaces indicates 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;
|
||||
/**
|
||||
* An instance of or reference to a tradable instrument.
|
||||
*/
|
||||
tradableInstrument: PositionDetails_market_tradableInstrument;
|
||||
}
|
||||
|
||||
export interface PositionDetails {
|
||||
__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;
|
||||
/**
|
||||
* Market relating to this position
|
||||
*/
|
||||
market: PositionDetails_market;
|
||||
}
|
160
libs/graphql/src/__generated__/positionSubscribe.ts
generated
Normal file
160
libs/graphql/src/__generated__/positionSubscribe.ts
generated
Normal file
@ -0,0 +1,160 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @generated
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
// ====================================================
|
||||
// GraphQL subscription operation: positionSubscribe
|
||||
// ====================================================
|
||||
|
||||
export interface positionSubscribe_positions_market_data {
|
||||
__typename: "MarketData";
|
||||
/**
|
||||
* the mark price (actually an unsigned int)
|
||||
*/
|
||||
markPrice: string;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions_market_tradableInstrument_instrument_metadata {
|
||||
__typename: "InstrumentMetadata";
|
||||
/**
|
||||
* An arbitrary list of tags to associated to associate to the Instrument (string list)
|
||||
*/
|
||||
tags: string[] | null;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions_market_tradableInstrument_instrument_product_settlementAsset {
|
||||
__typename: "Asset";
|
||||
/**
|
||||
* The id of the asset
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* The symbol of the asset (e.g: GBP)
|
||||
*/
|
||||
symbol: string;
|
||||
/**
|
||||
* The full name of the asset (e.g: Great British Pound)
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* The precision of the asset
|
||||
*/
|
||||
decimals: number;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions_market_tradableInstrument_instrument_product {
|
||||
__typename: "Future";
|
||||
/**
|
||||
* The name of the asset (string)
|
||||
*/
|
||||
settlementAsset: positionSubscribe_positions_market_tradableInstrument_instrument_product_settlementAsset;
|
||||
/**
|
||||
* String representing the quote (e.g. BTCUSD -> USD is quote)
|
||||
*/
|
||||
quoteName: string;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions_market_tradableInstrument_instrument {
|
||||
__typename: "Instrument";
|
||||
/**
|
||||
* Uniquely identify an instrument across all instruments available on Vega (string)
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* Full and fairly descriptive name for the instrument
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Metadata for this instrument
|
||||
*/
|
||||
metadata: positionSubscribe_positions_market_tradableInstrument_instrument_metadata;
|
||||
/**
|
||||
* A short non necessarily unique code used to easily describe the instrument (e.g: FX:BTCUSD/DEC18) (string)
|
||||
*/
|
||||
code: string;
|
||||
/**
|
||||
* A reference to or instance of a fully specified product, including all required product parameters for that product (Product union)
|
||||
*/
|
||||
product: positionSubscribe_positions_market_tradableInstrument_instrument_product;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions_market_tradableInstrument {
|
||||
__typename: "TradableInstrument";
|
||||
/**
|
||||
* An instance of or reference to a fully specified instrument.
|
||||
*/
|
||||
instrument: positionSubscribe_positions_market_tradableInstrument_instrument;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions_market {
|
||||
__typename: "Market";
|
||||
/**
|
||||
* Market ID
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* Market full name
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* marketData for the given market
|
||||
*/
|
||||
data: positionSubscribe_positions_market_data | null;
|
||||
/**
|
||||
* decimalPlaces indicates 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;
|
||||
/**
|
||||
* An instance of or reference to a tradable instrument.
|
||||
*/
|
||||
tradableInstrument: positionSubscribe_positions_market_tradableInstrument;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions {
|
||||
__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;
|
||||
/**
|
||||
* Market relating to this position
|
||||
*/
|
||||
market: positionSubscribe_positions_market;
|
||||
}
|
||||
|
||||
export interface positionSubscribe {
|
||||
/**
|
||||
* Subscribe to the positions updates
|
||||
*/
|
||||
positions: positionSubscribe_positions;
|
||||
}
|
||||
|
||||
export interface positionSubscribeVariables {
|
||||
partyId: string;
|
||||
}
|
172
libs/graphql/src/__generated__/positions.ts
generated
Normal file
172
libs/graphql/src/__generated__/positions.ts
generated
Normal file
@ -0,0 +1,172 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @generated
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
// ====================================================
|
||||
// GraphQL query operation: positions
|
||||
// ====================================================
|
||||
|
||||
export interface positions_party_positions_market_data {
|
||||
__typename: "MarketData";
|
||||
/**
|
||||
* the mark price (actually an unsigned int)
|
||||
*/
|
||||
markPrice: string;
|
||||
}
|
||||
|
||||
export interface positions_party_positions_market_tradableInstrument_instrument_metadata {
|
||||
__typename: "InstrumentMetadata";
|
||||
/**
|
||||
* An arbitrary list of tags to associated to associate to the Instrument (string list)
|
||||
*/
|
||||
tags: string[] | null;
|
||||
}
|
||||
|
||||
export interface positions_party_positions_market_tradableInstrument_instrument_product_settlementAsset {
|
||||
__typename: "Asset";
|
||||
/**
|
||||
* The id of the asset
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* The symbol of the asset (e.g: GBP)
|
||||
*/
|
||||
symbol: string;
|
||||
/**
|
||||
* The full name of the asset (e.g: Great British Pound)
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* The precision of the asset
|
||||
*/
|
||||
decimals: number;
|
||||
}
|
||||
|
||||
export interface positions_party_positions_market_tradableInstrument_instrument_product {
|
||||
__typename: "Future";
|
||||
/**
|
||||
* The name of the asset (string)
|
||||
*/
|
||||
settlementAsset: positions_party_positions_market_tradableInstrument_instrument_product_settlementAsset;
|
||||
/**
|
||||
* String representing the quote (e.g. BTCUSD -> USD is quote)
|
||||
*/
|
||||
quoteName: string;
|
||||
}
|
||||
|
||||
export interface positions_party_positions_market_tradableInstrument_instrument {
|
||||
__typename: "Instrument";
|
||||
/**
|
||||
* Uniquely identify an instrument across all instruments available on Vega (string)
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* Full and fairly descriptive name for the instrument
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Metadata for this instrument
|
||||
*/
|
||||
metadata: positions_party_positions_market_tradableInstrument_instrument_metadata;
|
||||
/**
|
||||
* A short non necessarily unique code used to easily describe the instrument (e.g: FX:BTCUSD/DEC18) (string)
|
||||
*/
|
||||
code: string;
|
||||
/**
|
||||
* A reference to or instance of a fully specified product, including all required product parameters for that product (Product union)
|
||||
*/
|
||||
product: positions_party_positions_market_tradableInstrument_instrument_product;
|
||||
}
|
||||
|
||||
export interface positions_party_positions_market_tradableInstrument {
|
||||
__typename: "TradableInstrument";
|
||||
/**
|
||||
* An instance of or reference to a fully specified instrument.
|
||||
*/
|
||||
instrument: positions_party_positions_market_tradableInstrument_instrument;
|
||||
}
|
||||
|
||||
export interface positions_party_positions_market {
|
||||
__typename: "Market";
|
||||
/**
|
||||
* Market ID
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* Market full name
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* marketData for the given market
|
||||
*/
|
||||
data: positions_party_positions_market_data | null;
|
||||
/**
|
||||
* decimalPlaces indicates 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;
|
||||
/**
|
||||
* An instance of or reference to a tradable instrument.
|
||||
*/
|
||||
tradableInstrument: positions_party_positions_market_tradableInstrument;
|
||||
}
|
||||
|
||||
export interface positions_party_positions {
|
||||
__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;
|
||||
/**
|
||||
* Market relating to this position
|
||||
*/
|
||||
market: positions_party_positions_market;
|
||||
}
|
||||
|
||||
export interface positions_party {
|
||||
__typename: "Party";
|
||||
/**
|
||||
* Party identifier
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* Trading positions relating to a party
|
||||
*/
|
||||
positions: positions_party_positions[] | null;
|
||||
}
|
||||
|
||||
export interface positions {
|
||||
/**
|
||||
* An entity that is trading on the VEGA network
|
||||
*/
|
||||
party: positions_party | null;
|
||||
}
|
||||
|
||||
export interface positionsVariables {
|
||||
partyId: string;
|
||||
}
|
@ -1 +1,2 @@
|
||||
export * from './markets-data-provider';
|
||||
export * from './positions-data-provider';
|
||||
|
98
libs/graphql/src/data-providers/positions-data-provider.ts
Normal file
98
libs/graphql/src/data-providers/positions-data-provider.ts
Normal file
@ -0,0 +1,98 @@
|
||||
import { gql } from '@apollo/client';
|
||||
import {
|
||||
positions,
|
||||
positions_party_positions,
|
||||
} from '../__generated__/positions';
|
||||
import { makeDataProvider } from './generic-data-provider';
|
||||
|
||||
import {
|
||||
positionSubscribe,
|
||||
positionSubscribe_positions,
|
||||
} from '../__generated__/positionSubscribe';
|
||||
|
||||
const POSITIONS_FRAGMENT = gql`
|
||||
fragment PositionDetails on Position {
|
||||
realisedPNL
|
||||
openVolume
|
||||
unrealisedPNL
|
||||
averageEntryPrice
|
||||
market {
|
||||
id
|
||||
name
|
||||
data {
|
||||
markPrice
|
||||
}
|
||||
decimalPlaces
|
||||
tradableInstrument {
|
||||
instrument {
|
||||
id
|
||||
name
|
||||
metadata {
|
||||
tags
|
||||
}
|
||||
code
|
||||
product {
|
||||
... on Future {
|
||||
settlementAsset {
|
||||
id
|
||||
symbol
|
||||
name
|
||||
decimals
|
||||
}
|
||||
quoteName
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const POSITION_QUERY = gql`
|
||||
${POSITIONS_FRAGMENT}
|
||||
query positions($partyId: ID!) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
positions {
|
||||
...PositionDetails
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const POSITIONS_SUB = gql`
|
||||
${POSITIONS_FRAGMENT}
|
||||
subscription positionSubscribe($partyId: ID!) {
|
||||
positions(partyId: $partyId) {
|
||||
...PositionDetails
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const positionsDataProvider = makeDataProvider<
|
||||
positions,
|
||||
positions_party_positions,
|
||||
positionSubscribe,
|
||||
positionSubscribe_positions
|
||||
>(
|
||||
POSITION_QUERY,
|
||||
POSITIONS_SUB,
|
||||
(
|
||||
draft: positions_party_positions[] | null,
|
||||
delta: positionSubscribe_positions
|
||||
) => {
|
||||
if (!draft) {
|
||||
return;
|
||||
}
|
||||
const index = draft.findIndex((m) => m.market.id === delta.market.id);
|
||||
if (index !== -1) {
|
||||
draft[index] = delta;
|
||||
} else {
|
||||
draft.push(delta);
|
||||
}
|
||||
},
|
||||
(responseData: positions): positions_party_positions[] | null =>
|
||||
responseData.party ? responseData.party.positions : null,
|
||||
(subscriptionData: positionSubscribe): positionSubscribe_positions =>
|
||||
subscriptionData.positions
|
||||
);
|
Loading…
Reference in New Issue
Block a user