hawk-sdk 0.0.6__py3-none-any.whl → 0.0.8__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/__init__.py CHANGED
@@ -1,2 +1,3 @@
1
1
  from hawk_sdk.api.futures.main import Futures
2
+ from hawk_sdk.api.equities.main import Equities
2
3
  from hawk_sdk.api.system.main import System
@@ -0,0 +1 @@
1
+ from hawk_sdk.api.futures.main import Futures
@@ -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])
@@ -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.connector = bigquery.Client(project=PROJECT_ID)
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
- from google.cloud.bigquery import Client
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, bq_client: Client, environment: str) -> None:
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 = 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.connector = bigquery.Client(project=PROJECT_ID)
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
- from google.cloud.bigquery import Client
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, bq_client: Client, environment: str) -> None:
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 = 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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hawk-sdk
3
- Version: 0.0.6
3
+ Version: 0.0.8
4
4
  Requires-Dist: google-cloud-bigquery
5
5
  Requires-Dist: pandas
6
6
 
@@ -0,0 +1,24 @@
1
+ hawk_sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ hawk_sdk/api/__init__.py,sha256=kraovUX7vWIb9tgl5eJbA9jnp77QpoqZYHLvmz0hNrg,138
3
+ hawk_sdk/api/equities/__init__.py,sha256=9mL1L6wlZKXTvMrTuQV35Fl9kTy4qjf3RIJzYBXcpeM,46
4
+ hawk_sdk/api/equities/main.py,sha256=EeC-h0GKAOYZT9Q2BulO4_NxX1Me-dMgC0yT6y7_Mi0,1380
5
+ hawk_sdk/api/equities/repository.py,sha256=oOboCi1w9e95_KK80mfEsojpUqKeT2HJKyBButUbi8Y,3133
6
+ hawk_sdk/api/equities/service.py,sha256=4t8hcAd7D2cDFxTdiGZzWEnpWdeeP7FwibJLlRHhOKo,1584
7
+ hawk_sdk/api/futures/__init__.py,sha256=9mL1L6wlZKXTvMrTuQV35Fl9kTy4qjf3RIJzYBXcpeM,46
8
+ hawk_sdk/api/futures/main.py,sha256=XNihiVb75wyPx78dOzEVWhQ6vmN-NLHZTk4L7zY-4WQ,1909
9
+ hawk_sdk/api/futures/repository.py,sha256=P6dsLJe8hQ2-hkDX_pa-VRoUUXaU-uBhA4S5mwK79_o,5983
10
+ hawk_sdk/api/futures/service.py,sha256=0zJn3xJNoHgEOeVVpIF2i0r5g8mvf4y1K_YnvHDF5mU,2078
11
+ hawk_sdk/api/system/__init__.py,sha256=Oy8XUp5WHx4fczjZXzfbkkHluHW-t7BLN4IgrOG6Pk4,44
12
+ hawk_sdk/api/system/main.py,sha256=t2zWeEHSTYuWZAsqCMLt_CyRWoN8T8N6oEVshPgf6kk,1025
13
+ hawk_sdk/api/system/repository.py,sha256=IllwoWXZyi46INuCRQeibHJaMDR1TfbT6l2uAhii2Xc,1654
14
+ hawk_sdk/api/system/service.py,sha256=LOZIfrEBKynJlj8V-4UM4abzVV9ogwUVxM7s2xFXlpo,1262
15
+ hawk_sdk/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ hawk_sdk/core/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
+ hawk_sdk/core/common/base_enum.py,sha256=ZgC8gZjTzsoJzzdgN2DjYk3dVL_uM2Stuaky5bo6GuQ,267
18
+ hawk_sdk/core/common/constants.py,sha256=KmsNfRVCwGeXEBHfo3TzSaDYJDMtnL-YEQKsO1DnWV8,33
19
+ hawk_sdk/core/common/data_object.py,sha256=f4YO415Zz-lm3QYJQ3sJ4ugH9ZX9Dc7T-JvO4IdeyOw,1073
20
+ hawk_sdk/core/common/utils.py,sha256=bxF-iJzbqXGYtQKElH6k5-bSsdcvft0o51G9slZ1grI,745
21
+ hawk_sdk-0.0.8.dist-info/METADATA,sha256=pngW5cV78C_9x-0_8PUZsAIXzZwXW6TdUjuAJF0XQpE,112
22
+ hawk_sdk-0.0.8.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
23
+ hawk_sdk-0.0.8.dist-info/top_level.txt,sha256=aSjbudHcWSYsKXH9Wg0L1ltJfDOHXzjYFPO3v3cP-SE,9
24
+ hawk_sdk-0.0.8.dist-info/RECORD,,
@@ -1,19 +0,0 @@
1
- hawk_sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- hawk_sdk/api/__init__.py,sha256=BD8XgbQ2o4EIzECUu4h6g-9jzpg--BiT6brrnyO4Puc,90
3
- hawk_sdk/api/futures/__init__.py,sha256=9mL1L6wlZKXTvMrTuQV35Fl9kTy4qjf3RIJzYBXcpeM,46
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
- hawk_sdk/api/system/__init__.py,sha256=Oy8XUp5WHx4fczjZXzfbkkHluHW-t7BLN4IgrOG6Pk4,44
8
- hawk_sdk/api/system/main.py,sha256=FdpXaHp5yPFi17M1-1v4LU9vnwywkdYeOelps1hnKr0,1191
9
- hawk_sdk/api/system/repository.py,sha256=3CfFjNVC0X09TKLh9sfwd5HxeLcb49MRCbvb3Su2Wnk,1642
10
- hawk_sdk/api/system/service.py,sha256=LOZIfrEBKynJlj8V-4UM4abzVV9ogwUVxM7s2xFXlpo,1262
11
- hawk_sdk/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
- hawk_sdk/core/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- hawk_sdk/core/common/base_enum.py,sha256=ZgC8gZjTzsoJzzdgN2DjYk3dVL_uM2Stuaky5bo6GuQ,267
14
- hawk_sdk/core/common/constants.py,sha256=KmsNfRVCwGeXEBHfo3TzSaDYJDMtnL-YEQKsO1DnWV8,33
15
- hawk_sdk/core/common/data_object.py,sha256=f4YO415Zz-lm3QYJQ3sJ4ugH9ZX9Dc7T-JvO4IdeyOw,1073
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,,