def test_get_past_candle_2(): set_up() candle1 = fake_candle() candle2 = fake_candle() store.candles.add_candle(candle1, 'Sandbox', 'BTCUSD', '1m') store.candles.add_candle(candle2, 'Sandbox', 'BTCUSD', '1m') np.testing.assert_equal( store.candles.get_past_candle('Sandbox', 'BTCUSD', '1m', 1), candle1)
def test_can_add_new_candle(): set_up() np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTCUSD', '1m'), np.zeros((0, 6))) c1 = fake_candle() store.candles.add_candle(c1, 'Sandbox', 'BTCUSD', '1m') np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTCUSD', '1m')[0], c1) # try to add duplicate store.candles.add_candle(c1, 'Sandbox', 'BTCUSD', '1m') # assert to make sure it's the same np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTCUSD', '1m')[0], c1) c2 = fake_candle() store.candles.add_candle(c2, 'Sandbox', 'BTCUSD', '1m') np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTCUSD', '1m'), np.array([c1, c2]))
def test_can_update_candle(): set_up() np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTCUSD', '1m'), np.zeros((0, 6))) # add it c1 = fake_candle() store.candles.add_candle(c1, 'Sandbox', 'BTCUSD', '1m') np.testing.assert_equal(store.candles.get_current_candle('Sandbox', 'BTCUSD', '1m'), c1) # now update it with another candle which has the same timestamp c2 = c1.copy() c2[1] = 1000 store.candles.add_candle(c2, 'Sandbox', 'BTCUSD', '1m') np.testing.assert_equal(store.candles.get_current_candle('Sandbox', 'BTCUSD', '1m'), c2) assert len(store.candles.get_candles('Sandbox', 'BTCUSD', '1m')) == 1
def fake_candle(attributes: dict = None, reset: bool = False) -> np.ndarray: """ Generates a fake candle. """ return factories.fake_candle(attributes, reset)