Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/SII-WANGZJ/Polymarket_data
/ functions
Functions
97 in github.com/SII-WANGZJ/Polymarket_data
⨍
Functions
97
◇
Types & classes
8
↓ 27 callers
Function
log
带时间戳的日志输出,立即 flush
polymarket/tools/sort_parquet.py:52
↓ 11 callers
Function
load_token_mapping
从 markets parquet 加载 token 映射 返回: token_id -> {market_id, condition_id, side, question}
polymarket/processors/trades.py:168
↓ 9 callers
Method
write_batch
追加写入一批数据
polymarket/tools/continuous_fetch.py:112
↓ 7 callers
Function
close_writers
关闭所有 writers,确保数据写入磁盘
polymarket/cli/main.py:232
↓ 7 callers
Function
extract_trades
从事件中提取交易数据 只保留: - 两个交易所合约 (CTF_EXCHANGE, NEGRISK_CTF_EXCHANGE) 的 - OrderFilled 事件 Args: events: 解码后的事件列表 token_
polymarket/processors/trades.py:29
↓ 6 callers
Function
save_progress
保存进度和数据
polymarket/cli/main.py:630
↓ 4 callers
Function
clean_trades_df
清洗单个 trades DataFrame(用于增量处理) Args: trades_df: 原始 trades DataFrame Returns: 清洗后的 quant DataFrame
polymarket/processors/cleaner.py:358
↓ 4 callers
Function
clean_users_df
清洗单个 trades DataFrame 生成 users 数据(用于增量处理) Args: trades_df: 原始 trades DataFrame Returns: 清洗后的 users DataFrame
polymarket/processors/cleaner.py:372
↓ 3 callers
Method
_parse_json
(self, value: Any)
polymarket/fetchers/gamma.py:134
↓ 3 callers
Method
fetch_range_in_batches
分批获取 返回: List[Dict]: 成功时返回记录列表(可能为空) None: RPC 请求失败时返回 None
polymarket/fetchers/rpc.py:220
↓ 3 callers
Method
get_markets
获取市场列表
polymarket/fetchers/gamma.py:63
↓ 3 callers
Function
save_last_block
保存最后处理的区块到state.json
polymarket/cli/main.py:113
↓ 2 callers
Method
_parse_market
解析市场数据
polymarket/fetchers/gamma.py:99
↓ 2 callers
Function
_process_trades_batch
处理交易数据批次 1. 过滤NaN价格和合约地址 2. 统一YES视角
polymarket/processors/cleaner.py:106
↓ 2 callers
Function
_process_users_batch
处理用户数据批次 1. 过滤NaN价格和合约地址 2. 拆分maker/taker 3. 统一YES视角 4. 统一方向(SELL转BUY,token_amount取负)
polymarket/processors/cleaner.py:39
↓ 2 callers
Method
_request
发送请求
polymarket/fetchers/gamma.py:30
↓ 2 callers
Function
cleanup_temp
清理 DuckDB 临时文件
polymarket/tools/sort_parquet.py:71
↓ 2 callers
Function
cmd_clean
运行所有数据清洗
polymarket/cli/main.py:1129
↓ 2 callers
Function
cmd_clean_trades
清洗交易数据(量化用)
polymarket/cli/main.py:1107
↓ 2 callers
Function
cmd_clean_users
清洗用户数据
polymarket/cli/main.py:1085
↓ 2 callers
Function
cmd_fetch_markets
增量获取新市场(高频运行,如每小时) 特性: - 增量获取新市场,不重复获取已有市场 - 支持安全退出(Ctrl+C) - 支持断点续传(--continue) - 市场数据较小,直接内存操作后一次性保存
polymarket/cli/main.py:416
↓ 2 callers
Function
cmd_fetch_onchain
获取链上数据(增量模式) 特性: - 使用 PyArrow 流式写入,不读取历史数据 - 支持安全退出(Ctrl+C) - 支持断点续传(--continue)
polymarket/cli/main.py:137
↓ 2 callers
Function
cmd_process
处理交易数据(带 market_id 关联和缺失 token 补全) 警告:此命令会一次性读取全部数据,仅适用于小数据集! 对于大数据集(>1GB),请使用 process-historical 命令。
polymarket/cli/main.py:1009
↓ 2 callers
Method
decode
解码 OrderFilled 事件
polymarket/processors/decoder.py:35
↓ 2 callers
Method
decode_batch
批量解码
polymarket/processors/decoder.py:63
↓ 2 callers
Method
fetch_and_process_range
获取并处理一个区块范围
polymarket/tools/continuous_fetch.py:260
↓ 2 callers
Method
format_batch
批量格式化
polymarket/processors/decoder.py:102
↓ 2 callers
Method
format_event
格式化 OrderFilled 事件为输出格式
polymarket/processors/decoder.py:67
↓ 2 callers
Method
get_block_timestamp
获取区块时间戳
polymarket/fetchers/rpc.py:59
↓ 2 callers
Method
get_latest_block
获取链上最新区块号
polymarket/tools/continuous_fetch.py:251
↓ 2 callers
Method
get_latest_block
(self)
polymarket/fetchers/rpc.py:245
↓ 2 callers
Method
get_market_by_token
通过 token_id 获取市场
polymarket/fetchers/gamma.py:163
↓ 2 callers
Function
get_memory_limit_gb
获取可用内存的一半作为限制
polymarket/tools/sort_parquet.py:80
↓ 2 callers
Function
get_temp_dir
获取临时目录 - 集群用 SSD,本地用项目目录
polymarket/tools/sort_parquet.py:57
↓ 2 callers
Function
main
()
polymarket/cli/main.py:1223
↓ 2 callers
Method
save_state
保存当前处理到的区块号
polymarket/tools/continuous_fetch.py:239
↓ 2 callers
Method
test_connection
(self)
polymarket/fetchers/gamma.py:157
↓ 1 callers
Method
_decode_data
解码 data 字段
polymarket/processors/decoder.py:120
↓ 1 callers
Method
_decode_topic
解码 topic
polymarket/processors/decoder.py:106
↓ 1 callers
Function
_parse_order_filled
解析 OrderFilled 事件
polymarket/processors/trades.py:68
↓ 1 callers
Method
_process_log
处理单个日志
polymarket/fetchers/rpc.py:164
↓ 1 callers
Function
_sort_with_best_method
使用最佳可用方法进行排序
polymarket/processors/cleaner.py:135
↓ 1 callers
Method
_update_csv_preview
更新 CSV 预览文件
polymarket/tools/continuous_fetch.py:165
↓ 1 callers
Method
batch_get_timestamps
批量获取时间戳
polymarket/fetchers/rpc.py:72
↓ 1 callers
Function
clean_trades
清洗交易数据 Args: input_path: 输入 trades.parquet 路径 output_path: 输出 quant.parquet 路径 batch_size: 批处理大小 test_rows:
polymarket/processors/cleaner.py:276
↓ 1 callers
Function
clean_users
清洗用户交易数据 Args: input_path: 输入 trades.parquet 路径 output_path: 输出 users.parquet 路径 batch_size: 批处理大小 test_rows
polymarket/processors/cleaner.py:184
↓ 1 callers
Method
close_all
关闭所有 writer
polymarket/tools/continuous_fetch.py:175
↓ 1 callers
Function
cmd_merge_sessions
合并所有 session 文件到主文件
polymarket/cli/main.py:1164
↓ 1 callers
Function
cmd_process_historical
分批处理历史数据(用于大文件,避免内存溢出) 使用方式: python3 run.py process-historical --batch-size 1000000 python3 run.py process-historical --continue
polymarket/cli/main.py:703
↓ 1 callers
Function
cmd_update
全量更新
polymarket/cli/main.py:1140
↓ 1 callers
Function
cmd_update_markets
更新未closed市场的状态(低频运行,如每周) 特性: - 只更新未closed的市场 - 支持安全退出(Ctrl+C) - 支持断点续传(--continue) - 市场数据较小,需要加载全部用于更新 注意:市场文件较小(~60MB),需要完整
polymarket/cli/main.py:560
↓ 1 callers
Function
convert_batch_to_target_schema
将 batch 转换为目标 schema Args: batch: RecordBatch target_schema: 目标 schema Returns: 转换后的 RecordBatch
polymarket/tools/merge_orderfilled.py:25
↓ 1 callers
Method
estimate_timestamps
估算时间戳(减少 RPC 调用)
polymarket/fetchers/rpc.py:79
↓ 1 callers
Method
fetch_all_markets
获取所有市场
polymarket/fetchers/gamma.py:90
↓ 1 callers
Method
fetch_block_range
获取指定区块范围的日志 返回: List[Dict]: 成功时返回记录列表(可能为空) None: RPC 请求失败时返回 None
polymarket/fetchers/rpc.py:110
↓ 1 callers
Method
fetch_missing_tokens
批量获取缺失的 token 对应的市场
polymarket/fetchers/gamma.py:171
↓ 1 callers
Function
find_missing_tokens
找出交易中没有映射的 token
polymarket/processors/trades.py:227
↓ 1 callers
Function
get_last_block
获取上次处理的区块 优先级: 1. STATE_FILE 中的 last_block(最准确,记录了实际处理到的区块) 2. orderfilled.parquet 中的最大 block_number(备用) 3. 返回 0(首次运行)
polymarket/cli/main.py:73
↓ 1 callers
Method
get_logs
获取区块范围内的 OrderFilled 日志 返回: List[Dict]: 成功时返回日志列表(可能为空) None: RPC 请求失败时返回 None
polymarket/fetchers/rpc.py:40
↓ 1 callers
Function
get_rpc_url
获取 RPC URL
polymarket/config.py:53
↓ 1 callers
Method
iter_all_markets
迭代获取所有市场
polymarket/fetchers/gamma.py:76
↓ 1 callers
Method
load_state
加载上次处理到的区块号
polymarket/tools/continuous_fetch.py:227
↓ 1 callers
Function
main
()
polymarket/tools/refetch_failed_blocks.py:50
↓ 1 callers
Function
main
()
polymarket/tools/merge_orderfilled.py:166
↓ 1 callers
Function
main
()
polymarket/tools/merge_parquet.py:172
↓ 1 callers
Function
main
()
polymarket/tools/continuous_fetch.py:409
↓ 1 callers
Function
main
()
polymarket/tools/sort_parquet.py:253
↓ 1 callers
Function
merge_orderfilled_files
合并两个 orderfilled 文件 Args: file1: 第一个文件(需要转换 schema) file2: 第二个文件(作为 schema 基准) output_file: 输出文件 auto_yes: 自
polymarket/tools/merge_orderfilled.py:71
↓ 1 callers
Function
merge_parquet_files
合并多个 parquet 文件 Args: input_files: 输入文件列表(按顺序) output_file: 输出文件路径 dry_run: 是否只显示信息不实际合并 auto_yes: 自动确认覆盖
polymarket/tools/merge_parquet.py:29
↓ 1 callers
Function
merge_session_files
合并所有session文件到主文件
polymarket/cli/main.py:850
↓ 1 callers
Function
merge_temp_files
合并当前 session 文件到主文件(仅当前 session)
polymarket/cli/main.py:244
↓ 1 callers
Function
read_failed_blocks
读取失败区块列表
polymarket/tools/refetch_failed_blocks.py:38
↓ 1 callers
Function
record_failed_block
记录失败的区块范围
polymarket/cli/main.py:281
↓ 1 callers
Method
run
主循环:持续获取新区块
polymarket/tools/continuous_fetch.py:303
↓ 1 callers
Function
save_preview_csv
保存最新 N 条交易为 CSV 预览(保留所有字段)
polymarket/processors/trades.py:242
↓ 1 callers
Function
setup_logging
设置日志,输出到控制台和文件
polymarket/cli/main.py:43
↓ 1 callers
Function
sort_quant_parquet
排序 quant.parquet 排序优先级: 1. event_id, 2. market_id, 3. timestamp
polymarket/tools/sort_parquet.py:171
↓ 1 callers
Function
sort_users_parquet
排序 users.parquet 排序优先级: 1. user, 2. timestamp
polymarket/tools/sort_parquet.py:91
Method
__init__
(self, output_dir, session_timestamp, preview_size=1000)
polymarket/tools/continuous_fetch.py:58
Method
__init__
(self, output_dir, batch_size=100)
polymarket/tools/continuous_fetch.py:191
Method
__init__
(self, use_alchemy: bool = False)
polymarket/fetchers/rpc.py:27
Method
__init__
(self, use_alchemy: bool = False)
polymarket/fetchers/rpc.py:104
Method
__init__
(self, timeout: int = 60, max_retries: int = 5)
polymarket/fetchers/gamma.py:20
Method
__init__
(self)
polymarket/processors/decoder.py:32
Method
__init__
(self, token_mapping: Optional[Dict[str, Dict]] = None)
polymarket/processors/trades.py:257
Method
__init__
(self, markets_file=None)
polymarket/processors/trades.py:271
Method
_signal_handler
处理停止信号
polymarket/tools/continuous_fetch.py:222
Method
add_markets
添加新市场到映射
polymarket/processors/trades.py:277
Method
build_from_events
(self, events: List[Dict])
polymarket/processors/trades.py:260
Function
get_event_name
根据签名获取事件名
polymarket/config.py:115
Method
get_latest_block
(self)
polymarket/fetchers/rpc.py:37
Method
get_market
(self, token_id: str)
polymarket/processors/trades.py:274
Method
get_token_mapping
创建 token_id -> market 映射
polymarket/fetchers/gamma.py:144
Function
signal_handler
(signum, frame)
polymarket/cli/main.py:208
Method
test_connection
(self)
polymarket/fetchers/rpc.py:93
Method
test_connection
(self)
polymarket/fetchers/rpc.py:248
Method
to_dataframe
(self, trades: List[Dict])
polymarket/processors/trades.py:264