Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.4.239] - 2024-12-19
### Added
[Enum] Option Exchange Type
[Exchanges] Polymarket tests

## [2.4.238] - 2024-12-17
### Fixes
[CCXT] fix failed market fetch
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OctoBot-Trading [2.4.238](https://github.com/Drakkar-Software/OctoBot-Trading/blob/master/CHANGELOG.md)
# OctoBot-Trading [2.4.239](https://github.com/Drakkar-Software/OctoBot-Trading/blob/master/CHANGELOG.md)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/903b6b22bceb4661b608a86fea655f69)](https://app.codacy.com/gh/Drakkar-Software/OctoBot-Trading?utm_source=github.com&utm_medium=referral&utm_content=Drakkar-Software/OctoBot-Trading&utm_campaign=Badge_Grade_Dashboard)
[![PyPI](https://img.shields.io/pypi/v/OctoBot-Trading.svg)](https://pypi.python.org/pypi/OctoBot-Trading/)
[![Coverage Status](https://coveralls.io/repos/github/Drakkar-Software/OctoBot-Trading/badge.svg?branch=master)](https://coveralls.io/github/Drakkar-Software/OctoBot-Trading?branch=master)
Expand Down
2 changes: 1 addition & 1 deletion octobot_trading/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# License along with this library.

PROJECT_NAME = "OctoBot-Trading"
VERSION = "2.4.238" # major.minor.revision
VERSION = "2.4.239" # major.minor.revision
1 change: 1 addition & 0 deletions octobot_trading/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ class ExchangeTypes(enum.Enum):
SPOT = "spot"
FUTURE = "future"
MARGIN = "margin"
OPTION = "option"
UNKNOWN = "unknown"


Expand Down
58 changes: 30 additions & 28 deletions tests_additional/real_exchanges/real_exchange_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ async def inner_test_get_order_books(
supports_custom_limit: bool,
custom_limit: typing.Optional[int],
max_empty_book_sides: int,
supports_without_symbols_filter: bool,
):
async with (self.get_exchange_manager() as exchange_manager):
# with symbols filter
Expand Down Expand Up @@ -205,36 +206,37 @@ async def inner_test_get_order_books(
f"More empty book sides than expected: {max_empty_book_sides=} {empty_book_sides=}"
)
# without symbols filter
books_by_symbol = await exchange_manager.exchange.get_order_books(symbols=None)
empty_book_sides = []
assert len(books_by_symbol) >= expected_missing_symbol_filter_books_min_count, (
f"{len(books_by_symbol)=} NOT >= {expected_missing_symbol_filter_books_min_count=}"
)
for symbol, book in books_by_symbol.items():
assert 0 < book[trading_enums.ExchangeConstantsOrderBookInfoColumns.TIMESTAMP.value] < ref_time, (
f"Invalid {symbol} book timestamp value: "
f"{book[trading_enums.ExchangeConstantsOrderBookInfoColumns.TIMESTAMP.value]}, {ref_time=}"
if supports_without_symbols_filter:
books_by_symbol = await exchange_manager.exchange.get_order_books(symbols=None)
empty_book_sides = []
assert len(books_by_symbol) >= expected_missing_symbol_filter_books_min_count, (
f"{len(books_by_symbol)=} NOT >= {expected_missing_symbol_filter_books_min_count=}"
)
for side in [
trading_enums.ExchangeConstantsOrderBookInfoColumns.BIDS,
trading_enums.ExchangeConstantsOrderBookInfoColumns.ASKS
]:
if len(book[side.value]) == 0:
empty_book_sides.append((symbol, side))
else:
assert min_book_orders_count <= len(book[side.value]) <= expected_max_orders_by_side, (
f"Unexpected {symbol} {side.value} orders count: {len(book[side.value])}. Expected: "
f"[{min_book_orders_count}:{expected_max_orders_by_side}]"
)
if len(empty_book_sides) > max_empty_book_sides:
raise AssertionError(
f"More empty book sides than expected: {max_empty_book_sides=} {len(empty_book_sides)=}"
for symbol, book in books_by_symbol.items():
assert 0 < book[trading_enums.ExchangeConstantsOrderBookInfoColumns.TIMESTAMP.value] < ref_time, (
f"Invalid {symbol} book timestamp value: "
f"{book[trading_enums.ExchangeConstantsOrderBookInfoColumns.TIMESTAMP.value]}, {ref_time=}"
)
for side in [
trading_enums.ExchangeConstantsOrderBookInfoColumns.BIDS,
trading_enums.ExchangeConstantsOrderBookInfoColumns.ASKS
]:
if len(book[side.value]) == 0:
empty_book_sides.append((symbol, side))
else:
assert min_book_orders_count <= len(book[side.value]) <= expected_max_orders_by_side, (
f"Unexpected {symbol} {side.value} orders count: {len(book[side.value])}. Expected: "
f"[{min_book_orders_count}:{expected_max_orders_by_side}]"
)
if len(empty_book_sides) > max_empty_book_sides:
raise AssertionError(
f"More empty book sides than expected: {max_empty_book_sides=} {len(empty_book_sides)=}"
)
# with custom limit
books_by_symbol = await exchange_manager.exchange.get_order_books(symbols=None, limit=custom_limit)
self._ensure_book_custom_limit(
books_by_symbol, supports_custom_limit, expected_max_orders_by_side, custom_limit
)
# with custom limit
books_by_symbol = await exchange_manager.exchange.get_order_books(symbols=None, limit=custom_limit)
self._ensure_book_custom_limit(
books_by_symbol, supports_custom_limit, expected_max_orders_by_side, custom_limit
)

def _ensure_book_custom_limit(
self,
Expand Down
1 change: 1 addition & 0 deletions tests_additional/real_exchanges/test_hitbtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ async def test_get_order_books(self):
True,
10,
140,
True
)

async def test_get_recent_trades(self):
Expand Down
1 change: 1 addition & 0 deletions tests_additional/real_exchanges/test_hollaex.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ async def test_get_order_books(self):
False,
None,
1,
True
)

async def test_get_recent_trades(self):
Expand Down
182 changes: 182 additions & 0 deletions tests_additional/real_exchanges/test_polymarket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# Drakkar-Software OctoBot-Trading
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
import pytest

from octobot_commons.enums import TimeFrames, PriceIndexes
from octobot_trading.enums import ExchangeConstantsMarketStatusColumns as Ecmsc, \
ExchangeConstantsOrderBookInfoColumns as Ecobic, ExchangeConstantsOrderColumns as Ecoc, \
ExchangeConstantsTickersColumns as Ectc
from tests_additional.real_exchanges.real_exchange_tester import RealExchangeTester
import octobot_trading.enums as trading_enums
# required to catch async loop context exceptions
from tests import event_loop

try:
import tentacles.Trading.Exchange.polymarket.ccxt.polymarket_async
except ImportError:
pytest.skip(
reason=(
"Polymarket tentacle is not installed, skipping TestPolymarketRealExchangeTester"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

)
)

# All test coroutines will be treated as marked.
pytestmark = pytest.mark.asyncio


class TestPolymarketRealExchangeTester(RealExchangeTester):
EXCHANGE_NAME = "polymarket"
SYMBOL = "will-bitcoin-replace-sha-256-before-2027/USDC"
SYMBOL_2 = "will-the-us-confirm-that-aliens-exist-before-2027/USDC"
SYMBOL_3 = "10pt0-or-above-earthquake-before-2027/USDC"
TIME_FRAME = TimeFrames.ONE_MINUTE
MARKET_STATUS_TYPE = trading_enums.ExchangeTypes.OPTION.value

async def test_time_frames(self):
time_frames = await self.time_frames()
assert all(time_frame in time_frames for time_frame in (
TimeFrames.ONE_MINUTE.value,
TimeFrames.ONE_HOUR.value,
TimeFrames.SIX_HOURS.value,
TimeFrames.ONE_DAY.value,
TimeFrames.ONE_WEEK.value,
))

async def test_active_symbols(self):
await self.inner_test_active_symbols(18412, 18412)

async def test_get_market_status(self):
for market_status in await self.get_market_statuses():
self.ensure_required_market_status_values(market_status)
self.check_market_status_limits(market_status, has_price_limits=True)

async def test_get_symbol_prices(self):
# without limit
symbol_prices = await self.get_symbol_prices()
assert len(symbol_prices) >= 1000
# check candles order (oldest first)
self.ensure_elements_order(symbol_prices, PriceIndexes.IND_PRICE_TIME.value)
# check last candle is the current candle
assert symbol_prices[-1][PriceIndexes.IND_PRICE_TIME.value] >= self.get_time() - self.get_allowed_time_delta()

# try with candles limit (used in candled updater)
symbol_prices = await self.get_symbol_prices(limit=200)
assert len(symbol_prices) == 200
# check candles order (oldest first)
self.ensure_elements_order(symbol_prices, PriceIndexes.IND_PRICE_TIME.value)
# check last candle is the current candle
assert symbol_prices[-1][PriceIndexes.IND_PRICE_TIME.value] >= self.get_time() - self.get_allowed_time_delta()

async def test_get_historical_symbol_prices(self):
# try with since and limit (used in data collector)
for limit in (50, None):
symbol_prices = await self.get_symbol_prices(since=self.CANDLE_SINCE, limit=limit)
if limit:
assert len(symbol_prices) == limit
else:
assert len(symbol_prices) > 5
# check candles order (oldest first)
self.ensure_elements_order(symbol_prices, PriceIndexes.IND_PRICE_TIME.value)
# check that fetched candles are historical candles
max_candle_time = self.get_time_after_time_frames(self.CANDLE_SINCE_SEC, len(symbol_prices))
assert max_candle_time <= self.get_time()
with pytest.raises(AssertionError): # not supported
for candle in symbol_prices:
assert self.CANDLE_SINCE_SEC <= candle[PriceIndexes.IND_PRICE_TIME.value] <= max_candle_time

async def test_get_historical_ohlcv(self):
await super().test_get_historical_ohlcv()

async def test_get_kline_price(self):
kline_price = await self.get_kline_price()
assert len(kline_price) == 1
assert len(kline_price[0]) == 6
kline_start_time = kline_price[0][PriceIndexes.IND_PRICE_TIME.value]
# assert kline is the current candle
assert kline_start_time >= self.get_time() - self.get_allowed_time_delta()

async def test_get_order_book(self):
order_book = await self.get_order_book()
assert 0 < order_book[Ecobic.TIMESTAMP.value] < self._get_ref_order_book_timestamp()
assert len(order_book[Ecobic.ASKS.value]) >= 5
assert len(order_book[Ecobic.ASKS.value][0]) == 2
assert len(order_book[Ecobic.BIDS.value]) >= 5
assert len(order_book[Ecobic.BIDS.value][0]) == 2

async def test_get_order_books(self):
await self.inner_test_get_order_books(
True,
1000, # asked symbols
100, # up to 100 orders
0, # from 0 orders
False,
None,
0,
False
)

async def test_get_recent_trades(self):
recent_trades = await self.get_recent_trades()
assert len(recent_trades) == 50
# check trades order (oldest first)
self.ensure_elements_order(recent_trades, Ecoc.TIMESTAMP.value)

async def test_get_price_ticker(self):
ticker = await self.get_price_ticker()
self._check_ticker(ticker, self.SYMBOL, check_content=True)

async def test_get_all_currencies_price_ticker(self):
tickers = await self.get_all_currencies_price_ticker()
for symbol, ticker in tickers.items():
self._check_ticker(ticker, symbol)

@staticmethod
def _check_ticker(ticker, symbol, check_content=False):
assert ticker[Ectc.SYMBOL.value] == symbol
assert all(key in ticker for key in (
Ectc.HIGH.value,
Ectc.LOW.value,
Ectc.BID.value,
Ectc.BID_VOLUME.value,
Ectc.ASK.value,
Ectc.ASK_VOLUME.value,
Ectc.OPEN.value,
Ectc.CLOSE.value,
Ectc.LAST.value,
Ectc.PREVIOUS_CLOSE.value
))
if check_content:
assert ticker[Ectc.HIGH.value] is None
assert ticker[Ectc.LOW.value] is None
assert ticker[Ectc.BID.value]
assert ticker[Ectc.BID_VOLUME.value] is None
assert ticker[Ectc.ASK.value]
assert ticker[Ectc.ASK_VOLUME.value] is None
assert ticker[Ectc.OPEN.value] is None
assert ticker[Ectc.CLOSE.value]
assert ticker[Ectc.LAST.value]
assert ticker[Ectc.PREVIOUS_CLOSE.value] is None
assert ticker[Ectc.BASE_VOLUME.value]
assert ticker[Ectc.TIMESTAMP.value]
RealExchangeTester.check_ticker_typing(
ticker,
check_open=False,
check_high=False,
check_low=False,
check_close=True,
check_base_volume=True,
check_timestamp=True
)
1 change: 1 addition & 0 deletions tests_additional/real_exchanges/test_upbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ async def test_get_order_books(self):
False,
10,
10,
True
)

async def test_get_recent_trades(self):
Expand Down