Skip to main content

nautilus_betfair/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//! Core constants for the Betfair adapter.
17
18use std::sync::LazyLock;
19
20use nautilus_model::identifiers::{ClientId, Venue};
21use ustr::Ustr;
22
23/// Venue identifier string.
24pub const BETFAIR: &str = "BETFAIR";
25
26/// Static venue instance.
27pub static BETFAIR_VENUE: LazyLock<Venue> = LazyLock::new(|| Venue::new(Ustr::from(BETFAIR)));
28
29/// Static client ID instance.
30pub static BETFAIR_CLIENT_ID: LazyLock<ClientId> =
31    LazyLock::new(|| ClientId::new(Ustr::from(BETFAIR)));
32
33/// Price decimal precision for Betfair markets.
34pub const BETFAIR_PRICE_PRECISION: u8 = 2;
35
36/// Quantity decimal precision for Betfair markets.
37pub const BETFAIR_QUANTITY_PRECISION: u8 = 2;
38
39// Identity API (SSO)
40pub const BETFAIR_IDENTITY_URL: &str = "https://identitysso-cert.betfair.com/api";
41
42// Betting API (JSON-RPC)
43pub const BETFAIR_BETTING_URL: &str = "https://api.betfair.com/exchange/betting/json-rpc/v1";
44
45// Accounts API (JSON-RPC)
46pub const BETFAIR_ACCOUNTS_URL: &str = "https://api.betfair.com/exchange/account/json-rpc/v1";
47
48// Navigation API (REST)
49pub const BETFAIR_NAVIGATION_URL: &str =
50    "https://api.betfair.com/exchange/betting/rest/v1/en/navigation/menu.json";
51
52// Exchange stream (market data and orders)
53pub const BETFAIR_STREAM_HOST: &str = "stream-api.betfair.com";
54
55// Race stream (TPD / race tracking data)
56pub const BETFAIR_RACE_STREAM_HOST: &str = "sports-data-stream-api.betfair.com";
57
58/// Stream TLS port.
59pub const BETFAIR_STREAM_PORT: u16 = 443;
60
61// Interactive login URL (non-cert)
62pub const BETFAIR_IDENTITY_LOGIN_URL: &str = "https://identitysso.betfair.com/api/login";
63
64// Keep-alive URL (must match login host: interactive SSO, not cert)
65pub const BETFAIR_KEEP_ALIVE_URL: &str = "https://identitysso.betfair.com/api/keepAlive";
66
67// Rate limiter keys
68pub const BETFAIR_RATE_LIMIT_DEFAULT: &str = "default";
69pub const BETFAIR_RATE_LIMIT_ORDERS: &str = "orders";
70
71/// Maximum length for the `customer_order_ref` field on place instructions.
72///
73/// Betfair silently truncates longer references. We take the last 32 characters
74/// of the client order ID to preserve the high-entropy suffix (UUID tail).
75pub const BETFAIR_CUSTOMER_ORDER_REF_MAX_LEN: usize = 32;
76
77// Betting API JSON-RPC methods
78pub const METHOD_LIST_MARKET_CATALOGUE: &str = "SportsAPING/v1.0/listMarketCatalogue";
79pub const METHOD_LIST_CURRENT_ORDERS: &str = "SportsAPING/v1.0/listCurrentOrders";
80pub const METHOD_PLACE_ORDERS: &str = "SportsAPING/v1.0/placeOrders";
81pub const METHOD_CANCEL_ORDERS: &str = "SportsAPING/v1.0/cancelOrders";
82pub const METHOD_REPLACE_ORDERS: &str = "SportsAPING/v1.0/replaceOrders";
83
84// Accounts API JSON-RPC methods
85pub const METHOD_GET_ACCOUNT_FUNDS: &str = "AccountAPING/v1.0/getAccountFunds";
86pub const METHOD_GET_ACCOUNT_DETAILS: &str = "AccountAPING/v1.0/getAccountDetails";
87
88// Stream operation strings
89pub const STREAM_OP_AUTHENTICATION: &str = "authentication";
90pub const STREAM_OP_MARKET_SUBSCRIPTION: &str = "marketSubscription";
91pub const STREAM_OP_ORDER_SUBSCRIPTION: &str = "orderSubscription";
92pub const STREAM_OP_RACE_SUBSCRIPTION: &str = "raceSubscription";
93pub const STREAM_OP_CRICKET_SUBSCRIPTION: &str = "cricketSubscription";
94pub const STREAM_OP_HEARTBEAT: &str = "heartbeat";
95
96// HTTP header names
97pub const HEADER_X_AUTHENTICATION: &str = "X-Authentication";
98pub const HEADER_X_APPLICATION: &str = "X-Application";
99
100// Default market attribute values
101pub const DEFAULT_BETTING_TYPE: &str = "ODDS";
102pub const DEFAULT_MARKET_TYPE: &str = "WIN";