Skip to content

Models

Every endpoint returns Pydantic models rather than raw dictionaries, so fields are validated, timestamps arrive as datetime, and your editor can complete them. All of them are importable from the package root:

from pylightningfx import Board, ChildOrder, Ticker

Fields such as product_code, side and child_order_state are typed str rather than as enums on purpose — bitFlyer adds products and state values without warning, and a closed enum would reject a valid response. See Enums for the known values.

Public API

public

Response models for the Public API.

String fields such as product_code, state and side are typed str rather than as enums so that a product or state bitFlyer adds after this release still parses. See pylightningfx.enums for the known values.

Market

Bases: BaseModel

A tradable market.

product_code instance-attribute
product_code: str
market_type instance-attribute
market_type: str

One of MarketType.

BoardEntry

Bases: BaseModel

A single price level in the order book.

price instance-attribute
price: float
size instance-attribute
size: float

Board

Bases: BaseModel

A snapshot of the order book.

The order of bids and asks is not guaranteed, so sort before treating the first element as the best price::

best_bid = max(board.bids, key=lambda e: e.price)
mid_price instance-attribute
mid_price: float
bids instance-attribute
bids: list[BoardEntry]
asks instance-attribute
asks: list[BoardEntry]

Ticker

Bases: BaseModel

Best bid and ask, last traded price, and rolling volume.

product_code instance-attribute
product_code: str
state instance-attribute
state: str

One of MarketState.

timestamp instance-attribute
timestamp: datetime
tick_id instance-attribute
tick_id: int
best_bid instance-attribute
best_bid: float
best_ask instance-attribute
best_ask: float
best_bid_size instance-attribute
best_bid_size: float
best_ask_size instance-attribute
best_ask_size: float
total_bid_depth instance-attribute
total_bid_depth: float
total_ask_depth instance-attribute
total_ask_depth: float
market_bid_size instance-attribute
market_bid_size: float
market_ask_size instance-attribute
market_ask_size: float
ltp instance-attribute
ltp: float

Last traded price.

volume instance-attribute
volume: float

24-hour volume across every market of the underlying asset.

volume_by_product instance-attribute
volume_by_product: float

24-hour volume for this product_code alone.

preopen_end class-attribute instance-attribute
preopen_end: datetime | None = None

When the pre-open auction ends. Undocumented by bitFlyer; usually None.

circuit_break_end class-attribute instance-attribute
circuit_break_end: datetime | None = None

When the circuit breaker lifts. Undocumented by bitFlyer; usually None.

Execution

Bases: BaseModel

A public trade.

id instance-attribute
id: int
side instance-attribute
side: str

Taker side; one of Side.

Empty for trades matched by the opening auction, which have no taker.

price instance-attribute
price: float
size instance-attribute
size: float
exec_date instance-attribute
exec_date: datetime
buy_child_order_acceptance_id instance-attribute
buy_child_order_acceptance_id: str
sell_child_order_acceptance_id instance-attribute
sell_child_order_acceptance_id: str

BoardState

Bases: BaseModel

Order book availability, which is finer-grained than Health.

health instance-attribute
health: str

One of HealthStatus.

state instance-attribute
state: str

One of MarketState.

Health

Bases: BaseModel

Exchange health for one market.

status instance-attribute
status: str

One of HealthStatus.

FundingRate

Bases: BaseModel

The current funding rate for a perpetual market.

current_funding_rate instance-attribute
current_funding_rate: float
next_funding_rate_settledate instance-attribute
next_funding_rate_settledate: datetime

FundingRateHistory

Bases: BaseModel

One settled funding rate.

calculation_date instance-attribute
calculation_date: datetime
settlement_date instance-attribute
settlement_date: datetime
rate instance-attribute
rate: float

CorporateLeverage

Bases: BaseModel

Maximum leverage for corporate accounts, current and upcoming.

current_max instance-attribute
current_max: float
current_startdate instance-attribute
current_startdate: datetime
next_max class-attribute instance-attribute
next_max: float | None = None
next_startdate class-attribute instance-attribute
next_startdate: datetime | None = None

Chat

Bases: BaseModel

A message from the exchange chat room.

nickname instance-attribute
nickname: str
message instance-attribute
message: str
date instance-attribute
date: datetime

Private API

private

Request and response models for the Private API.

String fields such as product_code, side and child_order_state are typed str rather than as enums so that a value bitFlyer adds after this release still parses. See pylightningfx.enums for the known values.

Balance

Bases: BaseModel

Balance of one currency.

available excludes amounts reserved by open orders, so it is the figure to size new orders against.

currency_code instance-attribute
currency_code: str
amount instance-attribute
amount: float
available instance-attribute
available: float

Collateral

Bases: BaseModel

Margin status for the account as a whole.

collateral instance-attribute
collateral: float
open_position_pnl instance-attribute
open_position_pnl: float
require_collateral instance-attribute
require_collateral: float
keep_rate instance-attribute
keep_rate: float

Maintenance margin ratio. A margin call follows once this falls far enough.

margin_call_amount class-attribute instance-attribute
margin_call_amount: float | None = None
margin_call_due_date class-attribute instance-attribute
margin_call_due_date: datetime | None = None

CollateralAccount

Bases: BaseModel

Collateral held in one currency.

currency_code instance-attribute
currency_code: str
amount instance-attribute
amount: float

Address

Bases: BaseModel

A deposit address for one crypto asset.

type instance-attribute
type: str
currency_code instance-attribute
currency_code: str
address instance-attribute
address: str

CoinIn

Bases: BaseModel

An incoming crypto transfer.

id instance-attribute
id: int
order_id instance-attribute
order_id: str
currency_code instance-attribute
currency_code: str
amount instance-attribute
amount: float
address instance-attribute
address: str
tx_hash instance-attribute
tx_hash: str
status instance-attribute
status: str
event_date instance-attribute
event_date: datetime

CoinOut

Bases: BaseModel

An outgoing crypto transfer.

id instance-attribute
id: int
order_id instance-attribute
order_id: str
currency_code instance-attribute
currency_code: str
amount instance-attribute
amount: float
address instance-attribute
address: str
tx_hash instance-attribute
tx_hash: str
fee instance-attribute
fee: float
additional_fee instance-attribute
additional_fee: float
status instance-attribute
status: str
event_date instance-attribute
event_date: datetime

BankAccount

Bases: BaseModel

A registered bank account, usable as a withdrawal destination.

id instance-attribute
id: int

Pass as bank_account_id to withdraw.

is_verified instance-attribute
is_verified: bool
bank_name instance-attribute
bank_name: str
branch_name instance-attribute
branch_name: str
account_type instance-attribute
account_type: str
account_number instance-attribute
account_number: str
account_name instance-attribute
account_name: str

Deposit

Bases: BaseModel

A cash deposit.

id instance-attribute
id: int
order_id instance-attribute
order_id: str
currency_code instance-attribute
currency_code: str
amount instance-attribute
amount: float
status instance-attribute
status: str
event_date instance-attribute
event_date: datetime

Withdrawal

Bases: BaseModel

A cash withdrawal.

id instance-attribute
id: int
order_id instance-attribute
order_id: str
currency_code instance-attribute
currency_code: str
amount instance-attribute
amount: float
status instance-attribute
status: str
event_date instance-attribute
event_date: datetime

WithdrawResponse

Bases: BaseModel

Acknowledgement of a withdrawal request.

message_id instance-attribute
message_id: str

Pass as message_id to get_withdrawals to follow up on this request.

ChildOrderResponse

Bases: BaseModel

Acknowledgement of an order submission.

The exchange has accepted the order, not necessarily filled or even placed it. Poll get_child_orders with the acceptance id, or subscribe to child_order_events on the Realtime API, to learn what happened.

child_order_acceptance_id instance-attribute
child_order_acceptance_id: str

ParentOrderResponse

Bases: BaseModel

Acknowledgement of a parent order submission.

parent_order_acceptance_id instance-attribute
parent_order_acceptance_id: str

ChildOrder

Bases: BaseModel

One of your orders.

id instance-attribute
id: int
child_order_id instance-attribute
child_order_id: str
product_code instance-attribute
product_code: str
side instance-attribute
side: str
child_order_type instance-attribute
child_order_type: str
price instance-attribute
price: float
average_price instance-attribute
average_price: float
size instance-attribute
size: float
child_order_state instance-attribute
child_order_state: str

One of ChildOrderState.

