Skip to content
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

feat: remove redis for exchange position tracking #398

Merged
merged 10 commits into from
Aug 10, 2023
Merged

Conversation

bodymindarts
Copy link
Member

No description provided.

@thevaibhav-dixit thevaibhav-dixit force-pushed the remove-redis-wip branch 4 times, most recently from d2ae2fe to c8e8741 Compare August 5, 2023 19:51
.exchange_position_account_balance(exchange_position_id)
.await?
.map(|b| b.settled())
.unwrap_or(rust_decimal::Decimal::ZERO);
Copy link
Contributor

@thevaibhav-dixit thevaibhav-dixit Aug 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we return an error here if the option is None or does the unwrap_or pattern works fine?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine

&self,
exchange_position_id: impl Into<LedgerAccountId> + std::fmt::Debug,
) -> Result<Option<AccountBalance>, LedgerError> {
self.get_ledger_account_balance(HEDGING_JOURNAL_ID, exchange_position_id, self.usd)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you rename it to EXCHANGE_POSITION_JOURNAL_ID

.await
}

pub async fn hedge_position_omnibus_account_balance(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistent use of exchange_position

@@ -10,7 +10,7 @@ mod constants;
mod error;
mod templates;

use constants::*;
pub use constants::*;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these public?

@@ -67,6 +72,84 @@ impl Ledger {
}
}

#[instrument(name = "ledger.adjust_exchange_position", skip(self, tx))]
pub async fn adjust_exchange_position(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't see why this is pub.

.exchange_position_account_balance(exchange_position_id)
.await?
.map(|b| b.settled())
.unwrap_or(rust_decimal::Decimal::ZERO);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine

.map(|b| b.settled())
.unwrap_or(rust_decimal::Decimal::ZERO);
let diff = current_balance * CENTS_PER_USD + usd_cents_amount;
if diff < rust_decimal::Decimal::ZERO {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use rust_decimal::Decimal at the top?

.map(|b| b.settled())
.unwrap_or(Decimal::ZERO);

ledger
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be exposed. Expose adjust_okex_position like in the calling code in poll_okex

.unwrap()
.settled();
assert_eq!(
balance_after_second_adjustment - balance_after_first_adjustment,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this assert. You are executing the same template twice and only asserting the effect of the second application. Wouldn't it be better to apply each template once and assert balance_after_second_adjustment - initial_balance - that way both templates must have worked.

@bodymindarts bodymindarts changed the title wip feat: remove redis for exchange position tracking Aug 10, 2023
@bodymindarts bodymindarts marked this pull request as ready for review August 10, 2023 08:33
@bodymindarts bodymindarts merged commit 33e4f22 into main Aug 10, 2023
@bodymindarts bodymindarts deleted the remove-redis-wip branch August 10, 2023 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants