-
Notifications
You must be signed in to change notification settings - Fork 661
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standardize Bybit endpoint error handling
- Loading branch information
1 parent
751ba25
commit 2d118fa
Showing
8 changed files
with
122 additions
and
7 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
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
51 changes: 51 additions & 0 deletions
51
nautilus_trader/adapters/bybit/endpoints/asset/coin_info.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,51 @@ | ||
# ------------------------------------------------------------------------------------------------- | ||
# Copyright (C) 2015-2024 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 msgspec | ||
|
||
from nautilus_trader.adapters.bybit.common.enums import BybitEndpointType | ||
from nautilus_trader.adapters.bybit.endpoints.endpoint import BybitHttpEndpoint | ||
from nautilus_trader.adapters.bybit.http.client import BybitHttpClient | ||
from nautilus_trader.adapters.bybit.schemas.asset.coin_info import BybitCoinInfoResponse | ||
from nautilus_trader.core.nautilus_pyo3 import HttpMethod | ||
|
||
|
||
class BybitCoinInfoGetParams(msgspec.Struct, omit_defaults=True, frozen=False): | ||
coin: str | None = None | ||
|
||
|
||
class BybitCoinInfoEndpoint(BybitHttpEndpoint): | ||
def __init__( | ||
self, | ||
client: BybitHttpClient, | ||
base_endpoint: str, | ||
) -> None: | ||
self.http_method = HttpMethod.GET | ||
url_path = base_endpoint + "/asset/coin/query-info" | ||
super().__init__( | ||
client=client, | ||
endpoint_type=BybitEndpointType.ASSET, | ||
url_path=url_path, | ||
) | ||
self._get_resp_decoder = msgspec.json.Decoder(BybitCoinInfoResponse) | ||
|
||
async def get(self, params: BybitCoinInfoGetParams) -> BybitCoinInfoResponse: | ||
raw = await self._method(self.http_method, params) | ||
try: | ||
return self._get_resp_decoder.decode(raw) | ||
except Exception as e: | ||
raise RuntimeError( | ||
f"Failed to decode response from {self.url_path}: {raw.decode()}", | ||
) from e |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# ------------------------------------------------------------------------------------------------- | ||
# Copyright (C) 2015-2024 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. | ||
# ------------------------------------------------------------------------------------------------- |
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,50 @@ | ||
# ------------------------------------------------------------------------------------------------- | ||
# Copyright (C) 2015-2024 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 typing import Any | ||
|
||
import msgspec as msgspec | ||
|
||
|
||
class BybitCoinChainInfo(msgspec.Struct): | ||
confirmation: str | ||
chainType: str | ||
withdrawFee: str | ||
depositMin: str | ||
withdrawMin: str | ||
chain: str | ||
chainDeposit: str | ||
chainWithdraw: str | ||
minAccuracy: str | ||
withdrawPercentageFee: str | ||
|
||
|
||
class BybitCoinInfo(msgspec.Struct): | ||
name: str | ||
coin: str | ||
remainAmount: str | ||
chains: list[BybitCoinChainInfo] | ||
|
||
|
||
class BybitCoinInfoResult(msgspec.Struct): | ||
rows: list[BybitCoinInfo] | ||
|
||
|
||
class BybitCoinInfoResponse(msgspec.Struct): | ||
retCode: int | ||
retMsg: str | ||
result: BybitCoinInfoResult | ||
retExtInfo: dict[str, Any] | ||
time: int |