mirror of
https://github.com/Ichinga-Samuel/aiomql.git
synced 2026-08-22 00:08:08 +00:00
change candles indexing
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
import pytz
|
||||
import pandas as pd
|
||||
from pandas import Series
|
||||
|
||||
from aiomql.lib.candle import Candle, Candles
|
||||
from aiomql.core.meta_trader import MetaTrader
|
||||
from aiomql.core.constants import TimeFrame
|
||||
@@ -11,8 +12,8 @@ from aiomql.core.constants import TimeFrame
|
||||
class TestCandle:
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
cls.bullish_candle = Candle(open=1.3421, high=1.3462, low=1.3405, close=1.3452, time=0, Index=0)
|
||||
cls.bearish_candle = Candle(open=1.3452, high=1.3405, low=1.3462, close=1.3421, time=1, Index=1)
|
||||
cls.bullish_candle = Candle(open=1.3421, high=1.3462, low=1.3405, close=1.3452)
|
||||
cls.bearish_candle = Candle(open=1.3452, high=1.3405, low=1.3462, close=1.3421)
|
||||
|
||||
def test_repr(self):
|
||||
repr_str = repr(self.bearish_candle)
|
||||
@@ -48,6 +49,10 @@ class TestCandle:
|
||||
assert self.bearish_candle.is_bearish()
|
||||
assert self.bullish_candle.is_bullish()
|
||||
|
||||
def test_to_series(self):
|
||||
ser = self.bearish_candle.to_series()
|
||||
assert isinstance(ser, Series)
|
||||
|
||||
|
||||
class TestCandles:
|
||||
@pytest.fixture(scope="class")
|
||||
@@ -57,6 +62,13 @@ class TestCandles:
|
||||
rates = await mt.copy_rates_from("BTCUSD", mt.TIMEFRAME_H1, start, 200)
|
||||
return Candles(data=rates)
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
async def candles_2(self):
|
||||
mt = MetaTrader()
|
||||
start = datetime(day=5, month=10, year=2023)
|
||||
rates = await mt.copy_rates_from("BTCUSD", mt.TIMEFRAME_H1, start, 300)
|
||||
return Candles(data=rates)
|
||||
|
||||
def test_get_series(self, candles):
|
||||
series = candles["open"]
|
||||
assert isinstance(series, pd.Series)
|
||||
@@ -102,3 +114,35 @@ class TestCandles:
|
||||
assert isinstance(fas, pd.Series)
|
||||
candles["fas"] = fas
|
||||
assert "fas" in candles.data.columns
|
||||
|
||||
def test_add_candles(self, candles, candles_2):
|
||||
nc = candles + candles_2
|
||||
candles += candles_2
|
||||
assert len(nc) == 300
|
||||
assert len(candles) == 300
|
||||
|
||||
def test_add_candle(self, candles):
|
||||
length = len(candles)
|
||||
candle = candles[-1]
|
||||
now = datetime.now()
|
||||
candle.time = now.timestamp()
|
||||
candle.index = pd.Timestamp(candle.time, unit="s", tz=now.astimezone().tzinfo)
|
||||
candles.add(candle)
|
||||
assert len(candles) == length + 1
|
||||
|
||||
def test_add_series(self, candles):
|
||||
candle = candles[-1]
|
||||
length = len(candles)
|
||||
now = datetime.now()
|
||||
candle.time = now.timestamp()
|
||||
series = candle.to_series()
|
||||
candles.add(series)
|
||||
assert len(candles) == length + 1
|
||||
|
||||
def test_add_dataframe(self, candles, candles_2):
|
||||
df = candles_2._data.iloc[0:3]
|
||||
now = datetime.now()
|
||||
df.index = pd.DatetimeIndex(df.time, tz=now.astimezone().tzinfo)
|
||||
length = len(candles)
|
||||
candles.add(df)
|
||||
assert len(candles) == length + len(df)
|
||||
|
||||
@@ -11,8 +11,7 @@ class TestSymbol:
|
||||
@pytest.fixture(scope="class", autouse=True)
|
||||
async def btc(self):
|
||||
symbol = Symbol(name="BTCUSD")
|
||||
select = getattr(symbol, "select", False)
|
||||
if select is False:
|
||||
if symbol.initialized is False:
|
||||
await symbol.initialize()
|
||||
return symbol
|
||||
|
||||
|
||||
Reference in New Issue
Block a user