pybinbot 2.1.12__tar.gz → 2.1.14__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.
Files changed (89) hide show
  1. {pybinbot-2.1.12/pybinbot.egg-info → pybinbot-2.1.14}/PKG-INFO +4 -1
  2. {pybinbot-2.1.12 → pybinbot-2.1.14}/README.md +3 -0
  3. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/models/bot_base.py +9 -3
  4. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/strategy/swing_protection.py +16 -4
  5. {pybinbot-2.1.12 → pybinbot-2.1.14/pybinbot.egg-info}/PKG-INFO +4 -1
  6. {pybinbot-2.1.12 → pybinbot-2.1.14}/pyproject.toml +1 -1
  7. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_conditional_entry.py +4 -2
  8. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_swing_protection.py +65 -0
  9. {pybinbot-2.1.12 → pybinbot-2.1.14}/LICENSE +0 -0
  10. {pybinbot-2.1.12 → pybinbot-2.1.14}/MANIFEST.in +0 -0
  11. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/__init__.py +0 -0
  12. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/apis/binance/base.py +0 -0
  13. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/apis/binance/exceptions.py +0 -0
  14. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/apis/binbot/base.py +0 -0
  15. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/apis/binbot/exceptions.py +0 -0
  16. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/apis/coingecko.py +0 -0
  17. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/apis/kucoin/base.py +0 -0
  18. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/apis/kucoin/exceptions.py +0 -0
  19. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/apis/kucoin/futures.py +0 -0
  20. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/apis/kucoin/market.py +0 -0
  21. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/apis/kucoin/orders.py +0 -0
  22. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/apis/kucoin/rest.py +0 -0
  23. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/models/__init__.py +0 -0
  24. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/models/autotrade_settings.py +0 -0
  25. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/models/bot.py +0 -0
  26. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/models/cvd.py +0 -0
  27. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/models/deal.py +0 -0
  28. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/models/derivatives.py +0 -0
  29. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/models/fastest_movers.py +0 -0
  30. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/models/grid_ladder.py +0 -0
  31. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/models/order.py +0 -0
  32. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/models/routes.py +0 -0
  33. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/models/signals.py +0 -0
  34. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/models/symbol.py +0 -0
  35. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/py.typed +0 -0
  36. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/shared/__init__.py +0 -0
  37. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/shared/beta.py +0 -0
  38. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/shared/breadth.py +0 -0
  39. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/shared/cache.py +0 -0
  40. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/shared/candles.py +0 -0
  41. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/shared/enums.py +0 -0
  42. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/shared/handlers.py +0 -0
  43. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/shared/heikin_ashi.py +0 -0
  44. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/shared/indicators.py +0 -0
  45. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/shared/logging_config.py +0 -0
  46. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/shared/maths.py +0 -0
  47. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/shared/price_crossings.py +0 -0
  48. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/shared/telegram_delivery.py +0 -0
  49. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/shared/timestamps.py +0 -0
  50. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/shared/types.py +0 -0
  51. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/shared/utils.py +0 -0
  52. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/strategy/beta.py +0 -0
  53. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/strategy/breadth.py +0 -0
  54. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/strategy/price_crossings.py +0 -0
  55. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/streaming/binance/async_socket_client.py +0 -0
  56. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/streaming/binance/socket_client.py +0 -0
  57. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/streaming/binance/socket_manager.py +0 -0
  58. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot/streaming/kucoin/kucoin_async_client.py +0 -0
  59. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot.egg-info/SOURCES.txt +0 -0
  60. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot.egg-info/dependency_links.txt +0 -0
  61. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot.egg-info/requires.txt +0 -0
  62. {pybinbot-2.1.12 → pybinbot-2.1.14}/pybinbot.egg-info/top_level.txt +0 -0
  63. {pybinbot-2.1.12 → pybinbot-2.1.14}/setup.cfg +0 -0
  64. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_beta.py +0 -0
  65. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_binbot_api.py +0 -0
  66. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_bot_futures_leverage.py +0 -0
  67. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_breadth.py +0 -0
  68. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_candles.py +0 -0
  69. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_closed_bot_status.py +0 -0
  70. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_coingecko.py +0 -0
  71. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_conditional_futures_orders.py +0 -0
  72. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_cvd_api.py +0 -0
  73. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_deal_model.py +0 -0
  74. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_derivatives_api.py +0 -0
  75. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_fastest_movers.py +0 -0
  76. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_futures_place_order.py +0 -0
  77. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_grid_ladder.py +0 -0
  78. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_handlers.py +0 -0
  79. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_heikin_ashi.py +0 -0
  80. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_indicators.py +0 -0
  81. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_kucoin_api.py +0 -0
  82. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_logging_config.py +0 -0
  83. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_matching_engine.py +0 -0
  84. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_maths.py +0 -0
  85. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_price_crossings.py +0 -0
  86. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_symbol_model.py +0 -0
  87. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_telegram_delivery.py +0 -0
  88. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_timestamps.py +0 -0
  89. {pybinbot-2.1.12 → pybinbot-2.1.14}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pybinbot
