-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Build out DatabentoInstrumentProvider
1 parent
1c4f707
commit 47a83f6
Showing
7 changed files
with
180 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# ------------------------------------------------------------------------------------------------- | ||
# Copyright (C) 2015-2023 Nautech Systems Pty Ltd. All rights reserved. | ||
# https://nautechsystems.io | ||
# | ||
# Licensed under the GNU Lesser General Public License Version 3.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ------------------------------------------------------------------------------------------------- | ||
|
||
|
||
from nautilus_trader.config import LiveDataClientConfig | ||
|
||
|
||
class DatabentoDataClientConfig(LiveDataClientConfig, frozen=True): | ||
""" | ||
Configuration for ``DatabentoDataClient`` instances. | ||
Parameters | ||
---------- | ||
api_key : str, optional | ||
The Binance API public key. | ||
If ``None`` then will source the `BINANCE_API_KEY` or | ||
`BINANCE_TESTNET_API_KEY` environment variables. | ||
api_secret : str, optional | ||
The Binance API public key. | ||
If ``None`` then will source the `BINANCE_API_KEY` or | ||
`BINANCE_TESTNET_API_KEY` environment variables. | ||
http_gateway : str, optional | ||
The HTTP historical client gateway override. | ||
""" | ||
|
||
api_key: str | None = None | ||
api_secret: str | None = None | ||
http_gateway: str | None = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# ------------------------------------------------------------------------------------------------- | ||
# Copyright (C) 2015-2023 Nautech Systems Pty Ltd. All rights reserved. | ||
# https://nautechsystems.io | ||
# | ||
# Licensed under the GNU Lesser General Public License Version 3.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ------------------------------------------------------------------------------------------------- | ||
|
||
from functools import lru_cache | ||
|
||
import databento | ||
|
||
from nautilus_trader.adapters.env import get_env_key | ||
|
||
|
||
DATABENTO_HTTP_CLIENTS: dict[str, databento.Historical] = {} | ||
|
||
|
||
@lru_cache(1) | ||
def get_cached_databento_http_client( | ||
key: str | None = None, | ||
gateway: str | None = None, | ||
) -> databento.Historical: | ||
""" | ||
Cache and return a Databento historical HTTP client with the given key and gateway. | ||
If a cached client with matching key and gateway already exists, then that | ||
cached client will be returned. | ||
Parameters | ||
---------- | ||
key : str, optional | ||
The API key for the client. | ||
gateway : str, optional | ||
The HTTP historical client gateway override. | ||
Returns | ||
------- | ||
databento.Historical | ||
""" | ||
global BINANCE_HTTP_CLIENTS | ||
|
||
key = key or get_env_key("DATABENTO_API_KEY") | ||
|
||
client_key: str = "|".join((key, gateway or "")) | ||
if client_key not in DATABENTO_HTTP_CLIENTS: | ||
client = databento.Historical(key=key, gateway=gateway or databento.HistoricalGateway.BO1) | ||
DATABENTO_HTTP_CLIENTS[client_key] = client | ||
return DATABENTO_HTTP_CLIENTS[client_key] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/integration_tests/adapters/databento/sandbox/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# ------------------------------------------------------------------------------------------------- | ||
# Copyright (C) 2015-2023 Nautech Systems Pty Ltd. All rights reserved. | ||
# https://nautechsystems.io | ||
# | ||
# Licensed under the GNU Lesser General Public License Version 3.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ------------------------------------------------------------------------------------------------- |
55 changes: 55 additions & 0 deletions
55
tests/integration_tests/adapters/databento/sandbox/sandbox_instrument_provider.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# ------------------------------------------------------------------------------------------------- | ||
# Copyright (C) 2015-2023 Nautech Systems Pty Ltd. All rights reserved. | ||
# https://nautechsystems.io | ||
# | ||
# Licensed under the GNU Lesser General Public License Version 3.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ------------------------------------------------------------------------------------------------- | ||
|
||
import os | ||
|
||
import databento | ||
import pytest | ||
|
||
from nautilus_trader.adapters.databento.factories import get_cached_databento_http_client | ||
from nautilus_trader.adapters.databento.providers import DatabentoInstrumentProvider | ||
from nautilus_trader.common.clock import LiveClock | ||
from nautilus_trader.common.logging import Logger | ||
from nautilus_trader.model.identifiers import InstrumentId | ||
|
||
|
||
@pytest.mark.asyncio() | ||
async def test_binance_futures_testnet_market_http_client(): | ||
clock = LiveClock() | ||
|
||
key = os.getenv("DATABENTO_API_KEY") | ||
|
||
http_client = get_cached_databento_http_client( | ||
key=key, | ||
# gateway=gateway, | ||
) | ||
|
||
live_client = databento.Live( | ||
key=key, | ||
# gateway=gateway, | ||
) | ||
|
||
provider = DatabentoInstrumentProvider( | ||
http_client=http_client, | ||
live_client=live_client, | ||
clock=clock, | ||
logger=Logger(clock=clock), | ||
) | ||
|
||
instrument_ids = [ | ||
InstrumentId.from_str("ESM2.GLBX"), | ||
] | ||
|
||
provider.load_ids(instrument_ids) |