Skip to content

Commit

Permalink
exp/ticker: add ledgerCloseTime to markets and ticker GraphQL queries (
Browse files Browse the repository at this point in the history
…#1235)

* exp/ticker: add ledgerCloseTime to markets and ticker GraphQL queries

* exp/ticker: rename ledgerCloseTime to lastLedgerCloseTime for clarity
  • Loading branch information
accordeiro authored May 10, 2019
1 parent 05e37d7 commit 09930b8
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 33 deletions.
1 change: 1 addition & 0 deletions exp/ticker/internal/gql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type partialMarket struct {
Close float64
IntervalStart graphql.Time
FirstLedgerCloseTime graphql.Time
LastLedgerCloseTime graphql.Time
OrderbookStats orderbookStats
}

Expand Down
1 change: 1 addition & 0 deletions exp/ticker/internal/gql/resolvers_market.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func dbMarketToPartialMarket(dbMarket tickerdb.PartialMarket) *partialMarket {
Close: dbMarket.Close,
IntervalStart: graphql.Time{Time: dbMarket.IntervalStart},
FirstLedgerCloseTime: graphql.Time{Time: dbMarket.FirstLedgerCloseTime},
LastLedgerCloseTime: graphql.Time{Time: dbMarket.LastLedgerCloseTime},
OrderbookStats: os,
}
}
64 changes: 32 additions & 32 deletions exp/ticker/internal/gql/static/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions exp/ticker/internal/gql/static/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type Market {
close: Float!
intervalStart: Time!
firstLedgerCloseTime: Time!
lastLedgerCloseTime: Time!
orderbookStats: OrderbookStats!
}

Expand All @@ -90,6 +91,7 @@ type AggregatedMarket {
close: Float!
intervalStart: Time!
firstLedgerCloseTime: Time!
lastLedgerCloseTime: Time!
orderbookStats: OrderbookStats!
}

Expand Down
1 change: 1 addition & 0 deletions exp/ticker/internal/tickerdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ type PartialMarket struct {
LowestAsk float64 `db:"lowest_ask"`
IntervalStart time.Time `db:"interval_start"`
FirstLedgerCloseTime time.Time `db:"first_ledger_close_time"`
LastLedgerCloseTime time.Time `db:"last_ledger_close_time"`
}

// CreateSession returns a new TickerSession that connects to the given db settings
Expand Down
5 changes: 4 additions & 1 deletion exp/ticker/internal/tickerdb/queries_market.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ SELECT
((array_agg(t.price ORDER BY t.ledger_close_time DESC))[1] - (array_agg(t.price ORDER BY t.ledger_close_time ASC))[1]) AS price_change,
(now() - interval '__NUMHOURS__ hours') AS interval_start,
min(t.ledger_close_time) AS first_ledger_close_time,
max(t.ledger_close_time) AS last_ledger_close_time,
COALESCE((array_agg(os.num_bids))[1], 0) AS num_bids,
COALESCE((array_agg(os.bid_volume))[1], 0.0) AS bid_volume,
COALESCE((array_agg(os.highest_bid))[1], 0.0) AS highest_bid,
Expand Down Expand Up @@ -231,6 +232,7 @@ SELECT
t1.price_change,
t1.interval_start,
t1.first_ledger_close_time,
t1.last_ledger_close_time,
COALESCE(aob.base_asset_code, '') as base_asset_code,
COALESCE(aob.counter_asset_code, '') as counter_asset_code,
COALESCE(aob.num_bids, 0) AS num_bids,
Expand All @@ -251,7 +253,8 @@ FROM (
(array_agg(t.price ORDER BY t.ledger_close_time DESC))[1] AS last_price,
((array_agg(t.price ORDER BY t.ledger_close_time DESC))[1] - (array_agg(t.price ORDER BY t.ledger_close_time ASC))[1]) AS price_change,
(now() - interval '__NUMHOURS__ hours') AS interval_start,
min(t.ledger_close_time) AS first_ledger_close_time
min(t.ledger_close_time) AS first_ledger_close_time,
max(t.ledger_close_time) AS last_ledger_close_time
FROM trades AS t
LEFT JOIN orderbook_stats AS os ON t.base_asset_id = os.base_asset_id AND t.counter_asset_id = os.counter_asset_id
JOIN assets AS bAsset ON t.base_asset_id = bAsset.id
Expand Down
15 changes: 15 additions & 0 deletions exp/ticker/internal/tickerdb/queries_market_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,11 @@ func TestRetrievePartialMarkets(t *testing.T) {
oneHourAgo.Local().Truncate(time.Millisecond),
btceth1Mkt.FirstLedgerCloseTime.Local().Truncate(time.Millisecond),
)
assert.Equal(
t,
tenMinutesAgo.Local().Truncate(time.Millisecond),
btceth1Mkt.LastLedgerCloseTime.Local().Truncate(time.Millisecond),
)

assert.Equal(t, 24.0, btceth2Mkt.BaseVolume)
assert.Equal(t, 26.0, btceth2Mkt.CounterVolume)
Expand All @@ -572,6 +577,11 @@ func TestRetrievePartialMarkets(t *testing.T) {
now.Local().Truncate(time.Millisecond),
btceth2Mkt.FirstLedgerCloseTime.Local().Truncate(time.Millisecond),
)
assert.Equal(
t,
now.Local().Truncate(time.Millisecond),
btceth2Mkt.FirstLedgerCloseTime.Local().Truncate(time.Millisecond),
)

// Analyzing non-aggregated orderbook data
assert.Equal(t, 15, btceth1Mkt.NumBids)
Expand Down Expand Up @@ -608,6 +618,11 @@ func TestRetrievePartialMarkets(t *testing.T) {
oneHourAgo.Local().Truncate(time.Millisecond),
partialAggMkt.FirstLedgerCloseTime.Local().Truncate(time.Millisecond),
)
assert.Equal(
t,
now.Local().Truncate(time.Millisecond),
partialAggMkt.LastLedgerCloseTime.Local().Truncate(time.Millisecond),
)

// There might be some floating point rounding issues, so this test
// needs to be a bit more flexible. Since the change is 0.08, an error
Expand Down

0 comments on commit 09930b8

Please sign in to comment.