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;
28
29/// Kalshi client identifier.
30pub static KALSHI_CLIENT_ID: LazyLock<ClientId> =
31 LazyLock::new(|| ClientId::new(Ustr::from(KALSHI)));
32
33/// Kalshi venue identifier.
34pub static KALSHI_VENUE: LazyLock<Venue> = LazyLock::new(|| Venue::new(Ustr::from(KALSHI)));
35
36/// Path prefix for the REST trading API.
37pub const KALSHI_API_PATH_PREFIX: &str = "/trade-api/v2";
38
39/// Path signed for WebSocket authentication.
40pub const KALSHI_WS_SIGN_PATH: &str = "/trade-api/ws/v2";
41
42/// API key ID header name.
43pub const KALSHI_ACCESS_KEY_HEADER: &str = "KALSHI-ACCESS-KEY";
44
45/// Request signature header name.
46pub const KALSHI_ACCESS_SIGNATURE_HEADER: &str = "KALSHI-ACCESS-SIGNATURE";
47
48/// Request timestamp header name.
49pub const KALSHI_ACCESS_TIMESTAMP_HEADER: &str = "KALSHI-ACCESS-TIMESTAMP";
50
51/// Default HTTP request timeout.
52pub const HTTP_TIMEOUT: Duration = Duration::from_secs(10);
53
54/// Kalshi sends WebSocket Ping frames every 10 seconds.
55pub const WS_PING_INTERVAL: Duration = Duration::from_secs(10);
56
57/// Base reconnect backoff for the WebSocket client.
58pub const RECONNECT_BASE_BACKOFF: Duration = Duration::from_millis(250);
59
60/// Maximum reconnect backoff for the WebSocket client.
61pub const RECONNECT_MAX_BACKOFF: Duration = Duration::from_secs(30);
62
63/// Basic-tier read token refill per second.
64pub const BASIC_READ_TOKENS_PER_SEC: u32 = 200;
65
66/// Basic-tier write token refill per second.
67pub const BASIC_WRITE_TOKENS_PER_SEC: u32 = 100;
68
69/// Maximum page size accepted by public trades pagination.
70pub const MAX_TRADES_PAGE_SIZE: u32 = 1000;