# Path: vnpy/trader/object.py
# class BarData(BaseData):
#     """
#     Candlestick bar data of a certain trading period.
#     """
# 
#     symbol: str
#     exchange: Exchange
#     datetime: datetime
# 
#     interval: Interval = None
#     volume: float = 0
#     turnover: float = 0
#     open_interest: float = 0
#     open_price: float = 0
#     high_price: float = 0
#     low_price: float = 0
#     close_price: float = 0
# 
#     def __post_init__(self):
#         """"""
#         self.vt_symbol = f"{self.symbol}.{self.exchange.value}"
# 
# class TickData(BaseData):
#     """
#     Tick data contains information about:
#         * last trade in market
#         * orderbook snapshot
#         * intraday market statistics.
#     """
# 
#     symbol: str
#     exchange: Exchange
#     datetime: datetime
# 
#     name: str = ""
#     volume: float = 0
#     turnover: float = 0
#     open_interest: float = 0
#     last_price: float = 0
#     last_volume: float = 0
#     limit_up: float = 0
#     limit_down: float = 0
# 
#     open_price: float = 0
#     high_price: float = 0
#     low_price: float = 0
#     pre_close: float = 0
# 
#     bid_price_1: float = 0
#     bid_price_2: float = 0
#     bid_price_3: float = 0
#     bid_price_4: float = 0
#     bid_price_5: float = 0
# 
#     ask_price_1: float = 0
#     ask_price_2: float = 0
#     ask_price_3: float = 0
#     ask_price_4: float = 0
#     ask_price_5: float = 0
# 
#     bid_volume_1: float = 0
#     bid_volume_2: float = 0
#     bid_volume_3: float = 0
#     bid_volume_4: float = 0
#     bid_volume_5: float = 0
# 
#     ask_volume_1: float = 0
#     ask_volume_2: float = 0
#     ask_volume_3: float = 0
#     ask_volume_4: float = 0
#     ask_volume_5: float = 0
# 
#     localtime: datetime = None
# 
#     def __post_init__(self):
#         """"""
#         self.vt_symbol = f"{self.symbol}.{self.exchange.value}"
# 
# Path: vnpy/trader/constant.py
# class Exchange(Enum):
#     """
#     Exchange.
#     """
#     # Chinese
#     CFFEX = "CFFEX"         # China Financial Futures Exchange
#     SHFE = "SHFE"           # Shanghai Futures Exchange
#     CZCE = "CZCE"           # Zhengzhou Commodity Exchange
#     DCE = "DCE"             # Dalian Commodity Exchange
#     INE = "INE"             # Shanghai International Energy Exchange
#     SSE = "SSE"             # Shanghai Stock Exchange
#     SZSE = "SZSE"           # Shenzhen Stock Exchange
#     BSE = "BSE"             # Beijing Stock Exchange
#     SGE = "SGE"             # Shanghai Gold Exchange
#     WXE = "WXE"             # Wuxi Steel Exchange
#     CFETS = "CFETS"         # CFETS Bond Market Maker Trading System
#     XBOND = "XBOND"         # CFETS X-Bond Anonymous Trading System
# 
#     # Global
#     SMART = "SMART"         # Smart Router for US stocks
#     NYSE = "NYSE"           # New York Stock Exchnage
#     NASDAQ = "NASDAQ"       # Nasdaq Exchange
#     ARCA = "ARCA"           # ARCA Exchange
#     EDGEA = "EDGEA"         # Direct Edge Exchange
#     ISLAND = "ISLAND"       # Nasdaq Island ECN
#     BATS = "BATS"           # Bats Global Markets
#     IEX = "IEX"             # The Investors Exchange
#     NYMEX = "NYMEX"         # New York Mercantile Exchange
#     COMEX = "COMEX"         # COMEX of CME
#     GLOBEX = "GLOBEX"       # Globex of CME
#     IDEALPRO = "IDEALPRO"   # Forex ECN of Interactive Brokers
#     CME = "CME"             # Chicago Mercantile Exchange
#     ICE = "ICE"             # Intercontinental Exchange
#     SEHK = "SEHK"           # Stock Exchange of Hong Kong
#     HKFE = "HKFE"           # Hong Kong Futures Exchange
#     SGX = "SGX"             # Singapore Global Exchange
#     CBOT = "CBT"            # Chicago Board of Trade
#     CBOE = "CBOE"           # Chicago Board Options Exchange
#     CFE = "CFE"             # CBOE Futures Exchange
#     DME = "DME"             # Dubai Mercantile Exchange
#     EUREX = "EUX"           # Eurex Exchange
#     APEX = "APEX"           # Asia Pacific Exchange
#     LME = "LME"             # London Metal Exchange
#     BMD = "BMD"             # Bursa Malaysia Derivatives
#     TOCOM = "TOCOM"         # Tokyo Commodity Exchange
#     EUNX = "EUNX"           # Euronext Exchange
#     KRX = "KRX"             # Korean Exchange
#     OTC = "OTC"             # OTC Product (Forex/CFD/Pink Sheet Equity)
#     IBKRATS = "IBKRATS"     # Paper Trading Exchange of IB
# 
#     # Special Function
#     LOCAL = "LOCAL"         # For local generated data
# 
# class Interval(Enum):
#     """
#     Interval of bar data.
#     """
#     MINUTE = "1m"
#     HOUR = "1h"
#     DAILY = "d"
#     WEEKLY = "w"
#     TICK = "tick"


