"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const utils_1=require("@b/api/exchange/utils"),exchange_1=__importDefault(require("@b/utils/exchange")),console_1=require("@b/utils/console"),query_1=require("@b/utils/query"),utils_2=require("@b/api/exchange/utils");exports.metadata={summary:"Get Market Ticker",operationId:"getMarketTicker",tags:["Exchange","Markets"],description:"Retrieves ticker information for a specific market pair.",logModule:"EXCHANGE",logTitle:"Get Ticker for Pair",parameters:[{name:"currency",in:"path",required:!0,description:"The base currency of the market pair.",schema:{type:"string"}},{name:"pair",in:"path",required:!0,description:"The quote currency of the market pair.",schema:{type:"string"}}],responses:{200:{description:"Ticker information",content:{"application/json":{schema:{type:"object",properties:utils_1.baseTickerSchema}}}},401:query_1.unauthorizedResponse,404:(0,query_1.notFoundMetadataResponse)("Ticker"),500:query_1.serverErrorResponse}};exports.default=async e=>{const{params:r,ctx:t}=e,{currency:a,pair:s}=r,o=`${a}/${s}`;try{null==t||t.step(`Fetching ticker for ${o}`);const e=await(0,utils_2.loadBanStatus)();if(await(0,utils_2.handleBanStatus)(e))return query_1.serverErrorResponse;const r=await exchange_1.default.startExchange(t);if(!r){console_1.logger.error("EXCHANGE","Failed to start exchange");return query_1.serverErrorResponse}const a=await r.fetchTicker(o);if(!a)return(0,query_1.notFoundMetadataResponse)("Ticker");null==t||t.success(`Ticker retrieved for ${o}`);return{symbol:a.symbol,bid:a.bid,ask:a.ask,close:a.close,last:a.last,change:a.percentage,baseVolume:a.baseVolume,quoteVolume:a.quoteVolume}}catch(e){if("number"==typeof await(0,utils_2.handleExchangeError)(e,exchange_1.default))return query_1.serverErrorResponse;console_1.logger.error("EXCHANGE","Failed to fetch ticker",e);return query_1.serverErrorResponse}};