fix: Streamlined Polymarket code; removed sports markets

This commit is contained in:
NunoSempere 2021-08-31 21:55:57 +02:00
parent f7a324cce0
commit 6f87f8bc43

View File

@ -66,65 +66,68 @@ async function fetch_all() {
let allData = await fetchAllContractData() let allData = await fetchAllContractData()
let allInfo = await fetchAllContractInfo() let allInfo = await fetchAllContractInfo()
let combinedObj = ({}) let infos = ({})
let results = []
for (let info of allInfo) { for (let info of allInfo) {
let address = info.marketMakerAddress let address = info.marketMakerAddress
let addressLowerCase = address.toLowerCase() let addressLowerCase = address.toLowerCase()
//delete info.history //delete info.history
if (info.outcomes[0] != "Long" || info.outcomes[1] != "Long") if (info.outcomes[0] != "Long" || info.outcomes[1] != "Long")
combinedObj[addressLowerCase] = { infos[addressLowerCase] = {
title: info.question, title: info.question,
url: "https://polymarket.com/market/" + info.slug, url: "https://polymarket.com/market/" + info.slug,
address: address, address: address,
description: info.description, description: info.description,
outcomes: info.outcomes, outcomes: info.outcomes,
options: [] options: [],
category: info.category
} }
} }
let results = []
for (let data of allData) { for (let data of allData) {
let addressLowerCase = data.id let addressLowerCase = data.id
// console.log(data) // console.log(data)
if (combinedObj[addressLowerCase] != undefined) { if (infos[addressLowerCase] != undefined) {
// console.log(addressLowerCase) // console.log(addressLowerCase)
let obj = combinedObj[addressLowerCase] let info = infos[addressLowerCase]
let numforecasts = data.tradesQuantity let numforecasts = Number(data.tradesQuantity)
let isbinary = Number(data.conditions[0].outcomeSlotCount) == 2
let tradevolume = (Number(data.collateralBuyVolume) + Number(data.collateralSellVolume)) / units let tradevolume = (Number(data.collateralBuyVolume) + Number(data.collateralSellVolume)) / units
let liquidity = Number(data.liquidityParameter) / units let liquidity = Number(data.liquidityParameter) / units
let percentage = Number(data.outcomeTokenPrices[0]) * 100 // let isbinary = Number(data.conditions[0].outcomeSlotCount) == 2
let percentageFormatted = isbinary ? (percentage.toFixed(0) + "%") : "none" // let percentage = Number(data.outcomeTokenPrices[0]) * 100
// let percentageFormatted = isbinary ? (percentage.toFixed(0) + "%") : "none"
let options = [] let options = []
for (let outcome in data.outcomeTokenPrices) { for (let outcome in data.outcomeTokenPrices) {
options.push({ options.push({
"name": obj.outcomes[outcome], "name": info.outcomes[outcome],
"probability": data.outcomeTokenPrices[outcome], "probability": data.outcomeTokenPrices[outcome],
"type": "PROBABILITY" "type": "PROBABILITY"
}) })
} }
combinedObj[addressLowerCase] = { let result = ({
"title": obj.title, "title": info.title,
"url": obj.url, "url": info.url,
"platform": "PolyMarket", "platform": "PolyMarket",
"description": obj.description, "description": info.description,
"options": options, "options": options,
"timestamp": new Date().toISOString(), "timestamp": new Date().toISOString(),
"qualityindicators": { "qualityindicators": {
"numforecasts": Number(data.tradesQuantity).toFixed(0), "numforecasts": numforecasts.toFixed(0),
"liquidity": liquidity.toFixed(2), "liquidity": liquidity.toFixed(2),
"tradevolume": tradevolume.toFixed(2), "tradevolume": tradevolume.toFixed(2),
"stars": calculateStars("Polymarket", ({ liquidity, option: options[0], volume: tradevolume})) "stars": calculateStars("Polymarket", ({ liquidity, option: options[0], volume: tradevolume}))
} }
/* /*
address: obj.address address: info.address
*/ */
} })
results.push(combinedObj[addressLowerCase]) if(info.category != "Sports"){
}
}
// let resultsProcessed = Object.values(combinedObj)
// console.log(result) // console.log(result)
results.push(result)
}
}
}
return results //resultsProcessed return results //resultsProcessed
} }
@ -132,7 +135,6 @@ async function fetch_all() {
export async function polymarket() { export async function polymarket() {
let results = await fetch_all() let results = await fetch_all()
// console.log(results) // console.log(results)
// console.log(result)
// let string = JSON.stringify(results, null, 2) // let string = JSON.stringify(results, null, 2)
// fs.writeFileSync('polymarket-questions.json', string); // fs.writeFileSync('polymarket-questions.json', string);
await upsert(results, "polymarket-questions") await upsert(results, "polymarket-questions")