Skip to content

DataStruct transaction 模块

交易数据结构模块,提供股票和指数分时成交数据结构的实现。

模块结构

transaction.py

StockTransactionData

股票交易数据结构。

python
from FQData.DataStruct import StockTransactionData

tx_data = StockTransactionData(df)

初始化参数

参数类型说明
datapd.DataFrame分时成交数据

数据预处理

  • 自动计算 amount(如果不存在):volume * price * 100
  • 自动删除 _id 列(如果存在)

属性

属性类型说明
buyorsellpd.Series买卖方向 (0-买入, 1-卖出, 2-中性)
pricepd.Series成交价格
volume / volpd.Series成交量
amountpd.Series成交额
datepd.Series成交日期
datetimepd.Series成交时间
codepd.Series股票代码
timepd.Series成交时间(分钟级)
orderpd.Series委托订单号
indexpd.Index交易索引

方法

get_code

获取某只股票的交易数据。

python
stock_tx = tx_data.get_code('600000')

参数:

参数类型说明
codestr股票代码

返回: StockTransactionData


get_date

获取某一天的交易数据。

python
day_tx = tx_data.get_date('2024-01-01')

参数:

参数类型说明
datestr日期字符串

返回: StockTransactionData


get_time_range

获取时间范围内的交易数据。

python
range_tx = tx_data.get_time_range(
    start='2024-01-01 09:30:00',
    end='2024-01-01 15:00:00'
)

参数:

参数类型说明
startstr开始时间
endstr结束时间

返回: StockTransactionData


get_big_orders

获取大单(成交额大于等于阈值)。

python
big_tx = tx_data.get_big_orders(bigamount=1000000)

参数:

参数类型默认值说明
bigamountint1000000大单阈值

返回: StockTransactionData


get_medium_order

获取中等单(成交额在范围内)。

python
medium_tx = tx_data.get_medium_order(lower=200000, higher=1000000)

参数:

参数类型默认值说明
lowerint200000下限
higherint1000000上限

返回: StockTransactionData


get_small_order

获取小单(成交额小于等于阈值)。

python
small_tx = tx_data.get_small_order(smallamount=200000)

参数:

参数类型默认值说明
smallamountint200000小单阈值

返回: StockTransactionData


resample

重采样为分钟线。

python
min_tx = tx_data.resample('1min')

参数:

参数类型默认值说明
type_str'1min'分钟周期

返回: StockTransactionData


to_df

转换为 DataFrame。

python
df = tx_data.to_df()

返回: pd.DataFrame


IndexTransactionData

指数交易数据结构。

python
from FQData.DataStruct import IndexTransactionData

index_tx = IndexTransactionData(df)

与 StockTransactionData 接口相同


使用示例

基本使用

python
from FQData.DataStruct import StockTransactionData

tx_data = StockTransactionData(df)

print(f"成交数量: {len(tx_data)}")
print(f"买卖方向: {tx_data.buyorsell.value_counts()}")

筛选大单

python
big_orders = tx_data.get_big_orders(bigamount=5000000)
print(f"大单数量: {len(big_orders)}")

时间范围查询

python
morning_tx = tx_data.get_time_range(
    start='2024-01-01 09:30:00',
    end='2024-01-01 11:30:00'
)

重采样为分钟线

python
min_tx = tx_data.resample('1min')

相关文档