Skip to content

Commit

Permalink
add restrictemode
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmkeng committed Dec 13, 2024
1 parent b5f6e99 commit f4e7847
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions helpers/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const ENV_KEYS = new Set([
'OKX_API_KEY',
'ALCHEMIX_KEY',
'ALCHEMIX_SECRET',
'FLIPSIDE_RESTRICTED_MODE',
])

// This is done to support both ZEROx_API_KEY and ZEROX_API_KEY
Expand Down
9 changes: 9 additions & 0 deletions helpers/flipsidecrypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { httpPost } from "../utils/fetchURL";
import { getEnv } from "./env";

const token = {} as IJSON<string>
const isRestrictedMode = getEnv('FLIPSIDE_RESTRICTED_MODE') === 'true'
const FLIPSIDE_API_KEYS = getEnv('FLIPSIDE_API_KEY')?.split(',') ?? ["f3b65679-a179-4983-b794-e41cf40103ed"]
let API_KEY_INDEX = 0;
const MAX_RETRIES = 20;
Expand All @@ -19,6 +20,7 @@ async function randomDelay() {
}

export async function queryFlipside(sqlQuery: string, maxAgeMinutes: number = 90) {
checkCanFlipSideQuery();
if (!query[sqlQuery]) {
query[sqlQuery] = _queryFlipside(sqlQuery, maxAgeMinutes)
}
Expand Down Expand Up @@ -178,3 +180,10 @@ async function _queryFlipside(sqlQuery: string, maxAgeMinutes: number = 90) {
}
);
}

export function checkCanFlipSideQuery() {
if (!isRestrictedMode) return;
const currentHour = new Date().getUTCHours();
if (currentHour >= 1 && currentHour <= 3) return; // 1am - 3am - any time other than this, throw error
throw new Error(`Current hour is ${currentHour}. In restricted mode, can run flipsside queries only between 1am - 3am UTC`);
}

0 comments on commit f4e7847

Please sign in to comment.