-
-
Save tg12/aec5519dfafc031b5384fde3210c556a to your computer and use it in GitHub Desktop.
Find out of the Market is open in the respective Time Zone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import pytz | |
import datetime | |
set(pytz.all_timezones_set) | |
# https://gist.github.com/mjrulesamrat/0c1f7de951d3c508fb3a20b4b0b33a98 | |
YEAR_var = 2018 | |
types = { | |
# "Cryptocurrency": "668394", | |
# "Options (Australia 200)": "77976799", | |
# "Weekend Indices": "5371876", | |
# "Indices": "97601", | |
# "Forex": "195235", | |
# "Commodities Metals Energies": "101515", | |
# "Bonds and Moneymarket": "108092", | |
# "ETFs, ETCs & Trackers": "184730", | |
"Shares - UK": ["180500", 'Europe/London'], | |
"Shares - UK International (IOB)": ["97695", 'Europe/London'], | |
"Shares - US (All Sessions)": ["298158", 'America/New_York'], | |
"Shares - US": ["97477", 'America/New_York'], | |
"Shares - Austria": ["114058", 'Europe/Vienna'], | |
"Shares - Belgium": ["114036", 'Europe/Brussels'], | |
"Shares - LSE (UK)": ["172904", 'Europe/London'], | |
"Shares - Finland": ["99514", 'Europe/Helsinki'], | |
"Shares - Canada": ["103185", 'America/Halifax'], | |
"Shares - France": ["113659", 'Europe/Paris'], | |
"Shares - Denmark": ["419769", 'Europe/Copenhagen'], | |
"Shares - Germany": ["97466", 'Europe/Berlin'], | |
"Shares - Greece": ["100437", 'Europe/Athens'], | |
"Shares - Hong Kong": ["105775", 'Asia/Tokyo'], | |
"Shares - Ireland (ISEQ)": ["113665", 'Europe/Dublin'], | |
"Shares - Ireland (LSE)": ["421257", 'Europe/Dublin'], | |
"Shares - Netherlands": ["105509", 'Europe/Amsterdam'], | |
"Shares - Norway": ["99808", 'Europe/Oslo'], | |
"Shares - Portugal": ["99787", 'Europe/Lisbon'], | |
"Shares - Singapore": ["105781", 'Asia/Singapore'], | |
"Shares - South Africa": ["100066", 'Africa/Johannesburg'], | |
"Shares - Sweden": ["113681", 'Europe/Stockholm'], | |
"Shares - Switzerland": ["99814", 'Europe/Zurich']} | |
# "Options (Eu Stocks 50)": "245938", | |
# "Options (France 40)": "188760", | |
# "Options (FTSE)": "122250", | |
# "Options (Germany)": "97612", | |
# "Options (Italy 40)": "188955", | |
# "Options (Spain 35)": "188763", | |
# "Options (Sweden 30)": "319963", | |
# "Options (US 500)": "267039", | |
# "Options (Wall St)": "122505", | |
# "Options on FX Majors": "255072", | |
# "Options on Metals, Energies": "195913"} | |
# | |
market_close_tm = "16:30" | |
market_open_tm = "08:30" | |
def is_between(time, time_range): | |
if time_range[1] < time_range[0]: | |
return time >= time_range[0] or time <= time_range[1] | |
return time_range[0] <= time <= time_range[1] | |
for t in types.keys(): | |
id, time_zone = types[t] | |
print ("#######################") | |
print(time_zone) | |
tz = pytz.timezone(time_zone) | |
now_time = datetime.datetime.now(tz=tz).strftime("%H:%M") | |
print(now_time) | |
if is_between(str(now_time), (str(market_close_tm), str(market_open_tm))): | |
print("Market Closed") | |
else: | |
print("Market Likely Open") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment