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

Feature/market sessions #215

Merged
merged 14 commits into from
Feb 17, 2025
Merged

Conversation

JBlohm
Copy link
Contributor

@JBlohm JBlohm commented Feb 9, 2025

Description

I needed some market-session related functions to get the market opening date and time for the next market session, as well as market holidays and the current state of the market (Open/Closed) per market.

Added a module market_sessions.py with functions: sync & async

get_market_time_sessions(session: Session, instrument_collections: list[str]) -> list[MarketTimeSessionsCurrent]
Retrieves market metrics for the given symbols. The instrument collection to get market sessions for has available values : Equity, CME, CFE, Smalls.

Example:
import tastytrade.market_sessions as Market
mt = Market.get_market_time_sessions(session=session, instrument_collections=['Equity','CME])

get_market_time_equity_holidays(session: Session) -> MarketCalendarData
Retrieves market calendar for half days and holidays.

get_market_state(session: Session, instrument_collections: list[str]) -> list
Retrieves market state (Open/Closed)

Example:
s = Market.get_market_state(session=session, instrument_collections=['Equity','CME','CFE','Smalls'])
Returns ['Closed', 'Closed', 'Closed', 'Closed'] when all markets are closed.

Related issue(s)

@Graeme22 : Can you please review and run the tests?

My tests worked as:

from tastytrade import Session
import tastytrade.market_sessions as Market

session = Session('username', 'password') # Your own TT username, password

mt = Market.get_market_time_sessions(session=session, instrument_collections=['Equity','CME'])
print("Market time sessions:")
print(mt)

s = Market.get_market_state(session=session, instrument_collections=['Equity','CME','CFE','Smalls'])
print(s)

calendar_data = Market.get_market_time_equity_holidays(session=session)
print("Market half days")
print(calendar_data.market_half_days)    # list of datetime.date objects
print("Market holidays")
print(calendar_data.market_holidays)     # list of datetime.date objects

session.destroy()

Pre-merge checklist

  • Code formatted correctly (check with make lint)
  • Code implemented for both sync and async
  • Passing tests locally (check with make test, make sure you have TT_USERNAME, TT_PASSWORD, and TT_ACCOUNT environment variables set)
  • New tests added (if applicable)

Please note that, in order to pass the tests, you'll need to set up your Tastytrade credentials as repository secrets on your local fork. Read more at CONTRIBUTING.md.

Copy link
Contributor

@Graeme22 Graeme22 left a comment

Choose a reason for hiding this comment

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

Hey thanks for this! There's a few tweaks I'd like to suggest for naming so this is a bit easier and more intuitive for users.

@JBlohm
Copy link
Contributor Author

JBlohm commented Feb 14, 2025 via email

@Graeme22
Copy link
Contributor

Hi @JBlohm thanks for the contribution! I ended up simplifying the code a bit and it now fits a bit better with the rest of the SDK in my opinion. As a last step before merging this, could you add a docs section for this? In a file named something like docs/market-sessions.rst, all you'd have to do other than that is add the line market-sessions to the first toctree.

@JBlohm
Copy link
Contributor Author

JBlohm commented Feb 16, 2025 via email

@Graeme22
Copy link
Contributor

Thanks a lot Graeme, this looks good. My day Job is IT Project manager, I just try to keep up with Python a bit for myself :-)
So, please always be prepared to clean up what I produce. But I will try to do my best to work as far ahead as I can and learn from what I see.

Docs section, yes, give me a few days. Will do.

Appreciate it!

@JBlohm
Copy link
Contributor Author

JBlohm commented Feb 16, 2025 via email

@JBlohm
Copy link
Contributor Author

JBlohm commented Feb 17, 2025 via email

@Graeme22
Copy link
Contributor

Had to fix formatting of the .rst file again. I currently do not have a preview in my VSCode for this, Can you make a recommendation for a good extension that can be used for previewing .rst files?

I don't use VS Code but you can build the docs locally by running make docs assuming you're not on Windows. I'll finish up the rest though, thanks again!

@Graeme22 Graeme22 merged commit c862105 into tastyware:master Feb 17, 2025
1 check failed
@JBlohm JBlohm deleted the feature/market_sessions branch February 17, 2025 16:47
@JBlohm
Copy link
Contributor Author

JBlohm commented Feb 17, 2025 via email

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