Skip to content

Commit

Permalink
Single source Nautilus user-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Dec 28, 2023
1 parent 6dc33b6 commit d04aefe
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
13 changes: 7 additions & 6 deletions nautilus_trader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
PACKAGE_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PYPROJECT_PATH = os.path.join(PACKAGE_ROOT, "pyproject.toml")

try:
__version__ = toml.load(PYPROJECT_PATH)["tool"]["poetry"]["version"]
except FileNotFoundError: # pragma: no cover
__version__ = "latest"

USER_AGENT = f"NautilusTrader/{__version__}"


def clean_version_string(version: str) -> str:
"""
Expand Down Expand Up @@ -61,9 +68,3 @@ def get_package_version_installed(package_name: str) -> str:
Return the package version installed for the given `package_name`.
"""
return version(package_name)


try:
__version__ = toml.load(PYPROJECT_PATH)["tool"]["poetry"]["version"]
except FileNotFoundError: # pragma: no cover
__version__ = "latest"
3 changes: 2 additions & 1 deletion nautilus_trader/adapters/betfair/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
# -------------------------------------------------------------------------------------------------


from betfair_parser.endpoints import ENDPOINTS
from betfair_parser.spec.accounts.operations import GetAccountDetails
from betfair_parser.spec.accounts.operations import GetAccountFunds
Expand Down Expand Up @@ -58,6 +57,7 @@
from betfair_parser.spec.navigation import Menu
from betfair_parser.spec.navigation import Navigation

import nautilus_trader
from nautilus_trader.common.logging import Logger
from nautilus_trader.common.logging import LoggerAdapter
from nautilus_trader.core.nautilus_pyo3 import HttpClient
Expand Down Expand Up @@ -128,6 +128,7 @@ def reset_headers(self):
self._headers = {
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": nautilus_trader.USER_AGENT,
"X-Application": self.app_key,
}

Expand Down
1 change: 0 additions & 1 deletion nautilus_trader/adapters/betfair/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
# -------------------------------------------------------------------------------------------------


from nautilus_trader.adapters.betfair.providers import BetfairInstrumentProviderConfig
from nautilus_trader.config import LiveDataClientConfig
from nautilus_trader.config import LiveExecClientConfig
Expand Down
2 changes: 1 addition & 1 deletion nautilus_trader/adapters/binance/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(
self._secret: str = secret
self._headers: dict[str, Any] = {
"Content-Type": "application/json",
"User-Agent": "nautilus-trader/" + nautilus_trader.__version__,
"User-Agent": nautilus_trader.USER_AGENT,
"X-MBX-APIKEY": key,
}
self._client = HttpClient(
Expand Down
2 changes: 1 addition & 1 deletion nautilus_trader/adapters/bybit/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(
self._base_url: str = base_url
self._headers: dict[str, Any] = {
"Content-Type": "application/json",
"User-Agent": "nautilus-trader/" + nautilus_trader.__version__,
"User-Agent": nautilus_trader.USER_AGENT,
"X-BAPI-API-KEY": self._api_key,
}
self._client = HttpClient(
Expand Down
6 changes: 6 additions & 0 deletions nautilus_trader/adapters/databento/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import databento

import nautilus_trader
from nautilus_trader.adapters.databento.types import DatabentoPublisher
from nautilus_trader.core.correctness import PyCondition
from nautilus_trader.model.data import BarType
Expand All @@ -27,6 +28,11 @@
from nautilus_trader.model.identifiers import Venue


# Update Databento user-agent constant value with NautilusTrader version
if nautilus_trader.USER_AGENT not in databento.common.system.USER_AGENT:
databento.common.system.USER_AGENT += f" {nautilus_trader.USER_AGENT}"


def check_file_path(path: Path) -> None:
"""
Check that the file at the given `path` exists and is not empty.
Expand Down

0 comments on commit d04aefe

Please sign in to comment.