Comments (12)
修复了,对期货了解不多,简单看了一下数据的结构,类似是这样的,
nature字段的值分为3类 10000以下, 10000 to 20000 , 20000 to 30000, 所以可以通过 //10000将数据分类,我把这个字段拆成了 nature_mark = nature // 10000 , nature_value = nature % 10000 两个字段..
具体的含义您可以再帮忙看看,期货的我的确不太了解.. 已经更新的代码到 1.30了
https://github.com/rainx/pytdx/blob/master/ChangeLog.md
In [14]: print(api.to_df(api.get_transaction_data(30, "RB1709")))
hour minute price volume zengcang nature nature_mark \
0 20 59 4122000 8 -8 20000 2
1 21 0 4101000 2 2 10001 1
2 21 0 4072000 24 0 10003 1
3 21 0 4079000 2 0 10013 1
4 21 0 4080000 2 0 14 0
5 21 0 4089000 2 -2 36 0
nature_value
0 0
1 1
2 3
3 13
4 14
5 36
from pytdx.
@zzeric 请帮忙验证一下
from pytdx.
nature_value对应的是秒
nature_mark对应的行情软件里性质栏的颜色 0红色 1绿色 2白色
0红 and zengcang > 0 #多开
0红 and zengcang < 0 and volume == abs(zengcang) #双平
0红 and zengcang < 0 and volume > abs(zengcang) #空平
0红 and zengcang == 0 #多换
1绿 and zengcang > 0 #空开
1绿 and zengcang < 0 and volume == abs(zengcang) #双平
1绿 and zengcang < 0 and volume > abs(zengcang) #多平
1绿 and zengcang == 0 #空换
2白 and zengcang > 0 and volume > zengcang #开仓
2白 and zengcang > 0 and volume == zengcang #双开
2白 and zengcang == 0 #换手
2白 and zengcang < 0 and volume > abs(zengcang) #平仓
2白 and zengcang < 0 and volume == abs(zengcang) #双平
from pytdx.
@zzeric 多谢..
from pytdx.
get_history_transaction_data也有同样的问题
from pytdx.
`# coding=utf-8
from pytdx.parser.base import BaseParser
from pytdx.helper import get_datetime, get_volume, get_price, get_time
from collections import OrderedDict
import struct
import six
class GetTransactionData(BaseParser):
def setParams(self, market, code, start, count):
if type(code) is six.text_type:
code = code.encode("utf-8")
pkg = bytearray.fromhex('01 01 08 00 03 01 12 00 12 00 fc 23')
pkg.extend(struct.pack("<B9siH", market, code, start, count))
self.send_pkg = pkg
self.date = date
def parseResponse(self, body_buf):
pos = 0
market, code, _, num = struct.unpack('<B9s4sH', body_buf[pos: pos + 16])
pos += 16
result = []
for i in range(num):
(raw_time, price, volume, zengcang, nature) = struct.unpack("<HIIiH", body_buf[pos: pos + 16])
pos += 16
year = self.date // 10000
month = self.date % 10000 // 100
day = self.date % 100
hour = raw_time // 60
minute = raw_time % 60
second = direction % 10000
from datetime import datetime
date = datetime(year,month,day,hour,minute,second)
value = direction // 10000
if value == 0:
direction = 1
if zengcang > 0:
nature = "多开"
elif zengcang == 0:
nature = "多换"
else:
if volume == -zengcang:
nature = "双平"
else:
nature = "空平"
elif value == 1:
direction = -1
if zengcang > 0:
nature = "空开"
elif zengcang == 0:
nature = "空换"
else:
if volume == -zengcang:
nature = "双平"
else:
nature = "多平"
else:
direction = 0
if zengcang> 0:
if volume > zengcang:
nature = "开仓"
elif volume == zengcang:
nature = "双开"
elif zengcang < 0:
if volume > -zengcang:
nature = "平仓"
elif volume == -zengcang:
nature = "双平"
else:
nature = "换手"
result.append(OrderedDict([
("date", date),
("price", price),
("volume", volume),
("zengcang", zengcang),
("direction",direction ),
("nature",nature)
]))
return result
`
from pytdx.
`# coding=utf-8
from pytdx.parser.base import BaseParser
from pytdx.helper import get_datetime, get_volume, get_price
from collections import OrderedDict
import struct
class GetHistoryTransactionData(BaseParser):
def setParams(self, market, code, date, start, count):
# if type(code) is six.text_type:
code = code.encode("utf-8")
# if type(date) is (type(date) is six.text_type) or (type(date) is six.binary_type):
# date = int(date)
# pkg1 = bytearray.fromhex('01 01 30 00 02 01 16 00 16 00 06 24 3b c8 33 01 1f 30 30 30 32 30 00 00 00 01 00 00 00 00 f0 00')
pkg = bytearray.fromhex('01 01 30 00 02 01 16 00 16 00 06 24')
pkg.extend(struct.pack("<IB9siH", date, market, code, start, count))
self.send_pkg = pkg
self.date = date
def parseResponse(self, body_buf):
pos = 0
market, code, _, num = struct.unpack('<B9s4sH', body_buf[pos: pos + 16])
pos += 16
result = []
for i in range(num):
(raw_time, price, volume, zengcang, direction) = struct.unpack("<HIIiH", body_buf[pos: pos + 16])
pos += 16
year = self.date // 10000
month = self.date % 10000 // 100
day = self.date % 100
hour = raw_time // 60
minute = raw_time % 60
second = direction % 10000
from datetime import datetime
date = datetime(year,month,day,hour,minute,second)
value = direction // 10000
if value == 0:
direction = 1
if zengcang > 0:
nature = "多开"
elif zengcang == 0:
nature = "多换"
else:
if volume == -zengcang:
nature = "双平"
else:
nature = "空平"
elif value == 1:
direction = -1
if zengcang > 0:
nature = "空开"
elif zengcang == 0:
nature = "空换"
else:
if volume == -zengcang:
nature = "双平"
else:
nature = "多平"
else:
direction = 0
if zengcang> 0:
if volume > zengcang:
nature = "开仓"
elif volume == zengcang:
nature = "双开"
elif zengcang < 0:
if volume > -zengcang:
nature = "平仓"
elif volume == -zengcang:
nature = "双平"
else:
nature = "换手"
result.append(OrderedDict([
("date", date),
("price", price),
("volume", volume),
("zengcang", zengcang),
("direction",direction ),
("nature",nature)
]))
return result
`
from pytdx.
收到... 感谢..
from pytdx.
创建了新的分支 https://github.com/rainx/pytdx/tree/fix_issue_31 处理此问题, 简单测试了一下代码
1 不知道第一段 GetTransactionData 里的date 代表什么,当日的时间么?我在获取当日行情的时候加了second字段, 因为不确定 GetTransactionData 是否就是只限于获取当日的行情(目前看来应该是获取当日的,保守期间暂时还没有加)
2 由于扩展行情的品类比较多,有一些品类,如港股, second = direction % 10000 会得到 512 ,这样在进行 date = datetime(year,month,day,hour,minute,second) 操作的时候会出错,所以修改了一下。
3 由于已经有不少人在使用这个接口返回的数据,所以暂时对原油的字段就不做修改了,增加了natrue_name 字段,来保存类似 平仓 空开 空换 等信息。
代码在:
https://github.com/rainx/pytdx/blob/fix_issue_31/pytdx/parser/ex_get_history_transaction_data.py
https://github.com/rainx/pytdx/blob/fix_issue_31/pytdx/parser/ex_get_transaction_data.py
请帮忙验证
from pytdx.
from pytdx.
GetTransactionData是当天的, 港股没试过
from pytdx.
已经修复并合并到主干了, 后续升级的时候会一起发布
from pytdx.
Related Issues (20)
- 扩展行情的IP都没有可以连接的。 HOT 1
- 扩展行情里面有没有可以获取多个行情quotes的接口?
- get_security_list 请问一下这个是用来获取股票列表的吗? HOT 2
- 请教一下下载的财务数据的 315个列字段的意义问题. HOT 1
- get_security_list这个函数的pre_close有误 HOT 10
- get_security_bars取出来的vol值差了1个 HOT 4
- 跳过的4个字节估计是上一日收盘价
- get_security_list获取的数据中的pre_close有解析正确有些解析不正确 HOT 1
- 不支持美股了?
- AttributeError: __enter__
- 怎么获取行情服务器的IP HOT 1
- 官方文档代码某行缺失 HOT 1
- 请问有办法获取涨停价和跌停价吗 HOT 1
- 可以获取level2的逐笔成交明细吗? HOT 1
- 心跳包还有多线程有没有详细的文档解释? HOT 1
- TdxDailyBarReader() 读取 上海 688 的时候,异常 Unknown security type ! HOT 1
- 盘口价格是不是颠倒了 HOT 1
- exhq.py文件 运行报错 AttributeError: __enter__
- debian python 3.7 get_security_quotes 解析 servertime 报错 HOT 2
- 如何判断股票代码是否指数
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytdx.