openfund-core 0.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openfund/core/__init__.py +0 -0
- openfund/core/binance_tools/__init__.py +16 -0
- openfund/core/binance_tools/binance_tools.py +39 -0
- openfund/core/binance_tools/continuous_klines.py +147 -0
- openfund/core/factory.py +37 -0
- openfund/core/libs/__init__.py +6 -0
- openfund/core/libs/email_tools.py +56 -0
- openfund/core/libs/enums.py +507 -0
- openfund/core/libs/file_tools.py +13 -0
- openfund/core/libs/log_tools.py +45 -0
- openfund/core/libs/prepare_env.py +28 -0
- openfund/core/libs/time.py +14 -0
- openfund/core/libs/time_tools.py +22 -0
- openfund/core/openfund_old/__init__.py +0 -0
- openfund/core/openfund_old/continuous_klines.py +153 -0
- openfund/core/openfund_old/depth.py +92 -0
- openfund/core/openfund_old/historical_trades.py +123 -0
- openfund/core/openfund_old/index_info.py +67 -0
- openfund/core/openfund_old/index_price_kline.py +118 -0
- openfund/core/openfund_old/klines.py +95 -0
- openfund/core/openfund_old/klines_qrr.py +103 -0
- openfund/core/openfund_old/mark_price.py +121 -0
- openfund/core/openfund_old/mark_price_klines.py +122 -0
- openfund/core/openfund_old/ticker_24hr_price_change.py +99 -0
- openfund/core/pyopenfund.py +32 -0
- openfund/core/sample/__init__.py +1 -0
- openfund/core/sample/sample.py +20 -0
- openfund/core/sycu_exam/__init__.py +1 -0
- openfund/core/sycu_exam/exam.py +19 -0
- openfund/core/sycu_exam/random_grade_cplus.py +440 -0
- openfund/core/sycu_exam/random_grade_web.py +404 -0
- openfund_core-0.0.2.dist-info/LICENSE +201 -0
- openfund_core-0.0.2.dist-info/METADATA +66 -0
- openfund_core-0.0.2.dist-info/RECORD +35 -0
- openfund_core-0.0.2.dist-info/WHEEL +4 -0
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# from binance.spot import Spot
|
2
|
+
|
3
|
+
# client = Spot()
|
4
|
+
|
5
|
+
# Get server timestamp
|
6
|
+
# print(client.time())
|
7
|
+
# Get klines of BTCUSDT at 1m interval
|
8
|
+
# print(client.klines("BTCUSDT", "1m"))
|
9
|
+
# Get last 10 klines of BNBUSDT at 1h interval
|
10
|
+
# print(client.klines("BNBUSDT", "1h", limit=10))
|
11
|
+
|
12
|
+
# API key/secret are required for user data endpoints
|
13
|
+
# client = Spot(api_key='<api_key>', api_secret='<api_secret>')
|
14
|
+
|
15
|
+
# Get account and balance information
|
16
|
+
# print(client.account())
|
@@ -0,0 +1,39 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import logging
|
4
|
+
from poetry.utils.authenticator import Authenticator
|
5
|
+
|
6
|
+
from typing import TYPE_CHECKING
|
7
|
+
from binance.spot import Spot as Client
|
8
|
+
from openfund.core.pyopenfund import Openfund
|
9
|
+
|
10
|
+
|
11
|
+
tools = "binance"
|
12
|
+
logger = logging.getLogger(__name__)
|
13
|
+
|
14
|
+
|
15
|
+
class BinanceTools:
|
16
|
+
def __init__(self, openfund: Openfund) -> None:
|
17
|
+
logger.debug("######## BinanceTools init ########")
|
18
|
+
self._openfund: Openfund = openfund
|
19
|
+
self._password_manager = Authenticator(
|
20
|
+
self._openfund._poetry.config
|
21
|
+
)._password_manager
|
22
|
+
|
23
|
+
@property
|
24
|
+
def api_key(self) -> str:
|
25
|
+
return self._password_manager.get_http_auth(tools).get("username")
|
26
|
+
|
27
|
+
@property
|
28
|
+
def apk_secret(self) -> str:
|
29
|
+
return self._password_manager.get_http_auth(tools).get("password")
|
30
|
+
|
31
|
+
def get_time():
|
32
|
+
client = Client()
|
33
|
+
return client.time()
|
34
|
+
|
35
|
+
def get_account(self):
|
36
|
+
logger.debug("######## BinanceTools.get_account() ########")
|
37
|
+
logger.debug("######## BinanceTools api_key=%s ########", self.api_key)
|
38
|
+
client = Client(self.api_key, self.apk_secret)
|
39
|
+
return client.account()
|
@@ -0,0 +1,147 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
import csv
|
3
|
+
import logging
|
4
|
+
import time
|
5
|
+
|
6
|
+
from datetime import datetime
|
7
|
+
|
8
|
+
from binance.um_futures import UMFutures
|
9
|
+
from binance.um_futures import UMFutures
|
10
|
+
from binance.error import ClientError
|
11
|
+
|
12
|
+
from libs.time_tools import format_timestamp
|
13
|
+
from libs.file_tools import create_path
|
14
|
+
from libs.prepare_env import get_api_key, get_path
|
15
|
+
from libs import enums
|
16
|
+
|
17
|
+
# 数据路径、日志路径
|
18
|
+
data_path, log_path = get_path()
|
19
|
+
# client
|
20
|
+
um_futures_client = UMFutures()
|
21
|
+
# 合同类型
|
22
|
+
contractTypes = [type.value for type in enums.ContractType]
|
23
|
+
# 币种类型
|
24
|
+
# POOL = enums.CUR_SYMBOL_POOL
|
25
|
+
POOL = [
|
26
|
+
"BTCUSDT_240329",
|
27
|
+
"BLURUSDT",
|
28
|
+
"DYDXUSDT",
|
29
|
+
"ETHBTC",
|
30
|
+
"ETHBUSD",
|
31
|
+
"ETHUSDT",
|
32
|
+
"ETHUSDT_231229",
|
33
|
+
"ETHUSDT_240329",
|
34
|
+
"GMTBUSD",
|
35
|
+
"GMTUSDT",
|
36
|
+
"LTCBUSD",
|
37
|
+
"LTCUSDT",
|
38
|
+
"MATICBUSD",
|
39
|
+
"MATICUSDT",
|
40
|
+
"SOLBUSD",
|
41
|
+
"SOLUSDT",
|
42
|
+
]
|
43
|
+
interval = enums.KLINE_INTERVAL_5MINUTE
|
44
|
+
limit = 1500
|
45
|
+
errorLimit = 100
|
46
|
+
sleepSec = 10
|
47
|
+
|
48
|
+
# 历史截止数据开关
|
49
|
+
hisSwitch = 0
|
50
|
+
# hisSwitch 打开的情况下,抓取数据截止时间
|
51
|
+
hisDateTime = 1653974399999
|
52
|
+
|
53
|
+
for symbol in POOL:
|
54
|
+
fileName = "{}/continuous_klines_{}_{}.log".format(
|
55
|
+
log_path, symbol, format_timestamp(datetime.now().timestamp() * 1000)
|
56
|
+
)
|
57
|
+
# print(fileName)
|
58
|
+
logging.basicConfig(
|
59
|
+
format="%(asctime)s %(name)s:%(levelname)s:%(message)s",
|
60
|
+
datefmt="%Y-%m-%d %H:%M:%S",
|
61
|
+
level=logging.INFO,
|
62
|
+
filename=fileName,
|
63
|
+
)
|
64
|
+
logging.info("{} symbol 开始 ++++++++++++++++++++++++++++ ".format(symbol))
|
65
|
+
total = 0
|
66
|
+
for contractType in contractTypes:
|
67
|
+
latestRecords = 1
|
68
|
+
records = 0 # 累计记录数
|
69
|
+
queryTimes = 0 # 执行次数
|
70
|
+
nextEndTime = 0
|
71
|
+
errorCount = 0
|
72
|
+
params = {"limit": limit}
|
73
|
+
while latestRecords != 0: # 循环读取,直到记录为空
|
74
|
+
queryTimes = queryTimes + 1
|
75
|
+
if nextEndTime != 0:
|
76
|
+
params = {"limit": limit, "endTime": nextEndTime}
|
77
|
+
|
78
|
+
logging.info(
|
79
|
+
"1、{}-{} 第{}次开始执行...".format(symbol, contractType, queryTimes)
|
80
|
+
)
|
81
|
+
listData = []
|
82
|
+
try:
|
83
|
+
listData = um_futures_client.continuous_klines(
|
84
|
+
symbol, contractType, interval, **params
|
85
|
+
)
|
86
|
+
except KeyError as err:
|
87
|
+
print("KeyError:", err)
|
88
|
+
logging.error(err)
|
89
|
+
break
|
90
|
+
except ClientError as error:
|
91
|
+
logging.error(
|
92
|
+
"Found error. status: {}, error code: {}, error message: {}".format(
|
93
|
+
error.status_code, error.error_code, error.error_message
|
94
|
+
)
|
95
|
+
)
|
96
|
+
if error.error_code == -4144 and error.status_code == 400:
|
97
|
+
break
|
98
|
+
except Exception as e:
|
99
|
+
print("Error:", e)
|
100
|
+
logging.error(e)
|
101
|
+
errorCount = errorCount + 1
|
102
|
+
if errorCount > errorLimit:
|
103
|
+
break
|
104
|
+
else:
|
105
|
+
time.sleep(sleepSec)
|
106
|
+
continue
|
107
|
+
|
108
|
+
latestRecords = len(listData)
|
109
|
+
records = latestRecords + records
|
110
|
+
logging.info("2、{}条写入文件...".format(latestRecords))
|
111
|
+
|
112
|
+
path = "{}/continuous_klines/{}/{}/".format(data_path, symbol, contractType)
|
113
|
+
create_path(path) # 不存在路径进行呢创建
|
114
|
+
|
115
|
+
with open(
|
116
|
+
"{}continuous_klines_{}_{}_{}.csv".format(
|
117
|
+
path, symbol, contractType, interval
|
118
|
+
),
|
119
|
+
"a",
|
120
|
+
newline="",
|
121
|
+
) as file:
|
122
|
+
writer = csv.writer(file)
|
123
|
+
# 时间戳倒序,插入文件尾部
|
124
|
+
writer.writerows(sorted(listData, key=lambda x: x[0], reverse=True))
|
125
|
+
|
126
|
+
# 拿到最后一条记录后,获取close时间戳,变为下一次截止时间戳
|
127
|
+
if latestRecords > 0:
|
128
|
+
nextEndTime = (
|
129
|
+
listData[0][0] - 1
|
130
|
+
) # -1 不和close时间戳相同,避免重新拉取重复数据
|
131
|
+
errorCount = 0
|
132
|
+
logging.info(
|
133
|
+
"3、下次结束时间 {} {}".format(
|
134
|
+
format_timestamp(nextEndTime), nextEndTime
|
135
|
+
)
|
136
|
+
)
|
137
|
+
|
138
|
+
if nextEndTime <= hisDateTime and hisSwitch == 1:
|
139
|
+
break
|
140
|
+
else:
|
141
|
+
logging.info("4、结束...")
|
142
|
+
|
143
|
+
total = total + records
|
144
|
+
logging.info("5、{} 抓取数据 {} 条记录...".format(symbol, records))
|
145
|
+
|
146
|
+
logging.info("6、{} 抓取数据 {} 条记录...".format(symbol, total))
|
147
|
+
logging.info("{} symbol --------------------------------- ".format(symbol))
|
openfund/core/factory.py
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import logging
|
4
|
+
|
5
|
+
from pathlib import Path
|
6
|
+
from typing import TYPE_CHECKING
|
7
|
+
from poetry.factory import Factory as BaseFactory
|
8
|
+
from openfund.core.pyopenfund import Openfund
|
9
|
+
|
10
|
+
if TYPE_CHECKING:
|
11
|
+
from poetry.poetry import Poetry
|
12
|
+
|
13
|
+
|
14
|
+
logger = logging.getLogger(__name__)
|
15
|
+
|
16
|
+
|
17
|
+
class Factory(BaseFactory):
|
18
|
+
def __init__(self) -> None:
|
19
|
+
super().__init__()
|
20
|
+
|
21
|
+
def create_poetry(
|
22
|
+
self,
|
23
|
+
cwd: Path | None = None,
|
24
|
+
with_groups: bool = True,
|
25
|
+
) -> Poetry:
|
26
|
+
poetry = super().create_poetry(cwd=cwd, with_groups=with_groups)
|
27
|
+
return poetry
|
28
|
+
|
29
|
+
def create_openfund(
|
30
|
+
self,
|
31
|
+
cwd: Path | None = None,
|
32
|
+
with_groups: bool = True,
|
33
|
+
) -> Openfund:
|
34
|
+
|
35
|
+
poetry = self.create_poetry(cwd=cwd, with_groups=with_groups)
|
36
|
+
|
37
|
+
return Openfund(poetry)
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
import ssl
|
3
|
+
import os
|
4
|
+
import sys
|
5
|
+
import logging
|
6
|
+
|
7
|
+
import smtplib
|
8
|
+
|
9
|
+
from email.mime.text import MIMEText
|
10
|
+
|
11
|
+
from email.header import Header
|
12
|
+
from email.message import EmailMessage
|
13
|
+
import time
|
14
|
+
|
15
|
+
# app = "email_tools"
|
16
|
+
# logging.basicConfig(
|
17
|
+
# format="%(asctime)s %(name)s:%(levelname)s:%(message)s",
|
18
|
+
# datefmt="%Y-%m-%d %H:%M:%S",
|
19
|
+
# level=logging.DEBUG,
|
20
|
+
# )
|
21
|
+
|
22
|
+
curPath = os.path.abspath(os.path.dirname(__file__))
|
23
|
+
sys.path.append(curPath)
|
24
|
+
|
25
|
+
from prepare_env import get_mail
|
26
|
+
|
27
|
+
# logging.info("---- Read config.ini -----")
|
28
|
+
(email_address, email_password, email_receiver) = get_mail()
|
29
|
+
# logging.info(
|
30
|
+
# "---- Read config.ini Finish!----{0}||{1}".format(email_address, email_receiver)
|
31
|
+
# )
|
32
|
+
|
33
|
+
|
34
|
+
def mail(topic, content):
|
35
|
+
EMAIL_ADDRESS = email_address
|
36
|
+
EMAIL_PASSWORD = email_password
|
37
|
+
context = ssl.create_default_context()
|
38
|
+
sender = EMAIL_ADDRESS
|
39
|
+
receiver = email_receiver.split(",")
|
40
|
+
|
41
|
+
subject = topic
|
42
|
+
body = content
|
43
|
+
msg = EmailMessage()
|
44
|
+
msg["subject"] = subject
|
45
|
+
msg["From"] = sender
|
46
|
+
msg["To"] = receiver
|
47
|
+
msg.set_content(body)
|
48
|
+
|
49
|
+
with smtplib.SMTP_SSL("smtp.qq.com", 465, context=context) as smtp:
|
50
|
+
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
|
51
|
+
smtp.send_message(msg)
|
52
|
+
print("---- send_message ----\n{0}".format(msg))
|
53
|
+
|
54
|
+
|
55
|
+
if __name__ == "__main__":
|
56
|
+
mail("QRR", "BTCUSDT [2023-12-04 21:44:59 ~ 2023-12-04 21:39:59],QRR=9.4 > 5")
|