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

♻️ update capitalcom.py with api waiting time between call #438

Merged
merged 2 commits into from
Apr 8, 2024
Merged

Conversation

mraniki
Copy link
Owner

@mraniki mraniki commented Apr 8, 2024

The maximum request rate is 10 per second per user.
The maximum request rate is 1 per 0.1 seconds per user when opening positions or creating orders

@mraniki mraniki enabled auto-merge April 8, 2024 18:53
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @mraniki - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Docstrings: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@@ -96,6 +97,7 @@ async def get_quote(self, instrument):
instrument = await self.replace_instrument(instrument)
logger.debug("Changed Instrument: {}", instrument)
search_markets = self.client.searching_market(searchTerm=instrument)
await asyncio.sleep(1) # Wait for 1 second
Copy link

Choose a reason for hiding this comment

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

suggestion (performance): Consider removing fixed sleep to improve performance.

Using a fixed sleep could lead to unnecessary delays. If this is for rate-limiting, consider a more dynamic approach based on the API's response.

Suggested change
await asyncio.sleep(1) # Wait for 1 second
response = await self.client.searching_market(searchTerm=instrument)
retry_after = response.headers.get("Retry-After", 1)
await asyncio.sleep(int(retry_after))

Copy link

codecov bot commented Apr 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.62%. Comparing base (2d06ce7) to head (bb9f899).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #438      +/-   ##
==========================================
+ Coverage   71.02%   71.62%   +0.59%     
==========================================
  Files           7        7              
  Lines         428      437       +9     
==========================================
+ Hits          304      313       +9     
  Misses        124      124              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mraniki mraniki merged commit 526918a into main Apr 8, 2024
11 checks passed
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.

1 participant