Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
tfukaza committed May 22, 2024
1 parent 1c64c8f commit fe91001
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 52 deletions.
21 changes: 13 additions & 8 deletions harvest/algo.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
# Builtins
from datetime import timedelta, timezone
import datetime as dt
from typing import Any, List, Tuple
import math
from datetime import timezone
from typing import List, Tuple

# External libraries
from finta import TA
import numpy as np
import pandas as pd
from finta import TA

from harvest.definitions import *
from harvest.util.helper import *
from harvest.definitions import Interval
from harvest.plugin._base import Plugin
from harvest.util.date import datetime_utc_to_local
from harvest.util.helper import (
convert_input_to_datetime,
debugger,
interval_string_to_enum,
mark_up,
pandas_timestamp_to_local,
symbol_type,
)

"""
Algo class is the main interface between users and the program.
Expand Down
16 changes: 8 additions & 8 deletions harvest/plugin/_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import List
from harvest.util.helper import debugger


class Plugin:
Expand All @@ -11,7 +10,7 @@ class Plugin:
{Name of source}{Functionality added}Plugin
"""

def __init__(self, name: str, dependencies: List[str] = []) -> None:
def __init__(self, name: str, dependencies: List[str] = None) -> None:
"""
:name: a string that will serve as the name of the plugin. Must
be a valid python variable because in the algo class, this plugin
Expand All @@ -33,9 +32,10 @@ def installation(self) -> str:
raise NotImplementedError(f"No installation steps for plugin: {type(self).__name__}")

def _check_dependency(self, dep: str) -> None:
try:
exec(f"import {dep}")
except ModuleNotFoundError as e:
debugger.error(f"Error importing module!\n {e}")
debugger.error(self.installation())
raise e
# try:
# exec(f"import {dep}")
# except ModuleNotFoundError as e:
# debugger.error(f"Error importing module!\n {e}")
# debugger.error(self.installation())
# raise e
pass
5 changes: 2 additions & 3 deletions harvest/plugin/dolt_options_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from harvest.plugin._base import Plugin


class DoltOptionsPlugin:
class DoltOptionsPlugin(Plugin):
"""
Interfaces with the Dolt CLI to get data from the
`https://www.dolthub.com/repositories/post-no-preference/options`
Expand All @@ -15,8 +15,7 @@ def __init__(self, name: str = "dolt_options", path: str = "options") -> None:
:path: The path to the post-no-preference/options repo.
"""
super.__init__(name, ["doltpy"])
from doltpy.cli import Dolt
from doltpy.cli import read
from doltpy.cli import Dolt, read

self.dolt = Dolt(path)
self.read = read
Expand Down
14 changes: 6 additions & 8 deletions harvest/server.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import logging
from flask import Flask, render_template, request, redirect
from werkzeug.security import generate_password_hash, check_password_hash
from flask_cors import CORS
import threading
import json
import threading

from flask import Flask, redirect, render_template, request
from flask_login import (
LoginManager,
login_user,
UserMixin,
current_user,
login_required,
login_user,
logout_user,
current_user,
UserMixin,
)
from werkzeug.security import check_password_hash, generate_password_hash

from harvest.util.helper import debugger

Expand Down
18 changes: 9 additions & 9 deletions harvest/storage/base_storage.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from numpy import ERR_CALL
import pandas as pd
import datetime as dt
from threading import Lock
from typing import Tuple
import re
from typing import Any, Dict

import pandas as pd

from harvest.definitions import *
from harvest.util.helper import *
from harvest.definitions import Stats
from harvest.enum import Interval
from harvest.util.helper import aggregate_df, debugger, interval_to_timedelta, symbol_type

"""
This module serves as a basic storage system for pandas dataframes in memory.
Expand Down Expand Up @@ -132,9 +132,9 @@ def store(self, symbol: str, interval: Interval, data: pd.DataFrame, remove_dupl
intervals[interval] = self._append(intervals[interval], data, remove_duplicate=remove_duplicate)
if self.price_storage_limit:
intervals[interval] = intervals[interval][-self.price_storage_size :]
except:
except Exception:
self.storage_lock.release()
raise Exception("Append Failure, case not found!")
debugger.error("Append Failure, case not found!")
else:
# Add the data as a new interval
intervals[interval] = data
Expand Down Expand Up @@ -350,7 +350,7 @@ def aggregate(
self.storage_lock.release()

def init_performace_data(self, equity: float, timestamp: dt.datetime) -> None:
for interval, days in self.performance_history_intervals:
for interval, _ in self.performance_history_intervals:
self.storage_performance[interval] = pd.DataFrame({"equity": [equity]}, index=[timestamp])

def add_performance_data(self, equity: float, timestamp: dt.datetime) -> None:
Expand Down
9 changes: 4 additions & 5 deletions harvest/storage/csv_storage.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import re
from os import listdir, makedirs
from os.path import isfile, join

import pandas as pd
import datetime as dt
from typing import Tuple

from harvest.definitions import Interval
from harvest.storage import BaseStorage
from harvest.definitions import *
from harvest.util.helper import *

from harvest.util.helper import debugger, interval_enum_to_string, interval_string_to_enum

"""
This module serves as a storage system for pandas dataframes in with csv files.
Expand All @@ -35,6 +33,7 @@ def __init__(self, save_dir: str = "data") -> None:

for file in files:
debugger.debug(file)
# trunk-ignore(ruff/W605)
file_search = re.search("^(@?[\w]+)@([\w]+).csv$", file)
symbol, interval = file_search.group(1), file_search.group(2)
interval = interval_string_to_enum(interval)
Expand Down
9 changes: 3 additions & 6 deletions harvest/storage/database_storage.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import re
import pandas as pd
import datetime as dt
from typing import Tuple

from sqlalchemy import create_engine, select
from sqlalchemy import Column, Integer, String, DateTime, Float, String
import pandas as pd
from sqlalchemy import Column, DateTime, Float, String, create_engine, select
from sqlalchemy.orm import declarative_base, sessionmaker

from harvest.storage import BaseStorage
from harvest.definitions import *
from harvest.util.helper import *
from harvest.util.helper import aggregate_df, normalize_pandas_dt_index

"""
This module serves as a storage system for pandas dataframes in with SQL tables.
Expand Down
8 changes: 3 additions & 5 deletions harvest/storage/pickle_storage.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import re
from os import listdir, makedirs
from os.path import isfile, join

import pandas as pd
import datetime as dt
from typing import Tuple

from harvest.definitions import Interval
from harvest.storage import BaseStorage
from harvest.definitions import *
from harvest.util.helper import *
from harvest.util.helper import interval_enum_to_string, interval_string_to_enum

"""
This module serves as a storage system for pandas dataframes in with pickle files.
Expand Down

0 comments on commit fe91001

Please sign in to comment.