예제 #1
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)
예제 #2
0
    def read_orders(self):
        """
        Read the current order id from file
        :return: orders list
        """
        orders = []
        # Create an order ID which is 'global' for this session. This
        # will need incrementing once new orders are submitted.
        if FileUtils.check_file_exists_or_create(self.file_path, GlobalVariables.get_order_file_header()):
            data = pd.read_csv(self.file_path)

            if len(data) > 0:
                # datetime, stock_ticker
                orders = data

        return orders
예제 #3
0
    def _read_current_order_id(self):
        """
        Read the current order id from file
        :return: order id
        """

        # Create an order ID which is 'global' for this session. This
        # will need incrementing once new orders are submitted.
        last_order_id = pd.np.random.randint(1000, 90000)

        if FileUtils.check_file_exists_or_create(self.file_path, GlobalVariables.get_order_file_header()):
            data = pd.read_csv(self.file_path)

            if len(data) > 0:
                last_order_id = data['order_id'][len(data) - 1]

        order_id = last_order_id + 1
        return order_id