fix: volume chart values fixing - position dp (#2749)
This commit is contained in:
parent
860938f26c
commit
47b2a2fdcb
@ -97,4 +97,4 @@ export function useRewardsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<Re
|
|||||||
}
|
}
|
||||||
export type RewardsQueryHookResult = ReturnType<typeof useRewardsQuery>;
|
export type RewardsQueryHookResult = ReturnType<typeof useRewardsQuery>;
|
||||||
export type RewardsLazyQueryHookResult = ReturnType<typeof useRewardsLazyQuery>;
|
export type RewardsLazyQueryHookResult = ReturnType<typeof useRewardsLazyQuery>;
|
||||||
export type RewardsQueryResult = Apollo.QueryResult<RewardsQuery, RewardsQueryVariables>;
|
export type RewardsQueryResult = Apollo.QueryResult<RewardsQuery, RewardsQueryVariables>;
|
@ -12,6 +12,7 @@ query Candles($marketId: ID!, $interval: Interval!, $since: String!) {
|
|||||||
market(id: $marketId) {
|
market(id: $marketId) {
|
||||||
id
|
id
|
||||||
decimalPlaces
|
decimalPlaces
|
||||||
|
positionDecimalPlaces
|
||||||
tradableInstrument {
|
tradableInstrument {
|
||||||
instrument {
|
instrument {
|
||||||
id
|
id
|
||||||
|
@ -12,7 +12,7 @@ export type CandlesQueryVariables = Types.Exact<{
|
|||||||
}>;
|
}>;
|
||||||
|
|
||||||
|
|
||||||
export type CandlesQuery = { __typename?: 'Query', market?: { __typename?: 'Market', id: string, decimalPlaces: number, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', id: string, name: string, code: string } }, candlesConnection?: { __typename?: 'CandleDataConnection', edges?: Array<{ __typename?: 'CandleEdge', node: { __typename?: 'Candle', periodStart: any, lastUpdateInPeriod: any, high: string, low: string, open: string, close: string, volume: string } } | null> | null } | null } | null };
|
export type CandlesQuery = { __typename?: 'Query', market?: { __typename?: 'Market', id: string, decimalPlaces: number, positionDecimalPlaces: number, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', id: string, name: string, code: string } }, candlesConnection?: { __typename?: 'CandleDataConnection', edges?: Array<{ __typename?: 'CandleEdge', node: { __typename?: 'Candle', periodStart: any, lastUpdateInPeriod: any, high: string, low: string, open: string, close: string, volume: string } } | null> | null } | null } | null };
|
||||||
|
|
||||||
export type CandlesEventsSubscriptionVariables = Types.Exact<{
|
export type CandlesEventsSubscriptionVariables = Types.Exact<{
|
||||||
marketId: Types.Scalars['ID'];
|
marketId: Types.Scalars['ID'];
|
||||||
@ -38,6 +38,7 @@ export const CandlesDocument = gql`
|
|||||||
market(id: $marketId) {
|
market(id: $marketId) {
|
||||||
id
|
id
|
||||||
decimalPlaces
|
decimalPlaces
|
||||||
|
positionDecimalPlaces
|
||||||
tradableInstrument {
|
tradableInstrument {
|
||||||
instrument {
|
instrument {
|
||||||
id
|
id
|
||||||
|
@ -14,6 +14,7 @@ export const candlesQuery = (
|
|||||||
market: {
|
market: {
|
||||||
id: 'market-0',
|
id: 'market-0',
|
||||||
decimalPlaces: 5,
|
decimalPlaces: 5,
|
||||||
|
positionDecimalPlaces: 0,
|
||||||
tradableInstrument: {
|
tradableInstrument: {
|
||||||
instrument: {
|
instrument: {
|
||||||
id: '',
|
id: '',
|
||||||
|
@ -49,6 +49,7 @@ export class VegaDataSource implements DataSource {
|
|||||||
marketId: string;
|
marketId: string;
|
||||||
partyId: null | string;
|
partyId: null | string;
|
||||||
_decimalPlaces = 0;
|
_decimalPlaces = 0;
|
||||||
|
_positionDecimalPlaces = 0;
|
||||||
|
|
||||||
candlesSub: Subscription | null = null;
|
candlesSub: Subscription | null = null;
|
||||||
|
|
||||||
@ -60,6 +61,14 @@ export class VegaDataSource implements DataSource {
|
|||||||
return this._decimalPlaces;
|
return this._decimalPlaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates the number of position decimal places that an integer must be shifted by in order to get a correct
|
||||||
|
* number denominated in the unit size of the Market.
|
||||||
|
*/
|
||||||
|
get positionDecimalPlaces(): number {
|
||||||
|
return this._positionDecimalPlaces;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param client - An ApolloClient instance.
|
* @param client - An ApolloClient instance.
|
||||||
@ -145,11 +154,14 @@ export class VegaDataSource implements DataSource {
|
|||||||
|
|
||||||
if (data?.market?.candlesConnection?.edges) {
|
if (data?.market?.candlesConnection?.edges) {
|
||||||
const decimalPlaces = data.market.decimalPlaces;
|
const decimalPlaces = data.market.decimalPlaces;
|
||||||
|
const positionDecimalPlaces = data.market.positionDecimalPlaces;
|
||||||
|
|
||||||
const candles = data.market.candlesConnection.edges
|
const candles = data.market.candlesConnection.edges
|
||||||
.map((edge) => edge?.node)
|
.map((edge) => edge?.node)
|
||||||
.filter((node): node is CandleFieldsFragment => !!node)
|
.filter((node): node is CandleFieldsFragment => !!node)
|
||||||
.map((node) => parseCandle(node, decimalPlaces));
|
.map((node) =>
|
||||||
|
parseCandle(node, decimalPlaces, positionDecimalPlaces)
|
||||||
|
);
|
||||||
|
|
||||||
return candles;
|
return candles;
|
||||||
} else {
|
} else {
|
||||||
@ -180,7 +192,11 @@ export class VegaDataSource implements DataSource {
|
|||||||
|
|
||||||
this.candlesSub = res.subscribe(({ data }) => {
|
this.candlesSub = res.subscribe(({ data }) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
const candle = parseCandle(data.candles, this.decimalPlaces);
|
const candle = parseCandle(
|
||||||
|
data.candles,
|
||||||
|
this.decimalPlaces,
|
||||||
|
this.positionDecimalPlaces
|
||||||
|
);
|
||||||
|
|
||||||
onSubscriptionData(candle);
|
onSubscriptionData(candle);
|
||||||
}
|
}
|
||||||
@ -197,7 +213,8 @@ export class VegaDataSource implements DataSource {
|
|||||||
|
|
||||||
function parseCandle(
|
function parseCandle(
|
||||||
candle: CandleFieldsFragment,
|
candle: CandleFieldsFragment,
|
||||||
decimalPlaces: number
|
decimalPlaces: number,
|
||||||
|
positionDecimalPlaces: number
|
||||||
): Candle {
|
): Candle {
|
||||||
return {
|
return {
|
||||||
date: new Date(candle.periodStart),
|
date: new Date(candle.periodStart),
|
||||||
@ -205,6 +222,6 @@ function parseCandle(
|
|||||||
low: Number(addDecimal(candle.low, decimalPlaces)),
|
low: Number(addDecimal(candle.low, decimalPlaces)),
|
||||||
open: Number(addDecimal(candle.open, decimalPlaces)),
|
open: Number(addDecimal(candle.open, decimalPlaces)),
|
||||||
close: Number(addDecimal(candle.close, decimalPlaces)),
|
close: Number(addDecimal(candle.close, decimalPlaces)),
|
||||||
volume: Number(candle.volume),
|
volume: Number(addDecimal(candle.volume, positionDecimalPlaces)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user