Skip to content

Commit

Permalink
fix some optional fields
Browse files Browse the repository at this point in the history
  • Loading branch information
hzheng committed May 22, 2024
1 parent bada574 commit 5fedc1b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyschwab"
version = "0.0.1a2"
version = "0.0.1a3"
description = "A Python library for the Schwab trading API"
authors = ["Hui Zheng <[email protected]>"]
license = "MIT"
Expand Down
16 changes: 10 additions & 6 deletions pyschwab/trading_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,26 @@ class Deliverable:

@classmethod
def from_dict(cls, data: Dict[str, Any]) -> 'Deliverable':
if data is None:
return None
converted_data = {camel_to_snake(key): value for key, value in data.items()}
return cls(**converted_data)


@dataclass
class OptionDeliverable:
root_symbol: str
strike_percent: int
deliverable_number: int
deliverable_units: float
deliverable: Deliverable
root_symbol: str = None
symbol: str = None
strike_percent: int = None
deliverable_number: int = None

@classmethod
def from_dict(cls, data: Dict[str, Any]) -> 'OptionDeliverable':
converted_data = {camel_to_snake(key): value for key, value in data.items()}
converted_data['deliverable'] = Deliverable.from_dict(converted_data['deliverable'])
deliverable = converted_data.get('deliverable', None)
converted_data['deliverable'] = Deliverable.from_dict(deliverable)
return cls(**converted_data)


Expand Down Expand Up @@ -417,13 +421,13 @@ class Transaction:
time: datetime
type: str
status: str
position_id: int
net_amount: float
account_number: str
sub_account: str
transfer_items: List[TransferItem]
user: User = None
order_id: int = 0
order_id: int = None
position_id: int = None
trade_date: datetime = None
settlement_date: datetime = None
description: str = None
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def test_authentication_and_trading_data(app_config, logging_config):
assert transaction.time is not None, "Expected time to be fetched"
assert transaction.type is not None, "Expected transaction type to be fetched"
assert transaction.status is not None, "Expected status to be fetched"
assert transaction.position_id is not None, "Expected position id to be fetched"
# assert transaction.position_id is not None, "Expected position id to be fetched"
assert transaction.net_amount is not None, "Expected net amount to be fetched"
assert transaction.account_number is not None, "Expected account number to be fetched"
assert transaction.sub_account is not None, "Expected sub account to be fetched"
Expand Down

0 comments on commit 5fedc1b

Please sign in to comment.