Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Models data #2

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/models/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""A model to store data from various ticker / asset classes to be
used in various strategy / backtesting environments"""

from ohlcv import OHLCV
from identification import Identifier


class Data:
"""The data class that stores and provides various
accessor and mutator functions to access and modify the stored data
"""

def __init__(self, identification=None, ohlcv=None) -> None:
"""The constructor for the data class that takes in an Identifier
Object, and an OHLCV object


Args:
identification (Identifier, optional): The ticker, exchange,
datasource, desc, etc data, to be used for identification
and debugging purposes. Defaults to None.

ohlcv (OHLCV, optional): The open, high, low, close, volume data,
to generate indicators and perform trading. Defaults to None.
"""
self.identification = identification if identification else Identifier()
self.ohlcv = ohlcv if ohlcv else OHLCV()

def ohlcv_get_ltp(self):
"""Get the last traded price for a particular asset.
This is helpful for monitoring and the such.

Returns:
Float: The last traded price of an asset.
"""
return self.ohlcv.get_last_close()

def ohlcv_update_prices(self, )
4 changes: 4 additions & 0 deletions src/models/identification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Identifier:

def __init__(self) -> None:
pass
23 changes: 23 additions & 0 deletions src/models/ohlcv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class OHLCV:
def __init__(
self,
timestamp_list=[],
open_list=[],
high_list=[],
low_list=[],
close_list=[],
volume_list=[],
) -> None:
self.timestamps = timestamp_list
self.open = open_list
self.high = high_list
self.low = low_list
self.close = close_list
self.volume = volume_list

def get_last_close(self):
try:
last = self.close[-1]
except IndexError:
# given index does not exist in the data frame
print("NO OHLC data has been defined for this")
2 changes: 2 additions & 0 deletions src/models/test_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from ohlcv import OHLCV
from identification import Identifier
Empty file.
Empty file added src/models/test_ohlcv.py
Empty file.