Skip to content

Commit

Permalink
added a friendly version of the candles list
Browse files Browse the repository at this point in the history
  • Loading branch information
kakulukia committed Apr 17, 2024
1 parent 79c2b25 commit 706ffb6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions jesse/strategies/Strategy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from abc import ABC, abstractmethod
import arrow
from time import sleep
from typing import List, Dict, Union

Expand Down Expand Up @@ -985,6 +986,36 @@ def candles(self) -> np.ndarray:
"""
return store.candles.get_candles(self.exchange, self.symbol, self.timeframe)

class Candle:
def __init__(self, data):
self.data = data
self.names = ['timestamp', 'open', 'close', 'high', 'low', 'volume']

def __getitem__(self, key):
if isinstance(key, str):
index = self.names.index(key)
return self.data[index]
else:
return self.data[key]

def __getattr__(self, name):
if name in self.names:
index = self.names.index(name)
return self.data[index]
else:
raise AttributeError(f"The candle object has no attribute '{name}'")

@property
def date(self):
return arrow.get(self.timestamp / 1000).to('UTC').format('YYYY-MM-DD HH:mm')

def __repr__(self):
return self.date

@property
def friendly_candles(self):
return [self.Candle(candle) for candle in self.candles]

def get_candles(self, exchange: str, symbol: str, timeframe: str) -> np.ndarray:
"""
Get candles by passing exchange, symbol, and timeframe
Expand Down

0 comments on commit 706ffb6

Please sign in to comment.