2021-08-31 19:14:55 +00:00
|
|
|
/* Imports */
|
2022-02-11 14:21:36 +00:00
|
|
|
import axios from "axios";
|
2022-03-29 01:34:27 +00:00
|
|
|
|
2022-03-26 00:36:50 +00:00
|
|
|
import { calculateStars } from "../utils/stars";
|
2022-03-29 15:10:28 +00:00
|
|
|
import { Platform } from "./";
|
2021-08-31 19:14:55 +00:00
|
|
|
|
|
|
|
/* Definitions */
|
2022-04-01 20:24:35 +00:00
|
|
|
const platformName = "kalshi";
|
2022-02-11 14:21:36 +00:00
|
|
|
let jsonEndpoint = "https://trading-api.kalshi.com/v1/cached/markets/"; //"https://subgraph-matic.poly.market/subgraphs/name/TokenUnion/polymarket"//"https://subgraph-backup.poly.market/subgraphs/name/TokenUnion/polymarket"//'https://subgraph-matic.poly.market/subgraphs/name/TokenUnion/polymarket3'
|
2021-08-31 19:14:55 +00:00
|
|
|
|
2022-02-11 14:21:36 +00:00
|
|
|
async function fetchAllMarkets() {
|
|
|
|
// for info which the polymarket graphql API
|
|
|
|
let response = await axios
|
|
|
|
.get(jsonEndpoint)
|
|
|
|
.then((response) => response.data.markets);
|
2021-08-31 19:14:55 +00:00
|
|
|
// console.log(response)
|
2022-02-11 14:21:36 +00:00
|
|
|
return response;
|
2021-08-31 19:14:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function processMarkets(markets) {
|
2022-02-11 14:21:36 +00:00
|
|
|
let dateNow = new Date().toISOString();
|
2021-08-31 19:14:55 +00:00
|
|
|
// console.log(markets)
|
2022-02-11 14:21:36 +00:00
|
|
|
markets = markets.filter((market) => market.close_date > dateNow);
|
|
|
|
let results = await markets.map((market) => {
|
|
|
|
let probability = market.last_price / 100;
|
2021-08-31 19:14:55 +00:00
|
|
|
let options = [
|
|
|
|
{
|
2022-02-11 14:21:36 +00:00
|
|
|
name: "Yes",
|
|
|
|
probability: probability,
|
|
|
|
type: "PROBABILITY",
|
2021-08-31 19:14:55 +00:00
|
|
|
},
|
|
|
|
{
|
2022-02-11 14:21:36 +00:00
|
|
|
name: "No",
|
|
|
|
probability: 1 - probability,
|
|
|
|
type: "PROBABILITY",
|
|
|
|
},
|
|
|
|
];
|
2022-04-01 20:24:35 +00:00
|
|
|
let id = `${platformName}-${market.id}`;
|
2022-02-11 14:21:36 +00:00
|
|
|
let result = {
|
|
|
|
id: id,
|
|
|
|
title: market.title.replaceAll("*", ""),
|
|
|
|
url: `https://kalshi.com/markets/${market.ticker_name}`,
|
2022-04-01 20:24:35 +00:00
|
|
|
platform: platformName,
|
2022-02-11 14:21:36 +00:00
|
|
|
description: `${market.settle_details}. The resolution source is: ${market.ranged_group_name} (${market.settle_source_url})`,
|
|
|
|
options: options,
|
|
|
|
timestamp: new Date().toISOString(),
|
|
|
|
qualityindicators: {
|
2022-04-01 20:24:35 +00:00
|
|
|
stars: calculateStars(platformName, {
|
2022-02-11 14:21:36 +00:00
|
|
|
shares_volume: market.volume,
|
|
|
|
interest: market.open_interest,
|
|
|
|
}),
|
|
|
|
yes_bid: market.yes_bid,
|
|
|
|
yes_ask: market.yes_ask,
|
|
|
|
spread: Math.abs(market.yes_bid - market.yes_ask),
|
|
|
|
shares_volume: market.volume, // Assuming that half of all buys are for yes and half for no, which is a big if.
|
|
|
|
// "open_interest": market.open_interest, also in shares
|
|
|
|
},
|
|
|
|
};
|
|
|
|
return result;
|
|
|
|
});
|
2021-08-31 19:14:55 +00:00
|
|
|
//console.log(results.length)
|
|
|
|
// console.log(results.map(result => result.title))
|
|
|
|
// console.log(results.map(result => result.title).length)
|
2022-02-11 14:21:36 +00:00
|
|
|
console.log([...new Set(results.map((result) => result.title))]);
|
|
|
|
console.log(
|
|
|
|
"Number of unique questions: ",
|
|
|
|
[...new Set(results.map((result) => result.title))].length
|
|
|
|
);
|
2021-08-31 19:14:55 +00:00
|
|
|
// console.log([...new Set(results.map(result => result.title))].length)
|
2022-02-11 14:21:36 +00:00
|
|
|
return results; //resultsProcessed
|
2021-08-31 19:14:55 +00:00
|
|
|
}
|
|
|
|
|
2022-03-29 15:10:28 +00:00
|
|
|
export const kalshi: Platform = {
|
2022-04-01 20:24:35 +00:00
|
|
|
name: platformName,
|
|
|
|
label: "Kalshi",
|
|
|
|
color: "#615691",
|
2022-03-29 15:10:28 +00:00
|
|
|
fetcher: async function () {
|
|
|
|
let markets = await fetchAllMarkets();
|
|
|
|
return await processMarkets(markets);
|
|
|
|
},
|
2022-03-29 01:34:27 +00:00
|
|
|
};
|