Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_tinkoff-trading-bot-develop/app/utils/quotation.py
5935 views
1
import math
2
from typing import Union
3
4
from tinkoff.invest import Quotation, MoneyValue
5
6
7
def quotation_to_float(quotation: Union[Quotation, MoneyValue]) -> float:
8
"""
9
Convert quotation to float
10
11
:param quotation: Quotation or MoneyValue.
12
:return: float value - combination of fractional and integer part of quotation.
13
"""
14
15
return float(quotation.units + quotation.nano / 1000000000)
16
17
18
def float_to_quotation(f: float) -> Quotation:
19
"""
20
Convert float to quotation
21
22
:param f: float value.
23
:return: Quotation object
24
"""
25
return Quotation(*math.modf(f))
26
27