Skip to content

Instantly share code, notes, and snippets.

@MtkN1
Last active January 22, 2024 15:45
Show Gist options
  • Save MtkN1/2d6d47adbbfae7e84fa75a04f1d3a964 to your computer and use it in GitHub Desktop.
Save MtkN1/2d6d47adbbfae7e84fa75a04f1d3a964 to your computer and use it in GitHub Desktop.
Binance Spot Pydantic Models from datamodel-code-generator
# generated by datamodel-codegen:
# filename: https://github.com/binance/binance-api-swagger/raw/master/spot_api.yaml
# timestamp: 2024-01-22T15:18:47+00:00
from __future__ import annotations
from typing import List, Optional
from pydantic import BaseModel, Field, RootModel
class CommissionRates(BaseModel):
maker: str = Field(..., examples=['0.00150000'])
taker: str = Field(..., examples=['0.00150000'])
buyer: str = Field(..., examples=['0.00000000'])
seller: str = Field(..., examples=['0.00000000'])
class Balance(BaseModel):
asset: str = Field(..., examples=['BTC'])
free: str = Field(..., examples=['4723846.89208129'])
locked: str = Field(..., examples=['0.00000000'])
class Account(BaseModel):
makerCommission: int = Field(..., examples=[15])
takerCommission: int = Field(..., examples=[15])
buyerCommission: int = Field(..., examples=[0])
sellerCommission: int = Field(..., examples=[0])
commissionRates: CommissionRates
canTrade: bool
canWithdraw: bool
canDeposit: bool
brokered: bool = Field(..., examples=[False])
requireSelfTradePrevention: bool = Field(..., examples=[False])
preventSor: bool = Field(..., examples=[False])
updateTime: int = Field(..., examples=[123456789])
accountType: str = Field(..., examples=['SPOT'])
balances: List[Balance]
permissions: List[str]
uid: int = Field(..., examples=[354937868])
class Order(BaseModel):
symbol: str = Field(..., examples=['BNBBTC'])
origClientOrderId: str = Field(..., examples=['msXkySR3u5uYwpvRMFsi3u'])
orderId: int = Field(..., examples=[28])
orderListId: int = Field(
..., description='Unless OCO, value will be -1', examples=[-1]
)
clientOrderId: str = Field(..., examples=['6gCrw2kRUAF9CvJDGP16IP'])
transactTime: int = Field(..., examples=[1507725176595])
price: str = Field(..., examples=['1.00000000'])
origQty: str = Field(..., examples=['10.00000000'])
executedQty: str = Field(..., examples=['10.00000000'])
cummulativeQuoteQty: str = Field(..., examples=['10.00000000'])
status: str = Field(..., examples=['FILLED'])
timeInForce: str = Field(..., examples=['GTC'])
type: str = Field(..., examples=['LIMIT'])
side: str = Field(..., examples=['SELL'])
selfTradePreventionMode: str = Field(..., examples=['NONE'])
class Order1(BaseModel):
symbol: str
orderId: int
clientOrderId: str
class OrderReport(BaseModel):
symbol: str
origClientOrderId: str
orderId: int
orderListId: int
clientOrderId: str
price: str
origQty: str
executedQty: str
cummulativeQuoteQty: str
status: str
timeInForce: str
type: str
side: str
stopPrice: str
selfTradePreventionMode: str
transactTime: int
class OcoOrder(BaseModel):
orderListId: int = Field(..., examples=[1929])
contingencyType: str = Field(..., examples=['OCO'])
listStatusType: str = Field(..., examples=['ALL_DONE'])
listOrderStatus: str = Field(..., examples=['ALL_DONE'])
listClientOrderId: str = Field(..., examples=['C3wyj4WVEktd7u9aVBRXcN'])
transactionTime: int = Field(..., examples=[1574040868128])
symbol: str = Field(..., examples=['BNBBTC'])
orders: List[Order1] = Field(
...,
examples=[
[
{
'symbol': 'BNBBTC',
'orderId': 2,
'clientOrderId': 'pO9ufTiFGg3nw2fOdgeOXa',
},
{
'symbol': 'BNBBTC',
'orderId': 3,
'clientOrderId': 'TXOvglzXuaubXAaENpaRCB',
},
]
],
)
orderReports: List[OrderReport] = Field(
...,
examples=[
[
{
'symbol': 'BNBBTC',
'origClientOrderId': 'pO9ufTiFGg3nw2fOdgeOXa',
'orderId': 2,
'orderListId': 0,
'clientOrderId': 'unfWT8ig8i0uj6lPuYLez6',
'price': '1.00000000',
'origQty': '10.00000000',
'executedQty': '0.00000000',
'cummulativeQuoteQty': '0.00000000',
'status': 'CANCELED',
'timeInForce': 'GTC',
'type': 'STOP_LOSS_LIMIT',
'side': 'SELL',
'stopPrice': '1.00000000',
'transactTime': 1688005070874,
},
{
'symbol': 'BNBBTC',
'origClientOrderId': 'TXOvglzXuaubXAaENpaRCB',
'orderId': 3,
'orderListId': 0,
'clientOrderId': 'unfWT8ig8i0uj6lPuYLez6',
'price': '3.00000000',
'origQty': '10.00000000',
'executedQty': '0.00000000',
'cummulativeQuoteQty': '0.00000000',
'status': 'CANCELED',
'timeInForce': 'GTC',
'type': 'LIMIT_MAKER',
'side': 'SELL',
'selfTradePreventionMode': 'NONE',
'transactTime': 1688005070874,
},
]
],
)
class OrderReport1(BaseModel):
symbol: str
origClientOrderId: str
orderId: int
orderListId: int
clientOrderId: str
price: str
origQty: str
executedQty: str
cummulativeQuoteQty: str
status: str
timeInForce: str
type: str
side: str
stopPrice: str
class MarginOcoOrder(BaseModel):
orderListId: int = Field(..., examples=[0])
contingencyType: str = Field(..., examples=['OCO'])
listStatusType: str = Field(..., examples=['ALL_DONE'])
listOrderStatus: str = Field(..., examples=['ALL_DONE'])
listClientOrderId: str = Field(..., examples=['C3wyj4WVEktd7u9aVBRXcN'])
transactionTime: int = Field(..., examples=[1574040868128])
symbol: str = Field(..., examples=['BNBUSDT'])
isIsolated: bool = Field(..., examples=[False])
orders: List[Order1]
orderReports: List[OrderReport1]
class OrderDetails(BaseModel):
symbol: str = Field(..., examples=['LTCBTC'])
orderId: int = Field(..., examples=[1])
orderListId: int = Field(
..., description='Unless OCO, value will be -1', examples=[-1]
)
clientOrderId: str = Field(..., examples=['myOrder1'])
price: str = Field(..., examples=['0.1'])
origQty: str = Field(..., examples=['1.0'])
executedQty: str = Field(..., examples=['0.0'])
cummulativeQuoteQty: str = Field(..., examples=['0.0'])
status: str = Field(..., examples=['NEW'])
timeInForce: str = Field(..., examples=['GTC'])
type: str = Field(..., examples=['LIMIT'])
side: str = Field(..., examples=['BUY'])
stopPrice: str = Field(..., examples=['0.0'])
icebergQty: str = Field(..., examples=['0.0'])
time: int = Field(..., examples=[1499827319559])
updateTime: int = Field(..., examples=[1499827319559])
isWorking: bool
workingTime: int = Field(..., examples=[1499827319559])
origQuoteOrderQty: str = Field(..., examples=['0.00000000'])
selfTradePreventionMode: str = Field(..., examples=['NONE'])
preventedMatchId: Optional[int] = Field(None, examples=[0])
preventedQuantity: Optional[str] = Field(None, examples=['1.200000'])
class OrderResponseAck(BaseModel):
symbol: str = Field(..., examples=['BTCUSDT'])
orderId: int = Field(..., examples=[28])
orderListId: int = Field(..., examples=[-1])
clientOrderId: str = Field(..., examples=['6gCrw2kRUAF9CvJDGP16IP'])
transactTime: int = Field(..., examples=[1507725176595])
class OrderResponseResult(BaseModel):
symbol: str = Field(..., examples=['BTCUSDT'])
orderId: int = Field(..., examples=[28])
orderListId: int = Field(..., examples=[-1])
clientOrderId: str = Field(..., examples=['6gCrw2kRUAF9CvJDGP16IP'])
transactTime: int = Field(..., examples=[1507725176595])
price: str = Field(..., examples=['0.00000000'])
origQty: str = Field(..., examples=['10.00000000'])
executedQty: str = Field(..., examples=['10.00000000'])
cummulativeQuoteQty: str = Field(..., examples=['10.00000000'])
status: str = Field(..., examples=['FILLED'])
timeInForce: str = Field(..., examples=['GTC'])
type: str = Field(..., examples=['MARKET'])
side: str = Field(..., examples=['SELL'])
strategyId: Optional[int] = Field(None, examples=[1])
strategyType: Optional[int] = Field(None, examples=[1000000])
workingTime: int = Field(..., examples=[1507725176595])
selfTradePreventionMode: str = Field(..., examples=['NONE'])
class Fill(BaseModel):
price: str = Field(..., examples=['4000.00000000'])
qty: str = Field(..., examples=['1.00000000'])
commission: str = Field(..., examples=['4.00000000'])
commissionAsset: str = Field(..., examples=['USDT'])
class OrderResponseFull(BaseModel):
symbol: str = Field(..., examples=['BTCUSDT'])
orderId: int = Field(..., examples=[28])
orderListId: int = Field(..., examples=[-1])
clientOrderId: str = Field(..., examples=['6gCrw2kRUAF9CvJDGP16IP'])
transactTime: int = Field(..., examples=[1507725176595])
price: str = Field(..., examples=['0.00000000'])
origQty: str = Field(..., examples=['10.00000000'])
executedQty: str = Field(..., examples=['10.00000000'])
cummulativeQuoteQty: str = Field(..., examples=['10.00000000'])
status: str = Field(..., examples=['FILLED'])
timeInForce: str = Field(..., examples=['GTC'])
type: str = Field(..., examples=['MARKET'])
side: str = Field(..., examples=['SELL'])
strategyId: Optional[int] = Field(None, examples=[1])
strategyType: Optional[int] = Field(None, examples=[1000000])
workingTime: int = Field(..., examples=[1507725176595])
selfTradePreventionMode: str = Field(..., examples=['NONE'])
fills: List[Fill]
class MarginOrder(BaseModel):
symbol: str = Field(..., examples=['LTCBTC'])
orderId: int = Field(..., examples=[28])
origClientOrderId: str = Field(..., examples=['msXkySR3u5uYwpvRMFsi3u'])
clientOrderId: str = Field(..., examples=['6gCrw2kRUAF9CvJDGP16IP'])
price: str = Field(..., examples=['1.00000000'])
origQty: str = Field(..., examples=['10.00000000'])
executedQty: str = Field(..., examples=['8.00000000'])
cummulativeQuoteQty: str = Field(..., examples=['8.00000000'])
status: str = Field(..., examples=['CANCELED'])
timeInForce: str = Field(..., examples=['GTC'])
type: str = Field(..., examples=['LIMIT'])
side: str = Field(..., examples=['SELL'])
class MarginOrderDetail(BaseModel):
clientOrderId: str = Field(..., examples=['ZwfQzuDIGpceVhKW5DvCmO'])
cummulativeQuoteQty: str = Field(..., examples=['0.00000000'])
executedQty: str = Field(..., examples=['0.00000000'])
icebergQty: str = Field(..., examples=['0.00000000'])
isWorking: bool
orderId: int = Field(..., examples=[213205622])
origQty: str = Field(..., examples=['0.30000000'])
price: str = Field(..., examples=['0.00493630'])
side: str = Field(..., examples=['SELL'])
status: str = Field(..., examples=['NEW'])
stopPrice: str = Field(..., examples=['0.00000000'])
symbol: str = Field(..., examples=['BNBBTC'])
isIsolated: bool
time: int = Field(..., examples=[1562133008725])
timeInForce: str = Field(..., examples=['GTC'])
type: str = Field(..., examples=['LIMIT'])
updateTime: int = Field(..., examples=[1562133008725])
selfTradePreventionMode: str = Field(..., examples=['NONE'])
class CanceledMarginOrderDetail(BaseModel):
symbol: str = Field(..., examples=['BNBUSDT'])
isIsolated: bool
origClientOrderId: str = Field(..., examples=['E6APeyTJvkMvLMYMqu1KQ4'])
orderId: int = Field(..., examples=[11])
orderListId: int = Field(..., examples=[-1])
clientOrderId: str = Field(..., examples=['pXLV6Hz6mprAcVYpVMTGgx'])
price: str = Field(..., examples=['0.089853'])
origQty: str = Field(..., examples=['0.178622'])
executedQty: str = Field(..., examples=['0.000000'])
cummulativeQuoteQty: str = Field(..., examples=['0.000000'])
status: str = Field(..., examples=['CANCELED'])
timeInForce: str = Field(..., examples=['GTC'])
type: str = Field(..., examples=['LIMIT'])
side: str = Field(..., examples=['BUY'])
class MarginOrderResponseAck(BaseModel):
symbol: str = Field(..., examples=['BTCUSDT'])
orderId: int = Field(..., examples=[28])
clientOrderId: str = Field(..., examples=['6gCrw2kRUAF9CvJDGP16IP'])
isIsolated: bool
transactTime: int = Field(..., examples=[1507725176595])
class MarginOrderResponseResult(BaseModel):
symbol: str = Field(..., examples=['BTCUSDT'])
orderId: int = Field(..., examples=[28])
clientOrderId: str = Field(..., examples=['6gCrw2kRUAF9CvJDGP16IP'])
transactTime: int = Field(..., examples=[1507725176595])
price: str = Field(..., examples=['1.00000000'])
origQty: str = Field(..., examples=['10.00000000'])
executedQty: str = Field(..., examples=['10.00000000'])
cummulativeQuoteQty: str = Field(..., examples=['10.00000000'])
status: str = Field(..., examples=['FILLED'])
timeInForce: str = Field(..., examples=['GTC'])
type: str = Field(..., examples=['MARKET'])
isIsolated: bool
side: str = Field(..., examples=['SELL'])
class MarginOrderResponseFull(BaseModel):
symbol: str = Field(..., examples=['BTCUSDT'])
orderId: int = Field(..., examples=[28])
clientOrderId: str = Field(..., examples=['6gCrw2kRUAF9CvJDGP16IP'])
transactTime: int = Field(..., examples=[1507725176595])
price: str = Field(..., examples=['1.00000000'])
origQty: str = Field(..., examples=['10.00000000'])
executedQty: str = Field(..., examples=['10.00000000'])
cummulativeQuoteQty: str = Field(..., examples=['10.00000000'])
status: str = Field(..., examples=['FILLED'])
timeInForce: str = Field(..., examples=['GTC'])
type: str = Field(..., examples=['MARKET'])
side: str = Field(..., examples=['SELL'])
marginBuyBorrowAmount: float = Field(
..., description='will not return if no margin trade happens', examples=[5]
)
marginBuyBorrowAsset: str = Field(
..., description='will not return if no margin trade happens', examples=['BTC']
)
isIsolated: bool
fills: List[Fill]
class MarginTrade(BaseModel):
commission: str = Field(..., examples=['0.00006000'])
commissionAsset: str = Field(..., examples=['BTC'])
id: int = Field(..., examples=[28])
isBestMatch: bool
isBuyer: bool
isMaker: bool
orderId: int = Field(..., examples=[28])
price: str = Field(..., examples=['0.02000000'])
qty: str = Field(..., examples=['1.02000000'])
symbol: str = Field(..., examples=['BNBBTC'])
isIsolated: bool = Field(..., examples=[False])
time: int = Field(..., examples=[1507725176595])
class Row(BaseModel):
amount: str = Field(..., examples=['0.10000000'])
asset: str = Field(..., examples=['BNB'])
status: str = Field(..., examples=['CONFIRMED'])
timestamp: int = Field(..., examples=[1566898617000])
txId: int = Field(..., examples=[5240372201])
type: Optional[str] = Field(None, examples=['ROLL_IN'])
transFrom: str = Field(..., examples=['SPOT'])
transTo: str = Field(..., examples=['ISOLATED_MARGIN'])
class MarginTransferDetails(BaseModel):
rows: List[Row]
total: int = Field(..., examples=[1])
class BaseAsset(BaseModel):
asset: str = Field(..., examples=['BTC'])
borrowEnabled: bool
borrowed: str = Field(..., examples=['0.00000000'])
free: str = Field(..., examples=['0.00000000'])
interest: str = Field(..., examples=['0.00000000'])
locked: str = Field(..., examples=['0.00000000'])
netAsset: str = Field(..., examples=['0.00000000'])
netAssetOfBtc: str = Field(..., examples=['0.00000000'])
repayEnabled: bool
totalAsset: str = Field(..., examples=['0.00000000'])
class QuoteAsset(BaseModel):
asset: str = Field(..., examples=['USDT'])
borrowEnabled: bool
borrowed: str = Field(..., examples=['0.00000000'])
free: str = Field(..., examples=['0.00000000'])
interest: str = Field(..., examples=['0.00000000'])
locked: str = Field(..., examples=['0.00000000'])
netAsset: str = Field(..., examples=['0.00000000'])
netAssetOfBtc: str = Field(..., examples=['0.00000000'])
repayEnabled: bool
totalAsset: str = Field(..., examples=['0.00000000'])
class Asset(BaseModel):
baseAsset: BaseAsset
quoteAsset: QuoteAsset
symbol: str = Field(..., examples=['BTCUSDT'])
isolatedCreated: bool
enabled: bool = Field(..., description='true-enabled, false-disabled')
marginLevel: str = Field(..., examples=['0.00000000'])
marginLevelStatus: str = Field(
...,
description='"EXCESSIVE", "NORMAL", "MARGIN_CALL", "PRE_LIQUIDATION", "FORCE_LIQUIDATION"',
examples=['EXCESSIVE'],
)
marginRatio: str = Field(..., examples=['0.00000000'])
indexPrice: str = Field(..., examples=['10000.00000000'])
liquidatePrice: str = Field(..., examples=['1000.00000000'])
liquidateRate: str = Field(..., examples=['1.00000000'])
tradeEnabled: bool
class IsolatedMarginAccountInfo(BaseModel):
assets: List[Asset]
totalAssetOfBtc: str = Field(..., examples=['0.00000000'])
totalLiabilityOfBtc: str = Field(..., examples=['0.00000000'])
totalNetAssetOfBtc: str = Field(..., examples=['0.00000000'])
class BookTicker(BaseModel):
symbol: str = Field(..., examples=['BNBBTC'])
bidPrice: str = Field(..., examples=['16.36240000'])
bidQty: str = Field(..., examples=['256.78000000'])
askPrice: str = Field(..., examples=['16.36450000'])
askQty: str = Field(..., examples=['12.56000000'])
class PriceTicker(BaseModel):
symbol: str = Field(..., examples=['BNBBTC'])
price: str = Field(..., examples=['0.17160000'])
class RepaymentInfo(BaseModel):
loanCoin: str = Field(..., examples=['BUSD'])
remainingPrincipal: str = Field(..., examples=['100.5'])
remainingInterest: str = Field(..., examples=['0'])
collateralCoin: str = Field(..., examples=['BNB'])
remainingCollateral: str = Field(..., examples=['5.253'])
currentLTV: str = Field(..., examples=['0.25'])
repayStatus: str = Field(..., examples=['Repaying'])
class RepaymentInfo2(BaseModel):
loanCoin: str = Field(..., examples=['BUSD'])
collateralCoin: str = Field(..., examples=['BNB'])
repayStatus: str = Field(..., examples=['Repaying'])
class Ticker(BaseModel):
symbol: str = Field(..., examples=['BNBBTC'])
priceChange: str = Field(..., examples=['0.17160000'])
priceChangePercent: str = Field(..., examples=['1.060'])
prevClosePrice: str = Field(..., examples=['16.35920000'])
lastPrice: str = Field(..., examples=['27.84000000'])
bidPrice: str = Field(..., examples=['16.34488284'])
bidQty: str = Field(..., examples=['16.34488284'])
askPrice: str = Field(..., examples=['16.35920000'])
askQty: str = Field(..., examples=['25.06000000'])
openPrice: str = Field(..., examples=['16.18760000'])
highPrice: str = Field(..., examples=['16.55000000'])
lowPrice: str = Field(..., examples=['16.16940000'])
volume: str = Field(..., examples=['1678279.95000000'])
quoteVolume: str = Field(..., examples=['27431289.14792300'])
openTime: int = Field(..., examples=[1592808788637])
closeTime: int = Field(..., examples=[1592895188637])
firstId: int = Field(..., examples=[62683296])
lastId: int = Field(..., examples=[62739253])
count: int = Field(..., examples=[55958])
class MyTrade(BaseModel):
symbol: str = Field(..., examples=['BNBBTC'])
id: int = Field(..., description='Trade id', examples=[28457])
orderId: int = Field(..., examples=[100234])
orderListId: int = Field(..., examples=[-1])
price: str = Field(..., description='Price', examples=['4.00000100'])
qty: str = Field(..., description='Amount of base asset', examples=['12.00000000'])
quoteQty: str = Field(
..., description='Amount of quote asset', examples=['48.000012']
)
commission: str = Field(..., examples=['10.10000000'])
commissionAsset: str = Field(..., examples=['BNB'])
time: int = Field(..., description='Trade timestamp', examples=[1499865549590])
isBuyer: bool = Field(..., examples=[False])
isMaker: bool = Field(..., examples=[False])
isBestMatch: bool
class Transaction(BaseModel):
tranId: int = Field(..., description='transaction id', examples=[345196462])
class Trade(BaseModel):
id: int = Field(..., description='trade id', examples=[345196462])
price: str = Field(..., description='price', examples=['9638.99000000'])
qty: str = Field(..., description='amount of base asset', examples=['0.02077200'])
quoteQty: str = Field(
..., description='amount of quote asset', examples=['0.02077200']
)
time: int = Field(
...,
description='Trade executed timestamp, as same as `T` in the stream',
examples=[1592887772684],
)
isBuyerMaker: bool
isBestMatch: bool
class AggTrade(BaseModel):
a: int = Field(..., description='Aggregate tradeId', examples=[26129])
p: str = Field(..., description='Price', examples=['0.01633102'])
q: str = Field(..., description='Quantity', examples=['4.70443515'])
f: int = Field(..., description='First tradeId', examples=[27781])
l: int = Field(..., description='Last tradeId', examples=[27781])
T: bool = Field(..., description='Timestamp', examples=[1498793709153])
m: bool = Field(..., description='Was the buyer the maker?')
M: bool = Field(..., description='Was the trade the best price match?')
class BnbBurnStatus(BaseModel):
spotBNBBurn: bool
interestBNBBurn: bool = Field(..., examples=[False])
class Balance1(BaseModel):
asset: str = Field(..., examples=['BTC'])
free: str = Field(..., examples=['0.2'])
locked: str = Field(..., examples=['0.001'])
class Data(BaseModel):
balances: List[Balance1]
totalAssetOfBtc: str = Field(..., examples=['0.09905021'])
class SnapshotVo(BaseModel):
data: Data
type: str = Field(..., examples=['spot'])
updateTime: int = Field(..., examples=[1576281599000])
class SnapshotSpot(BaseModel):
code: int = Field(..., examples=[200])
msg: str = Field(..., examples=[''])
snapshotVos: List[SnapshotVo]
class UserAsset(BaseModel):
asset: str = Field(..., examples=['XRP'])
borrowed: str = Field(..., examples=['0.00000000'])
free: str = Field(..., examples=['1.00000000'])
interest: str = Field(..., examples=['0.00000000'])
locked: str = Field(..., examples=['0.00000000'])
netAsset: str = Field(..., examples=['1.00000000'])
class Data1(BaseModel):
marginLevel: str = Field(..., examples=['2748.02909813'])
totalAssetOfBtc: str = Field(..., examples=['0.00274803'])
totalLiabilityOfBtc: str = Field(..., examples=['0.00000100'])
totalNetAssetOfBtc: str = Field(..., examples=['0.00274750'])
userAssets: List[UserAsset]
class SnapshotVo1(BaseModel):
data: Data1
type: str = Field(..., examples=['margin'])
updateTime: int = Field(..., examples=[1576281599000])
class SnapshotMargin(BaseModel):
code: int = Field(..., examples=[200])
msg: str = Field(..., examples=[''])
snapshotVos: List[SnapshotVo1]
class Asset1(BaseModel):
asset: str = Field(..., examples=['USDT'])
marginBalance: str = Field(..., examples=['118.99782335'])
walletBalance: str = Field(..., examples=['120.23811389'])
class PositionItem(BaseModel):
entryPrice: str = Field(..., examples=['7130.41000000'])
markPrice: str = Field(..., examples=['7257.66239673'])
positionAmt: str = Field(..., examples=['0.01000000'])
symbol: str = Field(..., examples=['BTCUSDT'])
unRealizedProfit: str = Field(..., examples=['1.24029054'])
class Data2(BaseModel):
assets: List[Asset1]
position: List[PositionItem]
class SnapshotVo2(BaseModel):
data: Data2
type: str = Field(..., examples=['futures'])
updateTime: int = Field(..., examples=[1576281599000])
class SnapshotFutures(BaseModel):
code: int = Field(..., examples=[200])
msg: str = Field(..., examples=[''])
snapshotVos: List[SnapshotVo2]
class Asset2(BaseModel):
asset: str = Field(..., examples=['USDT'])
initialMargin: str = Field(..., examples=['0.00000000'])
maintenanceMargin: str = Field(..., examples=['0.00000000'])
marginBalance: str = Field(..., examples=['0.88308000'])
maxWithdrawAmount: str = Field(..., examples=['0.88308000'])
openOrderInitialMargin: str = Field(..., examples=['0.00000000'])
positionInitialMargin: str = Field(..., examples=['0.00000000'])
unrealizedProfit: str = Field(..., examples=['0.00000000'])
walletBalance: str = Field(..., examples=['0.88308000'])
class FutureAccountResp(BaseModel):
email: str = Field(..., examples=['[email protected]'])
assets: List[Asset2]
canDeposit: bool
canTrade: bool
canWithdraw: bool
feeTier: int = Field(..., examples=[2])
maxWithdrawAmount: str = Field(..., examples=['0.88308000'])
totalInitialMargin: str = Field(..., examples=['0.00000000'])
totalMaintenanceMargin: str = Field(..., examples=['0.00000000'])
totalMarginBalance: str = Field(..., examples=['0.88308000'])
totalOpenOrderInitialMargin: str = Field(..., examples=['0.00000000'])
totalPositionInitialMargin: str = Field(..., examples=['0.00000000'])
totalUnrealizedProfit: str = Field(..., examples=['0.00000000'])
totalWalletBalance: str = Field(..., examples=['0.88308000'])
updateTime: int = Field(..., examples=[1576756674610])
class SubAccountUSDTFuturesDetails(BaseModel):
futureAccountResp: FutureAccountResp
class Asset3(BaseModel):
asset: str = Field(..., examples=['BTC'])
initialMargin: str = Field(..., examples=['0.00000000'])
maintenanceMargin: str = Field(..., examples=['0.00000000'])
marginBalance: str = Field(..., examples=['0.88308000'])
maxWithdrawAmount: str = Field(..., examples=['0.88308000'])
openOrderInitialMargin: str = Field(..., examples=['0.00000000'])
positionInitialMargin: str = Field(..., examples=['0.00000000'])
unrealizedProfit: str = Field(..., examples=['0.00000000'])
walletBalance: str = Field(..., examples=['0.88308000'])
class SubAccountCOINFuturesDetails(BaseModel):
email: str = Field(..., examples=['[email protected]'])
assets: List[Asset3]
canDeposit: bool
canTrade: bool
canWithdraw: bool
feeTier: int = Field(..., examples=[2])
updateTime: int = Field(..., examples=[1598959682001])
class SubAccountListItem(BaseModel):
email: str = Field(..., examples=['[email protected]'])
totalInitialMargin: str = Field(..., examples=['9.00000000'])
totalMaintenanceMargin: str = Field(..., examples=['0.00000000'])
totalMarginBalance: str = Field(..., examples=['22.12659734'])
totalOpenOrderInitialMargin: str = Field(..., examples=['9.00000000'])
totalPositionInitialMargin: str = Field(..., examples=['0.00000000'])
totalUnrealizedProfit: str = Field(..., examples=['0.00000000'])
totalWalletBalance: str = Field(..., examples=['22.12659734'])
asset: str = Field(..., description='The sum of BUSD and USDT', examples=['USD'])
class FutureAccountSummaryResp(BaseModel):
totalInitialMargin: str = Field(..., examples=['9.83137400'])
totalMaintenanceMargin: str = Field(..., examples=['0.41568700'])
totalMarginBalance: str = Field(..., examples=['23.03235621'])
totalOpenOrderInitialMargin: str = Field(..., examples=['9.00000000'])
totalPositionInitialMargin: str = Field(..., examples=['0.83137400'])
totalUnrealizedProfit: str = Field(..., examples=['0.03219710'])
totalWalletBalance: str = Field(..., examples=['22.15879444'])
asset: str = Field(..., description='The sum of BUSD and USDT', examples=['USD'])
subAccountList: List[SubAccountListItem]
class SubAccountUSDTFuturesSummary(BaseModel):
futureAccountSummaryResp: FutureAccountSummaryResp
class SubAccountListItem1(BaseModel):
email: str = Field(..., examples=['[email protected]'])
totalMarginBalance: str = Field(..., examples=[22.12659734])
totalUnrealizedProfit: str = Field(..., examples=[0.0])
totalWalletBalance: str = Field(..., examples=[22.12659734])
asset: str = Field(..., examples=['BTC'])
class DeliveryAccountSummaryResp(BaseModel):
totalMarginBalanceOfBTC: str = Field(..., examples=[25.03221121])
totalUnrealizedProfitOfBTC: str = Field(..., examples=[0.1223341])
totalWalletBalanceOfBTC: str = Field(..., examples=[22.15879444])
asset: str = Field(..., examples=['BTC'])
subAccountList: List[SubAccountListItem1]
class SubAccountCOINFuturesSummary(BaseModel):
deliveryAccountSummaryResp: DeliveryAccountSummaryResp
class FuturePositionRiskVo(BaseModel):
entryPrice: str = Field(..., examples=['9975.12000'])
leverage: str = Field(..., description='current initial leverage', examples=['50'])
maxNotional: str = Field(
...,
description='notional value limit of current initial leverage',
examples=['1000000'],
)
liquidationPrice: str = Field(..., examples=['7963.54'])
markPrice: str = Field(..., examples=['9973.50770517'])
positionAmount: str = Field(..., examples=['0.010'])
symbol: str = Field(..., examples=['BTCUSDT'])
unrealizedProfit: str = Field(..., examples=['-0.01612295'])
class SubAccountUSDTFuturesPositionRisk(BaseModel):
futurePositionRiskVos: List[FuturePositionRiskVo]
class DeliveryPositionRiskVo(BaseModel):
entryPrice: str = Field(..., examples=['9975.12000'])
markPrice: str = Field(..., examples=['9973.50770517'])
leverage: str = Field(..., examples=['20'])
isolated: str = Field(..., examples=[False])
isolatedWallet: str = Field(..., examples=['9973.50770517'])
isolatedMargin: str = Field(..., examples=['0.00000000'])
isAutoAddMargin: str = Field(..., examples=['false'])
positionSide: str = Field(..., examples=['BOTH'])
positionAmount: str = Field(..., examples=['1.230'])
symbol: str = Field(..., examples=['BTCUSD_201225'])
unrealizedProfit: str = Field(..., examples=['-0.01612295'])
class SubAccountCOINFuturesPositionRisk(BaseModel):
deliveryPositionRiskVos: List[DeliveryPositionRiskVo]
class BswapAddLiquidityPreviewCombination(BaseModel):
quoteAsset: str = Field(..., examples=['USDT'])
baseAsset: str = Field(..., examples=['BUSD'])
quoteAmt: int = Field(..., examples=[300000])
baseAmt: int = Field(..., examples=[299975])
price: float = Field(..., examples=[1.00008334])
share: float = Field(..., examples=[1.23])
class BswapAddLiquidityPreviewSingle(BaseModel):
quoteAsset: str = Field(..., examples=['USDT'])
quoteAmt: int = Field(..., examples=[300000])
price: float = Field(..., examples=[1.00008334])
share: float = Field(..., examples=[1.23])
slippage: float = Field(..., examples=[7.245e-05])
fee: float = Field(..., examples=[120])
class BswapRmvLiquidityPreviewCombination(BaseModel):
quoteAsset: str = Field(..., examples=['USDT'])
baseAsset: str = Field(..., examples=['BUSD'])
quoteAmt: int = Field(..., examples=[300000])
baseAmt: int = Field(..., examples=[299975])
price: float = Field(..., examples=[1.00008334])
class BswapRmvLiquidityPreviewSingle(BaseModel):
quoteAsset: str = Field(..., examples=['USDT'])
quoteAmt: int = Field(..., examples=[300000])
price: float = Field(..., examples=[1.00008334])
slippage: float = Field(..., examples=[7.245e-05])
fee: float = Field(..., examples=[120])
class Error(BaseModel):
code: int = Field(..., description='Error code')
msg: str = Field(..., description='Error message', examples=['error message'])
class BookTickerList(RootModel[List[BookTicker]]):
root: List[BookTicker]
class PriceTickerList(RootModel[List[PriceTicker]]):
root: List[PriceTicker]
class TickerList(RootModel[List[Ticker]]):
root: List[Ticker]
@MtkN1
Copy link
Author

MtkN1 commented Jan 22, 2024

Generated by datamodel-code-generator (https://koxudaxi.github.io/datamodel-code-generator/)

Installation:

pip install datamodel-code-generator[http]

CLI:

datamodel-codegen \
  --url https://github.com/binance/binance-api-swagger/raw/master/spot_api.yaml \
  --input-file-type openapi \
  --output model.py \
  --output-model-type pydantic_v2.BaseModel

Usage:

import httpx

import model

client = httpx.Client(base_url="https://api.binance.com")
r = client.get("/api/v3/ticker/24hr", params={"symbol": "BTCUSDT"})

ticker = model.Ticker.model_validate_json(r.text)
print(ticker)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment