Git Product home page Git Product logo

Comments (12)

rainx avatar rainx commented on July 23, 2024

修复了,对期货了解不多,简单看了一下数据的结构,类似是这样的,

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.

rainx avatar rainx commented on July 23, 2024

@zzeric 请帮忙验证一下

from pytdx.

zzeric avatar zzeric commented on July 23, 2024

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.

rainx avatar rainx commented on July 23, 2024

@zzeric 多谢..

from pytdx.

zzeric avatar zzeric commented on July 23, 2024

get_history_transaction_data也有同样的问题

from pytdx.

zzeric avatar zzeric commented on July 23, 2024

`# 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.

zzeric avatar zzeric commented on July 23, 2024

`# 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.

rainx avatar rainx commented on July 23, 2024

收到... 感谢..

from pytdx.

rainx avatar rainx commented on July 23, 2024

创建了新的分支 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.

rainx avatar rainx commented on July 23, 2024

@zzeric

from pytdx.

zzeric avatar zzeric commented on July 23, 2024

GetTransactionData是当天的, 港股没试过

from pytdx.

rainx avatar rainx commented on July 23, 2024

已经修复并合并到主干了, 后续升级的时候会一起发布

from pytdx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.