feat: add insight non-binary markets

This commit is contained in:
NunoSempere 2022-10-28 13:25:58 +01:00
parent bf89e4b11d
commit d739def318

View File

@ -65,6 +65,20 @@ const getOrderbookPrize = (orderbook : any) => {
return yes_price_orderbook return yes_price_orderbook
} }
const getAnswerProbability = (answer : any) => {
let orderbook = answer.orderbook
let latest_yes_price = answer.latest_yes_price
if (!! orderbook && hasActiveYesNoOrderBook(orderbook)) {
let yes_price_orderbook = getOrderbookPrize(orderbook)
let yes_probability = (latest_yes_price ? geomMean(latest_yes_price, yes_price_orderbook) : yes_price_orderbook) / 100
return yes_probability
} else if (!! latest_yes_price) {
return latest_yes_price / 100
} else {
return -1
}
}
// Fetching // Fetching
async function fetchPage(bearer: string, pageNum: number) { async function fetchPage(bearer: string, pageNum: number) {
let pageUrl = `${marketsEnpoint}&page=${pageNum}` let pageUrl = `${marketsEnpoint}&page=${pageNum}`
@ -98,25 +112,15 @@ async function fetchMarket(bearer: string, marketId: number) {
} }
const processMarket = (market : any) => { const processMarket = (market : any) => {
let hasData = !!market && !!market.answer && !!market.answer.data let options: FetchedQuestion["options"] = []
const id = `${platformName}-${
market.id
}`;
if (hasData) { if (!!market && !!market.answer && !!market.answer.data) {
let data = market.answer.data let data = market.answer.data
// console.log("has data") if (isBinaryQuestion(data)) { // Binary questions
if (isBinaryQuestion(data)) { let answer = data[0]
let orderbook = data[0].orderbook let probability = getAnswerProbability(answer)
// console.log("has orderbook") if (probability != -1) {
// console.log(JSON.stringify(orderbook, null, 2)) options = [
if (!! orderbook && hasActiveYesNoOrderBook(orderbook)) { // console.log("has active orderbook")
let latest_yes_price = data[0].latest_yes_price
let yes_price_orderbook = getOrderbookPrize(orderbook)
let yes_probability = latest_yes_price ? geomMean(latest_yes_price, yes_price_orderbook) : yes_price_orderbook
const probability = yes_probability / 100;
const options: FetchedQuestion["options"] = [
{ {
name: "Yes", name: "Yes",
probability: probability, probability: probability,
@ -127,40 +131,24 @@ const processMarket = (market : any) => {
type: "PROBABILITY" type: "PROBABILITY"
}, },
]; ];
const result: FetchedQuestion = { }
id: id,
title: market.title,
url: market.url,
description: processDescriptionText(market.rules),
options,
qualityindicators: market.coin_id == "USD" ? (
{volume: market.volume}
) : ({})
};
return result;
} else {
return null
}
} else { // non binary question } else { // non binary question
console.log("Non-binary question")
console.log(market)
console.log(data)
let options = []
for (let answer of data) { for (let answer of data) {
let orderbook = answer.orderbook let probability = getAnswerProbability(answer)
if (!! orderbook && hasActiveYesNoOrderBook(orderbook)) { if (probability != -1) {
let latest_yes_price = answer.latest_yes_price
let yes_price_orderbook = getOrderbookPrize(orderbook)
let yes_probability = latest_yes_price ? geomMean(latest_yes_price, yes_price_orderbook) : yes_price_orderbook
let newOption: QuestionOption = ({ let newOption: QuestionOption = ({
name: String(answer.title), name: String(answer.title),
probability: Number(yes_probability / 100), probability: probability,
type: "PROBABILITY" type: "PROBABILITY"
}); });
options.push(newOption) options.push(newOption)
} }
} }
}
if (!! options && Array.isArray(options) && options.length > 0) {
const id = `${platformName}-${
market.id
}`
const result: FetchedQuestion = { const result: FetchedQuestion = {
id: id, id: id,
title: market.title, title: market.title,
@ -173,13 +161,12 @@ const processMarket = (market : any) => {
}; };
return result; return result;
} }
} else { }
return null return null
}
} }
async function fetchAllMarkets(bearer: string) { async function fetchAllMarkets(bearer: string) {
let pageNum = 2559 let pageNum = 1
let markets = [] let markets = []
let categories = [] let categories = []
let isEnd = false let isEnd = false