mirror of
https://github.com/theodore-song/polymarket-analyst.git
synced 2026-08-24 13:08:10 +00:00
Diversify verified bundle search by event
This commit is contained in:
+19
-2
@@ -1320,6 +1320,15 @@ function compareBundleOpportunities(a,b){
|
||||
||Number(b.net_edge||-Infinity)-Number(a.net_edge||-Infinity)
|
||||
||Number(b.bundle_net_profit_per_unit||-Infinity)-Number(a.bundle_net_profit_per_unit||-Infinity);
|
||||
}
|
||||
function prioritizeIndependentBundles(candidates,limit=Infinity){
|
||||
const ranked=(candidates||[]).slice().sort(compareBundleOpportunities),firstByEvent=[],alternates=[],seenEvents=new Set();
|
||||
ranked.forEach(candidate=>{
|
||||
const eventKey=bundleEventKey(candidate)||String(candidate.bundle_id||candidate.market_id||"");
|
||||
if(eventKey&&!seenEvents.has(eventKey)){seenEvents.add(eventKey);firstByEvent.push(candidate);}
|
||||
else alternates.push(candidate);
|
||||
});
|
||||
return [...firstByEvent,...alternates].slice(0,Math.max(0,Number(limit)||0));
|
||||
}
|
||||
function bundleEventExposure(portfolio,eventKey){
|
||||
const key=String(eventKey||"");if(!key)return 0;
|
||||
return (portfolio&&portfolio.positions||[]).filter(pos=>pos.requires_complete_bundle&&bundleEventKey(pos)===key)
|
||||
@@ -1367,7 +1376,7 @@ async function fetchBundleFeeRates(tokenIds){
|
||||
await Promise.all(workers);return results;
|
||||
}
|
||||
async function verifyExecutableBundles(candidates){
|
||||
const shortlist=(candidates||[]).slice().sort(compareBundleOpportunities).slice(0,BUNDLE_DEPTH_CANDIDATE_LIMIT);
|
||||
const shortlist=prioritizeIndependentBundles(candidates,BUNDLE_DEPTH_CANDIDATE_LIMIT);
|
||||
const tokenIds=shortlist.flatMap(candidate=>(candidate.bundle_legs||[]).map(leg=>leg.token_id));
|
||||
const books=await fetchBundleBooks(tokenIds),depthChecked=shortlist.map(candidate=>{
|
||||
const estimatedCost=Number(candidate.bundle_cost_per_unit),requiredUnits=bundleMinimumExecutionUnits(Math.max(estimatedCost,0.01));
|
||||
@@ -1421,10 +1430,12 @@ async function fetchNegativeRiskBundles(limit=NEG_RISK_EVENT_SCAN_LIMIT){
|
||||
const candidates=executableAudit.filter(candidate=>candidate.opportunity_actionable);
|
||||
const seen=new Set();
|
||||
const unique=candidates.filter(candidate=>{const id=String(candidate.bundle_id||candidate.market_id);if(!id||seen.has(id))return false;seen.add(id);return true;});
|
||||
const prioritized=prioritizeIndependentBundles(unique,20);
|
||||
const closest=executableAudit.find(candidate=>candidate.depth_verified)||executableAudit[0]||null;
|
||||
return {candidates:unique.slice(0,20),audit:{status:"ok",scanned_at:nowIso(),event_scan_limit:limit,events_scanned:events.length,
|
||||
return {candidates:prioritized,audit:{status:"ok",scanned_at:nowIso(),event_scan_limit:limit,events_scanned:events.length,
|
||||
evaluated_structures:audited.length,depth_checked_structures:executableAudit.length,depth_verified_structures:executableAudit.filter(candidate=>candidate.depth_verified).length,
|
||||
fee_verified_structures:executableAudit.filter(candidate=>candidate.fees_verified).length,actionable_bundles:unique.length,
|
||||
actionable_events:new Set(unique.map(bundleEventKey).filter(Boolean)).size,returned_events:new Set(prioritized.map(bundleEventKey).filter(Boolean)).size,
|
||||
closest_margin_cents:closest?+(Number(closest.bundle_net_profit_per_unit)*100).toFixed(2):null,
|
||||
closest_return_pct:closest?+(Number(closest.net_edge)*100).toFixed(3):null,
|
||||
closest_title:closest?closest.question:null,closest_url:closest?closest.url:null}};
|
||||
@@ -7215,6 +7226,11 @@ function runEngineSelfTest(){
|
||||
Object.assign({},dominanceSuggestion,{bundle_id:"dominance:slow-event:a:b",bundle_event_id:"slow-event",net_edge:0.03,days_to_resolution:30}),
|
||||
Object.assign({},dominanceSuggestion,{bundle_id:"dominance:fast-event:a:b",bundle_event_id:"fast-event",net_edge:0.02,days_to_resolution:5}),
|
||||
].sort(compareBundleOpportunities);
|
||||
const independentBundleOrder=prioritizeIndependentBundles([
|
||||
Object.assign({},dominanceSuggestion,{bundle_id:"dominance:event-a:a:b",bundle_event_id:"event-a",net_edge:0.05,days_to_resolution:5}),
|
||||
Object.assign({},dominanceSuggestion,{bundle_id:"dominance:event-a:c:d",bundle_event_id:"event-a",net_edge:0.04,days_to_resolution:5}),
|
||||
Object.assign({},dominanceSuggestion,{bundle_id:"dominance:event-b:a:b",bundle_event_id:"event-b",net_edge:0.02,days_to_resolution:5}),
|
||||
],3);
|
||||
const eventCapBook=defaultPortfolio();
|
||||
eventCapBook.cash=8800;
|
||||
eventCapBook.positions=[
|
||||
@@ -7734,6 +7750,7 @@ function runEngineSelfTest(){
|
||||
},
|
||||
bundleArbitrage:{
|
||||
prioritizesReturnPerLockedDay:capitalEfficiencyOrder[0].bundle_event_id==="fast-event",
|
||||
prioritizesIndependentEventsBeforeAlternates:independentBundleOrder.map(row=>row.bundle_event_id).join(",")==="event-a,event-b,event-a",
|
||||
derivesLegacyBundleEventKey:bundleEventKey({bundle_id:"dominance:legacy-event:market-a:market-b"})==="legacy-event",
|
||||
capsUnderlyingEventExposure:eventCapBook.positions.length===2&&eventCapBook.lastDecision.rejectionCounts.bundle_event_cap===1,
|
||||
blocksLowReturnPerLockedDay:slowCapitalBook.positions.length===0&&slowCapitalBook.lastDecision.rejectionCounts.bundle_capital_efficiency===1,
|
||||
|
||||
Reference in New Issue
Block a user