"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"),error_1=require("@b/utils/error");exports.metadata={summary:"Get Market Order Book",operationId:"getMarketOrderBook",tags:["Exchange","Markets"],description:"Retrieves the order book for a specific market pair.",logModule:"EXCHANGE",logTitle:"Get Orderbook for Pair",parameters:[{name:"currency",in:"path",description:"Currency symbol",required:!0,schema:{type:"string"}},{name:"pair",in:"path",description:"Pair symbol",required:!0,schema:{type:"string"}},{name:"limit",in:"query",description:"Limit the number of order book entries",schema:{type:"number"}}],responses:{200:{description:"Order book information",content:{"application/json":{schema:{type:"object",properties:utils_1.baseOrderBookSchema}}}},401:query_1.unauthorizedResponse,404:(0,query_1.notFoundMetadataResponse)("Orderbook"),500:query_1.serverErrorResponse}};exports.default=async e=>{const{params:r,query:t,ctx:o}=e,{currency:a,pair:i}=r,s=t.limit?parseInt(t.limit,10):50,n=`${a}/${i}`;try{null==o||o.step(`Fetching orderbook for ${n}`);const e=await(0,utils_2.loadBanStatus)();if(await(0,utils_2.handleBanStatus)(e))throw(0,error_1.createError)(503,"Service temporarily unavailable. Please try again later.");const r=await exchange_1.default.startExchange(o);if(!r)throw(0,error_1.createError)(503,"Service temporarily unavailable. Please try again later.");const t=await r.fetchOrderBook(n,s);null==o||o.success(`Orderbook retrieved for ${n}`);return{asks:t.asks,bids:t.bids}}catch(e){console_1.logger.error("EXCHANGE","Failed to fetch order book",e);if(503===e.statusCode)throw e;throw(0,error_1.createError)(500,"Unable to fetch order book at this time")}};