Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clients/spot/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "binance-sdk-spot"
version = "6.3.0"
version = "6.3.0+fork.2"
description = "Official Binance Spot SDK - A lightweight library that provides a convenient interface to Binance's Spot REST API, WebSocket API and WebSocket Streams."
authors = ["Binance"]
license = "MIT"
Expand All @@ -20,7 +20,7 @@ black = "^25.1.0"
ruff = "^0.12.0"
pycryptodome = "^3.17"
aiohttp = "^3.9"
binance-common = "3.4.1"
binance-common = "3.4.1+fork.2"
pytest = { version = ">=6.2.5", optional = true }

[tool.poetry.extras]
Expand Down
35 changes: 8 additions & 27 deletions clients/spot/src/binance_sdk_spot/rest_api/models/asset_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def __init__(self, *args, **kwargs) -> None:
def is_oneof_model(cls) -> bool:
return True

@classmethod
def model_validate(cls, obj: dict) -> Self:
"""Validate and deserialize a dict into the appropriate oneOf model."""
return cls.from_dict(obj)

@classmethod
def from_dict(cls, parsed) -> Self:
"""Returns the object represented by the json string"""
Expand All @@ -85,33 +90,9 @@ def from_dict(cls, parsed) -> Self:
instance.actual_instance = target_cls.from_dict(parsed)
return instance

instance = cls.model_construct()
error_messages = []
match = 0
is_list = isinstance(parsed, list)

for subcls in ["MaxAssetFilter"]:
if is_list == subcls.is_array():
try:
instance.actual_instance = subcls.from_dict(parsed)
match += 1
except (ValidationError, ValueError) as e:
error_messages.append(str(e))

if match > 1:
# more than 1 match
raise ValueError(
"Multiple matches found when deserializing the JSON string into AssetFilters with oneOf schemas: MaxAssetFilter. Details: "
+ ", ".join(error_messages)
)
elif match == 0:
# no match
raise ValueError(
"No match found when deserializing the JSON string into AssetFilters with oneOf schemas: MaxAssetFilter. Details: "
+ ", ".join(error_messages)
)
else:
return instance
raise ValueError(
f"Unable to deserialize into AssetFilters: 'filterType' field missing or unrecognized. Data: {parsed}"
)

def to_json(self) -> str:
"""Returns the JSON representation of the actual instance"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def __init__(self, *args, **kwargs) -> None:
def is_oneof_model(cls) -> bool:
return True

@classmethod
def model_validate(cls, obj: dict) -> Self:
"""Validate and deserialize a dict into the appropriate oneOf model."""
return cls.from_dict(obj)

@classmethod
def from_dict(cls, parsed) -> Self:
"""Returns the object represented by the json string"""
Expand All @@ -124,38 +129,9 @@ def from_dict(cls, parsed) -> Self:
instance.actual_instance = target_cls.from_dict(parsed)
return instance

instance = cls.model_construct()
error_messages = []
match = 0
is_list = isinstance(parsed, list)

for subcls in [
"ExchangeMaxNumAlgoOrdersFilter",
"ExchangeMaxNumIcebergOrdersFilter",
"ExchangeMaxNumOrderListsFilter",
"ExchangeMaxNumOrdersFilter",
]:
if is_list == subcls.is_array():
try:
instance.actual_instance = subcls.from_dict(parsed)
match += 1
except (ValidationError, ValueError) as e:
error_messages.append(str(e))

if match > 1:
# more than 1 match
raise ValueError(
"Multiple matches found when deserializing the JSON string into ExchangeFilters with oneOf schemas: ExchangeMaxNumAlgoOrdersFilter, ExchangeMaxNumIcebergOrdersFilter, ExchangeMaxNumOrderListsFilter, ExchangeMaxNumOrdersFilter. Details: "
+ ", ".join(error_messages)
)
elif match == 0:
# no match
raise ValueError(
"No match found when deserializing the JSON string into ExchangeFilters with oneOf schemas: ExchangeMaxNumAlgoOrdersFilter, ExchangeMaxNumIcebergOrdersFilter, ExchangeMaxNumOrderListsFilter, ExchangeMaxNumOrdersFilter. Details: "
+ ", ".join(error_messages)
)
else:
return instance
raise ValueError(
f"Unable to deserialize into ExchangeFilters: 'filterType' field missing or unrecognized. Data: {parsed}"
)

def to_json(self) -> str:
"""Returns the JSON representation of the actual instance"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of ExchangeInfoResponse from a JSON string"""
return cls.from_dict(json.loads(json_str))

