feat(dlob): support two sources + per-user switch
- Add "source" column + composite PKs for DLOB tables\n- Filter public Hasura selects by X-Hasura-Dlob-Source\n- Run parallel workers for mevnode + dlob.drift.trade\n- Frontend proxy sets x-hasura-dlob-source from cookie and injects UI switch
This commit is contained in:
50
kustomize/base/dlob-depth-worker/deployment-drift.yaml
Normal file
50
kustomize/base/dlob-depth-worker/deployment-drift.yaml
Normal file
@@ -0,0 +1,50 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: dlob-depth-worker-drift
|
||||
annotations:
|
||||
argocd.argoproj.io/sync-wave: "6"
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/name: dlob-depth-worker-drift
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/name: dlob-depth-worker-drift
|
||||
spec:
|
||||
containers:
|
||||
- name: worker
|
||||
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_SOURCE
|
||||
value: drift
|
||||
- name: DLOB_MARKETS
|
||||
value: PUMP-PERP,SOL-PERP,1MBONK-PERP,BTC-PERP,ETH-PERP
|
||||
- name: DLOB_POLL_MS
|
||||
value: "1000"
|
||||
- name: DLOB_DEPTH_BPS_BANDS
|
||||
value: "5,10,20,50,100,200"
|
||||
- name: PRICE_PRECISION
|
||||
value: "1000000"
|
||||
- name: BASE_PRECISION
|
||||
value: "1000000000"
|
||||
command: ["node", "/app/worker.mjs"]
|
||||
volumeMounts:
|
||||
- name: script
|
||||
mountPath: /app/worker.mjs
|
||||
subPath: worker.mjs
|
||||
readOnly: true
|
||||
volumes:
|
||||
- name: script
|
||||
configMap:
|
||||
name: dlob-depth-worker-script
|
||||
@@ -26,6 +26,8 @@ spec:
|
||||
secretKeyRef:
|
||||
name: trade-hasura
|
||||
key: HASURA_GRAPHQL_ADMIN_SECRET
|
||||
- name: DLOB_SOURCE
|
||||
value: mevnode
|
||||
- name: DLOB_MARKETS
|
||||
value: PUMP-PERP,SOL-PERP,1MBONK-PERP,BTC-PERP,ETH-PERP
|
||||
- name: DLOB_POLL_MS
|
||||
|
||||
@@ -64,6 +64,7 @@ function resolveConfig() {
|
||||
const hasuraAdminSecret = process.env.HASURA_ADMIN_SECRET || process.env.HASURA_GRAPHQL_ADMIN_SECRET || undefined;
|
||||
const hasuraAuthToken = process.env.HASURA_AUTH_TOKEN || process.env.HASURA_JWT || undefined;
|
||||
|
||||
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 pollMs = clampInt(process.env.DLOB_POLL_MS, 250, 60_000, 1000);
|
||||
const bandsBps = envIntList('DLOB_DEPTH_BPS_BANDS', '5,10,20,50,100,200');
|
||||
@@ -79,6 +80,7 @@ function resolveConfig() {
|
||||
hasuraUrl,
|
||||
hasuraAdminSecret,
|
||||
hasuraAuthToken,
|
||||
dlobSource,
|
||||
markets,
|
||||
pollMs,
|
||||
bandsBps,
|
||||
@@ -169,8 +171,9 @@ function computeBandDepth({ bids, asks, mid, bandBps }) {
|
||||
|
||||
async function fetchL2Latest(cfg) {
|
||||
const query = `
|
||||
query DlobL2Latest($markets: [String!]!) {
|
||||
dlob_l2_latest(where: {market_name: {_in: $markets}}) {
|
||||
query DlobL2Latest($source: String!, $markets: [String!]!) {
|
||||
dlob_l2_latest(where: {source: {_eq: $source}, market_name: {_in: $markets}}) {
|
||||
source
|
||||
market_name
|
||||
market_type
|
||||
market_index
|
||||
@@ -186,7 +189,7 @@ async function fetchL2Latest(cfg) {
|
||||
}
|
||||
}
|
||||
`;
|
||||
const data = await graphqlRequest(cfg, query, { markets: cfg.markets });
|
||||
const data = await graphqlRequest(cfg, query, { source: cfg.dlobSource, markets: cfg.markets });
|
||||
return Array.isArray(data?.dlob_l2_latest) ? data.dlob_l2_latest : [];
|
||||
}
|
||||
|
||||
@@ -232,6 +235,7 @@ async function main() {
|
||||
startedAt: getIsoNow(),
|
||||
hasuraUrl: cfg.hasuraUrl,
|
||||
hasuraAuth: cfg.hasuraAuthToken ? 'bearer' : cfg.hasuraAdminSecret ? 'admin-secret' : 'none',
|
||||
dlobSource: cfg.dlobSource,
|
||||
markets: cfg.markets,
|
||||
pollMs: cfg.pollMs,
|
||||
bandsBps: cfg.bandsBps,
|
||||
@@ -268,6 +272,7 @@ async function main() {
|
||||
for (const bandBps of cfg.bandsBps) {
|
||||
const d = computeBandDepth({ bids, asks, mid, bandBps });
|
||||
rows.push({
|
||||
source: cfg.dlobSource,
|
||||
market_name: market,
|
||||
band_bps: bandBps,
|
||||
market_type: l2.market_type ? String(l2.market_type) : 'perp',
|
||||
|
||||
Reference in New Issue
Block a user