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

data = api.get_security_quotes([(0, '000005'), (0, '002893')]) 因为002893 没有数据,这条就返回None了 #44

Closed
rainx opened this issue Sep 1, 2017 · 1 comment

Comments

@rainx
Copy link
Owner

rainx commented Sep 1, 2017

QQ留言

@翻开魔法书  09:27:02
@产品研发-徐景RainX      data = api.get_security_quotes([(0, '000005'), (0, '002893')])          因为002893 没有数据,这条就返回None了 

单独收取 0,002893 获取的数据

body_buf=b'\x01\x17\x01\x00\x00002893\x00\x00\x00\x00\x00\x00\x00\xa4\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
   ...: \x00\x00\x00\x00\x00\x00\x00\x00'

尝试解析

In [4]: from pytdx.helper import get_datetime, get_volume, get_price
   ...: from collections import OrderedDict
   ...: import struct
   ...: import six


error                                     Traceback (most recent call last)
<ipython-input-5-c8fcf5eb19bb> in <module>()
     69     reversed_bytes7, pos = get_price(body_buf, pos)
     70     reversed_bytes8, pos = get_price(body_buf, pos)
---> 71     (reversed_bytes9, active2) = struct.unpack("<HH", body_buf[pos: pos + 4])
     72     pos += 4
     73

error: unpack requires a bytes object of length 4
@rainx
Copy link
Owner Author

rainx commented Sep 1, 2017

看了一下,主要的问题在于这里
因为不确定这里应该是4个bytes还是get_price,所以目前的解决方案是发现股票的价格为空的时候,就使用get_price, 否则使用 4 bytes , 目前看来还是可以的,如果有更好的方法,后续再进行改进

            # 不确定这里应该是用 get_price 跳过还是直接跳过4个bytes
            if price == 0 and last_close_diff == 0 and open_diff == 0 and high_diff == 0 and low_diff == 0:
                # 这个股票当前应该无法获取信息, 这个时候,这个值一般是0 或者 100
                #reversed_bytes0 = body_buf[pos: pos + 1]
                #pos += 1
                # 感觉这里应该都可以用 get_price ,但是由于一次性改动影响比较大,所以暂时只针对没有行情的股票做改动
                reversed_bytes0, pos = get_price(body_buf, pos)
            else:
                reversed_bytes0 = body_buf[pos: pos + 4]
                pos += 4

@rainx rainx closed this as completed Sep 1, 2017
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

1 participant