"use strict";async function updateOrderData(e,r){var a;const t={status:r.status.toUpperCase(),filled:r.filled,remaining:r.remaining,cost:r.cost,fee:null===(a=r.fee)||void 0===a?void 0:a.cost,trades:r.trades,average:r.average},s=Object.fromEntries(Object.entries(t).filter(([e,r])=>void 0!==r));await db_1.models.exchangeOrder.update(s,{where:{id:e}});const o=await db_1.models.exchangeOrder.findOne({where:{id:e}});if(!o)throw(0,error_1.createError)({statusCode:404,message:"Order not found"});return o.get({plain:!0})}function adjustOrderData(e,r,a){var t;const s=e.side?e.side.toUpperCase():null;let o=parseFloat(e.amount),i=parseFloat(e.cost),c=parseFloat((null===(t=e.fee)||void 0===t?void 0:t.cost)||"0");if("xt"===r){const r=e.info,t=parseFloat(r.avgPrice),d=parseFloat(r.executedQty);"BUY"===s?o=d/t:"SELL"===s&&(o=d);i=o*t;c=parseFloat((o*(a/100)).toFixed(8))}else o&&a&&(c=parseFloat((o*(a/100)).toFixed(8)));return{...e,amount:o,cost:i,fee:c}}Object.defineProperty(exports,"__esModule",{value:!0});exports.baseOrderSchema=void 0;exports.updateOrderData=updateOrderData;exports.adjustOrderData=adjustOrderData;const db_1=require("@b/db"),error_1=require("@b/utils/error"),schema_1=require("@b/utils/schema");exports.baseOrderSchema={id:(0,schema_1.baseStringSchema)("Unique identifier for the order"),referenceId:(0,schema_1.baseStringSchema)("External reference ID for the order"),userId:(0,schema_1.baseStringSchema)("User ID associated with the order"),status:(0,schema_1.baseStringSchema)("Status of the order (e.g., pending, completed)"),symbol:(0,schema_1.baseStringSchema)("Trading symbol for the order"),type:(0,schema_1.baseStringSchema)("Type of order (e.g., market, limit)"),timeInForce:(0,schema_1.baseStringSchema)("Time in force policy for the order"),side:(0,schema_1.baseStringSchema)("Order side (buy or sell)"),price:(0,schema_1.baseNumberSchema)("Price per unit"),average:(0,schema_1.baseNumberSchema)("Average price per unit"),amount:(0,schema_1.baseNumberSchema)("Total amount ordered"),filled:(0,schema_1.baseNumberSchema)("Amount filled"),remaining:(0,schema_1.baseNumberSchema)("Amount remaining"),cost:(0,schema_1.baseNumberSchema)("Total cost"),trades:{type:"object",description:"Details of trades executed for this order",additionalProperties:!0},fee:(0,schema_1.baseNumberSchema)("Transaction fee"),feeCurrency:(0,schema_1.baseStringSchema)("Currency of the transaction fee"),createdAt:(0,schema_1.baseStringSchema)("Creation date of the order"),updatedAt:(0,schema_1.baseStringSchema)("Last update date of the order")};