def get_bar_list(df, frequency, date=None):
    bar_list = []

    end_time = df.ix[0].time
    if date is None:
        date = datetime.datetime.now()
    slice_start_time = to_market_datetime(
        datetime.datetime(date.year, date.month, date.day, 9, 30, 0))

    while slice_start_time.strftime("%H:%M:%S") < end_time:
        slice_end_time = slice_start_time + datetime.timedelta(
            seconds=frequency)

        ticks_slice = df.ix[(df.time < slice_end_time.strftime("%H:%M:%S")) &
                            (df.time >= slice_start_time.strftime("%H:%M:%S"))]

        if not ticks_slice.empty:
            open_ = ticks_slice.price.get_values()[-1]
            high = max(ticks_slice.price)
            low = min(ticks_slice.price)
            close = ticks_slice.price.get_values()[0]
            volume = sum(ticks_slice.volume)
            amount = sum(ticks_slice.amount)

            bar_list.append(
                bar.BasicBar(slice_start_time, open_, high, low, close, volume,
                             0, frequency, amount))
        else:
            bar_list.append(None)
        slice_start_time = slice_end_time

    return bar_list
def dataframeToBar(bar_dataframe, frequency):
    bars = []
    for _, row in bar_dataframe.iterrows():
        tmp_extra = {}
        for key in row.keys():
            if key not in [
                    'datetime', 'open', 'high', 'low', 'close', 'volume',
                    'amount'
            ]:
                tmp_extra[key] = row[key]
        bars.append(bar.BasicBar(row['datetime'], row['open'], row['high'], row['low'], row['close'], row['volume']\
                 , row['amount'], frequency, False, tmp_extra))
    return bars
def build_bar(dateTime, ds):
    prices = ds.getPriceDS()
    volumes = ds.getVolumeDS()
    amounts = ds.getAmountDS()

    open_ = float(prices[0])
    high = float(max(prices))
    low = float(min(prices))
    close = float(prices[-1])
    volume = sum(int(v) for v in volumes)
    amount = sum(float(a) for a in amounts)

    return bar.BasicBar(dateTime, open_, high, low, close, volume, None,
                        Frequency.DAY, amount)
示例#4
0
    def _build_bar(self, identifier, start, end):

        df = self._ticksDf[identifier]

        ticks_slice = df.ix[(df.time < end.strftime("%H:%M:%S"))
                            & (df.time >= start.strftime("%H:%M:%S"))]

        if not ticks_slice.empty:
            open_ = ticks_slice.price.get_values()[0]
            high = max(ticks_slice.price)
            low = min(ticks_slice.price)
            close = ticks_slice.price.get_values()[-1]
            volume = sum(ticks_slice.volume)
            amount = sum(ticks_slice.amount)

            return bar.BasicBar(to_market_datetime(start), open_, high, low,
                                close, volume, amount, self.__frequency, {})
        else:
            return None
示例#5
0
def get_futu_bar_list(df, frequency):

    bar_list = []

    for index, row in df.iterrows():
        open_ = row.open
        high = row.high
        low = row.low
        close = row.close
        volume = row.volume
        amount = row.turnover

        slice_start_time = datetime.datetime.strptime(row.time_key,
                                                      '%Y-%m-%d %H:%M:%S')
        #time formate.
        slice_start_time = to_market_datetime(slice_start_time)
        bar_list.append(
            bar.BasicBar(slice_start_time, open_, high, low, close, volume, 0,
                         frequency, amount))
    return bar_list
示例#6
0
    def on_recv_rsp(self, rsp_str):
        #ret_code, content = super().on_recv_rsp(rsp_str)
        ret_code, content = super(CurKlineTest, self).on_recv_rsp(rsp_str)
        print(ret_code)
        if ret_code != futu_open.RET_OK:
            print("CurKlineTest: error, msg: %s" % content)
            return futu_open.RET_ERROR, content
        print("CurKline : ", content)

        for index, row in content.iterrows():
            open_ = row.open
            high = row.high
            low = row.low
            close = row.close
            volume = row.volume
            amount = row.turnover
            slice_start_time = datetime.datetime.strptime(
                row.time_key, '%Y-%m-%d %H:%M:%S')
            slice_start_time = to_market_datetime(slice_start_time)
            identifier = row.code
            k_type = row.k_type
            if k_type != 'K_1M':
                continue
            if identifier not in self.__identifiers:
                continue

            if self.__last_kline_time[
                    identifier] is None or self.__last_kline_time[
                        identifier] < slice_start_time:
                self.__last_kline_time[identifier] = slice_start_time
            else:
                #print "slice_start_time %s last_kline_time %s", (slice_start_time, slice_start_time)
                continue

            frequency = bar.Frequency.MINUTE
            one_bar = bar.BasicBar(slice_start_time, open_, high, low, close,
                                   volume, 0, frequency, amount)
            bar_dict = {}
            bar_dict[identifier] = one_bar
            bars = bar.Bars(bar_dict)
            self.__queue.put((FutuLiveFeed.ON_BARS, bars))