pybinbot 2.1.3__tar.gz → 2.1.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pybinbot-2.1.3/pybinbot.egg-info → pybinbot-2.1.4}/PKG-INFO +24 -1
- {pybinbot-2.1.3 → pybinbot-2.1.4}/README.md +23 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/__init__.py +4 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/apis/binbot/base.py +23 -0
- pybinbot-2.1.4/pybinbot/models/cvd.py +30 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4/pybinbot.egg-info}/PKG-INFO +24 -1
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot.egg-info/SOURCES.txt +2 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pyproject.toml +1 -1
- pybinbot-2.1.4/tests/test_cvd_api.py +132 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/LICENSE +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/MANIFEST.in +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/apis/binance/base.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/apis/binance/exceptions.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/apis/binbot/exceptions.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/apis/coingecko.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/apis/kucoin/base.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/apis/kucoin/exceptions.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/apis/kucoin/futures.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/apis/kucoin/market.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/apis/kucoin/orders.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/apis/kucoin/rest.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/models/__init__.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/models/autotrade_settings.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/models/bot.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/models/bot_base.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/models/deal.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/models/derivatives.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/models/grid_ladder.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/models/order.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/models/routes.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/models/signals.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/models/symbol.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/py.typed +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/shared/__init__.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/shared/beta.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/shared/breadth.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/shared/cache.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/shared/candles.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/shared/enums.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/shared/handlers.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/shared/heikin_ashi.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/shared/indicators.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/shared/logging_config.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/shared/maths.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/shared/price_crossings.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/shared/telegram_delivery.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/shared/timestamps.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/shared/types.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/shared/utils.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/streaming/binance/async_socket_client.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/streaming/binance/socket_client.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/streaming/binance/socket_manager.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot/streaming/kucoin/kucoin_async_client.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot.egg-info/dependency_links.txt +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot.egg-info/requires.txt +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/pybinbot.egg-info/top_level.txt +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/setup.cfg +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_beta.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_binbot_api.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_bot_futures_leverage.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_breadth.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_candles.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_closed_bot_status.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_coingecko.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_conditional_entry.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_conditional_futures_orders.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_deal_model.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_derivatives_api.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_futures_place_order.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_grid_ladder.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_handlers.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_heikin_ashi.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_indicators.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_kucoin_api.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_logging_config.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_matching_engine.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_maths.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_price_crossings.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_symbol_model.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_telegram_delivery.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_timestamps.py +0 -0
- {pybinbot-2.1.3 → pybinbot-2.1.4}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pybinbot
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.4
|
|
4
4
|
Summary: Utility functions for the binbot project.
|
|
5
5
|
Author-email: Carlos Wu <carkodw@gmail.com>
|
|
6
6
|
Requires-Python: >=3.15
|
|
@@ -70,6 +70,29 @@ the highest selling price or lowest buying price; fills depend on the order book
|
|
|
70
70
|
from the futures ticker. The spot client exposes the same method for spot prices;
|
|
71
71
|
`KucoinFutures.get_mark_price(symbol)` remains available for mark prices.
|
|
72
72
|
|
|
73
|
+
## Stored CVD data
|
|
74
|
+
|
|
75
|
+
`BinbotApi` exposes the recorded KuCoin futures CVD endpoints:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
symbol_cvd = await api.get_cvd_symbol("RUMUSDTM", limit=15)
|
|
79
|
+
market_cvd = await api.get_cvd_aggregate(limit=15)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`CvdSymbolResponse`, `CvdAggregateResponse` and `CvdPoint` are public exports.
|
|
83
|
+
Symbol observations are one-minute buckets; aggregate observations are
|
|
84
|
+
15-minute buckets. Both are oldest first and retain the current/partial,
|
|
85
|
+
coverage, gap, universe or contract multiplier change, reset, and checkpoint
|
|
86
|
+
freshness fields. Missing values remain `None`, and empty collections remain
|
|
87
|
+
empty. Timestamp fields require time zones and numeric observations must be
|
|
88
|
+
finite. The endpoint responses are bare snapshots rather than
|
|
89
|
+
`StandardResponse` envelopes. Request and validation errors propagate to the
|
|
90
|
+
caller; a failed request never becomes a zero-valued reading.
|
|
91
|
+
|
|
92
|
+
Publish a new PyPI release before consuming these methods in binquant or
|
|
93
|
+
binbot, then upgrade each consumer's minimum dependency and lockfile to that
|
|
94
|
+
release.
|
|
95
|
+
|
|
73
96
|
## Telegram delivery
|
|
74
97
|
|
|
75
98
|
Import `TelegramDelivery` from `pybinbot.shared.telegram_delivery`. Initialization
|
|
@@ -41,6 +41,29 @@ the highest selling price or lowest buying price; fills depend on the order book
|
|
|
41
41
|
from the futures ticker. The spot client exposes the same method for spot prices;
|
|
42
42
|
`KucoinFutures.get_mark_price(symbol)` remains available for mark prices.
|
|
43
43
|
|
|
44
|
+
## Stored CVD data
|
|
45
|
+
|
|
46
|
+
`BinbotApi` exposes the recorded KuCoin futures CVD endpoints:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
symbol_cvd = await api.get_cvd_symbol("RUMUSDTM", limit=15)
|
|
50
|
+
market_cvd = await api.get_cvd_aggregate(limit=15)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`CvdSymbolResponse`, `CvdAggregateResponse` and `CvdPoint` are public exports.
|
|
54
|
+
Symbol observations are one-minute buckets; aggregate observations are
|
|
55
|
+
15-minute buckets. Both are oldest first and retain the current/partial,
|
|
56
|
+
coverage, gap, universe or contract multiplier change, reset, and checkpoint
|
|
57
|
+
freshness fields. Missing values remain `None`, and empty collections remain
|
|
58
|
+
empty. Timestamp fields require time zones and numeric observations must be
|
|
59
|
+
finite. The endpoint responses are bare snapshots rather than
|
|
60
|
+
`StandardResponse` envelopes. Request and validation errors propagate to the
|
|
61
|
+
caller; a failed request never becomes a zero-valued reading.
|
|
62
|
+
|
|
63
|
+
Publish a new PyPI release before consuming these methods in binquant or
|
|
64
|
+
binbot, then upgrade each consumer's minimum dependency and lockfile to that
|
|
65
|
+
release.
|
|
66
|
+
|
|
44
67
|
## Telegram delivery
|
|
45
68
|
|
|
46
69
|
Import `TelegramDelivery` from `pybinbot.shared.telegram_delivery`. Initialization
|
|
@@ -120,6 +120,7 @@ from pybinbot.models.signals import (
|
|
|
120
120
|
SignalsConsumer,
|
|
121
121
|
)
|
|
122
122
|
from pybinbot.models.symbol import SymbolModel
|
|
123
|
+
from pybinbot.models.cvd import CvdAggregateResponse, CvdPoint, CvdSymbolResponse
|
|
123
124
|
from pybinbot.models.routes import (
|
|
124
125
|
GainerLoserEntry,
|
|
125
126
|
GainersLosersSeriesResponse,
|
|
@@ -212,6 +213,9 @@ __all__ = [
|
|
|
212
213
|
"GainersLosersSnapshot",
|
|
213
214
|
"MarketBreadthSeries",
|
|
214
215
|
"MarketBreadthSeriesResponse",
|
|
216
|
+
"CvdPoint",
|
|
217
|
+
"CvdAggregateResponse",
|
|
218
|
+
"CvdSymbolResponse",
|
|
215
219
|
"AutotradeSettings",
|
|
216
220
|
"AutotradeSettingsResponse",
|
|
217
221
|
"AutotradeSettingsSchema",
|
|
@@ -28,6 +28,7 @@ from pybinbot import (
|
|
|
28
28
|
)
|
|
29
29
|
from datetime import datetime, timezone
|
|
30
30
|
from dateutil.parser import parse
|
|
31
|
+
from pybinbot.models.cvd import CvdAggregateResponse, CvdSymbolResponse
|
|
31
32
|
|
|
32
33
|
logger = logging.getLogger(__name__)
|
|
33
34
|
|
|
@@ -75,6 +76,8 @@ class BinbotApi:
|
|
|
75
76
|
self.bb_top_losers = f"{bb_base_url}/charts/top-losers"
|
|
76
77
|
self.bb_timeseries_url = f"{bb_base_url}/charts/timeseries"
|
|
77
78
|
self.bb_market_breadth_url = f"{bb_base_url}/charts/market-breadth"
|
|
79
|
+
self.bb_cvd_symbol_url = f"{bb_base_url}/charts/cvd-symbol"
|
|
80
|
+
self.bb_cvd_aggregate_url = f"{bb_base_url}/charts/cvd-aggregate"
|
|
78
81
|
self.bb_gainers_losers_series_url = (
|
|
79
82
|
f"{bb_base_url}/charts/gainers-losers-series"
|
|
80
83
|
)
|
|
@@ -303,6 +306,26 @@ class BinbotApi:
|
|
|
303
306
|
return []
|
|
304
307
|
return GainersLosersSeriesResponse.model_validate(response).data
|
|
305
308
|
|
|
309
|
+
async def get_cvd_symbol(self, symbol: str, limit: int = 15) -> CvdSymbolResponse:
|
|
310
|
+
"""Read oldest-first one-minute contract CVD, including coverage flags.
|
|
311
|
+
|
|
312
|
+
The endpoint returns a bare snapshot, not a StandardResponse envelope.
|
|
313
|
+
HTTP and validation failures propagate so callers can distinguish an
|
|
314
|
+
unavailable feed from an observed zero or empty collection.
|
|
315
|
+
"""
|
|
316
|
+
response = await self.fetch(
|
|
317
|
+
url=self.bb_cvd_symbol_url,
|
|
318
|
+
params={"symbol": symbol.upper(), "limit": limit},
|
|
319
|
+
)
|
|
320
|
+
return CvdSymbolResponse.model_validate(response)
|
|
321
|
+
|
|
322
|
+
async def get_cvd_aggregate(self, limit: int = 672) -> CvdAggregateResponse:
|
|
323
|
+
"""Read oldest-first 15-minute market CVD with gaps and freshness."""
|
|
324
|
+
response = await self.fetch(
|
|
325
|
+
url=self.bb_cvd_aggregate_url, params={"limit": limit}
|
|
326
|
+
)
|
|
327
|
+
return CvdAggregateResponse.model_validate(response)
|
|
328
|
+
|
|
306
329
|
async def create_signal(
|
|
307
330
|
self,
|
|
308
331
|
algorithm_name: str,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Stored CVD observations returned directly by the binbot charts endpoints."""
|
|
2
|
+
|
|
3
|
+
from pydantic import AwareDatetime, BaseModel, FiniteFloat
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CvdPoint(BaseModel):
|
|
7
|
+
timestamp: AwareDatetime
|
|
8
|
+
buy: FiniteFloat | None
|
|
9
|
+
sell: FiniteFloat | None
|
|
10
|
+
cvd: FiniteFloat | None
|
|
11
|
+
expected_symbols: int | None
|
|
12
|
+
covered_symbols: int
|
|
13
|
+
observed_minutes: int
|
|
14
|
+
complete: bool
|
|
15
|
+
gap: bool
|
|
16
|
+
current: bool
|
|
17
|
+
universe_changed: bool
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class CvdAggregateResponse(BaseModel):
|
|
21
|
+
source: str
|
|
22
|
+
data: list[CvdPoint]
|
|
23
|
+
reset_at: AwareDatetime
|
|
24
|
+
updated_at: AwareDatetime | None
|
|
25
|
+
stale: bool
|
|
26
|
+
partial: bool
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class CvdSymbolResponse(CvdAggregateResponse):
|
|
30
|
+
symbol: str
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pybinbot
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.4
|
|
4
4
|
Summary: Utility functions for the binbot project.
|
|
5
5
|
Author-email: Carlos Wu <carkodw@gmail.com>
|
|
6
6
|
Requires-Python: >=3.15
|
|
@@ -70,6 +70,29 @@ the highest selling price or lowest buying price; fills depend on the order book
|
|
|
70
70
|
from the futures ticker. The spot client exposes the same method for spot prices;
|
|
71
71
|
`KucoinFutures.get_mark_price(symbol)` remains available for mark prices.
|
|
72
72
|
|
|
73
|
+
## Stored CVD data
|
|
74
|
+
|
|
75
|
+
`BinbotApi` exposes the recorded KuCoin futures CVD endpoints:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
symbol_cvd = await api.get_cvd_symbol("RUMUSDTM", limit=15)
|
|
79
|
+
market_cvd = await api.get_cvd_aggregate(limit=15)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`CvdSymbolResponse`, `CvdAggregateResponse` and `CvdPoint` are public exports.
|
|
83
|
+
Symbol observations are one-minute buckets; aggregate observations are
|
|
84
|
+
15-minute buckets. Both are oldest first and retain the current/partial,
|
|
85
|
+
coverage, gap, universe or contract multiplier change, reset, and checkpoint
|
|
86
|
+
freshness fields. Missing values remain `None`, and empty collections remain
|
|
87
|
+
empty. Timestamp fields require time zones and numeric observations must be
|
|
88
|
+
finite. The endpoint responses are bare snapshots rather than
|
|
89
|
+
`StandardResponse` envelopes. Request and validation errors propagate to the
|
|
90
|
+
caller; a failed request never becomes a zero-valued reading.
|
|
91
|
+
|
|
92
|
+
Publish a new PyPI release before consuming these methods in binquant or
|
|
93
|
+
binbot, then upgrade each consumer's minimum dependency and lockfile to that
|
|
94
|
+
release.
|
|
95
|
+
|
|
73
96
|
## Telegram delivery
|
|
74
97
|
|
|
75
98
|
Import `TelegramDelivery` from `pybinbot.shared.telegram_delivery`. Initialization
|
|
@@ -24,6 +24,7 @@ pybinbot/models/__init__.py
|
|
|
24
24
|
pybinbot/models/autotrade_settings.py
|
|
25
25
|
pybinbot/models/bot.py
|
|
26
26
|
pybinbot/models/bot_base.py
|
|
27
|
+
pybinbot/models/cvd.py
|
|
27
28
|
pybinbot/models/deal.py
|
|
28
29
|
pybinbot/models/derivatives.py
|
|
29
30
|
pybinbot/models/grid_ladder.py
|
|
@@ -60,6 +61,7 @@ tests/test_closed_bot_status.py
|
|
|
60
61
|
tests/test_coingecko.py
|
|
61
62
|
tests/test_conditional_entry.py
|
|
62
63
|
tests/test_conditional_futures_orders.py
|
|
64
|
+
tests/test_cvd_api.py
|
|
63
65
|
tests/test_deal_model.py
|
|
64
66
|
tests/test_derivatives_api.py
|
|
65
67
|
tests/test_futures_place_order.py
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from datetime import UTC, datetime
|
|
3
|
+
from unittest.mock import AsyncMock, patch
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
from pydantic import ValidationError
|
|
7
|
+
|
|
8
|
+
from pybinbot import BinbotApi, CvdAggregateResponse, CvdPoint, CvdSymbolResponse
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def cvd_payload() -> dict:
|
|
12
|
+
return {
|
|
13
|
+
"source": "kucoin_futures",
|
|
14
|
+
"symbol": "RUMUSDTM",
|
|
15
|
+
"data": [
|
|
16
|
+
{
|
|
17
|
+
"timestamp": "2026-11-16T18:34:00Z",
|
|
18
|
+
"buy": 245.83,
|
|
19
|
+
"sell": 205.998,
|
|
20
|
+
"cvd": 39.832,
|
|
21
|
+
"expected_symbols": 1,
|
|
22
|
+
"covered_symbols": 1,
|
|
23
|
+
"observed_minutes": 1,
|
|
24
|
+
"complete": True,
|
|
25
|
+
"gap": False,
|
|
26
|
+
"current": False,
|
|
27
|
+
"universe_changed": False,
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"reset_at": "2026-11-16T18:34:00Z",
|
|
31
|
+
"updated_at": "2026-11-16T18:35:00Z",
|
|
32
|
+
"stale": False,
|
|
33
|
+
"partial": False,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@pytest.fixture
|
|
38
|
+
def api() -> BinbotApi:
|
|
39
|
+
with patch.object(BinbotApi, "_login_service_account"):
|
|
40
|
+
return BinbotApi("https://example.com", "service@example.com", "password")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_symbol_cvd_reads_bare_snapshot_and_normalizes_contract_id(api, monkeypatch):
|
|
44
|
+
fetch = AsyncMock(return_value=cvd_payload())
|
|
45
|
+
monkeypatch.setattr(api, "fetch", fetch)
|
|
46
|
+
|
|
47
|
+
result = asyncio.run(api.get_cvd_symbol("rumusdtm", limit=15))
|
|
48
|
+
|
|
49
|
+
fetch.assert_awaited_once_with(
|
|
50
|
+
url="https://example.com/charts/cvd-symbol",
|
|
51
|
+
params={"symbol": "RUMUSDTM", "limit": 15},
|
|
52
|
+
)
|
|
53
|
+
assert isinstance(result, CvdSymbolResponse)
|
|
54
|
+
assert isinstance(result.data[0], CvdPoint)
|
|
55
|
+
assert result.data[0].cvd == 39.832
|
|
56
|
+
assert result.updated_at == datetime(2026, 11, 16, 18, 35, tzinfo=UTC)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_aggregate_cvd_preserves_coverage_and_partial_observations(api, monkeypatch):
|
|
60
|
+
payload = cvd_payload()
|
|
61
|
+
del payload["symbol"]
|
|
62
|
+
payload["partial"] = True
|
|
63
|
+
payload["data"][0].update(
|
|
64
|
+
buy=None,
|
|
65
|
+
sell=None,
|
|
66
|
+
cvd=None,
|
|
67
|
+
complete=False,
|
|
68
|
+
gap=True,
|
|
69
|
+
expected_symbols=None,
|
|
70
|
+
covered_symbols=0,
|
|
71
|
+
observed_minutes=0,
|
|
72
|
+
)
|
|
73
|
+
fetch = AsyncMock(return_value=payload)
|
|
74
|
+
monkeypatch.setattr(api, "fetch", fetch)
|
|
75
|
+
|
|
76
|
+
result = asyncio.run(api.get_cvd_aggregate(limit=15))
|
|
77
|
+
|
|
78
|
+
fetch.assert_awaited_once_with(
|
|
79
|
+
url="https://example.com/charts/cvd-aggregate", params={"limit": 15}
|
|
80
|
+
)
|
|
81
|
+
assert isinstance(result, CvdAggregateResponse)
|
|
82
|
+
assert result.partial is True
|
|
83
|
+
assert result.data[0].cvd is None
|
|
84
|
+
assert result.data[0].gap is True
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@pytest.mark.parametrize("aggregate", [False, True])
|
|
88
|
+
def test_cvd_empty_data_is_a_valid_snapshot(api, monkeypatch, aggregate):
|
|
89
|
+
payload = {**cvd_payload(), "data": [], "updated_at": None, "stale": True}
|
|
90
|
+
fetch = AsyncMock(return_value=payload)
|
|
91
|
+
monkeypatch.setattr(api, "fetch", fetch)
|
|
92
|
+
request = api.get_cvd_aggregate() if aggregate else api.get_cvd_symbol("RUMUSDTM")
|
|
93
|
+
|
|
94
|
+
result = asyncio.run(request)
|
|
95
|
+
|
|
96
|
+
assert result.data == []
|
|
97
|
+
assert result.updated_at is None
|
|
98
|
+
assert result.stale is True
|
|
99
|
+
assert fetch.await_args.kwargs["params"]["limit"] == (672 if aggregate else 15)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@pytest.mark.parametrize("aggregate", [False, True])
|
|
103
|
+
def test_cvd_transport_errors_propagate_without_inventing_zero_data(
|
|
104
|
+
api, monkeypatch, aggregate
|
|
105
|
+
):
|
|
106
|
+
monkeypatch.setattr(api, "fetch", AsyncMock(side_effect=TimeoutError))
|
|
107
|
+
request = api.get_cvd_aggregate() if aggregate else api.get_cvd_symbol("RUMUSDTM")
|
|
108
|
+
with pytest.raises(TimeoutError):
|
|
109
|
+
asyncio.run(request)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@pytest.mark.parametrize("aggregate", [False, True])
|
|
113
|
+
def test_cvd_invalid_responses_raise_validation_errors(api, monkeypatch, aggregate):
|
|
114
|
+
monkeypatch.setattr(api, "fetch", AsyncMock(return_value={"data": []}))
|
|
115
|
+
request = api.get_cvd_aggregate() if aggregate else api.get_cvd_symbol("RUMUSDTM")
|
|
116
|
+
with pytest.raises(ValidationError):
|
|
117
|
+
asyncio.run(request)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
@pytest.mark.parametrize("invalid", [float("nan"), float("inf"), -float("inf")])
|
|
121
|
+
def test_cvd_rejects_nonfinite_observations(invalid):
|
|
122
|
+
payload = cvd_payload()
|
|
123
|
+
payload["data"][0]["cvd"] = invalid
|
|
124
|
+
with pytest.raises(ValidationError):
|
|
125
|
+
CvdSymbolResponse.model_validate(payload)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def test_cvd_rejects_timezone_ambiguous_observation_timestamps():
|
|
129
|
+
payload = cvd_payload()
|
|
130
|
+
payload["data"][0]["timestamp"] = "2026-11-16T18:34:00"
|
|
131
|
+
with pytest.raises(ValidationError):
|
|
132
|
+
CvdSymbolResponse.model_validate(payload)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|