Esempio n. 1
0
File: engine.py Progetto: Alyle/vnpy
    def load(
        self,
        file_path: str,
        symbol: str,
        exchange: Exchange,
        interval: Interval,
        datetime_head: str,
        open_head: str,
        close_head: str,
        low_head: str,
        high_head: str,
        volume_head: str,
        datetime_format: str
    ):
        """"""
        vt_symbol = f"{symbol}.{exchange.value}"

        start = None
        end = None
        count = 0

        with open(file_path, 'rt') as f:
            reader = csv.DictReader(f)

            for item in reader:
                db_bar = DbBarData()

                db_bar.symbol = symbol
                db_bar.exchange = exchange.value
                db_bar.datetime = datetime.strptime(
                    item[datetime_head], datetime_format
                )
                db_bar.interval = interval.value
                db_bar.volume = item[volume_head]
                db_bar.open_price = item[open_head]
                db_bar.high_price = item[high_head]
                db_bar.low_price = item[low_head]
                db_bar.close_price = item[close_head]
                db_bar.vt_symbol = vt_symbol
                db_bar.gateway_name = "DB"

                db_bar.replace()

                # do some statistics
                count += 1
                if not start:
                    start = db_bar.datetime

        end = db_bar.datetime

        return start, end, count
Esempio n. 2
0
def generate_bar_from_row(row, symbol, exchange):
    """"""
    bar = DbBarData()

    bar.symbol = symbol
    bar.exchange = exchange
    bar.interval = "1m"
    bar.open_price = row["open"]
    bar.high_price = row["high"]
    bar.low_price = row["low"]
    bar.close_price = row["close"]
    bar.volume = row["volume"]
    bar.datetime = row.name.to_pydatetime()
    bar.gateway_name = "DB"
    bar.vt_symbol = f"{symbol}.{exchange}"

    return bar
Esempio n. 3
0
def generate_bar_from_row(row, symbol, exchange):
    """"""
    bar = DbBarData()

    bar.symbol = symbol
    bar.exchange = exchange
    bar.interval = "1m"
    bar.open_price = row["open"]
    bar.high_price = row["high"]
    bar.low_price = row["low"]
    bar.close_price = row["close"]
    bar.volume = row["volume"]
    bar.datetime = row.name.to_pydatetime()
    bar.gateway_name = "DB"
    bar.vt_symbol = f"{symbol}.{exchange}"

    return bar
Esempio n. 4
0
    def load(self, file_path: str, symbol: str, exchange: Exchange,
             interval: Interval, datetime_head: str, open_head: str,
             close_head: str, low_head: str, high_head: str, volume_head: str,
             datetime_format: str):
        """"""
        vt_symbol = f"{symbol}.{exchange.value}"

        start = None
        end = None
        count = 0

        with open(file_path, 'rt') as f:
            reader = csv.DictReader(f)

            for item in reader:
                db_bar = DbBarData()

                db_bar.symbol = symbol
                db_bar.exchange = exchange.value
                db_bar.datetime = datetime.strptime(item[datetime_head],
                                                    datetime_format)
                db_bar.interval = interval.value
                db_bar.volume = item[volume_head]
                db_bar.open_price = item[open_head]
                db_bar.high_price = item[high_head]
                db_bar.low_price = item[low_head]
                db_bar.close_price = item[close_head]
                db_bar.vt_symbol = vt_symbol
                db_bar.gateway_name = "DB"

                db_bar.replace()

                # do some statistics
                count += 1
                if not start:
                    start = db_bar.datetime

        end = db_bar.datetime

        return start, end, count