Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug Stock and Broker would Dicts not Instances of Stock and Broker #539

Open
freelancing-solutions opened this issue Jul 18, 2021 · 0 comments
Labels

Comments

@freelancing-solutions
Copy link
Owner

fix bug Stock and Broker would Dicts not Instances of Stock and Broker

# TODO fix bug Stock and Broker would Dicts not Instances of Stock and Broker

        else:
            return jsonify({'status': False, 'message': 'Stock Model not found'}), 500

    @use_context
    @handle_view_errors
    async def update_stock_model_async(self, stock_model: dict) -> tuple:
        if ('transaction_id' in stock_model) and (stock_model['transaction_id'] != ""):
            transaction_id: typing.Union[str, None] = stock_model.get('transaction_id')
        else:
            return jsonify({'status': False, 'message': 'transaction_id is required'}), 500

        if ('exchange_id' in stock_model) and (stock_model['exchange_id'] != ""):
            exchange_id: typing.Union[str, None] = stock_model.get('exchange_id')
        else:
            return jsonify({'status': False, 'message': 'exchange_id is required'}), 500

        if ('stock' in stock_model) and (stock_model['stock'] != ""):
            stock: typing.Union[Stock, None] = stock_model.get('stock')
        else:
            return jsonify({'status': False, 'message': 'stock is required'}), 500

        if ('broker' in stock_model) and (stock_model['broker'] != ""):
            broker: typing.Union[Broker, None] = stock_model.get('broker')
        else:
            return jsonify({'status': False, 'message': 'Broker is required'}), 500
        # TODO fix bug Stock and Broker would Dicts not Instances of Stock and Broker
        stock_model_instance: StockModel = StockModel.query(
            StockModel.transaction_id == transaction_id).get_async().get_result()

        if stock is not None:
            stock_instance: Stock = Stock.query(Stock.stock_code == stock['stock_code']).get_async().get_result()
        else:
            return jsonify({'status': False, 'message': 'stock is required'}), 500

        if broker is not None:
            broker_instance: Broker = Broker.query(
                Broker.broker_code == broker['broker_code']).get_async().get_result()
        else:
            return jsonify({'status': False, 'message': 'Broker is required'}), 500

        if isinstance(stock_model_instance, StockModel):
            stock_model = stock_model_instance
            stock_model.transaction_id = transaction_id
            stock_model.exchange_id = exchange_id
            stock_model.stock = stock_instance
            stock_model.broker = broker_instance
            key = stock_model.put_async(retries=self._max_retries, timeout=self._max_timeout).get_result()
            if key is not None:
                return jsonify({'status': True, 'payload': stock_model.to_dict(),
                                'message': 'stock model is update'}), 200
            else:
                message: str = 'Something snapped while updating stock model'
                raise DataServiceError(message)
        else:
            return jsonify({'status': False, 'message': 'Stock Model not found'}), 500

    # noinspection DuplicatedCode
    @data_wrappers.get_buy_volume_data
    @use_context

5a7ecf752a4e41cab8341be963c02f1d10eb81cf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant