def result_stock_data_container_list_changed(self):
        """
        Update the columns and data of the view, of stock data container list changed.
        Additionally, it adds the not already available columns to the MvcModel and fill not available columns with dummy.
        :return: -
        """
        tree = w.Scrolledtreeview1
        tree.delete(*tree.get_children())
        stock_data_container_list = self.model.result_stock_data_container_list.get(
        )

        # sort the list by rank
        newlist = sorted(stock_data_container_list,
                         key=lambda x: x.get_rank(),
                         reverse=True)

        for result_container in newlist:
            try:
                is_updated = self.model.update_column_list(
                    result_container.get_names_and_values().keys())

                if is_updated:
                    init_result_table(self.view.Scrolledtreeview1,
                                      self.model.get_column_list())

                GuiUtils.insert_into_treeview(
                    self.view.Scrolledtreeview1, self.model.get_column_list(),
                    result_container.get_names_and_values(), "Stock")

                # append all COLUMNS to file --> new layout leads to new line with header
                FileUtils.append_text_list_to_file(
                    self.model.get_column_list(),
                    GlobalVariables.get_data_files_path() +
                    "ScreeningResults.csv", True, ",")

                # append VALUES to file
                values = result_container.get_names_and_values().values()
                text = ','.join(str(e) for e in values)
                FileUtils.append_textline_to_file(
                    text,
                    GlobalVariables.get_data_files_path() +
                    "ScreeningResults.csv", True)

            except Exception as e:
                logger.error("Exception: " + str(e) + "\n" +
                             str(traceback.format_exc()))
                continue

        # add a sort functionality for each column, when click on header
        GuiUtils.advanced_sorting(self.view.Scrolledtreeview1,
                                  self.model.get_column_list(), True)

        # add a color for the entries in tree view
        for color in GlobalVariables.get_row_colors().keys():
            tree.tag_configure(
                GlobalVariables.get_row_colors()[color],
                background=GlobalVariables.get_row_colors()[color])
Exemplo n.º 2
0
    def _method_to_execute(self, elm):
        """
        read news from traderfox home page with dpa-afx-compact news
        :param date_time_format: news datetime format
        :param date_file: file for last check date
        :param url: traderfox news page url
        :return: news as list
        """
        from Utils.FileUtils import FileUtils
        all_news = []

        date_time = (str(elm.footer.span.get_text()))  # date and Time
        date_time = date_time.rsplit(' Uhr')[
            0]  # TODO: split because of datetime format

        article_text = (str(elm.h2.get_text(strip=True))
                        )  # h2 --> article head line
        news_text = date_time.replace(',', '.') + ", " + article_text.replace(
            ',', '.')
        # TODO REMOVE THAT
        # THIS IS JUST FOR BACKTESTING NEWS DATA COLLECTION
        FileUtils.append_textline_to_file(
            news_text,
            GlobalVariables.get_data_files_path() + "NewsForBacktesting.txt",
            True)
        all_news.append(news_text)

        prep_news = self.text_analysis.optimize_text_for_german_tagger(
            news_text)
        name_ticker_exchange_target_prize = \
            self.text_analysis.identify_stock_name_and_stock_ticker_and_target_price_from_news_nltk_german_classifier(
                news_text)

        if name_ticker_exchange_target_prize is not None and name_ticker_exchange_target_prize.get_stock_name(
        ) != "":
            container = StockDataContainer(
                name_ticker_exchange_target_prize.get_stock_name(),
                name_ticker_exchange_target_prize.stock_ticker(),
                name_ticker_exchange_target_prize.stock_exchange())

            if container in self.stock_data_container_list:
                idx = self.stock_data_container_list.index(container)
                container_2 = self.stock_data_container_list[idx]
                if isinstance(container_2, StockDataContainer):
                    container = container_2
                    self.stock_data_container_list.remove(container_2)

            news_dec = NewsDataContainerDecorator(
                container,
                name_ticker_exchange_target_prize.stock_target_price(), 0,
                prep_news)

            self.stock_data_container_list.append(news_dec)
Exemplo n.º 3
0
    def test_append_to_file__only_new_entries__all_entries(self):
        filename = GlobalVariables.get_data_files_path(
        ) + "TestData\\NewsForBacktesting.txt"
        text = "25.07.2018 um 08:41, ANALYSE-FLASH: Berenberg hebt Ziel für Adidas auf 207 Euro - 'Hold'"
        self.assertFalse(
            FileUtils.append_textline_to_file(text, filename, True))

        text = str(datetime.now()) + ", Test Eintrag"
        self.assertTrue(FileUtils.append_textline_to_file(
            text, filename, True))

        text = "16.07.2018 um 8:51, Test Eintrag"
        self.assertTrue(
            FileUtils.append_textline_to_file(text, filename, False))
Exemplo n.º 4
0
    def _save_current_order(self, order_id, stock_ticker, order_type='', action='', quantity=0,
                            limit_price=0, security_type='STK', exchange='SMART', currency='USD'):
        """
        Save the current order into file.
        :param order_id: order id by interactive broker, must be unique
        :param stock_ticker: stock ticker
        :param order_type: oder type , ex: LMT for limit orders
        :param action: BUY / SELL
        :param quantity: number of stocks to order
        :param limit_price: limit price to buy or sell
        :param security_type: STK for stocks
        :param exchange: echange to trade, SMART
        :param currency: USD / EUR
        :return: nothing
        """
        FileUtils.check_file_exists_or_create(self.file_path, GlobalVariables.get_order_file_header())

        text_line = str(datetime.now()) + "," + str(stock_ticker) + "," + str(order_id) + "," + str(
            order_type) + "," + str(action) + "," + str(quantity) + "," + str(limit_price) + "," + str(
            security_type) + "," + str(exchange) + "," + str(currency)
        print(text_line)
        FileUtils.append_textline_to_file(text_line, self.file_path, False)