"use strict";async function saveBanStatus(e){await redis.set(exports.BAN_STATUS_KEY,e)}async function loadBanStatus(){const e=await redis.get(exports.BAN_STATUS_KEY);return e?parseInt(e):0}function formatWaitTime(e){return`${Math.floor(e/6e4)} minutes and ${(e%6e4/1e3).toFixed(0)} seconds`}async function handleBanStatus(e){if(Date.now()<e){const a=e-Date.now();console_1.logger.info("EXCHANGE",`Exchange is banned for ${formatWaitTime(a)} more`);return!0}return!1}function extractBanTime(e){if(e.includes("IP banned until")){const a=e.match(/until (\d+)/);if(a)return parseInt(a[1])}return null}async function handleExchangeError(e,a){const t=extractBanTime(e.message);if(t){await saveBanStatus(t);return t}await a.stopExchange();await new Promise(e=>setTimeout(e,5e3));return await a.startExchange()}function sanitizeErrorMessage(e){if(null==e)return"An unknown error occurred";e instanceof Error&&(e=e.message);if("string"==typeof e){let a=e;["kucoin","binance","okx"].forEach(e=>{const t=new RegExp(e,"gi");a=a.replace(t,"***")});return a}return e}Object.defineProperty(exports,"__esModule",{value:!0});exports.baseWatchlistItemSchema=exports.baseTickerSchema=exports.baseOrderBookSchema=exports.baseOrderBookEntrySchema=exports.BAN_STATUS_KEY=void 0;exports.saveBanStatus=saveBanStatus;exports.loadBanStatus=loadBanStatus;exports.formatWaitTime=formatWaitTime;exports.handleBanStatus=handleBanStatus;exports.extractBanTime=extractBanTime;exports.handleExchangeError=handleExchangeError;exports.sanitizeErrorMessage=sanitizeErrorMessage;const schema_1=require("@b/utils/schema"),redis_1=require("@b/utils/redis"),console_1=require("@b/utils/console"),redis=redis_1.RedisSingleton.getInstance();exports.BAN_STATUS_KEY="exchange:ban_status";exports.baseOrderBookEntrySchema={type:"array",items:{type:"number",description:"Order book entry consisting of price and volume"}};exports.baseOrderBookSchema={asks:{type:"array",items:exports.baseOrderBookEntrySchema,description:"Asks are sell orders in the order book"},bids:{type:"array",items:exports.baseOrderBookEntrySchema,description:"Bids are buy orders in the order book"}};exports.baseTickerSchema={symbol:(0,schema_1.baseStringSchema)("Trading symbol for the market pair"),bid:(0,schema_1.baseNumberSchema)("Current highest bid price"),ask:(0,schema_1.baseNumberSchema)("Current lowest ask price"),close:(0,schema_1.baseNumberSchema)("Last close price"),last:(0,schema_1.baseNumberSchema)("Most recent transaction price"),change:(0,schema_1.baseNumberSchema)("Price change percentage"),baseVolume:(0,schema_1.baseNumberSchema)("Volume of base currency traded"),quoteVolume:(0,schema_1.baseNumberSchema)("Volume of quote currency traded")};exports.baseWatchlistItemSchema={id:(0,schema_1.baseStringSchema)("Unique identifier for the watchlist item",void 0,void 0,!1,void 0,"uuid"),userId:(0,schema_1.baseStringSchema)("User ID associated with the watchlist item",void 0,void 0,!1,void 0,"uuid"),symbol:(0,schema_1.baseStringSchema)("Symbol of the watchlist item")};