Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECO-1520] fix function permissions #749

Merged
merged 1 commit into from Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/rust/dbv2/migrations/2024-04-10-175509_fix_tickers/down.sql
@@ -0,0 +1,29 @@
-- This file should undo anything in `up.sql`
CREATE OR REPLACE FUNCTION api.get_market_best_ask_price (market_id numeric) RETURNS NUMERIC AS $$
SELECT min_ask
FROM aggregator.spreads
WHERE market_id = $1
ORDER BY "time" DESC
LIMIT 1
$$ LANGUAGE SQL;


CREATE OR REPLACE FUNCTION api.get_market_best_bid_price (market_id numeric) RETURNS NUMERIC AS $$
SELECT max_bid
FROM aggregator.spreads
WHERE market_id = $1
ORDER BY "time" DESC
LIMIT 1
$$ LANGUAGE SQL;


CREATE OR REPLACE FUNCTION api.get_market_liquidity (market_id numeric, depth numeric) RETURNS NUMERIC AS $$
SELECT (amount_ask_ticks + amount_bid_ticks) / (SELECT tick_size FROM market_registration_events WHERE market_id = $1)
FROM aggregator.liquidity
WHERE group_id = (
SELECT group_id FROM aggregator.liquidity_groups WHERE name = 'all' AND market_id = $1
)
AND bps_times_ten = $2 * 10
ORDER BY "time" DESC
LIMIT 1;
$$ LANGUAGE SQL;
33 changes: 33 additions & 0 deletions src/rust/dbv2/migrations/2024-04-10-175509_fix_tickers/up.sql
@@ -0,0 +1,33 @@
-- Your SQL goes here
GRANT SELECT ON api.liquidity TO web_anon;
GRANT SELECT ON api.liquidity_groups TO web_anon;


CREATE OR REPLACE FUNCTION api.get_market_best_ask_price (market_id numeric) RETURNS NUMERIC AS $$
SELECT min_ask
FROM api.spreads
WHERE market_id = $1
ORDER BY "time" DESC
LIMIT 1
$$ LANGUAGE SQL;


CREATE OR REPLACE FUNCTION api.get_market_best_bid_price (market_id numeric) RETURNS NUMERIC AS $$
SELECT max_bid
FROM api.spreads
WHERE market_id = $1
ORDER BY "time" DESC
LIMIT 1
$$ LANGUAGE SQL;


CREATE OR REPLACE FUNCTION api.get_market_liquidity (market_id numeric, depth numeric) RETURNS NUMERIC AS $$
SELECT (amount_ask_ticks + amount_bid_ticks) / (SELECT tick_size FROM market_registration_events WHERE market_id = $1)
FROM api.liquidity
WHERE group_id = (
SELECT group_id FROM api.liquidity_groups WHERE name = 'all' AND market_id = $1
)
AND bps_times_ten = $2 * 10
ORDER BY "time" DESC
LIMIT 1;
$$ LANGUAGE SQL;