hawk-sdk 0.0.5__py3-none-any.whl → 0.0.6__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.
Potentially problematic release.
This version of hawk-sdk might be problematic. Click here for more details.
- hawk_sdk/api/futures/main.py +12 -0
- hawk_sdk/api/futures/repository.py +58 -2
- hawk_sdk/api/futures/service.py +10 -0
- {hawk_sdk-0.0.5.dist-info → hawk_sdk-0.0.6.dist-info}/METADATA +1 -1
- {hawk_sdk-0.0.5.dist-info → hawk_sdk-0.0.6.dist-info}/RECORD +7 -7
- {hawk_sdk-0.0.5.dist-info → hawk_sdk-0.0.6.dist-info}/WHEEL +0 -0
- {hawk_sdk-0.0.5.dist-info → hawk_sdk-0.0.6.dist-info}/top_level.txt +0 -0
hawk_sdk/api/futures/main.py
CHANGED
|
@@ -34,3 +34,15 @@ class Futures:
|
|
|
34
34
|
name="futures_ohlcvo",
|
|
35
35
|
data=self.service.get_ohlcvo(start_date, end_date, interval, hawk_ids)
|
|
36
36
|
)
|
|
37
|
+
|
|
38
|
+
def get_snapshot(self, timestamp: str, hawk_ids: List[int]) -> DataObject:
|
|
39
|
+
"""Fetch snapshot data for the specified timestamp and hawk_ids.
|
|
40
|
+
|
|
41
|
+
:param timestamp: The timestamp for the data query (YYYY-MM-DD HH:MM:SS).
|
|
42
|
+
:param hawk_ids: A list of specific hawk_ids to filter by.
|
|
43
|
+
:return: A hawk DataObject containing the snapshot data.
|
|
44
|
+
"""
|
|
45
|
+
return DataObject(
|
|
46
|
+
name="futures_snapshot",
|
|
47
|
+
data=self.service.get_snapshot(timestamp, hawk_ids)
|
|
48
|
+
)
|
|
@@ -22,8 +22,7 @@ class FuturesRepository:
|
|
|
22
22
|
self.environment = environment
|
|
23
23
|
|
|
24
24
|
def fetch_ohlcvo(self, start_date: str, end_date: str, interval: str, hawk_ids: List[int]) -> Iterator[dict]:
|
|
25
|
-
"""Fetches raw data from BigQuery for the given date range and hawk_ids using query parameters."""
|
|
26
|
-
|
|
25
|
+
"""Fetches raw OHLCVO data from BigQuery for the given date range and hawk_ids using query parameters."""
|
|
27
26
|
query = f"""
|
|
28
27
|
WITH records_data AS (
|
|
29
28
|
SELECT
|
|
@@ -85,3 +84,60 @@ class FuturesRepository:
|
|
|
85
84
|
except Exception as e:
|
|
86
85
|
logging.error(f"Failed to fetch OHLCVO data: {e}")
|
|
87
86
|
raise
|
|
87
|
+
|
|
88
|
+
def fetch_snapshot(self, timestamp: str, hawk_ids: List[int]) -> Iterator[dict]:
|
|
89
|
+
"""Fetches the most recent snapshot data from BigQuery for the given time and hawk_ids."""
|
|
90
|
+
query = f"""
|
|
91
|
+
WITH records_data AS (
|
|
92
|
+
SELECT
|
|
93
|
+
r.record_timestamp AS date,
|
|
94
|
+
hi.value AS ticker,
|
|
95
|
+
MAX(CASE WHEN f.field_name = 'close_snapshot' THEN r.double_value END) AS close_snapshot,
|
|
96
|
+
MAX(CASE WHEN f.field_name = 'high_snapshot' THEN r.double_value END) AS high_snapshot,
|
|
97
|
+
MAX(CASE WHEN f.field_name = 'low_snapshot' THEN r.double_value END) AS low_snapshot,
|
|
98
|
+
MAX(CASE WHEN f.field_name = 'cvol_snapshot' THEN r.int_value END) AS cvol_snapshot,
|
|
99
|
+
MAX(CASE WHEN f.field_name = 'bid_snapshot' THEN r.double_value END) AS bid_snapshot,
|
|
100
|
+
MAX(CASE WHEN f.field_name = 'ask_snapshot' THEN r.double_value END) AS ask_snapshot
|
|
101
|
+
FROM
|
|
102
|
+
`wsb-hc-qasap-ae2e.{self.environment}.records` AS r
|
|
103
|
+
JOIN
|
|
104
|
+
`wsb-hc-qasap-ae2e.{self.environment}.fields` AS f
|
|
105
|
+
ON r.field_id = f.field_id
|
|
106
|
+
JOIN
|
|
107
|
+
`wsb-hc-qasap-ae2e.{self.environment}.hawk_identifiers` AS hi
|
|
108
|
+
ON r.hawk_id = hi.hawk_id
|
|
109
|
+
WHERE
|
|
110
|
+
r.hawk_id IN UNNEST(@hawk_ids)
|
|
111
|
+
AND f.field_name IN ('close_snapshot', 'high_snapshot', 'low_snapshot', 'cvol_snapshot', 'bid_snapshot', 'ask_snapshot')
|
|
112
|
+
AND r.record_timestamp <= @timestamp
|
|
113
|
+
GROUP BY
|
|
114
|
+
date, ticker
|
|
115
|
+
)
|
|
116
|
+
SELECT DISTINCT
|
|
117
|
+
date,
|
|
118
|
+
ticker,
|
|
119
|
+
close_snapshot,
|
|
120
|
+
high_snapshot,
|
|
121
|
+
low_snapshot,
|
|
122
|
+
cvol_snapshot,
|
|
123
|
+
bid_snapshot,
|
|
124
|
+
ask_snapshot
|
|
125
|
+
FROM
|
|
126
|
+
records_data
|
|
127
|
+
ORDER BY
|
|
128
|
+
date;
|
|
129
|
+
"""
|
|
130
|
+
|
|
131
|
+
query_params = [
|
|
132
|
+
bigquery.ArrayQueryParameter("hawk_ids", "INT64", hawk_ids),
|
|
133
|
+
bigquery.ScalarQueryParameter("timestamp", "DATETIME", timestamp)
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
job_config = bigquery.QueryJobConfig(query_parameters=query_params)
|
|
137
|
+
|
|
138
|
+
try:
|
|
139
|
+
query_job = self.bq_client.query(query, job_config=job_config)
|
|
140
|
+
return query_job.result()
|
|
141
|
+
except Exception as e:
|
|
142
|
+
logging.error(f"Failed to fetch snapshot data: {e}")
|
|
143
|
+
raise
|
hawk_sdk/api/futures/service.py
CHANGED
|
@@ -31,6 +31,16 @@ class FuturesService:
|
|
|
31
31
|
raw_data = self.repository.fetch_ohlcvo(start_date, end_date, interval, hawk_ids)
|
|
32
32
|
return self._normalize_data(raw_data)
|
|
33
33
|
|
|
34
|
+
def get_snapshot(self, timestamp: str, hawk_ids: List[int]) -> pd.DataFrame:
|
|
35
|
+
"""Fetches snapshot data and normalizes it into a pandas DataFrame.
|
|
36
|
+
|
|
37
|
+
:param timestamp: The timestamp for the data query (YYYY-MM-DD HH:MM:SS).
|
|
38
|
+
:param hawk_ids: A list of specific hawk_ids to filter by.
|
|
39
|
+
:return: A pandas DataFrame containing the normalized snapshot data.
|
|
40
|
+
"""
|
|
41
|
+
raw_data = self.repository.fetch_snapshot(timestamp, hawk_ids)
|
|
42
|
+
return self._normalize_data(raw_data)
|
|
43
|
+
|
|
34
44
|
@staticmethod
|
|
35
45
|
def _normalize_data(data: Iterator[dict]) -> pd.DataFrame:
|
|
36
46
|
"""Converts raw data into a normalized pandas DataFrame.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
hawk_sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
hawk_sdk/api/__init__.py,sha256=BD8XgbQ2o4EIzECUu4h6g-9jzpg--BiT6brrnyO4Puc,90
|
|
3
3
|
hawk_sdk/api/futures/__init__.py,sha256=9mL1L6wlZKXTvMrTuQV35Fl9kTy4qjf3RIJzYBXcpeM,46
|
|
4
|
-
hawk_sdk/api/futures/main.py,sha256=
|
|
5
|
-
hawk_sdk/api/futures/repository.py,sha256=
|
|
6
|
-
hawk_sdk/api/futures/service.py,sha256=
|
|
4
|
+
hawk_sdk/api/futures/main.py,sha256=aJ08ohKTIOSa8wQIb_ddos4yRlsX6Z16V2aNilRXlrc,2074
|
|
5
|
+
hawk_sdk/api/futures/repository.py,sha256=MI61N4EfRFDM0SOzaW9M7EWT2uHkWGFY-DTTfHx0lLw,6029
|
|
6
|
+
hawk_sdk/api/futures/service.py,sha256=0zJn3xJNoHgEOeVVpIF2i0r5g8mvf4y1K_YnvHDF5mU,2078
|
|
7
7
|
hawk_sdk/api/system/__init__.py,sha256=Oy8XUp5WHx4fczjZXzfbkkHluHW-t7BLN4IgrOG6Pk4,44
|
|
8
8
|
hawk_sdk/api/system/main.py,sha256=FdpXaHp5yPFi17M1-1v4LU9vnwywkdYeOelps1hnKr0,1191
|
|
9
9
|
hawk_sdk/api/system/repository.py,sha256=3CfFjNVC0X09TKLh9sfwd5HxeLcb49MRCbvb3Su2Wnk,1642
|
|
@@ -13,7 +13,7 @@ hawk_sdk/core/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
|
|
|
13
13
|
hawk_sdk/core/common/base_enum.py,sha256=ZgC8gZjTzsoJzzdgN2DjYk3dVL_uM2Stuaky5bo6GuQ,267
|
|
14
14
|
hawk_sdk/core/common/constants.py,sha256=KmsNfRVCwGeXEBHfo3TzSaDYJDMtnL-YEQKsO1DnWV8,33
|
|
15
15
|
hawk_sdk/core/common/data_object.py,sha256=f4YO415Zz-lm3QYJQ3sJ4ugH9ZX9Dc7T-JvO4IdeyOw,1073
|
|
16
|
-
hawk_sdk-0.0.
|
|
17
|
-
hawk_sdk-0.0.
|
|
18
|
-
hawk_sdk-0.0.
|
|
19
|
-
hawk_sdk-0.0.
|
|
16
|
+
hawk_sdk-0.0.6.dist-info/METADATA,sha256=k77ZeTkssmZJ7J-k9QlZYfP8jxDlmKmyoZfBzHfun6k,112
|
|
17
|
+
hawk_sdk-0.0.6.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
|
18
|
+
hawk_sdk-0.0.6.dist-info/top_level.txt,sha256=aSjbudHcWSYsKXH9Wg0L1ltJfDOHXzjYFPO3v3cP-SE,9
|
|
19
|
+
hawk_sdk-0.0.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|