tickflow 0.1.0.dev1__tar.gz → 0.1.0.dev3__tar.gz
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.
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/PKG-INFO +8 -14
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/README.md +7 -13
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/pyproject.toml +1 -1
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow/resources/klines.py +15 -6
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow/resources/quotes.py +14 -1
- tickflow-0.1.0.dev3/tickflow/utils.py +53 -0
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow.egg-info/PKG-INFO +8 -14
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow.egg-info/SOURCES.txt +1 -0
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/setup.cfg +0 -0
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow/__init__.py +0 -0
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow/_base_client.py +0 -0
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow/_exceptions.py +0 -0
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow/_types.py +0 -0
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow/client.py +0 -0
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow/generated_model.py +0 -0
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow/resources/__init__.py +0 -0
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow/resources/_base.py +0 -0
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow/resources/exchanges.py +0 -0
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow/resources/instruments.py +0 -0
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow/resources/universes.py +0 -0
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow.egg-info/dependency_links.txt +0 -0
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow.egg-info/requires.txt +0 -0
- {tickflow-0.1.0.dev1 → tickflow-0.1.0.dev3}/tickflow.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tickflow
|
|
3
|
-
Version: 0.1.0.
|
|
3
|
+
Version: 0.1.0.dev3
|
|
4
4
|
Summary: TickFlow Python Client
|
|
5
5
|
Author: TickFlow Team
|
|
6
6
|
License: MIT
|
|
@@ -36,12 +36,6 @@ Requires-Dist: tqdm>=4.60.0; extra == "all"
|
|
|
36
36
|
|
|
37
37
|
## 安装
|
|
38
38
|
|
|
39
|
-
```bash
|
|
40
|
-
pip install tickflow
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
如需 DataFrame 支持和进度条功能:
|
|
44
|
-
|
|
45
39
|
```bash
|
|
46
40
|
pip install tickflow[all]
|
|
47
41
|
```
|
|
@@ -52,14 +46,14 @@ pip install tickflow[all]
|
|
|
52
46
|
from tickflow import TickFlow
|
|
53
47
|
|
|
54
48
|
# 初始化客户端
|
|
55
|
-
|
|
49
|
+
tf = TickFlow(api_key="your-api-key")
|
|
56
50
|
|
|
57
51
|
# 获取 K 线数据
|
|
58
|
-
df =
|
|
52
|
+
df = tf.klines.get("600000.SH", period="1d", count=100, as_dataframe=True)
|
|
59
53
|
print(df.tail())
|
|
60
54
|
|
|
61
55
|
# 获取实时行情
|
|
62
|
-
quotes =
|
|
56
|
+
quotes = tf.quotes.get(symbols=["600000.SH", "AAPL.US"])
|
|
63
57
|
for q in quotes:
|
|
64
58
|
print(f"{q['symbol']}: {q['last_price']}")
|
|
65
59
|
```
|
|
@@ -71,8 +65,8 @@ import asyncio
|
|
|
71
65
|
from tickflow import AsyncTickFlow
|
|
72
66
|
|
|
73
67
|
async def main():
|
|
74
|
-
async with AsyncTickFlow(api_key="your-api-key") as
|
|
75
|
-
df = await
|
|
68
|
+
async with AsyncTickFlow(api_key="your-api-key") as tf:
|
|
69
|
+
df = await tf.klines.get("600000.SH", as_dataframe=True)
|
|
76
70
|
print(df.tail())
|
|
77
71
|
|
|
78
72
|
asyncio.run(main())
|
|
@@ -82,8 +76,8 @@ asyncio.run(main())
|
|
|
82
76
|
|
|
83
77
|
```python
|
|
84
78
|
# 批量获取大量股票数据,自动分批并发请求
|
|
85
|
-
symbols =
|
|
86
|
-
df =
|
|
79
|
+
symbols = tf.exchanges.get_symbols("SH")[:500]
|
|
80
|
+
df = tf.klines.batch(
|
|
87
81
|
symbols,
|
|
88
82
|
period="1d",
|
|
89
83
|
as_dataframe=True,
|
|
@@ -4,12 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
7
|
-
```bash
|
|
8
|
-
pip install tickflow
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
如需 DataFrame 支持和进度条功能:
|
|
12
|
-
|
|
13
7
|
```bash
|
|
14
8
|
pip install tickflow[all]
|
|
15
9
|
```
|
|
@@ -20,14 +14,14 @@ pip install tickflow[all]
|
|
|
20
14
|
from tickflow import TickFlow
|
|
21
15
|
|
|
22
16
|
# 初始化客户端
|
|
23
|
-
|
|
17
|
+
tf = TickFlow(api_key="your-api-key")
|
|
24
18
|
|
|
25
19
|
# 获取 K 线数据
|
|
26
|
-
df =
|
|
20
|
+
df = tf.klines.get("600000.SH", period="1d", count=100, as_dataframe=True)
|
|
27
21
|
print(df.tail())
|
|
28
22
|
|
|
29
23
|
# 获取实时行情
|
|
30
|
-
quotes =
|
|
24
|
+
quotes = tf.quotes.get(symbols=["600000.SH", "AAPL.US"])
|
|
31
25
|
for q in quotes:
|
|
32
26
|
print(f"{q['symbol']}: {q['last_price']}")
|
|
33
27
|
```
|
|
@@ -39,8 +33,8 @@ import asyncio
|
|
|
39
33
|
from tickflow import AsyncTickFlow
|
|
40
34
|
|
|
41
35
|
async def main():
|
|
42
|
-
async with AsyncTickFlow(api_key="your-api-key") as
|
|
43
|
-
df = await
|
|
36
|
+
async with AsyncTickFlow(api_key="your-api-key") as tf:
|
|
37
|
+
df = await tf.klines.get("600000.SH", as_dataframe=True)
|
|
44
38
|
print(df.tail())
|
|
45
39
|
|
|
46
40
|
asyncio.run(main())
|
|
@@ -50,8 +44,8 @@ asyncio.run(main())
|
|
|
50
44
|
|
|
51
45
|
```python
|
|
52
46
|
# 批量获取大量股票数据,自动分批并发请求
|
|
53
|
-
symbols =
|
|
54
|
-
df =
|
|
47
|
+
symbols = tf.exchanges.get_symbols("SH")[:500]
|
|
48
|
+
df = tf.klines.batch(
|
|
55
49
|
symbols,
|
|
56
50
|
period="1d",
|
|
57
51
|
as_dataframe=True,
|
|
@@ -17,6 +17,10 @@ from typing import (
|
|
|
17
17
|
)
|
|
18
18
|
|
|
19
19
|
from .._types import NOT_GIVEN, NotGiven
|
|
20
|
+
from ..utils import (
|
|
21
|
+
instrument_timestamp_to_trade_date,
|
|
22
|
+
instrument_timestamp_to_trade_time,
|
|
23
|
+
)
|
|
20
24
|
from ._base import AsyncResource, SyncResource
|
|
21
25
|
|
|
22
26
|
if TYPE_CHECKING:
|
|
@@ -29,7 +33,8 @@ MAX_SYMBOLS_PER_BATCH = 100
|
|
|
29
33
|
|
|
30
34
|
|
|
31
35
|
def _klines_to_dataframe(
|
|
32
|
-
data: "CompactKlineData",
|
|
36
|
+
data: "CompactKlineData",
|
|
37
|
+
symbol: Optional[str] = None,
|
|
33
38
|
) -> "pd.DataFrame":
|
|
34
39
|
"""Convert compact K-line data to a pandas DataFrame.
|
|
35
40
|
|
|
@@ -39,7 +44,9 @@ def _klines_to_dataframe(
|
|
|
39
44
|
Compact columnar K-line data from the API.
|
|
40
45
|
symbol : str, optional
|
|
41
46
|
Symbol code to include as a column.
|
|
42
|
-
|
|
47
|
+
period : Period, optional
|
|
48
|
+
K-line period. One of: "1m", "5m", "10m", "15m", "30m", "60m",
|
|
49
|
+
"4h", "1d", "1w", "1M". Defaults to "1d".
|
|
43
50
|
Returns
|
|
44
51
|
-------
|
|
45
52
|
pd.DataFrame
|
|
@@ -51,6 +58,12 @@ def _klines_to_dataframe(
|
|
|
51
58
|
df = pd.DataFrame(
|
|
52
59
|
{
|
|
53
60
|
"timestamp": data["timestamp"],
|
|
61
|
+
"trade_date": [
|
|
62
|
+
instrument_timestamp_to_trade_date(symbol, x) for x in data["timestamp"]
|
|
63
|
+
],
|
|
64
|
+
"trade_time": [
|
|
65
|
+
instrument_timestamp_to_trade_time(symbol, x) for x in data["timestamp"]
|
|
66
|
+
],
|
|
54
67
|
"open": data["open"],
|
|
55
68
|
"high": data["high"],
|
|
56
69
|
"low": data["low"],
|
|
@@ -63,10 +76,6 @@ def _klines_to_dataframe(
|
|
|
63
76
|
if symbol:
|
|
64
77
|
df.insert(0, "symbol", symbol)
|
|
65
78
|
|
|
66
|
-
# Convert timestamp (milliseconds) to datetime
|
|
67
|
-
df["timestamp"] = pd.to_datetime(df["timestamp"], unit="ms")
|
|
68
|
-
df.set_index("timestamp", inplace=True)
|
|
69
|
-
|
|
70
79
|
return df
|
|
71
80
|
|
|
72
81
|
|
|
@@ -5,6 +5,10 @@ from __future__ import annotations
|
|
|
5
5
|
from typing import TYPE_CHECKING, Dict, List, Literal, Optional, Union, overload
|
|
6
6
|
|
|
7
7
|
from .._types import NOT_GIVEN, NotGiven
|
|
8
|
+
from ..utils import (
|
|
9
|
+
instrument_timestamp_to_trade_date,
|
|
10
|
+
instrument_timestamp_to_trade_time,
|
|
11
|
+
)
|
|
8
12
|
from ._base import AsyncResource, SyncResource
|
|
9
13
|
|
|
10
14
|
if TYPE_CHECKING:
|
|
@@ -32,7 +36,16 @@ def _quotes_to_dataframe(data: List["Quote"]) -> "pd.DataFrame":
|
|
|
32
36
|
return pd.DataFrame()
|
|
33
37
|
|
|
34
38
|
df = pd.DataFrame(data)
|
|
35
|
-
|
|
39
|
+
trade_dates = [
|
|
40
|
+
instrument_timestamp_to_trade_date(q["symbol"], q["timestamp"], unit="ms")
|
|
41
|
+
for q in data
|
|
42
|
+
]
|
|
43
|
+
trade_times = [
|
|
44
|
+
instrument_timestamp_to_trade_time(q["symbol"], q["timestamp"], unit="ms")
|
|
45
|
+
for q in data
|
|
46
|
+
]
|
|
47
|
+
df["trade_date"] = trade_dates
|
|
48
|
+
df["trade_time"] = trade_times
|
|
36
49
|
df.set_index("symbol", inplace=True)
|
|
37
50
|
|
|
38
51
|
return df
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
from zoneinfo import ZoneInfo
|
|
3
|
+
|
|
4
|
+
CN_TZ = ZoneInfo("Asia/Shanghai")
|
|
5
|
+
US_TZ = ZoneInfo("America/New_York")
|
|
6
|
+
HK_TZ = ZoneInfo("Asia/Hong_Kong")
|
|
7
|
+
|
|
8
|
+
exchange_region_map = {
|
|
9
|
+
"SH": "CN",
|
|
10
|
+
"SZ": "CN",
|
|
11
|
+
"BJ": "CN",
|
|
12
|
+
"US": "US",
|
|
13
|
+
"HK": "HK",
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
region_timezone_map = {
|
|
17
|
+
"CN": CN_TZ,
|
|
18
|
+
"US": US_TZ,
|
|
19
|
+
"HK": HK_TZ,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_instrument_region(symbol: str):
|
|
24
|
+
return exchange_region_map.get(
|
|
25
|
+
symbol.rsplit(".", 1)[-1],
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def get_region_timezone(region: str):
|
|
30
|
+
return region_timezone_map.get(region)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def instrument_timestamp_to_datetime(symbol: str, timestamp: int, unit="ms"):
|
|
34
|
+
tz = get_region_timezone(get_instrument_region(symbol))
|
|
35
|
+
if tz is None:
|
|
36
|
+
return None
|
|
37
|
+
|
|
38
|
+
dt = (
|
|
39
|
+
datetime.datetime.fromtimestamp(timestamp / 1000, tz)
|
|
40
|
+
if unit == "ms"
|
|
41
|
+
else datetime.datetime.fromtimestamp(timestamp, tz)
|
|
42
|
+
)
|
|
43
|
+
return dt
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def instrument_timestamp_to_trade_date(symbol: str, timestamp: int, unit="ms"):
|
|
47
|
+
dt = instrument_timestamp_to_datetime(symbol, timestamp, unit)
|
|
48
|
+
return dt.strftime("%Y-%m-%d")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def instrument_timestamp_to_trade_time(symbol: str, timestamp: int, unit="ms"):
|
|
52
|
+
dt = instrument_timestamp_to_datetime(symbol, timestamp, unit)
|
|
53
|
+
return dt.strftime("%Y-%m-%d %H:%M:%S")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tickflow
|
|
3
|
-
Version: 0.1.0.
|
|
3
|
+
Version: 0.1.0.dev3
|
|
4
4
|
Summary: TickFlow Python Client
|
|
5
5
|
Author: TickFlow Team
|
|
6
6
|
License: MIT
|
|
@@ -36,12 +36,6 @@ Requires-Dist: tqdm>=4.60.0; extra == "all"
|
|
|
36
36
|
|
|
37
37
|
## 安装
|
|
38
38
|
|
|
39
|
-
```bash
|
|
40
|
-
pip install tickflow
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
如需 DataFrame 支持和进度条功能:
|
|
44
|
-
|
|
45
39
|
```bash
|
|
46
40
|
pip install tickflow[all]
|
|
47
41
|
```
|
|
@@ -52,14 +46,14 @@ pip install tickflow[all]
|
|
|
52
46
|
from tickflow import TickFlow
|
|
53
47
|
|
|
54
48
|
# 初始化客户端
|
|
55
|
-
|
|
49
|
+
tf = TickFlow(api_key="your-api-key")
|
|
56
50
|
|
|
57
51
|
# 获取 K 线数据
|
|
58
|
-
df =
|
|
52
|
+
df = tf.klines.get("600000.SH", period="1d", count=100, as_dataframe=True)
|
|
59
53
|
print(df.tail())
|
|
60
54
|
|
|
61
55
|
# 获取实时行情
|
|
62
|
-
quotes =
|
|
56
|
+
quotes = tf.quotes.get(symbols=["600000.SH", "AAPL.US"])
|
|
63
57
|
for q in quotes:
|
|
64
58
|
print(f"{q['symbol']}: {q['last_price']}")
|
|
65
59
|
```
|
|
@@ -71,8 +65,8 @@ import asyncio
|
|
|
71
65
|
from tickflow import AsyncTickFlow
|
|
72
66
|
|
|
73
67
|
async def main():
|
|
74
|
-
async with AsyncTickFlow(api_key="your-api-key") as
|
|
75
|
-
df = await
|
|
68
|
+
async with AsyncTickFlow(api_key="your-api-key") as tf:
|
|
69
|
+
df = await tf.klines.get("600000.SH", as_dataframe=True)
|
|
76
70
|
print(df.tail())
|
|
77
71
|
|
|
78
72
|
asyncio.run(main())
|
|
@@ -82,8 +76,8 @@ asyncio.run(main())
|
|
|
82
76
|
|
|
83
77
|
```python
|
|
84
78
|
# 批量获取大量股票数据,自动分批并发请求
|
|
85
|
-
symbols =
|
|
86
|
-
df =
|
|
79
|
+
symbols = tf.exchanges.get_symbols("SH")[:500]
|
|
80
|
+
df = tf.klines.batch(
|
|
87
81
|
symbols,
|
|
88
82
|
period="1d",
|
|
89
83
|
as_dataframe=True,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|