2022-11-02 07:01:40 +00:00
|
|
|
import isEqual from 'lodash/isEqual';
|
2022-08-16 07:18:55 +00:00
|
|
|
import produce from 'immer';
|
|
|
|
import BigNumber from 'bignumber.js';
|
|
|
|
import sortBy from 'lodash/sortBy';
|
2022-10-04 08:37:31 +00:00
|
|
|
import type { Account } from '@vegaprotocol/accounts';
|
2022-08-26 15:39:40 +00:00
|
|
|
import { accountsDataProvider } from '@vegaprotocol/accounts';
|
|
|
|
import { toBigNum } from '@vegaprotocol/react-helpers';
|
|
|
|
import {
|
|
|
|
makeDataProvider,
|
|
|
|
makeDerivedDataProvider,
|
|
|
|
} from '@vegaprotocol/react-helpers';
|
2022-08-16 07:18:55 +00:00
|
|
|
import { AccountType } from '@vegaprotocol/types';
|
|
|
|
import type { MarketTradingMode } from '@vegaprotocol/types';
|
2022-10-04 08:37:31 +00:00
|
|
|
import type { MarketWithData } from '@vegaprotocol/market-list';
|
|
|
|
import { marketsWithDataProvider } from '@vegaprotocol/market-list';
|
|
|
|
import type {
|
2022-10-05 09:30:42 +00:00
|
|
|
PositionsQuery,
|
|
|
|
PositionsSubscriptionSubscription,
|
|
|
|
MarginsQuery,
|
|
|
|
MarginFieldsFragment,
|
|
|
|
} from './__generated___/Positions';
|
|
|
|
import {
|
|
|
|
PositionsDocument,
|
|
|
|
PositionsSubscriptionDocument,
|
|
|
|
} from './__generated___/Positions';
|
|
|
|
import { marginsDataProvider } from './margin-data-provider';
|
2022-10-04 08:37:31 +00:00
|
|
|
|
|
|
|
type PositionMarginLevel = Pick<
|
2022-10-05 09:30:42 +00:00
|
|
|
MarginFieldsFragment,
|
2022-10-04 08:37:31 +00:00
|
|
|
'maintenanceLevel' | 'searchLevel' | 'initialLevel'
|
|
|
|
>;
|
|
|
|
|
|
|
|
interface PositionRejoined {
|
|
|
|
realisedPNL: string;
|
|
|
|
openVolume: string;
|
|
|
|
unrealisedPNL: string;
|
|
|
|
averageEntryPrice: string;
|
2022-10-05 09:30:42 +00:00
|
|
|
updatedAt?: string | null;
|
2022-10-04 08:37:31 +00:00
|
|
|
market: MarketWithData | null;
|
|
|
|
margins: PositionMarginLevel | null;
|
|
|
|
}
|
2022-08-16 07:18:55 +00:00
|
|
|
|
|
|
|
export interface Position {
|
|
|
|
marketName: string;
|
|
|
|
averageEntryPrice: string;
|
2022-11-02 07:01:40 +00:00
|
|
|
marginAccountBalance: string;
|
2022-08-16 07:18:55 +00:00
|
|
|
capitalUtilisation: number;
|
|
|
|
currentLeverage: number;
|
2022-09-02 20:53:00 +00:00
|
|
|
decimals: number;
|
2022-08-16 07:18:55 +00:00
|
|
|
marketDecimalPlaces: number;
|
|
|
|
positionDecimalPlaces: number;
|
|
|
|
totalBalance: string;
|
|
|
|
assetSymbol: string;
|
|
|
|
liquidationPrice: string;
|
|
|
|
lowMarginLevel: boolean;
|
|
|
|
marketId: string;
|
|
|
|
marketTradingMode: MarketTradingMode;
|
|
|
|
markPrice: string;
|
|
|
|
notional: string;
|
|
|
|
openVolume: string;
|
|
|
|
realisedPNL: string;
|
|
|
|
unrealisedPNL: string;
|
|
|
|
searchPrice: string;
|
|
|
|
updatedAt: string | null;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Data {
|
2022-10-05 09:30:42 +00:00
|
|
|
party: PositionsQuery['party'] | null;
|
2022-08-16 07:18:55 +00:00
|
|
|
positions: Position[] | null;
|
|
|
|
}
|
|
|
|
|
2022-08-26 15:39:40 +00:00
|
|
|
export const getMetrics = (
|
2022-10-04 08:37:31 +00:00
|
|
|
data: PositionRejoined[] | null,
|
|
|
|
accounts: Account[] | null
|
2022-08-26 15:39:40 +00:00
|
|
|
): Position[] => {
|
2022-10-04 08:37:31 +00:00
|
|
|
if (!data || !data?.length) {
|
2022-08-16 07:18:55 +00:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
const metrics: Position[] = [];
|
2022-10-04 08:37:31 +00:00
|
|
|
data.forEach((position) => {
|
|
|
|
const market = position.market;
|
|
|
|
const marketData = market?.data;
|
|
|
|
const marginLevel = position.margins;
|
2022-08-26 15:39:40 +00:00
|
|
|
const marginAccount = accounts?.find((account) => {
|
2022-10-04 08:37:31 +00:00
|
|
|
return account.market?.id === market?.id;
|
2022-08-26 15:39:40 +00:00
|
|
|
});
|
2022-09-02 20:53:00 +00:00
|
|
|
if (
|
|
|
|
!marginAccount ||
|
|
|
|
!marginLevel ||
|
2022-10-04 08:37:31 +00:00
|
|
|
!market ||
|
2022-09-02 20:53:00 +00:00
|
|
|
!marketData ||
|
2022-10-04 08:37:31 +00:00
|
|
|
position.openVolume === '0'
|
2022-09-02 20:53:00 +00:00
|
|
|
) {
|
2022-08-16 07:18:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-08-26 15:39:40 +00:00
|
|
|
const generalAccount = accounts?.find(
|
2022-08-16 07:18:55 +00:00
|
|
|
(account) =>
|
|
|
|
account.asset.id === marginAccount.asset.id &&
|
2022-08-22 22:50:13 +00:00
|
|
|
account.type === AccountType.ACCOUNT_TYPE_GENERAL
|
2022-08-16 07:18:55 +00:00
|
|
|
);
|
2022-09-02 20:53:00 +00:00
|
|
|
const decimals = marginAccount.asset.decimals;
|
2022-08-16 07:18:55 +00:00
|
|
|
const { positionDecimalPlaces, decimalPlaces: marketDecimalPlaces } =
|
|
|
|
market;
|
2022-10-04 08:37:31 +00:00
|
|
|
const openVolume = toBigNum(position.openVolume, positionDecimalPlaces);
|
2022-08-16 07:18:55 +00:00
|
|
|
|
2022-09-02 20:53:00 +00:00
|
|
|
const marginAccountBalance = toBigNum(marginAccount.balance ?? 0, decimals);
|
2022-08-26 15:39:40 +00:00
|
|
|
const generalAccountBalance = toBigNum(
|
|
|
|
generalAccount?.balance ?? 0,
|
2022-09-02 20:53:00 +00:00
|
|
|
decimals
|
2022-08-16 07:18:55 +00:00
|
|
|
);
|
2022-08-26 15:39:40 +00:00
|
|
|
const markPrice = toBigNum(marketData.markPrice, marketDecimalPlaces);
|
2022-08-16 07:18:55 +00:00
|
|
|
|
|
|
|
const notional = (
|
|
|
|
openVolume.isGreaterThan(0) ? openVolume : openVolume.multipliedBy(-1)
|
|
|
|
).multipliedBy(markPrice);
|
|
|
|
const totalBalance = marginAccountBalance.plus(generalAccountBalance);
|
|
|
|
const currentLeverage = totalBalance.isEqualTo(0)
|
|
|
|
? new BigNumber(0)
|
|
|
|
: notional.dividedBy(totalBalance);
|
|
|
|
const capitalUtilisation = totalBalance.isEqualTo(0)
|
|
|
|
? new BigNumber(0)
|
|
|
|
: marginAccountBalance.dividedBy(totalBalance).multipliedBy(100);
|
|
|
|
|
2022-08-26 15:39:40 +00:00
|
|
|
const marginMaintenance = toBigNum(
|
|
|
|
marginLevel.maintenanceLevel,
|
2022-08-16 07:18:55 +00:00
|
|
|
marketDecimalPlaces
|
|
|
|
);
|
2022-08-26 15:39:40 +00:00
|
|
|
const marginSearch = toBigNum(marginLevel.searchLevel, marketDecimalPlaces);
|
|
|
|
const marginInitial = toBigNum(
|
|
|
|
marginLevel.initialLevel,
|
2022-08-16 07:18:55 +00:00
|
|
|
marketDecimalPlaces
|
|
|
|
);
|
|
|
|
|
2022-09-02 20:53:00 +00:00
|
|
|
const searchPrice = marginSearch
|
|
|
|
.minus(marginAccountBalance)
|
|
|
|
.dividedBy(openVolume)
|
|
|
|
.plus(markPrice);
|
|
|
|
|
|
|
|
const liquidationPrice = BigNumber.maximum(
|
|
|
|
0,
|
|
|
|
marginMaintenance
|
|
|
|
.minus(marginAccountBalance)
|
|
|
|
.minus(generalAccountBalance)
|
|
|
|
.dividedBy(openVolume)
|
|
|
|
.plus(markPrice)
|
|
|
|
);
|
2022-08-16 07:18:55 +00:00
|
|
|
|
|
|
|
const lowMarginLevel =
|
|
|
|
marginAccountBalance.isLessThan(
|
|
|
|
marginSearch.plus(marginInitial.minus(marginSearch).dividedBy(2))
|
|
|
|
) && generalAccountBalance.isLessThan(marginInitial.minus(marginSearch));
|
|
|
|
|
|
|
|
metrics.push({
|
2022-09-07 18:37:39 +00:00
|
|
|
marketName: market.tradableInstrument.instrument.name,
|
2022-10-04 08:37:31 +00:00
|
|
|
averageEntryPrice: position.averageEntryPrice,
|
2022-11-02 07:01:40 +00:00
|
|
|
marginAccountBalance: marginAccount.balance,
|
2022-08-16 07:18:55 +00:00
|
|
|
capitalUtilisation: Math.round(capitalUtilisation.toNumber()),
|
|
|
|
currentLeverage: currentLeverage.toNumber(),
|
|
|
|
marketDecimalPlaces,
|
|
|
|
positionDecimalPlaces,
|
2022-09-02 20:53:00 +00:00
|
|
|
decimals,
|
2022-10-04 08:37:31 +00:00
|
|
|
assetSymbol:
|
|
|
|
market.tradableInstrument.instrument.product.settlementAsset.symbol,
|
2022-09-02 20:53:00 +00:00
|
|
|
totalBalance: totalBalance.multipliedBy(10 ** decimals).toFixed(),
|
2022-08-16 07:18:55 +00:00
|
|
|
lowMarginLevel,
|
|
|
|
liquidationPrice: liquidationPrice
|
|
|
|
.multipliedBy(10 ** marketDecimalPlaces)
|
|
|
|
.toFixed(0),
|
2022-10-04 08:37:31 +00:00
|
|
|
marketId: market.id,
|
|
|
|
marketTradingMode: market.tradingMode,
|
2022-08-16 07:18:55 +00:00
|
|
|
markPrice: marketData.markPrice,
|
|
|
|
notional: notional.multipliedBy(10 ** marketDecimalPlaces).toFixed(0),
|
2022-10-04 08:37:31 +00:00
|
|
|
openVolume: position.openVolume,
|
|
|
|
realisedPNL: position.realisedPNL,
|
|
|
|
unrealisedPNL: position.unrealisedPNL,
|
2022-08-16 07:18:55 +00:00
|
|
|
searchPrice: searchPrice
|
|
|
|
.multipliedBy(10 ** marketDecimalPlaces)
|
|
|
|
.toFixed(0),
|
2022-10-05 09:30:42 +00:00
|
|
|
updatedAt: position.updatedAt || null,
|
2022-08-16 07:18:55 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
return metrics;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const update = (
|
2022-10-05 09:30:42 +00:00
|
|
|
data: PositionsQuery['party'],
|
|
|
|
deltas: PositionsSubscriptionSubscription['positions']
|
2022-08-16 07:18:55 +00:00
|
|
|
) => {
|
2022-08-26 15:39:40 +00:00
|
|
|
return produce(data, (draft) => {
|
chore: stagnet3 api updates (#1321)
* chore: update account, fills and orders subscriptions in data providers
* chore: update account, fills and orders subscriptions in data providers
* fixing console-lite
* fixing types in general - regen
* chore: update account, fills and orders subscriptions in data providers
* fixed console-lite unit tests, uncommented quote name
* chore: update account, fills and orders subscriptions in data providers
* type aligning of assets and proposals
* fixes liquidity data provider
* fixed accounts build errors and unit tests
* regen types, removed market name
* regen types
* fixed positions
* chore: handle updates in derived market provider, update orders
* removed taker fee mapping (renamed to maker fee)
* chore: update account, fills and orders subscriptions in data providers
* chore: update account, fills and orders subscriptions in data providers
* chore: fix Order type
* chore: fix possible null types
* chore: revert order-list.stories.tsx
* chore: derivedDataProvider fixes
* fills unit tests fixes
* orders unit tests fixes
* added eslint ingore for generated files in liquidity
* added unique key to the list element of simple market toolbar
* changed main-branch-name to develop for pr workflows
* removed redundant waitFor
* increased test timeout to 10s
* removed mocked response
* chore: disable simple market list tests
* chore: fix e2e projects mock types
* feat: [subscription-update] - uncomment some console-lite tests
* cypress: trading-accounts
* chore: replace market candles with candlesConnection
* chore: ignore gql errors, to be reverted after candlesConnectio n will be fixed
* feat: [subscription-update] - improve wrongly renamed hook
* feat: [subscription-update] - improve wrongly renamed hook
* feat: [subscription-update] - improve wrongly renamed hook 3
* chore: add pagination hangdling to derived data provier
* cypress: trading-fills
* feat: [stagnet3 api update] - remove redundant command in tests
* feat: [stagnet3 api update] - remove redundant command in tests
* chore: fix trading orders e2e tests
* chore: fix console lite e2e mocks
* chore: fix market-trade tests
* chore: use markets only in market selector, change Instrument cache policy
* chore: fix market-selector tests
* feat: [subscription-update] - improve ag grid conf for unit tests
* feat: [subscription-update] - improve ag grid conf for unit tests
* chore: fix candle types in console lite market mocks
* chore: revert error policy ignore
* chore: revert jest timeout
* chore: remove unused AccountFields
* chore: revert remove unused AccountFields
* chore: simplify node subscription probe
* chore: remove unused generated types in candles-chart
* chore: improve useMarketsList mock
* feat: [subscription-update] - increase jest timeout
* feat: [subscription-update] - fix jest timeout
* feat: [subscription-update] - fix jest timeout
* feat: [subscription-update] - try to fix failing test again
* chore: fix candles-chart types
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - fix failling int test
* feat: [subscription-update] - try to restore commented unit tests
* feat: [subscription-update] - try to restore commented unit tests
* feat: [subscription-update] - improve fixed unit tests
Co-authored-by: asiaznik <artur@vegaprotocol.io>
Co-authored-by: maciek <maciek@vegaprotocol.io>
2022-09-20 15:24:28 +00:00
|
|
|
deltas.forEach((delta) => {
|
2022-10-05 09:30:42 +00:00
|
|
|
if (!draft?.positionsConnection?.edges || !delta) {
|
chore: stagnet3 api updates (#1321)
* chore: update account, fills and orders subscriptions in data providers
* chore: update account, fills and orders subscriptions in data providers
* fixing console-lite
* fixing types in general - regen
* chore: update account, fills and orders subscriptions in data providers
* fixed console-lite unit tests, uncommented quote name
* chore: update account, fills and orders subscriptions in data providers
* type aligning of assets and proposals
* fixes liquidity data provider
* fixed accounts build errors and unit tests
* regen types, removed market name
* regen types
* fixed positions
* chore: handle updates in derived market provider, update orders
* removed taker fee mapping (renamed to maker fee)
* chore: update account, fills and orders subscriptions in data providers
* chore: update account, fills and orders subscriptions in data providers
* chore: fix Order type
* chore: fix possible null types
* chore: revert order-list.stories.tsx
* chore: derivedDataProvider fixes
* fills unit tests fixes
* orders unit tests fixes
* added eslint ingore for generated files in liquidity
* added unique key to the list element of simple market toolbar
* changed main-branch-name to develop for pr workflows
* removed redundant waitFor
* increased test timeout to 10s
* removed mocked response
* chore: disable simple market list tests
* chore: fix e2e projects mock types
* feat: [subscription-update] - uncomment some console-lite tests
* cypress: trading-accounts
* chore: replace market candles with candlesConnection
* chore: ignore gql errors, to be reverted after candlesConnectio n will be fixed
* feat: [subscription-update] - improve wrongly renamed hook
* feat: [subscription-update] - improve wrongly renamed hook
* feat: [subscription-update] - improve wrongly renamed hook 3
* chore: add pagination hangdling to derived data provier
* cypress: trading-fills
* feat: [stagnet3 api update] - remove redundant command in tests
* feat: [stagnet3 api update] - remove redundant command in tests
* chore: fix trading orders e2e tests
* chore: fix console lite e2e mocks
* chore: fix market-trade tests
* chore: use markets only in market selector, change Instrument cache policy
* chore: fix market-selector tests
* feat: [subscription-update] - improve ag grid conf for unit tests
* feat: [subscription-update] - improve ag grid conf for unit tests
* chore: fix candle types in console lite market mocks
* chore: revert error policy ignore
* chore: revert jest timeout
* chore: remove unused AccountFields
* chore: revert remove unused AccountFields
* chore: simplify node subscription probe
* chore: remove unused generated types in candles-chart
* chore: improve useMarketsList mock
* feat: [subscription-update] - increase jest timeout
* feat: [subscription-update] - fix jest timeout
* feat: [subscription-update] - fix jest timeout
* feat: [subscription-update] - try to fix failing test again
* chore: fix candles-chart types
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - fix failling int test
* feat: [subscription-update] - try to restore commented unit tests
* feat: [subscription-update] - try to restore commented unit tests
* feat: [subscription-update] - improve fixed unit tests
Co-authored-by: asiaznik <artur@vegaprotocol.io>
Co-authored-by: maciek <maciek@vegaprotocol.io>
2022-09-20 15:24:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const index = draft.positionsConnection.edges.findIndex(
|
2022-09-27 00:40:08 +00:00
|
|
|
(edge) => edge.node.market.id === delta.marketId
|
chore: stagnet3 api updates (#1321)
* chore: update account, fills and orders subscriptions in data providers
* chore: update account, fills and orders subscriptions in data providers
* fixing console-lite
* fixing types in general - regen
* chore: update account, fills and orders subscriptions in data providers
* fixed console-lite unit tests, uncommented quote name
* chore: update account, fills and orders subscriptions in data providers
* type aligning of assets and proposals
* fixes liquidity data provider
* fixed accounts build errors and unit tests
* regen types, removed market name
* regen types
* fixed positions
* chore: handle updates in derived market provider, update orders
* removed taker fee mapping (renamed to maker fee)
* chore: update account, fills and orders subscriptions in data providers
* chore: update account, fills and orders subscriptions in data providers
* chore: fix Order type
* chore: fix possible null types
* chore: revert order-list.stories.tsx
* chore: derivedDataProvider fixes
* fills unit tests fixes
* orders unit tests fixes
* added eslint ingore for generated files in liquidity
* added unique key to the list element of simple market toolbar
* changed main-branch-name to develop for pr workflows
* removed redundant waitFor
* increased test timeout to 10s
* removed mocked response
* chore: disable simple market list tests
* chore: fix e2e projects mock types
* feat: [subscription-update] - uncomment some console-lite tests
* cypress: trading-accounts
* chore: replace market candles with candlesConnection
* chore: ignore gql errors, to be reverted after candlesConnectio n will be fixed
* feat: [subscription-update] - improve wrongly renamed hook
* feat: [subscription-update] - improve wrongly renamed hook
* feat: [subscription-update] - improve wrongly renamed hook 3
* chore: add pagination hangdling to derived data provier
* cypress: trading-fills
* feat: [stagnet3 api update] - remove redundant command in tests
* feat: [stagnet3 api update] - remove redundant command in tests
* chore: fix trading orders e2e tests
* chore: fix console lite e2e mocks
* chore: fix market-trade tests
* chore: use markets only in market selector, change Instrument cache policy
* chore: fix market-selector tests
* feat: [subscription-update] - improve ag grid conf for unit tests
* feat: [subscription-update] - improve ag grid conf for unit tests
* chore: fix candle types in console lite market mocks
* chore: revert error policy ignore
* chore: revert jest timeout
* chore: remove unused AccountFields
* chore: revert remove unused AccountFields
* chore: simplify node subscription probe
* chore: remove unused generated types in candles-chart
* chore: improve useMarketsList mock
* feat: [subscription-update] - increase jest timeout
* feat: [subscription-update] - fix jest timeout
* feat: [subscription-update] - fix jest timeout
* feat: [subscription-update] - try to fix failing test again
* chore: fix candles-chart types
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - fix failling int test
* feat: [subscription-update] - try to restore commented unit tests
* feat: [subscription-update] - try to restore commented unit tests
* feat: [subscription-update] - improve fixed unit tests
Co-authored-by: asiaznik <artur@vegaprotocol.io>
Co-authored-by: maciek <maciek@vegaprotocol.io>
2022-09-20 15:24:28 +00:00
|
|
|
);
|
|
|
|
if (index !== -1) {
|
2022-09-27 00:40:08 +00:00
|
|
|
const currNode = draft.positionsConnection.edges[index].node;
|
|
|
|
draft.positionsConnection.edges[index].node = {
|
|
|
|
...currNode,
|
|
|
|
realisedPNL: delta.realisedPNL,
|
|
|
|
unrealisedPNL: delta.unrealisedPNL,
|
|
|
|
openVolume: delta.openVolume,
|
|
|
|
averageEntryPrice: delta.averageEntryPrice,
|
|
|
|
updatedAt: delta.updatedAt,
|
|
|
|
};
|
chore: stagnet3 api updates (#1321)
* chore: update account, fills and orders subscriptions in data providers
* chore: update account, fills and orders subscriptions in data providers
* fixing console-lite
* fixing types in general - regen
* chore: update account, fills and orders subscriptions in data providers
* fixed console-lite unit tests, uncommented quote name
* chore: update account, fills and orders subscriptions in data providers
* type aligning of assets and proposals
* fixes liquidity data provider
* fixed accounts build errors and unit tests
* regen types, removed market name
* regen types
* fixed positions
* chore: handle updates in derived market provider, update orders
* removed taker fee mapping (renamed to maker fee)
* chore: update account, fills and orders subscriptions in data providers
* chore: update account, fills and orders subscriptions in data providers
* chore: fix Order type
* chore: fix possible null types
* chore: revert order-list.stories.tsx
* chore: derivedDataProvider fixes
* fills unit tests fixes
* orders unit tests fixes
* added eslint ingore for generated files in liquidity
* added unique key to the list element of simple market toolbar
* changed main-branch-name to develop for pr workflows
* removed redundant waitFor
* increased test timeout to 10s
* removed mocked response
* chore: disable simple market list tests
* chore: fix e2e projects mock types
* feat: [subscription-update] - uncomment some console-lite tests
* cypress: trading-accounts
* chore: replace market candles with candlesConnection
* chore: ignore gql errors, to be reverted after candlesConnectio n will be fixed
* feat: [subscription-update] - improve wrongly renamed hook
* feat: [subscription-update] - improve wrongly renamed hook
* feat: [subscription-update] - improve wrongly renamed hook 3
* chore: add pagination hangdling to derived data provier
* cypress: trading-fills
* feat: [stagnet3 api update] - remove redundant command in tests
* feat: [stagnet3 api update] - remove redundant command in tests
* chore: fix trading orders e2e tests
* chore: fix console lite e2e mocks
* chore: fix market-trade tests
* chore: use markets only in market selector, change Instrument cache policy
* chore: fix market-selector tests
* feat: [subscription-update] - improve ag grid conf for unit tests
* feat: [subscription-update] - improve ag grid conf for unit tests
* chore: fix candle types in console lite market mocks
* chore: revert error policy ignore
* chore: revert jest timeout
* chore: remove unused AccountFields
* chore: revert remove unused AccountFields
* chore: simplify node subscription probe
* chore: remove unused generated types in candles-chart
* chore: improve useMarketsList mock
* feat: [subscription-update] - increase jest timeout
* feat: [subscription-update] - fix jest timeout
* feat: [subscription-update] - fix jest timeout
* feat: [subscription-update] - try to fix failing test again
* chore: fix candles-chart types
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - fix failling int test
* feat: [subscription-update] - try to restore commented unit tests
* feat: [subscription-update] - try to restore commented unit tests
* feat: [subscription-update] - improve fixed unit tests
Co-authored-by: asiaznik <artur@vegaprotocol.io>
Co-authored-by: maciek <maciek@vegaprotocol.io>
2022-09-20 15:24:28 +00:00
|
|
|
} else {
|
2022-10-04 08:37:31 +00:00
|
|
|
draft.positionsConnection.edges.unshift({
|
|
|
|
__typename: 'PositionEdge',
|
|
|
|
node: {
|
|
|
|
...delta,
|
|
|
|
__typename: 'Position',
|
|
|
|
market: {
|
|
|
|
__typename: 'Market',
|
|
|
|
id: delta.marketId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
chore: stagnet3 api updates (#1321)
* chore: update account, fills and orders subscriptions in data providers
* chore: update account, fills and orders subscriptions in data providers
* fixing console-lite
* fixing types in general - regen
* chore: update account, fills and orders subscriptions in data providers
* fixed console-lite unit tests, uncommented quote name
* chore: update account, fills and orders subscriptions in data providers
* type aligning of assets and proposals
* fixes liquidity data provider
* fixed accounts build errors and unit tests
* regen types, removed market name
* regen types
* fixed positions
* chore: handle updates in derived market provider, update orders
* removed taker fee mapping (renamed to maker fee)
* chore: update account, fills and orders subscriptions in data providers
* chore: update account, fills and orders subscriptions in data providers
* chore: fix Order type
* chore: fix possible null types
* chore: revert order-list.stories.tsx
* chore: derivedDataProvider fixes
* fills unit tests fixes
* orders unit tests fixes
* added eslint ingore for generated files in liquidity
* added unique key to the list element of simple market toolbar
* changed main-branch-name to develop for pr workflows
* removed redundant waitFor
* increased test timeout to 10s
* removed mocked response
* chore: disable simple market list tests
* chore: fix e2e projects mock types
* feat: [subscription-update] - uncomment some console-lite tests
* cypress: trading-accounts
* chore: replace market candles with candlesConnection
* chore: ignore gql errors, to be reverted after candlesConnectio n will be fixed
* feat: [subscription-update] - improve wrongly renamed hook
* feat: [subscription-update] - improve wrongly renamed hook
* feat: [subscription-update] - improve wrongly renamed hook 3
* chore: add pagination hangdling to derived data provier
* cypress: trading-fills
* feat: [stagnet3 api update] - remove redundant command in tests
* feat: [stagnet3 api update] - remove redundant command in tests
* chore: fix trading orders e2e tests
* chore: fix console lite e2e mocks
* chore: fix market-trade tests
* chore: use markets only in market selector, change Instrument cache policy
* chore: fix market-selector tests
* feat: [subscription-update] - improve ag grid conf for unit tests
* feat: [subscription-update] - improve ag grid conf for unit tests
* chore: fix candle types in console lite market mocks
* chore: revert error policy ignore
* chore: revert jest timeout
* chore: remove unused AccountFields
* chore: revert remove unused AccountFields
* chore: simplify node subscription probe
* chore: remove unused generated types in candles-chart
* chore: improve useMarketsList mock
* feat: [subscription-update] - increase jest timeout
* feat: [subscription-update] - fix jest timeout
* feat: [subscription-update] - fix jest timeout
* feat: [subscription-update] - try to fix failing test again
* chore: fix candles-chart types
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - fix failling int test
* feat: [subscription-update] - try to restore commented unit tests
* feat: [subscription-update] - try to restore commented unit tests
* feat: [subscription-update] - improve fixed unit tests
Co-authored-by: asiaznik <artur@vegaprotocol.io>
Co-authored-by: maciek <maciek@vegaprotocol.io>
2022-09-20 15:24:28 +00:00
|
|
|
}
|
|
|
|
});
|
2022-08-16 07:18:55 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-09-13 10:14:06 +00:00
|
|
|
export const positionsDataProvider = makeDataProvider<
|
2022-10-05 09:30:42 +00:00
|
|
|
PositionsQuery,
|
|
|
|
PositionsQuery['party'],
|
|
|
|
PositionsSubscriptionSubscription,
|
|
|
|
PositionsSubscriptionSubscription['positions']
|
2022-08-26 15:39:40 +00:00
|
|
|
>({
|
2022-10-05 09:30:42 +00:00
|
|
|
query: PositionsDocument,
|
|
|
|
subscriptionQuery: PositionsSubscriptionDocument,
|
2022-08-16 07:18:55 +00:00
|
|
|
update,
|
2022-10-05 09:30:42 +00:00
|
|
|
getData: (responseData: PositionsQuery) => responseData.party,
|
|
|
|
getDelta: (subscriptionData: PositionsSubscriptionSubscription) =>
|
2022-08-26 15:39:40 +00:00
|
|
|
subscriptionData.positions,
|
|
|
|
});
|
|
|
|
|
2022-10-28 15:14:29 +00:00
|
|
|
const upgradeMarginsConnection = (
|
2022-10-04 08:37:31 +00:00
|
|
|
marketId: string,
|
2022-10-05 09:30:42 +00:00
|
|
|
margins: MarginsQuery['party'] | null
|
2022-10-04 08:37:31 +00:00
|
|
|
) => {
|
|
|
|
if (marketId && margins?.marginsConnection?.edges) {
|
|
|
|
const index =
|
|
|
|
margins.marginsConnection.edges.findIndex(
|
|
|
|
(edge) => edge.node.market.id === marketId
|
|
|
|
) ?? -1;
|
|
|
|
if (index >= 0) {
|
|
|
|
const marginLevel = margins.marginsConnection.edges[index].node;
|
|
|
|
return {
|
|
|
|
maintenanceLevel: marginLevel.maintenanceLevel,
|
|
|
|
searchLevel: marginLevel.searchLevel,
|
|
|
|
initialLevel: marginLevel.initialLevel,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const rejoinPositionData = (
|
2022-10-05 09:30:42 +00:00
|
|
|
positions: PositionsQuery['party'] | null,
|
2022-10-04 08:37:31 +00:00
|
|
|
marketsData: MarketWithData[] | null,
|
2022-10-05 09:30:42 +00:00
|
|
|
margins: MarginsQuery['party'] | null
|
2022-10-04 08:37:31 +00:00
|
|
|
): PositionRejoined[] | null => {
|
|
|
|
if (positions?.positionsConnection?.edges && marketsData && margins) {
|
2022-10-05 09:30:42 +00:00
|
|
|
return positions.positionsConnection.edges.map(({ node }) => {
|
|
|
|
return {
|
|
|
|
realisedPNL: node.realisedPNL,
|
|
|
|
openVolume: node.openVolume,
|
|
|
|
unrealisedPNL: node.unrealisedPNL,
|
|
|
|
averageEntryPrice: node.averageEntryPrice,
|
|
|
|
updatedAt: node.updatedAt,
|
|
|
|
market:
|
|
|
|
marketsData?.find((market) => market.id === node.market.id) || null,
|
2022-10-28 15:14:29 +00:00
|
|
|
margins: upgradeMarginsConnection(node.market.id, margins),
|
2022-10-05 09:30:42 +00:00
|
|
|
};
|
|
|
|
});
|
2022-10-04 08:37:31 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2022-11-02 07:01:40 +00:00
|
|
|
export interface PositionsMetricsProviderVariables {
|
|
|
|
partyId: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const positionsMetricsProvider = makeDerivedDataProvider<
|
|
|
|
Position[],
|
chore: stagnet3 api updates (#1321)
* chore: update account, fills and orders subscriptions in data providers
* chore: update account, fills and orders subscriptions in data providers
* fixing console-lite
* fixing types in general - regen
* chore: update account, fills and orders subscriptions in data providers
* fixed console-lite unit tests, uncommented quote name
* chore: update account, fills and orders subscriptions in data providers
* type aligning of assets and proposals
* fixes liquidity data provider
* fixed accounts build errors and unit tests
* regen types, removed market name
* regen types
* fixed positions
* chore: handle updates in derived market provider, update orders
* removed taker fee mapping (renamed to maker fee)
* chore: update account, fills and orders subscriptions in data providers
* chore: update account, fills and orders subscriptions in data providers
* chore: fix Order type
* chore: fix possible null types
* chore: revert order-list.stories.tsx
* chore: derivedDataProvider fixes
* fills unit tests fixes
* orders unit tests fixes
* added eslint ingore for generated files in liquidity
* added unique key to the list element of simple market toolbar
* changed main-branch-name to develop for pr workflows
* removed redundant waitFor
* increased test timeout to 10s
* removed mocked response
* chore: disable simple market list tests
* chore: fix e2e projects mock types
* feat: [subscription-update] - uncomment some console-lite tests
* cypress: trading-accounts
* chore: replace market candles with candlesConnection
* chore: ignore gql errors, to be reverted after candlesConnectio n will be fixed
* feat: [subscription-update] - improve wrongly renamed hook
* feat: [subscription-update] - improve wrongly renamed hook
* feat: [subscription-update] - improve wrongly renamed hook 3
* chore: add pagination hangdling to derived data provier
* cypress: trading-fills
* feat: [stagnet3 api update] - remove redundant command in tests
* feat: [stagnet3 api update] - remove redundant command in tests
* chore: fix trading orders e2e tests
* chore: fix console lite e2e mocks
* chore: fix market-trade tests
* chore: use markets only in market selector, change Instrument cache policy
* chore: fix market-selector tests
* feat: [subscription-update] - improve ag grid conf for unit tests
* feat: [subscription-update] - improve ag grid conf for unit tests
* chore: fix candle types in console lite market mocks
* chore: revert error policy ignore
* chore: revert jest timeout
* chore: remove unused AccountFields
* chore: revert remove unused AccountFields
* chore: simplify node subscription probe
* chore: remove unused generated types in candles-chart
* chore: improve useMarketsList mock
* feat: [subscription-update] - increase jest timeout
* feat: [subscription-update] - fix jest timeout
* feat: [subscription-update] - fix jest timeout
* feat: [subscription-update] - try to fix failing test again
* chore: fix candles-chart types
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - temporary skip failing test
* feat: [subscription-update] - fix failling int test
* feat: [subscription-update] - try to restore commented unit tests
* feat: [subscription-update] - try to restore commented unit tests
* feat: [subscription-update] - improve fixed unit tests
Co-authored-by: asiaznik <artur@vegaprotocol.io>
Co-authored-by: maciek <maciek@vegaprotocol.io>
2022-09-20 15:24:28 +00:00
|
|
|
Position[],
|
2022-11-02 07:01:40 +00:00
|
|
|
PositionsMetricsProviderVariables
|
2022-10-04 08:37:31 +00:00
|
|
|
>(
|
|
|
|
[
|
|
|
|
positionsDataProvider,
|
|
|
|
accountsDataProvider,
|
|
|
|
marketsWithDataProvider,
|
|
|
|
marginsDataProvider,
|
|
|
|
],
|
2022-11-02 07:01:40 +00:00
|
|
|
([positions, accounts, marketsData, margins], variables) => {
|
2022-10-04 08:37:31 +00:00
|
|
|
const positionsData = rejoinPositionData(positions, marketsData, margins);
|
2022-11-02 07:01:40 +00:00
|
|
|
if (!variables) {
|
|
|
|
return [];
|
|
|
|
}
|
2022-10-04 08:37:31 +00:00
|
|
|
return sortBy(
|
|
|
|
getMetrics(positionsData, accounts as Account[] | null),
|
2022-10-28 15:14:29 +00:00
|
|
|
'marketName'
|
|
|
|
);
|
2022-11-02 07:01:40 +00:00
|
|
|
},
|
|
|
|
(data, delta, previousData) =>
|
|
|
|
data.filter((row) => {
|
|
|
|
const previousRow = previousData?.find(
|
|
|
|
(previousRow) => previousRow.marketId === row.marketId
|
|
|
|
);
|
|
|
|
return !(previousRow && isEqual(previousRow, row));
|
|
|
|
})
|
2022-10-04 08:37:31 +00:00
|
|
|
);
|