import Logs from "../libs/logs.js"; import { receivePartnerData } from "./Partner.js"; import eventSolutions from '../triangle/eventSolutions.js'; import { placePlatformOrder } from "./Markets.js"; /** * 精确浮点数字 * @param {number} number * @param {number} x * @returns {number} */ const fixFloat = (number, x=3) => { return parseFloat(number.toFixed(x)); } /** * 根据赔率获取策略 * @param {*} params * @returns */ const getSolutionWithIors = async(params) => { const { iors, cross_type, base_stake } = params; if (typeof params !== 'object' || params === null || Array.isArray(params)) { return Promise.reject(new Error('params must be an object')); } if (!Array.isArray(iors) || iors.length < 2) { return Promise.reject(new Error('iors must be an array and length must be greater than 2')); } iors.forEach(item => { if (typeof item.v !== 'number' || !Number.isFinite(item.v)) { return Promise.reject(new Error('iors must be an array of numbers')); } if (item.v <= 1) { return Promise.reject(new Error('iors must be an array of numbers greater than 1')); } }); if (typeof cross_type !== 'string' || cross_type.length === 0) { return Promise.reject(new Error('cross_type must be a non-empty string')); } if (typeof base_stake !== 'number' || !Number.isFinite(base_stake) || base_stake <= 0) { return Promise.reject(new Error('base_stake must be a positive number')); } const base_index = iors.reduce((minIdx, cur, idx) => cur.v < iors[minIdx].v ? idx : minIdx, 0); if (iors.length === 2) { iors.push({ v: 1 }); } const betInfo = { cross_type, base_index, base_stake, odds_side_a: fixFloat(iors[0].v - 1), odds_side_b: fixFloat(iors[1].v - 1), odds_side_c: fixFloat(iors[2].v - 1), }; const sol = eventSolutions(betInfo, true); return sol; } /** * 下注Pinnacle * @param {*} data * @returns */ const betPinnacle = async (params) => { const { id, ior, stake=0 } = params; const iorInfo = await placePlatformOrder(ior, 'pinnacle', id, stake); if (!iorInfo) { return Promise.reject(new Error('ior info not found')); } return iorInfo; } export const gate = async (data) => { return receivePartnerData(data). then(({ action, params }) => { switch (action) { case 'iors.solution': return getSolutionWithIors(params); case 'bet.pinnacle': return betPinnacle(params); default: return Promise.reject(new Error('invalid action')); } }); } export default { gate };