Compare commits
9 Commits
b02bd6b66c
...
feat/mevno
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71b00f80bb | ||
|
|
01f6543ae9 | ||
|
|
8a474242df | ||
|
|
db4e45dc55 | ||
|
|
3572382c90 | ||
|
|
bb6f633d19 | ||
|
|
108bf22968 | ||
|
|
59c3f3ee06 | ||
|
|
9c4c3096d7 |
@@ -29,7 +29,7 @@ spec:
|
|||||||
- name: DLOB_SOURCE
|
- name: DLOB_SOURCE
|
||||||
value: drift
|
value: drift
|
||||||
- name: DLOB_MARKETS
|
- name: DLOB_MARKETS
|
||||||
value: PUMP-PERP,SOL-PERP,1MBONK-PERP,BTC-PERP,ETH-PERP
|
value: SOL-PERP,DOGE-PERP,JUP-PERP
|
||||||
- name: DLOB_POLL_MS
|
- name: DLOB_POLL_MS
|
||||||
value: "1000"
|
value: "1000"
|
||||||
- name: DLOB_DEPTH_BPS_BANDS
|
- name: DLOB_DEPTH_BPS_BANDS
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ spec:
|
|||||||
- name: DLOB_SOURCE
|
- name: DLOB_SOURCE
|
||||||
value: mevnode
|
value: mevnode
|
||||||
- name: DLOB_MARKETS
|
- name: DLOB_MARKETS
|
||||||
value: PUMP-PERP,SOL-PERP,1MBONK-PERP,BTC-PERP,ETH-PERP
|
value: SOL-PERP,DOGE-PERP,JUP-PERP
|
||||||
- name: DLOB_POLL_MS
|
- name: DLOB_POLL_MS
|
||||||
value: "1000"
|
value: "1000"
|
||||||
- name: DLOB_DEPTH_BPS_BANDS
|
- name: DLOB_DEPTH_BPS_BANDS
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ function resolveConfig() {
|
|||||||
const hasuraAuthToken = process.env.HASURA_AUTH_TOKEN || process.env.HASURA_JWT || undefined;
|
const hasuraAuthToken = process.env.HASURA_AUTH_TOKEN || process.env.HASURA_JWT || undefined;
|
||||||
|
|
||||||
const dlobSource = String(process.env.DLOB_SOURCE || 'mevnode').trim() || 'mevnode';
|
const dlobSource = String(process.env.DLOB_SOURCE || 'mevnode').trim() || 'mevnode';
|
||||||
const markets = envList('DLOB_MARKETS', 'PUMP-PERP,SOL-PERP,1MBONK-PERP,BTC-PERP,ETH-PERP');
|
const markets = envList('DLOB_MARKETS', 'SOL-PERP,DOGE-PERP,JUP-PERP');
|
||||||
const pollMs = clampInt(process.env.DLOB_POLL_MS, 250, 60_000, 1000);
|
const pollMs = clampInt(process.env.DLOB_POLL_MS, 250, 60_000, 1000);
|
||||||
const bandsBps = envIntList('DLOB_DEPTH_BPS_BANDS', '5,10,20,50,100,200');
|
const bandsBps = envIntList('DLOB_DEPTH_BPS_BANDS', '5,10,20,50,100,200');
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ spec:
|
|||||||
- name: DLOB_SOURCE
|
- name: DLOB_SOURCE
|
||||||
value: drift
|
value: drift
|
||||||
- name: DLOB_MARKETS
|
- name: DLOB_MARKETS
|
||||||
value: PUMP-PERP,SOL-PERP,1MBONK-PERP,BTC-PERP,ETH-PERP
|
value: SOL-PERP,DOGE-PERP,JUP-PERP
|
||||||
- name: DLOB_POLL_MS
|
- name: DLOB_POLL_MS
|
||||||
value: "1000"
|
value: "1000"
|
||||||
- name: DLOB_SLIPPAGE_SIZES_USD
|
- name: DLOB_SLIPPAGE_SIZES_USD
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ spec:
|
|||||||
- name: DLOB_SOURCE
|
- name: DLOB_SOURCE
|
||||||
value: mevnode
|
value: mevnode
|
||||||
- name: DLOB_MARKETS
|
- name: DLOB_MARKETS
|
||||||
value: PUMP-PERP,SOL-PERP,1MBONK-PERP,BTC-PERP,ETH-PERP
|
value: SOL-PERP,DOGE-PERP,JUP-PERP
|
||||||
- name: DLOB_POLL_MS
|
- name: DLOB_POLL_MS
|
||||||
value: "1000"
|
value: "1000"
|
||||||
- name: DLOB_SLIPPAGE_SIZES_USD
|
- name: DLOB_SLIPPAGE_SIZES_USD
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ function resolveConfig() {
|
|||||||
const hasuraAuthToken = process.env.HASURA_AUTH_TOKEN || process.env.HASURA_JWT || undefined;
|
const hasuraAuthToken = process.env.HASURA_AUTH_TOKEN || process.env.HASURA_JWT || undefined;
|
||||||
|
|
||||||
const dlobSource = String(process.env.DLOB_SOURCE || 'mevnode').trim() || 'mevnode';
|
const dlobSource = String(process.env.DLOB_SOURCE || 'mevnode').trim() || 'mevnode';
|
||||||
const markets = envList('DLOB_MARKETS', 'PUMP-PERP,SOL-PERP,1MBONK-PERP,BTC-PERP,ETH-PERP');
|
const markets = envList('DLOB_MARKETS', 'SOL-PERP,DOGE-PERP,JUP-PERP');
|
||||||
const pollMs = clampInt(process.env.DLOB_POLL_MS, 250, 60_000, 1000);
|
const pollMs = clampInt(process.env.DLOB_POLL_MS, 250, 60_000, 1000);
|
||||||
|
|
||||||
const sizesUsd = envList('DLOB_SLIPPAGE_SIZES_USD', '10,25,50,100,250,500,1000')
|
const sizesUsd = envList('DLOB_SLIPPAGE_SIZES_USD', '10,25,50,100,250,500,1000')
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ spec:
|
|||||||
- name: DLOB_SOURCE
|
- name: DLOB_SOURCE
|
||||||
value: drift
|
value: drift
|
||||||
- name: DLOB_MARKETS
|
- name: DLOB_MARKETS
|
||||||
value: PUMP-PERP,SOL-PERP,1MBONK-PERP,BTC-PERP,ETH-PERP
|
value: SOL-PERP,DOGE-PERP,JUP-PERP
|
||||||
- name: DLOB_TS_POLL_MS
|
- name: DLOB_TS_POLL_MS
|
||||||
value: "1000"
|
value: "1000"
|
||||||
command: ["node", "/app/worker.mjs"]
|
command: ["node", "/app/worker.mjs"]
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ spec:
|
|||||||
- name: DLOB_SOURCE
|
- name: DLOB_SOURCE
|
||||||
value: mevnode
|
value: mevnode
|
||||||
- name: DLOB_MARKETS
|
- name: DLOB_MARKETS
|
||||||
value: PUMP-PERP,SOL-PERP,1MBONK-PERP,BTC-PERP,ETH-PERP
|
value: SOL-PERP,DOGE-PERP,JUP-PERP
|
||||||
- name: DLOB_TS_POLL_MS
|
- name: DLOB_TS_POLL_MS
|
||||||
value: "1000"
|
value: "1000"
|
||||||
command: ["node", "/app/worker.mjs"]
|
command: ["node", "/app/worker.mjs"]
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ function resolveConfig() {
|
|||||||
const hasuraAuthToken = process.env.HASURA_AUTH_TOKEN || process.env.HASURA_JWT || undefined;
|
const hasuraAuthToken = process.env.HASURA_AUTH_TOKEN || process.env.HASURA_JWT || undefined;
|
||||||
|
|
||||||
const dlobSource = String(process.env.DLOB_SOURCE || 'mevnode').trim() || 'mevnode';
|
const dlobSource = String(process.env.DLOB_SOURCE || 'mevnode').trim() || 'mevnode';
|
||||||
const markets = envList('DLOB_MARKETS', 'PUMP-PERP,SOL-PERP,1MBONK-PERP,BTC-PERP,ETH-PERP');
|
const markets = envList('DLOB_MARKETS', 'SOL-PERP,DOGE-PERP,JUP-PERP');
|
||||||
const pollMs = clampInt(process.env.DLOB_TS_POLL_MS, 500, 60_000, 1000);
|
const pollMs = clampInt(process.env.DLOB_TS_POLL_MS, 500, 60_000, 1000);
|
||||||
|
|
||||||
return { hasuraUrl, hasuraAdminSecret, hasuraAuthToken, dlobSource, markets, pollMs };
|
return { hasuraUrl, hasuraAdminSecret, hasuraAuthToken, dlobSource, markets, pollMs };
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ spec:
|
|||||||
- name: DLOB_FORCE_IPV6
|
- name: DLOB_FORCE_IPV6
|
||||||
value: "true"
|
value: "true"
|
||||||
- name: DLOB_MARKETS
|
- name: DLOB_MARKETS
|
||||||
value: PUMP-PERP,SOL-PERP,1MBONK-PERP,BTC-PERP,ETH-PERP
|
value: SOL-PERP,DOGE-PERP,JUP-PERP
|
||||||
- name: DLOB_POLL_MS
|
- name: DLOB_POLL_MS
|
||||||
value: "500"
|
value: "500"
|
||||||
- name: DLOB_DEPTH
|
- name: DLOB_DEPTH
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ spec:
|
|||||||
- name: DLOB_HTTP_URL
|
- name: DLOB_HTTP_URL
|
||||||
value: http://dlob-server:6969
|
value: http://dlob-server:6969
|
||||||
- name: DLOB_MARKETS
|
- name: DLOB_MARKETS
|
||||||
value: PUMP-PERP,SOL-PERP,1MBONK-PERP,BTC-PERP,ETH-PERP
|
value: SOL-PERP,DOGE-PERP,JUP-PERP
|
||||||
- name: DLOB_POLL_MS
|
- name: DLOB_POLL_MS
|
||||||
value: "500"
|
value: "500"
|
||||||
- name: DLOB_DEPTH
|
- name: DLOB_DEPTH
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ function resolveConfig() {
|
|||||||
const dlobForceIpv6 = envBool('DLOB_FORCE_IPV6', false);
|
const dlobForceIpv6 = envBool('DLOB_FORCE_IPV6', false);
|
||||||
const dlobSource = String(process.env.DLOB_SOURCE || 'mevnode').trim() || 'mevnode';
|
const dlobSource = String(process.env.DLOB_SOURCE || 'mevnode').trim() || 'mevnode';
|
||||||
|
|
||||||
const markets = envList('DLOB_MARKETS', 'PUMP-PERP,SOL-PERP,1MBONK-PERP,BTC-PERP,ETH-PERP');
|
const markets = envList('DLOB_MARKETS', 'SOL-PERP,DOGE-PERP,JUP-PERP');
|
||||||
const depth = clampInt(process.env.DLOB_DEPTH, 1, 50, 10);
|
const depth = clampInt(process.env.DLOB_DEPTH, 1, 50, 10);
|
||||||
const pollMs = clampInt(process.env.DLOB_POLL_MS, 100, 10_000, 500);
|
const pollMs = clampInt(process.env.DLOB_POLL_MS, 100, 10_000, 500);
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ spec:
|
|||||||
- name: gitea-registry
|
- name: gitea-registry
|
||||||
containers:
|
containers:
|
||||||
- name: publisher
|
- name: publisher
|
||||||
image: gitea.mpabi.pl/trade/trade-dlob-server:sha-8a378b7-lite-l2
|
image: gitea.mpabi.pl/trade/trade-dlob-server:sha-5d55631-canonical
|
||||||
imagePullPolicy: IfNotPresent
|
imagePullPolicy: IfNotPresent
|
||||||
ports:
|
ports:
|
||||||
- name: http
|
- name: http
|
||||||
@@ -43,7 +43,7 @@ spec:
|
|||||||
- name: REDIS_CLIENT
|
- name: REDIS_CLIENT
|
||||||
value: DLOB
|
value: DLOB
|
||||||
- name: PERP_MARKETS_TO_LOAD
|
- name: PERP_MARKETS_TO_LOAD
|
||||||
value: "0,1,2,4,75"
|
value: "0,7,24"
|
||||||
- name: ENDPOINT
|
- name: ENDPOINT
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ spec:
|
|||||||
- name: gitea-registry
|
- name: gitea-registry
|
||||||
containers:
|
containers:
|
||||||
- name: server
|
- name: server
|
||||||
image: gitea.mpabi.pl/trade/trade-dlob-server:sha-8a378b7-lite-l2
|
image: gitea.mpabi.pl/trade/trade-dlob-server:sha-5d55631-canonical
|
||||||
imagePullPolicy: IfNotPresent
|
imagePullPolicy: IfNotPresent
|
||||||
ports:
|
ports:
|
||||||
- name: http
|
- name: http
|
||||||
|
|||||||
@@ -96,7 +96,11 @@ async function main() {
|
|||||||
|
|
||||||
const baseTicks = { schema: 'public', name: 'drift_ticks' };
|
const baseTicks = { schema: 'public', name: 'drift_ticks' };
|
||||||
const dlobL2LatestTable = { schema: 'public', name: 'dlob_l2_latest' };
|
const dlobL2LatestTable = { schema: 'public', name: 'dlob_l2_latest' };
|
||||||
|
const dlobL2LatestProjectionView = { schema: 'public', name: 'dlob_l2_latest_projection' };
|
||||||
|
const dlobL3LatestProjectionView = { schema: 'public', name: 'dlob_l3_latest_projection' };
|
||||||
|
const dlobBestMakersLatestProjectionView = { schema: 'public', name: 'dlob_best_makers_latest_projection' };
|
||||||
const dlobStatsLatestTable = { schema: 'public', name: 'dlob_stats_latest' };
|
const dlobStatsLatestTable = { schema: 'public', name: 'dlob_stats_latest' };
|
||||||
|
const dlobStatsLatestProjectionView = { schema: 'public', name: 'dlob_stats_latest_projection' };
|
||||||
const dlobDepthBpsLatestTable = { schema: 'public', name: 'dlob_depth_bps_latest' };
|
const dlobDepthBpsLatestTable = { schema: 'public', name: 'dlob_depth_bps_latest' };
|
||||||
const dlobSlippageLatestTable = { schema: 'public', name: 'dlob_slippage_latest' };
|
const dlobSlippageLatestTable = { schema: 'public', name: 'dlob_slippage_latest' };
|
||||||
const dlobSlippageLatestV2Table = { schema: 'public', name: 'dlob_slippage_latest_v2' };
|
const dlobSlippageLatestV2Table = { schema: 'public', name: 'dlob_slippage_latest_v2' };
|
||||||
@@ -261,9 +265,36 @@ async function main() {
|
|||||||
await metadataIgnore({ type: 'pg_drop_update_permission', args: { source, table, role: 'ingestor' } });
|
await metadataIgnore({ type: 'pg_drop_update_permission', args: { source, table, role: 'ingestor' } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function ensureProjectedPublicSelectTable(table, columns, { publicFilter, customName } = {}) {
|
||||||
|
await metadataIgnore({ type: 'pg_untrack_table', args: { source, table, cascade: true } });
|
||||||
|
const args = { source, table };
|
||||||
|
if (customName) {
|
||||||
|
args.configuration = { custom_name: customName };
|
||||||
|
}
|
||||||
|
await metadata({ type: 'pg_track_table', args });
|
||||||
|
|
||||||
|
await metadataIgnore({ type: 'pg_drop_select_permission', args: { source, table, role: 'public' } });
|
||||||
|
await metadata({
|
||||||
|
type: 'pg_create_select_permission',
|
||||||
|
args: {
|
||||||
|
source,
|
||||||
|
table,
|
||||||
|
role: 'public',
|
||||||
|
permission: {
|
||||||
|
columns,
|
||||||
|
filter: publicFilter || {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await metadataIgnore({ type: 'pg_drop_insert_permission', args: { source, table, role: 'ingestor' } });
|
||||||
|
await metadataIgnore({ type: 'pg_drop_update_permission', args: { source, table, role: 'ingestor' } });
|
||||||
|
}
|
||||||
|
|
||||||
const dlobPublicFilter = { source: { _eq: PUBLIC_DLOB_SOURCE_HEADER } };
|
const dlobPublicFilter = { source: { _eq: PUBLIC_DLOB_SOURCE_HEADER } };
|
||||||
|
|
||||||
await ensureDlobTable(dlobL2LatestTable, [
|
await metadataIgnore({ type: 'pg_untrack_table', args: { source, table: dlobL2LatestTable, cascade: true } });
|
||||||
|
await ensureProjectedPublicSelectTable(dlobL2LatestProjectionView, [
|
||||||
'source',
|
'source',
|
||||||
'market_name',
|
'market_name',
|
||||||
'market_type',
|
'market_type',
|
||||||
@@ -278,9 +309,10 @@ async function main() {
|
|||||||
'asks',
|
'asks',
|
||||||
'raw',
|
'raw',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
], { publicFilter: dlobPublicFilter });
|
], { publicFilter: dlobPublicFilter, customName: 'dlob_l2_latest' });
|
||||||
|
|
||||||
await ensureDlobTable(dlobStatsLatestTable, [
|
await metadataIgnore({ type: 'pg_untrack_table', args: { source, table: dlobStatsLatestTable, cascade: true } });
|
||||||
|
await ensureProjectedPublicSelectTable(dlobStatsLatestProjectionView, [
|
||||||
'source',
|
'source',
|
||||||
'market_name',
|
'market_name',
|
||||||
'market_type',
|
'market_type',
|
||||||
@@ -302,6 +334,31 @@ async function main() {
|
|||||||
'imbalance',
|
'imbalance',
|
||||||
'raw',
|
'raw',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
|
], { publicFilter: dlobPublicFilter, customName: 'dlob_stats_latest' });
|
||||||
|
|
||||||
|
await ensureProjectedPublicSelectTable(dlobL3LatestProjectionView, [
|
||||||
|
'source',
|
||||||
|
'market_name',
|
||||||
|
'market_type',
|
||||||
|
'market_index',
|
||||||
|
'ts',
|
||||||
|
'slot',
|
||||||
|
'bids',
|
||||||
|
'asks',
|
||||||
|
'raw',
|
||||||
|
'updated_at',
|
||||||
|
], { publicFilter: dlobPublicFilter });
|
||||||
|
|
||||||
|
await ensureProjectedPublicSelectTable(dlobBestMakersLatestProjectionView, [
|
||||||
|
'source',
|
||||||
|
'market_name',
|
||||||
|
'market_type',
|
||||||
|
'market_index',
|
||||||
|
'slot',
|
||||||
|
'bids',
|
||||||
|
'asks',
|
||||||
|
'raw',
|
||||||
|
'updated_at',
|
||||||
], { publicFilter: dlobPublicFilter });
|
], { publicFilter: dlobPublicFilter });
|
||||||
|
|
||||||
await ensurePublicSelectTable(dlobDepthBpsLatestTable, [
|
await ensurePublicSelectTable(dlobDepthBpsLatestTable, [
|
||||||
|
|||||||
@@ -814,3 +814,246 @@ BEGIN
|
|||||||
PERFORM add_retention_policy('dlob_slippage_ts_v2', INTERVAL '7 days');
|
PERFORM add_retention_policy('dlob_slippage_ts_v2', INTERVAL '7 days');
|
||||||
EXCEPTION WHEN OTHERS THEN
|
EXCEPTION WHEN OTHERS THEN
|
||||||
END $$;
|
END $$;
|
||||||
|
|
||||||
|
-- Canonical DLOB storage and projection layer.
|
||||||
|
CREATE TABLE IF NOT EXISTS public.dlob_orderbook_l2_latest (
|
||||||
|
source TEXT NOT NULL,
|
||||||
|
market_name TEXT NOT NULL,
|
||||||
|
market_type TEXT NOT NULL,
|
||||||
|
market_index INTEGER,
|
||||||
|
is_indicative BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
ts BIGINT,
|
||||||
|
slot BIGINT,
|
||||||
|
mark_price_raw TEXT,
|
||||||
|
oracle_price_raw TEXT,
|
||||||
|
best_bid_price_raw TEXT,
|
||||||
|
best_ask_price_raw TEXT,
|
||||||
|
spread_pct_raw TEXT,
|
||||||
|
spread_quote_raw TEXT,
|
||||||
|
oracle_data JSONB,
|
||||||
|
bids JSONB,
|
||||||
|
asks JSONB,
|
||||||
|
payload JSONB NOT NULL,
|
||||||
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
|
PRIMARY KEY (source, market_name, is_indicative)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS public.dlob_orderbook_l3_latest (
|
||||||
|
source TEXT NOT NULL,
|
||||||
|
market_name TEXT NOT NULL,
|
||||||
|
market_type TEXT NOT NULL,
|
||||||
|
market_index INTEGER,
|
||||||
|
is_indicative BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
ts BIGINT,
|
||||||
|
slot BIGINT,
|
||||||
|
oracle_data JSONB,
|
||||||
|
bids JSONB,
|
||||||
|
asks JSONB,
|
||||||
|
payload JSONB NOT NULL,
|
||||||
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
|
PRIMARY KEY (source, market_name, is_indicative)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS public.dlob_best_makers_latest (
|
||||||
|
source TEXT NOT NULL,
|
||||||
|
market_name TEXT NOT NULL,
|
||||||
|
market_type TEXT NOT NULL,
|
||||||
|
market_index INTEGER,
|
||||||
|
slot BIGINT,
|
||||||
|
bids JSONB,
|
||||||
|
asks JSONB,
|
||||||
|
payload JSONB NOT NULL,
|
||||||
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
|
PRIMARY KEY (source, market_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS dlob_orderbook_l2_latest_updated_at_idx
|
||||||
|
ON public.dlob_orderbook_l2_latest (updated_at DESC);
|
||||||
|
CREATE INDEX IF NOT EXISTS dlob_orderbook_l3_latest_updated_at_idx
|
||||||
|
ON public.dlob_orderbook_l3_latest (updated_at DESC);
|
||||||
|
CREATE INDEX IF NOT EXISTS dlob_best_makers_latest_updated_at_idx
|
||||||
|
ON public.dlob_best_makers_latest (updated_at DESC);
|
||||||
|
|
||||||
|
CREATE OR REPLACE VIEW public.dlob_l2_latest_projection AS
|
||||||
|
SELECT
|
||||||
|
source,
|
||||||
|
market_name,
|
||||||
|
market_type,
|
||||||
|
market_index,
|
||||||
|
ts,
|
||||||
|
slot,
|
||||||
|
CASE
|
||||||
|
WHEN NULLIF(mark_price_raw, '') IS NULL THEN NULL
|
||||||
|
ELSE NULLIF(mark_price_raw, '')::numeric / 1000000::numeric
|
||||||
|
END AS mark_price,
|
||||||
|
CASE
|
||||||
|
WHEN NULLIF(oracle_price_raw, '') IS NULL THEN NULL
|
||||||
|
ELSE NULLIF(oracle_price_raw, '')::numeric / 1000000::numeric
|
||||||
|
END AS oracle_price,
|
||||||
|
CASE
|
||||||
|
WHEN NULLIF(best_bid_price_raw, '') IS NULL THEN NULL
|
||||||
|
ELSE NULLIF(best_bid_price_raw, '')::numeric / 1000000::numeric
|
||||||
|
END AS best_bid_price,
|
||||||
|
CASE
|
||||||
|
WHEN NULLIF(best_ask_price_raw, '') IS NULL THEN NULL
|
||||||
|
ELSE NULLIF(best_ask_price_raw, '')::numeric / 1000000::numeric
|
||||||
|
END AS best_ask_price,
|
||||||
|
bids,
|
||||||
|
asks,
|
||||||
|
payload AS raw,
|
||||||
|
updated_at
|
||||||
|
FROM public.dlob_orderbook_l2_latest
|
||||||
|
WHERE is_indicative = FALSE;
|
||||||
|
|
||||||
|
CREATE OR REPLACE VIEW public.dlob_l3_latest_projection AS
|
||||||
|
SELECT
|
||||||
|
source,
|
||||||
|
market_name,
|
||||||
|
market_type,
|
||||||
|
market_index,
|
||||||
|
ts,
|
||||||
|
slot,
|
||||||
|
bids,
|
||||||
|
asks,
|
||||||
|
payload AS raw,
|
||||||
|
updated_at
|
||||||
|
FROM public.dlob_orderbook_l3_latest
|
||||||
|
WHERE is_indicative = FALSE;
|
||||||
|
|
||||||
|
CREATE OR REPLACE VIEW public.dlob_best_makers_latest_projection AS
|
||||||
|
SELECT
|
||||||
|
source,
|
||||||
|
market_name,
|
||||||
|
market_type,
|
||||||
|
market_index,
|
||||||
|
slot,
|
||||||
|
bids,
|
||||||
|
asks,
|
||||||
|
payload AS raw,
|
||||||
|
updated_at
|
||||||
|
FROM public.dlob_best_makers_latest;
|
||||||
|
|
||||||
|
CREATE OR REPLACE VIEW public.dlob_stats_latest_projection AS
|
||||||
|
WITH base AS (
|
||||||
|
SELECT
|
||||||
|
source,
|
||||||
|
market_name,
|
||||||
|
market_type,
|
||||||
|
market_index,
|
||||||
|
ts,
|
||||||
|
slot,
|
||||||
|
CASE
|
||||||
|
WHEN NULLIF(mark_price_raw, '') IS NULL THEN NULL
|
||||||
|
ELSE NULLIF(mark_price_raw, '')::numeric / 1000000::numeric
|
||||||
|
END AS mark_price,
|
||||||
|
CASE
|
||||||
|
WHEN NULLIF(oracle_price_raw, '') IS NULL THEN NULL
|
||||||
|
ELSE NULLIF(oracle_price_raw, '')::numeric / 1000000::numeric
|
||||||
|
END AS oracle_price,
|
||||||
|
CASE
|
||||||
|
WHEN NULLIF(best_bid_price_raw, '') IS NULL THEN NULL
|
||||||
|
ELSE NULLIF(best_bid_price_raw, '')::numeric / 1000000::numeric
|
||||||
|
END AS best_bid_price,
|
||||||
|
CASE
|
||||||
|
WHEN NULLIF(best_ask_price_raw, '') IS NULL THEN NULL
|
||||||
|
ELSE NULLIF(best_ask_price_raw, '')::numeric / 1000000::numeric
|
||||||
|
END AS best_ask_price,
|
||||||
|
bids,
|
||||||
|
asks,
|
||||||
|
payload,
|
||||||
|
updated_at
|
||||||
|
FROM public.dlob_orderbook_l2_latest
|
||||||
|
WHERE is_indicative = FALSE
|
||||||
|
),
|
||||||
|
bid_levels AS (
|
||||||
|
SELECT
|
||||||
|
b.source,
|
||||||
|
b.market_name,
|
||||||
|
COALESCE(
|
||||||
|
SUM((NULLIF(level->>'size', '')::numeric) / 1000000000::numeric),
|
||||||
|
0::numeric
|
||||||
|
) AS depth_bid_base,
|
||||||
|
COALESCE(
|
||||||
|
SUM(
|
||||||
|
((NULLIF(level->>'size', '')::numeric) / 1000000000::numeric) *
|
||||||
|
((NULLIF(level->>'price', '')::numeric) / 1000000::numeric)
|
||||||
|
),
|
||||||
|
0::numeric
|
||||||
|
) AS depth_bid_usd
|
||||||
|
FROM base b
|
||||||
|
LEFT JOIN LATERAL (
|
||||||
|
SELECT level
|
||||||
|
FROM jsonb_array_elements(COALESCE(b.bids, '[]'::jsonb)) WITH ORDINALITY AS e(level, ord)
|
||||||
|
WHERE ord <= 10
|
||||||
|
) levels ON TRUE
|
||||||
|
GROUP BY b.source, b.market_name
|
||||||
|
),
|
||||||
|
ask_levels AS (
|
||||||
|
SELECT
|
||||||
|
b.source,
|
||||||
|
b.market_name,
|
||||||
|
COALESCE(
|
||||||
|
SUM((NULLIF(level->>'size', '')::numeric) / 1000000000::numeric),
|
||||||
|
0::numeric
|
||||||
|
) AS depth_ask_base,
|
||||||
|
COALESCE(
|
||||||
|
SUM(
|
||||||
|
((NULLIF(level->>'size', '')::numeric) / 1000000000::numeric) *
|
||||||
|
((NULLIF(level->>'price', '')::numeric) / 1000000::numeric)
|
||||||
|
),
|
||||||
|
0::numeric
|
||||||
|
) AS depth_ask_usd
|
||||||
|
FROM base b
|
||||||
|
LEFT JOIN LATERAL (
|
||||||
|
SELECT level
|
||||||
|
FROM jsonb_array_elements(COALESCE(b.asks, '[]'::jsonb)) WITH ORDINALITY AS e(level, ord)
|
||||||
|
WHERE ord <= 10
|
||||||
|
) levels ON TRUE
|
||||||
|
GROUP BY b.source, b.market_name
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
b.source,
|
||||||
|
b.market_name,
|
||||||
|
b.market_type,
|
||||||
|
b.market_index,
|
||||||
|
b.ts,
|
||||||
|
b.slot,
|
||||||
|
b.mark_price,
|
||||||
|
b.oracle_price,
|
||||||
|
b.best_bid_price,
|
||||||
|
b.best_ask_price,
|
||||||
|
CASE
|
||||||
|
WHEN b.best_bid_price IS NOT NULL AND b.best_ask_price IS NOT NULL
|
||||||
|
THEN (b.best_bid_price + b.best_ask_price) / 2
|
||||||
|
ELSE NULL
|
||||||
|
END AS mid_price,
|
||||||
|
CASE
|
||||||
|
WHEN b.best_bid_price IS NOT NULL AND b.best_ask_price IS NOT NULL
|
||||||
|
THEN b.best_ask_price - b.best_bid_price
|
||||||
|
ELSE NULL
|
||||||
|
END AS spread_abs,
|
||||||
|
CASE
|
||||||
|
WHEN b.best_bid_price IS NOT NULL
|
||||||
|
AND b.best_ask_price IS NOT NULL
|
||||||
|
AND (b.best_bid_price + b.best_ask_price) > 0
|
||||||
|
THEN ((b.best_ask_price - b.best_bid_price) / ((b.best_bid_price + b.best_ask_price) / 2)) * 10000
|
||||||
|
ELSE NULL
|
||||||
|
END AS spread_bps,
|
||||||
|
10::integer AS depth_levels,
|
||||||
|
bids.depth_bid_base,
|
||||||
|
asks.depth_ask_base,
|
||||||
|
bids.depth_bid_usd,
|
||||||
|
asks.depth_ask_usd,
|
||||||
|
CASE
|
||||||
|
WHEN (bids.depth_bid_usd + asks.depth_ask_usd) > 0
|
||||||
|
THEN (bids.depth_bid_usd - asks.depth_ask_usd) / (bids.depth_bid_usd + asks.depth_ask_usd)
|
||||||
|
ELSE NULL
|
||||||
|
END AS imbalance,
|
||||||
|
jsonb_build_object(
|
||||||
|
'canonical_table', 'dlob_orderbook_l2_latest',
|
||||||
|
'projection', 'dlob_stats_latest_projection'
|
||||||
|
) AS raw,
|
||||||
|
b.updated_at
|
||||||
|
FROM base b
|
||||||
|
LEFT JOIN bid_levels bids USING (source, market_name)
|
||||||
|
LEFT JOIN ask_levels asks USING (source, market_name);
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ data:
|
|||||||
"timezone": "browser",
|
"timezone": "browser",
|
||||||
"schemaVersion": 39,
|
"schemaVersion": 39,
|
||||||
"version": 2,
|
"version": 2,
|
||||||
|
"time": { "from": "now-6h", "to": "now" },
|
||||||
|
"timepicker": {
|
||||||
|
"refresh_intervals": ["5s", "10s", "30s", "1m", "5m"],
|
||||||
|
"time_options": ["5m", "15m", "1h", "6h", "12h", "24h", "2d", "7d"]
|
||||||
|
},
|
||||||
"refresh": "10s",
|
"refresh": "10s",
|
||||||
"tags": ["agave", "solana", "mpabi"],
|
"tags": ["agave", "solana", "mpabi"],
|
||||||
"templating": {
|
"templating": {
|
||||||
@@ -171,7 +176,63 @@ data:
|
|||||||
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||||
"targets": [{ "refId": "Q", "expr": "sum by (reason) (increase(grpc_client_disconnects_total{job=\"mpabi-yellowstone-geyser\"}[15m]))", "legendFormat": "{{reason}}" }],
|
"targets": [{ "refId": "Q", "expr": "sum by (reason) (increase(grpc_client_disconnects_total{job=\"mpabi-yellowstone-geyser\"}[15m]))", "legendFormat": "{{reason}}" }],
|
||||||
"gridPos": { "h": 8, "w": 24, "x": 0, "y": 46 }
|
"gridPos": { "h": 8, "w": 24, "x": 0, "y": 46 }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 16,
|
||||||
|
"type": "stat",
|
||||||
|
"title": "RPC Slot Lag (slots)",
|
||||||
|
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||||
|
"targets": [{ "refId": "R", "expr": "solana_rpc_slot_lag{job=\"mpabi-node-exporter\",instance=\"$instance\"}" }],
|
||||||
|
"fieldConfig": {
|
||||||
|
"defaults": {
|
||||||
|
"unit": "short",
|
||||||
|
"thresholds": {
|
||||||
|
"mode": "absolute",
|
||||||
|
"steps": [
|
||||||
|
{ "color": "green", "value": null },
|
||||||
|
{ "color": "yellow", "value": 20 },
|
||||||
|
{ "color": "red", "value": 50 }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"overrides": []
|
||||||
|
},
|
||||||
|
"gridPos": { "h": 6, "w": 12, "x": 0, "y": 54 }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 17,
|
||||||
|
"type": "stat",
|
||||||
|
"title": "RPC Slot Lag (szac. minuty)",
|
||||||
|
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||||
|
"targets": [{ "refId": "S", "expr": "solana_rpc_slot_lag{job=\"mpabi-node-exporter\",instance=\"$instance\"} * 0.4 / 60" }],
|
||||||
|
"fieldConfig": {
|
||||||
|
"defaults": {
|
||||||
|
"unit": "min",
|
||||||
|
"decimals": 2,
|
||||||
|
"thresholds": {
|
||||||
|
"mode": "absolute",
|
||||||
|
"steps": [
|
||||||
|
{ "color": "green", "value": null },
|
||||||
|
{ "color": "yellow", "value": 1 },
|
||||||
|
{ "color": "red", "value": 2 }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"overrides": []
|
||||||
|
},
|
||||||
|
"gridPos": { "h": 6, "w": 12, "x": 12, "y": 54 }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 18,
|
||||||
|
"type": "timeseries",
|
||||||
|
"title": "RPC Slot & Reference Slot",
|
||||||
|
"datasource": { "type": "prometheus", "uid": "prometheus" },
|
||||||
|
"targets": [
|
||||||
|
{ "refId": "T", "expr": "solana_rpc_slot{job=\"mpabi-node-exporter\",instance=\"$instance\"}" },
|
||||||
|
{ "refId": "U", "expr": "solana_rpc_slot_reference{job=\"mpabi-node-exporter\",instance=\"$instance\"}" },
|
||||||
|
{ "refId": "V", "expr": "solana_rpc_block_height{job=\"mpabi-node-exporter\",instance=\"$instance\"}" }
|
||||||
|
],
|
||||||
|
"gridPos": { "h": 8, "w": 24, "x": 0, "y": 60 }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,3 +8,4 @@ resources:
|
|||||||
- ingressroute-prometheus.yaml
|
- ingressroute-prometheus.yaml
|
||||||
- ingressroute-prometheus-http.yaml
|
- ingressroute-prometheus-http.yaml
|
||||||
- dashboard-agave-status.yaml
|
- dashboard-agave-status.yaml
|
||||||
|
- prometheus-rules-agave.yaml
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
apiVersion: monitoring.coreos.com/v1
|
||||||
|
kind: PrometheusRule
|
||||||
|
metadata:
|
||||||
|
name: agave-rpc-alerts
|
||||||
|
namespace: monitoring
|
||||||
|
labels:
|
||||||
|
app: kube-prometheus-stack
|
||||||
|
release: monitoring-stack
|
||||||
|
spec:
|
||||||
|
groups:
|
||||||
|
- name: agave-rpc-health
|
||||||
|
rules:
|
||||||
|
- alert: AgaveRPCDown
|
||||||
|
expr: "max by (instance) (solana_rpc_up{job=\"mpabi-node-exporter\"}) == 0"
|
||||||
|
for: 30s
|
||||||
|
labels:
|
||||||
|
severity: critical
|
||||||
|
team: mpabi
|
||||||
|
annotations:
|
||||||
|
summary: "Agave RPC is unreachable"
|
||||||
|
description: "RPC probe from node exporter reports solana_rpc_up == 0 for instance {{ $labels.instance }}."
|
||||||
|
- alert: AgaveRPCSlotLagHigh
|
||||||
|
expr: "sum by (instance) (solana_rpc_slot_lag{job=\"mpabi-node-exporter\"}) > 50"
|
||||||
|
for: 2m
|
||||||
|
labels:
|
||||||
|
severity: warning
|
||||||
|
team: mpabi
|
||||||
|
annotations:
|
||||||
|
summary: "Agave RPC is lagging behind cluster"
|
||||||
|
description: "Current slot lag is {{ $value }} for instance {{ $labels.instance }}. Reference endpoint in probe config may be misconfigured or validator is behind."
|
||||||
|
- alert: AgaveRPCSlotLagCritical
|
||||||
|
expr: "sum by (instance) (solana_rpc_slot_lag{job=\"mpabi-node-exporter\"}) > 500"
|
||||||
|
for: 2m
|
||||||
|
labels:
|
||||||
|
severity: critical
|
||||||
|
team: mpabi
|
||||||
|
annotations:
|
||||||
|
summary: "Agave RPC severe lag"
|
||||||
|
description: "Slot lag is critically high ({{ $value }} slots) on instance {{ $labels.instance }}."
|
||||||
|
- alert: AgaveIOHigh
|
||||||
|
expr: |
|
||||||
|
sum by (instance) (
|
||||||
|
(rate(node_disk_read_bytes_total{job="mpabi-node-exporter",device=~"nvme.*"}[5m]) +
|
||||||
|
rate(node_disk_written_bytes_total{job="mpabi-node-exporter",device=~"nvme.*"}[5m])) / 1024 / 1024
|
||||||
|
) > 300
|
||||||
|
for: 5m
|
||||||
|
labels:
|
||||||
|
severity: warning
|
||||||
|
team: mpabi
|
||||||
|
annotations:
|
||||||
|
summary: "High storage I/O on Agave node"
|
||||||
|
description: "Combined NVMe read+write throughput >300 MiB/s for 5m on {{ $labels.instance }}. Check disk pressure and Geyser/ledger workload."
|
||||||
|
- alert: AgaveIOWaitHigh
|
||||||
|
expr: "avg by (instance) (rate(node_cpu_seconds_total{job=\"mpabi-node-exporter\",mode=\"iowait\"}[5m])) > 0.2"
|
||||||
|
for: 5m
|
||||||
|
labels:
|
||||||
|
severity: warning
|
||||||
|
team: mpabi
|
||||||
|
annotations:
|
||||||
|
summary: "High iowait on Agave node"
|
||||||
|
description: "Iowait over 20% on average for 5m on {{ $labels.instance }}. Storage latency is likely impacting slot progress."
|
||||||
49
kustomize/overlays/mevnode-bot/README.md
Normal file
49
kustomize/overlays/mevnode-bot/README.md
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
# mevnode-bot overlay
|
||||||
|
|
||||||
|
To jest docelowy overlay dla runtime `mevnode_bot`.
|
||||||
|
|
||||||
|
Zakres:
|
||||||
|
|
||||||
|
- `postgres`
|
||||||
|
- `hasura`
|
||||||
|
- `trade-api`
|
||||||
|
- `trade-frontend` (`NodePort 30081`)
|
||||||
|
- `trade-ingestor`
|
||||||
|
- `dlob-redis`
|
||||||
|
- `dlob-publisher`
|
||||||
|
- `dlob-server`
|
||||||
|
- `dlob-worker`
|
||||||
|
- `dlob-depth-worker`
|
||||||
|
- `dlob-slippage-worker`
|
||||||
|
|
||||||
|
Założenia runtime:
|
||||||
|
|
||||||
|
- `mevnode_sol` wystawia po `wg0`:
|
||||||
|
- `RPC`: `http://10.91.0.1:8899`
|
||||||
|
- `WS`: `ws://10.91.0.1:8900`
|
||||||
|
- `Yellowstone`: `http://10.91.0.1:10000`
|
||||||
|
- `mevnode_bot` uruchamia tylko warstwę aplikacyjną.
|
||||||
|
- `trade-frontend` jest wystawiany przez `NodePort 30081`.
|
||||||
|
- Namespace pozostaje `trade-staging`.
|
||||||
|
|
||||||
|
Wymagane sekrety:
|
||||||
|
|
||||||
|
- `trade-postgres`
|
||||||
|
- `trade-hasura`
|
||||||
|
- `trade-api`
|
||||||
|
- `trade-frontend-tokens`
|
||||||
|
- `trade-dlob-rpc`
|
||||||
|
|
||||||
|
Opcjonalne:
|
||||||
|
|
||||||
|
- `gitea-registry` nie jest tu wymagane, bo overlay czyści `imagePullSecrets`.
|
||||||
|
|
||||||
|
Uwagi:
|
||||||
|
|
||||||
|
- Overlay zastępuje lokalny `_tmp/bot-rx-stack`.
|
||||||
|
- `trade-deploy/kustomize/overlays/mevnode-bot` jest teraz źródłem prawdy dla runtime `mevnode_bot`.
|
||||||
|
- Ten overlay nadal korzysta z plików z `../../base` w `configMapGenerator`, więc przy lokalnym `kustomize` może być potrzebne:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo k3s kubectl kustomize trade-deploy/kustomize/overlays/mevnode-bot --load-restrictor LoadRestrictionsNone | sudo k3s kubectl apply -f -
|
||||||
|
```
|
||||||
219
kustomize/overlays/mevnode-bot/dlob-ingestor.mjs
Normal file
219
kustomize/overlays/mevnode-bot/dlob-ingestor.mjs
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
import process from 'node:process';
|
||||||
|
import { setTimeout as sleep } from 'node:timers/promises';
|
||||||
|
|
||||||
|
function getIsoNow() {
|
||||||
|
return new Date().toISOString();
|
||||||
|
}
|
||||||
|
|
||||||
|
function envString(name, fallback) {
|
||||||
|
const v = process.env[name];
|
||||||
|
if (v == null) return fallback;
|
||||||
|
const s = String(v).trim();
|
||||||
|
return s ? s : fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
function envInt(name, fallback, { min, max } = {}) {
|
||||||
|
const v = process.env[name];
|
||||||
|
if (v == null) return fallback;
|
||||||
|
const n = Number.parseInt(String(v), 10);
|
||||||
|
if (!Number.isFinite(n)) return fallback;
|
||||||
|
const low = typeof min === 'number' ? min : n;
|
||||||
|
const high = typeof max === 'number' ? max : n;
|
||||||
|
return Math.max(low, Math.min(high, n));
|
||||||
|
}
|
||||||
|
|
||||||
|
function envList(name, fallbackCsv) {
|
||||||
|
const raw = process.env[name] ?? fallbackCsv;
|
||||||
|
return String(raw)
|
||||||
|
.split(',')
|
||||||
|
.map((s) => s.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toIntOrNull(v) {
|
||||||
|
if (v == null) return null;
|
||||||
|
if (typeof v === 'number') return Number.isFinite(v) ? Math.trunc(v) : null;
|
||||||
|
if (typeof v === 'string') {
|
||||||
|
const s = v.trim();
|
||||||
|
if (!s) return null;
|
||||||
|
const n = Number.parseInt(s, 10);
|
||||||
|
return Number.isFinite(n) ? n : null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function numStr(v) {
|
||||||
|
if (v == null) return null;
|
||||||
|
if (typeof v === 'number') return Number.isFinite(v) ? String(v) : null;
|
||||||
|
if (typeof v === 'string') {
|
||||||
|
const s = v.trim();
|
||||||
|
return s ? s : null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isoFromEpochMs(v) {
|
||||||
|
const n = typeof v === 'number' ? v : typeof v === 'string' ? Number(v.trim()) : NaN;
|
||||||
|
if (!Number.isFinite(n) || n <= 0) return null;
|
||||||
|
const d = new Date(n);
|
||||||
|
const ms = d.getTime();
|
||||||
|
if (!Number.isFinite(ms)) return null;
|
||||||
|
return d.toISOString();
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveConfig() {
|
||||||
|
const hasuraUrl = envString('HASURA_GRAPHQL_URL', 'http://hasura:8080/v1/graphql');
|
||||||
|
const hasuraAdminSecret = envString('HASURA_ADMIN_SECRET', '');
|
||||||
|
if (!hasuraAdminSecret) throw new Error('Missing HASURA_ADMIN_SECRET');
|
||||||
|
|
||||||
|
const markets = envList('DLOB_MARKETS', 'SOL-PERP,PUMP-PERP');
|
||||||
|
const pollMs = envInt('TICKS_POLL_MS', 1000, { min: 250, max: 60000 });
|
||||||
|
const source = envString('TICKS_SOURCE', 'dlob_stats');
|
||||||
|
|
||||||
|
return { hasuraUrl, hasuraAdminSecret, markets, pollMs, source };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function graphqlRequest(cfg, query, variables) {
|
||||||
|
const res = await fetch(cfg.hasuraUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'content-type': 'application/json',
|
||||||
|
'x-hasura-admin-secret': cfg.hasuraAdminSecret,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ query, variables }),
|
||||||
|
signal: AbortSignal.timeout(10000),
|
||||||
|
});
|
||||||
|
|
||||||
|
const text = await res.text();
|
||||||
|
if (!res.ok) throw new Error(`Hasura HTTP ${res.status}: ${text}`);
|
||||||
|
|
||||||
|
let json;
|
||||||
|
try {
|
||||||
|
json = JSON.parse(text);
|
||||||
|
} catch {
|
||||||
|
throw new Error(`Hasura: invalid json: ${text}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json.errors?.length) throw new Error(json.errors.map((e) => e.message).join(' | '));
|
||||||
|
return json.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchStats(cfg) {
|
||||||
|
const query = `
|
||||||
|
query DlobStatsLatest($markets: [String!]!) {
|
||||||
|
dlob_stats_latest(where: { market_name: { _in: $markets } }) {
|
||||||
|
market_name
|
||||||
|
market_index
|
||||||
|
ts
|
||||||
|
slot
|
||||||
|
oracle_price
|
||||||
|
mark_price
|
||||||
|
mid_price
|
||||||
|
best_bid_price
|
||||||
|
best_ask_price
|
||||||
|
updated_at
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const data = await graphqlRequest(cfg, query, { markets: cfg.markets });
|
||||||
|
const rows = Array.isArray(data?.dlob_stats_latest) ? data.dlob_stats_latest : [];
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function insertTicks(cfg, objects) {
|
||||||
|
if (!objects.length) return 0;
|
||||||
|
|
||||||
|
const mutation = `
|
||||||
|
mutation InsertTicks($objects: [drift_ticks_insert_input!]!) {
|
||||||
|
insert_drift_ticks(objects: $objects) { affected_rows }
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const data = await graphqlRequest(cfg, mutation, { objects });
|
||||||
|
return Number(data?.insert_drift_ticks?.affected_rows || 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const cfg = resolveConfig();
|
||||||
|
const lastUpdatedAtByMarket = new Map();
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
JSON.stringify(
|
||||||
|
{
|
||||||
|
service: 'trade-ingestor',
|
||||||
|
mode: 'dlob_stats_ticks',
|
||||||
|
startedAt: getIsoNow(),
|
||||||
|
hasuraUrl: cfg.hasuraUrl,
|
||||||
|
markets: cfg.markets,
|
||||||
|
pollMs: cfg.pollMs,
|
||||||
|
source: cfg.source,
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
const rows = await fetchStats(cfg);
|
||||||
|
const nowIso = getIsoNow();
|
||||||
|
|
||||||
|
const objects = [];
|
||||||
|
for (const r of rows) {
|
||||||
|
const marketName = String(r?.market_name || '').trim();
|
||||||
|
if (!marketName) continue;
|
||||||
|
|
||||||
|
const updatedAt = r?.updated_at ? String(r.updated_at) : '';
|
||||||
|
if (updatedAt && lastUpdatedAtByMarket.get(marketName) === updatedAt) continue;
|
||||||
|
if (updatedAt) lastUpdatedAtByMarket.set(marketName, updatedAt);
|
||||||
|
|
||||||
|
const marketIndex = toIntOrNull(r?.market_index) ?? 0;
|
||||||
|
const dlobIso = isoFromEpochMs(r?.ts);
|
||||||
|
const tsIso = dlobIso || nowIso;
|
||||||
|
|
||||||
|
const oraclePrice = numStr(r?.oracle_price) || numStr(r?.mark_price) || numStr(r?.mid_price);
|
||||||
|
const markPrice = numStr(r?.mark_price) || numStr(r?.mid_price) || oraclePrice;
|
||||||
|
if (!oraclePrice) continue;
|
||||||
|
|
||||||
|
objects.push({
|
||||||
|
ts: tsIso,
|
||||||
|
market_index: marketIndex,
|
||||||
|
symbol: marketName,
|
||||||
|
oracle_price: oraclePrice,
|
||||||
|
mark_price: markPrice,
|
||||||
|
oracle_slot: r?.slot == null ? null : String(r.slot),
|
||||||
|
source: cfg.source,
|
||||||
|
raw: {
|
||||||
|
from: 'dlob_stats_latest',
|
||||||
|
market_name: marketName,
|
||||||
|
market_index: marketIndex,
|
||||||
|
dlob: {
|
||||||
|
ts: r?.ts ?? null,
|
||||||
|
slot: r?.slot ?? null,
|
||||||
|
best_bid_price: r?.best_bid_price ?? null,
|
||||||
|
best_ask_price: r?.best_ask_price ?? null,
|
||||||
|
mid_price: r?.mid_price ?? null,
|
||||||
|
updated_at: updatedAt || null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const inserted = await insertTicks(cfg, objects);
|
||||||
|
if (inserted) {
|
||||||
|
console.log(`[dlob-ticks] inserted=${inserted} ts=${nowIso}`);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`[dlob-ticks] error: ${String(err?.message || err)}`);
|
||||||
|
await sleep(2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
await sleep(cfg.pollMs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch((err) => {
|
||||||
|
console.error(String(err?.stack || err));
|
||||||
|
process.exitCode = 1;
|
||||||
|
});
|
||||||
67
kustomize/overlays/mevnode-bot/kustomization.yaml
Normal file
67
kustomize/overlays/mevnode-bot/kustomization.yaml
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
|
||||||
|
namespace: trade-staging
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- namespace.yaml
|
||||||
|
- ../../base/cm-trade-deploy.yaml
|
||||||
|
- ../../base/postgres/service.yaml
|
||||||
|
- ../../base/postgres/statefulset.yaml
|
||||||
|
- ../../base/postgres/job-migrate.yaml
|
||||||
|
- ../../base/hasura/service.yaml
|
||||||
|
- ../../base/hasura/deployment.yaml
|
||||||
|
- ../../base/hasura/job-bootstrap.yaml
|
||||||
|
- ../../base/api/service.yaml
|
||||||
|
- ../../base/api/deployment.yaml
|
||||||
|
- ../../base/ingestor/deployment.yaml
|
||||||
|
- ../../base/frontend/service.yaml
|
||||||
|
- ../../base/frontend/deployment.yaml
|
||||||
|
- ../../base/dlob/redis.yaml
|
||||||
|
- ../../base/dlob/publisher-deployment.yaml
|
||||||
|
- ../../base/dlob/server-service.yaml
|
||||||
|
- ../../base/dlob/server-deployment.yaml
|
||||||
|
- ../../base/dlob-worker/deployment.yaml
|
||||||
|
- ../../base/dlob-depth-worker/deployment.yaml
|
||||||
|
- ../../base/dlob-slippage-worker/deployment.yaml
|
||||||
|
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- patch-api.yaml
|
||||||
|
- patch-frontend.yaml
|
||||||
|
- patch-frontend-service.yaml
|
||||||
|
- patch-ingestor.yaml
|
||||||
|
- patch-dlob-publisher.yaml
|
||||||
|
- patch-dlob-publisher-storage.yaml
|
||||||
|
- patch-dlob-server.yaml
|
||||||
|
- patch-dlob-worker.yaml
|
||||||
|
- patch-dlob-depth-worker.yaml
|
||||||
|
- patch-dlob-slippage-worker.yaml
|
||||||
|
|
||||||
|
configMapGenerator:
|
||||||
|
- name: postgres-initdb
|
||||||
|
files:
|
||||||
|
- ../../base/initdb/001_init.sql
|
||||||
|
- name: hasura-bootstrap-script
|
||||||
|
files:
|
||||||
|
- ../../base/hasura/hasura-bootstrap.mjs
|
||||||
|
- name: trade-api-wrapper
|
||||||
|
files:
|
||||||
|
- ../../base/api/wrapper.mjs
|
||||||
|
- name: trade-api-upstream
|
||||||
|
files:
|
||||||
|
- ../../base/api/server.mjs
|
||||||
|
- name: dlob-worker-script
|
||||||
|
files:
|
||||||
|
- ../../base/dlob-worker/worker.mjs
|
||||||
|
- name: dlob-depth-worker-script
|
||||||
|
files:
|
||||||
|
- ../../base/dlob-depth-worker/worker.mjs
|
||||||
|
- name: dlob-slippage-worker-script
|
||||||
|
files:
|
||||||
|
- ../../base/dlob-slippage-worker/worker.mjs
|
||||||
|
- name: trade-dlob-ingestor-script
|
||||||
|
files:
|
||||||
|
- dlob-ingestor.mjs
|
||||||
|
|
||||||
|
generatorOptions:
|
||||||
|
disableNameSuffixHash: true
|
||||||
4
kustomize/overlays/mevnode-bot/namespace.yaml
Normal file
4
kustomize/overlays/mevnode-bot/namespace.yaml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: trade-staging
|
||||||
8
kustomize/overlays/mevnode-bot/patch-api.yaml
Normal file
8
kustomize/overlays/mevnode-bot/patch-api.yaml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: trade-api
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
imagePullSecrets: []
|
||||||
12
kustomize/overlays/mevnode-bot/patch-dlob-depth-worker.yaml
Normal file
12
kustomize/overlays/mevnode-bot/patch-dlob-depth-worker.yaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dlob-depth-worker
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: worker
|
||||||
|
env:
|
||||||
|
- name: DLOB_MARKETS
|
||||||
|
value: SOL-PERP,PUMP-PERP
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dlob-publisher
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: publisher
|
||||||
|
env:
|
||||||
|
- name: ENABLE_PERSISTENT_STORE
|
||||||
|
value: "true"
|
||||||
|
- name: DLOB_SOURCE
|
||||||
|
value: "mevnode_bot"
|
||||||
|
- name: PRICE_PRECISION
|
||||||
|
value: "1000000"
|
||||||
|
- name: BASE_PRECISION
|
||||||
|
value: "1000000000"
|
||||||
|
- name: PERSISTENT_STATS_DEPTH
|
||||||
|
value: "10"
|
||||||
|
- name: PGHOST
|
||||||
|
value: postgres
|
||||||
|
- name: PGPORT
|
||||||
|
value: "5432"
|
||||||
|
- name: PGUSER
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: trade-postgres
|
||||||
|
key: POSTGRES_USER
|
||||||
|
- name: PGPASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: trade-postgres
|
||||||
|
key: POSTGRES_PASSWORD
|
||||||
|
- name: PGDATABASE
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: trade-postgres
|
||||||
|
key: POSTGRES_DB
|
||||||
31
kustomize/overlays/mevnode-bot/patch-dlob-publisher.yaml
Normal file
31
kustomize/overlays/mevnode-bot/patch-dlob-publisher.yaml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dlob-publisher
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
imagePullSecrets: []
|
||||||
|
containers:
|
||||||
|
- name: publisher
|
||||||
|
env:
|
||||||
|
- name: PERP_MARKETS_TO_LOAD
|
||||||
|
value: "0,75"
|
||||||
|
- name: USE_GRPC
|
||||||
|
value: "true"
|
||||||
|
- name: USE_WEBSOCKET
|
||||||
|
value: "true"
|
||||||
|
- name: DISABLE_GPA_REFRESH
|
||||||
|
value: "true"
|
||||||
|
- name: GRPC_CLIENT
|
||||||
|
value: "yellowstone"
|
||||||
|
- name: GRPC_ENDPOINT
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: trade-dlob-rpc
|
||||||
|
key: GRPC_ENDPOINT
|
||||||
|
- name: TOKEN
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: trade-dlob-rpc
|
||||||
|
key: TOKEN
|
||||||
8
kustomize/overlays/mevnode-bot/patch-dlob-server.yaml
Normal file
8
kustomize/overlays/mevnode-bot/patch-dlob-server.yaml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dlob-server
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
imagePullSecrets: []
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dlob-slippage-worker
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: worker
|
||||||
|
env:
|
||||||
|
- name: DLOB_MARKETS
|
||||||
|
value: SOL-PERP,PUMP-PERP
|
||||||
12
kustomize/overlays/mevnode-bot/patch-dlob-worker.yaml
Normal file
12
kustomize/overlays/mevnode-bot/patch-dlob-worker.yaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dlob-worker
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: worker
|
||||||
|
env:
|
||||||
|
- name: DLOB_MARKETS
|
||||||
|
value: SOL-PERP,PUMP-PERP
|
||||||
11
kustomize/overlays/mevnode-bot/patch-frontend-service.yaml
Normal file
11
kustomize/overlays/mevnode-bot/patch-frontend-service.yaml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: trade-frontend
|
||||||
|
spec:
|
||||||
|
type: NodePort
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
port: 8081
|
||||||
|
targetPort: http
|
||||||
|
nodePort: 30081
|
||||||
8
kustomize/overlays/mevnode-bot/patch-frontend.yaml
Normal file
8
kustomize/overlays/mevnode-bot/patch-frontend.yaml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: trade-frontend
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
imagePullSecrets: []
|
||||||
39
kustomize/overlays/mevnode-bot/patch-ingestor.yaml
Normal file
39
kustomize/overlays/mevnode-bot/patch-ingestor.yaml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: trade-ingestor
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
imagePullSecrets: []
|
||||||
|
containers:
|
||||||
|
- name: ingestor
|
||||||
|
image: node:20-slim
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
env:
|
||||||
|
- name: HASURA_GRAPHQL_URL
|
||||||
|
value: http://hasura:8080/v1/graphql
|
||||||
|
- name: HASURA_ADMIN_SECRET
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: trade-hasura
|
||||||
|
key: HASURA_GRAPHQL_ADMIN_SECRET
|
||||||
|
- name: DLOB_MARKETS
|
||||||
|
value: SOL-PERP,PUMP-PERP
|
||||||
|
- name: TICKS_POLL_MS
|
||||||
|
value: "1000"
|
||||||
|
- name: TICKS_SOURCE
|
||||||
|
value: "dlob_stats"
|
||||||
|
command:
|
||||||
|
- node
|
||||||
|
args:
|
||||||
|
- /opt/dlob/dlob-ingestor.mjs
|
||||||
|
volumeMounts:
|
||||||
|
- name: dlob-script
|
||||||
|
mountPath: /opt/dlob/dlob-ingestor.mjs
|
||||||
|
subPath: dlob-ingestor.mjs
|
||||||
|
readOnly: true
|
||||||
|
volumes:
|
||||||
|
- name: dlob-script
|
||||||
|
configMap:
|
||||||
|
name: trade-dlob-ingestor-script
|
||||||
@@ -66,7 +66,7 @@ function resolveConfig() {
|
|||||||
const hasuraAdminSecret = envString('HASURA_ADMIN_SECRET', '');
|
const hasuraAdminSecret = envString('HASURA_ADMIN_SECRET', '');
|
||||||
if (!hasuraAdminSecret) throw new Error('Missing HASURA_ADMIN_SECRET');
|
if (!hasuraAdminSecret) throw new Error('Missing HASURA_ADMIN_SECRET');
|
||||||
|
|
||||||
const markets = envList('DLOB_MARKETS', 'PUMP-PERP,SOL-PERP,1MBONK-PERP,BTC-PERP,ETH-PERP');
|
const markets = envList('DLOB_MARKETS', 'SOL-PERP,DOGE-PERP,JUP-PERP');
|
||||||
const pollMs = envInt('TICKS_POLL_MS', 1000, { min: 250, max: 60_000 });
|
const pollMs = envInt('TICKS_POLL_MS', 1000, { min: 250, max: 60_000 });
|
||||||
const source = envString('TICKS_SOURCE', 'dlob_stats');
|
const source = envString('TICKS_SOURCE', 'dlob_stats');
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ spec:
|
|||||||
name: trade-hasura
|
name: trade-hasura
|
||||||
key: HASURA_GRAPHQL_ADMIN_SECRET
|
key: HASURA_GRAPHQL_ADMIN_SECRET
|
||||||
- name: DLOB_MARKETS
|
- name: DLOB_MARKETS
|
||||||
value: PUMP-PERP,SOL-PERP,1MBONK-PERP,BTC-PERP,ETH-PERP
|
value: SOL-PERP,DOGE-PERP,JUP-PERP
|
||||||
- name: TICKS_POLL_MS
|
- name: TICKS_POLL_MS
|
||||||
value: "1000"
|
value: "1000"
|
||||||
- name: TICKS_SOURCE
|
- name: TICKS_SOURCE
|
||||||
|
|||||||
Reference in New Issue
Block a user