expire_date instance-attribute
expire_date: datetime
child_order_date instance-attribute
child_order_date: datetime
child_order_acceptance_id instance-attribute
child_order_acceptance_id: str
outstanding_size instance-attribute
outstanding_size: float
cancel_size instance-attribute
cancel_size: float
executed_size instance-attribute
executed_size: float
total_commission instance-attribute
total_commission: float
time_in_force instance-attribute
time_in_force: str

ParentOrder

Bases: BaseModel

One of your parent (conditional) orders, as listed.

id instance-attribute
id: int
parent_order_id instance-attribute
parent_order_id: str
product_code instance-attribute
product_code: str
side instance-attribute
side: str
parent_order_type instance-attribute
parent_order_type: str
price instance-attribute
price: float
average_price instance-attribute
average_price: float
size instance-attribute
size: float
parent_order_state instance-attribute
parent_order_state: str
expire_date instance-attribute
expire_date: datetime
parent_order_date instance-attribute
parent_order_date: datetime
parent_order_acceptance_id instance-attribute
parent_order_acceptance_id: str
outstanding_size instance-attribute
outstanding_size: float
cancel_size instance-attribute
cancel_size: float
executed_size instance-attribute
executed_size: float
total_commission instance-attribute
total_commission: float

ParentOrderParameter

Bases: BaseModel

One leg of a parent order.

Serves as both the input to send_parent_order and an element of parameters. Fields that only apply to certain condition types default to None and are left out of the request body::

client.send_parent_order(
    [
        ParentOrderParameter(
            product_code=ProductCode.FX_BTC_JPY,
            condition_type=ConditionType.STOP,
            side=Side.SELL,
            size=0.01,
            trigger_price=9_000_000,
        )
    ]
)
product_code instance-attribute
product_code: str
condition_type instance-attribute
condition_type: str

One of ConditionType.

side instance-attribute
side: str
size instance-attribute
size: float
price class-attribute instance-attribute
price: float | None = None

Required for LIMIT and STOP_LIMIT.

trigger_price class-attribute instance-attribute
trigger_price: float | None = None

Required for STOP and STOP_LIMIT.

offset class-attribute instance-attribute
offset: float | None = None

Required for TRAIL; the trailing distance in the quote currency.

ParentOrderDetail

Bases: BaseModel

A parent order together with its legs.

id instance-attribute
id: int
parent_order_id instance-attribute
parent_order_id: str
order_method instance-attribute
order_method: str

One of OrderMethod.

expire_date instance-attribute
expire_date: datetime
time_in_force instance-attribute
time_in_force: str
parameters instance-attribute
parameters: list[ParentOrderParameter]
parent_order_acceptance_id instance-attribute
parent_order_acceptance_id: str

MyExecution

Bases: BaseModel

One of your fills.

id instance-attribute
id: int
child_order_id instance-attribute
child_order_id: str
side instance-attribute
side: str
price instance-attribute
price: float
size instance-attribute
size: float
commission instance-attribute
commission: float
exec_date instance-attribute
exec_date: datetime
child_order_acceptance_id instance-attribute
child_order_acceptance_id: str

BalanceHistory

Bases: BaseModel

One entry from the balance ledger.

id instance-attribute
id: int
trade_date instance-attribute
trade_date: datetime
event_date instance-attribute
event_date: datetime
product_code instance-attribute
product_code: str
currency_code instance-attribute
currency_code: str
trade_type instance-attribute
trade_type: str
price instance-attribute
price: float
amount instance-attribute
amount: float
quantity instance-attribute
quantity: float
commission instance-attribute
commission: float
balance instance-attribute
balance: float

Running balance after this entry.

order_id instance-attribute
order_id: str

Position

Bases: BaseModel

An open leveraged position.

bitFlyer reports positions individually rather than netted, so a single market can hold several entries on the same side.

product_code instance-attribute
product_code: str
side instance-attribute
side: str
price instance-attribute
price: float
size instance-attribute
size: float
commission instance-attribute
commission: float
swap_point_accumulate instance-attribute
swap_point_accumulate: float
require_collateral instance-attribute
require_collateral: float
open_date instance-attribute
open_date: datetime
leverage instance-attribute
leverage: float
pnl instance-attribute
pnl: float
sfd instance-attribute
sfd: float

