fix: Don't send unlisted/fake bybit securities to sparkd
Securities that aren't listed in the instrument-info response from the exchange shouldn't be in our system.
This commit is contained in:
1 parent
ae868ab74d
commit
cf3f7e6862
1 file changed
+9
-14
@@ -15,6 +15,7 @@ from python_interop_module import (
|
||||
PySecurityList,
|
||||
)
|
||||
from spark_core import (
|
||||
JsonElement,
|
||||
configure_logger,
|
||||
get_contract_spec,
|
||||
get_price_info,
|
||||
@@ -34,14 +35,7 @@ def normalize_contract_name(contract: str) -> str:
|
||||
|
||||
def fetch_futures_specs(contracts: Iterable[str], use_testnet: bool = True) -> dict:
|
||||
# Fetch specs for futures only, explicitly, handling pagination
|
||||
default_specs = {
|
||||
"tick_unit": 1,
|
||||
"tick_base": 10,
|
||||
"cash_per_point": 0.1,
|
||||
"qty_tick_unit": 1,
|
||||
"qty_tick_base": 10000
|
||||
}
|
||||
specs_dict = {contract: default_specs for contract in contracts}
|
||||
specs_dict = {}
|
||||
try:
|
||||
host = "api-testnet.bybit.com" if use_testnet else "api.bybit.com"
|
||||
base_url = f"https://{host}/v5/market/instruments-info?category=linear&limit=500"
|
||||
@@ -96,11 +90,7 @@ def fetch_futures_specs(contracts: Iterable[str], use_testnet: bool = True) -> d
|
||||
if not cursor:
|
||||
logger.info("No more pages to fetch; pagination complete")
|
||||
break
|
||||
|
||||
for contract in contracts:
|
||||
if contract not in found_contracts:
|
||||
logger.warning(f"Futures contract {contract} not found in API response, using default specs")
|
||||
|
||||
|
||||
logger.info(f"Returning specs for contracts: {list(specs_dict.keys())}")
|
||||
logger.debug(f"Final specs: {specs_dict}")
|
||||
return specs_dict
|
||||
@@ -150,7 +140,12 @@ class BybitMdProvider(MdProvider):
|
||||
)
|
||||
contract_specs = fetch_futures_specs(contracts, use_testnet=self.use_testnet)
|
||||
sec_list = PySecurityList()
|
||||
|
||||
missing_contracts = list(filter(lambda c: c not in contract_specs, contracts))
|
||||
if missing_contracts:
|
||||
logger.error(
|
||||
"Did not find instrument info for %s" % JsonElement(missing_contracts)
|
||||
)
|
||||
contracts = list(filter(lambda c: c in contract_specs, contracts))
|
||||
for contract in contracts:
|
||||
normalized_contract = normalize_contract_name(contract)
|
||||
asset, quote = normalized_contract.split("_")
|
||||
|
||||
Reference in new issue
Block a user