import json
import logging
import sys
import numpy as np
import talib
from pathlib import Path
from typing import Callable, Dict, Tuple, Union, Optional
from decimal import Decimal
from math import floor, ceil
from .object import BarData, TickData
from .constant import Exchange, Interval
    Get number of digits after decimal point.
    """
    value_str = str(value)

    if "e-" in value_str:
        _, buf = value_str.split("e-")
        return int(buf)
    elif "." in value_str:
        _, buf = value_str.split(".")
        return len(buf)
    else:
        return 0


class BarGenerator:
    """
    For:
    1. generating 1 minute bar data from tick data
    2. generating x minute bar/x hour bar data from 1 minute data

    Notice:
    1. for x minute bar, x must be able to divide 60: 2, 3, 5, 6, 10, 15, 20, 30
    2. for x hour bar, x can be any number
    """

    def __init__(
        self,
        on_bar: Callable,
        window: int = 0,
        on_window_bar: Callable = None,

# Path: vnpy/trader/object.py
# class BarData(BaseData):
#     """
#     Candlestick bar data of a certain trading period.
#     """
# 
#     symbol: str
#     exchange: Exchange
#     datetime: datetime
# 
#     interval: Interval = None
#     volume: float = 0
#     turnover: float = 0
#     open_interest: float = 0
#     open_price: float = 0
#     high_price: float = 0
#     low_price: float = 0
#     close_price: float = 0
# 
#     def __post_init__(self):
#         """"""
#         self.vt_symbol = f"{self.symbol}.{self.exchange.value}"
# 
# class TickData(BaseData):
#     """
#     Tick data contains information about:
#         * last trade in market
#         * orderbook snapshot
#         * intraday market statistics.
#     """
# 
#     symbol: str
#     exchange: Exchange
#     datetime: datetime
# 
#     name: str = ""
#     volume: float = 0
#     turnover: float = 0
#     open_interest: float = 0
#     last_price: float = 0
#     last_volume: float = 0
#     limit_up: float = 0
#     limit_down: float = 0
# 
#     open_price: float = 0
#     high_price: float = 0
#     low_price: float = 0
#     pre_close: float = 0
# 
#     bid_price_1: float = 0
#     bid_price_2: float = 0
#     bid_price_3: float = 0
#     bid_price_4: float = 0
#     bid_price_5: float = 0
# 
#     ask_price_1: float = 0
#     ask_price_2: float = 0
#     ask_price_3: float = 0
#     ask_price_4: float = 0
#     ask_price_5: float = 0
# 
#     bid_volume_1: float = 0
#     bid_volume_2: float = 0
#     bid_volume_3: float = 0
#     bid_volume_4: float = 0
#     bid_volume_5: float = 0
# 
#     ask_volume_1: float = 0
#     ask_volume_2: float = 0
#     ask_volume_3: float = 0
#     ask_volume_4: float = 0
#     ask_volume_5: float = 0
# 
#     localtime: datetime = None
# 
#     def __post_init__(self):
#         """"""
#         self.vt_symbol = f"{self.symbol}.{self.exchange.value}"
# 
# Path: vnpy/trader/constant.py
# class Exchange(Enum):
#     """
#     Exchange.
#     """
#     # Chinese
#     CFFEX = "CFFEX"         # China Financial Futures Exchange
#     SHFE = "SHFE"           # Shanghai Futures Exchange
#     CZCE = "CZCE"           # Zhengzhou Commodity Exchange
#     DCE = "DCE"             # Dalian Commodity Exchange
#     INE = "INE"             # Shanghai International Energy Exchange
#     SSE = "SSE"             # Shanghai Stock Exchange
#     SZSE = "SZSE"           # Shenzhen Stock Exchange
#     BSE = "BSE"             # Beijing Stock Exchange
#     SGE = "SGE"             # Shanghai Gold Exchange
#     WXE = "WXE"             # Wuxi Steel Exchange
#     CFETS = "CFETS"         # CFETS Bond Market Maker Trading System
#     XBOND = "XBOND"         # CFETS X-Bond Anonymous Trading System
# 
#     # Global
#     SMART = "SMART"         # Smart Router for US stocks
#     NYSE = "NYSE"           # New York Stock Exchnage
#     NASDAQ = "NASDAQ"       # Nasdaq Exchange
#     ARCA = "ARCA"           # ARCA Exchange
#     EDGEA = "EDGEA"         # Direct Edge Exchange
#     ISLAND = "ISLAND"       # Nasdaq Island ECN
#     BATS = "BATS"           # Bats Global Markets
#     IEX = "IEX"             # The Investors Exchange
#     NYMEX = "NYMEX"         # New York Mercantile Exchange
#     COMEX = "COMEX"         # COMEX of CME
#     GLOBEX = "GLOBEX"       # Globex of CME
#     IDEALPRO = "IDEALPRO"   # Forex ECN of Interactive Brokers
#     CME = "CME"             # Chicago Mercantile Exchange
#     ICE = "ICE"             # Intercontinental Exchange
#     SEHK = "SEHK"           # Stock Exchange of Hong Kong
#     HKFE = "HKFE"           # Hong Kong Futures Exchange
#     SGX = "SGX"             # Singapore Global Exchange
#     CBOT = "CBT"            # Chicago Board of Trade
#     CBOE = "CBOE"           # Chicago Board Options Exchange
#     CFE = "CFE"             # CBOE Futures Exchange
#     DME = "DME"             # Dubai Mercantile Exchange
#     EUREX = "EUX"           # Eurex Exchange
#     APEX = "APEX"           # Asia Pacific Exchange
#     LME = "LME"             # London Metal Exchange
#     BMD = "BMD"             # Bursa Malaysia Derivatives
#     TOCOM = "TOCOM"         # Tokyo Commodity Exchange
#     EUNX = "EUNX"           # Euronext Exchange
#     KRX = "KRX"             # Korean Exchange
#     OTC = "OTC"             # OTC Product (Forex/CFD/Pink Sheet Equity)
#     IBKRATS = "IBKRATS"     # Paper Trading Exchange of IB
# 
#     # Special Function
#     LOCAL = "LOCAL"         # For local generated data
# 
# class Interval(Enum):
#     """
#     Interval of bar data.
#     """
#     MINUTE = "1m"
#     HOUR = "1h"
#     DAILY = "d"
#     WEEKLY = "w"
#     TICK = "tick"


# Path: vnpy/trader/utility.py
import json
import logging
import sys
import numpy as np
import talib
from pathlib import Path
from typing import Callable, Dict, Tuple, Union, Optional
from decimal import Decimal
from math import floor, ceil
from .object import BarData, TickData
from .constant import Exchange, Interval

    Get number of digits after decimal point.
    """
    value_str = str(value)

    if "e-" in value_str:
        _, buf = value_str.split("e-")
        return int(buf)
    elif "." in value_str:
        _, buf = value_str.split(".")
        return len(buf)
    else:
        return 0


class BarGenerator:
    """
    For:
    1. generating 1 minute bar data from tick data
    2. generating x minute bar/x hour bar data from 1 minute data

    Notice:
    1. for x minute bar, x must be able to divide 60: 2, 3, 5, 6, 10, 15, 20, 30
    2. for x hour bar, x can be any number
    """

    def __init__(
        self,
        on_bar: Callable,
        window: int = 0,
        on_window_bar: Callable = None,

        interval: Interval = Interval.MINUTE