Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_invest-bot-main/invest_api/utils.py
5929 views
1
import uuid
2
from decimal import Decimal
3
4
from tinkoff.invest import MoneyValue, Quotation, Candle, HistoricCandle
5
from tinkoff.invest.utils import quotation_to_decimal, decimal_to_quotation
6
7
__all__ = ()
8
9
10
def rub_currency_name() -> str:
11
return "rub"
12
13
14
def moex_exchange_name() -> str:
15
return "MOEX"
16
17
18
def moneyvalue_to_decimal(money_value: MoneyValue) -> Decimal:
19
return quotation_to_decimal(
20
Quotation(
21
units=money_value.units,
22
nano=money_value.nano
23
)
24
)
25
26
27
def decimal_to_moneyvalue(decimal: Decimal, currency: str = rub_currency_name()) -> MoneyValue:
28
quotation = decimal_to_quotation(decimal)
29
return MoneyValue(
30
currency=currency,
31
units=quotation.units,
32
nano=quotation.nano
33
)
34
35
36
def generate_order_id() -> str:
37
return str(uuid.uuid4())
38
39
40
def candle_to_historiccandle(candle: Candle) -> HistoricCandle:
41
return HistoricCandle(
42
open=candle.open,
43
high=candle.high,
44
low=candle.low,
45
close=candle.close,
46
volume=candle.volume,
47
time=candle.time,
48
is_complete=True
49
)
50
51