fix: volume chart values fixing - position dp (#2749)
This commit is contained in:
parent
860938f26c
commit
47b2a2fdcb
@ -12,6 +12,7 @@ query Candles($marketId: ID!, $interval: Interval!, $since: String!) {
|
||||
market(id: $marketId) {
|
||||
id
|
||||
decimalPlaces
|
||||
positionDecimalPlaces
|
||||
tradableInstrument {
|
||||
instrument {
|
||||
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<{
|
||||
marketId: Types.Scalars['ID'];
|
||||
@ -38,6 +38,7 @@ export const CandlesDocument = gql`
|
||||
market(id: $marketId) {
|
||||
id
|
||||
decimalPlaces
|
||||
positionDecimalPlaces
|
||||
tradableInstrument {
|
||||
instrument {
|
||||
id
|
||||
|
@ -14,6 +14,7 @@ export const candlesQuery = (
|
||||
market: {
|
||||
id: 'market-0',
|
||||
decimalPlaces: 5,
|
||||
positionDecimalPlaces: 0,
|
||||
tradableInstrument: {
|
||||
instrument: {
|
||||
id: '',
|
||||
|
@ -49,6 +49,7 @@ export class VegaDataSource implements DataSource {
|
||||
marketId: string;
|
||||
partyId: null | string;
|
||||
_decimalPlaces = 0;
|
||||
_positionDecimalPlaces = 0;
|
||||
|
||||
candlesSub: Subscription | null = null;
|
||||
|
||||
@ -60,6 +61,14 @@ export class VegaDataSource implements DataSource {
|
||||
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.
|
||||
@ -145,11 +154,14 @@ export class VegaDataSource implements DataSource {
|
||||
|
||||
if (data?.market?.candlesConnection?.edges) {
|
||||
const decimalPlaces = data.market.decimalPlaces;
|
||||
const positionDecimalPlaces = data.market.positionDecimalPlaces;
|
||||
|
||||
const candles = data.market.candlesConnection.edges
|
||||
.map((edge) => edge?.node)
|
||||
.filter((node): node is CandleFieldsFragment => !!node)
|
||||
.map((node) => parseCandle(node, decimalPlaces));
|
||||
.map((node) =>
|
||||
parseCandle(node, decimalPlaces, positionDecimalPlaces)
|
||||
);
|
||||
|
||||
return candles;
|
||||
} else {
|
||||
@ -180,7 +192,11 @@ export class VegaDataSource implements DataSource {
|
||||
|
||||
this.candlesSub = res.subscribe(({ data }) => {
|
||||
if (data) {
|
||||
const candle = parseCandle(data.candles, this.decimalPlaces);
|
||||
const candle = parseCandle(
|
||||
data.candles,
|
||||
this.decimalPlaces,
|
||||
this.positionDecimalPlaces
|
||||
);
|
||||
|
||||
onSubscriptionData(candle);
|
||||
}
|
||||
@ -197,7 +213,8 @@ export class VegaDataSource implements DataSource {
|
||||
|
||||
function parseCandle(
|
||||
candle: CandleFieldsFragment,
|
||||
decimalPlaces: number
|
||||
decimalPlaces: number,
|
||||
positionDecimalPlaces: number
|
||||
): Candle {
|
||||
return {
|
||||
date: new Date(candle.periodStart),
|
||||
@ -205,6 +222,6 @@ function parseCandle(
|
||||
low: Number(addDecimal(candle.low, decimalPlaces)),
|
||||
open: Number(addDecimal(candle.open, 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