Betfair - Loren1166/NautilusTrader- GitHub Wiki
Betfair
NautilusTrader offers adapters for integrating with the Betfair REST API and Exchange Streaming API.
NautilusTrader 提供了与 Betfair REST API 和交易所流 API 集成的适配器。
Overview 概述
The following adapter classes are available:
以下适配器类可用:
BetfairInstrumentProvider
which enables querying the Betfair market catalogue for betting markets, which are then converted into Nautilus "instruments".BetfairInstrumentProvider
支持查询 Betfair 市场目录以获取博彩市场,然后将其转换为 Nautilus “Instrument”。BetfairDataClient
which connects to the Exchange Stream API and streams market data.BetfairDataClient
连接到交易所流 API 并流式传输市场数据。BetfairExecutionClient
which enables the retrieval of account information and execution and updates for orders (or bets).BetfairExecutionClient
支持检索账户信息以及订单(或投注)的执行和更新。
Configuration 配置
The most common use case is to configure a live
TradingNode
to include Betfair data and execution clients. To achieve this, add aBETFAIR
section to your client configuration(s):最常见的用例是配置实时
TradingNode
以包含 Betfair 数据和执行客户端。为此,请将BETFAIR
部分添加到您的客户端配置中:
from nautilus_trader.config import TradingNodeConfig
config = TradingNodeConfig(
..., # Omitted
data_clients={
"BETFAIR": {
"username": "YOUR_BETFAIR_USERNAME",
"password": "YOUR_BETFAIR_PASSWORD",
"app_key": "YOUR_BETFAIR_APP_KEY",
"cert_dir": "YOUR_BETFAIR_CERT_DIR",
},
},
exec_clients={
"BETFAIR": {
"username": "YOUR_BETFAIR_USERNAME",
"password": "YOUR_BETFAIR_PASSWORD",
"app_key": "YOUR_BETFAIR_APP_KEY",
"cert_dir": "YOUR_BETFAIR_CERT_DIR",
"base_currency": "AUD",
},
}
)
Then, create a
TradingNode
and add the client factories:然后,创建一个
TradingNode
并添加客户端工厂:
from nautilus_trader.adapters.betfair.factories import BetfairLiveDataClientFactory
from nautilus_trader.adapters.betfair.factories import BetfairLiveExecClientFactory
from nautilus_trader.live.node import TradingNode
# Instantiate the live trading node with a configuration
# 使用配置实例化实时交易节点
node = TradingNode(config=config)
# Register the client factories with the node
# 向节点注册客户端工厂
node.add_data_client_factory("BETFAIR", BetfairLiveDataClientFactory)
node.add_exec_client_factory("BETFAIR", BetfairLiveExecClientFactory)
# Finally build the node
# 最后构建节点
node.build()
API credentials API 凭证
There are two options for supplying your credentials to the Betfair clients. Either pass the corresponding
api_key
andapi_secret
values to theconfig
dictionaries, or set the following environment variables:向 Betfair 客户端提供凭据有两种选择。将相应的
api_key
和api_secret
值传递给config
字典,或者设置以下环境变量:
BETFAIR_API_KEY
BETFAIR_API_SECRET
BETFAIR_APP_KEY
BETFAIR_CERT_DIR
When starting the trading node, you'll receive immediate confirmation of whether your credentials are valid and have trading permissions.
启动交易节点时,您将立即收到您的凭据是否有效以及是否具有交易权限的确认。