3
- Version: 2.1.12
3
+ Version: 2.1.14
4
4
  Summary: Utility functions for the binbot project.
5
5
  Author-email: Carlos Wu <carkodw@gmail.com>
6
6
  Requires-Python: >=3.15
@@ -168,6 +168,9 @@ in `pybinbot.shared`. New reusable strategy calculations belong in
168
168
  confirmed, unbroken swing on completed 15m, 5m or 1m candles. Callers descend in
169
169
  that order when a candidate is unsuitable. The maximum search window is three
170
170
  hours, optionally narrowed to one hour or to the start of the current setup.
171
+ The reference price must remain on the protected side of the unbuffered swing.
172
+ A forming candle cannot confirm a swing, but a wick touching or crossing the
173
+ swing invalidates it even when the current price subsequently recovers.
171
174
  The selector rejects swing candles wider than 3% and stop distances over 2.5%
172
175
  after the buffer and outward tick rounding. It never clips a distant swing or
173
176
  searches older swings to force a result. Entry callers skip when all timeframes
@@ -139,6 +139,9 @@ in `pybinbot.shared`. New reusable strategy calculations belong in
139
139
  confirmed, unbroken swing on completed 15m, 5m or 1m candles. Callers descend in
140
140
  that order when a candidate is unsuitable. The maximum search window is three
141
141
  hours, optionally narrowed to one hour or to the start of the current setup.
142
+ The reference price must remain on the protected side of the unbuffered swing.
143
+ A forming candle cannot confirm a swing, but a wick touching or crossing the
144
+ swing invalidates it even when the current price subsequently recovers.
142
145
  The selector rejects swing candles wider than 3% and stop distances over 2.5%
143
146
  after the buffer and outward tick rounding. It never clips a distant swing or
144
147
  searches older swings to force a result. Entry callers skip when all timeframes
