hawk-sdk 0.0.0__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.0/PKG-INFO +3 -0
- hawk-sdk-0.0.0/README.md +1 -0
- hawk-sdk-0.0.0/hawk_sdk/__init__.py +1 -0
- hawk-sdk-0.0.0/hawk_sdk/common/__init__.py +0 -0
- hawk-sdk-0.0.0/hawk_sdk/common/bigquery_connector.py +47 -0
- hawk-sdk-0.0.0/hawk_sdk/common/data_object.py +39 -0
- hawk-sdk-0.0.0/hawk_sdk/futures/__init__.py +1 -0
- hawk-sdk-0.0.0/hawk_sdk/futures/main.py +39 -0
- hawk-sdk-0.0.0/hawk_sdk/futures/repository.py +70 -0
- hawk-sdk-0.0.0/hawk_sdk/futures/service.py +40 -0
- hawk-sdk-0.0.0/hawk_sdk.egg-info/PKG-INFO +3 -0
- hawk-sdk-0.0.0/hawk_sdk.egg-info/SOURCES.txt +15 -0
- hawk-sdk-0.0.0/hawk_sdk.egg-info/dependency_links.txt +1 -0
- hawk-sdk-0.0.0/hawk_sdk.egg-info/requires.txt +2 -0
- hawk-sdk-0.0.0/hawk_sdk.egg-info/top_level.txt +1 -0
- hawk-sdk-0.0.0/setup.cfg +4 -0
- hawk-sdk-0.0.0/setup.py +11 -0
hawk-sdk-0.0.0/PKG-INFO
ADDED
hawk-sdk-0.0.0/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# hawk-sdk
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from hawk_sdk.futures import Futures
|
|
File without changes
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""
|
|
2
|
+
@description: Handles the connection and interaction with Google BigQuery.
|
|
3
|
+
@author: Rithwik Babu
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
from typing import Iterator
|
|
8
|
+
|
|
9
|
+
from google.cloud import bigquery
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class BigQueryConnector:
|
|
13
|
+
"""Handles authentication and querying BigQuery."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, project_id: str, credentials_path: str = None) -> None:
|
|
16
|
+
"""Initializes BigQuery client and sets up authentication.
|
|
17
|
+
|
|
18
|
+
:param project_id: The GCP project ID.
|
|
19
|
+
:param credentials_path: Path to the Google Cloud credentials file.
|
|
20
|
+
"""
|
|
21
|
+
if credentials_path:
|
|
22
|
+
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = credentials_path
|
|
23
|
+
|
|
24
|
+
if not self._validate_credentials_exists():
|
|
25
|
+
raise ValueError("Credentials not found. Set GOOGLE_APPLICATION_CREDENTIALS environment variable.")
|
|
26
|
+
|
|
27
|
+
self.client = bigquery.Client(project=project_id)
|
|
28
|
+
|
|
29
|
+
def run_query(self, query: str) -> Iterator[bigquery.Row]:
|
|
30
|
+
"""Runs a SQL query on BigQuery and returns an iterator over rows.
|
|
31
|
+
|
|
32
|
+
:param query: The SQL query to execute.
|
|
33
|
+
:return: An iterator over the result rows.
|
|
34
|
+
"""
|
|
35
|
+
query_job = self.client.query(query)
|
|
36
|
+
return query_job.result()
|
|
37
|
+
|
|
38
|
+
def _validate_credentials_exists(self) -> bool:
|
|
39
|
+
"""Validates if the GOOGLE_APPLICATION_CREDENTIALS environment variable is set.
|
|
40
|
+
|
|
41
|
+
:return: True if the environment variable is set, False otherwise.
|
|
42
|
+
"""
|
|
43
|
+
if "GOOGLE_APPLICATION_CREDENTIALS" in os.environ:
|
|
44
|
+
return True
|
|
45
|
+
else:
|
|
46
|
+
print("Environment variable for credentials is not set.")
|
|
47
|
+
return False
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class DataObject:
|
|
5
|
+
def __init__(self, name, data):
|
|
6
|
+
self.__name = name
|
|
7
|
+
self.__data = data
|
|
8
|
+
|
|
9
|
+
def to_df(self) -> pd.DataFrame:
|
|
10
|
+
"""Exports data to a pandas DataFrame.
|
|
11
|
+
|
|
12
|
+
:return: pd.Dataframe
|
|
13
|
+
"""
|
|
14
|
+
return self.__data
|
|
15
|
+
|
|
16
|
+
def to_csv(self, file_name):
|
|
17
|
+
"""Exports data to an Excel file.
|
|
18
|
+
|
|
19
|
+
:param file_name: The name of the output Excel file.
|
|
20
|
+
:return: None
|
|
21
|
+
"""
|
|
22
|
+
self.__data.to_csv(file_name, index=False)
|
|
23
|
+
|
|
24
|
+
def to_xlsx(self, file_name):
|
|
25
|
+
"""Exports data to an Excel file.
|
|
26
|
+
|
|
27
|
+
:param file_name: The name of the output Excel file.
|
|
28
|
+
:return: None
|
|
29
|
+
"""
|
|
30
|
+
self.__data.to_excel(file_name, index=False)
|
|
31
|
+
|
|
32
|
+
def show(self, n=5):
|
|
33
|
+
"""Print the first n rows of the data.
|
|
34
|
+
|
|
35
|
+
:param n: Number of rows to print.
|
|
36
|
+
:return: None, prints the head of the data.
|
|
37
|
+
"""
|
|
38
|
+
print(self.__name)
|
|
39
|
+
print(self.__data.head(n))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from hawk_sdk.futures.main import Futures
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""
|
|
2
|
+
@description: Datasource API for Hawk Global Futures data access and export functions.
|
|
3
|
+
@author: Rithwik Babu
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from hawk_sdk.common.bigquery_connector import BigQueryConnector
|
|
7
|
+
from hawk_sdk.common.data_object import DataObject
|
|
8
|
+
from hawk_sdk.futures.repository import FuturesRepository
|
|
9
|
+
from hawk_sdk.futures.service import FuturesService
|
|
10
|
+
from typing import List
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Futures:
|
|
14
|
+
"""Datasource API for fetching Futures data."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, project_id: str, credentials_path: str = None) -> None:
|
|
17
|
+
"""Initializes the Futures datasource with required configurations.
|
|
18
|
+
|
|
19
|
+
:param project_id: The GCP project ID.
|
|
20
|
+
:param credentials_path: Path to the Google Cloud credentials file.
|
|
21
|
+
"""
|
|
22
|
+
self.connector = BigQueryConnector(project_id, credentials_path)
|
|
23
|
+
self.repository = FuturesRepository(self.connector)
|
|
24
|
+
self.service = FuturesService(self.repository)
|
|
25
|
+
|
|
26
|
+
def get_ohlcvo(self, start_date: str, end_date: str, interval: str, hawk_ids: List[int]) -> DataObject:
|
|
27
|
+
"""Fetch open, high, low, close, volume, and open interest data for the given date range and hawk_ids.
|
|
28
|
+
|
|
29
|
+
:param start_date: The start date for the data query (YYYY-MM-DD).
|
|
30
|
+
:param end_date: The end date for the data query (YYYY-MM-DD).
|
|
31
|
+
:param interval: The interval for the data query (e.g., '1d', '1h', '1m').
|
|
32
|
+
:param hawk_ids: A list of specific hawk_ids to filter by.
|
|
33
|
+
:return: A hawk DataObject containing the data.
|
|
34
|
+
"""
|
|
35
|
+
return DataObject(
|
|
36
|
+
name="futures_ohlcvo",
|
|
37
|
+
data=self.service.get_ohlcvo(start_date, end_date, interval, hawk_ids)
|
|
38
|
+
)
|
|
39
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""
|
|
2
|
+
@description: Repository layer for fetching Futures data from BigQuery.
|
|
3
|
+
@author: Rithwik Babu
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from hawk_sdk.common.bigquery_connector import BigQueryConnector
|
|
7
|
+
from typing import Iterator, List
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class FuturesRepository:
|
|
11
|
+
"""Repository for accessing Futures raw data."""
|
|
12
|
+
|
|
13
|
+
def __init__(self, connector: BigQueryConnector) -> None:
|
|
14
|
+
"""Initializes the repository with a BigQuery connector.
|
|
15
|
+
|
|
16
|
+
:param connector: An instance of BigQueryConnector.
|
|
17
|
+
"""
|
|
18
|
+
self.connector = connector
|
|
19
|
+
|
|
20
|
+
def fetch_ohlcvo(self, start_date: str, end_date: str, interval: str, hawk_ids: List[int]) -> Iterator[dict]:
|
|
21
|
+
"""Fetches raw data from BigQuery 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: An iterator over raw data rows.
|
|
28
|
+
"""
|
|
29
|
+
hawk_ids_str = ', '.join(map(str, hawk_ids))
|
|
30
|
+
query = f"""
|
|
31
|
+
WITH records_data AS (
|
|
32
|
+
SELECT
|
|
33
|
+
r.record_timestamp AS date,
|
|
34
|
+
hi.value AS ticker,
|
|
35
|
+
MAX(CASE WHEN f.field_name = 'open_{interval}' THEN r.double_value END) AS open,
|
|
36
|
+
MAX(CASE WHEN f.field_name = 'high_{interval}' THEN r.double_value END) AS high,
|
|
37
|
+
MAX(CASE WHEN f.field_name = 'low_{interval}' THEN r.double_value END) AS low,
|
|
38
|
+
MAX(CASE WHEN f.field_name = 'close_{interval}' THEN r.double_value END) AS close,
|
|
39
|
+
MAX(CASE WHEN f.field_name = 'volume_{interval}' THEN r.int_value END) AS volume,
|
|
40
|
+
MAX(CASE WHEN f.field_name = 'open_interest_{interval}' THEN r.double_value END) AS open_interest
|
|
41
|
+
FROM
|
|
42
|
+
`wsb-hc-qasap-ae2e.development.records` AS r
|
|
43
|
+
JOIN
|
|
44
|
+
`wsb-hc-qasap-ae2e.development.fields` AS f
|
|
45
|
+
ON r.field_id = f.field_id
|
|
46
|
+
JOIN
|
|
47
|
+
`wsb-hc-qasap-ae2e.development.hawk_identifiers` AS hi
|
|
48
|
+
ON r.hawk_id = hi.hawk_id
|
|
49
|
+
WHERE
|
|
50
|
+
r.hawk_id IN ({hawk_ids_str})
|
|
51
|
+
AND f.field_name IN ('open_1d', 'high_1d', 'low_1d', 'close_1d', 'volume_1d', 'open_interest_1d')
|
|
52
|
+
AND r.record_timestamp BETWEEN '{start_date}' AND '{end_date}'
|
|
53
|
+
GROUP BY
|
|
54
|
+
date, ticker
|
|
55
|
+
)
|
|
56
|
+
SELECT
|
|
57
|
+
date,
|
|
58
|
+
ticker,
|
|
59
|
+
open,
|
|
60
|
+
high,
|
|
61
|
+
low,
|
|
62
|
+
close,
|
|
63
|
+
volume,
|
|
64
|
+
open_interest
|
|
65
|
+
FROM
|
|
66
|
+
records_data
|
|
67
|
+
ORDER BY
|
|
68
|
+
date;
|
|
69
|
+
"""
|
|
70
|
+
return self.connector.run_query(query)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""
|
|
2
|
+
@description: Service layer for processing and normalizing Futures data.
|
|
3
|
+
@author: Rithwik Babu
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from hawk_sdk.futures.repository import FuturesRepository
|
|
7
|
+
from typing import List, Iterator
|
|
8
|
+
import pandas as pd
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class FuturesService:
|
|
12
|
+
"""Service class for Futures business logic."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, repository: FuturesRepository) -> None:
|
|
15
|
+
"""Initializes the service with a repository.
|
|
16
|
+
|
|
17
|
+
:param repository: An instance of FuturesRepository for data access.
|
|
18
|
+
"""
|
|
19
|
+
self.repository = repository
|
|
20
|
+
|
|
21
|
+
def get_ohlcvo(self, start_date: str, end_date: str, interval: str, hawk_ids: List[int]) -> pd.DataFrame:
|
|
22
|
+
"""Fetches and normalizes data into a pandas DataFrame.
|
|
23
|
+
|
|
24
|
+
:param start_date: The start date for the data query (YYYY-MM-DD).
|
|
25
|
+
:param end_date: The end date for the data query (YYYY-MM-DD).
|
|
26
|
+
:param interval: The interval for the data query (e.g., '1d', '1h', '1m').
|
|
27
|
+
:param hawk_ids: A list of specific hawk_ids to filter by.
|
|
28
|
+
:return: A pandas DataFrame containing the normalized data.
|
|
29
|
+
"""
|
|
30
|
+
raw_data = self.repository.fetch_ohlcvo(start_date, end_date, interval, hawk_ids)
|
|
31
|
+
return self._normalize_data(raw_data)
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def _normalize_data(data: Iterator[dict]) -> pd.DataFrame:
|
|
35
|
+
"""Converts raw data into a normalized pandas DataFrame.
|
|
36
|
+
|
|
37
|
+
:param data: An iterator over raw data rows.
|
|
38
|
+
:return: A pandas DataFrame containing normalized data.
|
|
39
|
+
"""
|
|
40
|
+
return pd.DataFrame([dict(row) for row in data])
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
hawk_sdk/__init__.py
|
|
4
|
+
hawk_sdk.egg-info/PKG-INFO
|
|
5
|
+
hawk_sdk.egg-info/SOURCES.txt
|
|
6
|
+
hawk_sdk.egg-info/dependency_links.txt
|
|
7
|
+
hawk_sdk.egg-info/requires.txt
|
|
8
|
+
hawk_sdk.egg-info/top_level.txt
|
|
9
|
+
hawk_sdk/common/__init__.py
|
|
10
|
+
hawk_sdk/common/bigquery_connector.py
|
|
11
|
+
hawk_sdk/common/data_object.py
|
|
12
|
+
hawk_sdk/futures/__init__.py
|
|
13
|
+
hawk_sdk/futures/main.py
|
|
14
|
+
hawk_sdk/futures/repository.py
|
|
15
|
+
hawk_sdk/futures/service.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hawk_sdk
|
hawk-sdk-0.0.0/setup.cfg
ADDED