From 5f77a7b4cb808913431ac08530146b5a784744b2 Mon Sep 17 00:00:00 2001 From: jppade Date: Wed, 20 Sep 2023 15:17:06 +0200 Subject: [PATCH] add native denomination to get feed endpoint. --- .../graphqlServer/schema/quotation.graphql | 1 + internal/pkg/filtersBlockService/FilterMA.go | 53 +++++++++++-------- .../pkg/filtersBlockService/FilterMAIR.go | 51 +++++++++++------- .../filtersBlockService/FilterMAIR_test.go | 4 +- .../pkg/filtersBlockService/FilterMEDIR.go | 42 ++++++++------- .../filtersBlockService/FilterMEDIR_test.go | 2 +- .../pkg/filtersBlockService/FilterVWAP.go | 44 ++++++++------- .../pkg/filtersBlockService/FilterVWAPIR.go | 44 ++++++++------- .../filtersBlockService/FilterVWAPIR_test.go | 4 +- .../filtersBlockService/FilterVWAP_test.go | 4 +- .../FiltersBlockService.go | 8 +-- pkg/dia/helpers/queryHelper/filters.go | 10 ++-- .../helpers/queryHelper/filtersExtended.go | 20 +++---- pkg/graphql/resolver/root.go | 18 +++++-- 14 files changed, 177 insertions(+), 128 deletions(-) diff --git a/cmd/http/graphqlServer/schema/quotation.graphql b/cmd/http/graphqlServer/schema/quotation.graphql index 0ce329841..bce957f6f 100644 --- a/cmd/http/graphqlServer/schema/quotation.graphql +++ b/cmd/http/graphqlServer/schema/quotation.graphql @@ -45,6 +45,7 @@ type Query { StartTime: Time EndTime: Time TradeVolumeThreshold: Float + NativeDenomination: Boolean FeedSelection: [FeedSelection!] ): [FilterPointExtended] diff --git a/internal/pkg/filtersBlockService/FilterMA.go b/internal/pkg/filtersBlockService/FilterMA.go index ad6344889..ceca7c004 100644 --- a/internal/pkg/filtersBlockService/FilterMA.go +++ b/internal/pkg/filtersBlockService/FilterMA.go @@ -13,32 +13,34 @@ import ( // FilterMA is the struct for a moving average filter implementing // the Filter interface. type FilterMA struct { - asset dia.Asset - exchange string - currentTime time.Time - prices []float64 - volumes []float64 - lastTrade dia.Trade - memory int - value float64 - modified bool - filterName string + asset dia.Asset + exchange string + currentTime time.Time + prices []float64 + volumes []float64 + lastTrade dia.Trade + memory int + value float64 + modified bool + filterName string + nativeDenomination bool //max float64 min float64 } // NewFilterMA returns a moving average filter. // @currentTime is the begin time of the filtersBlock. -func NewFilterMA(asset dia.Asset, exchange string, currentTime time.Time, memory int) *FilterMA { +func NewFilterMA(asset dia.Asset, exchange string, currentTime time.Time, memory int, nativeDenomination bool) *FilterMA { filter := &FilterMA{ - asset: asset, - exchange: exchange, - prices: []float64{}, - volumes: []float64{}, - currentTime: currentTime, - memory: memory, - filterName: "MA" + strconv.Itoa(memory), - min: -1, + asset: asset, + exchange: exchange, + prices: []float64{}, + volumes: []float64{}, + currentTime: currentTime, + memory: memory, + filterName: "MA" + strconv.Itoa(memory), + min: -1, + nativeDenomination: nativeDenomination, } return filter } @@ -88,7 +90,12 @@ func (filter *FilterMA) processDataPoint(trade dia.Trade) { filter.prices = filter.prices[0 : filter.memory-1] filter.volumes = filter.volumes[0 : filter.memory-1] } - filter.prices = append([]float64{trade.EstimatedUSDPrice}, filter.prices...) + if !filter.nativeDenomination { + filter.prices = append([]float64{trade.EstimatedUSDPrice}, filter.prices...) + } else { + filter.prices = append([]float64{trade.Price}, filter.prices...) + } + filter.volumes = append([]float64{trade.Volume}, filter.volumes...) } @@ -118,7 +125,11 @@ func (filter *FilterMA) finalCompute(t time.Time) float64 { } if len(filter.prices) > 0 && len(filter.volumes) > 0 { - filter.prices = []float64{filter.lastTrade.EstimatedUSDPrice} + if !filter.nativeDenomination { + filter.prices = []float64{filter.lastTrade.EstimatedUSDPrice} + } else { + filter.prices = []float64{filter.lastTrade.Price} + } filter.volumes = []float64{filter.lastTrade.Volume} } return filter.value diff --git a/internal/pkg/filtersBlockService/FilterMAIR.go b/internal/pkg/filtersBlockService/FilterMAIR.go index 77ce38e54..2ca514e2f 100644 --- a/internal/pkg/filtersBlockService/FilterMAIR.go +++ b/internal/pkg/filtersBlockService/FilterMAIR.go @@ -13,28 +13,30 @@ import ( // Outliers are eliminated using interquartile range. // see: https://en.wikipedia.org/wiki/Interquartile_range type FilterMAIR struct { - asset dia.Asset - exchange string - currentTime time.Time - prices []float64 - volumes []float64 - lastTrade dia.Trade - memory int - value float64 - filterName string - modified bool + asset dia.Asset + exchange string + currentTime time.Time + prices []float64 + volumes []float64 + lastTrade dia.Trade + memory int + value float64 + filterName string + nativeDenomination bool + modified bool } // NewFilterMAIR returns a FilterMAIR -func NewFilterMAIR(asset dia.Asset, exchange string, currentTime time.Time, memory int) *FilterMAIR { +func NewFilterMAIR(asset dia.Asset, exchange string, currentTime time.Time, memory int, nativeDenomination bool) *FilterMAIR { filter := &FilterMAIR{ - asset: asset, - exchange: exchange, - prices: []float64{}, - volumes: []float64{}, - currentTime: currentTime, - memory: memory, - filterName: "MAIR" + strconv.Itoa(memory), + asset: asset, + exchange: exchange, + prices: []float64{}, + volumes: []float64{}, + currentTime: currentTime, + memory: memory, + filterName: "MAIR" + strconv.Itoa(memory), + nativeDenomination: nativeDenomination, } return filter } @@ -84,7 +86,12 @@ func (filter *FilterMAIR) processDataPoint(trade dia.Trade) { filter.prices = filter.prices[0 : filter.memory-1] filter.volumes = filter.volumes[0 : filter.memory-1] } - filter.prices = append([]float64{trade.EstimatedUSDPrice}, filter.prices...) + if !filter.nativeDenomination { + filter.prices = append([]float64{trade.EstimatedUSDPrice}, filter.prices...) + } else { + filter.prices = append([]float64{trade.Price}, filter.prices...) + } + filter.volumes = append([]float64{trade.Volume}, filter.volumes...) } @@ -113,7 +120,11 @@ func (filter *FilterMAIR) finalCompute(t time.Time) float64 { filter.value = mean // Reduce the filter values to the last recorded value for the next tradesblock. if len(filter.prices) > 0 && len(filter.volumes) > 0 { - filter.prices = []float64{filter.lastTrade.EstimatedUSDPrice} + if !filter.nativeDenomination { + filter.prices = []float64{filter.lastTrade.EstimatedUSDPrice} + } else { + filter.prices = []float64{filter.lastTrade.Price} + } filter.volumes = []float64{filter.lastTrade.Volume} } return filter.value diff --git a/internal/pkg/filtersBlockService/FilterMAIR_test.go b/internal/pkg/filtersBlockService/FilterMAIR_test.go index 5ae13d1c3..de191fdcf 100644 --- a/internal/pkg/filtersBlockService/FilterMAIR_test.go +++ b/internal/pkg/filtersBlockService/FilterMAIR_test.go @@ -113,7 +113,7 @@ func TestFilterMAIRIgnore(t *testing.T) { Symbol: "XRP", Name: "XRP", } - f := NewFilterMAIR(assetXRP, "", d, filterParam) + f := NewFilterMAIR(assetXRP, "", d, filterParam, false) p := firstPrice priceIncrements := 1.0 for i := 0; i <= steps; i++ { @@ -205,7 +205,7 @@ func TestFilterMAIRAverageCleanOutliers(t *testing.T) { Symbol: "XRP", Name: "XRP", } - f := NewFilterMAIR(assetXRP, "", d, memory) + f := NewFilterMAIR(assetXRP, "", d, memory, false) for _, p := range c.samples { f.compute(dia.Trade{EstimatedUSDPrice: p, Time: d}) d = d.Add(time.Second) diff --git a/internal/pkg/filtersBlockService/FilterMEDIR.go b/internal/pkg/filtersBlockService/FilterMEDIR.go index 01965ded6..ec99a5126 100644 --- a/internal/pkg/filtersBlockService/FilterMEDIR.go +++ b/internal/pkg/filtersBlockService/FilterMEDIR.go @@ -13,26 +13,28 @@ import ( // It implements a trimmed median. Outliers are eliminated using interquartile range // see: https://en.wikipedia.org/wiki/Interquartile_range type FilterMEDIR struct { - asset dia.Asset - exchange string - currentTime time.Time - prices []float64 - lastTrade dia.Trade - memory int - value float64 - filterName string - modified bool + asset dia.Asset + exchange string + currentTime time.Time + prices []float64 + lastTrade dia.Trade + memory int + value float64 + filterName string + modified bool + nativeDenomination bool } -//NewFilterMEDIR creates a FilterMEDIR -func NewFilterMEDIR(asset dia.Asset, exchange string, currentTime time.Time, memory int) *FilterMEDIR { +// NewFilterMEDIR creates a FilterMEDIR +func NewFilterMEDIR(asset dia.Asset, exchange string, currentTime time.Time, memory int, nativeDenomination bool) *FilterMEDIR { filter := &FilterMEDIR{ - asset: asset, - exchange: exchange, - prices: []float64{}, - currentTime: currentTime, - memory: memory, - filterName: "MEDIR" + strconv.Itoa(memory), + asset: asset, + exchange: exchange, + prices: []float64{}, + currentTime: currentTime, + memory: memory, + filterName: "MEDIR" + strconv.Itoa(memory), + nativeDenomination: nativeDenomination, } return filter } @@ -62,7 +64,11 @@ func (filter *FilterMEDIR) processDataPoint(trade dia.Trade) { if len(filter.prices) >= filter.memory { filter.prices = filter.prices[0 : filter.memory-1] } - filter.prices = append([]float64{trade.EstimatedUSDPrice}, filter.prices...) + if !filter.nativeDenomination { + filter.prices = append([]float64{trade.EstimatedUSDPrice}, filter.prices...) + } else { + filter.prices = append([]float64{trade.Price}, filter.prices...) + } } func (filter *FilterMEDIR) finalCompute(t time.Time) float64 { diff --git a/internal/pkg/filtersBlockService/FilterMEDIR_test.go b/internal/pkg/filtersBlockService/FilterMEDIR_test.go index f2a2ba74f..5b69fcffb 100644 --- a/internal/pkg/filtersBlockService/FilterMEDIR_test.go +++ b/internal/pkg/filtersBlockService/FilterMEDIR_test.go @@ -54,7 +54,7 @@ func TestFilterMEDIRMedianCleanOutliers(t *testing.T) { Symbol: "XRP", Name: "XRP", } - f := NewFilterMEDIR(assetXRP, "", d, memory) + f := NewFilterMEDIR(assetXRP, "", d, memory, false) for _, p := range c.samples { f.compute(dia.Trade{EstimatedUSDPrice: p, Time: d}) d = d.Add(time.Second) diff --git a/internal/pkg/filtersBlockService/FilterVWAP.go b/internal/pkg/filtersBlockService/FilterVWAP.go index 0868f2304..48e64727e 100644 --- a/internal/pkg/filtersBlockService/FilterVWAP.go +++ b/internal/pkg/filtersBlockService/FilterVWAP.go @@ -11,28 +11,30 @@ import ( // FilterVWAP ... type FilterVWAP struct { - asset dia.Asset - exchange string - currentTime time.Time - prices []float64 - volumes []float64 - lastTrade dia.Trade - param int - value float64 - filterName string - modified bool + asset dia.Asset + exchange string + currentTime time.Time + prices []float64 + volumes []float64 + lastTrade dia.Trade + param int + value float64 + filterName string + nativeDenomination bool + modified bool } // NewFilterVWAP ... -func NewFilterVWAP(asset dia.Asset, exchange string, currentTime time.Time, param int) *FilterVWAP { +func NewFilterVWAP(asset dia.Asset, exchange string, currentTime time.Time, param int, nativeDenomination bool) *FilterVWAP { s := &FilterVWAP{ - asset: asset, - exchange: exchange, - prices: []float64{}, - volumes: []float64{}, - currentTime: currentTime, - param: param, - filterName: "VWAP" + strconv.Itoa(param), + asset: asset, + exchange: exchange, + prices: []float64{}, + volumes: []float64{}, + currentTime: currentTime, + param: param, + filterName: "VWAP" + strconv.Itoa(param), + nativeDenomination: nativeDenomination, } return s } @@ -62,7 +64,11 @@ func (filter *FilterVWAP) fill(trade dia.Trade) { } func (filter *FilterVWAP) processDataPoint(trade dia.Trade) { - filter.prices = append([]float64{trade.EstimatedUSDPrice}, filter.prices...) + if !filter.nativeDenomination { + filter.prices = append([]float64{trade.EstimatedUSDPrice}, filter.prices...) + } else { + filter.prices = append([]float64{trade.Price}, filter.prices...) + } filter.volumes = append([]float64{trade.Volume}, filter.volumes...) } diff --git a/internal/pkg/filtersBlockService/FilterVWAPIR.go b/internal/pkg/filtersBlockService/FilterVWAPIR.go index 874bff55d..7dd506786 100644 --- a/internal/pkg/filtersBlockService/FilterVWAPIR.go +++ b/internal/pkg/filtersBlockService/FilterVWAPIR.go @@ -12,27 +12,29 @@ import ( // FilterVWAP ... type FilterVWAPIR struct { - exchange string - currentTime time.Time - prices []float64 - volumes []float64 - lastTrade dia.Trade - param int - value float64 - modified bool - filterName string - asset dia.Asset + exchange string + currentTime time.Time + prices []float64 + volumes []float64 + lastTrade dia.Trade + param int + value float64 + modified bool + filterName string + asset dia.Asset + nativeDenomination bool } -func NewFilterVWAPIR(asset dia.Asset, exchange string, currentTime time.Time, param int) *FilterVWAPIR { +func NewFilterVWAPIR(asset dia.Asset, exchange string, currentTime time.Time, param int, nativeDenomination bool) *FilterVWAPIR { s := &FilterVWAPIR{ - asset: asset, - exchange: exchange, - prices: []float64{}, - volumes: []float64{}, - currentTime: currentTime, - param: param, - filterName: "VWAPIR" + strconv.Itoa(param), + asset: asset, + exchange: exchange, + prices: []float64{}, + volumes: []float64{}, + currentTime: currentTime, + param: param, + filterName: "VWAPIR" + strconv.Itoa(param), + nativeDenomination: nativeDenomination, } return s } @@ -61,7 +63,11 @@ func (filter *FilterVWAPIR) fill(trade dia.Trade) { } func (filter *FilterVWAPIR) processDataPoint(trade dia.Trade) { - filter.prices = append([]float64{trade.EstimatedUSDPrice}, filter.prices...) + if !filter.nativeDenomination { + filter.prices = append([]float64{trade.EstimatedUSDPrice}, filter.prices...) + } else { + filter.prices = append([]float64{trade.Price}, filter.prices...) + } filter.volumes = append([]float64{trade.Volume}, filter.volumes...) } diff --git a/internal/pkg/filtersBlockService/FilterVWAPIR_test.go b/internal/pkg/filtersBlockService/FilterVWAPIR_test.go index 0f76b90bf..a6a6cc724 100644 --- a/internal/pkg/filtersBlockService/FilterVWAPIR_test.go +++ b/internal/pkg/filtersBlockService/FilterVWAPIR_test.go @@ -9,7 +9,7 @@ import ( func TestVWAPIR(t *testing.T) { var filterPoints []dia.FilterPoint trades := getTrades() - maFilter := NewFilterVWAPIR(dia.Asset{}, "Binance", trades[len(trades)-1].Time, dia.BlockSizeSeconds) + maFilter := NewFilterVWAPIR(dia.Asset{}, "Binance", trades[len(trades)-1].Time, dia.BlockSizeSeconds, false) for _, trade := range trades { @@ -32,7 +32,7 @@ func BenchmarkVWAPIR(b *testing.B) { trades := getTrades() for n := 0; n < b.N; n++ { - maFilter := NewFilterVWAPIR(dia.Asset{}, "Binance", trades[len(trades)-1].Time, dia.BlockSizeSeconds) + maFilter := NewFilterVWAPIR(dia.Asset{}, "Binance", trades[len(trades)-1].Time, dia.BlockSizeSeconds, false) for _, trade := range trades { diff --git a/internal/pkg/filtersBlockService/FilterVWAP_test.go b/internal/pkg/filtersBlockService/FilterVWAP_test.go index 166ae68e3..e3cbc7e34 100644 --- a/internal/pkg/filtersBlockService/FilterVWAP_test.go +++ b/internal/pkg/filtersBlockService/FilterVWAP_test.go @@ -17,7 +17,7 @@ func getTrades() (trades []dia.Trade) { func TestVWAP(t *testing.T) { var filterPoints []dia.FilterPoint trades := getTrades() - maFilter := NewFilterVWAP(dia.Asset{}, "Binance", trades[len(trades)-1].Time, dia.BlockSizeSeconds) + maFilter := NewFilterVWAP(dia.Asset{}, "Binance", trades[len(trades)-1].Time, dia.BlockSizeSeconds, false) totalVolume := 0.0 totalPrice := 0.0 @@ -47,7 +47,7 @@ func BenchmarkVWAP(b *testing.B) { trades := getTrades() for n := 0; n < b.N; n++ { - maFilter := NewFilterVWAP(dia.Asset{}, "Binance", trades[len(trades)-1].Time, dia.BlockSizeSeconds) + maFilter := NewFilterVWAP(dia.Asset{}, "Binance", trades[len(trades)-1].Time, dia.BlockSizeSeconds, false) for _, trade := range trades { diff --git a/internal/pkg/filtersBlockService/FiltersBlockService.go b/internal/pkg/filtersBlockService/FiltersBlockService.go index 890bdfa2b..fecd6bf06 100644 --- a/internal/pkg/filtersBlockService/FiltersBlockService.go +++ b/internal/pkg/filtersBlockService/FiltersBlockService.go @@ -184,10 +184,10 @@ func (s *FiltersBlockService) createFilters(asset dia.Asset, exchange string, Be _, ok := s.filters[fa] if !ok { s.filters[fa] = []Filter{ - NewFilterMA(asset, exchange, BeginTime, dia.BlockSizeSeconds), - NewFilterMAIR(asset, exchange, BeginTime, dia.BlockSizeSeconds), - NewFilterMEDIR(asset, exchange, BeginTime, dia.BlockSizeSeconds), - NewFilterVWAPIR(asset, exchange, BeginTime, dia.BlockSizeSeconds), + NewFilterMA(asset, exchange, BeginTime, dia.BlockSizeSeconds, false), + NewFilterMAIR(asset, exchange, BeginTime, dia.BlockSizeSeconds, false), + NewFilterMEDIR(asset, exchange, BeginTime, dia.BlockSizeSeconds, false), + NewFilterVWAPIR(asset, exchange, BeginTime, dia.BlockSizeSeconds, false), NewFilterVOL(asset, exchange, dia.BlockSizeSeconds), NewFilterCOUNT(asset, exchange, dia.BlockSizeSeconds), NewFilterTLT(asset, exchange), diff --git a/pkg/dia/helpers/queryHelper/filters.go b/pkg/dia/helpers/queryHelper/filters.go index ee9a35d23..85393414e 100644 --- a/pkg/dia/helpers/queryHelper/filters.go +++ b/pkg/dia/helpers/queryHelper/filters.go @@ -16,7 +16,7 @@ func FilterMA(tradeBlocks []Block, asset dia.Asset, blockSize int) (filterPoints metadata = dia.NewFilterPointMetadata() for _, block := range tradeBlocks { if len(block.Trades) > 0 { - maFilter := filters.NewFilterMA(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize) + maFilter := filters.NewFilterMA(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize, false) for _, trade := range block.Trades { maFilter.Compute(trade) @@ -59,7 +59,7 @@ func FilterMAIR(tradeBlocks []Block, asset dia.Asset, blockSize int) (filterPoin log.Infof("block number: %v", i) if len(block.Trades) > 0 { - mairFilter := filters.NewFilterMAIR(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize) + mairFilter := filters.NewFilterMAIR(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize, false) firstBlock := block.Trades[0] for _, trade := range block.Trades { mairFilter.Compute(trade) @@ -99,7 +99,7 @@ func FilterVWAP(tradeBlocks []Block, asset dia.Asset, blockSize int) (filterPoin metadata = dia.NewFilterPointMetadata() for _, block := range tradeBlocks { if len(block.Trades) > 0 { - vwapFilter := filters.NewFilterVWAP(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize) + vwapFilter := filters.NewFilterVWAP(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize, false) for _, trade := range block.Trades { vwapFilter.Compute(trade) @@ -135,7 +135,7 @@ func FilterVWAPIR(tradeBlocks []Block, asset dia.Asset, blockSize int) (filterPo for _, block := range tradeBlocks { if len(block.Trades) > 0 { - vwapirFilter := filters.NewFilterVWAPIR(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize) + vwapirFilter := filters.NewFilterVWAPIR(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize, false) for _, trade := range block.Trades { vwapirFilter.Compute(trade) } @@ -177,7 +177,7 @@ func FilterMEDIR(tradeBlocks []Block, asset dia.Asset, blockSize int) (filterPoi for _, block := range tradeBlocks { if len(block.Trades) > 0 { - medirFilter := filters.NewFilterMEDIR(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize) + medirFilter := filters.NewFilterMEDIR(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize, false) for _, trade := range block.Trades { diff --git a/pkg/dia/helpers/queryHelper/filtersExtended.go b/pkg/dia/helpers/queryHelper/filtersExtended.go index cce061b56..6505b3c2e 100644 --- a/pkg/dia/helpers/queryHelper/filtersExtended.go +++ b/pkg/dia/helpers/queryHelper/filtersExtended.go @@ -7,7 +7,7 @@ import ( "github.com/diadata-org/diadata/pkg/dia" ) -func FilterMAextended(tradeBlocks []Block, asset dia.Asset, blockSize int, volumeThresholdUSD float64) (filterPointsExtended []dia.FilterPointExtended) { +func FilterMAextended(tradeBlocks []Block, asset dia.Asset, blockSize int, volumeThresholdUSD float64, nativeDenomination bool) (filterPointsExtended []dia.FilterPointExtended) { lastfp := &dia.FilterPoint{} @@ -19,7 +19,7 @@ func FilterMAextended(tradeBlocks []Block, asset dia.Asset, blockSize int, volum fpe.Pools = pools if len(block.Trades) > 0 { - maFilter := filters.NewFilterMA(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize) + maFilter := filters.NewFilterMA(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize, nativeDenomination) for _, trade := range block.Trades { if trade.VolumeUSD() > volumeThresholdUSD { @@ -61,7 +61,7 @@ func FilterMAextended(tradeBlocks []Block, asset dia.Asset, blockSize int, volum return } -func FilterMAIRextended(tradeBlocks []Block, asset dia.Asset, blockSize int, volumeThresholdUSD float64) (filterPointsExtended []dia.FilterPointExtended) { +func FilterMAIRextended(tradeBlocks []Block, asset dia.Asset, blockSize int, volumeThresholdUSD float64, nativeDenomination bool) (filterPointsExtended []dia.FilterPointExtended) { lastfp := &dia.FilterPoint{} for _, block := range tradeBlocks { @@ -71,7 +71,7 @@ func FilterMAIRextended(tradeBlocks []Block, asset dia.Asset, blockSize int, vol fpe.Pools = pools if len(block.Trades) > 0 { - mairFilter := filters.NewFilterMAIR(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize) + mairFilter := filters.NewFilterMAIR(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize, nativeDenomination) for _, trade := range block.Trades { if trade.VolumeUSD() > volumeThresholdUSD { fpe.TradesCount++ @@ -113,7 +113,7 @@ func FilterMAIRextended(tradeBlocks []Block, asset dia.Asset, blockSize int, vol return } -func FilterVWAPextended(tradeBlocks []Block, asset dia.Asset, blockSize int, volumeThresholdUSD float64) (filterPointsExtended []dia.FilterPointExtended) { +func FilterVWAPextended(tradeBlocks []Block, asset dia.Asset, blockSize int, volumeThresholdUSD float64, nativeDenomination bool) (filterPointsExtended []dia.FilterPointExtended) { var lastfp *dia.FilterPoint for _, block := range tradeBlocks { @@ -124,7 +124,7 @@ func FilterVWAPextended(tradeBlocks []Block, asset dia.Asset, blockSize int, vol if len(block.Trades) > 0 { - vwapFilter := filters.NewFilterVWAP(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize) + vwapFilter := filters.NewFilterVWAP(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize, nativeDenomination) for _, trade := range block.Trades { if trade.VolumeUSD() > volumeThresholdUSD { fpe.TradesCount++ @@ -161,7 +161,7 @@ func FilterVWAPextended(tradeBlocks []Block, asset dia.Asset, blockSize int, vol return } -func FilterVWAPIRextended(tradeBlocks []Block, asset dia.Asset, blockSize int, volumeThresholdUSD float64) (filterPointsExtended []dia.FilterPointExtended) { +func FilterVWAPIRextended(tradeBlocks []Block, asset dia.Asset, blockSize int, volumeThresholdUSD float64, nativeDenomination bool) (filterPointsExtended []dia.FilterPointExtended) { var lastfp *dia.FilterPoint for _, block := range tradeBlocks { @@ -173,7 +173,7 @@ func FilterVWAPIRextended(tradeBlocks []Block, asset dia.Asset, blockSize int, v if len(block.Trades) > 0 { - vwapirFilter := filters.NewFilterVWAPIR(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize) + vwapirFilter := filters.NewFilterVWAPIR(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize, nativeDenomination) for _, trade := range block.Trades { if trade.VolumeUSD() > volumeThresholdUSD { fpe.TradesCount++ @@ -216,7 +216,7 @@ func FilterVWAPIRextended(tradeBlocks []Block, asset dia.Asset, blockSize int, v return } -func FilterMEDIRextended(tradeBlocks []Block, asset dia.Asset, blockSize int, volumeThresholdUSD float64) (filterPointsExtended []dia.FilterPointExtended) { +func FilterMEDIRextended(tradeBlocks []Block, asset dia.Asset, blockSize int, volumeThresholdUSD float64, nativeDenomination bool) (filterPointsExtended []dia.FilterPointExtended) { var lastfp *dia.FilterPoint for _, block := range tradeBlocks { @@ -228,7 +228,7 @@ func FilterMEDIRextended(tradeBlocks []Block, asset dia.Asset, blockSize int, vo if len(block.Trades) > 0 { - medirFilter := filters.NewFilterMEDIR(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize) + medirFilter := filters.NewFilterMEDIR(asset, "", time.Unix(block.TimeStamp/1e9, 0), blockSize, nativeDenomination) for _, trade := range block.Trades { if trade.VolumeUSD() > volumeThresholdUSD { fpe.TradesCount++ diff --git a/pkg/graphql/resolver/root.go b/pkg/graphql/resolver/root.go index fabe36984..8a2df4788 100644 --- a/pkg/graphql/resolver/root.go +++ b/pkg/graphql/resolver/root.go @@ -451,6 +451,7 @@ func (r *DiaResolver) GetFeed(ctx context.Context, args struct { StartTime graphql.NullTime EndTime graphql.NullTime TradeVolumeThreshold graphql.NullFloat + NativeDenomination graphql.NullBool FeedSelection *[]FeedSelection }) (*[]*FilterPointExtendedResolver, error) { var ( @@ -461,6 +462,7 @@ func (r *DiaResolver) GetFeed(ctx context.Context, args struct { blockShiftSeconds int64 tradeVolumeThreshold float64 err error + nativeDenomination bool ) // Parsing input parameters. @@ -515,6 +517,12 @@ func (r *DiaResolver) GetFeed(ctx context.Context, args struct { tradeVolumeThreshold = TRADE_VOLUME_THRESHOLD_DEFAULT } + // If nativeDenomination is true, price is returned in terms of the respective base asset. + // Default is false, i.e. price is returned in USD denomination. + if args.NativeDenomination.Value != nil { + nativeDenomination = *args.NativeDenomination.Value + } + if args.FeedSelection == nil { return sr, errors.New("At least 1 asset must be selected.") } @@ -599,23 +607,23 @@ func (r *DiaResolver) GetFeed(ctx context.Context, args struct { // } case "mair": { - filterPoints = queryhelper.FilterMAIRextended(tradeBlocks, feedselection[0].Asset, int(blockSizeSeconds), tradeVolumeThreshold) + filterPoints = queryhelper.FilterMAIRextended(tradeBlocks, feedselection[0].Asset, int(blockSizeSeconds), tradeVolumeThreshold, nativeDenomination) } case "ma": { - filterPoints = queryhelper.FilterMAextended(tradeBlocks, feedselection[0].Asset, int(blockSizeSeconds), tradeVolumeThreshold) + filterPoints = queryhelper.FilterMAextended(tradeBlocks, feedselection[0].Asset, int(blockSizeSeconds), tradeVolumeThreshold, nativeDenomination) } case "vwap": { - filterPoints = queryhelper.FilterVWAPextended(tradeBlocks, feedselection[0].Asset, int(blockSizeSeconds), tradeVolumeThreshold) + filterPoints = queryhelper.FilterVWAPextended(tradeBlocks, feedselection[0].Asset, int(blockSizeSeconds), tradeVolumeThreshold, nativeDenomination) } case "vwapir": { - filterPoints = queryhelper.FilterVWAPIRextended(tradeBlocks, feedselection[0].Asset, int(blockSizeSeconds), tradeVolumeThreshold) + filterPoints = queryhelper.FilterVWAPIRextended(tradeBlocks, feedselection[0].Asset, int(blockSizeSeconds), tradeVolumeThreshold, nativeDenomination) } case "medir": { - filterPoints = queryhelper.FilterMEDIRextended(tradeBlocks, feedselection[0].Asset, int(blockSizeSeconds), tradeVolumeThreshold) + filterPoints = queryhelper.FilterMEDIRextended(tradeBlocks, feedselection[0].Asset, int(blockSizeSeconds), tradeVolumeThreshold, nativeDenomination) } case "vol": {