Ejemplo n.º 1
0
    def _submit(self):
        stock = Stock()

        brand = self.brand_comboBox
        stock.brand_name(brand.currentText()).brand_id(brand.currentData())

        model = self.model_combo_box
        stock.model_name(model.currentText()).model_id(model.currentData())

        first_service = self.first_service_combo_box
        stock.first_service_id(first_service.currentData()).first_service_name(
            first_service.currentText())

        second_service = self.second_service_combo_box
        stock.second_service_name(
            second_service.currentText()).second_service_id(
                second_service.currentData())

        name = brand.currentText() + '-' + model.currentText()
        stock.name(name)
        stock.unit(self.unit.text())
        stock.create_op(common.config.login_user_info[0])
        stock.create_time(get_now())

        stock_id = stock_handler.add_stock_info(stock)

        stock.id(stock_id)
Ejemplo n.º 2
0
def add_stock_info(model, brand, model_id, brand_id, unit, second_service_id):
    second_service = service_handler.get_service_by_id(second_service_id)

    stock_info = Stock()

    stock_info.model_id(model_id).model_name(model)
    stock_info.brand_id(brand_id).brand_name(brand)
    stock_info.first_service_id(second_service['father_id']).first_service_name(second_service['father_name'])
    stock_info.second_service_id(second_service_id).second_service_name(second_service['name'])
    stock_info.unit(unit)
    stock_info.name(brand + '-' + model)
    stock_info.create_op(config.login_user_info[0]).create_time(time_utils.get_now())

    stock_id = stock_handler.add_stock_info(stock_info)
    stock_info.id(stock_id)
    return stock_info
    def export_stock_data(self, fileformat="xls"):
        """Retrieve a user's options data and save as JSON and transposed requested file format.

        Args:
            fileformat (string): Requested file format to export data to, default XLS.
        """
        order_history = self.get_order_history()
        self.rhApihelper.save_to_json_file(order_history, "orders")

        stockTranData = tablib.Dataset(title="Transactions")
        stockTranData.headers = ['Ticker', 'Name', 'Date', 'Quantity', 'Price', 'TranType', 'Fees', 'Total']

        stockDict = {}

        for order_entry in order_history:
            if order_entry["state"] not in ["cancelled", "confirmed", "rejected"]:
                order_entry_instrument = self.rhApihelper.api_get(order_entry["instrument"])

                stock = Stock()
                stock.name = order_entry_instrument["simple_name"]
                stock.ticker = order_entry_instrument["symbol"]
                stock.fees = order_entry["fees"]
                stock.price = order_entry["average_price"]
                stock.totalPrice = order_entry["executed_notional"]["amount"]
                stock.quantity = order_entry["cumulative_quantity"]
                stock.date = order_entry["executions"][0]["settlement_date"]
                stock.tranType = order_entry["side"]

                stockTranData.append([stock.ticker, stock.name, stock.date, stock.quantity, stock.price, stock.tranType, stock.fees, stock.totalPrice])

                # Group the stocks into dictionary for further processing.
                if order_entry_instrument["symbol"] not in stockDict:
                    stockDict[stock.ticker] = [stock]
                else:
                    stockDict[stock.ticker].append(stock)

        stockSummaryData = self.create_summary(stockDict)

        stockExcelBook = tablib.Databook((stockTranData, stockSummaryData))

        self.rhApihelper.save_dataset_to_excel(
            "stockdata",
            fileformat,
            stockExcelBook
        )
Ejemplo n.º 4
0
def add_stock_info(stock: Stock):
    sql_text = '''
                INSERT INTO stock_info(
                                        UNIT,
                                        first_service_name,
                                        first_service_id,
                                        model_id,
                                        model_name,
                                        brand_id,
                                        brand_name,
                                        name,
                                        second_service_id,
                                        second_service_name,
                                        balance,
                                        total_cost,
                                        create_time,
                                        create_op
                                        )
                VALUES(
                        '{}',
                        '{}',
                         {},
                         {},
                        '{}',
                         {},
                        '{}',
                        '{}',
                         {},
                        '{}',
                         {},
                        {:.2f},
                        '{}',
                        {}                    
                )''' \
        .format(stock.unit(), stock.first_service_name(), stock.first_service_id(), stock.model_id(),
                stock.model_name(), stock.brand_id(), stock.brand_name(), stock.name(), stock.second_service_id(),
                stock.second_service_name(), stock.balance(), stock.total_cost(), stock.create_time(),
                stock.create_op())
    new_stock_id = execute(sql_text)

    return new_stock_id