当前位置: 首页>>代码示例>>Python>>正文


Python hq.TdxHq_API类代码示例

本文整理汇总了Python中pytdx.hq.TdxHq_API的典型用法代码示例。如果您正苦于以下问题:Python TdxHq_API类的具体用法?Python TdxHq_API怎么用?Python TdxHq_API使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TdxHq_API类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_bars

 def _get_bars(self, market, code, ktype):
     data = []
     tdx_market = self._trans_market(market)
     if tdx_market is None:
         print("tdx_market == None")
         return data
     
     tdx_ktype = self._trans_ktype(ktype)
     if tdx_ktype is None:
         print("tdx_ktype == None")
         return data
     
     try:
         ip = self.getParam('ip')
         port = self.getParam('port')
     except:
         ip = '119.147.212.81'
         port = 7709
         
     api = TdxHq_API(raise_exception=True)
     
     with api.connect(ip, port):
         if (market == 'SH' and code[:3] == '000') \
               or (market == 'SZ'  and code[:2] == '39'):
             for i in range(self._max[ktype]):
                 data += api.get_index_bars(tdx_ktype, tdx_market, code,
                                        (self._max[ktype]-1-i)*800,800)
         else:
             for i in range(self._max[ktype]):
                 data += api.get_security_bars(tdx_ktype, tdx_market, code,
                                             (self._max[ktype]-1-i)*800,800)
             
     return data
开发者ID:fasiondog,项目名称:hikyuu,代码行数:33,代码来源:pytdx_data_driver.py

示例2: QA_fetch_get_stock_realtime

def QA_fetch_get_stock_realtime(code=['000001', '000002'], ip=best_ip, port=7709):
    api = TdxHq_API()
    __data = pd.DataFrame()
    code = [code] if type(code) is str else code






    async def _get_security_quotes(__code):
        """
        """
        assert isinstance(__code, str)

        data=await api.get_security_quotes([(__select_market_code(__code), __code)])
        data=api.to_df(data)
        data['datetime'] = datetime.datetime.now()

        return data[['datetime', 'code', 'open', 'high', 'low', 'price']]

    with api.connect(ip, port):
        coroutines = [asyncio.ensure_future(
            _get_security_quotes(code_)) for code_ in code]

        print(coroutines)
        try:
            loop = asyncio.get_event_loop()
        except RuntimeError:
            loop = asyncio.new_event_loop()
            asyncio.set_event_loop(loop)

        res = loop.run_until_complete(asyncio.gather(*coroutines))
        print(res)
        return res
开发者ID:imsimplise,项目名称:QUANTAXIS,代码行数:35,代码来源:test.py

示例3: QA_fetch_get_stock_min

def QA_fetch_get_stock_min(code, start, end, level='1min', ip=best_ip, port=7709):
    api = TdxHq_API()
    type_ = ''
    if str(level) in ['5', '5m', '5min', 'five']:
        level, type_ = 0, '5min'
    elif str(level) in ['1', '1m', '1min', 'one']:
        level, type_ = 8, '1min'
    elif str(level) in ['15', '15m', '15min', 'fifteen']:
        level, type_ = 1, '15min'
    elif str(level) in ['30', '30m', '30min', 'half']:
        level, type_ = 2, '30min'
    elif str(level) in ['60', '60m', '60min', '1h']:
        level, type_ = 3, '60min'
    with api.connect(ip, port):

        data = pd.concat([api.to_df(api.get_security_bars(level, __select_market_code(
            str(code)), str(code), (25 - i) * 800, 800)) for i in range(26)], axis=0)

        data = data\
            .assign(datetime=pd.to_datetime(data['datetime']), code=str(code))\
            .drop(['year', 'month', 'day', 'hour', 'minute'], axis=1, inplace=False)\
            .assign(date=data['datetime'].apply(lambda x: str(x)[0:10]))\
            .assign(date_stamp=data['datetime'].apply(lambda x: QA_util_date_stamp(x)))\
            .assign(time_stamp=data['datetime'].apply(lambda x: QA_util_time_stamp(x)))\
            .assign(type=type_).set_index('datetime', drop=False, inplace=False)[start:end]
        return data.assign(datetime=data['datetime'].apply(lambda x: str(x)))
开发者ID:imsimplise,项目名称:QUANTAXIS,代码行数:26,代码来源:QATdx.py

示例4: QA_fetch_get_stock_block

def QA_fetch_get_stock_block(ip=None, port=None):
    '板块数据'
    global best_ip
    if ip is None and port is None and best_ip['stock']['ip'] is None and best_ip['stock']['port'] is None:
        best_ip = select_best_ip()
        ip = best_ip['stock']['ip']
        port = best_ip['stock']['port']
    elif ip is None and port is None and best_ip['stock']['ip'] is not None and best_ip['stock']['port'] is not None:
        ip = best_ip['stock']['ip']
        port = best_ip['stock']['port']
    else:
        pass
    api = TdxHq_API()
    with api.connect(ip, port):

        data = pd.concat([api.to_df(api.get_and_parse_block_info("block_gn.dat")).assign(type='gn'),
                          api.to_df(api.get_and_parse_block_info(
                              "block.dat")).assign(type='yb'),
                          api.to_df(api.get_and_parse_block_info(
                              "block_zs.dat")).assign(type='zs'),
                          api.to_df(api.get_and_parse_block_info("block_fg.dat")).assign(type='fg')])

        if len(data) > 10:
            return data.assign(source='tdx').drop(['block_type', 'code_index'], axis=1).set_index('code', drop=False, inplace=False).drop_duplicates()
        else:
            QA_util_log_info('Wrong with fetch block ')
开发者ID:liangshanbovsluomio,项目名称:QUANTAXIS,代码行数:26,代码来源:QATdx.py

示例5: QA_fetch_get_stock_transaction_realtime

def QA_fetch_get_stock_transaction_realtime(code, ip=None, port=None):
    '实时分笔成交 包含集合竞价 buyorsell 1--sell 0--buy 2--盘前'
    global best_ip
    if ip is None and port is None and best_ip['stock']['ip'] is None and best_ip['stock']['port'] is None:
        best_ip = select_best_ip()
        ip = best_ip['stock']['ip']
        port = best_ip['stock']['port']
    elif ip is None and port is None and best_ip['stock']['ip'] is not None and best_ip['stock']['port'] is not None:
        ip = best_ip['stock']['ip']
        port = best_ip['stock']['port']
    else:
        pass
    api = TdxHq_API()
    try:
        with api.connect(ip, port):
            data = pd.DataFrame()
            data = pd.concat([api.to_df(api.get_transaction_data(
                _select_market_code(str(code)), code, (2 - i) * 2000, 2000)) for i in range(3)], axis=0)
            if 'value' in data.columns:
                data = data.drop(['value'], axis=1)
            data = data.dropna()
            day = datetime.date.today()
            return data.assign(date=str(day)).assign(datetime=pd.to_datetime(data['time'].apply(lambda x: str(day) + ' ' + str(x))))\
                .assign(code=str(code)).assign(order=range(len(data.index))).set_index('datetime', drop=False, inplace=False)
    except:
        return None
开发者ID:liangshanbovsluomio,项目名称:QUANTAXIS,代码行数:26,代码来源:QATdx.py

示例6: QA_fetch_get_stock_xdxr

def QA_fetch_get_stock_xdxr(code, ip=None, port=None):
    '除权除息'
    global best_ip
    if ip is None and port is None and best_ip['stock']['ip'] is None and best_ip['stock']['port'] is None:
        best_ip = select_best_ip()
        ip = best_ip['stock']['ip']
        port = best_ip['stock']['port']
    elif ip is None and port is None and best_ip['stock']['ip'] is not None and best_ip['stock']['port'] is not None:
        ip = best_ip['stock']['ip']
        port = best_ip['stock']['port']
    else:
        pass
    api = TdxHq_API()
    market_code = _select_market_code(code)
    with api.connect(ip, port):
        category = {
            '1': '除权除息', '2': '送配股上市', '3': '非流通股上市', '4': '未知股本变动', '5': '股本变化',
            '6': '增发新股', '7': '股份回购', '8': '增发新股上市', '9': '转配股上市', '10': '可转债上市',
            '11': '扩缩股', '12': '非流通股缩股', '13':  '送认购权证', '14': '送认沽权证'}
        data = api.to_df(api.get_xdxr_info(market_code, code))
        if len(data) >= 1:
            data = data\
                .assign(date=pd.to_datetime(data[['year', 'month', 'day']]))\
                .drop(['year', 'month', 'day'], axis=1)\
                .assign(category_meaning=data['category'].apply(lambda x: category[str(x)]))\
                .assign(code=str(code))\
                .rename(index=str, columns={'panhouliutong': 'liquidity_after',
                                            'panqianliutong': 'liquidity_before', 'houzongguben': 'shares_after',
                                            'qianzongguben': 'shares_before'})\
                .set_index('date', drop=False, inplace=False)
            return data.assign(date=data['date'].apply(lambda x: str(x)[0:10]))
        else:
            return None
开发者ID:liangshanbovsluomio,项目名称:QUANTAXIS,代码行数:33,代码来源:QATdx.py

示例7: ping

def ping(ip):
    __time1 = datetime.datetime.now()
    api = TdxHq_API()
    try:
        with api.connect(ip, 7709):
            if len(api.get_security_list(0, 1)) > 800:
                return datetime.datetime.now() - __time1
    except:
        return datetime.timedelta(9, 9, 0)
开发者ID:gvc0461082002,项目名称:pytdx,代码行数:9,代码来源:best_ip.py

示例8: ping

def ping(ip):
    api = TdxHq_API()
    __time1 = datetime.datetime.now()
    try:
        with api.connect(ip, 7709):
            if len(api.get_security_list(0, 1)) > 800:
                return datetime.datetime.now() - __time1
    except:
        print('Bad REPSONSE %s' % ip)
        return datetime.timedelta(9, 9, 0)
开发者ID:imsimplise,项目名称:QUANTAXIS,代码行数:10,代码来源:QATdx.py

示例9: api

