-
Notifications
You must be signed in to change notification settings - Fork 6
/
kalshi.ts
141 lines (127 loc) · 3.85 KB
/
kalshi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* Imports */
import axios from "axios";
import api from "api";
const kalshi_api = api("@trading-api/v2.0#13mtbs10lc863irx");
import { average } from "../../utils";
import { FetchedQuestion, Platform } from "./";
/* Definitions */
const platformName = "kalshi";
let jsonEndpoint = "https://trading-api.kalshi.com/v2";
async function fetchAllMarkets() {
try {
let response = await kalshi_api.login({
email: process.env.KALSHI_EMAIL,
password: process.env.KALSHI_PASSWORD,
});
console.log(response.data);
let exchange_status = await kalshi_api.getExchangeStatus();
console.log(exchange_status.data);
// kalshi_api.auth(process.env.KALSHI_EMAIL, process.env.KALSHI_PASSWORD);
kalshi_api.auth(response.member_id, response.token);
/*
*/
let market_params = {
limit: "100",
cursor: null,
event_ticker: null,
series_ticker: null,
max_close_ts: null,
min_close_ts: null,
status: null,
tickers: null,
};
// let markets = await kalshi_api.getMarkets(market_params).then(({data: any}) => console.log(data))
// console.log(markets)
} catch (error) {
console.log(error);
}
return 1;
}
/*
async function fetchAllMarkets() {
let response = await axios
.get(jsonEndpoint)
.then((response) => response.data.markets);
return response;
}
async function processMarkets(markets: any[]) {
let dateNow = new Date().toISOString();
// console.log(markets)
markets = markets.filter((market) => market.close_date > dateNow);
let results = await markets.map((market) => {
const probability = market.last_price / 100;
const options: FetchedQuestion["options"] = [
{
name: "Yes",
probability: probability,
type: "PROBABILITY",
},
{
name: "No",
probability: 1 - probability,
type: "PROBABILITY",
},
];
const id = `${platformName}-${market.id}`;
const result: FetchedQuestion = {
id,
title: market.title.replaceAll("*", ""),
url: `https://kalshi.com/markets/${market.ticker_name}`,
description: `${market.settle_details}. The resolution source is: ${market.ranged_group_name} (${market.settle_source_url})`,
options,
qualityindicators: {
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
},
extra: {
open_interest: market.open_interest,
},
};
return result;
});
console.log([...new Set(results.map((result) => result.title))]);
console.log(
"Number of unique questions: ",
[...new Set(results.map((result) => result.title))].length
);
return results;
}
*/
export const kalshi: Platform = {
name: platformName,
label: "Kalshi",
color: "#615691",
version: "v1",
fetcher: async function () {
// let markets = await fetchAllMarkets();
// console.log(markets)
return [];
},
calculateStars(data) {
let nuno = () =>
((data.extra as any)?.open_interest || 0) > 500 &&
data.qualityindicators.shares_volume > 10000
? 4
: data.qualityindicators.shares_volume > 2000
? 3
: 2;
// let eli = (data) => data.interest > 10000 ? 5 : 4
// let misha = (data) => 4
let starsDecimal = average([nuno()]);
// , eli(data), misha(data)])
// Substract 1 star if probability is above 90% or below 10%
if (
data.options instanceof Array &&
data.options[0] &&
((data.options[0].probability || 0) < 0.1 ||
(data.options[0].probability || 0) > 0.9)
) {
starsDecimal = starsDecimal - 1;
}
let starsInteger = Math.round(starsDecimal);
return starsInteger;
},
};