Path: blob/master/ invest-robot-contest_invest-bot-main/invest_api/utils.py
5929 views
import uuid1from decimal import Decimal23from tinkoff.invest import MoneyValue, Quotation, Candle, HistoricCandle4from tinkoff.invest.utils import quotation_to_decimal, decimal_to_quotation56__all__ = ()789def rub_currency_name() -> str:10return "rub"111213def moex_exchange_name() -> str:14return "MOEX"151617def moneyvalue_to_decimal(money_value: MoneyValue) -> Decimal:18return quotation_to_decimal(19Quotation(20units=money_value.units,21nano=money_value.nano22)23)242526def decimal_to_moneyvalue(decimal: Decimal, currency: str = rub_currency_name()) -> MoneyValue:27quotation = decimal_to_quotation(decimal)28return MoneyValue(29currency=currency,30units=quotation.units,31nano=quotation.nano32)333435def generate_order_id() -> str:36return str(uuid.uuid4())373839def candle_to_historiccandle(candle: Candle) -> HistoricCandle:40return HistoricCandle(41open=candle.open,42high=candle.high,43low=candle.low,44close=candle.close,45volume=candle.volume,46time=candle.time,47is_complete=True48)495051