tickflow 0.1.0.dev4__py3-none-any.whl → 0.1.0.dev5__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.
- tickflow/resources/klines.py +14 -20
- {tickflow-0.1.0.dev4.dist-info → tickflow-0.1.0.dev5.dist-info}/METADATA +1 -1
- {tickflow-0.1.0.dev4.dist-info → tickflow-0.1.0.dev5.dist-info}/RECORD +5 -5
- {tickflow-0.1.0.dev4.dist-info → tickflow-0.1.0.dev5.dist-info}/WHEEL +0 -0
- {tickflow-0.1.0.dev4.dist-info → tickflow-0.1.0.dev5.dist-info}/top_level.txt +0 -0
tickflow/resources/klines.py
CHANGED
|
@@ -79,7 +79,9 @@ def _klines_to_dataframe(
|
|
|
79
79
|
return df
|
|
80
80
|
|
|
81
81
|
|
|
82
|
-
def
|
|
82
|
+
def _batch_klines_to_dataframes(
|
|
83
|
+
data: Dict[str, "CompactKlineData"],
|
|
84
|
+
) -> Dict[str, "pd.DataFrame"]:
|
|
83
85
|
"""Convert batch K-line data to a single pandas DataFrame.
|
|
84
86
|
|
|
85
87
|
Parameters
|
|
@@ -89,25 +91,17 @@ def _batch_klines_to_dataframe(data: Dict[str, "CompactKlineData"]) -> "pd.DataF
|
|
|
89
91
|
|
|
90
92
|
Returns
|
|
91
93
|
-------
|
|
92
|
-
pd.DataFrame
|
|
93
|
-
|
|
94
|
+
dict of str to pd.DataFrame
|
|
95
|
+
Dictionary mapping symbol codes to pandas DataFrames.
|
|
94
96
|
"""
|
|
95
97
|
import pandas as pd
|
|
96
98
|
|
|
97
|
-
dfs =
|
|
99
|
+
dfs = {}
|
|
98
100
|
for symbol, kline_data in data.items():
|
|
99
101
|
df = _klines_to_dataframe(kline_data, symbol=symbol)
|
|
100
|
-
dfs
|
|
101
|
-
|
|
102
|
-
if not dfs:
|
|
103
|
-
return pd.DataFrame()
|
|
104
|
-
|
|
105
|
-
combined = pd.concat(dfs)
|
|
106
|
-
combined.reset_index(inplace=True)
|
|
107
|
-
combined.set_index(["symbol", "timestamp"], inplace=True)
|
|
108
|
-
combined.sort_index(inplace=True)
|
|
102
|
+
dfs[symbol] = df
|
|
109
103
|
|
|
110
|
-
return
|
|
104
|
+
return dfs
|
|
111
105
|
|
|
112
106
|
|
|
113
107
|
def _chunk_list(lst: List[str], chunk_size: int) -> List[List[str]]:
|
|
@@ -372,7 +366,7 @@ class Klines(SyncResource):
|
|
|
372
366
|
>>> print(f"Got data for {len(df.index.get_level_values('symbol').unique())} symbols")
|
|
373
367
|
"""
|
|
374
368
|
if not symbols:
|
|
375
|
-
return {} if not as_dataframe else
|
|
369
|
+
return {} if not as_dataframe else _batch_klines_to_dataframes({})
|
|
376
370
|
|
|
377
371
|
# Build base params
|
|
378
372
|
params: Dict[str, Any] = {}
|
|
@@ -392,7 +386,7 @@ class Klines(SyncResource):
|
|
|
392
386
|
if len(chunks) == 1:
|
|
393
387
|
data, errors = self._fetch_batch_chunk(chunks[0], params)
|
|
394
388
|
if as_dataframe:
|
|
395
|
-
return
|
|
389
|
+
return _batch_klines_to_dataframes(data)
|
|
396
390
|
return data
|
|
397
391
|
|
|
398
392
|
# Setup progress bar
|
|
@@ -433,7 +427,7 @@ class Klines(SyncResource):
|
|
|
433
427
|
# Users can check if their symbols are in the result
|
|
434
428
|
|
|
435
429
|
if as_dataframe:
|
|
436
|
-
return
|
|
430
|
+
return _batch_klines_to_dataframes(all_data)
|
|
437
431
|
return all_data
|
|
438
432
|
|
|
439
433
|
|
|
@@ -641,7 +635,7 @@ class AsyncKlines(AsyncResource):
|
|
|
641
635
|
>>> df = await client.klines.batch(symbols[:500], as_dataframe=True, show_progress=True)
|
|
642
636
|
"""
|
|
643
637
|
if not symbols:
|
|
644
|
-
return {} if not as_dataframe else
|
|
638
|
+
return {} if not as_dataframe else _batch_klines_to_dataframes({})
|
|
645
639
|
|
|
646
640
|
# Build base params
|
|
647
641
|
params: Dict[str, Any] = {}
|
|
@@ -661,7 +655,7 @@ class AsyncKlines(AsyncResource):
|
|
|
661
655
|
if len(chunks) == 1:
|
|
662
656
|
data, errors = await self._fetch_batch_chunk(chunks[0], params)
|
|
663
657
|
if as_dataframe:
|
|
664
|
-
return
|
|
658
|
+
return _batch_klines_to_dataframes(data)
|
|
665
659
|
return data
|
|
666
660
|
|
|
667
661
|
# Setup progress bar
|
|
@@ -699,5 +693,5 @@ class AsyncKlines(AsyncResource):
|
|
|
699
693
|
pbar.close()
|
|
700
694
|
|
|
701
695
|
if as_dataframe:
|
|
702
|
-
return
|
|
696
|
+
return _batch_klines_to_dataframes(all_data)
|
|
703
697
|
return all_data
|
|
@@ -9,10 +9,10 @@ tickflow/resources/__init__.py,sha256=JayIwwlrRnSAI83fy97LfFstiYGz3qzdmbxApiIJNt
|
|
|
9
9
|
tickflow/resources/_base.py,sha256=KcaNDouymvPp9FC4QJuYzBdioYB2wTIIdmLKoomtb58,667
|
|
10
10
|
tickflow/resources/exchanges.py,sha256=EtWBcOA_3VG9OaCHwXJ0HMjZIxylFoJu6XS8nzvv7_w,4580
|
|
11
11
|
tickflow/resources/instruments.py,sha256=xE0IK42MuyWQAhlObC_9Xecm-JnrDHu281t_NzqoPis,5863
|
|
12
|
-
tickflow/resources/klines.py,sha256=
|
|
12
|
+
tickflow/resources/klines.py,sha256=2Mwjc2mmv9o7FNMyFaAlHp_Fq5zzu6eMCsYH6ExA0zs,23832
|
|
13
13
|
tickflow/resources/quotes.py,sha256=8DglL0cVS02PI79-EUM-GfhkpQedBEraBezQSBf0q4Q,12491
|
|
14
14
|
tickflow/resources/universes.py,sha256=Pk--9Zlt6vfq9SzzkuJENkDAUUGmqiq4kdeOjMKXWQU,4542
|
|
15
|
-
tickflow-0.1.0.
|
|
16
|
-
tickflow-0.1.0.
|
|
17
|
-
tickflow-0.1.0.
|
|
18
|
-
tickflow-0.1.0.
|
|
15
|
+
tickflow-0.1.0.dev5.dist-info/METADATA,sha256=Lt4V7vs_kqHspu-JOWule4TiA7gd6rEO0kJdk6VYnK0,2574
|
|
16
|
+
tickflow-0.1.0.dev5.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
17
|
+
tickflow-0.1.0.dev5.dist-info/top_level.txt,sha256=_0JOxGpAnD-wmnVj9CKo6Bwp2qNC0xWdbDXJX8B1jrs,9
|
|
18
|
+
tickflow-0.1.0.dev5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|