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