tweak: Improvements to PredictIt fetcher
This commit is contained in:
parent
d9b654d19e
commit
c08ee19479
|
@ -12,7 +12,8 @@ async function fetchmarkets() {
|
||||||
url: 'https://www.predictit.org/api/marketdata/all/'
|
url: 'https://www.predictit.org/api/marketdata/all/'
|
||||||
|
|
||||||
})
|
})
|
||||||
return response.data.markets
|
let openMarkets = response.data.markets.filter(market => market.status == "Open")
|
||||||
|
return openMarkets
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchmarketrules(market_id) {
|
async function fetchmarketrules(market_id) {
|
||||||
|
@ -23,6 +24,14 @@ async function fetchmarketrules(market_id) {
|
||||||
return response.data.rule
|
return response.data.rule
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchmarketvolumes(){
|
||||||
|
let response = await axios({
|
||||||
|
method: 'get',
|
||||||
|
url: "https://predictit-f497e.firebaseio.com/marketStats.json"
|
||||||
|
})
|
||||||
|
return response.data
|
||||||
|
}
|
||||||
|
|
||||||
function sleep(ms) {
|
function sleep(ms) {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
|
@ -30,16 +39,25 @@ function sleep(ms) {
|
||||||
|
|
||||||
/* Body */
|
/* Body */
|
||||||
export async function predictit() {
|
export async function predictit() {
|
||||||
let response = await fetchmarkets()
|
let markets = await fetchmarkets()
|
||||||
// console.log(response)
|
let marketVolumes = await fetchmarketvolumes()
|
||||||
|
|
||||||
|
markets = markets.map(market => ({
|
||||||
|
...market,
|
||||||
|
TotalSharesTraded: marketVolumes[market.id]["TotalSharesTraded"]
|
||||||
|
}))
|
||||||
|
// console.log(markets)
|
||||||
|
|
||||||
let results = []
|
let results = []
|
||||||
for (let market of response) {
|
for (let market of markets) {
|
||||||
|
// console.log(market.name)
|
||||||
let isbinary = market.contracts.length == 1;
|
let isbinary = market.contracts.length == 1;
|
||||||
await sleep(3000 * (1 + Math.random()))
|
await sleep(3000 * (1 + Math.random()))
|
||||||
let descriptionraw = await fetchmarketrules(market.id)
|
let descriptionraw = await fetchmarketrules(market.id)
|
||||||
let descriptionprocessed1 = toMarkdown(descriptionraw)
|
let descriptionprocessed1 = toMarkdown(descriptionraw)
|
||||||
let description = descriptionprocessed1
|
let description = descriptionprocessed1
|
||||||
let percentageFormatted = isbinary ? Number(Number(market.contracts[0].lastTradePrice) * 100).toFixed(0) + "%" : "none"
|
let shares_volume = market["TotalSharesTraded"]
|
||||||
|
// let percentageFormatted = isbinary ? Number(Number(market.contracts[0].lastTradePrice) * 100).toFixed(0) + "%" : "none"
|
||||||
|
|
||||||
let options = market.contracts.map(contract => ({
|
let options = market.contracts.map(contract => ({
|
||||||
"name": contract.name,
|
"name": contract.name,
|
||||||
|
@ -80,9 +98,9 @@ export async function predictit() {
|
||||||
"options": options,
|
"options": options,
|
||||||
"timestamp": new Date().toISOString(),
|
"timestamp": new Date().toISOString(),
|
||||||
"qualityindicators": {
|
"qualityindicators": {
|
||||||
"stars": calculateStars("PredictIt", ({}))
|
"stars": calculateStars("PredictIt", ({})),
|
||||||
|
"shares_volume": shares_volume
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
// console.log(obj)
|
// console.log(obj)
|
||||||
results.push(obj)
|
results.push(obj)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user