Skip to content
Open
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
22 changes: 14 additions & 8 deletions src/openalgo_bt/utils/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Initialize OpenAlgo client
client = api(
api_key=os.getenv('OPENALGO_API_KEY'), # Set OPENALGO_API_KEY in your .env file
host='http://127.0.0.1:5000'
host=os.getenv('OPENALGO_API_HOST')
)

def history(symbol, start, end_date, interval="D", exchange=None, use_cache=False):
Expand Down Expand Up @@ -87,7 +87,19 @@ def history(symbol, start, end_date, interval="D", exchange=None, use_cache=Fals

from diskcache import Cache

ltpbulk_cache = Cache('/Users/sudranga1/workspace/openalgo_strategies/cache/ltp_bulk/')
from pathlib import Path
import os

cache_dir = Path.home() / ".openalgo_bt_cache"
cache_dir.mkdir(exist_ok=True)


ltpbulk_cache = Cache(cache_dir / "ltp_bulk")

ltp_cache = Cache(cache_dir / "ltp")

# 9:30am price fetcher with cache
morn_cache = Cache(cache_dir / "930am")

@ltpbulk_cache.memoize(name='ltp_bulk')
def fetch_ltp_bulk(symbols, current_date):
Expand All @@ -103,9 +115,6 @@ def fetch_ltp_bulk(symbols, current_date):
ltp_dict[symbol] = None
return ltp_dict


ltp_cache = Cache('/Users/sudranga1/workspace/openalgo_strategies/cache/ltp/')

@ltp_cache.memoize(name='ltp')
def get_ltp(symbol, current_date):
"""
Expand Down Expand Up @@ -135,9 +144,6 @@ def get_ltp(symbol, current_date):
print(f"Error fetching LTP from OpenAlgo API for {symbol} on {query_date}: {e}")
raise ValueError(f"LTP fetch failed: {symbol} on {query_date}: {e}")

# 9:30am price fetcher with cache
morn_cache = Cache('/Users/sudranga1/workspace/openalgo_strategies/cache/930am/')

@morn_cache.memoize(name='930am')
def fetch_930am_price(symbol, date):
"""
Expand Down