当前位置:网站首页>量化交易之数字货币篇 - 通过时间戳与方向来合并逐笔成交数据(大单合并)
量化交易之数字货币篇 - 通过时间戳与方向来合并逐笔成交数据(大单合并)
2022-07-26 16:05:00 【Post-Truth】
import csv
from source_data.tqz_load_source_data import TQZSourceData
import tqdm
from public_module.tqz_extern.tools.file_path_operator.file_path_operator import TQZFilePathOperator
import datetime
# from public_module.tqz_extern.tools.pandas_operator.pandas_operator import pandas
if __name__ == '__main__':
symbol = 'BTCUSDT'
start_date, end_date = datetime.datetime.strptime("2022-05-03", '%Y-%m-%d').date(), datetime.datetime.strptime("2022-07-24", '%Y-%m-%d').date()
digital_point_counts = 1
qty_digital_point_counts = 3
quoteQty_digital_point_counts = 2
while True:
if start_date > end_date:
break
trades_file = f'F:/tqz_test/{symbol}-trades-{str(start_date)}.csv'
merge_trades_path = f'F:/tqz_test/{symbol}-mergeTrades-{str(start_date)}.csv'
current_timestamp = None
row_data_map = {'buy_qty': 0, 'sell_qty': 0, 'buy_quoteQty': 0, 'sell_quoteQty': 0}
with open(trades_file, 'rt') as update_file:
csv_reader_file = csv.reader(update_file)
for row in tqdm.tqdm(csv_reader_file):
# 1. write row_data & update current_timestamp
if current_timestamp != row[4]:
# 1.1 write to csv
if current_timestamp is not None:
with open(merge_trades_path, 'a', newline="") as _file:
if row_data_map['buy_qty'] != 0:
csv.writer(_file).writerow([
str(round(row_data_map['buy_quoteQty'] / row_data_map['buy_qty'], digital_point_counts)),
str(round(row_data_map['buy_qty'], qty_digital_point_counts)),
str(round(row_data_map['buy_quoteQty'], quoteQty_digital_point_counts)),
current_timestamp,
'true'
])
if row_data_map['sell_qty'] != 0:
csv.writer(_file).writerow([
str(round(row_data_map['sell_quoteQty'] / row_data_map['sell_qty'], digital_point_counts)),
str(round(row_data_map['sell_qty'], qty_digital_point_counts)),
str(round(row_data_map['sell_quoteQty'], quoteQty_digital_point_counts)),
current_timestamp,
'false'
])
row_data_map = {'buy_qty': 0, 'sell_qty': 0, 'buy_quoteQty': 0, 'sell_quoteQty': 0}
else:
with open(merge_trades_path, 'a', newline="") as _file:
csv.writer(_file).writerow(['price', 'qty', 'quoteQty', 'datetime', 'isBuyerMaker'])
# 1.2 update current_timestamp
current_timestamp = row[4]
# 2. update row_data_map
if row[5] == 'true':
row_data_map['buy_qty'] += float(row[2])
row_data_map['buy_quoteQty'] += float(row[3])
else:
row_data_map['sell_qty'] += float(row[2])
row_data_map['sell_quoteQty'] += float(row[3])
start_date += datetime.timedelta(days=1)
边栏推荐
- 物联网工业级串口转WiFi转网口转以太网模块的选型
- 提问征集丨快来向NLLB作者提问啦!(智源Live第24期)
- ACL-IJCAI-SIGIR顶级会议论文报告会(AIS 2022)笔记3:对话和生成
- 朋友圈如何测试(思维导图)
- First knowledge of OpenGL (2) compilation shaders
- Parker pump pv140r1k1t1pmmc
- 2021年软件测试工具趋势
- A firefox/chrome plug-in that visualizes browser history
- Jmeter快速上手之接口测试
- There are six ways to help you deal with the simpledateformat class, which is not a thread safety problem
猜你喜欢

互联网协议
![[BJDCTF2020]Easy MD5](/img/6a/61a4b5624c33f1f334bea344cfa2c8.png)
[BJDCTF2020]Easy MD5
![[tool sharing] automatic generation of file directory structure tool mddir](/img/bc/1071c0dfb20d16f5fdde641092c1af.png)
[tool sharing] automatic generation of file directory structure tool mddir

Pat grade a 1048 find coins

Pat grade a 1050 string subtraction

Implementation of personalized healthy diet recommendation system based on SSM

Test cases should never be used casually, recording the thinking caused by the exception of a test case

博途PLC顺序开关机功能块(SCL)
![[physical simulation] the principle and practice of the simplest shape matching](/img/1e/d91ed992bc648d90d0c68bfe541d7e.jpg)
[physical simulation] the principle and practice of the simplest shape matching

Bugku login2
随机推荐
Understand │ XSS attack, SQL injection, CSRF attack, DDoS attack, DNS hijacking
ZABBIX 6.2.0 deployment
Pat grade a 1046 shortest distance
想让照片中的云飘起来?视频编辑服务一键动效3步就能实现
zabbix 6.2.0部署
How to test the circle of friends (mind map)
“核弹级” Log4j 漏洞仍普遍存在,并造成持续影响
Modify the password of the root user of MySQL database
Comprehensively design an oppe homepage -- Design of star models
【ARM学习(9) arm 编译器了解学习(armcc/armclang)】
Taishan Office Technology Lecture: the zoom ratio of word is slightly different from the display
Yushenle's learning record: the first project of SOC FPGA -hello world
“卡片笔记法”在思源的具体实践案例
[BJDCTF2020]Easy MD5
《硅谷之谜》读后感
哪本书才是编程领域的“九阴真经”
研发效能的道与术 - 道篇
最终一致性性分布式事务 TCC
Specific practice cases of "card note taking method" in Siyuan
First knowledge of OpenGL (2) compilation shaders