Public
Edited
May 23
Paused
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function getMarketData(adj_ticker) {
let market_data = fetch(
`https://api.data.adj.news/api/markets/${adj_ticker}?api_key=38314d45-7899-4f51-a860-f6b898707a70`
).then((response) => response.json());
return market_data;
}
Insert cell
Insert cell
Insert cell
Insert cell
function getNews(adj_ticker) {
let news = fetch(
`https://api.data.adj.news/api/news/${adj_ticker}?api_key=38314d45-7899-4f51-a860-f6b898707a70`
).then((response) => response.json());
return news;
}
Insert cell
Insert cell
articles = news.data.flat(2)
Insert cell
viewof articleTable = Inputs.table(articles)
Insert cell
Insert cell
// historical market data will soon be a part of the Adjacent Trade API but for now we can fetch direct from the sources
function polymarketPrices(id) {
try {
// Current time in milliseconds
const endTs = Date.now();

// Fetch price history data for the last 30 days
const startTs = endTs - 30 * 24 * 60 * 60 * 1000;

const response = fetch(
`https://clob.polymarket.com/prices-history?market=${id}&endTs=${endTs}&startTs=${startTs}`
).then((response) => response.json());
return response || [];
} catch (error) {
console.error(`Error fetching price history for market ${id}:`, error);
return [];
}
}
Insert cell
data = {
const marketPromises = [];

let filteredMarkets = markets.data.filter(market => market.platform === 'polymarket');
for (let marketIndex in filteredMarkets) {
const market = filteredMarkets[marketIndex];
let pricePromise;
// find what platform the market is to pull the pricing
switch (market.platform) {
case 'polymarket':
pricePromise = polymarketPrices(market.platform_ids.asset_id_yes)
.then(prices => {
market.history = prices.history || [];
return market;
});
break;
default:
pricePromise = Promise.resolve(market);
}
marketPromises.push(pricePromise);
}
// Wait for all market price fetching to complete
const updatedMarkets = await Promise.all(marketPromises);
// If you need to update the original markets object
updatedMarkets.forEach((updatedMarket, index) => {
filteredMarkets[index] = updatedMarket;
});

return filteredMarkets
}
Insert cell
Insert cell
Insert cell
visualizePredictionMarkets(data);
Insert cell
// break out mention markets, rate markets, and other
mentionMarkets = data.filter(market => market.question.includes("say"))
Insert cell
visualizePredictionMarkets(mentionMarkets, "Mention Market Probabilities Over Time")
Insert cell
// break out mention markets, rate markets, and other
rateMarkets = data.filter(market => market.question.includes("rate"))
Insert cell
visualizePredictionMarkets(rateMarkets, "Rate Market Probabilities Over Time")
Insert cell
otherMarkets = {
const nonMentionData = data.filter(market => !market.question.includes("say"));
const nonRateData = nonMentionData.filter(market => !market.question.includes("rate"));

return nonRateData;
}
Insert cell
visualizePredictionMarkets(otherMarkets, "Other Market Probabilities Over Time")
Insert cell
Insert cell
Insert cell
// weightings
indexData = {
const weightAssignments = [
{ questionFragment: "pharmaceuticals", weight: 0.1 },
{ questionFragment: "impose large tariffs in 2025", weight: 0.4 },
{ questionFragment: "large tariffs in his first 6 months", weight: 0.1 },
{ questionFragment: "remove majority of reciprocal tariffs before 90 day deadline", weight: 0.2 },
{ questionFragment: "insider trading", weight: 0.1 },
{ questionFragment: "courts block", weight: 0.1 },
];
weightAssignments.forEach(assignment => {
addWeightToMarket(otherMarkets, assignment.questionFragment, assignment.weight);
});

return otherMarkets;
}
Insert cell
Insert cell
weightedIndex = createWeightedIndex(indexData);
Insert cell
Insert cell
visualizeIndex(weightedIndex, "Tariff Prediction Market Index");
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more