Skip to main content

nautilus_kalshi/common/
consts.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Venue identifiers and protocol constants for the Kalshi adapter.
17
18use std::{sync::LazyLock, time::Duration};
19
20use nautilus_model::identifiers::{ClientId, Venue};
21use ustr::Ustr;
22
23/// Venue name string for Kalshi.
24pub const KALSHI: &str = "KALSHI";
25
26pub(crate) const PRICE_PRECISION: u8 = 6;
27pub(crate) const SIZE_PRECISION: u8 = 2;
28pub(crate) const MAX_SUBACCOUNT: u32 = 63;
29
30/// Kalshi client identifier.
31pub static KALSHI_CLIENT_ID: LazyLock<ClientId> =
32    LazyLock::new(|| ClientId::new(Ustr::from(KALSHI)));
33
34/// Kalshi venue identifier.
35pub static KALSHI_VENUE: LazyLock<Venue> = LazyLock::new(|| Venue::new(Ustr::from(KALSHI)));
36
37/// Path prefix for the REST trading API.
38pub const KALSHI_API_PATH_PREFIX: &str = "/trade-api/v2";
39
40/// Path signed for WebSocket authentication.
41pub const KALSHI_WS_SIGN_PATH: &str = "/trade-api/ws/v2";
42
43/// API key ID header name.
44pub const KALSHI_ACCESS_KEY_HEADER: &str = "KALSHI-ACCESS-KEY";
45
46/// Request signature header name.
47pub const KALSHI_ACCESS_SIGNATURE_HEADER: &str = "KALSHI-ACCESS-SIGNATURE";
48
49/// Request timestamp header name.
50pub const KALSHI_ACCESS_TIMESTAMP_HEADER: &str = "KALSHI-ACCESS-TIMESTAMP";
51
52/// Default HTTP request timeout.
53pub const HTTP_TIMEOUT: Duration = Duration::from_secs(10);
54
55/// Kalshi sends WebSocket Ping frames every 10 seconds.
56pub const WS_PING_INTERVAL: Duration = Duration::from_secs(10);
57
58/// Base reconnect backoff for the WebSocket client.
59pub const RECONNECT_BASE_BACKOFF: Duration = Duration::from_millis(250);
60
61/// Maximum reconnect backoff for the WebSocket client.
62pub const RECONNECT_MAX_BACKOFF: Duration = Duration::from_secs(30);
63
64/// Basic-tier read token refill per second.
65pub const BASIC_READ_TOKENS_PER_SEC: u32 = 200;
66
67/// Basic-tier write token refill per second.
68pub const BASIC_WRITE_TOKENS_PER_SEC: u32 = 100;
69
70/// Maximum page size accepted by public trades pagination.
71pub const MAX_TRADES_PAGE_SIZE: u32 = 1000;