@classmethod
def model_validate(cls, obj: Any) -> Self:
"""Validate and deserialize using custom from_dict logic."""
# If obj is a dict, use from_dict to handle nested oneOf models properly
if isinstance(obj, dict):
return cls.from_dict(obj)
# Otherwise use Pydantic's default validation
return super().model_validate(obj)

def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.

Expand Down Expand Up @@ -134,9 +143,10 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
return None

if not isinstance(obj, dict):
return cls.model_validate(obj)
return BaseModel.model_validate.__func__(cls, obj)

_obj = cls.model_validate(
_obj = BaseModel.model_validate.__func__(
cls,
{
"timezone": obj.get("timezone"),
"serverTime": obj.get("serverTime"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of ExchangeInfoResponseSymbolsInner from a JSON string"""
return cls.from_dict(json.loads(json_str))

@classmethod
def model_validate(cls, obj: Any) -> Self:
"""Validate and deserialize using custom from_dict logic."""
# If obj is a dict, use from_dict to handle nested oneOf models properly
if isinstance(obj, dict):
return cls.from_dict(obj)
# Otherwise use Pydantic's default validation
return super().model_validate(obj)

def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.

Expand Down Expand Up @@ -182,9 +191,10 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
return None

if not isinstance(obj, dict):
return cls.model_validate(obj)
return BaseModel.model_validate.__func__(cls, obj)

_obj = cls.model_validate(
_obj = BaseModel.model_validate.__func__(
cls,
{
"symbol": obj.get("symbol"),
"status": obj.get("status"),
Expand Down
14 changes: 12 additions & 2 deletions clients/spot/src/binance_sdk_spot/rest_api/models/rate_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of RateLimits from a JSON string"""
return cls.from_dict(json.loads(json_str))

@classmethod
def model_validate(cls, obj: Any) -> Self:
"""Validate and deserialize using custom from_dict logic."""
# If obj is a dict, use from_dict to handle nested oneOf models properly
if isinstance(obj, dict):
return cls.from_dict(obj)
# Otherwise use Pydantic's default validation
return super().model_validate(obj)

def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.

Expand Down Expand Up @@ -106,9 +115,10 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
return None

if not isinstance(obj, dict):
return cls.model_validate(obj)
return BaseModel.model_validate.__func__(cls, obj)

_obj = cls.model_validate(
_obj = BaseModel.model_validate.__func__(
cls,
{
"rateLimitType": obj.get("rateLimitType"),
"interval": obj.get("interval"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ def __init__(self, *args, **kwargs) -> None:
def is_oneof_model(cls) -> bool:
return True

@classmethod
def model_validate(cls, obj: dict) -> Self:
"""Validate and deserialize a dict into the appropriate oneOf model."""
return cls.from_dict(obj)

@classmethod
def from_dict(cls, parsed) -> Self:
"""Returns the object represented by the json string"""
Expand Down Expand Up @@ -210,50 +215,9 @@ def from_dict(cls, parsed) -> Self:
instance.actual_instance = target_cls.from_dict(parsed)
return instance

instance = cls.model_construct()
error_messages = []
match = 0
is_list = isinstance(parsed, list)

for subcls in [
"IcebergPartsFilter",
"LotSizeFilter",
"MarketLotSizeFilter",
"MaxNumAlgoOrdersFilter",
"MaxNumIcebergOrdersFilter",
"MaxNumOrderAmendsFilter",
"MaxNumOrderListsFilter",
"MaxNumOrdersFilter",
"MaxPositionFilter",
"MinNotionalFilter",
"NotionalFilter",
"PercentPriceBySideFilter",
"PercentPriceFilter",
"PriceFilter",
"TPlusSellFilter",
"TrailingDeltaFilter",
]:
if is_list == subcls.is_array():
try:
instance.actual_instance = subcls.from_dict(parsed)
match += 1
except (ValidationError, ValueError) as e:
error_messages.append(str(e))

if match > 1:
# more than 1 match
raise ValueError(
"Multiple matches found when deserializing the JSON string into SymbolFilters with oneOf schemas: IcebergPartsFilter, LotSizeFilter, MarketLotSizeFilter, MaxNumAlgoOrdersFilter, MaxNumIcebergOrdersFilter, MaxNumOrderAmendsFilter, MaxNumOrderListsFilter, MaxNumOrdersFilter, MaxPositionFilter, MinNotionalFilter, NotionalFilter, PercentPriceBySideFilter, PercentPriceFilter, PriceFilter, TPlusSellFilter, TrailingDeltaFilter. Details: "
+ ", ".join(error_messages)
)
elif match == 0:
# no match
raise ValueError(
"No match found when deserializing the JSON string into SymbolFilters with oneOf schemas: IcebergPartsFilter, LotSizeFilter, MarketLotSizeFilter, MaxNumAlgoOrdersFilter, MaxNumIcebergOrdersFilter, MaxNumOrderAmendsFilter, MaxNumOrderListsFilter, MaxNumOrdersFilter, MaxPositionFilter, MinNotionalFilter, NotionalFilter, PercentPriceBySideFilter, PercentPriceFilter, PriceFilter, TPlusSellFilter, TrailingDeltaFilter. Details: "
+ ", ".join(error_messages)
)
else:
return instance
raise ValueError(
f"Unable to deserialize into SymbolFilters: 'filterType' field missing or unrecognized. Data: {parsed}"
)

def to_json(self) -> str:
"""Returns the JSON representation of the actual instance"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,37 +67,32 @@ def __init__(self, *args, **kwargs) -> None:
def is_oneof_model(cls) -> bool:
return True

@classmethod
def model_validate(cls, obj: dict) -> Self:
"""Validate and deserialize a dict into the appropriate oneOf model."""
return cls.from_dict(obj)

@classmethod
def from_dict(cls, parsed) -> Self:
"""Returns the object represented by the json string"""
instance = cls.model_construct()
error_messages = []
match = 0

is_list = isinstance(parsed, list)

# deserialize data into MaxAssetFilter
if is_list == MaxAssetFilter.is_array():
try:
instance.actual_instance = MaxAssetFilter.from_dict(parsed)
match += 1
except (ValidationError, ValueError) as e:
error_messages.append(str(e))

if match > 1:
# more than 1 match
raise ValueError(
"Multiple matches found when deserializing the JSON string into AssetFilters with oneOf schemas: MaxAssetFilter. Details: "
+ ", ".join(error_messages)
)
elif match == 0:
# no match
raise ValueError(
"No match found when deserializing the JSON string into AssetFilters with oneOf schemas: MaxAssetFilter. Details: "
+ ", ".join(error_messages)
)
else:
return instance
if parsed is None:
return None

if isinstance(parsed, dict) and "filterType" in parsed:
filter_type_map = {"MAX_ASSET": MaxAssetFilter}

ft = parsed.get("filterType")
target_cls = filter_type_map.get(ft)

if target_cls is not None:
# Deserialize directly into the proper schema
instance = cls.model_construct()
instance.actual_instance = target_cls.from_dict(parsed)
return instance

raise ValueError(
f"Unable to deserialize into AssetFilters: 'filterType' field missing or unrecognized. Data: {parsed}"
)

def to_json(self) -> str:
"""Returns the JSON representation of the actual instance"""
Expand Down
Loading