設定¶
クライアントのコンストラクタに retry と rate_limits を渡すと、リクエストのリトライ方法と
送信ペースを調整できます。RateLimitState は bitFlyer 側のカウンタをクライアントが
rate_limit プロパティで報告するためのものです。
RetryPolicy
dataclass
¶
RetryPolicy(
attempts: int = 3,
backoff: float = 0.5,
max_backoff: float = 30.0,
retry_statuses: frozenset[int] = (
lambda: frozenset({500, 502, 503, 504})
)(),
retry_unsafe_methods: bool = False,
)
When and how far apart to retry a failed request.
Retries are deliberately conservative about writes. A 5xx or a dropped
connection on POST /v1/me/sendchildorder is ambiguous — the order may
already be live on the exchange — so retrying it risks a double fill. By
default only safe methods are retried on those failures.
HTTP 429 is always retried regardless of method: a rate-limited request was rejected before it reached the matching engine, so replaying it cannot duplicate an order.
Attributes:
| Name | Type | Description |
|---|---|---|
attempts |
int
|
Total attempts per request, including the first one. |
backoff |
float
|
Base delay in seconds. Doubles each attempt. |
max_backoff |
float
|
Ceiling for a single delay, in seconds. |
retry_statuses |
frozenset[int]
|
HTTP status codes worth retrying, on top of 429. |
retry_unsafe_methods |
bool
|
Retry |
should_retry
¶
Whether a failure is worth another attempt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
HTTP method of the failed request. |
required |
status_code
|
int | None
|
Status code received, or |
required |
delay
¶
Seconds to sleep before attempt, which is 1-based.
Honours a server-supplied retry_after when present, otherwise uses
exponential backoff with full jitter on the lower half of the interval
so that concurrent clients do not retry in lockstep.
RateLimits
dataclass
¶
Client-side request budget, mirroring bitFlyer's published limits.
The client tracks its own request timestamps and sleeps before sending when a window is full, so bursts get spread out instead of coming back as 429s. This is a courtesy backstop, not a guarantee: bitFlyer counts per IP and per account, so other processes sharing either will not be visible here.
One limit is not modelled here: bitFlyer separately caps orders of size 0.1 or less at 100 per minute, aggregated across every market, and drops you to 10 per minute for an hour if you exceed it. Sizing that budget needs to know each order's size, so pace small orders yourself.
Attributes:
| Name | Type | Description |
|---|---|---|
general |
int | None
|
Requests allowed per |
order |
int | None
|
Requests allowed per |
period |
float
|
Length of the window in seconds. |
RateLimitState
dataclass
¶
RateLimitState(
remaining: int | None = None,
period: int | None = None,
reset: int | None = None,
)
bitFlyer's own view of your rate limit, read from the response headers.
Attributes:
| Name | Type | Description |
|---|---|---|
remaining |
int | None
|
Requests left in the current window. |
period |
int | None
|
Seconds left in the current window. |
reset |
int | None
|
Unix timestamp at which the window resets. |
from_response
classmethod
¶
Parse the X-RateLimit-* headers, or None if absent.