@@ -15,6 +15,8 @@ from pybinbot.shared.enums import (
15
15
  from pybinbot.shared.timestamps import timestamp, ts_to_humandate
16
16
  from pybinbot.shared.types import Amount
17
17
 
18
+ DEFAULT_ENTRY_EXPIRY_MS = 15 * 60 * 1000
19
+
18
20
 
19
21
  class RecoveryParams(BaseModel):
20
22
  reversal_path: Literal["source", "recovery"] = "source"
@@ -50,10 +52,10 @@ class BotBase(BaseModel):
50
52
  entry_mode: EntryMode = Field(default=EntryMode.immediate, validate_default=True)
51
53
  entry_price: float | None = Field(default=None, ge=0, allow_inf_nan=False)
52
54
  entry_expires_at: float = Field(
53
- default_factory=lambda data: data["created_at"] + 6 * 60 * 60 * 1000,
55
+ default_factory=lambda data: data["created_at"] + DEFAULT_ENTRY_EXPIRY_MS,
54
56
  gt=0,
55
57
  allow_inf_nan=False,
56
- description="Absolute entry deadline in Unix milliseconds; defaults to creation + 6 hours",
58
+ description="Absolute entry deadline in Unix milliseconds; defaults to creation + 15 minutes",
57
59
  )
58
60
  dynamic_trailing: bool = Field(default=False)
59
61
  dynamic_position_sizing: bool = Field(default=False)
@@ -121,7 +123,11 @@ class BotBase(BaseModel):
121
123
  @field_validator("entry_expires_at", mode="before")
122
124
  @classmethod
123
125
  def default_entry_expiry(cls, value, info: ValidationInfo):
124
- return info.data["created_at"] + 6 * 60 * 60 * 1000 if value is None else value
126
+ return (
127
+ info.data["created_at"] + DEFAULT_ENTRY_EXPIRY_MS
128
+ if value is None
129
+ else value
130
+ )
125
131
 
126
132
  @model_validator(mode="after")
127
133
  def validate_conditional_entry(self):
@@ -171,10 +171,22 @@ def recent_swing_protection(
171
171
  return None
172
172
  timestamp, _opening, high, low, _close = rows[swing_index]
173
173
  swing_price = high if short else low
174
- if any(
175
- row[value_column] >= swing_price if short else row[value_column] <= swing_price
176
- for row in rows[swing_index + 1 :]
177
- ):
174
+ if reference_price >= swing_price if short else reference_price <= swing_price:
175
+ return None
176
+ # A forming candle cannot confirm a swing, but its wick can break one.
177
+ # Check the raw input as well as the reference so a recovered price or a
178
+ # wide buffer cannot conceal that the confirmed structure was reclaimed.
179
+ try:
180
+ for candle in candles:
181
+ candle_time = float(candle[0])
182
+ if not timestamp < candle_time <= now_ms:
183
+ continue
184
+ extreme = float(candle[value_column])
185
+ if not isfinite(extreme) or extreme <= 0:
186
+ return None
187
+ if extreme >= swing_price if short else extreme <= swing_price:
188
+ return None
189
+ except IndexError, TypeError, ValueError, OverflowError:
178
190
  return None
179
191
  candle_range = (Decimal(str(high)) / Decimal(str(low)) - 1) * 100
180
192
  if max_candle_range_pct is not None and candle_range > Decimal(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pybinbot
3
- Version: 2.1.12
3
+ Version: 2.1.14
4
4
  Summary: Utility functions for the binbot project.
5
5
  Author-email: Carlos Wu <carkodw@gmail.com>
6
6
  Requires-Python: >=3.15
@@ -168,6 +168,9 @@ in `pybinbot.shared`. New reusable strategy calculations belong in
168
168
  confirmed, unbroken swing on completed 15m, 5m or 1m candles. Callers descend in
169
169
  that order when a candidate is unsuitable. The maximum search window is three
170
170
  hours, optionally narrowed to one hour or to the start of the current setup.
171
+ The reference price must remain on the protected side of the unbuffered swing.
172
+ A forming candle cannot confirm a swing, but a wick touching or crossing the
173
+ swing invalidates it even when the current price subsequently recovers.
171
174
  The selector rejects swing candles wider than 3% and stop distances over 2.5%
172
175
  after the buffer and outward tick rounding. It never clips a distant swing or
173
176
  searches older swings to force a result. Entry callers skip when all timeframes
@@ -23,7 +23,7 @@ build-backend = "setuptools.build_meta"
23
23
 
24
24
  [project]
25
25
  name = "pybinbot"
26
- version = "2.1.12"
26
+ version = "2.1.14"
27
27
  description = "Utility functions for the binbot project."
28
28
  authors = [
29
29
  { name="Carlos Wu", email="carkodw@gmail.com" }
@@ -8,10 +8,12 @@ from pybinbot import BotBase, EntryMode, MarketType
8
8
  "overrides",
9
9
  [{}, {"entry_mode": None, "entry_expires_at": None, "entry_price": None}],
10
10
  )
11
- def test_omitted_or_null_entry_fields_default_to_immediate_and_six_hours(overrides):
11
+ def test_omitted_or_null_entry_fields_default_to_immediate_and_fifteen_minutes(
12
+ overrides,
13
+ ):
12
14
  bot = BotBase(pair="XBTUSDTM", created_at=1000, **overrides)
13
15
  assert bot.entry_mode == EntryMode.immediate
14
- assert bot.entry_expires_at == 21_601_000
16
+ assert bot.entry_expires_at == 901_000
15
17
  assert bot.entry_price is None
16
18
  assert bot.model_dump(mode="json")["entry_price"] is None
17
19
 
@@ -154,6 +154,71 @@ def test_latest_unconfirmed_break_invalidates_the_old_peak():
154
154
  assert resolve(rows) is None
155
155
 
156
156
 
157
+ @pytest.mark.parametrize("position", [Position.short, Position.long])
158
+ @pytest.mark.parametrize("reference", [102.0, 102.5])
159
+ def test_buffer_cannot_make_a_reclaimed_swing_valid(position, reference):
160
+ rows = candles()
161
+ if position == Position.long:
162
+ rows = [
163
+ [t, 200 - o, 200 - low, 200 - high, 200 - c, v, end]
164
+ for t, o, high, low, c, v, end in rows
165
+ ]
166
+ reference = 200 - reference
167
+ assert (
168
+ recent_swing_protection(
169
+ rows,
170
+ position=position,
171
+ reference_price=reference,
172
+ now_ms=NOW_MS,
173
+ interval_minutes=15,
174
+ price_precision=4,
175
+ buffer_pct=2.0,
176
+ )
177
+ is None
178
+ )
179
+
180
+
181
+ @pytest.mark.parametrize("position", [Position.short, Position.long])
182
+ @pytest.mark.parametrize(
183
+ "forming_high,valid", [(101.9, True), (102.0, False), (102.1, False)]
184
+ )
185
+ def test_forming_wick_can_break_a_swing_even_after_price_recovers(
186
+ position, forming_high, valid
187
+ ):
188
+ rows = candles()
189
+ rows.append([NOW_MS, 100, forming_high, 99.8, 100, 10, NOW_MS + 900_000 - 1])
190
+ if position == Position.long:
191
+ rows = [
192
+ [t, 200 - o, 200 - low, 200 - high, 200 - c, v, end]
193
+ for t, o, high, low, c, v, end in rows
194
+ ]
195
+ assert (resolve(rows, position=position) is not None) is valid
196
+
197
+
198
+ @pytest.mark.parametrize("position", [Position.short, Position.long])
199
+ def test_refinement_cannot_use_a_reclaimed_finer_swing(position):
200
+ history = {15: candles(15, high=106.35), 5: candles(5), 1: candles(1)}
201
+ reference = 102.5
202
+ if position == Position.long:
203
+ history = {
204
+ interval: [
205
+ [t, 200 - o, 200 - low, 200 - high, 200 - c, v, end]
206
+ for t, o, high, low, c, v, end in rows
207
+ ]
208
+ for interval, rows in history.items()
209
+ }
210
+ reference = 200 - reference
211
+ decision = refine_swing_protection(
212
+ history,
213
+ position=position,
214
+ reference_price=reference,
215
+ now_ms=NOW_MS,
216
+ price_precision=4,
217
+ buffer_pct=2.0,
218
+ )
219
+ assert decision.protection is None
220
+
221
+
157
222
  def test_latest_wide_swing_does_not_fall_back_to_an_arbitrary_older_peak():
158
223
  rows = candles(high=106.35)
159
224
  rows[3][2] = 101
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes