Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

api.GetSecurityQuotes 中返回的几个保留字段reversed_bytes中能不能提取出日期信息呀 #187

Open
neilyoung2008 opened this issue Oct 12, 2018 · 12 comments

Comments

@neilyoung2008
Copy link

想请问下有没有同学获取到日期信息,还是quote数据中压根就没有。

@liuyug
Copy link

liuyug commented Nov 23, 2018

同求,如果没有时间,这个数据就失去了意义

@liuyug
Copy link

liuyug commented Nov 23, 2018

数据没有日期,但有时间 reversed_bytes0
请参考

OrderedDict([('market', 0), ('code', '000001'), ('active1', 4322), ('price', 10.32), ('last_close', 10.55), ('open', 10.53), ('high', 10.58), ('low', 10.31), ('reversed_bytes0 ', 14999269), ('reversed_bytes1', -1032), ('vol', 700358), ('cur_vol', 11212), ('amount', 730667648.0), ('s_vol', 395083), ('b_vol', 305275), ('reversed_bytes2', -1), ('revers ed_bytes3', 7961), ('bid1', 10.32), ('ask1', 10.33), ('bid_vol1', 3143), ('ask_vol1', 4526), ('bid2', 10.31), ('ask2', 10.34), ('bid_vol2', 7046), ('ask_vol2', 2052), ('bid3',  10.3), ('ask3', 10.35), ('bid_vol3', 14425), ('ask_vol3', 2227), ('bid4', 10.29), ('ask4', 10.36), ('bid_vol4', 1237), ('ask_vol4', 2586), ('bid5', 10.28), ('ask5', 10.37), ( 'bid_vol5', 2470), ('ask_vol5', 1223), ('reversed_bytes4', (1018,)), ('reversed_bytes5', 1), ('reversed_bytes6', -29), ('reversed_bytes7', -19), ('reversed_bytes8', 18), ('rev ersed_bytes9', 0.0), ('active2', 4322)])
--

reversed_bytes0 ', 14999269
TIME:14:59:57.368

    def format_time(time_stamp):
        time = time_stamp[:-6] + ':'
        if int(time_stamp[-6:-4]) < 60:
            time += '%s:' % time_stamp[-6:-4]
            time += '%06.3f' % (
                int(time_stamp[-4:]) * 60 / 10000.0
            )
        else:
            time += '%02d:' % (
                int(time_stamp[-6:]) * 60 / 1000000
            )
            time += '%06.3f' % (
                (int(time_stamp[-6:]) * 60 % 1000000) * 60 / 1000000.0
            )
        return time

format_time('%' % reversed_bytes0)

@rainx
Copy link
Owner

rainx commented Aug 23, 2019

@liuyug 非常好,感谢,这个format_time是如何推断出来的,我之前一直没有看出规律

@yutiansut
Copy link
Collaborator

@liuyug 我测一测 给大哥递可乐

@rainx
Copy link
Owner

rainx commented Aug 24, 2019

创建了相关的分支 https://github.com/rainx/pytdx/tree/feautre/add-time-column-to-get-security-quotes 如果测试没有问题就合并到主干

@rainx rainx closed this as completed Aug 24, 2019
@yutiansut
Copy link
Collaborator

yutiansut commented Aug 26, 2019

我测了下 这个time的时间戳 相较于本地时间差了20秒左右
@rainx @liuyug

In [19]: QA.QA_fetch_get_stock_realtime('tdx','000004')
Out[19]:
                                     servertime  active1  active2  last_close   open   high   low  price  cur_vol  s_vol  b_vol   vol  ...   ask3  ask_vol3   bid3  bid_vol3   ask4  ask_vol4   bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5
datetime                   code                                                                                                        ...

2019-08-26 10:03:01.644348 000004  10:02:48.024      281      281       19.95  19.49  20.26  19.3  19.97       34    931   1866  2797  ...  20.12        43  19.93         2  20.13        33  19.88         5  20.14         2  19.87
 2

[1 rows x 32 columns]

In [20]: QA.QA_fetch_get_stock_realtime('tdx','000002')
Out[20]:
                                     servertime  active1  active2  last_close   open   high   low  price  cur_vol  s_vol  b_vol     vol  ...   ask3  ask_vol3   bid3  bid_vol3   ask4  ask_vol4   bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5
datetime                   code                                                                                                          ...

2019-08-26 10:03:09.164440 000002  10:02:47.814      663      663       26.96  26.46  26.56  26.2  26.32      100  85183  79588  164771  ...  26.34       112  26.29       468  26.35       944  26.28       206  26.36        34  26.27
 146

[1 rows x 32 columns]

In [21]: QA.QA_fetch_get_stock_realtime('tdx','600010')
Out[21]:
                                     servertime  active1  active2  last_close  open  high   low  price  cur_vol   s_vol   b_vol     vol  ...  ask3  ask_vol3  bid3  bid_vol3  ask4  ask_vol4  bid4  bid_vol4  ask5  ask_vol5  bid5  bid_vol5
datetime                   code                                                                                                          ...
2019-08-26 10:03:15.266577 600010  10:03:06.306      536      536         1.5  1.49   1.5  1.48    1.5      619  174595  125949  300543  ...  1.52    171529  1.47    144620  1.53    111224  1.46     94821  1.54     51345  1.45     60267

[1 rows x 32 columns]

@yutiansut yutiansut reopened this Aug 26, 2019
@yutiansut
Copy link
Collaborator

应该是解析方法的问题 @liuyug @rainx


In [1]: import QUANTAXIS as QA

In [2]: QA.QA_fetch_get_stock_realtime('tdx','600010')
QUANTAXIS>> Selecting the Best Server IP of TDX
USING DEFAULT STOCK IP
USING DEFAULT FUTURE IP
QUANTAXIS>> === The BEST SERVER ===
 stock_ip 180.153.18.170 future_ip 47.107.75.159
Out[2]:
                                  servertime  reversed_bytes0  active1  active2  last_close  open  high   low  price  cur_vol   s_vol   b_vol  ...  ask3  ask_vol3  bid3  bid_vol3  ask4  ask_vol4  bid4  bid_vol4  ask5  ask_vol5  bid5  bid_vol5
datetime                code                                                                                                                   ...

2019-08-26 10:05:40.518 600010  10:05:20.712         10053452      568      568         1.5  1.49   1.5  1.48   1.49        1  177039  127252  ...  1.52    171840  1.47    144961  1.53    111396  1.46     94841  1.54     51601  1.45     64545

[1 rows x 33 columns]

In [3]: QA.QA_fetch_get_stock_realtime('tdx','000002')
Out[3]:
                                     servertime  reversed_bytes0  active1  active2  last_close   open   high   low  price  cur_vol  s_vol  ...  ask_vol3   bid3  bid_vol3  ask4  ask_vol4   bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5
datetime                   code                                                                                                            ...
2019-08-26 10:05:45.864312 000002  10:05:09.378         10051563      715      715       26.96  26.46  26.56  26.2  26.38        7  87222  ...       274  26.34       544  26.4       572  26.33        81  26.41        88  26.32        41

[1 rows x 33 columns]

In [4]: QA.QA_fetch_get_stock_realtime('tdx','000004')
Out[4]:
                                     servertime  reversed_bytes0  active1  active2  last_close   open   high   low  price  cur_vol  s_vol  ...  ask_vol3   bid3  bid_vol3   ask4  ask_vol4   bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5 datetime                   code                                                                                                            ...
2019-08-26 10:05:49.411807 000004  10:05:16.800         10052800      297      297       19.95  19.49  20.26  19.3  20.01        9    960  ...         7  19.96        17  20.12        43  19.95        14  20.13        34  19.93         2

[1 rows x 33 columns]

In [5]: QA.QA_fetch_get_stock_realtime('tdx','000001')
Out[5]:
                                     servertime  reversed_bytes0  active1  active2  last_close   open  high    low  price  cur_vol   s_vol  ...  ask_vol3   bid3  bid_vol3   ask4  ask_vol4  bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5 datetime                   code                                                                                                             ...
2019-08-26 10:05:53.146422 000001  10:05:22.068         10053678      718      718       14.65  14.42  14.5  14.17  14.23       90  308615  ...      1329  14.21      4306  14.27       227  14.2      7107  14.28      1185  14.19      4695

[1 rows x 33 columns]

@yutiansut
Copy link
Collaborator

多次获取同一个股票的实时 reverse_byte0 只出现了非常微小的变化

In [8]: QA.QA_fetch_get_stock_realtime('tdx','000001')
Out[8]:
                                     servertime  reversed_bytes0  active1  active2  last_close   open  high    low  price  cur_vol   s_vol  ...  ask_vol3   bid3  bid_vol3   ask4  ask_vol4   bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5

datetime                   code                                                                                                             ...

2019-08-26 10:07:50.171591 000001  10:07:20.292         10073382      757      757       14.65  14.42  14.5  14.17  14.19      385  329319  ...      1177  14.17      2984  14.23       762  14.16      3944  14.24       235  14.15      7473


