Skip to content

Commit

Permalink
fix exchange timeframe operation cython header
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume De Saint Martin committed May 17, 2020
1 parent 407838b commit cade2ea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion octobot_trading/exchanges/rest_exchange.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ cdef class RestExchange(AbstractExchange):
cpdef tuple get_split_pair_from_exchange(self, str pair)
cpdef dict get_default_balance(self)
cpdef void set_sandbox_mode(self, bint is_sandboxed)
cpdef long get_candle_since_timestamp(self, object time_frame, int count)
cpdef object get_candle_since_timestamp(self, object time_frame, int count)

# parsers
cpdef dict parse_balance(self, dict balance)
Expand Down
34 changes: 34 additions & 0 deletions tests/exchanges/test_exchanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,25 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
import pytest
from mock import patch
from datetime import datetime

from octobot_commons.constants import MSECONDS_TO_MINUTE
from octobot_commons.enums import TimeFrames, TimeFramesMinutes
from octobot_commons.tests.test_config import load_test_config
from octobot_trading.exchanges.exchange_manager import ExchangeManager
from octobot_trading.exchanges.exchanges import Exchanges

pytestmark = pytest.mark.asyncio


MS_TIMESTAMP = round((datetime.utcnow() - datetime(1970, 1, 1)).total_seconds() * 1000)


def get_constant_ms_timestamp():
return MS_TIMESTAMP


class TestExchanges:
@staticmethod
async def init_default():
Expand Down Expand Up @@ -129,3 +140,26 @@ async def test_get_all_exchanges(self):
await exchange_manager_binance.stop()
await exchange_manager_bitmex.stop()
await exchange_manager_poloniex.stop()

async def test_ms_timestamp_operations(self):
config = await self.init_default()
exchange_manager_bitmex = ExchangeManager(config, "bitmex")
await exchange_manager_bitmex.initialize()
await exchange_manager_bitmex.stop()

exchange = exchange_manager_bitmex.exchange
with patch.object(exchange.client, 'milliseconds', new=get_constant_ms_timestamp):
expected_ms_timestamp = MS_TIMESTAMP - TimeFramesMinutes[TimeFrames.ONE_HOUR] * MSECONDS_TO_MINUTE * 200
assert exchange.get_candle_since_timestamp(TimeFrames.ONE_HOUR, count=200) == expected_ms_timestamp

expected_ms_timestamp = MS_TIMESTAMP - TimeFramesMinutes[TimeFrames.ONE_WEEK] * MSECONDS_TO_MINUTE * 200
assert exchange.get_candle_since_timestamp(TimeFrames.ONE_WEEK, count=200) == expected_ms_timestamp

expected_ms_timestamp = MS_TIMESTAMP - TimeFramesMinutes[TimeFrames.ONE_MONTH] * MSECONDS_TO_MINUTE * 2000
assert exchange.get_candle_since_timestamp(TimeFrames.ONE_MONTH, count=2000) == expected_ms_timestamp

expected_ms_timestamp = MS_TIMESTAMP - TimeFramesMinutes[TimeFrames.ONE_MINUTE] * MSECONDS_TO_MINUTE * 10
assert exchange.get_candle_since_timestamp(TimeFrames.ONE_MINUTE, count=10) == expected_ms_timestamp

expected_ms_timestamp = MS_TIMESTAMP - TimeFramesMinutes[TimeFrames.ONE_MINUTE] * MSECONDS_TO_MINUTE * 0
assert exchange.get_candle_since_timestamp(TimeFrames.ONE_MINUTE, count=0) == expected_ms_timestamp

0 comments on commit cade2ea

Please sign in to comment.