def __init__(self, root): super().__init__() self.tk_root = root self.close_button = None # self.surface_chart_button = None # self.line_chart_button = None # self.strike_chart_button = None self.delete_option_button = None self.status_label = None self.plot_frame = None self.symbol_var = tk.StringVar(self) self.expiration_var = tk.StringVar(self) self.strike_var = tk.StringVar(self) self.is_date_filter_on = tk.IntVar(value=0) self.start_date = None self.end_date = None self.shadow_expiration = dict() self.popup_symbol_menu = None self.popup_expiration_menu = None self.popup_strike_menu = None self.start_cal = None self.end_cal = None self.status_var = tk.StringVar(self) self.bid_extrinsic_value = tk.IntVar(self) self.init_ui() arg_parser = argparse.ArgumentParser() arg_parser.add_argument('-d', '--db', action='store', type=str, help="Database to use") args = arg_parser.parse_args() database = args.db self.clear_symbol_menu() self.clear_expiration_menu() self.clear_strike_menu() self.toggle_date_filter() self.update_chart_button_enable() if database is not None: self.options_db = FinanceDB(db_name_schema=database) else: self.options_db = FinanceDB() self.options_db.initialize() self.get_symbols() self.extrinsic_value_radio = None self.bid_value_radio = None
def __init__(self, root): super().__init__() self.tk_root = root self.close_button = None self.status_label = None self.call_screener_frame = None self.popup_expiration_menu = None self.expiration_var = tk.StringVar(self) self.otm_strike_var = tk.StringVar(self) self.otm_list = ["15%", "5%", "ATM", "10%", "20%"] self.request_queue = Queue() self.response_queue = Queue() self.status_var = tk.StringVar(self) self.init_ui() self.logger = self.create_logger() # self.web = FinanceWeb(self.logger) self.options_db = FinanceDB() self.options_db.initialize() self.companies = OptionsScreenerWatch() self.init_table() self.clear_expiration_menu() self.clear_otm_strike_menu() config = OptionsConfiguration() look_a_heads = ( config.get_configuration())["screener_look_ahead_expirations"] expiration_list = self.get_expirations(look_a_heads) self.update_expiration(expiration_list) self.expiration_var.set(expiration_list[0]) self.update_otm_strike(self.otm_list) self.otm_strike_var.set(self.otm_list[0]) self.temp() self.options_fetch = OptionsFetch(self.request_queue, self.response_queue, self.logger) self.options_fetch.start() self.update_options() self.tk_root.protocol("WM_DELETE_WINDOW", self.quit_app)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Aug 7 17:04:10 2017 @author: fredoleary """ from platform import python_version from BiasWeight import BiasWeights from DbFinance import FinanceDB from CompanyList import CompanyWatch if __name__ == "__main__": print('Python', python_version()) COMPANIES = CompanyWatch() FINANCE = FinanceDB(COMPANIES.get_companies()) FINANCE.initialize() BIAS = BiasWeights(FINANCE) BIAS.update_weights()
from DbFinance import FinanceDB from datetime import datetime stock_data = [{ "symbol": "INTC", "description": "Intel Corporation" }, { "symbol": "LITE", "description": "Lumentum Corporation" }] if __name__ == "__main__": print('Python', python_version()) now = datetime.now() ts = now.timestamp() newNow = datetime.fromtimestamp(ts) symbol = "LITE" finance = FinanceDB(stock_data) finance.initialize() quotes = YahooFinanceNews.get_quotes_for_stock(symbol) print(quotes) finance.add_quotes(symbol, quotes) quotes = finance.get_quotes(symbol) print(quotes) # news = YahooFinanceNews.get_news_for_stock("LITE") # finance.add_news( "LITE", news) # print( news)
def process_options(): logger = create_logger() database = "stock_options" configuration = OptionsConfiguration() update_rate = (configuration.get_configuration())["collector_update_rate_in_seconds"] try: parser = argparse.ArgumentParser() parser.add_argument("-r", "--repeat", help="Continuous collection - Set by update rate", action="store_true") parser.add_argument('-u', '--update', action='store', type=int, help="Update rate in seconds") parser.add_argument('-d', '--db', action='store', type=str, help="Database to use") parser.add_argument('-e', '--expire', action='store', type=str, help="expiration (YYYY-MM-DD)") parser.add_argument('-s', '--symbol', action='store', type=str, help="symbol (APPL") parser.add_argument('-f', '--force', help="symbol force reading", action="store_true") args = parser.parse_args() repeat = args.repeat if args.update is not None: update_rate = args.update if args.db is not None: database = args.db symbol = args.symbol expiration = args.expire force_reading = args.force except Exception as err: print(err) sys.exit(2) print("Repeat: {0}, database: {1}, update rate: {2}".format(repeat, database, update_rate)) web = Utilities.get_options_API(logger) logger.info("Application started") companies = OptionsWatch() options_db = FinanceDB(companies.options_list, logger, database) options_db.initialize() look_a_heads = (configuration.get_configuration())["collector_look_ahead_expirations"] repeat_get_quotes = True while repeat_get_quotes: start_time = Utilities.convert_time_str_to_datetime( (configuration.get_configuration())['collector_start_time_pst'], 'US/Pacific') end_time = Utilities.convert_time_str_to_datetime( (configuration.get_configuration())['collector_end_time_pst'], 'US/Pacific') now = datetime.datetime.now() if (start_time.time() <= now.time() <= end_time.time()) or force_reading is True: if symbol is not None: symbols = [{"symbol":symbol}] else: symbols = companies.get_companies() for _symbol in symbols: if expiration is not None: options = [web.get_options_for_symbol_and_expiration(_symbol["symbol"], expiration)] else: options = web.get_options_for_symbol(_symbol["symbol"], look_a_heads=look_a_heads) if len(options) > 0: for option in options: logger.info("{0}(Before filter). Expires {1}. {2} Calls, {3} Puts".format( option["ticker"], option['expire_date'].strftime("%Y-%m-%d"), len(option["options_chain"]["calls"]), len(option["options_chain"]["puts"]))) if len(option["options_chain"]["puts"]) > 0 and len(option["options_chain"]["calls"]) > 0: Utilities.filter_by_date(option, 10) Utilities.filter_by_at_the_money(option, 30, 50) Utilities.decimate_options(option, 50) logger.info("{0}(After filter). Expires {1}. {2} Calls, {3} Puts".format( option["ticker"], option['expire_date'].strftime("%Y-%m-%d"), len(option["options_chain"]["calls"]), len(option["options_chain"]["puts"]))) options_db.add_option_quote(options) else: logger.info("Time is outside options hours. No readings taken") if repeat: logger.info("Sleeping for {delay} seconds".format(delay=update_rate)) time.sleep(update_rate) else: repeat_get_quotes = False