Skip to content

Commit

Permalink
feat: aggregate market data indicators in JSON format
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz committed Nov 30, 2023
1 parent 8ee1a35 commit a9b2f7e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/controllers/api/v1/market_data_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ module V1
class MarketDataController < ApplicationController
skip_before_action :check_header_info

def index
render json: MarketData.new.indicators_json
end

def show
render json: MarketData.new(indicator: params[:id]).call
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/market_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def call
send(indicator)
end

def indicators_json
VALID_INDICATORS.index_with { |indicator| send(indicator) }
end

def ecosystem_locked
if current_timestamp < first_released_timestamp_other
ECOSYSTEM_QUOTA * 0.97
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
resources :daily_statistics, only: :show
resources :block_statistics, only: :show ## TODO: unused route
resources :epoch_statistics, only: :show
resources :market_data, only: :show
resources :market_data, only: [:index, :show]
resources :udts, only: %i(index show update) do
collection do
get :download_csv
Expand Down
6 changes: 3 additions & 3 deletions test/controllers/api/v1/market_data_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MarketDataControllerTest < ActionDispatch::IntegrationTest
create(:daily_statistic, treasury_amount: "45507635189304330.674891957030103511696912093394364431189654516859837775", created_at_unixtimestamp: Time.current.yesterday.beginning_of_day.to_i)
end

test "should set right content type when call index" do
test "should set right content type when call show" do
create(:address, address_hash: "ckb1qyqy6mtud5sgctjwgg6gydd0ea05mr339lnslczzrc", balance: 10**8 * 1000)
valid_get api_v1_market_datum_url("circulating_supply")

Expand Down Expand Up @@ -69,9 +69,9 @@ class MarketDataControllerTest < ActionDispatch::IntegrationTest
test "should return current circulating supply" do
create(:address, address_hash: "ckb1qyqy6mtud5sgctjwgg6gydd0ea05mr339lnslczzrc", balance: 10**8 * 1000)
valid_get api_v1_market_datum_url("circulating_supply")
MarketData.new(indicator: "circulating_supply").call
result = MarketData.new(indicator: "circulating_supply").call

assert_equal MarketData.new(indicator: "circulating_supply").call.to_s, json
assert_equal result.to_s, json
end
end
end
Expand Down

0 comments on commit a9b2f7e

Please sign in to comment.