hawk-sdk 0.0.6__tar.gz → 0.0.8__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.
Potentially problematic release.
This version of hawk-sdk might be problematic. Click here for more details.
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/PKG-INFO +1 -1
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk/api/__init__.py +1 -0
- hawk_sdk-0.0.8/hawk_sdk/api/equities/main.py +32 -0
- hawk_sdk-0.0.8/hawk_sdk/api/equities/repository.py +80 -0
- hawk_sdk-0.0.8/hawk_sdk/api/equities/service.py +41 -0
- hawk_sdk-0.0.8/hawk_sdk/api/futures/__init__.py +1 -0
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk/api/futures/main.py +3 -7
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk/api/futures/repository.py +4 -4
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk/api/system/main.py +2 -6
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk/api/system/repository.py +4 -3
- hawk_sdk-0.0.8/hawk_sdk/core/common/utils.py +21 -0
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk.egg-info/PKG-INFO +1 -1
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk.egg-info/SOURCES.txt +6 -1
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/setup.py +1 -1
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/README.md +0 -0
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk/__init__.py +0 -0
- {hawk_sdk-0.0.6/hawk_sdk/api/futures → hawk_sdk-0.0.8/hawk_sdk/api/equities}/__init__.py +0 -0
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk/api/futures/service.py +0 -0
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk/api/system/__init__.py +0 -0
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk/api/system/service.py +0 -0
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk/core/__init__.py +0 -0
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk/core/common/__init__.py +0 -0
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk/core/common/base_enum.py +0 -0
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk/core/common/constants.py +0 -0
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk/core/common/data_object.py +0 -0
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk.egg-info/dependency_links.txt +0 -0
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk.egg-info/requires.txt +0 -0
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/hawk_sdk.egg-info/top_level.txt +0 -0
- {hawk_sdk-0.0.6 → hawk_sdk-0.0.8}/setup.cfg +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""
|
|
2
|
+
@description: Datasource API for Equities data access and export functions.
|
|
3
|
+
@author: Rithwik Babu
|
|
4
|
+
"""
|
|
5
|
+
from typing import List
|
|
6
|
+
|
|
7
|
+
from hawk_sdk.api.equities.repository import EquitiesRepository
|
|
8
|
+
from hawk_sdk.api.equities.service import EquitiesService
|
|
9
|
+
from hawk_sdk.core.common.data_object import DataObject
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Equities:
|
|
13
|
+
"""Datasource API for fetching Futures data."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, environment="production") -> None:
|
|
16
|
+
"""Initializes the Equities datasource with required configurations."""
|
|
17
|
+
self.repository = EquitiesRepository(environment=environment)
|
|
18
|
+
self.service = EquitiesService(self.repository)
|
|
19
|
+
|
|
20
|
+
def get_adjusted_ohlc(self, start_date: str, end_date: str, interval: str, hawk_ids: List[int]) -> DataObject:
|
|
21
|
+
"""Fetch open, high, low, close data for the given date range and hawk_ids.
|
|
22
|
+
|
|
23
|
+
:param start_date: The start date for the data query (YYYY-MM-DD).
|
|
24
|
+
:param end_date: The end date for the data query (YYYY-MM-DD).
|
|
25
|
+
:param interval: The interval for the data query (e.g., '1d', '1h', '1m').
|
|
26
|
+
:param hawk_ids: A list of specific hawk_ids to filter by.
|
|
27
|
+
:return: A hawk DataObject containing the data.
|
|
28
|
+
"""
|
|
29
|
+
return DataObject(
|
|
30
|
+
name="adjusted_equities_ohlcv",
|
|
31
|
+
data=self.service.get_adjusted_ohlc(start_date, end_date, interval, hawk_ids)
|
|
32
|
+
)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""
|
|
2
|
+
@description: Repository layer for fetching Equities data from BigQuery.
|
|
3
|
+
@author: Rithwik Babu
|
|
4
|
+
"""
|
|
5
|
+
import logging
|
|
6
|
+
from typing import Iterator, List
|
|
7
|
+
|
|
8
|
+
from google.cloud import bigquery
|
|
9
|
+
|
|
10
|
+
from hawk_sdk.core.common.utils import get_bigquery_client
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class EquitiesRepository:
|
|
14
|
+
"""Repository for accessing Equities raw data."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, environment: str) -> None:
|
|
17
|
+
"""Initializes the repository with a BigQuery client.
|
|
18
|
+
|
|
19
|
+
:param environment: The environment to fetch data from (e.g., 'production', 'development').
|
|
20
|
+
"""
|
|
21
|
+
self.bq_client = get_bigquery_client()
|
|
22
|
+
self.environment = environment
|
|
23
|
+
|
|
24
|
+
def fetch_adjusted_ohlc(self, start_date: str, end_date: str, interval: str, hawk_ids: List[int]) -> Iterator[dict]:
|
|
25
|
+
"""Fetches raw adjusted OHLC data from BigQuery for the given date range and hawk_ids using query parameters."""
|
|
26
|
+
query = f"""
|
|
27
|
+
WITH records_data AS (
|
|
28
|
+
SELECT
|
|
29
|
+
r.record_timestamp AS date,
|
|
30
|
+
hi.value AS ticker,
|
|
31
|
+
MAX(CASE WHEN f.field_name = @open_field THEN r.double_value END) AS open,
|
|
32
|
+
MAX(CASE WHEN f.field_name = @high_field THEN r.double_value END) AS high,
|
|
33
|
+
MAX(CASE WHEN f.field_name = @low_field THEN r.double_value END) AS low,
|
|
34
|
+
MAX(CASE WHEN f.field_name = @close_field THEN r.double_value END) AS close
|
|
35
|
+
FROM
|
|
36
|
+
`wsb-hc-qasap-ae2e.{self.environment}.records` AS r
|
|
37
|
+
JOIN
|
|
38
|
+
`wsb-hc-qasap-ae2e.{self.environment}.fields` AS f
|
|
39
|
+
ON r.field_id = f.field_id
|
|
40
|
+
JOIN
|
|
41
|
+
`wsb-hc-qasap-ae2e.{self.environment}.hawk_identifiers` AS hi
|
|
42
|
+
ON r.hawk_id = hi.hawk_id
|
|
43
|
+
WHERE
|
|
44
|
+
r.hawk_id IN UNNEST(@hawk_ids)
|
|
45
|
+
AND f.field_name IN (@open_field, @high_field, @low_field, @close_field)
|
|
46
|
+
AND r.record_timestamp BETWEEN @start_date AND @end_date
|
|
47
|
+
GROUP BY
|
|
48
|
+
date, ticker
|
|
49
|
+
)
|
|
50
|
+
SELECT DISTINCT
|
|
51
|
+
date,
|
|
52
|
+
ticker,
|
|
53
|
+
open,
|
|
54
|
+
high,
|
|
55
|
+
low,
|
|
56
|
+
close,
|
|
57
|
+
FROM
|
|
58
|
+
records_data
|
|
59
|
+
ORDER BY
|
|
60
|
+
date;
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
query_params = [
|
|
64
|
+
bigquery.ArrayQueryParameter("hawk_ids", "INT64", hawk_ids),
|
|
65
|
+
bigquery.ScalarQueryParameter("start_date", "STRING", start_date),
|
|
66
|
+
bigquery.ScalarQueryParameter("end_date", "STRING", end_date),
|
|
67
|
+
bigquery.ScalarQueryParameter("open_field", "STRING", f"adjusted_open_{interval}"),
|
|
68
|
+
bigquery.ScalarQueryParameter("high_field", "STRING", f"adjusted_high_{interval}"),
|
|
69
|
+
bigquery.ScalarQueryParameter("low_field", "STRING", f"adjusted_low_{interval}"),
|
|
70
|
+
bigquery.ScalarQueryParameter("close_field", "STRING", f"adjusted_close_{interval}")
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
job_config = bigquery.QueryJobConfig(query_parameters=query_params)
|
|
74
|
+
|
|
75
|
+
try:
|
|
76
|
+
query_job = self.bq_client.query(query, job_config=job_config)
|
|
77
|
+
return query_job.result()
|
|
78
|
+
except Exception as e:
|
|
79
|
+
logging.error(f"Failed to fetch OHLC data: {e}")
|
|
80
|
+
raise
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""
|
|
2
|
+
@description: Service layer for processing and normalizing Equities data.
|
|
3
|
+
@author: Rithwik Babu
|
|
4
|
+
"""
|
|
5
|
+
from typing import List, Iterator
|
|
6
|
+
|
|
7
|
+
import pandas as pd
|
|
8
|
+
|
|
9
|
+
from hawk_sdk.api.equities.repository import EquitiesRepository
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class EquitiesService:
|
|
13
|
+
"""Service class for Futures business logic."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, repository: EquitiesRepository) -> None:
|
|
16
|
+
"""Initializes the service with a repository.
|
|
17
|
+
|
|
18
|
+
:param repository: An instance of FuturesRepository for data access.
|
|
19
|
+
"""
|
|
20
|
+
self.repository = repository
|
|
21
|
+
|
|
22
|
+
def get_adjusted_ohlc(self, start_date: str, end_date: str, interval: str, hawk_ids: List[int]) -> pd.DataFrame:
|
|
23
|
+
"""Equities and normalizes data into a pandas DataFrame.
|
|
24
|
+
|
|
25
|
+
:param start_date: The start date for the data query (YYYY-MM-DD).
|
|
26
|
+
:param end_date: The end date for the data query (YYYY-MM-DD).
|
|
27
|
+
:param interval: The interval for the data query (e.g., '1d', '1h', '1m').
|
|
28
|
+
:param hawk_ids: A list of specific hawk_ids to filter by.
|
|
29
|
+
:return: A pandas DataFrame containing the normalized data.
|
|
30
|
+
"""
|
|
31
|
+
raw_data = self.repository.fetch_adjusted_ohlc(start_date, end_date, interval, hawk_ids)
|
|
32
|
+
return self._normalize_data(raw_data)
|
|
33
|
+
|
|
34
|
+
@staticmethod
|
|
35
|
+
def _normalize_data(data: Iterator[dict]) -> pd.DataFrame:
|
|
36
|
+
"""Converts raw data into a normalized pandas DataFrame.
|
|
37
|
+
|
|
38
|
+
:param data: An iterator over raw data rows.
|
|
39
|
+
:return: A pandas DataFrame containing normalized data.
|
|
40
|
+
"""
|
|
41
|
+
return pd.DataFrame([dict(row) for row in data])
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from hawk_sdk.api.futures.main import Futures
|
|
@@ -4,12 +4,9 @@
|
|
|
4
4
|
"""
|
|
5
5
|
from typing import List
|
|
6
6
|
|
|
7
|
-
from google.cloud import bigquery
|
|
8
|
-
|
|
9
|
-
from hawk_sdk.core.common.constants import PROJECT_ID
|
|
10
|
-
from hawk_sdk.core.common.data_object import DataObject
|
|
11
7
|
from hawk_sdk.api.futures.repository import FuturesRepository
|
|
12
8
|
from hawk_sdk.api.futures.service import FuturesService
|
|
9
|
+
from hawk_sdk.core.common.data_object import DataObject
|
|
13
10
|
|
|
14
11
|
|
|
15
12
|
class Futures:
|
|
@@ -17,8 +14,7 @@ class Futures:
|
|
|
17
14
|
|
|
18
15
|
def __init__(self, environment="production") -> None:
|
|
19
16
|
"""Initializes the Futures datasource with required configurations."""
|
|
20
|
-
self.
|
|
21
|
-
self.repository = FuturesRepository(self.connector, environment=environment)
|
|
17
|
+
self.repository = FuturesRepository(environment=environment)
|
|
22
18
|
self.service = FuturesService(self.repository)
|
|
23
19
|
|
|
24
20
|
def get_ohlcvo(self, start_date: str, end_date: str, interval: str, hawk_ids: List[int]) -> DataObject:
|
|
@@ -45,4 +41,4 @@ class Futures:
|
|
|
45
41
|
return DataObject(
|
|
46
42
|
name="futures_snapshot",
|
|
47
43
|
data=self.service.get_snapshot(timestamp, hawk_ids)
|
|
48
|
-
)
|
|
44
|
+
)
|
|
@@ -6,19 +6,19 @@ import logging
|
|
|
6
6
|
from typing import Iterator, List
|
|
7
7
|
|
|
8
8
|
from google.cloud import bigquery
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
from hawk_sdk.core.common.utils import get_bigquery_client
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class FuturesRepository:
|
|
13
14
|
"""Repository for accessing Futures raw data."""
|
|
14
15
|
|
|
15
|
-
def __init__(self,
|
|
16
|
+
def __init__(self, environment: str) -> None:
|
|
16
17
|
"""Initializes the repository with a BigQuery client.
|
|
17
18
|
|
|
18
|
-
:param bq_client: An instance of BigQuery Client.
|
|
19
19
|
:param environment: The environment to fetch data from (e.g., 'production', 'development').
|
|
20
20
|
"""
|
|
21
|
-
self.bq_client =
|
|
21
|
+
self.bq_client = get_bigquery_client()
|
|
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]:
|
|
@@ -4,12 +4,9 @@
|
|
|
4
4
|
"""
|
|
5
5
|
from typing import List
|
|
6
6
|
|
|
7
|
-
from google.cloud import bigquery
|
|
8
|
-
|
|
9
|
-
from hawk_sdk.core.common.constants import PROJECT_ID
|
|
10
|
-
from hawk_sdk.core.common.data_object import DataObject
|
|
11
7
|
from hawk_sdk.api.system.repository import SystemRepository
|
|
12
8
|
from hawk_sdk.api.system.service import SystemService
|
|
9
|
+
from hawk_sdk.core.common.data_object import DataObject
|
|
13
10
|
|
|
14
11
|
|
|
15
12
|
class System:
|
|
@@ -17,8 +14,7 @@ class System:
|
|
|
17
14
|
|
|
18
15
|
def __init__(self, environment="production") -> None:
|
|
19
16
|
"""Initializes the System datasource with required configurations."""
|
|
20
|
-
self.
|
|
21
|
-
self.repository = SystemRepository(self.connector, environment=environment)
|
|
17
|
+
self.repository = SystemRepository(environment=environment)
|
|
22
18
|
self.service = SystemService(self.repository)
|
|
23
19
|
|
|
24
20
|
def get_hawk_ids(self, tickers: List[str]) -> DataObject:
|
|
@@ -6,19 +6,20 @@ import logging
|
|
|
6
6
|
from typing import Iterator, List
|
|
7
7
|
|
|
8
8
|
from google.cloud import bigquery
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
from hawk_sdk.core.common.utils import get_bigquery_client
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class SystemRepository:
|
|
13
14
|
"""Repository for accessing System data."""
|
|
14
15
|
|
|
15
|
-
def __init__(self,
|
|
16
|
+
def __init__(self, environment: str) -> None:
|
|
16
17
|
"""Initializes the repository with a BigQuery client.
|
|
17
18
|
|
|
18
19
|
:param bq_client: An instance of BigQuery Client.
|
|
19
20
|
:param environment: The environment to fetch data from (e.g., 'production', 'development').
|
|
20
21
|
"""
|
|
21
|
-
self.bq_client =
|
|
22
|
+
self.bq_client = get_bigquery_client()
|
|
22
23
|
self.environment = environment
|
|
23
24
|
|
|
24
25
|
def fetch_hawk_ids(self, tickers: List[str]) -> Iterator[dict]:
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
from google.cloud import bigquery
|
|
5
|
+
from google.oauth2 import service_account
|
|
6
|
+
|
|
7
|
+
from hawk_sdk.core.common.constants import PROJECT_ID
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_bigquery_client() -> bigquery.Client:
|
|
11
|
+
if 'GOOGLE_APPLICATION_CREDENTIALS' in os.environ:
|
|
12
|
+
# Initialize the client using the json file in the environment variable
|
|
13
|
+
return bigquery.Client(project=PROJECT_ID)
|
|
14
|
+
|
|
15
|
+
else:
|
|
16
|
+
# Load the service account credentials from the JSON string
|
|
17
|
+
service_account_json = os.environ.get('SERVICE_ACCOUNT_JSON')
|
|
18
|
+
credentials = service_account.Credentials.from_service_account_info(
|
|
19
|
+
json.loads(service_account_json)
|
|
20
|
+
)
|
|
21
|
+
return bigquery.Client(project=PROJECT_ID, credentials=credentials)
|
|
@@ -7,6 +7,10 @@ hawk_sdk.egg-info/dependency_links.txt
|
|
|
7
7
|
hawk_sdk.egg-info/requires.txt
|
|
8
8
|
hawk_sdk.egg-info/top_level.txt
|
|
9
9
|
hawk_sdk/api/__init__.py
|
|
10
|
+
hawk_sdk/api/equities/__init__.py
|
|
11
|
+
hawk_sdk/api/equities/main.py
|
|
12
|
+
hawk_sdk/api/equities/repository.py
|
|
13
|
+
hawk_sdk/api/equities/service.py
|
|
10
14
|
hawk_sdk/api/futures/__init__.py
|
|
11
15
|
hawk_sdk/api/futures/main.py
|
|
12
16
|
hawk_sdk/api/futures/repository.py
|
|
@@ -19,4 +23,5 @@ hawk_sdk/core/__init__.py
|
|
|
19
23
|
hawk_sdk/core/common/__init__.py
|
|
20
24
|
hawk_sdk/core/common/base_enum.py
|
|
21
25
|
hawk_sdk/core/common/constants.py
|
|
22
|
-
hawk_sdk/core/common/data_object.py
|
|
26
|
+
hawk_sdk/core/common/data_object.py
|
|
27
|
+
hawk_sdk/core/common/utils.py
|
|
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
|