-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add currency attributes to ibetStraightBond #552
Conversation
face_value_currency: str | ||
interest_rate: float | ||
interest_payment_date: List[str] | ||
interest_payment_currency: str | ||
redemption_date: str | ||
redemption_value: int | ||
redemption_value_currency: str | ||
base_fx_rate: float |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added four new items to the Bond contract.
- face_value_currency
- interest_payment_currency
- redemption_value_currency
- base_fx_rate
self.face_value_currency = ContractUtils.call_function( | ||
contract, "faceValueCurrency", (), "" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value of face_value_currency
is "".
self.interest_payment_currency = ContractUtils.call_function( | ||
contract, "interestPaymentCurrency", (), "" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value of interest_payment_currency
is "".
self.redemption_value_currency = ContractUtils.call_function( | ||
contract, "redemptionValueCurrency", (), "" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value of redemption_value_currency
is "".
try: | ||
_raw_base_fx_rate = ContractUtils.call_function( | ||
contract, "baseFXRate", (), "" | ||
) | ||
if _raw_base_fx_rate is not None and _raw_base_fx_rate != "": | ||
self.base_fx_rate = float(_raw_base_fx_rate) | ||
else: | ||
self.base_fx_rate = 0.0 | ||
except ValueError: | ||
self.base_fx_rate = 0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value of base_fx_rate
is 0.0.
Error handling is performed when invalid data that cannot be converted to float is set.
|
||
if data.base_fx_rate is not None: | ||
tx = contract.functions.setBaseFXRate( | ||
str(data.base_fx_rate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert the input value to str and set it.
@@ -132,6 +132,7 @@ class RetrieveLedgerHistoryResponse(BaseModel): | |||
|
|||
created: str | |||
token_name: str | |||
currency: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value is "".
Although the item itself does not exist in the data created with the old version, the default value (i.e. "") is returned as the API return value.
@field_validator("base_fx_rate") | ||
@classmethod | ||
def base_fx_rate_6_decimal_places(cls, v): | ||
if v is not None: | ||
float_data = float(v * 10**6) | ||
int_data = int(v * 10**6) | ||
if not math.isclose(int_data, float_data): | ||
raise ValueError( | ||
"base_fx_rate must be less than or equal to six decimal places" | ||
) | ||
return v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The number of digits after the decimal point is 6.
def upgrade(): | ||
# Delete all `token_cache` data | ||
op.get_bind().execute(delete(TokenCache)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If valid token cache data exists, the old format data will be returned, so I decided to delete it all at once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
close #546