Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Conversation

sourcery-ai[bot]
Copy link
Contributor

@sourcery-ai sourcery-ai bot commented Mar 10, 2022

Pull Request #142 refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the Wide-Spreads branch, then run:

git fetch origin sourcery/Wide-Spreads
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from pattertj March 10, 2022 13:20
@sourcery-ai sourcery-ai bot force-pushed the sourcery/Wide-Spreads branch 2 times, most recently from 618ab0a to 2ef32ab Compare March 14, 2022 19:48
@sourcery-ai sourcery-ai bot force-pushed the sourcery/Wide-Spreads branch from 2ef32ab to 5b2bb2f Compare March 14, 2022 20:02
Comment on lines -103 to +105
"Failed to get Account {}. Attempt #{}".format(
self.account_number, attempt
)
f"Failed to get Account {self.account_number}. Attempt #{attempt}"
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function TdaBroker.get_account refactored with the following changes:

Comment on lines -131 to +130
logger.exception(
"Failed to read order {}.".format(str(request.orderid))
)
logger.exception(f"Failed to read order {str(request.orderid)}.")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function TdaBroker.get_order refactored with the following changes:

Comment on lines -164 to +161
logger.exception("Chain Validation Failed. {}".format(optionchainobj))
logger.exception(f"Chain Validation Failed. {optionchainobj}")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function TdaBroker.get_option_chain refactored with the following changes:

Comment on lines -209 to +204
logger.exception(
"Failed to get quotes. Attempt #{}".format(attempt),
)
logger.exception(f"Failed to get quotes. Attempt #{attempt}")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function TdaBroker.get_quote refactored with the following changes:

Comment on lines -255 to +250
"Failed to get market hours for {} on {}. Attempt #{}".format(
markets, request.datetime, attempt
),
f"Failed to get market hours for {markets} on {request.datetime}. Attempt #{attempt}"
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function TdaBroker.get_market_hours refactored with the following changes:

Comment on lines -495 to +497
self.strategy_id, int(order_id)
self.strategy_id, order_id
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function SingleByDeltaStrategy.cancel_order refactored with the following changes:

Comment on lines -776 to +777
best_quantity = int(0)
best_quantity = 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function SingleByDeltaStrategy.get_best_strike_and_quantity refactored with the following changes:

# Check if should be sleeping
if now < self.sleepuntil:
logger.debug("Markets Closed. Sleeping until {}".format(self.sleepuntil))
logger.debug(f"Markets Closed. Sleeping until {self.sleepuntil}")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function SpreadsByDeltaStrategy.process_strategy refactored with the following changes:

Comment on lines -111 to +110
"Markets are closed until {}. Sleeping until {}".format(
nextmarketsession.start,
self.sleepuntil,
)
f"Markets are closed until {nextmarketsession.start}. Sleeping until {self.sleepuntil}"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function SpreadsByDeltaStrategy.process_pre_market refactored with the following changes:

Comment on lines -488 to 486
logger.info(
"Short Strike: {} Long Strike: {} BuyingPower: {} LiquidationValue: {} MaxLoss: {} BalanceToRisk: {} RemainingBalance: {} TradeSize: {} ".format(
shortstrike,
longstrike,
account_balance.buyingpower,
account_balance.liquidationvalue,
max_loss,
balance_to_risk,
remainingbalance,
trade_size,
)
f"Short Strike: {shortstrike} Long Strike: {longstrike} BuyingPower: {account_balance.buyingpower} LiquidationValue: {account_balance.liquidationvalue} MaxLoss: {max_loss} BalanceToRisk: {balance_to_risk} RemainingBalance: {remainingbalance} TradeSize: {trade_size} "
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function SpreadsByDeltaStrategy.calculate_order_quantity refactored with the following changes:

@sourcery-ai
Copy link
Contributor Author

sourcery-ai bot commented Mar 14, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.23%.

Quality metrics Before After Change
Complexity 5.96 ⭐ 5.96 ⭐ 0.00
Method Length 71.94 🙂 72.25 🙂 0.31 👎
Working memory 7.92 🙂 8.03 🙂 0.11 👎
Quality 68.46% 🙂 68.23% 🙂 -0.23% 👎
Other metrics Before After Change
Lines 2077 2058 -19
Changed files Quality Before Quality After Quality Change
looptrader/basetypes/Broker/tdaBroker.py 70.41% 🙂 70.22% 🙂 -0.19% 👎
looptrader/basetypes/Strategy/singlebydeltastrategy.py 66.10% 🙂 66.11% 🙂 0.01% 👍
looptrader/basetypes/Strategy/spreadsbydeltastrategy.py 69.30% 🙂 68.53% 🙂 -0.77% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
looptrader/basetypes/Strategy/spreadsbydeltastrategy.py SpreadsByDeltaStrategy.build_new_order 9 🙂 186 😞 11 😞 48.84% 😞 Try splitting into smaller methods. Extract out complex expressions
looptrader/basetypes/Strategy/singlebydeltastrategy.py SingleByDeltaStrategy.get_best_strike_and_quantity 9 🙂 110 🙂 16 ⛔ 49.88% 😞 Extract out complex expressions
looptrader/basetypes/Strategy/singlebydeltastrategy.py SingleByDeltaStrategy.place_order 8 ⭐ 168 😞 11 😞 51.37% 🙂 Try splitting into smaller methods. Extract out complex expressions
looptrader/basetypes/Strategy/singlebydeltastrategy.py SingleByDeltaStrategy.get_offsetting_strike 8 ⭐ 133 😞 13 😞 51.76% 🙂 Try splitting into smaller methods. Extract out complex expressions
looptrader/basetypes/Strategy/singlebydeltastrategy.py SingleByDeltaStrategy.process_strategy 9 🙂 139 😞 9 🙂 57.39% 🙂 Try splitting into smaller methods

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@pattertj pattertj merged commit c3fdcf7 into Wide-Spreads Mar 14, 2022
@pattertj pattertj deleted the sourcery/Wide-Spreads branch March 14, 2022 20:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants