Path: blob/master/ invest-robot-contest_tinkoff-invest-volume-analysis-robot-master/utils/parse_util.py
5929 views
from datetime import datetime1from typing import Dict23import pandas as pd45from utils.format_util import quotation_to_float678def processed_data(trade):9try:10if trade is None:11return1213price = quotation_to_float(trade.price)14data = pd.DataFrame.from_records([15{16"figi": trade.figi,17"direction": trade.direction,18"price": price,19"quantity": trade.quantity,20"time": pd.to_datetime(str(trade.time), utc=True)21}22])2324return data25except Exception as ex:26return ex272829def parse_date(str_date: str):30try:31return datetime.strptime(str_date, "%Y-%m-%d %H:%M:%S.%f%z")32except ValueError:33pass3435try:36return datetime.strptime(str_date, "%Y-%m-%d %H:%M:%S%z")37except ValueError:38pass3940return None414243def get_float_from_dict(dictionary: Dict, key: str) -> float:44if key in dictionary:45return float(dictionary.get(key))46return 0474849def get_int_value(dictionary: Dict, key: str) -> int:50if key in dictionary:51return int(dictionary.get(key))52return 0535455def get_datetime_value(dictionary: Dict, key: str):56if key in dictionary:57return pd.to_datetime(dictionary.get(key))58return None596061