当前位置:网站首页>Digital currency of quantitative transactions - merge transaction by transaction data through timestamp and direction (large order consolidation)
Digital currency of quantitative transactions - merge transaction by transaction data through timestamp and direction (large order consolidation)
2022-07-26 16:28: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)
边栏推荐
- 终于有人把红蓝对抗讲明白了
- Development daily summary (11): file upload function improvement: Chinese character detection and text content processing
- 我的sql没问题为什么还是这么慢|MySQL加锁规则
- Want the clouds in the picture to float? Video editing services can be achieved in three steps with one click
- Finally, someone explained the red blue confrontation clearly
- Which book is the "the Nine Yin Manual" in the field of programming
- 阿里云DMS MySQL云数据库建表报错,求解!!
- srec_cat 常用参数的使用
- Sql语句——单行注释与多行注释
- Linux安装mysql8.0.29详细教程
猜你喜欢
![[BJDCTF2020]Easy MD5](/img/6a/61a4b5624c33f1f334bea344cfa2c8.png)
[BJDCTF2020]Easy MD5

Finally, someone explained the red blue confrontation clearly
![[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

PAT甲级 1050 String Subtraction

Re9:读论文 DEAL Inductive Link Prediction for Nodes Having Only Attribute Information

我的sql没问题为什么还是这么慢|MySQL加锁规则

Pat grade a 1049 counting ones

Pat grade a 1044 shopping in Mars

PAT甲级1048 Find Coins

2022 Niuke summer multi school training camp 1 (acdgij)
随机推荐
2022年最新北京建筑安全员模拟题库及答案
Advanced CAD exercises (I)
A preliminary understanding of MVC and ECS design architectures
Pat grade a 1048 find coins
Internet Protocol
kubernetes之ReplicationController与ReplicaSet
Docker install redis? How to configure persistence policy?
【物理模拟】最简单的shape matching的原理与实践
Build resume editor based on Nocode
综合设计一个OPPE主页--顶部,头部的设计
Pat grade a 1045 favorite color stripe
NUC 11构建 ESXi 7.0.3f安装网卡驱动-V2(2022年7月升级版)
“核弹级” Log4j 漏洞仍普遍存在,并造成持续影响
C语言重点知识总结
A firefox/chrome plug-in that visualizes browser history
Want the clouds in the picture to float? Video editing services can be achieved in three steps with one click
【Flutter -- 进阶】打包
NUC 11 build esxi 7.0.3f install network card driver-v2 (upgraded version in July 2022)
Reflections on the mystery of Silicon Valley
Clojure Web Development -- ring user guide