def api(retry_count=3):
    for _ in range(retry_count):
        try:
            api = TdxHq_API(heartbeat=True)
            api.connect(ct._get_server(), ct.T_PORT)
        except Exception as e:
            print(e)
        else:
            return api
    raise IOError(ct.NETWORK_URL_ERROR_MSG)
开发者ID:TalesYuan,项目名称:tushare,代码行数:10,代码来源:conns.py

示例10: QA_fetch_get_stock_realtime

def QA_fetch_get_stock_realtime(code=['000001', '000002'], ip=best_ip, port=7709):
    api = TdxHq_API()
    __data = pd.DataFrame()
    with api.connect(ip, port):
        code = [code] if type(code) is str else code
        for id_ in range(int(len(code) / 80) + 1):
            __data = __data.append(api.to_df(api.get_security_quotes(
                [(__select_market_code(x), x) for x in code[80 * id_:80 * (id_ + 1)]])))
            __data['datetime'] = datetime.datetime.now()
        data = __data[['datetime', 'code', 'open', 'high', 'low', 'price']]
        return data.set_index('code', drop=False, inplace=False)
开发者ID:imsimplise,项目名称:QUANTAXIS,代码行数:11,代码来源:QATdx.py

示例11: _test_speed

    def _test_speed(self, ip, port=7709):

        api = TdxHq_API(raise_exception=True, auto_retry=False)
        _time = datetime.datetime.now()
        try:
            with api.connect(ip, port, time_out=0.05):
                if len(api.get_security_list(0, 1)) > 800:
                    return (datetime.datetime.now() - _time).total_seconds()
                else:
                    return datetime.timedelta(9, 9, 0).total_seconds()
        except Exception as e:
            return datetime.timedelta(9, 9, 0).total_seconds()
开发者ID:liangshanbovsluomio,项目名称:QUANTAXIS,代码行数:12,代码来源:QATdx_adv.py

示例12: QA_fetch_get_stock_latest

def QA_fetch_get_stock_latest(code, ip=best_ip, port=7709):
    code = [code] if isinstance(code, str) else code
    api = TdxHq_API(multithread=True)
    with api.connect(ip, port):
        data = pd.concat([api.to_df(api.get_security_bars(
            9, __select_market_code(item), item, 0, 1)).assign(code=item) for item in code], axis=0)
        return data\
            .assign(date=pd.to_datetime(data['datetime']
                                        .apply(lambda x: x[0:10])), date_stamp=data['datetime']
                    .apply(lambda x: QA_util_date_stamp(str(x[0:10]))))\
            .set_index('date', drop=False)\
            .drop(['year', 'month', 'day', 'hour', 'minute', 'datetime'], axis=1)
开发者ID:imsimplise,项目名称:QUANTAXIS,代码行数:12,代码来源:QATdx.py

示例13: get_tdx_kdata

def get_tdx_kdata(security_item, start, end):
    api = TdxHq_API()
    with api.connect():
        # open close high low vol amount date code
        # KDATA_COLUMN = ['timestamp', 'code', 'low', 'open', 'close', 'high', 'volume', 'turnover', 'securityId']

        df = api.get_k_data(security_item['code'], start, end)
        df = df[['date', 'code', 'low', 'open', 'close', 'high', 'vol', 'amount']]
        df['securityId'] = df['code'].apply(lambda x: 'stock_{}_{}'.format(get_exchange(x), x))
        df['vol'] = df['vol'].apply(lambda x: x * 100)
        df.columns = KDATA_COLUMN
    return df
开发者ID:intrad,项目名称:fooltrader,代码行数:12,代码来源:tdx.py

示例14: __call__

    def __call__(self):
        count = 0
        connect = sqlite3.connect(self.sqlitefile)
        try:
            progress = ProgressBar(self)
            api = TdxHq_API()
            api.connect(self.ip, self.port)
            count = import_time(connect, self.market, self.quotations, api,
                                 self.dest_dir, max_days=self.max_days, progress=progress)
        except Exception as e:
            print(e)
        finally:
            connect.commit()
            connect.close()

        self.queue.put([self.task_name, self.market, 'TIME', None, count])
开发者ID:fasiondog,项目名称:hikyuu,代码行数:16,代码来源:ImportPytdxTimeToH5Task.py

示例15: QA_fetch_get_stock_info

def QA_fetch_get_stock_info(code, ip=None, port=None):
    '股票基本信息'
    global best_ip
    if ip is None and port is None and best_ip['stock']['ip'] is None and best_ip['stock']['port'] is None:
        best_ip = select_best_ip()
        ip = best_ip['stock']['ip']
        port = best_ip['stock']['port']
    elif ip is None and port is None and best_ip['stock']['ip'] is not None and best_ip['stock']['port'] is not None:
        ip = best_ip['stock']['ip']
        port = best_ip['stock']['port']
    else:
        pass
    api = TdxHq_API()
    market_code = _select_market_code(code)
    with api.connect(ip, port):
        return api.to_df(api.get_finance_info(market_code, code))
开发者ID:liangshanbovsluomio,项目名称:QUANTAXIS,代码行数:16,代码来源:QATdx.py


注:本文中的pytdx.hq.TdxHq_API类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。