fix(trading): tick size backwards compatibility (#5988)

This commit is contained in:
Matthew Russell 2024-03-13 11:31:01 +00:00 committed by GitHub
parent a49f5f0dd1
commit 424061d64c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 498 additions and 3 deletions

View File

@ -61,6 +61,7 @@ const mockConsensusValidators: NodesFragmentFragment[] = [
];
jest.mock('@vegaprotocol/environment', () => ({
...jest.requireActual('@vegaprotocol/environment'),
useVegaRelease: jest.fn(),
useVegaReleases: jest.fn(),
}));

View File

@ -145,6 +145,30 @@ const cacheConfig: InMemoryCacheConfig = {
Product: {
keyFields: ['settlementAsset', ['id']],
},
Market: {
fields: {
/**
* Intercept cache field for tickSize because mainnet specific queries have been
* set up, marking this field as client only. The following can be removed when mainnet
* supports ticksize:
*
* 1. The typePolicy for tickSize below
* 2. The MarketInfoMainnet query in libs/markets/src/lib/components/market-info/MarketInfo.graphql
* 3. The ternary to switch queries in libs/markets/src/lib/components/market-info/market-info-data-provider.ts
* 4. The MarketsMainnet query in libs/markets/src/lib/markets.graphql
* 5. The ternary to switch queries in libs/markets/src/lib/markets-provider.ts
*/
tickSize: {
read(value) {
// value is not present, we have probably marked tickSize as a client only field
if (!value) return '1';
// Use fetch response value
return value;
},
},
},
},
MarketData: {
keyFields: ['market', ['id']],
},

File diff suppressed because one or more lines are too long

View File

@ -135,6 +135,134 @@ fragment Perpetual on Perpetual {
}
}
query MarketInfoMainnet($marketId: ID!) {
market(id: $marketId) {
id
decimalPlaces
positionDecimalPlaces
# tickSize is not on mainnet and the query will fail. See typePolicy for tickSize in bootstrapper.tsx
tickSize @client
state
tradingMode
linearSlippageFactor
parentMarketID
successorMarketID
proposal {
id
rationale {
title
description
}
}
marketTimestamps {
proposed
pending
open
close
}
openingAuction {
durationSecs
volume
}
accountsConnection {
edges {
node {
type
asset {
id
}
balance
}
}
}
fees {
factors {
makerFee
infrastructureFee
liquidityFee
}
liquidityFeeSettings {
feeConstant
method
}
}
priceMonitoringSettings {
parameters {
triggers {
horizonSecs
probability
auctionExtensionSecs
}
}
}
riskFactors {
market
short
long
}
liquidityMonitoringParameters {
targetStakeParameters {
timeWindow
scalingFactor
}
}
liquiditySLAParameters {
priceRange
commitmentMinTimeFraction
performanceHysteresisEpochs
slaCompetitionFactor
}
liquidationStrategy {
disposalTimeStep
disposalFraction
fullDisposalSize
maxFractionConsumed
}
tradableInstrument {
instrument {
id
name
code
metadata {
tags
}
product {
... on Future {
...Future
}
... on Perpetual {
...Perpetual
}
}
}
riskModel {
... on LogNormalRiskModel {
tau
riskAversionParameter
params {
r
sigma
mu
}
}
... on SimpleRiskModel {
params {
factorLong
factorShort
}
}
}
marginCalculator {
scalingFactors {
searchLevel
initialMargin
collateralRelease
}
}
}
}
}
query MarketInfo($marketId: ID!) {
market(id: $marketId) {
id

File diff suppressed because one or more lines are too long

View File

@ -2,8 +2,10 @@ import {
makeDataProvider,
makeDerivedDataProvider,
} from '@vegaprotocol/data-provider';
import { ENV, Networks } from '@vegaprotocol/environment';
import {
MarketInfoDocument,
MarketInfoMainnetDocument,
type MarketInfoQuery,
type MarketInfoQueryVariables,
} from './__generated__/MarketInfo';
@ -30,7 +32,11 @@ export const marketInfoProvider = makeDataProvider<
never,
MarketInfoQueryVariables
>({
query: MarketInfoDocument,
query:
// Mainnet does not support tickSize, and a query for tickSize on a market will completely fail
ENV.VEGA_ENV === Networks.MAINNET
? MarketInfoMainnetDocument
: MarketInfoDocument,
getData,
errorPolicy: 'all',
pollInterval: 5000,

View File

@ -4,10 +4,12 @@ import {
makeDerivedDataProvider,
useDataProvider,
} from '@vegaprotocol/data-provider';
import { ENV, Networks } from '@vegaprotocol/environment';
import {
MarketsDocument,
type MarketsQuery,
type MarketFieldsFragment,
MarketsMainnetDocument,
} from './__generated__/markets';
import { type MarketsCandlesQueryVariables } from './__generated__/markets-candles';
@ -42,7 +44,11 @@ export const marketsProvider = makeDataProvider<
never,
never
>({
query: MarketsDocument,
query:
// Mainnet does not support tickSize, and a query for tickSize on a market will completely fail
ENV.VEGA_ENV === Networks.MAINNET
? MarketsMainnetDocument
: MarketsDocument,
getData,
fetchPolicy: 'cache-first',
errorPolicy: 'all',

View File

@ -1,3 +1,58 @@
fragment MarketFieldsMainnet on Market {
id
decimalPlaces
positionDecimalPlaces
# tickSize is not on mainnet and the query will fail. See typePolicy for tickSize in bootstrapper.tsx
tickSize @client
state
tradingMode
parentMarketID
successorMarketID
fees {
factors {
makerFee
infrastructureFee
liquidityFee
}
liquidityFeeSettings {
feeConstant
method
}
}
tradableInstrument {
instrument {
id
name
code
metadata {
tags
}
product {
... on Future {
...Future
}
... on Perpetual {
...Perpetual
}
}
}
}
marketTimestamps {
proposed
pending
open
close
}
marketProposal {
... on Proposal {
id
}
... on BatchProposal {
id
}
}
}
fragment MarketFields on Market {
id
decimalPlaces
@ -61,3 +116,13 @@ query Markets {
}
}
}
query MarketsMainnet {
marketsConnection {
edges {
node {
...MarketFieldsMainnet
}
}
}
}