tickflow 0.1.0.dev2__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.dev2 → tickflow-0.1.0.dev3}/PKG-INFO +1 -1
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/pyproject.toml +1 -1
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/tickflow/resources/klines.py +15 -6
- {tickflow-0.1.0.dev2 → 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.dev2 → tickflow-0.1.0.dev3}/tickflow.egg-info/PKG-INFO +1 -1
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/tickflow.egg-info/SOURCES.txt +1 -0
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/README.md +0 -0
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/setup.cfg +0 -0
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/tickflow/__init__.py +0 -0
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/tickflow/_base_client.py +0 -0
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/tickflow/_exceptions.py +0 -0
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/tickflow/_types.py +0 -0
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/tickflow/client.py +0 -0
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/tickflow/generated_model.py +0 -0
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/tickflow/resources/__init__.py +0 -0
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/tickflow/resources/_base.py +0 -0
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/tickflow/resources/exchanges.py +0 -0
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/tickflow/resources/instruments.py +0 -0
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/tickflow/resources/universes.py +0 -0
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/tickflow.egg-info/dependency_links.txt +0 -0
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/tickflow.egg-info/requires.txt +0 -0
- {tickflow-0.1.0.dev2 → tickflow-0.1.0.dev3}/tickflow.egg-info/top_level.txt +0 -0
|
@@ -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")
|
|
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
|
|
File without changes
|