[1 rows x 33 columns]

In [9]: QA.QA_fetch_get_stock_realtime('tdx','000001')
Out[9]:
                                     servertime  reversed_bytes0  active1  active2  last_close   open  high    low  price  cur_vol   s_vol  ...  ask_vol3   bid3  bid_vol3   ask4  ask_vol4   bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5

datetime                   code                                                                                                             ...

2019-08-26 10:07:50.484442 000001  10:07:20.292         10073382      757      757       14.65  14.42  14.5  14.17  14.19      385  329319  ...      1177  14.17      2984  14.23       762  14.16      3944  14.24       235  14.15      7473


[1 rows x 33 columns]

In [10]: QA.QA_fetch_get_stock_realtime('tdx','000001')
Out[10]:
                                     servertime  reversed_bytes0  active1  active2  last_close   open  high    low  price  cur_vol   s_vol  ...  ask_vol3   bid3  bid_vol3   ask4  ask_vol4   bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5

datetime                   code                                                                                                             ...

2019-08-26 10:07:50.717429 000001  10:07:20.292         10073382      757      757       14.65  14.42  14.5  14.17  14.19      385  329319  ...      1177  14.17      2984  14.23       762  14.16      3944  14.24       235  14.15      7473


[1 rows x 33 columns]

In [11]: QA.QA_fetch_get_stock_realtime('tdx','000001')
Out[11]:
                                     servertime  reversed_bytes0  active1  active2  last_close   open  high    low  price  cur_vol   s_vol  ...  ask_vol3   bid3  bid_vol3   ask4  ask_vol4   bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5

datetime                   code                                                                                                             ...

2019-08-26 10:07:51.123309 000001  10:07:20.292         10073382      757      757       14.65  14.42  14.5  14.17  14.19      385  329319  ...      1177  14.17      2984  14.23       762  14.16      3944  14.24       235  14.15      7473


[1 rows x 33 columns]

In [12]: QA.QA_fetch_get_stock_realtime('tdx','000001')
Out[12]:
                                     servertime  reversed_bytes0  active1  active2  last_close   open  high    low  price  cur_vol   s_vol  ...  ask_vol3   bid3  bid_vol3   ask4  ask_vol4   bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5

datetime                   code                                                                                                             ...

2019-08-26 10:07:56.646339 000001  10:07:23.898         10073983      759      759       14.65  14.42  14.5  14.17  14.18     1391  335775  ...      2024  14.16      3924  14.22      1161  14.15      7480  14.23       757  14.14      2492


[1 rows x 33 columns]

In [13]: QA.QA_fetch_get_stock_realtime('tdx','000001')
Out[13]:
                                     servertime  reversed_bytes0  active1  active2  last_close   open  high    low  price  cur_vol   s_vol  ...  ask_vol3   bid3  bid_vol3   ask4  ask_vol4   bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5

datetime                   code                                                                                                             ...

2019-08-26 10:07:59.992633 000001  10:07:25.698         10074283      760      760       14.65  14.42  14.5  14.17  14.18      108  335883  ...      2024  14.16      3924  14.22      1161  14.15      7479  14.23       757  14.14      2492


[1 rows x 33 columns]

@yutiansut
Copy link
Collaborator

yutiansut commented Aug 26, 2019

并且可以看出
reversed_bytes0 active1 active2 这三个字段关系非常密切

怀疑active 是今天的交易的tick数?

In [23]: QA.QA_fetch_get_stock_realtime('tdx','000001')
Out[23]:
                                     servertime  reversed_bytes0  active1  active2  last_close   open  high    low  price  cur_vol   s_vol  ...  ask_vol3   bid3  bid_vol3   ask4  ask_vol4   bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5

datetime                   code                                                                                                             ...

2019-08-26 10:10:24.763325 000001  10:10:04.092         10100682      808      808       14.65  14.42  14.5  14.15  14.19      266  354675  ...       286  14.17      1478  14.24        12  14.16      3574  14.25       475  14.15      6484


[1 rows x 33 columns]

In [24]: QA.QA_fetch_get_stock_realtime('tdx','000001')
Out[24]:
                                     servertime  reversed_bytes0  active1  active2  last_close   open  high    low  price  cur_vol   s_vol  ...  ask_vol3   bid3  bid_vol3   ask4  ask_vol4   bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5

datetime                   code                                                                                                             ...

2019-08-26 10:10:25.715401 000001  10:10:05.886         10100981      809      809       14.65  14.42  14.5  14.15   14.2        7  354679  ...       286  14.18      1677  14.24        12  14.17      1492  14.25       475  14.16      3619


