Пример #1
0
    def execute(self):

        # Cancel existing orders
        self.__orders.cancel_opened_orders()

        # Liquidate position if it exists
        self.liquidate_position()

        # Wait for market to open
        t = Thread(target=self.__market.await_market_open)
        t.start()
        t.join()
        print("[Market Opened]")

        # Setup file
        file = open('temp_files/{}.csv'.format(self.symbol), 'w')
        file.write('Date,Close,buy_signal,sell_signal,SMA,STD,Upper,Lower\n')
        file.close()

        # Run the web socket
        t_socket = Thread(target=self.ws.connect_socket)
        t_socket.start()

        # Run the plot's process
        self.p.start()

        # Wait for thread to finish work
        t_socket.join()

        # Delete file
        file_manager.delete_file('SPY.csv'.format(self.symbol), True)
Пример #2
0
    def ws_close(self, ws):
        self.ws.on_close(ws)

        # Delete csv file
        file_manager.delete_file('temp_files/{}.csv'.format(self.symbol))

        # Close plot's process if alive
        if self.p is not None:
            self.p.terminate()
            self.p.join()
Пример #3
0
    def ws_close(self, ws):
        self.ws.on_close(ws)

        # Delete csv file
        file_manager.delete_file('temp_files/{}.csv'.format(self.symbol))

        # Terminate process if still running
        if self.p is not None:
            self.p.terminate()
            self.p.join()
Пример #4
0
    def execute(self):

        if self.error:
            # Delete csv file
            file_manager.delete_file('temp_files/{}.csv'.format(self.symbol))
            return

        if self.mode == 'active':
            # Cancel existing orders
            self.__orders.cancel_opened_orders()

            # Liquidate position if it exists
            self.liquidate_position()

            # Wait for market to open
            t = Thread(target=self.__market.await_market_open)
            t.start()
            t.join()
            print("[Market Opened]")

            # Retrieve historical data about the asset
            self.retrieve_data()

            # Calculate metrics
            self.pre_calculate(self.df)

            # Start algo in a thread
            t_socket = Thread(target=self.ws.connect_socket)
            t_socket.start()

            # Run the plot's process
            self.p.start()

            # Wait for socket to close
            t_socket.join()

        elif self.mode == 'test':

            # Retrieve historical data
            self.retrieve_data()

            # Calculate Metrics
            self.pre_calculate(self.hist_df)

            # Get buy and sell signals
            self.hist_df = self.hist_df[99:]
            self.hist_df['Buy'] = self.buy_sell_historical(self.hist_df)[0]
            self.hist_df['Sell'] = self.buy_sell_historical(self.hist_df)[1]

            # Plot graph
            self.plot_hist_graph(self.hist_df)

        # Delete CSV File
        file_manager.delete_file('{}.csv'.format(self.symbol), True)