Swap For Difference charge, applied when FX_BTC_JPY diverges from BTC_JPY.

funding_fees instance-attribute
funding_fees: float

CollateralHistory

Bases: BaseModel

One change to the collateral balance.

id instance-attribute
id: int
currency_code instance-attribute
currency_code: str
change instance-attribute
change: float
amount instance-attribute
amount: float
reason_code instance-attribute
reason_code: str
date instance-attribute
date: datetime

TradingCommission

Bases: BaseModel

The commission rate applied to your trades on one market.

commission_rate instance-attribute
commission_rate: float

Fraction of notional, so 0.0015 means 0.15%.

Realtime API

The public streaming channels reuse the models above. Only the private order event channels have models of their own.

realtime

Models for the private Realtime API channels.

The public channels reuse the Public API models: lightning_board* delivers a Board, lightning_ticker_* a Ticker, and lightning_executions_* a list of Execution.

Most fields below are optional because bitFlyer sends a different subset per event_type; each one documents when it is present.

ChildOrderEvent

Bases: BaseModel

One lifecycle event for one of your orders.

Delivered on the child_order_events channel. Watch event_type to decide which optional fields to read; see ChildOrderEventType.

product_code instance-attribute
product_code: str
child_order_id instance-attribute
child_order_id: str
child_order_acceptance_id instance-attribute
child_order_acceptance_id: str
event_date instance-attribute
event_date: datetime
event_type instance-attribute
event_type: str

ORDER, ORDER_FAILED, CANCEL, CANCEL_FAILED, EXECUTION or EXPIRE.

child_order_type class-attribute instance-attribute
child_order_type: str | None = None

ORDER only.

expire_date class-attribute instance-attribute
expire_date: datetime | None = None

ORDER and EXECUTION.

reason class-attribute instance-attribute
reason: str | None = None

ORDER_FAILED only: why the exchange rejected the order.

exec_id class-attribute instance-attribute
exec_id: int | None = None

EXECUTION only.

side class-attribute instance-attribute
side: str | None = None

ORDER and EXECUTION.

price class-attribute instance-attribute
price: float | None = None

ORDER, EXECUTION, CANCEL and EXPIRE.

size class-attribute instance-attribute
size: float | None = None

ORDER, EXECUTION, CANCEL and EXPIRE.

commission class-attribute instance-attribute
commission: float | None = None

EXECUTION only.

sfd class-attribute instance-attribute
sfd: float | None = None

EXECUTION only: the Swap For Difference charge.

outstanding_size class-attribute instance-attribute
outstanding_size: float | None = None

EXECUTION only: how much of the order is still unfilled.

ParentOrderEvent

Bases: BaseModel

One lifecycle event for one of your parent orders.

Delivered on the parent_order_events channel. See ParentOrderEventType for the event_type values, which differ from the child order set: parent orders report TRIGGER and COMPLETE instead of CANCEL_FAILED and EXECUTION.

product_code instance-attribute
product_code: str
parent_order_id instance-attribute
parent_order_id: str
parent_order_acceptance_id instance-attribute
parent_order_acceptance_id: str
event_date instance-attribute
event_date: datetime
event_type instance-attribute
event_type: str

ORDER, ORDER_FAILED, CANCEL, TRIGGER, COMPLETE or EXPIRE.

parent_order_type class-attribute instance-attribute
parent_order_type: str | None = None

ORDER only, e.g. STOP or IFD.

reason class-attribute instance-attribute
reason: str | None = None

ORDER_FAILED only.

child_order_type class-attribute instance-attribute
child_order_type: str | None = None

TRIGGER only: the order type of the child that fired.

parameter_index class-attribute instance-attribute
parameter_index: int | None = None

TRIGGER and COMPLETE: which leg, 1-based.

child_order_acceptance_id class-attribute instance-attribute
child_order_acceptance_id: str | None = None

TRIGGER and COMPLETE: links to the resulting child order.

side class-attribute instance-attribute
side: str | None = None

TRIGGER only.

price class-attribute instance-attribute
price: float | None = None

TRIGGER only.

size class-attribute instance-attribute
size: float | None = None

TRIGGER only.

expire_date class-attribute instance-attribute
expire_date: datetime | None = None

ORDER and TRIGGER.