[1 rows x 33 columns]

In [25]: QA.QA_fetch_get_stock_realtime('tdx','000001')
Out[25]:
                                     servertime  reversed_bytes0  active1  active2  last_close   open  high    low  price  cur_vol   s_vol  ...  ask_vol3   bid3  bid_vol3   ask4  ask_vol4   bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5

datetime                   code                                                                                                             ...

2019-08-26 10:10:28.359810 000001  10:10:07.680         10101280      810      810       14.65  14.42  14.5  14.15  14.21     1905  354679  ...       649  14.17      1505  14.23       286  14.16      3649  14.24        12  14.15      6581


[1 rows x 33 columns]

In [26]: QA.QA_fetch_get_stock_realtime('tdx','000001')
Out[26]:
                                     servertime  reversed_bytes0  active1  active2  last_close   open  high    low  price  cur_vol   s_vol  ...  ask_vol3   bid3  bid_vol3   ask4  ask_vol4   bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5

datetime                   code                                                                                                             ...

2019-08-26 10:10:29.809632 000001  10:10:07.680         10101280      810      810       14.65  14.42  14.5  14.15  14.21     1905  354679  ...       649  14.17      1505  14.23       286  14.16      3649  14.24        12  14.15      6581


[1 rows x 33 columns]

In [27]: QA.QA_fetch_get_stock_realtime('tdx','000001')
Out[27]:
                                     servertime  reversed_bytes0  active1  active2  last_close   open  high    low  price  cur_vol   s_vol  ...  ask_vol3   bid3  bid_vol3   ask4  ask_vol4   bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5

datetime                   code                                                                                                             ...

2019-08-26 10:10:30.736140 000001  10:10:07.680         10101280      810      810       14.65  14.42  14.5  14.15  14.21     1905  354679  ...       649  14.17      1505  14.23       286  14.16      3649  14.24        12  14.15      6581


[1 rows x 33 columns]

In [28]: QA.QA_fetch_get_stock_realtime('tdx','000001')
Out[28]:
                                     servertime  reversed_bytes0  active1  active2  last_close   open  high    low  price  cur_vol   s_vol  ...  ask_vol3   bid3  bid_vol3   ask4  ask_vol4   bid4  bid_vol4   ask5  ask_vol5   bid5  bid_vol5

datetime                   code                                                                                                             ...

2019-08-26 10:10:32.136020 000001  10:10:09.480         10101580      811      811       14.65  14.42  14.5  14.15  14.21      271  354679  ...       286  14.17      1504  14.24        12  14.16      3649  14.25       487  14.15      6585


[1 rows x 33 columns]

@johnwangwjq
Copy link

刚和天总沟通了一下,发现暂时还没有数据的“数据产生时间”字段。希望有这个字段提供出来。

目前增加的这个servertime字段(06b17cc)是服务器的当前时间(大致等于接口调用的时间),并不是数据产生时间。没有这个时间值,我们就要靠别的手段来判断行情的实际产生时间了。

@YangerXiaoying
Copy link

刚和天总沟通了一下,发现暂时还没有数据的“数据产生时间”字段。希望有这个字段提供出来。

目前增加的这个servertime字段(06b17cc)是服务器的当前时间(大致等于接口调用的时间),并不是数据产生时间。没有这个时间值,我们就要靠别的手段来判断行情的实际产生时间了。

新增的这个servertime就代表了数据产生的时间时间,比如连续调用get_security_quotes,第一次返回的servertime=1,第二次返回的值servertime的值仍然=1,就说明你调用的频次太快了(实际行情盘口数据可能3秒才刷新一次,而你通过代码调用可能两次间隔不到1秒钟),两次返回的数据是一样的。

@johnwangwjq
Copy link

刚和天总沟通了一下,发现暂时还没有数据的“数据产生时间”字段。希望有这个字段提供出来。
目前增加的这个servertime字段(06b17cc)是服务器的当前时间(大致等于接口调用的时间),并不是数据产生时间。没有这个时间值,我们就要靠别的手段来判断行情的实际产生时间了。

新增的这个servertime就代表了数据产生的时间时间,比如连续调用get_security_quotes,第一次返回的servertime=1,第二次返回的值servertime的值仍然=1,就说明你调用的频次太快了(实际行情盘口数据可能3秒才刷新一次,而你通过代码调用可能两次间隔不到1秒钟),两次返回的数据是一样的。
哦,这样啊,明白了。多谢多谢。

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants