Lista di cryptovalute #36
@@ -57,7 +57,9 @@ class BinanceWrapper(MarketWrapper):
|
|||||||
"""
|
"""
|
||||||
|
|
|||||||
Formatta l'asset_id nel formato richiesto da Binance.
|
Formatta l'asset_id nel formato richiesto da Binance.
|
||||||
"""
|
"""
|
||||||
return asset_id.replace('-', '') if '-' in asset_id else f"{asset_id}{self.currency}"
|
i = asset_id.index('-')
|
||||||
|
if i != -1: asset_id = asset_id[:i]
|
||||||
|
return f"{asset_id}{self.currency}" if self.currency not in asset_id else asset_id
|
||||||
|
|
||||||
def get_product(self, asset_id: str) -> ProductInfo:
|
def get_product(self, asset_id: str) -> ProductInfo:
|
||||||
symbol = self.__format_symbol(asset_id)
|
symbol = self.__format_symbol(asset_id)
|
||||||
|
|||||||
@@ -61,7 +61,9 @@ class CoinBaseWrapper(MarketWrapper):
|
|||||||
)
|
)
|
||||||
|
The The `str.index()` method raises a `ValueError` when the substring is not found, rather than returning -1. This will cause a runtime error when processing symbols without a hyphen. Use `asset_id.find('-')` instead, which returns -1 when not found, or handle the `ValueError` exception.
```suggestion
i = asset_id.find('-')
```
|
|||||||
|
|
||||||
def __format(self, asset_id: str) -> str:
|
def __format(self, asset_id: str) -> str:
|
||||||
return asset_id if '-' in asset_id else f"{asset_id}-{self.currency}"
|
i = asset_id.index('-')
|
||||||
|
if i != -1: asset_id = asset_id[:i]
|
||||||
|
return f"{asset_id}-{self.currency}"
|
||||||
|
|
||||||
def get_product(self, asset_id: str) -> ProductInfo:
|
def get_product(self, asset_id: str) -> ProductInfo:
|
||||||
asset_id = self.__format(asset_id)
|
asset_id = self.__format(asset_id)
|
||||||
|
|||||||
@@ -47,8 +47,9 @@ class YFinanceWrapper(MarketWrapper):
|
|||||||
Formatta il simbolo per yfinance.
|
Formatta il simbolo per yfinance.
|
||||||
|
The The `str.index()` method raises a `ValueError` when the substring is not found, rather than returning -1. This will cause a runtime error when processing symbols without a hyphen. Use `asset_id.find('-')` instead, which returns -1 when not found, or handle the `ValueError` exception.
```suggestion
i = asset_id.find('-')
```
|
|||||||
Per crypto, aggiunge '-' e la valuta (es. BTC -> BTC-USD).
|
Per crypto, aggiunge '-' e la valuta (es. BTC -> BTC-USD).
|
||||||
"""
|
"""
|
||||||
asset_id = asset_id.upper()
|
i = asset_id.index('-')
|
||||||
return f"{asset_id}-{self.currency}" if '-' not in asset_id else asset_id
|
if i != -1: asset_id = asset_id[:i]
|
||||||
|
return f"{asset_id}-{self.currency}"
|
||||||
|
|
||||||
def get_product(self, asset_id: str) -> ProductInfo:
|
def get_product(self, asset_id: str) -> ProductInfo:
|
||||||
symbol = self._format_symbol(asset_id)
|
symbol = self._format_symbol(asset_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user
The
str.index()method raises aValueErrorwhen the substring is not found, rather than returning -1. This will cause a runtime error when processing symbols without a hyphen. Useasset_id.find('-')instead, which returns -1 when not found, or handle theValueErrorexception.