
    !:h`
                    8   d dl mZ d dlmZ d dlZd dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl3m5Z5 d dl3m6Z6 d d	l3m7Z7 d d
l3m8Z8 d dl3m9Z9 d dl3m:Z: d dl3m;Z; d dl3m<Z< d dl3m=Z= d dl3m>Z> d dl3m?Z? d dl3m@Z@ d dl3mAZA d dl3mBZB d dl3mCZC d dl3mDZD d dl3mEZE d dl3mFZF d dl3mGZG d dl3mHZH d dl3mIZI d dl3mJZJ d dlKmLZL d dlKmMZM d dlNmOZO  G d  d!ee      ZPy)"    )Exchange)ImplicitAPIN)*AnyBalancesBorrowInterest
ConversionCrossBorrowRate
CurrenciesCurrencyDepositAddressGreeksIntIsolatedBorrowRateIsolatedBorrowRatesLedgerEntryLeverage	LeveragesLeverageTierLeverageTiersLongShortRatio
MarginModeMarginModesMarginModificationMarketNumOptionOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTradingFeeInterfaceTradingFeesTransactionMarketInterfaceTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)OperationRejected)MarginModeAlreadySet)MarketClosed)InsufficientFunds)InvalidOrder)OrderNotFound)OrderImmediatelyFillable)OrderNotFillable)NotSupported)OperationFailed)DDoSProtection)RateLimitExceeded)OnMaintenance)InvalidNonce)RequestTimeout)BadResponse)TRUNCATE)	TICK_SIZE)Precisec                       e Zd Zdef fdZddededefdZddededefdZ	def fd	Z
d
efdZd
edefdZddededededef
 fdZd ZddZd Zi fdefdZi fdefdZi fdee   fdZdedefdZd ZddefdZi fdefdZdi fd
ededefdZ ddedede!fd Z"i fd!Z#i fd
ede!fd"Z$di fd#e%fd$Z&di fd#e%fd%Z'ddefd&Z(di fd#e%de)fd'Z*i fd
ede!fd(Z+di fd#e%de)fd)Z,ddede-fd*Z.d+ddi fd
ed,ededee-   fd-Z/dd.edede0fd/Z1ddi fd
ed,ededee0   fd0Z2di fd1ed
ede3d2e4d3e5d4e6fd5Z7di fd1ed
ede3d2e4d3e5d4e6fd6Z8di fd1ed
ede3d2e4d3e5d4e6fd7Z9di fd1ed
ede3d2e4d3e5d4e6fd8Z:ddi fd1ed
ede3d2e4d3e6d4e6fd9Z;i fd:ee<   fd;Z=d<efd=Z>dd>edede?fd?Z@i fd:ee<   fd@ZAdi fd
ede3d2e4d3e5d4e6f
dAZBdi fd
ede3d2e4d3e5d4e6f
dBZCi fd
ed2e4dCe5fdDZDi fd
edCe5fdEZEi fd
edCe5fdFZFdi fd1ed
efdGZGdddi fd
ed,ededee?   fdHZHdddi fd
ed,ededee?   fdIZIdi fd1ed
efdJZJdddi fd
ed,ededee?   fdKZKdddi fd
ed,edefdLZLdddi fd
ed,ededee?   fdMZMdi fd1ed
efdNZNdi fd
efdOZOdi fdPee   d
efdQZPdddi fd1ed
ed,edefdRZQdddi fd
ed,edefdSZRdddi fd
ed,edefdTZSddefdUZTdddi fdVed,ededeeU   fdWZVdddi fdVed,ededeeU   fdXZWddYZXddZed[eYdeUfd\ZZd<edefd]Z[dd^ed[eYde\fd_Z]ddefd`Z^i fdVed3e5daedbede\f
dcZ_dddi fdVed,ededee\   fddZ`i fdVedeafdeZbdd[eYdeafdfZcdi fdge%fdhZddi fdge%fdiZedd[eYfdjZfdi fdVed3e5dkedeUfdlZgddmededehfdnZii fd
edehfdoZji fdekfdpZli fdVefdqZmi fd
edenfdrZodddi fd
ed,edefdsZpddefdtZqdi fd#e%derfduZsddedenfdvZtddwZuddefdxZvddefdyZwdi fdzZxdi fd#e%deyfd{Zzddedee{   fd|Z|i fd
efd}Z}di fd#e%fd~Z~ddedefdZdi fd#e%dee   fdZdi fd#e%fdZdi fd#e%fdZdddi fd
ed,edefdZdi fded
efdZdi fded
efdZdi fded
efdZdi fd#e%defdZddededefdZdddi fd
ed,edefdZdddi fd
ed,edefdZd Zd Zdi fd1edVedefdZdddi fdVed,ededee   fdZdded[eYdefdZd ZddededefdZdedefdZddi ddfdZdedefdZdVedededededefdZi fdZddi ddi fdZi fd
efdZddededefdZi fd
ed3e5defdZi fd
ed3e5defdZi fdVedefdZi fd
edefdZi fdefdZddi fdVed,edefdZdd[eYfdZddededefdZi fdVefdZi fdZi fd1efdZddddi fdVed
ed,ededee   f
dZddededefdZi fdVefdZi fd
edVefdZi fdVed3e5fdZi fd
edVed3e5fdZdd[eYfdZdddi fd
ed,edefdZi fd
efdZddefdZdddi fd
ed,edefdZddefdZi fd
edefdÄZddededefdńZdi fd#e%fdƄZdi fd
efdǄZdi fd#e%defdȄZi fd
edefdɄZddedefdʄZi fd
edefd˄Zdded[eYdedefd̈́Zddddi fd
eded,e6de6dee   f
d΄Zi fdefdτZdi fdeded3e6defd҄Zdi fd1ededed3e6def
dӄZdi fd1edVedefdԄZdddi fdVed,ededee   fdՄZddedeYdeYdefdلZdi fd#e%derfdڄZddddi fd
eded,ededee   f
d܄Zddededefd݄Zӈ xZS )binancereturnc                 h   | j                  t        t        |          i dddddg dddd	d
d	di dd dd	dd	dd	dd	dd	dd	dd	dd	dd	dd	dd	dddddd	dddd	i dd	dd	d d	d!d	d"d	d#d	d$d	d%d	d&dd'd	d(d	d)d	d*d	d+dd,d	d-d	d.d	i d/d	d0d	d1d	d2d d3d	d4d	d5d	d6dd7d	d8d9d:d9d;dd<d9d=d	d>d	d?d	d@d	i dAd	dBddCd	dDddEd	dFddGddHd	dIddJd9dKd	dLd	dMd9dNd	dOd	dPd	dQd	i dRd	dSd	dTd9dUd	dVddWd	dXd	dYd	dZd9d[d	d\d	d]dd^dd_d	d`d	dad	dbd	i dcd9ddd	ded	dfd	dgd	dhd	did	djd	dkd	dld	dmd	dnd	dod	dpd	dqddrd	dsd	i dtddud	dvd	dwd	dxddyd	dzd	d{dd|d	d}d	d~d	dd	dd	dd	dd	dd	dd	i dd	dd9dd9dd	dddddd	dddddddddd	dddd	dd	dd	dd	d	dd	d	dd	d	ddi dddddddddddddddddddddddddddddddddddddddddddddddi ddddddddddddddddddddÓddœddǓddɓddœddǓddɓddΓdddddҜdddd֜dgdddڜdi di ddݓddݓddՓddddՓddddddՓddՓddddddddՓddՓddՓddՓddi ddddddddddddddddՓddՓddՓddddd dddddddddi ddՓddd	dd
dddՓddՓddddddddՐddddddddՓddݓddՓddddddi ddddddddd d!d"dՓd#d$d%d$d&d'd(d'd)d*d+d$d,d$d-d$d.d$d/d$d0d$i d1d2d3d4d5d$d6d$d7d$d8d$d9d$d:d2d;d<d=dՓd>dd?dՓd@dAdBddCddDddEdՓi dFdՓdGdՓdHdݓdIddJddKddLddMddNddOddPdՓdQdՓdRdՓdSdՓdTddUdՓdVdi dWdՓdXdՓdYddZdd[dՓd\dd]dՓd^dՓd_dՓd`ddadbdcddddՓdeddfdՓdgdbdhdbi didՓdjdbdkdldmdbdndՓdodՓdpdՓdqdՓdrdՓdsdՓdtdՓdudՓdvdՓdwdՓdxdydzdyd{dyi d|dyd}dyd~dyddyddyddyddyddyddyddyddyddyddՓddՓddddddi ddddddddՓddddddddddddddddddddddՓddՓddՓddՓi ddddddddddddddddddddddddddddddddddi ddddddddddddddddՓddՓddddddddddddՓddՓddՓi ddՓddՓddՓddՓddՓddՓddՓdʐddːd̓d͐dddՓdϐdГdѐdddݓddݓdԐdddՓi ddՓddՓddՓddՓddՓddՓddՓddՓddՓddՓddՓddՓddՓddՓddՓddyddyi ddyddyddyddyddyddyddyddyddyddyddyddyddyddyddՓddՓddՓddii ddddՓddddՓddddՓd dՓdddJdddՓddddddddddddddi dddddddddSdՓddՓd	dd
dՓddՓddՓdWdՓddՓddՓd_dՓddՓddՓddՓi ddՓddՓd>dՓddՓddՓddՓddddddddddՓddՓddddddddddi ddddddddd dddddddddddd!dd"dd#dddd$dddd%di d&dd'dՓd(dՓd)dՓd*dd+dd,dd-dՓd.dՓd/dՓd0dyd1dyd2dyd3dyd4dyd5dd6di d7dd8d*d9d*d:d*d;d*d<d*d=d*d>d*d?d*d@d*dAdBdCd̓dDd̓dEdBdFdGdHddIdGi dϐdGdJdGdKddLddMdՓdNdՓdOdՓdPdՓdQdՓdRdՓdSdՓdTdՓdUdՓdVdydWdydXddYdՓdZdiddՐd[dՐdldldddddddՐdd\d]ddydddՐd4d$d$d$d$d$dݐd^dydd*d*d*d_d`ddadbidbdid`ddcdadbiiddci ddddeddfddgdddgdhdgdidgdjdggdkdlddmddnddoddpddqddrdgdsdgdjdgdtdggdkduddrdgdsdgdjdgdtdggdkdvddrdgdsdgdjdgdtdggdkdwddrdgdsdgdjdgdtdggdkdxddrdgdsdgdjdgdtdggdkdydd$dzd{ddݐdzd|dݐddzdddd}iddcdddddddd~idi dd4ddddddddddzddd$dzddddddddddd$dzddddddddzddddddddddddddddddddddddddddddddd]ddcddiidĐdci ddddeddfddgdddgdhdgdidgdjdggdkdlddmddnddqddrdgdsdgdjdgdtdggdkduddrdgdsdgdjdgdtdggdkdwddrdgdsdgdjdgdtdggdkdvddrdgdsdgdjdgdtdggdkdxddrdgdsdgdjdgdtdggdkdpddddoddydd$dzd{ddݐdzddݐdzdddddzddddzdddid͐dcddddddddidi ddddzddddddd$dzdddddddddddddd4dddd4dddddddd4i ddddddddddddddddddddddddjddddjddddjdddddddddddddddddddddddddddddddd]dƐdcd{diidːdcddddidȐdci id̐dcddddiddcdddddddddddАdАdidi ddГddddd$dzddГddddddddddddГdddddddddddddddddddddddd	ddddddddddd]ddddhdgdidgdjdgddggdkdݐddݐdddddzdddzddddzdddzdddddiddiddiddddddddzddddÐddddĜddddddddddŜ	ddddƜdǜi dddddddddd$dzdːdddddddd$dzdϐdddddd$dzddddd$dzddddd$dzdddאd$i ddddd dhddddhdddddddddddddddڐddddddݐddސdi dߐdddddddddzddddzdddݐdzddddddݓddݓddddddddddddddi ddddddddݓddddݓddddݓdddddd4ddddddddddi ddddddddddd dhddhdddddddېddܐdddGddGddGddGdddddd	dddd
dddddddddݐddݐddd]dddcdd	| j	                  d      | j	                  d      dddd	d	| j	                  d      | j	                  d      | j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d       g| j	                  d!      | j	                  d"      g| j	                  d#      | j	                  d      g| j	                  d$      | j	                  d%      gg
| j	                  d      | j	                  d      g| j	                  d      | j	                  d&      g| j	                  d      | j	                  d'      g| j	                  d      | j	                  d(      g| j	                  d      | j	                  d)      g| j	                  d      | j	                  d*      g| j	                  d      | j	                  d+      g| j	                  d!      | j	                  d,      g| j	                  d#      | j	                  d-      g| j	                  d$      | j	                  d      gg
d.d/idd0d	d	| j	                  d      | j	                  d)      | j	                  d      | j	                  d      g| j	                  d      | j	                  d1      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d       g| j	                  d      | j	                  d2      g| j	                  d      | j	                  d2      g| j	                  d!      | j	                  d2      g| j	                  d#      | j	                  d2      g| j	                  d$      | j	                  d2      gg
| j	                  d      | j	                  d)      g| j	                  d      | j	                  d*      g| j	                  d      | j	                  d3      g| j	                  d      | j	                  d4      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d5      g| j	                  d      | j	                  d6      g| j	                  d!      | j	                  d7      g| j	                  d#      | j	                  d8      g| j	                  d$      | j	                  d9      gg
d.d/ii d:d;d<| j                  d<d<| j	                  d      d=      id>d?d@dAdBt        dCi dDddEd	ddg dFdGddCd	dHdIdJddKd dLddMd	dNddzddOdtdPddQddRdSdSdTdUd	dVdVdWdXdWdXdXdYdZdZd[d\d\d]d^d]d]d^d_d`ddaddbdcddddedfdgdhdidjdkdkdldkdkidmdeidndfidoi dpd	dqd	drd	dsd	dtd	dud	dvd	dwd	dxd	dyd	dzd	d{d	d|d	d}d	d~d	dd	dd	d	d	d	d	d	d	d	d	d	d	d	d	d	d	d	ddd{idd	dd	d	d	d dd	d	d d	d	d	ddd	dd	dd	d	d	d	ddd	dd ddjd dd	dd	ddd	dd	d ddddd	djd dtddd	dd	djd d dtddd	dddjid	d	dd	d	d	ddd	d	d d	d	d	d	dd	d	d	dddd	dddidd djdd	ddddd	dd	diddddd	djddddd	dd	djddАdddd	dddid	ddiddidddiddiddddi dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt         dt        i dt        dt         dt"        dt        dt        dt        dt        dt$        dt        dt         dt         dt"        dt         dt        dt         dt        dt        i dt         dt         dt         dt        dt        dt"        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt         dt         dt        dt        dt         dt        dt        dt        dt        dt         dt        d t        dt        dt"        i dt"        dt"        dt"        dt"        dt"        dt"        d	t"        d
t"        dt"        dt"        dt"        dt        dt"        dt"        dt"        dt"        dt"        i dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        d t"        d!t"        d"t"        d#t"        d$t"        i d%t"        d&t"        d't"        d(t"        d)t"        d*t"        d+t"        d,t"        d-t"        d.t"        d/t"        d0t"        d1t"        d2t"        d3t"        d4t"        d5t"        i d6t"        d7t"        d8t"        d9t"        d:t"        d;t"        d<t"        d=t"        d>t"        d?t"        d@t"        dAt"        dBt"        dCt"        dDt"        dEt"        dFt"        i dGt"        dHt"        dIt"        dJt"        dKt"        dLt"        dMt"        dNt"        dOt"        dPt"        dQt"        dRt"        dSt"        dTt"        dUt"        dVt"        dWt"        i dXt"        dYt"        dZt"        d[t"        d\t"        d]t"        d^t"        d_t"        d`t"        dat"        dbt"        dct"        ddt"        det        dft        dgt        dht        i dit        djt        dkt        dlt        dmt        dnt        dot        dpt        dqt        drt        dst        dtt        dut         dvt        dwt        dxt        dyt        i dzt        d{t$        d|t        d}t        d~t        dt        dt        dt        dt         dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt         i dt        dt$        dt        dt        dt        dt         dt        dt        dt        dt         dt        dt        dt        dt         dt        dt        dt        t        t        t        t        t        t        t        t        t        t        d
idi dt         dt        dt         dt        dt        dt         dt        dt        dt        dt        dt        dt        dt        dt         dt        dt        dt        i dt&        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        d t        d!t        d"t         d#t        d't        d)t         d*t         dAt        dBt        dCt        dDt        dEt        dRt        i dt        d[t        d^t        dt        dWt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt         dt         dt         i dt         dt         dt        dt        dt        dt        dt         dt         dt         dt         drt(        dst(        dt        dt        dt        dt        dt        t        t        t        t        t        didi dt         dt         dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt&        dt        dt        dt        dt        i dt        dt        dt        d(t        d)t        d*t        d+t         dt         d>t        dt        d?t        d@t        ddt        dt        dt        dt        dt        t        t        t         t         t         t        t        t        t        t         t         t        didi dt"        dt"        dt"        dt"        dt$        dt"        dt"        dt"        dt"        dt"        dt        dt        dt        d t"        dt        dt        dt        i dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        i dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        i dt"        dt"        dt"        d t"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        d
t"        dt"        dt"        dt"        dt"        i dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        i d t"        d!t"        d"t"        d#t"        d$t"        d%t"        d&t"        d't"        d(t"        d)t"        d*t"        d+t"        d,t"        d-t"        d.t"        d/t"        d0t"        i d1t"        d2t"        d3t"        d4t"        d5t"        d6t"        d7t"        d8t"        d9t"        d:t"        d;t"        d<t"        d=t"        d>t"        d?t"        d@t"        dAt"        i dBt"        dCt"        dDt"        dEt"        dFt"        dGt"        dHt"        dIt"        dJt"        dKt"        dLt"        dMt"        dNt"        dOt"        dPt"        dQt"        dRt"        i dSt"        dTt"        dUt"        dVt"        dWt"        dXt"        dYt"        dZt"        d[t"        d\t"        d]t"        d^t"        d_t"        d`t"        dat"        dbt"        dct"        t"        t"        t"        t"        t"        t"        t"        t"        t"        t"        d
idi dt        dt"        dt         dt$        dt        dt         dt        dt        dt        dt"        dt         dt"        dt        dt        dt*        dt*        d	t        i d
t        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i d t        dt,        dt        d t        dt        dt        dt        dt(        dt&        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        d t        dt        dt        dt        dt        dt        dt        dt        dt        d	t        d
t         dt         dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        d t        i d!t        d"t         d#t        d$t        d%t        d&t*        d't        d(t        d)t         d*t         d8t        dAt        dBt        dEt        dRt        dVt        dXt        i dYt        dZt        dt&        d[t        d\t&        d^t        d!t        dt        dt        dt        dt        d"t        drt(        dst(        dt        d#t$        ii dt        dt        dt        dt$        dt        dt        dt.        dt        dt        dt        dt$        dt        dt        d	t0        d
t        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        d t,        dt,        dt        d t        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        d t        dt        dt        dt        dt        dt        dt        i dt        dt        d	t        d
t        dt        dt        dt        dt        dt        dt        dt        dt        d$t        d%t        d&t        d(t        d8t        i dVt        dXt        dYt        dZt        d\t&        d$t        d%t        d&t        d't        d(t        d)t        d*t        d+t        d,t        d-t2        d.t        d/t         i d0t        d1t&        d2t&        d3t&        d4t        d5t         d6t         d7t         d8t4        d9t$        d:t        d;t        d<t        d=t        d>t         d?t         t         t        d@dA      S (B  NidrK   nameBinance	countries	rateLimit2   	certifiedTprohasCORSspotmarginswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsFclosePositioncreateConvertTradecreateDepositAddresscreateLimitBuyOrdercreateLimitSellOrdercreateMarketBuyOrdercreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrdercreateMarketSellOrderWithCostcreateOrdercreateOrders$createOrderWithTakeProfitAndStopLosscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopLossOrdercreateStopMarketOrdercreateStopOrdercreateTakeProfitOrdercreateTrailingPercentOrdercreateTriggerOrder	editOrder
editOrdersfetchAccountsfetchBalancefetchBidsAsksfetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledAndClosedOrdersemulatedfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchConvertCurrenciesfetchConvertQuotefetchConvertTradefetchConvertTradeHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL3OrderBookfetchLastPricesfetchLedgerfetchLedgerEntryfetchLeveragefetchLeveragesfetchLeverageTiersfetchLiquidationsfetchLongShortRatiofetchLongShortRatioHistoryfetchMarginAdjustmentHistoryfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricefetchMarkPricesfetchMyLiquidationsfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTradingLimitsfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransferfetchTransfersfetchUnderlyingAssetsfetchVolatilityHistoryfetchWithdrawAddressesfetchWithdrawalfetchWithdrawalsfetchWithdrawalWhitelistreduceMarginrepayCrossMarginrepayIsolatedMarginsandbox)setLeverage	setMarginsetMarginModesetPositionModesignIntransferwithdraw
timeframes1s1m3m5m15m30m1h2h4h6h8h12h1d3d1w1MurlszOhttps://github.com/user-attachments/assets/e9419b93-ccb0-46aa-9bff-c883f096274bz)https://testnet.binancefuture.com/dapi/v1z)https://testnet.binancefuture.com/dapi/v2z)https://testnet.binancefuture.com/fapi/v1z)https://testnet.binancefuture.com/fapi/v2z)https://testnet.binancefuture.com/fapi/v3z%https://testnet.binance.vision/api/v3z%https://testnet.binance.vision/api/v1)
dapiPublicdapiPrivatedapiPrivateV2
fapiPublicfapiPublicV2fapiPublicV3fapiPrivatefapiPrivateV2fapiPrivateV3publicprivatev1sapizhttps://api.binance.com/sapi/v1sapiV2zhttps://api.binance.com/sapi/v2sapiV3zhttps://api.binance.com/sapi/v3sapiV4zhttps://api.binance.com/sapi/v4r   z https://dapi.binance.com/dapi/v1r   
eapiPublicz https://eapi.binance.com/eapi/v1eapiPrivater   z https://dapi.binance.com/dapi/v2dapiDataz%https://dapi.binance.com/futures/datar   z https://fapi.binance.com/fapi/v1r   z https://fapi.binance.com/fapi/v2r   z https://fapi.binance.com/fapi/v3r   r   r  fapiDataz%https://fapi.binance.com/futures/datazhttps://api.binance.com/api/v3zhttps://api.binance.com/api/v1z https://papi.binance.com/papi/v1)r  r  r  papizhttps://www.binance.comz5https://accounts.binance.com/en/register?ref=D7YA7CLYg?)urldiscountz!https://developers.binance.com/enz=https://www.binance.com/en/usercenter/settings/api-managementz'https://www.binance.com/en/fee/schedule)logotestapiwwwreferraldocapi_managementfeesr  zcopyTrading/futures/userStatus   zcopyTrading/futures/leadSymbolsystem/statusaccountSnapshot   zaccount/infozmargin/asset   zmargin/pairzmargin/allAssetszmargin/allPairszmargin/priceIndexzspot/delist-schedule
   zasset/assetDividendzasset/dribbletzasset/transferzasset/assetDetailzasset/tradeFeez.asset/ledger-transfer/cloud-mining/queryByPageg9m4 @z"asset/convert-transfer/queryByPagegoӟH?zasset/wallet/balance   zasset/custody/transfer-historyzmargin/borrow-repayzmargin/loanzmargin/repayzmargin/accountzmargin/transferzmargin/interestHistoryzmargin/forceLiquidationRecmargin/ordermargin/openOrderszmargin/allOrders   zmargin/myTradeszmargin/maxBorrowable   zmargin/maxTransferablezmargin/tradeCoeffzmargin/isolated/transfermargin/isolated/accountzmargin/isolated/pairzmargin/isolated/allPairszmargin/isolated/accountLimitzmargin/interestRateHistorymargin/orderListzmargin/allOrderListzmargin/openOrderListzmargin/crossMarginDatag      ?)costnoCoinzmargin/isolatedMarginDatazmargin/isolatedMarginTierzmargin/rateLimit/orderzmargin/dribbletzmargin/dustgK7A 4@z!margin/crossMarginCollateralRatiozmargin/exchange-small-liabilitygK=U?z'margin/exchange-small-liability-historyz margin/next-hourly-interest-ratezmargin/capital-flowzmargin/delist-schedulezmargin/available-inventoryg-!lV?zmargin/leverageBracketzloan/vip/loanable/data(   zloan/vip/collateral/datazloan/vip/request/datagK=U@zloan/vip/request/interestRatezloan/incomegK7A D@zloan/ongoing/orderszloan/ltv/adjustment/historyzloan/borrow/historyzloan/repay/historyzloan/loanable/datazloan/collateral/datazloan/repay/collateral/rateiX  loan/flexible/ongoing/orders   loan/flexible/borrow/historyloan/flexible/repay/history$loan/flexible/ltv/adjustment/historyzloan/vip/ongoing/orderszloan/vip/repay/historyzloan/vip/collateral/accountzfiat/ordersg
ףp=@zfiat/paymentszfutures/transferzfutures/histDataLinkzrebate/taxQuerygK7A T@zcapital/config/getallzcapital/deposit/addresszcapital/deposit/address/listzcapital/deposit/hisreczcapital/deposit/subAddresszcapital/deposit/subHisreczcapital/withdraw/historyzcapital/withdraw/address/listz"capital/contract/convertible-coinszconvert/tradeFlowconvert/exchangeInfozconvert/assetInfoconvert/orderStatuszconvert/limit/queryOpenOrderszaccount/statuszaccount/apiTradingStatusz%account/apiRestrictions/ipRestrictionbnbBurnsub-account/futures/account"sub-account/futures/accountSummary sub-account/futures/positionRiskz$sub-account/futures/internalTransferzsub-account/listzsub-account/margin/accountz!sub-account/margin/accountSummaryzsub-account/spotSummaryzsub-account/statusz sub-account/sub/transfer/historyz#sub-account/transfer/subUserHistoryzsub-account/universalTransferz8sub-account/apiRestrictions/ipRestriction/thirdPartyListz"sub-account/transaction-statisticsg'o|?'sub-account/subAccountApi/ipRestrictionzmanaged-subaccount/assetz"managed-subaccount/accountSnapshotz+managed-subaccount/queryTransLogForInvestorz.managed-subaccount/queryTransLogForTradeParentz%managed-subaccount/fetch-future-assetzmanaged-subaccount/marginAssetzmanaged-subaccount/infoz"managed-subaccount/deposit/addressgf/N{?z"managed-subaccount/query-trans-logzlending/daily/product/listzlending/daily/userLeftQuotaz!lending/daily/userRedemptionQuotazlending/daily/token/positionzlending/union/accountzlending/union/purchaseRecordzlending/union/redemptionRecordzlending/union/interestHistoryzlending/project/listzlending/project/position/listz&eth-staking/eth/history/stakingHistory   z)eth-staking/eth/history/redemptionHistoryz&eth-staking/eth/history/rewardsHistoryzeth-staking/eth/quotaz#eth-staking/eth/history/rateHistoryeth-staking/accountz%eth-staking/wbeth/history/wrapHistoryz'eth-staking/wbeth/history/unwrapHistoryz+eth-staking/eth/history/wbethRewardsHistoryz&sol-staking/sol/history/stakingHistoryz)sol-staking/sol/history/redemptionHistoryz+sol-staking/sol/history/bnsolRewardsHistoryz#sol-staking/sol/history/rateHistoryzsol-staking/accountzsol-staking/sol/quotazmining/pub/algoListzmining/pub/coinListzmining/worker/detailzmining/worker/listzmining/payment/listzmining/statistics/user/statuszmining/statistics/user/listzmining/payment/uidzbswap/poolszbswap/liquidity)r%  noPoolIdzbswap/liquidityOpszbswap/quoteg9m4 ?z
bswap/swapzbswap/poolConfigurezbswap/addLiquidityPreviewzbswap/removeLiquidityPreviewzbswap/unclaimedRewardsg^I@zbswap/claimedHistoryzblvt/tokenInfozblvt/subscribe/recordzblvt/redeem/recordzblvt/userLimitzapiReferral/ifNewUserapiReferral/customizationapiReferral/userCustomizationzapiReferral/rebate/recentRecordz#apiReferral/rebate/historicalRecordz!apiReferral/kickback/recentRecordz%apiReferral/kickback/historicalRecordbroker/subAccountApizbroker/subAccountz'broker/subAccountApi/commission/futuresz+broker/subAccountApi/commission/coinFutureszbroker/infozbroker/transferzbroker/transfer/futureszbroker/rebate/recentRecordzbroker/rebate/historicalRecordz broker/subAccount/bnbBurn/statuszbroker/subAccount/depositHistzbroker/subAccount/spotSummaryzbroker/subAccount/marginSummaryz broker/subAccount/futuresSummaryz"broker/rebate/futures/recentRecordz"broker/subAccountApi/ipRestrictionzbroker/universalTransferzaccount/apiRestrictionsz#c2c/orderMatch/listUserOrderHistoryznft/history/transactionsznft/history/depositznft/history/withdrawznft/user/getAssetzpay/transactionszgiftcard/verifyz$giftcard/cryptography/rsa-public-keyzgiftcard/buyCode/token-limitzalgo/spot/openOrderszalgo/spot/historicalOrderszalgo/spot/subOrderszalgo/futures/openOrderszalgo/futures/historicalOrderszalgo/futures/subOrdersportfolio/accountzportfolio/collateralRatezportfolio/pmLoang^I
@zportfolio/interest-historyzportfolio/asset-index-pricezportfolio/repay-futures-switch   zportfolio/margin-asset-leveragezportfolio/balancez*portfolio/negative-balance-exchange-recordzportfolio/pmloan-historyzstaking/productListzstaking/positionzstaking/stakingRecordzstaking/personalLeftQuotaz%lending/auto-invest/target-asset/listz)lending/auto-invest/target-asset/roi/listzlending/auto-invest/all/assetz%lending/auto-invest/source-asset/listzlending/auto-invest/plan/listzlending/auto-invest/plan/idz lending/auto-invest/history/listzlending/auto-invest/index/infoz&lending/auto-invest/index/user-summaryz"lending/auto-invest/one-off/statusz"lending/auto-invest/redeem/historyz%lending/auto-invest/rebalance/historyzsimple-earn/flexible/listzsimple-earn/locked/listz&simple-earn/flexible/personalLeftQuotaz$simple-earn/locked/personalLeftQuotaz(simple-earn/flexible/subscriptionPreviewz&simple-earn/locked/subscriptionPreviewz(simple-earn/flexible/history/rateHistoryzsimple-earn/flexible/positionzsimple-earn/locked/positionzsimple-earn/accountz/simple-earn/flexible/history/subscriptionRecordz-simple-earn/locked/history/subscriptionRecordz-simple-earn/flexible/history/redemptionRecordz+simple-earn/locked/history/redemptionRecordz*simple-earn/flexible/history/rewardsRecordz(simple-earn/locked/history/rewardsRecordz-simple-earn/flexible/history/collateralRecordzdci/product/listzdci/product/positionszdci/product/accounts
asset/dustgoӟH?zasset/dust-btcgUN @zasset/get-funding-assetzasset/convert-transferz!account/disableFastWithdrawSwitchz account/enableFastWithdrawSwitchcapital/withdraw/applyzcapital/deposit/credit-applygSc${?zmargin/order/ocog9m4  @zmargin/max-leveragei,  zsub-account/virtualSubAccountzsub-account/margin/transferzsub-account/margin/enablezsub-account/futures/enablezsub-account/futures/transferzsub-account/transfer/subToSubz sub-account/transfer/subToMasterzsub-account/options/enablezmanaged-subaccount/depositzmanaged-subaccount/withdrawuserDataStreamuserDataStream/isolatedz lending/customizedFixed/purchasezlending/daily/purchasezlending/daily/redeemzbswap/liquidityAdd<   zbswap/liquidityRemovezbswap/claimRewardszblvt/subscribezblvt/redeemzbroker/subAccount/marginzbroker/subAccount/futureszbroker/subAccountApi/permissionzbroker/subAccountApi/commissionzbroker/subAccount/bnbBurn/spotz(broker/subAccount/bnbBurn/marginInterestzbroker/subAccount/blvt)broker/subAccountApi/ipRestriction/ipListz1broker/subAccountApi/permission/universalTransferz.broker/subAccountApi/permission/vanillaOptionszgiftcard/createCodezgiftcard/redeemCodezgiftcard/buyCodezalgo/spot/newOrderTwapzalgo/futures/newOrderVpzalgo/futures/newOrderTwapzstaking/purchasezstaking/redeemzstaking/setAutoStakingeth-staking/eth/stakezeth-staking/eth/redeemzeth-staking/wbeth/wrapzsol-staking/sol/stakezsol-staking/sol/redeemzmining/hash-transfer/configz"mining/hash-transfer/config/cancelzportfolio/repayzloan/vip/renewzloan/vip/borrowzloan/borrowz
loan/repayzloan/adjust/ltvzloan/customize/margin_callloan/flexible/repayloan/flexible/adjust/ltvzloan/vip/repayconvert/getQuotegK=U?convert/acceptQuotezconvert/limit/placeOrderzconvert/limit/cancelOrderzportfolio/auto-collection   zportfolio/asset-collectionzportfolio/bnb-transferz(portfolio/repay-futures-negative-balancezportfolio/mintzportfolio/redeemzlending/auto-invest/plan/addzlending/auto-invest/plan/editz$lending/auto-invest/plan/edit-statuszlending/auto-invest/one-offzlending/auto-invest/redeemzsimple-earn/flexible/subscribezsimple-earn/locked/subscribezsimple-earn/flexible/redeemzsimple-earn/locked/redeemz%simple-earn/flexible/setAutoSubscribez#simple-earn/locked/setAutoSubscribez"simple-earn/locked/setRedeemOptionzdci/product/subscribezdci/product/auto_compound/edit)r>  r?  )r   r  r$  r#  r>  r?  r9  rA  zalgo/spot/orderzalgo/futures/orderz.sub-account/subAccountApi/ipRestriction/ipList)getpostputdelete)r5  r0  r1  r2  r(  r*  r+  r,  zloan/flexible/loanable/datazloan/flexible/collateral/datar:  )rB  r3  zloan/flexible/borrowrC  rD  )rH  rI  zsub-account/assetszasset/getUserAssetrH  pingtimeexchangeInfodepthd       )r%  byLimittradeshistoricalTrades	aggTradespremiumIndexfundingRateklinesc   i  i'  continuousKlinesindexPriceKlinesmarkPriceKlinespremiumIndexKlinesticker/24hr)r%  noSymbolticker/priceticker/bookTicker)constituentsopenInterestfundingInfo)delivery-priceopenInterestHisttopLongShortAccountRatiotopLongShortPositionRatioglobalLongShortAccountRatiotakerBuySellVolbasispositionSide/dualorderAmendmentorder	openOrder
openOrders	allOrdersbalanceaccountzpositionMargin/historypositionRisk
userTradesincomeleverageBracketforceOrdersadlQuantilecommissionRatezincome/asyn)income/asyn/id
trade/asyntrade/asyn/id
order/asynorder/asyn/idpmExchangeInfopmAccountInfo   )rm  ro  batchOrderscountdownCancelAllleverage
marginTypepositionMargin	listenKey)r  ro  r  )ro  allOpenOrdersr  r  re  )rb  rd  	indexInfo
assetIndexrc  apiTradingStatus	lvtKlinesr-  )rf  rg  rh  ri  rj  takerlongshortRatiorl  rateLimit/orderr  multiAssetsMarginzapiReferral/traderNumzapiReferral/overviewzapiReferral/tradeVolzapiReferral/rebateVolzapiReferral/traderSummaryr  r|  r  r  r}  r~  )feeBurnsymbolConfigaccountConfigr.     )r  rm  r  r  ro  r  r  r  r  r7  r8  r  rE  rF  )r  ro  r  r  r   )rt  rs  ru  )rL  rM  rN  indextickermarkrO  rY  rT  rU  exerciseHistoryrd  positionhistoryOrdersexerciseRecordbillmarginAccountmmpr  zblock/order/ordersblock/order/executezblock/user-tradesblockTrades)	ro  r  r  mmpSetmmpResetr  countdownCancelAllHeartBeatblock/order/creater  )r  r  )ro  r  r  allOpenOrdersByUnderlyingr  r  g?i  g?   g?)rL  rM  rO  rT  rV  rU  rY  uiKlinesr_  r  zticker/tradingDayra  rb  rN  avgPrice)rH  rJ  rI  rK  g333333?   )allOrderListopenOrderList	orderListro  rq  rr  rt  myTradesr  myPreventedMatchesmyAllocationszaccount/commission)	z	order/ocozorderList/ocozorderList/otozorderList/otoco	sor/orderzsor/order/testro  zorder/cancelReplacez
order/test)rq  r  ro  )rH  rI  rK  um/orderzum/openOrderzum/openOrderszum/allOrderscm/orderzcm/openOrderzcm/openOrderszcm/allOrderszum/conditional/openOrderzum/conditional/openOrderszum/conditional/orderHistoryzum/conditional/allOrderszcm/conditional/openOrderzcm/conditional/openOrderszcm/conditional/orderHistoryzcm/conditional/allOrderszmargin/maxWithdrawzum/positionRiskzcm/positionRiskzum/positionSide/dualzcm/positionSide/dualzum/userTradeszcm/userTradeszum/leverageBracketzcm/leverageBracketzmargin/forceOrderszum/forceOrderszcm/forceOrderszum/apiTradingStatuszum/commissionRatezcm/commissionRatezmargin/marginLoanzmargin/repayLoanzmargin/marginInterestHistoryz	um/incomez	cm/incomez
um/accountz
cm/accountzrepay-futures-switchzum/adlQuantilezcm/adlQuantilezum/trade/asynzum/trade/asyn/idzum/order/asynzum/order/asyn/idzum/income/asynzum/income/asyn/idzum/orderAmendmentzcm/orderAmendment
um/feeBurnzum/accountConfigzum/symbolConfigzcm/accountConfigzcm/symbolConfigum/conditional/ordercm/conditional/order
marginLoan	repayLoanzum/leveragezcm/leveragezauto-collectionzbnb-transferzrepay-futures-negative-balancer  i  )zasset-collectionzmargin/repay-debtr  )r  r  r  )r  r  zum/allOpenOrderszum/conditional/allOpenOrdersr  r  zcm/allOpenOrderszcm/conditional/allOpenOrdersr  zmargin/allOpenOrdersr$  r  )r  r  r  r  z0.001)feeSide	tierBased
percentagetakermakertradingquotez0.000500z0.0002000z0.0004002502500z0.0003507500z0.00032022500z0.00030050000z0.000270100000z0.000250200000z0.000220400000750000z0.000170z0.000160z0.000140z0.000120z0.000100z0.000080z0.000060z0.000040z0.000020)r  r  )r  r  r  r  r  tiersbasez0.000450z0.000240z0.000050z	0.0000030z	-0.000050z	-0.000060z	-0.000070z	-0.000080z	-0.000090)r  linearinverser\   
currenciesBNFCR)rN   code	precisioncommonCurrenciesBCCYOYOW)r  YOYOprecisionModeoptionssandboxModefetchMarginsrX   r  r  loadAllOptionsdefaultTimeInForceGTCdefaultTypedefaultSubType#hasAlreadyAuthenticatedSuccessfully"warnOnFetchOpenOrdersWithoutSymbolthrowMarginModeAlreadySet
recvWindowtimeDifferenceadjustForTimeDifferencenewOrderRespTypeFULL)marketlimitquoteOrderQty
x-TKT5PX2Fz
x-cvBPrNm9
x-xcKtGhcu)rX   rY   r[   deliveryrZ   r\   r  MAINFUNDINGMARGINUMFUTURECMFUTUREOPTION)mainrX   fundingrY   crossr[   r  r  rZ   r  r\   r  r  r  )r  r  r  r  r  r  ETHTRXBNBBSCOMNIEOSSOL)ERC20TRC20BEP2BEP20r  r  SPLr  r  r  )r  r  MXNUGXSEKCHFVNDAEDDKKKZTHUFPENPHPUSDTRYEURNGNPLNBRL)ZARKESARSRUBAUDNOKCZKGBPUAHGHSHKDCADINRJPYNZDBUSDg:0yE>)	brokeraccountsByTypeaccountsByIdnetworksnetworksByIdimpliedNetworks
legalMoneylegalMoneyCurrenciesByIddefaultWithdrawPrecisionfeatures)IOCFOKPOGTD)expire_makerexpire_takerexpire_bothnone)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedr  marketBuyByCostmarketBuyRequiresPriceselfTradePreventiontrailingicebergAmount)r6  r  daysBack	untilDayssymbolRequired)r6  triggerrB  rF  )r6  r  rG  rB  rF  )r6  r  rD  rE  rG  rB  rF  )r6  r  rD  daysBackCanceledrE  rG  rB  rF  r  )	r   rn   ro   r   r   r   r   r   r   )r  lastr  )r6  r7  r8  r:  r;  r<  r=  r>  rA  rB  icebergr  r@  r?  max   )r6  rD  r  rE  rF  Z     extendsforDerivatives)r  r  )rX   rP  rZ   r[   
exceptionsexactz-1004z-1008z-1099z-1108z-1131z-1134z-1135z-1145z-1151z-2008z-2016z-2021z-2022z-2026z-3000z-3001z-3002z-3003z-3004z-3005z-3006z-3007z-3008z-3009z-3010z-3011z-3012z-3013z-3014z-3015z-3016z-3017z-3018z-3019z-3020z-3021z-3022z-3023z-3024z-3025z-3026z-3027z-3028z-3029z-3036z-3037z-3038z-3041z-3042z-3043z-3044z-3045z-3999z-4000z-4001z-4002z-4003z-4004z-4005z-4006z-4007z-4008z-4009z-4010z-4011z-4012z-4013z-4014z-4015z-4016z-4017z-4018z-4019z-4020z-4021z-4022z-4023z-4024z-4025z-4026z-4027z-4028z-4029z-4030z-4031z-4032z-4033z-4034z-4035z-4036z-4037z-4038z-4039z-4040z-4041z-4042z-4043z-4044z-4045z-4046z-4047z-4048z-4049z-4050z-4051z-4052z-4053z-4054z-4055z-4056z-4057z-4058z-4059z-4060z-4061z-4062z-4063z-4064z-4065z-4066z-4067z-4068z-4069z-4070z-4071z-4072z-4073z-4074z-4075z-4076z-4077z-4078z-4079z-4080z-4081z-4082z-4083z-4084z-4085z-4086z-4087z-4088z-4089z-4091z-4092z-4093z-4094z-4095z-4096z-4097z-4098z-4099z-4101z-4102z-4103z-4104z-4105z-4106z-4107z-4108z-4109z-4110z-4112z-4113z-4114z-4115z-4116z-4117z-4118z-4119z-4120z-4121z-4122z-4123z-4124z-4125z-4126z-4127z-4128z-4129z-4130z-4131z-4132z-4133z-4134z-4135z-4136z-4137z-4138z-4139z-4141z-4142z-4143z-4144z-4145z-4146z-4147z-4148z-4149-4150z-5001z-5002z-5003z-5004z-5005z-5006z-5007z-5008z-5009z-5010z-5011z-5012z-5013z-5021z-5022z-6001z-6003z-6004z-6005z-6006z-6007z-6008z-6009z-6011z-6012z-6013z-6014z-6015z-6016z-6017z-6018z-6019z-6020z-7001z-7002z-10001z-10002z-10005z-10007z-10008z-10009z-10010z-10011z-10012z-10013z-10015z-10016z-10017z-10018z-10019z-10020z-10021z-10022z-10023z-10024z-10025z-10026z-10028z-10029z-10030z-10031z-10032z-10034z-10039z-10040z-10041z-10042z-10043z-10044z-10045z-10046z-10047z-11008z-12014z-13000z-13001z-13002z-13003z-13004z-13005z-13006z-13007z-18002z-18003z-18004z-18005z-18006z-18007z-21001)
z-21002z-21003z-21004z-21005z-21006z-21007z-32603400002	100001003	200003903z-1005z-1011z-1023z-1109z-1110z-1113z-1122z-1126z-1136z-2012z-2017z-2018z-2019z-2020z-2023z-2024z-2025z-2027z-2028z-4140z-4164z-4165z-4167z-4168z-4169z-4170z-4171z-4172z-4183z-4184-4192-4202z-4203z-4205z-4206z-4208z-4209z-4210z-4211z-4400z-4401z-4402z-4403z-5024z-5025z-5026z-5027z-5028)z-5037z-5038z-5039z-5040-5041z-1128z-4090z-4111z-4151z-4152z-4154z-4155)z-4178z-4188rW  z-4194z-4195z-4196z-4197z-4198z-4199z-4200z-4201rX  z-1003z-1006z-1007z-1010z-1013z-1112z-1114z-1129z-2011)
rS  -20121-20124-20130-20132-20194-20195-20196-20198-20204z-1000z-1001z-1002z-1014z-1015z-1016z-1020z-1021z-1022z-1100z-1101z-1102z-1103z-1104z-1105z-1106z-1111z-1115z-1116z-1117z-1118z-1119z-1120z-1121z-1125z-1127z-1130z-2010z-2013z-2014-2015z-4161z-4408rY  rZ  r[  r\  r]  r^  r_  r`  ra  rb  zSystem is under maintenance.zSystem abnormalityz/You are not authorized to execute self request.zAPI key does not existz Order would trigger immediately.z%Stop price would trigger immediately.z'Order would immediately match and take.z6Account has insufficient balance for requested action.z Rest API trading is not enabled.z,This account may not place or cancel orders.zYou don't have permission.zMarket is closed.z*Too many requests. Please try again later.z(This action is disabled on self account.z(Limit orders require GTC for self phase.z=This order type is not hasattr(self, possible) trading phase.z9This type of sub-account exceeds the maximum number limitz+This symbol is restricted for self account.z.This symbol is not permitted for self account.)zhas no operation privilegeMAX_POSITION)rX   r  r  r\   portfolioMarginrR  broad)deep_extendsuperrK   describeparse_numbersafe_currency_structurerH   r@   r1   r5   r6   r7   rF   r;   r3   r:   r2   r0   rB   r=   r>   r?   r<   rE   rD   rC   r9   )self	__class__s    F/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/binance.pyri  zbinance.describe*   sGo   gt = ? I(B
)I(B
II(B
 I(B
 	I(B

 I(B
 4I(B
  PPP $P 	P
 $P $P TP $TP 'P "4P tP P $UP  P %dP  '!P" &t#P$ '%P& ''P( /)P* ,T+P, (-P. 0/P0 t1P2 3P4 75P6 &t7P8 (9P: ';P< &t=P> (?P@ "4APB (CPD -dEPF %dGPH TIPJ dKPL  MPN OPP  QPR &tSPT +EUPV )$WPX /
YPZ &z[P\ #E]P^ $Z_P` )$aPb $TcPd $TePf +DgPh 'iPj (kPl "4mPn oPp &tqPr (sPt 1%uPv  wPx +EyPz *:{P| +D}P~ &tP@ '
APB (CPD #DEPF *4GPH $TIPJ tKPL "4MPN *:OPP +DQPR #ESPT "4UPV tWPX #DYPZ  [P\ !$]P^ %d_P` $UaPb &ucPd -dePf /gPh "4iPj #DkPl +JmPn oPp !$qPr !$sPt "4uPv &twPx +DyPz  {P| d}P~ $TP@ +DAPB !$CPD "4EPF tGPH #EIPJ dKPL !$MPN "5OPP tQPR #DSPT  UPV 'WPX $TYPZ !$[P\ (]P^ %d_P` )$aPb )$cPd tePf tgPh iPj TkPl tmPn "4oPp #DqPr %jsPt &zuPv 'wPx $UyPz  {P| !$}P~ (P@ )%APB )%CPD "5EPF #DGPH +EIPJ KPL #DMPN &tOPP 4QPR  $"!%#'  _PI(B
r  dd d d	
 u u d d d d d u d d d  d!sI(B
V i"M#N%P"M$O$O#N%P%PEFA=? ? ?	
 !"D "#E !"D "#E $%G  G !"D #$F #$F "#E $%G  $%G!"  G#$ ??:>+. 1R #
 8 #bAa1WI(B
z  eR8!R 9!R (	R *3R 'R 'R &qR +CR *3R ,QR /R .qR  )#!R" )##R$ ,S%R& )#'R( I&)R* =h+R, /-R. 9!/R0 .q1R2 &q3R4 '5R6 )!7R8 *39R: 1#;R< 5c=R> '?R@ ,QARB +BCRD *1ERF /GRH 1!IRJ ,QKRL 3CMRN 21ORP /QRR 3ASRT 7URV 5cWRX +AYRZ .r[R\ /]R^ 13#2N_R` 4cQ5OaRb 4ScRd 1!eRf *3gRh &viRj <RkRl :6mRn B6oRp ;FqRr .rsRt 1"uRv 5fwRx 1#yRz 1"{R| 3B}R~ 0R@ 8ARB &vCRD .rERF 6rGRH .rIRJ -bKRL -bMRN /ORP 5cQRR 7SRT 7URV 6rWRX ?YRZ 22[R\ 1"]R^ 6s_R` &vaRb (cRd +AeRf /gRh *6iRj 0kRl 21mRn 7oRp 1#qRr 5csRt 4SuRv 3AwRx 8yRz =f{R| ,V}R~ /R@ ,RARB .vCRD 8ERF )#GRH 3CIRJ @KRL "3MRN 6qORP =cQRR ;ASRT ?URV +CWRX 5aYRZ <Q[R\ 23]R^ -a_R` ;CaRb >scRd 8eRf STUgRh =giRj B6kRl 3CmRn =coRp FsqRr I'sRt @uRv 9#wRx 27yRz =h{R| =g}R@ 5cARB 6sCRD <SERF 7GRH 0IRJ 7KRL 9#MRN 8ORP /QRR 8SRV A"WRX DRYRZ A"[R\ 0]R^ >r_R` .raRb @cRd B2eRf FrgRh A"iRj DRkRl FrmRn >roRp .rqRr 0sRv .swRx .syRz /{R| -c}R~ .sR@ 8ARB 6sCRD -cERH &sIRJ *CQ+GKRL -fMRN &wORP %fQRR .wSRT 4WURV 7WRX 1%YRZ /[R^ )#_R` 0aRb -ccRd )#eRh 0iRj 4QkRl 8mRn :1oRp >qqRr <QsRt @uRx /yRz ,Q{R| B1}R~ FqR@ &qARB *1CRD 21ERF 5aGRH 9!IRJ ;AKRL 8MRN 8ORP :1QRR ;ASRT =aURV =aWRX 3AYR^ 23_Rb >scRf 3FgRh .viRj /kRl ,VmRn +FoRp *3qRr ?sRt 7uRv /wRx 5cyRz .s{R| 23}R~ 8R@ 1#ARB ,SCRD 3AERF +FGRH 5fIRJ 6sKRL 9!MRN :1ORP ,QQRR EaSRT 3AURX .sYRZ +C[R\ 0]R^ 4S_R` @aRb DScRd 8eRf @gRh 8iRj 6skRl ;CmRn 9#oRp A#qRr =csRt =cuRv @wRz 4R{R| 22}R~ A"R@ ?ARB CBCRD A"ERF CBGRH 8IRJ 6rKRL .rMRN J2ORP HQRR HSRT FrURV EbWRX CBYRZ H[R^ +C_R` 0aRb /cRfF$gF(#F )&F 23	F
 1(F <SF ;CF 1&F =fF 7F .vF *6F &vF  '!F" '#F$ +H%F& &v'F( :6)F, 3F-F. 26/F0 .s1F2 "33F4 85F6 6v7F8 4S9F: 5c;F< 7=F> ??F@ 8AFB ;CCFD 8EFF 5cGFH 5cIFJ 6sKFL )#MFN 23OFP +CQFT ;CUFV 1#WFX /YF\ -b]F^ 0_F` %baFb -ecFf )#gFh &siFl 4QmFn 8oFp >qqFr @sFt ,QuFv 3AwFx 4QyFz /{F| :1}F~ :1F@ B1AFB FqCFD *1EFF 21GFH 9!IFJ 9!KFL CAMFN 1!OFP =aQFR DQSFT 3AUFV LQWFX I!YF\ .s]F^ .s_F` +CaFb 1&cFd 26eFf 4VgFj +CkFl )#mFn 1#oFr 0sFt 1"uFv 1"wFx 0yFz 1"{F~ 6sF@ =cAFB *6CFD )&EFF *6GFH &vIFJ %fKFL *6MFN 5fOFP .vQFR 3FSFT )&UFV +FWFX .vYFZ 3F[F\ 4V]F^ 4S_F` 5aaFb 1#cFd 9#eFf CCgFh )"iFj +BkFl 7mFn 8oFp ?qFr 6ssFt 5cuFx 9#yFz 7{F| 6s}F~ 4SF@ @AFB >rCFD =aEFH 0IFJ 9#KFP +.36 .1(0,439*-3601EF+..1JPIsel /17:>?<?8:8:79@B799;-. 24CI06/54:meX ,g -c	Yeh ,gier   '  !"a3(SRTIX\^`Wa8b!c	
 !! +B $R ' &q !12q'C8dTUYY^`bXc9d"e +QRGcSTXX\^_W`chjlbmCn,o +QRGcSTXX\^_W`chjlbmCn,o *AB7SRSHW[]^V_bgikalBm+n -qr1gPSUVxZ^`aYbejlndoEp.q &r'B  '(B!" ,aQ-G#$ )*()'()seb *+,-455678+,!"
cex +R(!   $Q	
 %qa&@ $bb%A "1 "1 1! ' %rr&B !" *1 &'C &q  )"!" &q#$ +,&)),&)),*-),16 ./!"'(.0$%&'*+%&	 &'!"'( "#)*'(%&	U0 yeZ  )1"[ed   '  !"a3(SRTIX\^`Wa8b!c	
 !! +B $R !12q'C8dTUYY^`bXc9d"e +QRGcSTXX\^_W`chjlbmCn,o *AB7SRSHW[]^V_bgikalBm+n +QRGcSTXX\^_W`chjlbmCn,o -qr1gPSUVxZ^`aYbejlndoEp.q &q &q '  &r'B!" '(B#$ 78Q-G()%&/0b&A()56B,G%&013ee^ *+,-455678/0!"
_et (%'C(#Q( $Q( %qb&A	(
  ( "1( "1( *1( 1!( '( ,R( %a( !"( )"( *1(  +A!(" ,R#(& 0'(( 4Q)(* 8+(, 0-(. //(0 /1(2 03(4 4Q5(6 &q7(8 (9(: )!;(< &t=(> )"?(@ %dA(B (C(D %dE(F (G(H $%())*/0O(T ()-.*+&'!"$%%&.0-.569:#$,//1$ &'!"'( ()!")*%&	AF ueB &!CeL  #$#$()"MeZ 2![e`  #$#$()"aen  ! !()!""# !!""#"#,.+,()oeN !1"A %qb&A (	
 %a )!  &q )! ( q -a   -a .q  ,Q!" &q#( "#'(%&"#$%./79.//0
 &'./
 "#'()*56%&./G+ Oen !$ #*+#qC8dTVZZ^`bYc8d!e"#%(,-"%$'03'D+.B"?-014#(F69s-K()$'$ )# )# )#5@ )*),%(!$/2&C%&#$$%+,./)*./ &)),),+.%(*-!$/2&)
 '*%(!$5JDD"AD 'D (!)D	D
 'D #AD 'D (!)DD 'D 3AD 4aR5PD 6qD 3QB4OD 3AD 4aR5PD  6q!D" 3B#D$ '%D& ,Q'D( +C)D* +A+D, .s-D. //D0 *11D2 "13D4 "15D6 /7D8 -a9D: *1;D< *3=D> /?D@ /ADB (CDD (EDF -cGDH -cIDJ -aKDL )22*FMDN )22*FODP ./KQDR ,QSDT ,QUDV ,QWDX +AYDZ 7[D\ 5b]D^ $Q_D` $QaDb %acDd %aeDf /gDh )!iDj )!kDl (mDn +AoDp (qDr +AsDt )#uDv ,QwDx ,QyDz ,Q{D| %b}D~ +AD@ *1ADB +ACDD *1EDF *1GDJ"A. #A /	
 ' %c $S +A &s &s / / *3 ' /  9#!" $S#$ -.-1&'). &)$%$% %&01,-89$%01,-89()01,-%(Ksce{I(B
F$ $!&"&!..w7!..w7 #*%)&*!%!2!2:!>!%!2!2:!> "&!2!23!79J9J:9V W!%!2!25!94;L;LZ;X Y!%!2!26!:D<M<Mj<Y Z!%!2!26!:D<M<Mj<Y Z!%!2!27!;T=N=Nz=Z [!%!2!27!;T=N=Nz=Z [!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPZ>[ \& "&!2!23!79J9J:9V W!%!2!25!94;L;LZ;X Y!%!2!26!:D<M<Mj<Y Z!%!2!26!:D<M<Mj<Y Z!%!2!27!;T=N=Nz=Z [!%!2!27!;T=N=Nz=Z [!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPS>T U&"  "H #)%)&*!%!2!2:!>!%!2!2:!> "&!2!23!79J9J:9V W!%!2!25!94;L;LZ;X Y!%!2!26!:D<M<Mj<Y Z!%!2!26!:D<M<Mj<Y Z!%!2!27!;T=N=Nz=Z [!%!2!27!;T=N=Nz=Z [!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPZ>[ \!%!2!28!<d>O>OPZ>[ \& "&!2!23!79J9J:9V W!%!2!25!94;L;LZ;X Y!%!2!26!:D<M<Mj<Y Z!%!2!26!:D<M<Mk<Z [!%!2!27!;T=N=Ns=S T!%!2!27!;T=N=N{=[ \!%!2!28!<d>O>OP[>\ ]!%!2!28!<d>O>OP[>\ ]!%!2!28!<d>O>OP[>\ ]!%!2!28!<d>O>OP[>\ ]&"  "F ]OG$I(B
f& 55Wgdhduduv}d~6  Ag&I(B
l& !m&I(B
t& Yu&I(B
x&  vuvv  !v !%v "4v %ev vv !$v  6u!v" 5d#v. ,U/v0 !.1v2 i3v4 !!5v6 *57v8 #$#%9v@  AvD )** ,(*+ #"(&%( *(&)&# #(& ( )&! #"!""   	 5! $U+#U+$!4!4! 4! 4	!
 4! 4! 4! 4! 4! 4! 4! 4! 4! 4! 4!  4!!" 4#!$  A!F E- -7kvy&I(B
f* #&*(,,0,1)-+/6:#'#'"&#(	( #'$)+/27,0,0+/$(	0 %*)-3$6 %)&+!%$(%&*.& '+#($)*.	# '+!%#($)*/( '+!%$(%*#($)*.$ '+!%$(,0%*#($)*.	*  #KHT  $&+(,$($(%*-
 *.+/6:#'#'"&#'	( #'/3$(#($)27+/3$8 q% ',$(!%%&*.& ',#($)*.	# '+!$#($)*/( '+!%$&%&#($)*.$ '+!%$&,-%&#($)*.	*  #OJ#Z "#3 "#3 	 "#3 "#3 	{eg*I(B
r/  M  	M
  M  !4M  M  M  M  M  M  M   !4!M"  !2#M$  %M&  'M(  )M0  1M2  !43M4  5M6  7M8  !29M:  ;M<  =M>  ?M@  AMB  !2CMD  EMF  GMH  !2IMJ  KML  !1MMN  OMP  QMR  !2SMT  !1UMV  !1WMX  YMZ  [M\  !1]M^  !2_M`  !2aMb  cMd  eMf  gMh  iMj  kMl  !1mMn  oMp  qMr  !2sMt  uMv  !1wMx  yMz  !2{M|  !1}MD  EMF  GMH  IMJ  KML  !4MMN  !2OMP  QMR  !1SMT  !1UMV  WMX  !1YMZ  [M\  !1]M^  !4_M`  !2aMb  !1cMd  !1eMf  !1gMh  iMj  kMl  mMn  oMp  qMr  !2sMt  !2uMv  !2wMx  !2yMz  {M|  }M~  M@  AMB  CMD  !2EMF  GMH  !2IMJ  !1KML  !1MMN  OMP  QMR  !1SMT  !2UMV  WMX  !2YMZ  !2[M\  !1]M^  _M`  !4aMb  cMd  eMf  gMh  iMj  kMl  mMn  oMp  qMr  sMt  uMv  wMx  yMz  {M|  }M~  M@  AMB  CMD  EMF  GMH  IMJ  KML  MMN  OMP  QMR  SMT  UMV  WMX  YMZ  [M\  ]M^  _M`  aMb  cMd  eMf  gMh  iMj  kMl  mMn  oMp  qMr  sMt  uMv  wMx  yMz  {M|  }M~  M@  AMB  CMD  EMF  GMH  IMJ  KML  MMN  OMP  QMR  SMT  UMV  WMX  YMZ  [M\  ]M^  _M`  aMb  cMd  eMf  gMh  iMj  kMl  mMn  oMp  qMr  sMt  uMv  wMx  yMz  {M|  }M~  M@  AMB  CMD  EMF  GMH  IMJ  KML  MMN  OMP  QMR  SMT  UMV  WMX  YMZ  [M\  ]M^  _M`  aMb  cMd  eMf  gMh  iMp  qMr  !2sMt  !2uMv  !2wMx  !2yMz  !2{M|  }M~  !2M@  AMB  CMD  EMF  GMH  !2IMJ  KML  MMT  UMV  !1WMX  YMZ  [M\  ]M^  !2_M`  !2aMb  !2cMd  !2eMf  !2gMh  iMj  !2kMl  mMn  oMp  !1qMr  !2sMt  !2uMv  wM~  M@  AMH !/IMJ !*KML !+MMN !*OMP !*QMR !*SMT !*UMV !"3WMX !*YMZ !"3[M\ !/]M^ !/_M` !"3aMb !*cMd !*eMf !*gMh !,iMj !*kMl !/mMn !*oMp !/qMr !*sMt !*uMv !"3wMx !"3yMz !"3{M| !/}M~ !"3M@	 !"3A	MB	 !"3C	MD	 !/E	MF	 !)G	MH	 !"3I	MJ	 !"3K	ML	 !"3M	MN	 !"3O	MP	 !"2Q	MR	 !"3S	MT	 !"3U	MX	 !"3Y	MZ	 !"3[	M\	 !"3]	M^	 !"2_	M`	 !"3a	Mb	 !"3c	Md	 !"3e	Mf	 !"2g	Mj	 !"3k	Ml	 !"3m	Mn	 !"3o	Mp	 !"2q	Mr	 !"3s	Mt	 !"3u	M~	 !*	M@
 #-"-"3"3"1"1 #-",%8%8Y
MOb
  g  !1	g
  g  !1g  g  !4g  !1g  g  g  g  g  g$  %g&  !2'g(  !1)g*  !2+g,  !2-g.  /g0  !91g2  3g4  5g6  !27g8  !29g:  ;g<  !2=g>  !2?gF  GgH  IgJ  KgL  MgN  OgP  QgR  SgT  !2UgV  WgX  !2YgZ  [g\  !2]g^  !2_g`  agb  cgd  !1egf  ggh  igj  !1kgl  !1mgn  ogp  qgr  sgt  !2ugv  !2wgx  !2ygz  {g|  !2}g~  g@  AgB  CgD  EgF  GgH  IgJ  !2KgL  !2MgN  !2OgP  !2QgR  SgT  UgV  !1WgX  !1YgZ  !1[g\  !1]g^  !1_g`  !2agb  !2cgd  egf  ggh  !1igj  !1kgl  !1mgn  !1ogv  !1wgx  !1ygz  !2{g|  !2}g~  !2g@  !2AgB  CgD ",!+!+!+!0MgiV  8  !1	8
  !18  8  !48  8  8  8  8  !28   !2!8"  !2#8$  %8&  !9'8(  )8*  +8,  -8.  !2/80  182  !2384  !258<  =8>  ?8@  A8B  !1C8D  !1E8F  G8H  I8J  !2K8L  !2M8N  !2O8P  Q8R  S8T  U8V  W8X ",!+!1!1!1!+!2!2!+!1!1!2o8:x  |  	|
  |  |  |  !2|  |  |  |  |  |  |  |   !|(  )|*  !2+|,  !2-|4  5|F  G|H  I|J  K|L  M|N  O|P  Q|R  S|V  W|X  Y|Z  [|\  ]|^  _|`  a|b  c|d  e|f  g|h  i|j  k|l  m|n  o|p  q|r  s|x  y|z  {||  }|~  |@  A|B  C|D  E|F  G|H  I|J  K|L  M|N  O|P  Q|R  S|T  U|V  W|X  Y|Z  [|\  ]|^  _|`  a|b  c|d  e|f  g|j  k|l  m|n  o|p  q|r  s|t  u|v  w|x  y|z  {||  }|~  |@  A|B  C|D  E|F  G|H  I|J  K|L  M|N  O|P  Q|R  S|T  U|V  W|X  Y|Z  [|\  ]|^  _|`  a|b  c|d  e|f  g|h  i|j  k|l  m|n  o|p  q|r  s|t  u|v  w|x  y|z  {||  }|~  |@  A|B  C|D  E|F  G|H  I|J  K|L  M|N  O|P  Q|R  S|T  U|V  W|X  Y|Z  [|\  ]|^  _|`  a|b  c|d  e|f  g|h  i|j  k|l  m|n  o|p  q|r  s|t  u|v  w|x  y|z  {||  }|~  |@  A|B  C|D  E|F  G|H  I|J  K|L  M|N  O|P  Q|R  S|T  U|V  W|X  Y|Z  [|\  ]|^ "/ #0"/"/"/"/"/"/"/"/w|~@  y  	y
  y  !1y  !2y  y  !1y  y  y  y  y  !1y  y   !y"  #y$  %y&  'y(  )y*  +y,  -y.  /y6  7y8  9y:  ;y<  =y>  ?y@  AyB  CyD  EyF  GyH  IyJ  KyL  MyN  OyP  QyR  SyT  UyV  WyX  YyZ  [y\  ]y^  _y`  ayb  cyd  eyf  gyh  iyj  kyl  myn  oyp  qyx  yyz  !2{y|  }y~  !2y@  !2AyB  CyD  EyF  GyH  !1IyJ  !9KyL  MyN  OyP  !2QyR  !2SyT  UyV  !2WyX  !2Yy`  ayb  cyd  eyf  gyh  iyj  kyl  myn  oyp  qyr  syt  uyv  wyx  yyz  {y|  }y~  y@  AyB  CyD  EyF  GyH  IyJ  KyL  MyN  OyP  QyR  SyT  UyV  WyX  YyZ  [y\  ]y^  _y`  ayb  cyd  eyf  gyh  iyj  kyl  myn  oyp  qyr  syt  uyv  wyx  yyz  {y|  !1}y~  !1y@  AyB  CyD  EyF  GyH  IyJ  KyL  MyN  OyP  QyR  SyT  UyV  WyX  YyZ  [y\  !2]y^  _y`  ayb  cyd  !2eyf  !2gyh  iyj  kyl  !1myn  oyp  qyr  syt  uyv  wyx  yyz  !1{y|  !1}y~  y@  AyB  CyD  !2EyF  !2GyH  IyJ  KyL  MyN  OyP  !9QyR  SyT  !9UyV  WyX  !2YyZ  [y\  ]y^  _y`  ayb  cyj  !1kyl  !1myn  oyp  !2qy{$xY
 _Y _Y 0Y .Y .Y _Y ^Y _Y ZY \Y .Y  Z!Y" Z#Y$ \%Y& 0'Y( Z)Y* Z+Y, Z-Y. Z/Y0 Z1Y2 Z3Y4 Z5Y6 Y7Y8 Z9Y: _;Y< Z=Y> Z?Y@ ZAYB ZCYD ZEYF ZGYH ZIYJ YKYL 0MYN ZOYP ZQYR ZSYZ \[Y\ ]]Y^ ]_Y` 0aYb 0cYj \kYl ZmYn ZoYp ZqYr ZsYt ZuYv ZwYx ZyYz Z{Y| Z}Y~ ZY@ ZAYB ZCYD ZEYF ZGYH ZIYJ ZKYL ZMYN ZOYP .QYR ZSYT ZUYV ZWYX ZYYZ Z[Y\ Z]Y^ Z_Y` ZaYb ZcYd ZeYf ZgYh ZiYj .kYl ZmYn ZoYp .qYr .sYt .uYv .wYx ZyYz .{Y| .}Y~ .Y@ ZAYB .CYD ZEYF 0GYH 0IYJ ZKYL .MYN ZOYP .QYR ZSYT .UYV .WYX ZYYZ .[Y\ Z]Y^ Z_Y` ZaYb ZcYd ZeYf ZgYh ZiYj 5kYt iuYv jwYx jyYz j{Y| j}Y~ jY@ jAYB /CYD jEYL 3MMYN )/OYP FGWQYR -.ASYT 78PUYV <=UWYX >?WYYZ MN_[Y\ 78H]Y^ CDT_Y` 12BaYb (cYd ABSeYf ?@PgYh ?
iYj TU_kYl PQbmYn BCSoYp EFVqYv 3C$.W Os/I(B
 I( I(	    NtypesubTypec                     ||dk(  S |dk(  S )Nr  r   rl  rp  rq  s      rn  
is_inversezbinance.is_inverse6
  s    ?:%&i''ro  c                 (    ||dk(  xs |dk(  S |dk(  S )Nr[   rZ   r  rs  rt  s      rn  	is_linearzbinance.is_linear<
  s&    ?8#88h&&ro  enablec                 J    t         t        |   |       || j                  d<   y )Nr  )rh  rK   set_sandbox_moder  )rl  rx  rm  s     rn  rz  zbinance.set_sandbox_modeB
  s     gt-f5&,]#ro  symbolc                    d}|j                  d      }|j                  d      }d }|j                  d      dkD  r| j                  |d      }n| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	| j	                  |      }
| j                  |
      }i d	|dz   |z   dz   |z   dz   |	z   d
|dz   |z   dz   |z   dz   |z   dz   |z   dz   |	z   d|d|d|d|dd dddd dd dddddddddddddd ||
|	dk(  rdnd|||d d d d d d!d d d!d d d!d"d d#	S )$NUSDT-/r   r  r  r;  rN   r{  :r  r  baseIdquoteIdactiverp  r\   r  r  rX   FrZ   r[   TrY   contractcontractSizeCcallrJ  )amountpriceminrK  )r  r  r%  )	expiryexpiryDatetime
optionTypestrikesettlesettleIdr  limitsinfo)splitfindsafe_stringsafe_integerconvert_expire_date	parse8601)rl  r{  r  optionParts
symbolBaser  r  r  strikeAsStringr  datetime	timestamps               rn  create_expired_option_marketz$binance.create_expired_option_marketF
  sE   ll3'\\#&
;;sb ##J2D##K3D!!+q1"";2))+q9%%k15
++F3NN8,	+
$*v%+n<sBZO+
dSj6)C/&83>G#MP^^addgqq+
 D+
 V	+

 d+
 v+
 d+
 H+
 d+
 t+
 E+
 E+
 e+
 d+
 e+
  !+
" D#+
$  &%/3%6&U  
  
   U+
 +	
ro  c                    | j                   t        | j                  dz         | j                  | j                  d      }| j                  | j                  d      }|dk(  }|dk(  }|xs |}t        |t              rS|| j                   v rJ| j                   |   }|r7|d   r2|r|d   n|d   }|d	z   |z   }	|	| j                   v r| j                   |	   S |S || j                  v rJ| j                  |   }
|rd
}n	|rd}n||}t        dt        |
            D ]  }|
|   }||   s|c S  |
d   S |j                  d      dkD  rV|j                  d	      dk  rB|j                  d      \  }}|dk(  r|n|}|d	z   |z   }	|	| j                   v rH| j                   |	   S |j                  d      dkD  s|j                  d      dkD  r| j                  |      S t        | j                  dz   |z         )Nz markets not loadedr  r  r[   r  rX   r  r  r  r  r  r   r  r  r  -C-Pz does not have market symbol )marketsr0   rN   r  r  
isinstancestrmarkets_by_idrangelenr  r  r  r6   )rl  r{  r  r  isLegacyLinearisLegacyInverseisLegacyr  r  futuresSymbolr  ir  r  s                 rn  r  zbinance.market
  s   <<*? ?@@&&t||]C))$,,8HI$0%3!4_fc"%f-v0>VG_F6NF$*SL6$9M$4#||M::!M4---,,V4!"*K$"+K ("0Kq#g,/ &A$QZFk*%& qz!++c"R'fkk#.>.B$ll3/e"'5.u &v 5 DLL0<<66++d#b(fkk$.?".D88@@"AAFJKKro  marketIdr  	delimiter
marketTypec                     |d uxr* |j                  d      dkD  xs |j                  d      dkD  }|r|| j                  vr| j                  |      S t        t        |   ||||      S )Nr  r  r  )r  r  r  rh  rK   safe_market)rl  r  r  r  r  isOptionrm  s         rn  r  zbinance.safe_market
  sn    D(hd0Cb0H/ghmm\`NadfNfX););;44X>>Wd/&)ZXXro  c                     | j                  |t        | j                  |   d   d   | j                  | j                        S )Nr  r  )decimal_to_precisionrG   r  r  paddingMode)rl  r{  r%  s      rn  cost_to_precisionzbinance.cost_to_precision
  sK    ((xf9Mk9Z[b9ceiewewy}  zJ  zJ  K  	Kro  c                     | j                  | j                  |   d      =| j                  |t        | j                  |   d   | j                  | j
                        S | j                  |      S )Nr  )
safe_valuer  r  rG   r  r  number_to_string)rl  r  feenetworkCodes       rn  currency_to_precisionzbinance.currency_to_precision
  sq    ??4??40+>J,,S(DOOD<QR]<^`d`r`rtx  uE  uE  F  F((--ro  c                 B    | j                         | j                  d   z
  S )Nr  )millisecondsr  )rl  s    rn  noncezbinance.nonce
  s       "T\\2B%CCCro  c                    | j                  | j                  ddd      }| j                  |d|      }| j                  |d      }d}| j	                  dd|      \  }}d}| j                  ||      r| j                  |      }n5| j                  ||      r| j                  |      }n| j                  |      }| j                  |d      S )a  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#check-server-time          # spot
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Check-Server-Time    # swap
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Check-Server-time    # future

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :returns int: the current integer timestamp in milliseconds from the exchange server
        r   r  rX   rp  N
serverTime)safe_string_2r  r  omithandle_sub_type_and_paramsrw  fapiPublicGetTimeru  dapiPublicGetTimepublicGetTimer  )rl  paramsr  rp  queryrq  responses          rn  
fetch_timezbinance.fetch_time
  s     (({MSYZ<		&&)99+tVT>>$(--e4H__T7+--e4H))%0H  <88ro  c                    | j                  | j                  d      }|sy| j                  d      sy| j                  | j                  d      }|y| j                  |      g}| j                  | j                  dd      }|r |j                  | j                  |             |}|d   }d}|r|d   }	| j                  |	d      }i }
t        dt        |            D ]i  }||   }| j                  |d	      }| j                  |d
      }| j                  |      }| j                  |d      }d}d}d}| j                  |dg       }i }d}i }t        dt        |            D ]r  }||   }| j                  |d      }| j                  |      }|dk(  }| j                  |d      }| j                  |d      }| j                  |d      }|xs |}|xs |}|||<   | j                  |d      } | s||}| j                  |d      }!|!}"t!        j"                  |!d      s||!nt!        j$                  ||!      }nC|sA|s?| j'                  | j                  |d            }"|"| j                  | j                  d      }"||||xr ||||| j)                  |"      | j                  |d      | j                  |d      d| j                  |d      dddd	||<   u | j                  |d      }#|xr |xr |#}$| j+                  ||i       }%||||rdnd | j)                  |      ||$|||||| j,                  | j                  |%d!      d"|
|<   l |
S )#a~  
        fetches all available currencies on an exchange

        https://developers.binance.com/docs/wallet/capital/all-coins-info
        https://developers.binance.com/docs/margin_trading/market-data/Get-All-Margin-Assets

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r   NF	apiBackupr  r   r  	assetNamecoinrO   isLegalMoneyTnetworkListnetworkETFwithdrawFeedepositEnablewithdrawEnable	isDefaultwithdrawIntegerMultipler  withdrawInternalMinr,  withdrawMinwithdrawMaxr  depositDustr   deposit)	r  rN   r  r  r  r   r  r  r  r  fiatcryptoisBorrowable)rN   rO   r  rp  r  r  r  r  r   r'  r  r  r  rY   )	safe_boolr  check_required_credentialsr  r   sapiGetCapitalConfigGetallappendsapiGetMarginAllPairsindex_byr  r  r  safe_currency_code	safe_listnetwork_id_to_codesafe_numberrI   	string_eq
string_min	omit_zerorj  	safe_dictr  )&rl  r  fetchCurrenciesEnabledr  promisesr  resultsresponseCurrenciesmarginablesByIdresponseMarginablesresultr  entryrN   rO   r  isFiatminPrecisionisWithdrawEnabledisDepositEnabledr  r  r  r'  jnetworkItemr  r  isETFr  r  r  r  precisionTickwithdrawPrecisionr  r  marginEntrys&                                         rn  fetch_currencieszbinance.fetch_currencies
  s    "&>O!P%
 ..u5OODII{;	 33F;<~~dllNEJOOD66v>?$QZ")!*"mm,?MOq#012 {	A@ 'q)E!!%0B##E62D**2.D^^E>:FL $#..rBKDCH1c+./ 2)!n**;	B"55g> E)"..{MJ ${O L!%=M!N#3#D} $5$G! +W NN;D	%C
 !% 0 0>W X$1!((<5A5I=PWPbPbcoq~PL!% -1NN4;K;KKYn;o,p),4040@0@Oi0j-'!*+>, .&!%!2!23D!E $(#3#3K#O#'#3#3K#O%
 $(#3#3K#O#'$	)%?2f nnUI6G'H,<HF.."bAK "(h!..|< +-$++..nEF4LY{	x ro  c                    g }| j                  | j                  dg d      }| j                  | j                  dd      }|r#| j                  d|      s|j	                  d       | j                  | j                  dd      }g }t        dt        |            D ]   }||   }|dk(  r|r|j	                  |       " | j                  | j                  dd      }	t        dt        |            D ]  }||   }
|
d	k(  ry|j	                  | j                  |             |	s1| j                  d      sC|rF|j	                  | j                  |             |j	                  | j                  |             |
d
k(  r!|j	                  | j                  |             |
dk(  r!|j	                  | j                  |             |
dk(  r!|j	                  | j                  |             t        | j                  dz   |
z   dz          |}g }g | j                  d<   g | j                  d<   t        dt        |            D ]  }| j!                  ||      }|	rvt#        |t$              rft%        | j'                  |d      j)                               }t        | j                  d         }|dk(  r|| j                  d<   }|| j                  d<   | j+                  |ddg       }| j-                  ||      } | j                  d   r| j/                          g }t        dt        |            D ]%  }|j	                  | j1                  ||                ' |S )a  
        retrieves data on all markets for binance

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#exchange-information           # spot
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Exchange-Information     # swap
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Exchange-Information     # future
        https://developers.binance.com/docs/derivatives/option/market-data/Exchange-Information                             # option
        https://developers.binance.com/docs/margin_trading/market-data/Get-All-Cross-Margin-Pairs                           # cross margin
        https://developers.binance.com/docs/margin_trading/market-data/Get-All-Isolated-Margin-Symbol                       # isolated margin

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r   r  r  Fr\   r  r   r  rX   r  r  z+ fetchMarkets() self.options fetchMarkets "z " is not a supported market typecrossMarginPairsDataisolatedMarginPairsDatar{  symbolsoptionSymbolsr  )r  r  r  in_arrayr  r  r  publicGetExchangeInfor  r  sapiGetMarginIsolatedAllPairsfapiPublicGetExchangeInfodapiPublicGetExchangeInfoeapiPublicGetExchangeInfor0   rN   r  r  listr  keyssafe_list_2array_concatload_time_differenceparse_market)rl  r  promisesRawrawFetchMarketsr  r  r   r  rp  r  r  r  r  reskeysListlengthresultMarketsr  s                     rn  fetch_marketszbinance.fetch_markets  s#    ..~Gde6FN==?;&&x0nnT\\=%Hq#o./ 	&A"1%DxK%		&
 ~~dllNEJq#l+, 	OA%aJV#""4#=#=f#EFD$C$CE$JS^&&t'A'A&'IJ&&t'I'I&'QRx'""4#A#A&#IJy(""4#A#A&#IJx'""4#A#A&#IJ#DGG.[$[^h$h  lN  %N  O  O	O /1+,24./q#g,' 	DA//'1-C
3 5c8 < A A CDT\\*@ABQ;;CDLL!78>FDLL!:; $ 0 0iRT U++G]C	DJ <<12%%'q#g,' 	9AMM$++GAJ78	9ro  c                    d}d}d}| j                  |d      }| j                  |d      }|j                  d      }| j                  |d      }| j                  |d      }	| j                  |d|      }
| j                  |d      }| j                  |
      }| j                  |      }| j                  |d      }d|v }| j	                  |d	d
      }| j                  |d      }|dk(  s|dk(  rd }d}n|d}d}|dn|}n|d}| j                  |      }| }| j                  |dg       }| j                  |d      }| j                  |dd      }d }| j                  }d }d }|dz   |z   }d }|r|r	|dz   |z   }n|r|dz   |z   dz   | j                  |      z   }nk|ri| j                  | j                  | j                  |d                  }|dz   |z   dz   | j                  |      z   dz   |z   dz   | j                  |d      z   }| j                  |dd| j                  d            }||k(  }||k(  }|rdnd}| j                  | j                  |i       }|dk(  }|r9| j                  |dg       }t        dt!        |            D ]  } ||    dk(  sd} n | j#                  |d d      }!d }"|rD| j%                  || j&                  d!         }#| j%                  || j&                  d"         }$|#|$d#}"n	|s|rddd#}"d }%|rd$}%n|rd%}%n|rd&}%n|rd'}%d }d }&|| j                  |      }&i d(|d)|	d|d*|d+|d,|d-|
d.|d/|d0|%d$|d1|xr |!d2|"d%|d&|d'|d3|||||d4   d5   |d4   d6   ||| j)                  |      |&| j                  |d7      | j                  | j+                  | j                  |d8d9                  | j                  | j+                  | j                  |d:d;                  | j                  | j+                  | j                  |d<                  | j                  | j+                  | j                  |d=                  d>d d d?| j-                  |d@      | j-                  |dA      d?d d d?d d d?dB|| j/                  |dC      dD}'dE|v rV| j                  |dEi       }(| j-                  |(dF      | j-                  |(dG      d?|'dH   dI<   | j-                  |(dJ      |'dK   dI<   dL|v rV| j                  |dLi       }(| j-                  |(dM      |'dK   dN<   | j-                  |(d@      | j-                  |(dA      d?|'dH   dN<   dO|v r>| j                  |dOi       }(| j-                  |(d@      | j-                  |(dA      d?|'dH   dP<   dQ|v sdR|v rK| j1                  |dQdRi       }(| j                  |(dSdT      |'dH   dU   dV<   | j-                  |(dW      |'dH   dU   dX<   |'S )YNF
underlyingr{  r~  r   	baseAsset
quoteAssetcontractTypedeliveryDate
expiryDatemarginAsset	PERPETUALl    t?D	Tr}  filters
filterTypestatuscontractStatusr  r  strikePricer;  r  unit1r  r  TRADINGpermissionsTRD_GRP_003isMarginTradingAllowedr  r  )r  isolatedrX   rZ   r[   r\   rN   lowercaseIdr  r  r  r  r  r  rp  rY   marginModesr  r  r  r  sidequantityPrecisionquantityScalepricePrecision
priceScalebaseAssetPrecisionquotePrecision)r  r  r  r  r  minQtymaxQty)r  r  r  r%  onboardDate)r  r  r  r  r  r  r  r  r  r  r  r  r  createdPRICE_FILTERminPricemaxPricer  r  tickSizer  LOT_SIZEstepSizer  MARKET_LOT_SIZEr  MIN_NOTIONALNOTIONALminNotionalnotionalr%  r  maxNotionalrK  )r  r  safe_string_lowerr  safe_integer_2r  r  r  r  yymmddr  parse_to_numericsafe_number_2rj  r  r  r  r  r
  r  iso8601parse_precisionr  r  safe_dict_2))rl  r  rZ   r[   r\   r  rN   r  
optionBaser2  r  r  r  r  r!  r  r  r  r  rX   r&  filtersByTyper(  r  r  r  r  r{  r  feesTyper  r.  r  r0  r3  hasCrossMarginhasIsolatedMarginunifiedTypeparsedStriker  filters)                                            rn  r  zbinance.parse_market  s   %%fl;
fh/hhsm%%k15
,,VX>!!&+zB""6<8&&v.''0''?"f,$$V^\J##FM:K'V}-DFD#HF"*"2vHF((2|..B7g|<##FH6FGyye##.#.4t{{67JJ..t/D/DTEUEUV\^kEl/mn#.4t{{67JJSPSYY\__bfbrbrs~  AB  cC  C--fnfdN_N_`cNdeLu_FnG#)xyH>>$))Xr:DI%..CK1c+./ q>]2"F "&8PRW!X!]]2t||<R/STN $b$,,?X2Y Z'-K w K  K K"K"KF008L6
"6
;6
 f6
 D	6

 U6
 f6
 f6
 w6
 6
 K6
 D6
 d556
 ;6
 D6
 f6
  f!6
" f#6
$ !)_W-)_W-("ll62"00@++D,@,@ASASTZ\o  rA  BB  -C  D**4+?+?@R@RSY[kmy@z+{|))$*>*>t?O?OPVXl?m*no**4+?+?@P@PQWYi@j+kl	  
  ++FH=++FH=
  
  $ ((?k6
n ]*^^M>2FF ''
;''
;(E(OG$ +/*:*:6:*NE+w'&^^M:rBF+/+;+;FJ+OE+x(''9''9)E(OH% -^^M3DbIF''9''9)E(OH% m+}1L%%m^ZQSTF-1-?-?Wa-bE(OF#E*-1-=-=fm-TE(OF#E*ro  c                     | j                         }| j                  |d      |d<   | j                  |d      |d<   | j                  |d      }| j                  |d      }t        j                  ||      |d<   |S )Nlockedusedfreeinterestborroweddebt)rt  r  rI   
string_add)rl  r  rt  r_  ra  s        rn  parse_balance_helperzbinance.parse_balance_helper  sx    ,,.**5(;**5&9##E:6z2!,,T8<ro  Fc                    d|i}d }|dk(  }|dk(  xs |dk(  }|rt        dt        |            D ]  }	||	   }
| j                         }| j                  |
d      }| j	                  |      }|dk(  r,| j                  |
d      |d	<   | j                  |
d
      |d<   n|dk(  r+| j                  |
d      |d	<   | j                  |
d      |d<   n|r}| j                  |
d      }| j                  |
d      }t        j                  ||      |d<   | j                  |
d      |d	<   | j                  |
d      |d<   | j                  |
d      |d<   ne| j                  |
d
      }| j                  |
d      }t        j                  ||      }| j                  |
d      }t        j                  ||      |d<   |||<    n|s|dk(  s|r| j                  |d      }| j                  |ddg       }t        dt        |            D ]  }	||	   }| j                  |d      }| j	                  |      }| j                         }| j                  |d	      |d	<   | j                  |d      |d<   |r=| j                  |d      }| j                  |d      }t        j                  ||      |d<   |||<    n|r| j                  |d      }t        dt        |            D ]  }	||	   }| j                  |d      }| j                  |d d d      }| j                  |d i       }| j                  |d!i       }| j	                  | j                  |d            }| j	                  | j                  |d            }i }| j                  |      ||<   | j                  |      ||<   | j                  |      ||<    n|d"k(  r| j                  |d#g       } t        dt        |             D ][  }	| |	   }
| j                  |
d      }| j	                  |      }| j                         }| j                  |
d$      }!|!|d<   |!|d<   |||<   ] n|d%k(  rt        dt        |            D ]  }	||	   }
| j                         }| j                  |
d      }| j	                  |      }| j                  |
d	      |d	<   | j                  |
d&      }"| j                  |
d'      }#| j                  |
d      }$t        j                  |"t        j                  |$|#            |d<   |||<    n|}t        |t              s| j                  |dg       }t        dt        |            D ]  }	||	   }| j                  |d      }| j	                  |      }| j                         }| j                  |d(      |d	<   | j                  |d)      |d<   | j!                  |d*d+      |d<   |||<    ||d,<   | j#                  |      |d-<   |r|S | j                  |      S ).Nr  r1  rY   r  r   assetr  umWalletBalancer^  umUnrealizedPNLr]  r  cmWalletBalancecmUnrealizedPNLcrossMarginBorrowedcrossMarginInterestra  crossMarginFreecrossMarginLockedcrossMarginAssettotaltotalWalletBalancerX   
updateTimebalances
userAssetsr\  r`  r_  assetsr{  r  r   savingspositionAmountVosr  r  freezewithdrawingavailableBalanceinitialMarginmarginBalancers  r  r  )r  r  rt  r  r  rI   rb  r  r  r  safe_symbolr  rc  safe_balancer  r  r  rP  )%rl  r  rp  r6  isPortfolioMarginr  r  r1  r  r  r  rt  
currencyIdr  r`  r_  
usedLinearusedInverse	totalUsedrp  rr  rs  ra  rt  re  r  r{  r  r  baseCode	quoteCode	subResultrv  usedAndTotalfrozenrx  r\  s%                                        rn  parse_balance_customzbinance.parse_balance_custom  sI   H
 	+!=zW'<1c(m, ' ,,.!--eW=
..z:8#&*&6&6u>O&PGFO&*&6&6u>O&PGFOY&&*&6&6u>O&PGFO&*&6&6u>O&PGFO#//7LMH#//7LMH&-&8&88&LGFO&*&6&6u>O&PGFO&*&6&6u>Q&RGFO'+'7'7?Q'RGG$!%!1!1%9J!KJ"&"2"25:K"LK ' 2 2:{ KI)-)9)9%AU)V&'.'9'9)EW'XGG$&t1'2 5))(LAI''*lBOH1c(m, '"1+!--gw?
..z:,,."&"2"27F"C"&"2"27H"E++GZ@D#//DH&-&8&8x&HGFO&t' ^^Hh7F1c&k* >q	++E8<))(D$G~~e["=ulB?2243C3CD'3RS 33D4D4DUG4TU	"$	&*&?&?&E	(#'+'@'@'G	)$!%!2!29!=v> Y $x9Lb Q1c"345 ')!,!--eW=
..z:,,.#//x@#/ ".&t' Y1c(m, 
' ,,.!--eW=
..z:"&"2"25&"A))%:"..umD))%:")"4"4VW=O=OPVXc=d"e&t
'  Hh->>(HbA1c(m, '"1+!--gw?
..z:,,."&"2"27<N"O"&"2"27O"L#'#5#5gPY#Z &t' ({!\\)4z!v@t'8'8'@@ro  c                    | j                          | j                  | j                  ddd      }| j                  |d|      }d}| j	                  dd|      \  }}d}| j                  |dddd      \  }}d}d}| j                  d|      \  }}| j                  |d      }d}i }	|s|dk(  rN| j                  ||      rd	}n| j                  ||      rd
}d}| j                  | j                  |	|            }n| j                  ||      rUd	}d}
| j                  |ddd      \  }
}| j                  |	|      }|
s| j                  |      }n| j                  |      }n| j                  ||      r%d
}| j                  | j                  |	|            }nN|dk(  r| j!                  |d      }| j                  |d      }|fd}t#        |t$              rM| j'                  |d         }t)        dt+        |            D ]   }||   }| j'                  |      }|d|z   z  }" n|}||	d<   | j-                  | j                  |	|            }n|dk(  s|dk(  r"| j/                  | j                  |	|            }no|dk(  r"| j1                  | j                  |	|            }nH|dk(  r"| j3                  | j                  |	|            }n!| j5                  | j                  |	|            }| j7                  ||||      S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#account-information-user_data  # spot
        https://developers.binance.com/docs/margin_trading/account/Query-Cross-Margin-Account-Details                       # cross margin
        https://developers.binance.com/docs/margin_trading/account/Query-Isolated-Margin-Account-Info                       # isolated margin
        https://developers.binance.com/docs/wallet/asset/funding-wallet                                                     # funding
        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Futures-Account-Balance-V2   # swap
        https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Futures-Account-Balance      # future
        https://developers.binance.com/docs/derivatives/option/account/Option-Account-Information                           # option
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/Account-Balance                            # portfolio margin

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: 'future', 'delivery', 'savings', 'funding', or 'spot' or 'papi'
        :param str [params.marginMode]: 'cross' or 'isolated', for margin trading, uses self.options.defaultMarginMode if not passed, defaults to None/None/None
        :param str[]|None [params.symbols]: unified market symbols, only used in isolated margin mode
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch the balance for a portfolio margin account
        :param str [params.subType]: 'linear' or 'inverse'
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        r}   r  rX   rp  Nr  re  Fr  r  TuseV2r1  r   r   r  ,rY   r  ru  r  )load_marketsr  r  r  r  handle_option_and_params_2handle_margin_mode_and_paramsr  rw  ru  papiGetBalanceextendhandle_option_and_paramsfapiPrivateV3GetAccountfapiPrivateV2GetAccountdapiPrivateGetAccountr  r  r  	market_idr  r  sapiGetMarginIsolatedAccountsapiGetMarginAccountsapiGetLendingUnionAccountsapiPostAssetGetFundingAssetprivateGetAccountr  )rl  r  r  rp  rq  r~  r6  r  r  requestr  paramSymbolsr  r  r{  rN   s                   rn  fetch_balancezbinance.fetch_balance  s   * 	((~}V\]<99.$PVW $($C$CFN\bduw|$}!6
 >>~vV
E		%(~~dG,w/  $**4;;w+FGH^^D'*DE 99&.RY[`aME6[[%0F77?77?__T7+D11$++gu2MNH:%>>&)<LIIeY/E'lD1"nn\!_=G"1c,&78 ,!-a!^^F338+,
 +G%,	"88We9TUHhJ'$900We1LMHY66t{{7E7RSHY88We9TUH--dkk'5.IJHj ((4EVWWro  r  c                 
   | j                          | j                  |      }d|d   i}|||d<   d}|d   r"| j                  | j                  ||            }no|d   r"| j	                  | j                  ||            }nH|d   r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |d      }| j                  |||      }| j                  |d	d
      |d<   |S )a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#order-book     # spot
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Order-Book   # swap
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Order-Book   # future
        https://developers.binance.com/docs/derivatives/option/market-data/Order-Book                           # option

        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        r{  rN   Nr  r\   r  r  TlastUpdateIdur  )
r  r  eapiPublicGetDepthr  fapiPublicGetDepthdapiPublicGetDepthpublicGetDepthr  parse_order_bookrL  )	rl  r{  r  r  r  r  r  r  	orderbooks	            rn  fetch_order_bookzbinance.fetch_order_book  s    	V$fTl
 $GG(..t{{7F/KLHH..t{{7F/KLHI..t{{7F/KLH**4;;w+GHHJ %%h4	))(FIF	!00>3O	'ro  r  c           
         | j                  |dd      }d }d|v rd}|d|v rdnd}| j                  |d      }| j                  ||d |      }| j                  |d      }| j                  |d      }d	|v }	d }
d }|	r)| j                  |d	      }
t        j                  |
|      }n%| j                  |d
      }
| j                  |dd      }| j                  i d|d|d| j                  |      d| j                  |dd      d| j                  |dd      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d|d| j                  |dd      d|d|d| j                  |d       d!| j                  |d"      d#| j                  |d$      d%d |
|| j                  |d&      | j                  |d'      |d(|      S ))N	closeTimerM  r  bidQtyrX   r{  	lastPriceweightedAvgPrice
baseVolumevolumequoteVolumer  r  r  high	highPricelowlowPricebidbidPrice	bidVolumeaskaskPrice	askVolumeaskQtyvwapopen	openPricecloserI  previousCloseprevClosePricechangepriceChanger  priceChangePercentaverage	markPrice
indexPrice)r  r  r  r  r  )rL  r  r|  rI   
string_mulr  safe_tickerrP  )rl  r  r  r  r  r  r{  rI  wAvgisCoinmr  r  s               rn  parse_tickerzbinance.parse_ticker=  s   h ''VD	
f#J$,$6ZJ##FH5!!(FD*E4(:;6)
))&,?J!,,Z>K))&(;J,,V]HMK !
f!
!
 Y/!
 D&&v{FC	!

 4%%fj%@!
 4##FJ7!
 ))&(;!
 4##FJ7!
 ))&(;!
 D!
 D&&v{FC!
 T!
 D!
 T--f6FG!
 d&&v}=!
  $**63GH!!
" t#!
$ %&))&+>**6<@-!
. / 	ro  c                     | j                  |      }| j                  |d      }| j                  ddd||      ddd|dS )aY  
        the latest known information on the availability of the exchange API

        https://developers.binance.com/docs/wallet/others/system-status

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
        r(  okmaintenance)r  r,  N)r(  updatedetar  r  )sapiGetSystemStatusr  )rl  r  r  	statusRaws       rn  fetch_statuszbinance.fetch_status  sV     ++F3 $$Xx8	&&T'F	S\]
 	
ro  c                    | j                          | j                  |      }d|d   i}d}|d   r"| j                  | j                  ||            }n|d   r"| j	                  | j                  ||            }n|d   r"| j                  | j                  ||            }nj| j                  |dd      }| j                  |d      }|r"| j                  | j                  ||            }n!| j                  | j                  ||            }t        |t              r%| j                  |d	i       }| j                  ||      S | j                  ||      S )
a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#24hr-ticker-price-change-statistics     # spot
        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#rolling-window-price-change-statistics  # spot
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/24hr-Ticker-Price-Change-Statistics   # swap
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/24hr-Ticker-Price-Change-Statistics   # future
        https://developers.binance.com/docs/derivatives/option/market-data/24hr-Ticker-Price-Change-Statistics                           # option

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.rolling]:(spot only) default False, if True, uses the rolling 24 hour ticker endpoint /api/v3/ticker
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r{  rN   Nr\   r  r  rollingFr   )r  r  eapiPublicGetTickerr  fapiPublicGetTicker24hrdapiPublicGetTicker24hrr  r  publicGetTickerpublicGetTicker24hrr  r  r  r  )rl  r{  r  r  r  r  r  firstTickers           rn  fetch_tickerzbinance.fetch_ticker  s;    	V$fTl
 (//GV0LMHH33DKK4PQHI33DKK4PQHnnVY>GYYvy1F//GV0LM33DKK4PQh%..1b9K$$[&99  622ro  r  c                 ^   | j                          | j                  |dddd      }| j                  |      }d}| j                  d||      \  }}d}| j	                  d||      \  }}d}| j                  ||      r| j                  |      }n| j                  ||      r| j                  |      }nl|dk(  rIi }|#| j                  | j                  |            |d<   | j                  | j                  ||            }nt        | j                  dz   |z   dz         | j                  ||      S )ac  
        fetches the bid and ask price and volume for multiple markets

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#symbol-order-book-ticker   # spot
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Symbol-Order-Book-Ticker  # swap
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Symbol-Order-Book-Ticker  # future

        :param str[]|None symbols: unified symbols of the markets to fetch the bids and asks for, all markets are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        NTr~   rX   r  z" fetchBidsAsks() does not support  markets yet)r  market_symbolsget_market_from_symbolshandle_market_type_and_paramsr  rw  fapiPublicGetTickerBookTickerru  dapiPublicGetTickerBookTickerjson
market_idspublicGetTickerBookTickerr  r?   rN   parse_tickersrl  r  r  r  rp  rq  r  r  s           rn  fetch_bids_askszbinance.fetch_bids_asks  s2    	%%gtT4F--g699/6SYZf99/6SYZ>>$(99&AH__T7+99&AHV^G"%)YYtw/G%H	"55dkk'66RSHtww)MMPTTWeeff!!(G44ro  c                    | j                          | j                  |dddd      }| j                  |      }d}| j                  d||      \  }}d}| j	                  d||      \  }}d}| j                  ||      r| j                  |      }nY| j                  ||      r| j                  |      }n5|dk(  r| j                  |      }nt        | j                  dz   |z   dz         | j                  ||      S )a  
        fetches the last price for multiple markets

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#symbol-price-ticker    # spot
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Symbol-Price-Ticker  # swap
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Symbol-Price-Ticker  # future

        :param str[]|None symbols: unified symbols of the markets to fetch the last prices
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a dictionary of lastprices structures
        NTr   rX   z$ fetchLastPrices() does not support r  )r  r  r  r  r  rw  fapiPublicV2GetTickerPriceru  dapiPublicGetTickerPricepublicGetTickerPricer?   rN   parse_last_pricesrl  r  r  r  rp  rq  r  s          rn  fetch_last_priceszbinance.fetch_last_prices@  s    	%%gtT4F--g699:KVU[\f99:KVU[\>>$(66v>H __T7+44V<H V^008H tww)OORVVYgghh%%h88ro  c                     | j                  |d      }|dnd}| j                  |d      }| j                  ||d |      }|d   || j                  |      | j	                  |d      d |dS )NrM  rX   rZ   r{  r  )r{  r  r  r  r4  r  )r  r  r  rP  safe_number_omit_zero)rl  r  r  r  rp  r  s         rn  parse_last_pricezbinance.parse_last_price|  s    6 %%eV4	#+v&##E84!!(FD$?X&"Y///w?
 	
ro  c                    | j                          | j                  |dddd      }| j                  |      }d}| j                  d||      \  }}d}| j	                  d||      \  }}d}| j                  ||      r| j                  |      }n| j                  ||      r| j                  |      }n|dk(  rIi }|#| j                  | j                  |            |d<   | j                  | j                  ||            }n5|dk(  r| j                  |      }nt        | j                  dz   |z   dz         | j!                  ||      S )	a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#24hr-ticker-price-change-statistics    # spot
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/24hr-Ticker-Price-Change-Statistics  # swap
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/24hr-Ticker-Price-Change-Statistics  # future
        https://developers.binance.com/docs/derivatives/option/market-data/24hr-Ticker-Price-Change-Statistics                          # option

        :param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :param str [params.type]: 'spot', 'option', use params["subType"] for swap and future markets
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        NTr   rX   r  r\   z! fetchTickers() does not support r  )r  r  r  r  r  rw  r  ru  r  r  r  r  r  r  r?   rN   r  r  s           rn  fetch_tickerszbinance.fetch_tickers  sI    	%%gtT4F--g699.&RXYf99.&RXY>>$(33F;H__T7+33F;HV^G"%)YYtw/G%H	"//GV0LMHX//7Htww)LLtSVddee!!(G44ro  c                 P   | j                          | j                  |      }d}| j                  d||d      \  }}d}| j                  d||d      \  }}d|d   i}d}| j	                  ||      r"| j                  | j                  ||            }nR| j                  ||      r"| j                  | j                  ||            }nt        | j                  dz   |z   dz         t        |t              r#| j                  | j                  |d	i       |      S | j                  ||      S )
ak  
        fetches mark price for the market

        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-and-Mark-Price
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nr   rZ   r  r{  rN   z# fetchMarkPrice() does not support r  r   )r  r  r  r  rw  fapiPublicGetPremiumIndexr  ru  dapiPublicGetPremiumIndexr?   rN   r  r  r  r  )rl  r{  r  r  rp  rq  r  r  s           rn  fetch_mark_pricezbinance.fetch_mark_price  s)    	V$99:JFTZ\bcf99:JFTZ\defTl
 >>$(55dkk'66RSH__T7+55dkk'66RSHtww)NNQUUXffggh%$$T^^Ha%DfMM  622ro  c                    | j                          | j                  |dddd      }| j                  |      }d}| j                  d||d      \  }}d}| j	                  d||d      \  }}d}| j                  ||      r| j                  |      }nB| j                  ||      r| j                  |      }nt        | j                  dz   |z   dz         | j                  ||      S )a  
        fetches mark prices for multiple markets

        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-and-Mark-Price
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price

        :param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        NTr   rZ   r  z$ fetchMarkPrices() does not support r  )r  r  r  r  r  rw  r  ru  r  r?   rN   r  r  s          rn  fetch_mark_priceszbinance.fetch_mark_prices  s     	%%gtT4F--g699:KVU[]cdf99:KVU[]ef>>$(55f=H__T7+55f=Htww)OORVVYgghh!!(G44ro  c           
         | j                  |d      }|rdnd}| j                  |dd      | j                  |dd      | j                  |dd	      | j                  |d
d      | j                  |dd      | j                  ||d      gS )Nr  rL  r"  r   openTimer  r  r  r  r;  r  r  r  r  )r  rL  rO  )rl  ohlcvr  r  volumeIndexs        rn  parse_ohlcvzbinance.parse_ohlcv  s    h ..3"aq*5ua0ua0ua/ua1uk8<
 	
ro  r   sincec           	         | j                          d}| j                  |ddd      \  }}|r| j                  d|||||d      S | j                  |      }d}d}	| j	                  |d      }
| j                  |d      }| j                  |ddg      }||||	}||nt        ||	      }| j	                  | j                  ||      |d
}|d   }|
dk(  r)|j                  d      }| j	                  |d      }||d<   n||d<   |Z||d<   |d   rP|dkD  rK| j                  |      }| j                  |||z  dz  dz
        }| j                         }t        ||      |d<   |||d<   d	}|d   r#| j                  | j                  ||            }n[|
dk(  rK|d   r#| j                  | j                  ||            }n.| j!                  | j                  ||            }n|
dk(  rI|d   r"| j#                  | j                  ||            }n| j%                  | j                  ||            }n|
dk(  rI|d   r"| j'                  | j                  ||            }n| j)                  | j                  ||            }no|d   r"| j+                  | j                  ||            }nH|d   r"| j-                  | j                  ||            }n!| j/                  | j                  ||            }| j1                  |||||      }|S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#klinecandlestick-data
        https://developers.binance.com/docs/derivatives/option/market-data/Kline-Candlestick-Data
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Kline-Candlestick-Data
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Premium-Index-Kline-Data

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.price]: "mark" or "index" for mark price and index price candles
        :param int [params.until]: timestamp in ms of the latest candle to fetch
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Fr   paginaterR  rQ  rN  r  untilN)intervalr  rN   r  _r   pairr{  	startTimer  r  endTimer\   r  rW  r  )r  r  "fetch_paginated_call_deterministicr  r  r  r  r  r   r  parse_timeframesumr  eapiPublicGetKlinesr  dapiPublicGetMarkPriceKlinesfapiPublicGetMarkPriceKlinesdapiPublicGetIndexPriceKlinesfapiPublicGetIndexPriceKlinesdapiPublicGetPremiumIndexKlinesfapiPublicGetPremiumIndexKlinesfapiPublicGetKlinesdapiPublicGetKlinespublicGetKlinesparse_ohlcvs)rl  r{  	timeframer  r  r  r  r  defaultLimitmaxLimitr  r  r  r  partsr	  durationr  nowr  candless                        rn  fetch_ohlcvzbinance.fetch_ohlcvE  s3   2 	88z[`a&::<QVX]_hjprvwwV$   1!!&'26GW#56!2u}E!&S5I(()YO
 $<GNN3'E##E1-D"GFO (GH#(GK 
 i 19#33I>H"hhueh.>.E.IJG++-C),S'):GI&!&GI(//GV0LMHf_i <<T[[RX=YZ<<T[[RX=YZgi ==dkk'SY>Z[==dkk'SY>Z[n$i ??GU[@\]??GU[@\]H//GV0LMHI//GV0LMH++DKK,HIH6 ##HfiNro  tradec                 t   d|v r| j                  ||      S | j                  |dd      }| j                  |dd      }| j                  |d|      }| j                  |d      }d|v xs d	|v xs
 d
|v xs d|v }|rdnd}| j	                  ||d |      }|d   }d }	| j                  |dd      }
d }|
|
rdnd}	n$d|v r| j                  |d      }	nd|v r	|d   rdnd}	d }d|v r4| j                  |d      | j                  | j                  |d            d}d|v r	|d   rdnd}d|v r	|d   rdnd}d|v s|d   r| j                  | j                  |dd            }| j                  |d      }d|v r| j                  |d      |d}|	dk7  r|	dk7  r	|	dk(  rdnd}	d|v r|	dk7  rt        j                  d |      }| j                  ||| j                  |      || j                  |g d!      | j                  |d"      | j                  |d#      |	|| j                  |d$d%      || j                  |d&d'      |d(|      S ))NisDustTrader  rM  qqtyquantityr{  
isIsolatedMorderListIdisMakerrX   r  misBuyerMakersellbuyr4  isBuyer
commissioncommissionAsset)r%  currencyr  r  
optionSider\   r   r}  	liquidityr  r,  -1)tatradeIdrN   orderIdrp  pr  quoteQtybaseQty)r  r  r  r{  rN   ro  rp  r4  takerOrMakerr  r  r%  r  )parse_dust_traderL  r  r  r  safe_bool_2rK  r  rI   r  
safe_traderP  safe_string_n)rl  r"  r  r  r  r  isSpotTrader  r{  r4  
buyerMakerr>  r  r  s                 rn  parse_tradezbinance.parse_trade  s   E!((77J ''sF;	##E36!!%V<##E84#u,s#,sMUZDZs`imr`r*V

!!(FD*E!%%eS.A
!'6UDu_))%8DE! %i 0uf5 ((= 33D4D4DUL]4^_C &+I&67GLe&+Gn7'LE!fX&6,,T-=-=e\SY-Z[F11%EL~ ,,UE: & DFN!%u6u$5=$//f=F"Y/$$U,GH%%eY7**5&9(''sG<&&uj)D 
  	ro  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||      S | j                  |      }d|d   i}|d   s5|||d<   | j	                  |d	      |d
<   | j                  |d      }|||d
<   | j                  | j                  d      }	| j                  |dd|	      }	|?|d   xs |d   }
|	duxr |	j                  d      dk\  }|rdnd}|
rt        ||      n||d<   | j                  |ddg      }d}|d   s|	dk(  r"| j                  | j                  ||            }ny|d   s|	dk(  r"| j                  | j                  ||            }nM|d   s|	dk(  r"| j                  | j                  ||            }n!| j!                  | j                  ||            }| j#                  ||||      S )aa  
        get the list of most recent trades for a particular symbol
 Default fetchTradesMethod

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#compressedaggregate-trades-list    # publicGetAggTrades(spot)
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Compressed-Aggregate-Trades-List  # fapiPublicGetAggTrades(swap)
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Compressed-Aggregate-Trades-List  # dapiPublicGetAggTrades(future)
        https://developers.binance.com/docs/derivatives/option/market-data/Recent-Trades-List                                       # eapiPublicGetTrades(option)

 Other fetchTradesMethod

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#recent-trades-list                 # publicGetTrades(spot)
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Recent-Trades-List               # fapiPublicGetTrades(swap)
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Recent-Trades-List               # dapiPublicGetTrades(future)
        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#old-trade-lookup                   # publicGetHistoricalTrades(spot)
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Old-Trades-Lookup                # fapiPublicGetHistoricalTrades(swap)
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Old-Trades-Lookup                # dapiPublicGetHistoricalTrades(future)
        https://developers.binance.com/docs/derivatives/option/market-data/Old-Trades-Lookup                                        # eapiPublicGetHistoricalTrades(option)

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: only used when fetchTradesMethod is 'publicGetAggTrades', 'fapiPublicGetAggTrades', or 'dapiPublicGetAggTrades'
        :param int [limit]: default 500, max 1000
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: only used when fetchTradesMethod is 'publicGetAggTrades', 'fapiPublicGetAggTrades', or 'dapiPublicGetAggTrades'
        :param int [params.fetchTradesMethod]: 'publicGetAggTrades'(spot default), 'fapiPublicGetAggTrades'(swap default), 'dapiPublicGetAggTrades'(future default), 'eapiPublicGetTrades'(option default), 'publicGetTrades', 'fapiPublicGetTrades', 'dapiPublicGetTrades', 'publicGetHistoricalTrades', 'fapiPublicGetHistoricalTrades', 'dapiPublicGetHistoricalTrades', 'eapiPublicGetHistoricalTrades'
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)

 EXCHANGE SPECIFIC PARAMETERS
        :param int [params.fromId]: trade id to fetch from, default gets most recent trades, not used when fetchTradesMethod is 'publicGetTrades', 'fapiPublicGetTrades', 'dapiPublicGetTrades', or 'eapiPublicGetTrades'
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        Fr   r  r{  rN   r\   Nr
  i6 r  r  fetchTradesMethodmethodrZ   r[   GetHistoricalTradesr   rQ  rR  r  eapiPublicGetTradesr  fapiPublicGetAggTradesr  dapiPublicGetAggTrades)r  r  fetch_paginated_call_dynamicr  r  r  r  r  r  r  r  r  rJ  r  rK  rL  publicGetAggTradesparse_trades)rl  r{  r  r  r  r  r  r  r  rH  isFutureOrSwapisHistoricalEndpointmaxLimitForContractHistoricalr  s                 rn  fetch_tradeszbinance.fetch_trades  s   @ 	88PZ[&44]FESXZ`aaV$fTl
 h ',$ &*XXeW%=	"%%fg6E %*	"!!$,,0CD##F,?6R$Vn@x0@N$*$$6#eV[[I^=_cd=d 3GCT)LZs5*GH`eGG6G-@#AB(v)>>//GV0LMHH+C!C224;;w3OPHI&,D"D224;;w3OPH..t{{7F/KLHF   65%@@ro  rN   r4  r  r  c           	      (   | j                          | j                  |      }|d   s!t        | j                  dz   |d   z   dz         | j	                  |||||||      }	| j                  |	      }
| j                  |
d      }| j                  ||      S )a  
 @ignore
        edit a trade order

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-an-existing-order-and-send-a-new-order-trade

        :param str id: cancel order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit' or 'STOP_LOSS' or 'STOP_LOSS_LIMIT' or 'TAKE_PROFIT' or 'TAKE_PROFIT_LIMIT' or 'STOP'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated', for spot margin trading
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rX   z" editSpotOrder() does not support rp   ordersnewOrderResponse)r  r  r?   rN   edit_spot_order_requestprivatePostOrderCancelReplacer  parse_order)rl  rN   r{  rp  r4  r  r  r  r  payloadr  datas               rn  edit_spot_orderzbinance.edit_spot_orderH  s    " 	V$f~tww)MMPVW]P^^ajjkk..r64vuV\]55g>P ~~h(:;f--ro  c                 >   | j                  |      }| j                  |g d      }	|d   |j                         d}
|j                         }|}| j                  |dk(  |dk(  |      }|rd}||
d<   | j	                  |dd      }||dk(  rd	}n|d
k(  rd}| j                  |d   d      }| j                  ||      sM||k7  r$t        | j                  dz   |z   dz   |z   dz         t        | j                  dz   |z   dz   |z   dz         |	I| j                  | j                  d      }|0| j                  |d      }||| j                         z   |
d<   n|	|
d<   | j                  | j                  d   |d      |
d<   d}d}d}d}|dk(  r| j                  | j                  dd      }|r| j                  |dd      }|d   d   }|&| j!                  |t"        || j$                        |
d<   n|^| j'                  |      }| j'                  |      }t)        j*                  ||      }| j!                  |t"        || j$                        |
d<   n=d}n:d}n7|d
k(  rd}d}d}n+|d	k(  s|dk(  rd}d}n|dk(  s|dk(  r	d}d}d}d}n	|dk(  rd}d}|r| j-                  ||      |
d <   |r5|t        | j                  d!z   |z   d"z         | j/                  ||      |
d<   |r$| j                  |d#      | j                  d$   |
d#<   |r5|t        | j                  d%z   |z   d"z         | j/                  ||      |
d<   d&|
d'<   | j1                  |d(d)      }|||
d*<   | j                  |d#      d+k(  r| j3                  |d#g      }| j3                  |g d,      }| j5                  |
|      S )-a>  
 @ignore
        helper function to build request for editSpotOrder
        :param str id: order id to be edited
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit' or 'STOP_LOSS' or 'STOP_LOSS_LIMIT' or 'TAKE_PROFIT' or 'TAKE_PROFIT_LIMIT' or 'STOP'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict params: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated', for spot margin trading
        :returns dict: request to be sent to the exchange
        newClientOrderIdclientOrderIdorigClientOrderIdrN   r{  r4  MARKETLIMIT_MAKERrp  	stopPricer7  	STOP_LOSSLIMITSTOP_LOSS_LIMITr  
orderTypes+ triggerPrice parameter is not allowed for  rU  # is not a valid order type for the  marketr$  rX   r_  r  RESULTFr  Tr%  r  r  TAKE_PROFITTAKE_PROFIT_LIMITr'  z- editOrder() requires a price argument for a  orderr=  r  z7 editOrder() requires a triggerPrice extra param for a STOP_ON_FAILUREcancelReplaceModecancelNewClientOrderIdcancelOrigClientOrderIdcancelOrderIdr0  )r  r%  re  r_  r`  postOnly)r  rB  upperis_post_onlyrO  r  r
  r;   rN   r  r  r  uuid22r  r  safe_value_2r  rG   r  r  rI   r  amount_to_precisionprice_to_precisionr  r  r  )rl  rN   r{  rp  r4  r  r  r  r  r`  r  initialUppercaseTypeuppercaseTyperw  r7  validOrderTypesr$  brokerIdtimeInForceIsRequiredpriceIsRequiredtriggerPriceIsRequiredquantityIsRequiredr  quoteOrderQtyNewr  amountStringpriceStringquoteOrderQuantitycancelIds                                rn  rW  zbinance.edit_spot_order_request  sh    V$**63mnTlJJL
  $zz|,$$%9X%EG[_lGlntu)M'))&+~N#( +') 1..F}}]O<#}4"477-Z#Z]c#cfi#ilp#ps|#|}}"477S=4#7:_#_bh#hkt#tuu ^^DLL(;F!++FF;'2:T[[]2JG./*7G&'&*oodllCU6VX\^f&g"# %!&"H$ NN4<<$OM#'#4#4V_f#U ";/8	#//3/H/HIY[cenpt  qC  qC  0DGO,&#'#8#8#@L"&"7"7">K)0););L+)V&/3/H/HI[]egprv  sE  sE  0FGO,)-&%)"g%"O$(!!%{*0N%)"!%00mGZ6Z!%%)""O$(!m+"O!%"&":":66"JGJ}"477-\#\_c#cfn#noo#66vuEGG d&6&6v}&M&U%)\\2F%GGM"!#"477-f#fim#mpx#xyy'+'>'>v|'T$'8#$%%f.FHab')GO$FM2d:YYv7F6#z{{{7F++ro  c                 P   | j                  |      }|d   s!t        | j                  dz   |d   z   dz         |d   |j                         || j	                  ||      d}	| j                  |g d      }
|| j                  ||      |	d<   |
|
|	d	<   | j                  |d
dg      }|	S )Nr  z& editContractOrder() does not support rp  rU  rN   )r{  r4  r:  r'  r^  r  ra  r`  r_  )r  r?   rN   rx  r|  rB  r}  r  )rl  rN   r{  rp  r4  r  r  r  r  r  r`  s              rn  edit_contract_order_requestz#binance.edit_contract_order_request  s    V$j!tww)QQTZ[aTbbennooTlJJL00@	
 **63mn#66vuEGG$+8G'(6O5G#HIro  c           	      B   | j                          | j                  |      }d}	| j                  |dddd      \  }	}|d   s|	r|d|vrt        | j                  dz         | j                  |||||||      }
d}|d   rF|	r"| j                  | j                  |
|            }nl| j                  | j                  |
|            }nJ|d	   rE|	r"| j                  | j                  |
|            }n!| j                  | j                  |
|            }| j                  ||      S )
a  
        edit a trade order

        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Modify-Order
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Modify-UM-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Modify-CM-Order

        :param str id: cancel order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.portfolioMargin]: set to True if you would like to edit an order in a portfolio margin account
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        NeditContractOrderr  re  Fr  
priceMatchzM editOrder() requires a price argument for portfolio margin and linear ordersr  )r  r  r  r4   rN   r  papiPutUmOrderr  fapiPrivatePutOrderpapiPutCmOrderdapiPrivatePutOrderrY  )rl  rN   r{  rp  r4  r  r  r  r  r~  r  r  s               rn  edit_contract_orderzbinance.edit_contract_order  s?   & 	V$ $($C$CFL_agiz  }B  %C!6(0(>'  3B  )B  C  C222vtT6SXZ`a( ..t{{7F/KL33DKK4PQI ..t{{7F/KL33DKK4PQ8 &11ro  c           	          | j                          | j                  |      }|d   r!t        | j                  dz   |d   z   dz         |d   r| j	                  |||||||      S | j                  |||||||      S )a  
        edit a trade order

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-an-existing-order-and-send-a-new-order-trade
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Modify-Order
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Order

        :param str id: cancel order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r\   z editOrder() does not support rp  rU  rX   )r  r  r?   rN   r\  r  )	rl  rN   r{  rp  r4  r  r  r  r  s	            rn  
edit_orderzbinance.edit_orderG  s    " 	V$(tww)IIFSYNZ]ffgg&>''FD$vVV++BdFESYZZro  ordersc           
         | j                          g }g }t        dt        |            D ]  }||   }| j                  |d      }|j	                  |       | j                  |d      }| j                  |d      }	| j                  |d      }
| j                  |d      }| j                  |d      }| j                  |di       }d	}| j                  |d
ddd      \  }}|rt        | j                  dz         | j                  |||	|
|||      }|j	                  |        | j                  |d	ddd      }| j                  |d         }|d   s|d   r!t        | j                  dz   |d   z   dz         d	}d|i}| j                  ||      }|d   r| j                  |      }n|d   r| j                  |      }| j!                  |      S )at  
        edit a list of trade orders

        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Modify-Multiple-Orders
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Multiple-Orders

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   r{  rN   rp  r4  r  r  r  Nr{   r  re  Fz6 editOrders() does not support portfolio margin ordersTrX   r\   z editOrders() does not support rU  r  r  r  )r  r  r  r  r  r  r  r  r?   rN   r  r  r  r  fapiPrivatePutBatchOrdersdapiPrivatePutBatchOrdersparse_orders)rl  r  r  ordersRequestsorderSymbolsr  rawOrderr  rN   rp  r4  r  r  orderParamsr~  orderRequestr  r  r  s                      rn  edit_orderszbinance.edit_ordersa  s    	q#f+& 	0AayH''(;H)!!(D1B##Hf5D##Hf5D__Xx8FOOHg6E..8R@K $-1-L-L[Zfhn  qB  DI  .J*{ "477-e#eff;;B$PTV\^cepqL!!,/	0  **<udDQ\!_-&>VH-tww)JJVTZ^[^gghh>
 ++gv.(55g>HI55g>HF   **ro  r(  c                 B    ddddddddddd
}| j                  |||      S )Nr  closedcanceled	cancelingrejectedexpired)
NEWPARTIALLY_FILLEDACCEPTEDFILLEDCANCELED	CANCELLEDPENDING_CANCELREJECTEDEXPIREDEXPIRED_IN_MATCHr  rl  r(  statusess      rn  parse_order_statuszbinance.parse_order_status  s>     &"#)"  )
 &&99ro  ro  c           
      V   | j                  |d      }|| j                  |dd|      S | j                  | j                  |dd            }| j                  |d      }d|v xs d|v }|rd	nd
}| j	                  ||d |      }| j                  |dd      }	| j                  |g d      }
d }d|v sd|v r8| j                  |dd      }|dk(  rt        j                  |	d      r
|}n|dk(  r|}| j                  |dd      }| j                  |d      }| j                  |d      }| j                  |dd      }| j                  |dd      }| j                  |d|      }| j                  |d      }| j                  |d      }| j                  |dg       }| j                  |d      }|dk(  rd}|dk(  xs |dk(  }|dk(  rd}| j                  |d       }| j                  | j                  |            }| j                  |d!      }d }|| j                  |d"      |d d#}| j                  i d$|d%| j                  |d&d'      d(| j                  |d(d)      d*|
d+| j                  |
      d,|d-|d|d|d|d.|d/| j                  |d/      d|d|d0|d1|d2|||	d |||d3|      S )4Nr  r  )r  r(  r(  strategyStatusr{  positionSidecumQuoter  rX   executedQtyr  )rM  
createTimeworkingTimetransactTimerq  r  rq  r  r  r  r  origQtyr'  cummulativeQuoteQtycumBaserp  r4  fillsr=  GTXr0  limit_makerr  re  r  r   )r3  r%  rater  rN   
strategyIdr:  r`  newClientStrategyIdr  r  lastTradeTimestamplastUpdateTimestamprw  
reduceOnlyr7  r  r%  )r  filled	remainingr(  r  rT  )r  
safe_orderr  r  r|  safe_integer_nrL  rI   	string_gtrK  r  rj  r  r  rP  r  )rl  ro  r  r  r(  r  
isContractr  r{  r  r  r  timestampValuer  r  r  r  r%  rp  r4  r  r=  rw  stopPriceStringr7  feeCostr  s                              rn  rY  zbinance.parse_order  s   F v.??EZ#H&QQ((););E8M])^_##E84$-G:3F
#-Z6
!!(FD*E!!%<''/rs	!e#)>!00nUN$$VS1)7&8#%3""11%V""5*5  0##E9jA !!%)>
Ky$7%%eV4%%eV4ugr2&&um<%KM)C{d/B= D**5+>(()HI""5%0 ,,ULAC
   
E 
$$$UL)D 
 T//H]^ 
 	 

 Y/ 
 !"4 
 "#6 
 f 
 D 
 ; 
  
 $..= 
 D 
 U 
 L 
  f! 
" D# 
$ / 
0 1 	ro  c           	          | j                          g }g }t        dt        |            D ]  }||   }| j                  |d      }|j	                  |       | j                  |d      }| j                  |d      }	| j                  |d      }
| j                  |d      }| j                  |di       }| j                  |||	|
||      }|j	                  |        | j                  |dd	d
d
      }| j                  |d         }|d   r!t        | j                  dz   |d   z   dz         d}d|i}| j                  ||      }|d   r| j                  |      }n(|d   r| j                  |      }n| j                  |      }| j!                  |      S )a  
        *contract only* create a list of trade orders

        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Place-Multiple-Orders
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Place-Multiple-Orders
        https://developers.binance.com/docs/derivatives/option/trade/Place-Multiple-Orders

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   r{  rp  r4  r  r  r  NFTrX   z! createOrders() does not support rU  r  r  r\   )r  r  r  r  r  r  r  create_order_requestr  r  r?   rN   r  fapiPrivatePostBatchOrderseapiPrivatePostBatchOrdersdapiPrivatePostBatchOrdersr  )rl  r  r  r  r  r  r  r  rp  r4  r  r  r  r  r  r  r  s                    rn  create_orderszbinance.create_orders  s    	q#f+& 
	0AayH''(;H)##Hf5D##Hf5D__Xx8FOOHg6E..8R@K44XtT6SXZefL!!,/
	0 **<udDQ\!_-&>tww)LLvV\~]`iijj>
 ++gv.(66w?HH66w?H66w?HF   **ro  c                    | j                          | j                  |      }| j                  |d|d         }| j                  |d      }	| j                  | j                  ddd      }
| j                  |dd|
      }| j                  |dd      }| j                  |d      }| j                  |d	      }| j                  |d
d      }|du}|du}|du}|duxs
 |xs |xs |}| j                  |ddd      }| j                  |dd      }| j                  |g d      }| j                  ||||||      }d}|d   r| j                  |      }n|r&|r| j                  |      }n| j                  |      }n|d   r:|r&|r| j                  |      }n| j                  |      }n| j                  |      }n|d   r:|r&|r| j                  |      }nx| j!                  |      }nf| j#                  |      }nT|dk(  s|	|r&|r| j%                  |      }n7| j'                  |      }n%|r| j)                  |      }n| j+                  |      }| j-                  ||      S )aK  
        create a trade order

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade
        https://developers.binance.com/docs/binance-spot-api-docs/testnet/rest-api/trading-endpoints#test-new-order-trade
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/New-Order
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api
        https://developers.binance.com/docs/derivatives/option/trade/New-Order
        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#sor
        https://developers.binance.com/docs/binance-spot-api-docs/testnet/rest-api/trading-endpoints#sor
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-UM-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-CM-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-Margin-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-UM-Conditional-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-CM-Conditional-Order

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit' or 'STOP_LOSS' or 'STOP_LOSS_LIMIT' or 'TAKE_PROFIT' or 'TAKE_PROFIT_LIMIT' or 'STOP'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of you want to trade in units of the base currency
        :param float [price]: the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.reduceOnly]: for swap and future reduceOnly is a string 'true' or 'false' that cant be sent with close position set to True or in hedge mode. For spot margin and option reduceOnly is a boolean.
        :param str [params.marginMode]: 'cross' or 'isolated', for spot margin trading
        :param boolean [params.sor]: *spot only* whether to use SOR(Smart Order Routing) or not, default is False
        :param boolean [params.test]: *spot only* whether to use the test endpoint or not, default is False
        :param float [params.trailingPercent]: the percent to trail away from the current market price
        :param float [params.trailingTriggerPrice]: the price to trigger a trailing order, default uses the price argument
        :param float [params.triggerPrice]: the price that a trigger order is triggered at
        :param float [params.stopLossPrice]: the price that a stop loss order is triggered at
        :param float [params.takeProfitPrice]: the price that a take profit order is triggered at
        :param boolean [params.portfolioMargin]: set to True if you would like to create an order in a portfolio margin account
        :param str [params.selfTradePrevention]: set unified value for stp(see .features for available values)
        :param float [params.icebergAmount]: set iceberg amount for limit orders
        :param str [params.stopLossOrTakeProfit]: 'stopLoss' or 'takeProfit', required for spot trailing orders
        :param str [params.positionSide]: *swap and portfolio margin only* "BOTH" for one-way mode, "LONG" for buy side of hedged mode, "SHORT" for sell side of hedged mode
        :param bool [params.hedged]: *swap and portfolio margin only* True for hedged mode, False for one way mode, default is False
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rp  r6  r  re  Fr7  re  r:  r;  trailingPercentcallbackRateNsorSORr  )r  r  r  r\   r  r  rY   )r  r  r  r@  r  r  r  r  r  eapiPrivatePostOrderprivatePostSorOrderTestprivatePostSorOrderpapiPostUmConditionalOrderpapiPostUmOrderfapiPrivatePostOrderpapiPostCmConditionalOrderpapiPostCmOrderdapiPrivatePostOrderpapiPostMarginOrdersapiPostMarginOrderprivatePostOrderTestprivatePostOrderrY  )rl  r{  rp  r4  r  r  r  r  r  r6  porfolioOptionsValuer~  r7  r:  r;  r  isTrailingPercentOrder
isStopLossisTakeProfitisConditionalr  r  r  r  s                           rn  create_orderzbinance.create_order9  s   P 	V$%%fffVnE
%%fl;
#//fFWY^_ ,,VV=NPde))&.+N((A**63DE,,V5FW!0!<"$.
&d2%T1j6LjPZj^jvueU;~~ffe46#9: ++FD$vV(009H77@33G<H  #>>wGH#33G<H44W=I  #>>wGH#33G<H44W=8#z'=AR 33G<33G<44W=009&11ro  c                 f   | j                  |      }| j                  |d|d         }| j                  |dd      }	|j                         }
|
dk(  }|
dk(  }|d   |j                         d}d}| j	                  |d	d
dd      \  }}d}| j                  d	|      \  }}| j                  |dd      }|r#|dk(  s|d   s|| j                  |d      }d|d<   | j                  |dd      }| j                  |d|      }| j                  |d      }| j                  |d      }| j                  |dd      }| j                  |g d      }| j                  |d      }|du}|duxs |du}|du}|du}|xs
 |xs |xs |}|xr |}|du}|j                         }d} |r|d   rd}||d<   || j                  ||      |d<   n|r$t        | j                  dz   |z   dz   |z   d z         | j                  |d!      }!| j                  |d!      }|!d"k7  r |!d#k7  rt        | j                  |z   d$z         |!d"k(  rd%}n|!d#k(  rd&}|| j                  ||      } t        j                  |d'      }"|"|d<   n7|r|} |r
|d   rd(nd)}n'|r%|d   rd*nd%}n|r|} |r
|d   rd+nd,}n|r	|d   rd,nd&}|d-   r)|d.k(  rt        | j                  dz   |z   d/z   |z   d0z         | j                  |d1   d2      }#| j                  ||#      sM|
|k7  r$t        | j                  d3z   |z   dz   |z   d z         t        | j                  dz   |z   d/z   |z   d0z         |rd4nd}$|	e| j!                  | j"                  d5i       }%|d   rd6nd7}&d8}'|d   r|d   r|d9   rdnd:}'| j                  |%|'|&      }(|(| j%                         z   ||$<   n|	||$<   d})|s/| j'                  ||
d;k(  |      })|d8   s|dk(  r4|)rd;}|d<k(  r+d=|d><   n%| j'                  ||
d;k(  |      })|)r|d   sd;}nd?|d@<   |d8k(  s|dk(  r&|s$| j                  | j"                  dA   |dB      |dA<   ndC|dA<   |rdDnd}*|||*<   | j                  |dEd      }+d},d}-d}.d}/|dk(  r|d8   r| j                  | j"                  dFd=      }0|0r| j                  |dFdG      }1|dH   dI   }2|1&| j)                  |1t*        |2| j,                        |dF<   n|^| j/                  |      }3| j/                  |      }4t        j                  |3|4      }5| j)                  |5t*        |2| j,                        |dF<   nd=}/nd=}/nd=}/n|dk(  rd=}-d=},d=}/n~|d)k(  s|d,k(  rd=}.d=}/|d9   s|d:   rfd=}-nc|d%k(  s|d&k(  r	d=}/d=}.d=}-d=},nP|d;k(  rd=}-d=}/nF|d*k(  rd=}/d=}.d=}-n:|d(k(  s|d+k(  r|+sd=}/d=}.n)|dk(  r$|+sd=}/|t        | j                  dJz   |z   dKz         |/r\|r| j1                  |      |dL<   nE| j                  |dH   dM      }6|6du}7|7r| j3                  ||      |dL<   n| j1                  |      |dL<   |-rg|se|t        | j                  dNz   |z   dKz         | j                  |dH   dI      }8|8du}9|9r| j                  ||      |dI<   n| j1                  |      |dI<   |.r`|d   r | Bt        | j                  dOz   |z   dKz         |"|  |t        | j                  dPz   |z   dKz         | | j                  ||       |d<   |,rC| j                  |d@      1| j                  |d@      | j                  | j"                  dQ      |d@<   |s|d   r|)rd?|d@<   | j                  |d@      dRk(  r| j                  |d@      }| j                  |dSd      }:|d8   s0|d-   s+|:r)|r| j                  |d      }|dTk(  rdUndT}|dTk(  rdVndW|dX<   | j                  |dY      };|;|d8   r|;j                         |dZ<   | j5                  |d[      }<|<|d8   r| j3                  ||<      |d\<   | j                  |g d]      }=| j7                  ||=      S )^aL  
 @ignore
        helper function to build the request
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency
        :param float [price]: the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: request to be sent to the exchange
        rp  r_  r`  rc  rg  rN   rb  Nrn   r  re  Fr  rY   r  
AUTO_REPAYsideEffectTyper7  re  r:  r;  trailingDeltatrailingTriggerPriceactivationPrice)r  r  r  r  rZ   TRAILING_STOP_MARKETr  z. trailingPercent orders are not supported for rk  rU  stopLossOrTakeProfitstopLoss
takeProfitza trailingPercent orders require a stopLossOrTakeProfit parameter of either stopLoss or takeProfitrh  rp  100STOP_MARKETrf  STOPTAKE_PROFIT_MARKETro  r\   r  rl  rm  r  ri  rj  r  r$  r  r  rX   r  r  rd  r1  Tr(  r  r=  r  r  rn  strategyTyperd   r  r%  r  r  z6 createOrder() requires a trailingPercent param for a rq  r'  r  z/ createOrder() requires a price argument for a z9 createOrder() requires a triggerPrice extra param for a zU createOrder() requires a triggerPrice, trailingDelta or trailingPercent param for a r  r0  r>  r/  r.  LONGSHORTr  rA  selfTradePreventionModerC  
icebergQty)rp  r_  r`  rw  r:  r;  re  r7  r  r  r  r%  r  r>  rA  rC  )r  r  r  rx  r  r  r  r  rB  r}  r;   rN   rI   r  r  r
  r  r  rz  ry  r  rG   r  r  rN  r|  r  r  )>rl  r{  rp  r4  r  r  r  r  r  r`  r~  isMarketOrderisLimitOrderr  r~  r6  r  r7  r:  r;  r  r  r  r  r  r  r  isTriggerOrderr  isPortfolioMarginConditionalisPriceMatchr  re  r  trailingPercentConvertedr  clientOrderIdRequestr$  	defaultIdidMarketTyper  rw  typeRequestrd   r  r  r  r  r  r  r  r  r  r  marketAmountPrecisionisPrecisionAvailabler7  isPricePrecisionAvailabler>  rA  rC  requestParamss>                                                                 rn  r  zbinance.create_order_request  s
    V$%%fffVnE
**63EW#zz|,8+w6TlJJL
 !$($C$CFM[actv{$|!6
!??vV
F^^FL%@
X%fZ.@jF\6<8,8()))&.+N((,O**63DE((A#11&:PRcd,,V5ij%%fl;
!0!<"$.K-t2K
&d2%T1&^*@^J^R^(9(Km$!-

	!f~ 6*9''3151H1HQe1fG-. &tww1a'adj'jmp'psw'w  {D  (D  E  E'+'7'7@V'W$6+AB':5:NR^:^&tww'7  ;^  (^  _  _':5$5M)\9$7M'3 $ 7 7@T UI+2+=+=ou+U(+C(%I17
1C*0*<BS'I8>z8J 4P]17
1CI\(x"477S=4#7:_#_bh#hkt#tuu"nnVF^\JO==@'=8&tww1^'^ag'gjm'mpt't  xA  (A  B  B&tww}t';>c'cfl'lox'xyy8T4Zl ^^DLL(B?F)/
);,I!Lj!*0.VH=MvT]''iHH,4t{{},DG(),9G() ((8LP]8]_efHf~x!7$1M+,0GL)((8LP]8]_efHj)$1M-2GM*6!zX'=HY*.*:*:4<<HZ;[]aci*jG&' +3G&'(Dn&,vF %!&"* H$f~ $t||_d S '+'9'9&/SY'Z$ &{ 3G <I'3373L3LM]_girtx  uG  uG  4H0*'+'<'<V'D&*&;&;E&B-4-?-?k-Z*373L3LM_aiktvz  wI  wI  4J0-1*)-&%)"g%"O$(!!%{*0N%)"!%h6)#4"&00mGZ6Z!%%)""O$(!m+"O!%f$!%%)""O},-CW2W %)"%)"44 %)"&"477-e#ehl#low#wxx &*&;&;F&C
#(,(8(89Lh(W%(=T(I$'*.*B*B66*RGJ'*.*?*?*GGJ'<}"477-^#^ae#ehp#pqq!--f[.A7KN)7t)C%(#'#:#:65#I #'#8#8#? !j!$&tww1l'los'sv~'~ !(Y->?CZ&tww  2I  (I  LP  (P  S[  ([  \  \$'+'>'>vy'Q$ d&6&6v}&M&U\`\l\lmt  wD  ]E  ]M%)%5%5dllDX%YGM" VJ%7H%*GM"FM2d:YYv}5F%8f~fX&666<8"&%-ve15fWGN#"..v7LM*f~5H5N5N5P12((A$f~(,(@(@(W%		&  +c  d{{7M22ro  r%  c                     | j                          | j                  |      }|d   st        | j                  dz         d|i}| j	                  |d||d| j                  ||            S )a8  
        create a market order by providing the symbol, side and cost

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade

        :param str symbol: unified symbol of the market to create an order in
        :param str side: 'buy' or 'sell'
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rX   z6 createMarketOrderWithCost() supports spot orders onlyr%  r  Nr  r  r?   rN   r  r  )rl  r{  r4  r%  r  r  reqs          rn  create_market_order_with_costz%binance.create_market_order_with_cost  sp     	V$f~tww)aabbD
   4tT[[QTV\E]^^ro  c                     | j                          | j                  |      }|d   st        | j                  dz         d|i}| j	                  |dd|d| j                  ||            S )a  
        create a market buy order by providing the symbol and cost

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade

        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rX   z9 createMarketBuyOrderWithCost() supports spot orders onlyr%  r  r/  Nr  )rl  r{  r%  r  r  r  s         rn  !create_market_buy_order_with_costz)binance.create_market_buy_order_with_cost  sp     	V$f~tww)ddeeD
   5$dkkRUW]F^__ro  c                     | j                          | j                  |      }|d   st        | j                  dz         ||d<   | j	                  |dd|d|      S )a  
        create a market sell order by providing the symbol and cost

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade

        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rX   z: createMarketSellOrderWithCost() supports spot orders onlyr  r  r.  N)r  r  r?   rN   r  )rl  r{  r%  r  r  s        rn  "create_market_sell_order_with_costz*binance.create_market_sell_order_with_cost  s_     	V$f~tww)eeff"&  64vNNro  c                 `   |t        | j                  dz         | j                          | j                  |      }| j	                  | j
                  ddd      }| j                  |d|      }d}| j                  d|      \  }}d}| j                  |dddd	      \  }}d
|d   i}	| j	                  |dd      }
|
|d   r|
|	d<   n|
|	d<   n||	d<   | j                  |g d      }d}|d   r#| j                  | j                  |	|            }n|d   rF|r"| j                  | j                  |	|            }n| j                  | j                  |	|            }n|d   rF|r"| j                  | j                  |	|            }n| j                  | j                  |	|            }nz|dk(  s||rP|r"| j!                  | j                  |	|            }nM|dk(  rd|	d<   | j#                  | j                  |	|            }n!| j%                  | j                  |	|            }| j'                  ||      S )a  
        fetches information on an order made by the user

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#query-order-user_data
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-Order
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Query-Order
        https://developers.binance.com/docs/derivatives/option/trade/Query-Single-Order
        https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Order

        :param str id: the order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated', for spot margin trading
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch an order in a portfolio margin account
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz( fetchOrder() requires a symbol argumentr   r  rX   rp  r  re  Fr{  rN   ra  r`  r\   r:  )rp  r`  ra  r  r  rY   r1  Tr(  )r4   rN   r  r  r  r  r  r  r  r  eapiPrivateGetOrderr  papiGetUmOrderfapiPrivateGetOrderpapiGetCmOrderdapiPrivateGetOrderpapiGetMarginOrdersapiGetMarginOrderprivateGetOrderrY  )rl  rN   r{  r  r  r  rp  r6  r~  r  r`  r  s               rn  fetch_orderzbinance.fetch_order  sB   & >#DGG.X$XYYV$((|]TZ[<
!??fU
F $($C$CFLZ`bsuz${!6fTl
 **63FX$h+8(/<+,!#GI6#QR(//GV0LMHH ..t{{7F/KL33DKK4PQI ..t{{7F/KL33DKK4PQhJ$:?P 224;;w3OP+,0GL)224;;w3OP++DKK,HIH&11ro  c                 r   |t        | j                  dz         | j                          d}| j                  |dd      \  }}|r| j	                  d||||      S | j                  |      }| j                  | j                  dd|d         }| j                  |d|      }d}	| j                  d|      \  }	}d}
| j                  |ddd	d      \  }
}| j                  |g d
      }| j                  |g d      }d|d   i}| j                  d||      \  }}|||d<   |||d<   d}|d   r#| j                  | j                  ||            }nX|d   rl|
rH|r#| j!                  | j                  ||            }n,| j#                  | j                  ||            }n	| j%                  | j                  ||            }n|d   rj|
rF|r"| j'                  | j                  ||            }n| j)                  | j                  ||            }n| j+                  | j                  ||            }nx|
r"| j-                  | j                  ||            }nT|dk(  s|	,|	dk(  rd|d<   | j/                  | j                  ||            }n!| j1                  | j                  ||            }| j3                  ||||      S )a1  
        fetches information on multiple orders made by the user

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#all-orders-user_data
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/All-Orders
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/All-Orders
        https://developers.binance.com/docs/derivatives/option/trade/Query-Option-Order-History
        https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-All-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-UM-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-CM-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-UM-Conditional-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-CM-Conditional-Orders

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated', for spot margin trading
        :param int [params.until]: the latest time in ms to fetch orders for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch orders in a portfolio margin account
        :param boolean [params.trigger]: set to True if you would like to fetch portfolio margin account trigger or conditional orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz) fetchOrders() requires a symbol argumentFr   r  r  rp  r  re  stoprG  conditional)r&  rG  r'  rp  r{  rN   r  r
  r  r\   r  r  rY   r1  Tr(  )r4   rN   r  r  rM  r  r  r  r  r  r  safe_bool_nr  handle_until_optioneapiPrivateGetHistoryOrdersr  papiGetUmConditionalAllOrderspapiGetUmAllOrdersfapiPrivateGetAllOrderspapiGetCmConditionalAllOrderspapiGetCmAllOrdersdapiPrivateGetAllOrderspapiGetMarginAllOrderssapiGetMarginAllOrdersprivateGetAllOrdersr  )rl  r{  r  r  r  r  r  r  rp  r6  r~  r  r  r  s                 rn  fetch_orderszbinance.fetch_orders  s   2 >#DGG.Y$YZZ88PZ[&44]FESXZ`aaV$((}mU[\bUcd<
!??vV
F $($C$CFM[actv{$|!6((1ST6#MNfTl
 229gvN#(GK $GG(77GV8TUHH  #AA$++gW]B^_H#66t{{7F7STH77GV8TUI  #AA$++gW]B^_H#66t{{7F7STH77GV8TU 66t{{7F7ST!Z%;+,0GL)66t{{7F7ST33DKK4PQj   65%@@ro  c                 F   | j                          d}d}i }d}| j                  d|      \  }}d}	| j                  |dddd      \  }	}| j                  |g d      }
|V| j	                  |      }|d   |d<   | j                  | j                  dd	d
      }d|v r|d   n|}| j                  |d|      }nh| j                  d   r(t        | j                  dz   | j                  z   dz         | j                  | j                  dd	d
      }| j                  |d|      }d}| j                  d||      \  }}| j                  |g d      }d}|dk(  r1|||d<   |||d<   | j                  | j                  ||            }n| j                  ||      rm|	rH|
r#| j                  | j                  ||            }nV| j!                  | j                  ||            }n3| j#                  | j                  ||            }n| j%                  ||      rj|	rF|
r"| j'                  | j                  ||            }n| j)                  | j                  ||            }n| j+                  | j                  ||            }n|dk(  s||	rj|	r"| j-                  | j                  ||            }ng|dk(  rd|d<   |t/        | j                  dz         | j1                  | j                  ||            }n!| j3                  | j                  ||            }| j5                  ||||      S )a`  
        fetch all unfilled currently open orders

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#current-open-orders-user_data
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Current-All-Open-Orders
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Current-All-Open-Orders
        https://developers.binance.com/docs/derivatives/option/trade/Query-Current-Open-Option-Orders
        https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-Open-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Conditional-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-CM-Open-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-CM-Open-Conditional-Orders

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated', for spot margin trading
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch open orders in the portfolio margin account
        :param boolean [params.trigger]: set to True if you would like to fetch portfolio margin account conditional orders
        :param str [params.subType]: "linear" or "inverse"
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   r  re  Fr%  rN   r{  r  rX   rp  r  z fetchOpenOrders() WARNING: fetching open orders without specifying a symbol has stricter rate limits(10 times more for spot, 40 times more for other markets) compared to requesting with symbol argument. To acknowledge self warning, set zX.options["warnOnFetchOpenOrdersWithoutSymbol"] = False to suppress self warning message.rp  r&  rG  r'  r\   r
  r  rY   r1  Tr(  zB fetchOpenOrders() requires a symbol argument for isolated markets)r  r  r  r(  r  r  r  r  r0   rN   r  r  eapiPrivateGetOpenOrdersr  rw  papiGetUmConditionalOpenOrderspapiGetUmOpenOrdersfapiPrivateGetOpenOrdersru  papiGetCmConditionalOpenOrderspapiGetCmOpenOrdersdapiPrivateGetOpenOrderspapiGetMarginOpenOrdersr4   sapiGetMarginOpenOrdersprivateGetOpenOrdersr  )rl  r{  r  r  r  r  rp  r  r6  r~  r  r  r  rq  r  s                  rn  fetch_open_orderszbinance.fetch_open_orders  sP   0 	
!??@QSYZ
F $($C$CFL]_egxz  %A!6((1ST[[(F &tGH,,T\\;Lm]cdK,2f,<;J##FFJ?D\\>?  +Z  !Z  ]a  ]d  ]d  !d  gA  !A  B  B,,T\\;Lm]cdK##FFK@D99:KVU[\6#MN8 ',$ #( 44T[[&5QRH^^D'*  #BB4;;wX^C_`H#77GV8TUH88Wf9UV__T7+  #BB4;;wX^C_`H#77GV8TUH88Wf9UVX!7;L 77GV8TU+,0GL)~/:~0~77GV8TU00Wf1MNH  65%@@ro  c                    |t        | j                  dz         | j                          | j                  |      }d|d   i}d}| j	                  |dddd      \  }}| j                  |g d	      }| j                  |g d	      }|xr |}|rd
nd}	|||	<   d}
|d   rj|rF|r"| j                  | j                  ||            }
n| j                  | j                  ||            }
n| j                  | j                  ||            }
n|d   rj|rF|r"| j                  | j                  ||            }
n~| j                  | j                  ||            }
n\| j                  | j                  ||            }
n:|d   rt        | j                  dz         |d   rt        | j                  dz         | j                  |
|      S )a  
        fetch an open order by the id

        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-Current-Open-Order
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Query-Current-Open-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-UM-Open-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-UM-Open-Conditional-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-CM-Open-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-CM-Open-Conditional-Order

        :param str id: order id
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.trigger]: set to True if you would like to fetch portfolio margin account stop or conditional orders
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch for a portfolio margin account
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz, fetchOpenOrder() requires a symbol argumentr{  rN   r   r  re  Fr%  r  r:  r  r  r\   z1 fetchOpenOrder() does not support option marketsrX   z/ fetchOpenOrder() does not support spot markets)r4   rN   r  r  r  r(  r  papiGetUmConditionalOpenOrderr  papiGetUmOpenOrderfapiPrivateGetOpenOrderpapiGetCmConditionalOpenOrderpapiGetCmOpenOrderdapiPrivateGetOpenOrderr?   rY  )rl  rN   r{  r  r  r  r~  r  r  orderIdRequestr  s              rn  fetch_open_orderzbinance.fetch_open_ordero  s   $ >#DGG.\$\]]V$fTl
 !$($C$CFL\^dfwy~$!6((1ST6#EF(9(Km$)E9"$(  #AA$++gW]B^_H#66t{{7F7STH77GV8TUI  #AA$++gW]B^_H#66t{{7F7STH77GV8TUh"477-`#`aa"477-^#^__j &11ro  c                     |t        | j                  dz         | j                  ||d|      }| j                  |dd      }| j	                  |||      S )a  
        fetches information on multiple closed orders made by the user

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#all-orders-user_data
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/All-Orders
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/All-Orders
        https://developers.binance.com/docs/derivatives/option/trade/Query-Option-Order-History
        https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-All-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-UM-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-CM-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-UM-Conditional-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-CM-Conditional-Orders

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch orders in a portfolio margin account
        :param boolean [params.trigger]: set to True if you would like to fetch portfolio margin account trigger or conditional orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz/ fetchClosedOrders() requires a symbol argumentr(  r  r4   rN   r4  	filter_byfilter_by_since_limitrl  r{  r  r  r  r  filteredOrderss          rn  fetch_closed_orderszbinance.fetch_closed_orders;  s[    . >#DGG._$_``""65$?(C)).%GGro  c                     |t        | j                  dz         | j                  ||d|      }| j                  |dd      }| j	                  |||      S )  
        fetches information on multiple canceled orders made by the user

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#all-orders-user_data
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/All-Orders
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/All-Orders
        https://developers.binance.com/docs/derivatives/option/trade/Query-Option-Order-History
        https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-All-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-UM-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-CM-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-UM-Conditional-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-CM-Conditional-Orders

        :param str symbol: unified market symbol of the market the orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch orders in a portfolio margin account
        :param boolean [params.trigger]: set to True if you would like to fetch portfolio margin account trigger or conditional orders
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz1 fetchCanceledOrders() requires a symbol argumentr(  r  rL  rO  s          rn  fetch_canceled_orderszbinance.fetch_canceled_ordersX  s[    . >#DGG.a$abb""65$?*E)).%GGro  c                    |t        | j                  dz         | j                  ||d|      }| j                  |dd      }| j                  |dd      }| j	                  ||      }| j                  |d      }	| j                  |	||      S )rS  Nz: fetchCanceledAndClosedOrders() requires a symbol argumentr(  r  r  r  )r4   rN   r4  rM  r  sort_byrN  )
rl  r{  r  r  r  r  canceledOrdersclosedOrdersrP  sortedOrderss
             rn   fetch_canceled_and_closed_ordersz(binance.fetch_canceled_and_closed_ordersu  s    . >#DGG.j$jkk""65$?*E~~fhA**><H||NK@)),uEEro  c                 F   |t        | j                  dz         | j                          | j                  |      }| j	                  | j
                  ddd      }| j                  |d|      }d}| j                  d|      \  }}d}| j                  |dddd	      \  }}| j                  |g d
      }	d|d   i}
| j                  |g d      }||d   r||
d<   n|r|	r||
d<   n||
d<   n|r|	r||
d<   n||
d<   | j                  |g d      }d}|d   r#| j                  | j                  |
|            }nZ|d   rl|rH|	r#| j                  | j                  |
|            }n.| j                  | j                  |
|            }n| j!                  | j                  |
|            }n|d   rj|rF|	r"| j#                  | j                  |
|            }n| j%                  | j                  |
|            }n| j'                  | j                  |
|            }nz|dk(  s||rP|r"| j)                  | j                  |
|            }nM|dk(  rd|
d<   | j+                  | j                  |
|            }n!| j-                  | j                  |
|            }| j/                  ||      S )a=  
        cancels an open order

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-order-trade
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-Order
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Cancel-Order
        https://developers.binance.com/docs/derivatives/option/trade/Cancel-Option-Order
        https://developers.binance.com/docs/margin_trading/trade/Margin-Account-Cancel-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-UM-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-CM-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-UM-Conditional-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-CM-Conditional-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-Order

        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.portfolioMargin]: set to True if you would like to cancel an order in a portfolio margin account
        :param boolean [params.trigger]: set to True if you would like to cancel a portfolio margin account conditional order
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz) cancelOrder() requires a symbol argumentra   r  rX   rp  r  re  Fr%  r{  rN   )ra  r`  r  r\   r`  r  ra  r  r:  )rp  ra  r`  r  r&  rG  r'  r  r  rY   r1  Tr(  )r4   rN   r  r  r  r  r  r  r  r(  rB  r  eapiPrivateDeleteOrderr  papiDeleteUmConditionalOrderpapiDeleteUmOrderfapiPrivateDeleteOrderpapiDeleteCmConditionalOrderpapiDeleteCmOrderdapiPrivateDeleteOrderpapiDeleteMarginOrdersapiDeleteMarginOrderprivateDeleteOrderrY  )rl  rN   r{  r  r  r  rp  r6  r~  r  r  r`  r  s                rn  cancel_orderzbinance.cancel_order  s   , >#DGG.Y$YZZV$((}mU[\<
!??vV
F $($C$CFM[actv{$|!6((1STfTl
 **63pq$h+8($5BG123@G/0 ](*%%'	"6  $K  L(224;;w3OPHH  #@@WV\A]^H#55dkk'66RSH66t{{7F7STI  #@@WV\A]^H#55dkk'66RSH66t{{7F7SThJ$:?P 55dkk'66RS+,0GL)55dkk'66RS..t{{7F/KLH&11ro  c                    |t        | j                  dz         | j                          | j                  |      }d|d   i}d}| j	                  |dddd      \  }}| j                  |g d	      }| j                  |d
|d
         }| j                  |g d      }d}| j                  d|      \  }}d}	|d   r#| j                  | j                  ||            }	nZ|d   rl|rH|r#| j                  | j                  ||            }	n.| j                  | j                  ||            }	n| j                  | j                  ||            }	n|d   rj|rF|r"| j                  | j                  ||            }	n| j                  | j                  ||            }	n| j!                  | j                  ||            }	nz|dk(  s||rP|r"| j#                  | j                  ||            }	nM|dk(  rd|d<   | j%                  | j                  ||            }	n!| j'                  | j                  ||            }	t)        |	t*              r| j-                  |	|      S | j/                  d|	i      gS )a  
        cancel all open orders in a market

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-all-open-orders-on-a-symbol-trade
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-All-Open-Orders
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Cancel-All-Open-Orders
        https://developers.binance.com/docs/derivatives/option/trade/Cancel-all-Option-orders-on-specific-symbol
        https://developers.binance.com/docs/margin_trading/trade/Margin-Account-Cancel-All-Open-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-UM-Open-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-UM-Open-Conditional-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-CM-Open-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-CM-Open-Conditional-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-All-Open-Orders-on-a-Symbol

        :param str symbol: unified market symbol of the market to cancel orders in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated', for spot margin trading
        :param boolean [params.portfolioMargin]: set to True if you would like to cancel orders in a portfolio margin account
        :param boolean [params.trigger]: set to True if you would like to cancel portfolio margin account conditional orders
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz- cancelAllOrders() requires a symbol argumentr{  rN   r`   r  re  Fr%  rp  r6  r\   r  r  rY   r1  Tr(  r  )r4   rN   r  r  r  r(  r  r  r  eapiPrivateDeleteAllOpenOrdersr  $papiDeleteUmConditionalAllOpenOrderspapiDeleteUmAllOpenOrdersfapiPrivateDeleteAllOpenOrders$papiDeleteCmConditionalAllOpenOrderspapiDeleteCmAllOpenOrdersdapiPrivateDeleteAllOpenOrderspapiDeleteMarginAllOpenOrderssapiDeleteMarginOpenOrdersprivateDeleteOpenOrdersr  r  r  r  )
rl  r{  r  r  r  r~  r  rp  r6  r  s
             rn  cancel_all_orderszbinance.cancel_all_orders  s   , >#DGG.]$]^^V$fTl
 !$($C$CFL]_egxz  %A!6((1STv?6#MN
!??@QSYZ
F(::4;;wPV;WXH H  #HHU\^dIefH  $==dkk'SY>Z[H  >>t{{7TZ?[\ I  #HHU\^dIefH  $==dkk'SY>Z[H  >>t{{7TZ?[\ hJ$:?P ==dkk'SY>Z[+,0GL)::4;;wPV;WX0 33DKK4PQH, h%$$Xv66 H!  ro  idsc                    |t        | j                  dz         | j                          | j                  |      }|d   st	        | j                  dz         |d   |d}d}|d   r"| j                  | j                  ||            }n&|d   r!| j                  | j                  ||            }| j                  ||      S )	a  
        cancel multiple orders

        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-Multiple-Orders
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Cancel-Multiple-Orders

        :param str[] ids: order ids
        :param str [symbol]: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint

 EXCHANGE SPECIFIC PARAMETERS
        :param str[] [params.origClientOrderIdList]: max length 10 e.g. ["my_id_1","my_id_2"], encode the double quotes. No space after comma
        :param int[] [params.recvWindow]:
        :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz* cancelOrders() requires a symbol argumentr  z1 cancelOrders is only supported for swap markets.rN   )r{  orderidlistr  r  )	r4   rN   r  r  r5   fapiPrivateDeleteBatchOrdersr  dapiPrivateDeleteBatchOrdersr  )rl  rs  r{  r  r  r  r  s          rn  cancel_orderszbinance.cancel_orders  s      >#DGG.Z$Z[[V$j!TWW'ZZ[[Tl
 (88Wf9UVHI88Wf9UVHH   622ro  c           	      R   |t        | j                  dz         | j                          | j                  |      }| j	                  |d|d         }| j                  |d      }|dk7  rt        | j                  dz         d|i}| j                  |||| j                  ||            S )a  
        fetch all the trades made from a single order

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#account-trade-list-user_data
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Account-Trade-List
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Account-Trade-List
        https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-Trade-List

        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        z. fetchOrderTrades() requires a symbol argumentrp  rX   z. fetchOrderTrades() supports spot markets onlyr:  )	r4   rN   r  r  r  r  r?   fetch_my_tradesr  )	rl  rN   r{  r  r  r  r  rp  r  s	            rn  fetch_order_tradeszbinance.fetch_order_trades  s      >#DGG.^$^__V$v?66*6>tww)YYZZr
 ##FE5$++gv:VWWro  c                 V   | j                          d}| j                  |dd      \  }}|r| j                  d||||      S i }d}d}d}	|| j                  |      }|d   |d<   | j	                  d||      \  }}| j                  |dd      }
|F|}||d	<   | j                         }d
}||z
  |k\  r%|
#|d   r| j                  ||      }
t        |
|      }
|
|
|d<   | j                  |ddg      }||dk(  s|d   rt        |d      }||d<   d}|dk(  r#| j                  | j                  ||            }na|t        | j                  dz         | j                  d|      \  }	}d}| j                  |dddd      \  }}|dk(  s|dk(  ry|r"| j!                  | j                  ||            }n|dk(  s|	,|	dk(  rd|d<   | j#                  | j                  ||            }n| j%                  | j                  ||            }n|d   rF|r"| j'                  | j                  ||            }nl| j)                  | j                  ||            }nJ|d   rE|r"| j+                  | j                  ||            }n!| j-                  | j                  ||            }| j/                  ||||      S )aT  
        fetch all trades made by the user

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#account-trade-list-user_data
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Account-Trade-List
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Account-Trade-List
        https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-Trade-List
        https://developers.binance.com/docs/derivatives/option/trade/Account-Trade-List
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/UM-Account-Trade-List
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/CM-Account-Trade-List

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch trades for a portfolio margin account
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Fr   r  NrN   r{  r  r  r
  i $r  r\   r  rR  r  z+ fetchMyTrades() requires a symbol argumentr  re  rX   rY   r1  Tr(  r  )r  r  rM  r  r  rL  r  r  r  r  eapiPrivateGetUserTradesr  r4   rN   r  r  papiGetMarginMyTradessapiGetMarginMyTradesprivateGetMyTradespapiGetUmUserTradesfapiPrivateGetUserTradespapiGetCmUserTradesdapiPrivateGetUserTradesrO  )rl  r{  r  r  r  r  r  r  rp  r6  r  r
  currentTimestamponeWeekr  r~  s                   rn  rz  zbinance.fetch_my_trades  s	   * 	88R\]&44_feUZ\bcc
[[(F &tGH99/6SYZf%%fgyAI#,GK   $002-G 9,8O)9"hhy':G!'+;<G!(GIYYv	7';<F VJ%7E4($GG844T[[&5QRH~'2_(_``!%!C!COU[!\J $(,(G(GP_agiz  }B  )C%vv~!1$#99$++gv:VWHh&J,B!Z/04-#99$++gv:VWH#66t{{7F7STH!$#77GV8TUH#<<T[[RX=YZH	"$#77GV8TUH#<<T[[RX=YZHD   65%@@ro  c                 N   | j                          i }|||d<   | j                  |d      |d<   | j                  |d      }| j                  |d      }|||d<   | j	                  | j                  ||            }| j                  |dg       }| j                  |dd	      }	g }
t        d	|	      D ]N  }| j                  ||   d
g       }t        d	t        |            D ]  }d||   d<   |
j                  ||            P | j                  |
d||      }| j                  |||      S )aU  
        fetch all dust trades made by the user

        https://developers.binance.com/docs/wallet/asset/dust-log

        :param str symbol: not used by binance fetchMyDustTrades()
        :param int [since]: the earliest time in ms to fetch my dust trades for
        :param int [limit]: the maximum number of dust trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: 'spot' or 'margin', default spot
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nr
      X r  rp  accountTypeuserAssetDribbletsro  r   userAssetDribbletDetailsTr$  )r  r  safe_string_upperr  sapiGetAssetDribbletr  r  r  r  r  r  rO  rN  )rl  r{  r  r  r  r  r  r  r  rowsr[  r  logsr  rT  s                  rn  fetch_my_dust_tradeszbinance.fetch_my_dust_trades  sF   & 	#(GK !%%!<GI,,VV<66*"%0GM",,T[[&-IJ< ..+?D  7A6q$ 	%A>>'!*.H"MD1c$i( %)-Q&DG$%	%
 ""4ue<))&%??ro  c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  d      }|d   }|dz   |z   }	d}
|	| j                  v rd}
| j                  |d	      }|| j                  |      d
}d }d }d }d }|
r)|	}| j                  |d      }| j                  |d      }d}n.|dz   |z   }| j                  |d      }| j                  |d      }d}d }||rt        j                  ||      }d }| j                  |      }| j                  |      }| j                  |      }d }d }||| j                  |      ||||||||||dS )NtransIdoperateTime	fromAssetr  r  r  FTserviceChargeAmountr3  r%  transferedAmountr  r/  r.  )rN   r  r  r{  ro  rp  r>  r4  r  r  r%  r  r  )	r  r  r  r3  r  rj  rI   
string_divrP  )rl  r"  r  r:  r  r  tradedCurrencybnbearnedCurrencyapplicantSymboltradedCurrencyIsQuotefeeCostStringr  r{  r  
costStringr4  r  rN   r  r  r%  rp  r>  s                           rn  r?  zbinance.parse_dust_trade  s    ""5)4%%e];	%%e[9
00<mmE"V(3.? %dll*$(!((0EF&%%m4
 
 $F++E3EFL))%:JD#c)N:F++E8<L))%1CDJD!%00\J""<0!!+.  ,"Y/(
 	
ro  r  c                 d   | j                          d}| j                  |dd      \  }}|r| j                  d||||      S d}d}i }| j                  | j                  di       }	| j                  |dd      }
| j                  |d      }| j                  |d      }| j                  |d      }|
s||	v r[|| j                  |      }d	|d
<   |||d<   |||d<   | j                  | j                  ||            }| j                  |dg       }no|| j                  |      }|d   |d<   |*||d<   | j                  |d      }|t        ||      }||d<   |||d<   | j                  | j                  ||            }t        d	t!        |            D ]
  }d||   d<    | j#                  ||||      S )a  
        fetch all deposits made to an account

        https://developers.binance.com/docs/wallet/capital/deposite-history
        https://developers.binance.com/docs/fiat/rest-api/Get-Fiat-Deposit-Withdraw-History

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.fiat]: if True, only fiat deposits will be returned
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Fr   r  Nr*  r  fiatOnlyr  r   transactionType	beginTimer  r[  rN   r  r
  r  r  r  rp  )r  r  rM  r  r  r  r  r  r3  sapiGetFiatOrdersr  r  r  r  sapiGetCapitalDepositHisrecr  r  parse_transactions)rl  r  r  r  r  r  r3  r  r  r*  r  r  rawr  r  s                  rn  fetch_depositszbinance.fetch_depositsB  s     	88R\]&44_dESXZ`aa^^DLL,C
>>&&%86:.!!&'267+
*==.)*G%& ',$ %*	"((Wf)EFC~~c626H* ==."*4. ',$((5*5$!'51G%,	" #( 77GV8TUH6 q#h-( 	,A"+HQK	,&&x5%HHro  c                 D   | j                          d}| j                  |dd      \  }}|r| j                  d||||      S | j                  | j                  di       }| j                  |dd      }| j                  |d      }i }| j                  |d      }	|	| j                  |d      }|	|d	<   d}
d}|s||v rT|| j                  |      }d
|d<   |||d<   | j                  | j                  ||            }| j                  |dg       }
n_|| j                  |      }|d   |d<   |||d<   | j                  |d      |d	<   |||d<   | j                  | j                  ||            }
t        dt        |
            D ]
  }d|
|   d<    | j!                  |
|||      S )a  
        fetch all withdrawals made from an account

        https://developers.binance.com/docs/wallet/capital/withdraw-history
        https://developers.binance.com/docs/fiat/rest-api/Get-Fiat-Deposit-Withdraw-History

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.fiat]: if True, only fiat withdrawals will be returned
        :param int [params.until]: the latest time in ms to fetch withdrawals for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Fr   r  r*  r  r  r  Nr  r  r  r  r[  rN   r  r
  r  r  r   
withdrawalrp  )r  r  rM  r  r  r  r  r  r3  r  r  r  r  sapiGetCapitalWithdrawHistoryr  r  r  )rl  r  r  r  r  r  r*  r  r  r  r  r3  r  r  s                 rn  fetch_withdrawalszbinance.fetch_withdrawals  s     	88ASU_`&445GuV[]cdd^^DLL,C
>>&&%86:.!!&'2YYvw/F!&GI
*==.)*G%& ',$((Wf)EFC~~c626H@ ==."*4. ',$%)XXeZ%@	" #( 99$++gv:VWHP q#h-( 	/A".HQK	/&&x5%HHro  c                     ||S dddddddddd	ddddddddddddddd}| j                  ||i       }| j                  |||      S )Npendingr  failedr  )	r  r,  6
ProcessingFailed
Successful	RefundingRefundedRefund Failed)r  r,  2345r  r  r  r  r  r  r  )r  r  )r  r  )rl  r(  rp  statusesByTyper  s        rn   parse_transaction_status_by_typez(binance.parse_transaction_status_by_type#  s    <M  (""'&!)  (""'&!) 
@ >>.$;&&99ro  transactionr3  c                 $   | j                  |dd      }| j                  |d      }| j                  |d      }|t        |      dk  rd }| j                  |d      }||j                  d      dk\  r|d	d  }| j                  |d
d      }| j	                  ||      }d }	| j                  |dd      }	|	!| j                  | j                  |d            }	| j                  |dd      }
| j                  |d      }|L| j                  |d      }|	|dk(  rdnd}| j                  | j                  d      }| j                  |||      }| j                  | j                  |d      |      }| j                  |d      }| j                  |dd      }d }|||d}| j                  |d      }d }|	|dk7  rdnd}| j                  |d      }i d |d|d!|d"|	d#| j                  |	      d|d|d$|d%d d&|d'|d(d d|d|d)|d|d*|
|d |d+S ),NrN   orderNoaddress
addressTagr  txIdzInternal transfer r      r  fiatCurrency
insertTimer  	applyTimesuccessTimerq  rp  r  r  r  r  r+  r(  r  transactionFeetotalFeer  transferTypeTFr  r  txidr  r  	addressToaddressFromtagtagTotagFromr3  r  )internalcommentr  )r  r  r  r  r  rL  r  r  r  r  r  rO  r  rP  )rl  r  r3  rN   r  r  r  r  r  r  r  rp  txTyper+  r(  r  r  r  internalIntegerr  r  s                        rn  parse_transactionzbinance.parse_transactionI  s   B T9="";	:{L9?3x!|V4499-A#Ba#G9D''V^L
&&z8<	''\<P	t'7'7['QRI%%k=,OV4<%%k3DEF!%+s]y'+~~dllD^'_$##$<dDID66t7G7GU]7^`de!!+x8$$[2BJO#W5C++KH& /1 4t5H"";	:
K
"
 D
 	

 Y/
 w
 w
 
 4
 3
 S
 t
 D
 f
 
  f!
" w#
$ !)
 	
ro  c                 0    ddi}| j                  |||      S )N	CONFIRMEDr  r  r  s      rn  parse_transfer_statuszbinance.parse_transfer_status  s%    
 &&99ro  r   c           
         | j                  |dd      }| j                  |dd      }| j                  ||      }| j                  |d      }| j                  |d      }d }d }	| j	                  | j
                  di       }
|[|j                  d      }| j                  |d	      }| j                  |d
      }	| j                  |
||      }| j                  |
|	|	      }	| j                  |d      }|J| j	                  |di       }| j	                  |di       }| j                  |d      }| j                  |d      }	| j                  |dd      }| j                  | j                  |d            }|||| j                  |      ||||	|d	S )NtranIdtransactionIdre  r3  r  rp  r&  r  r   r  
walletType	payerInforeceiverInfo	accountIdr  transactionTimer(  )	r  rN   r  r  r3  r  fromAccount	toAccountr(  )r  r  r  r  r  r  r  r  r  rL  r  rP  )rl  r   r3  rN   r  r  r  rp  r  r  r&  r  r  payerreceiverr  r(  s                    rn  parse_transferzbinance.parse_transfer  s   F (OD''':F
&&z8<!!(H5&1	~~dllNBGJJsOE//%3Kq1I**<kRK((y)LI&&x>
!NN8["=E~~hCH**5+>K((;?I''+?PQ	++D,<,<Xx,PQ"Y/&"

 
	
ro  c           
      "   | j                  |d      }| j                  |d      }| j                  |d      }|| j                  ||d d      | j                  |      || j	                  |      | j                  |d      | j                  |d      dS )Nr{  re  rM  rZ   r  rw  )r  r{  r  r  r  rN   r  )r  r  r|  r  rP  r  )rl  rw  r  r  r  r  s         rn  parse_incomezbinance.parse_income.   s     ##FH5%%fg6
%%ff5	&&xvF++J7"Y/""684&&vx8
 	
ro  r  r  c                    | j                          | j                  |      }|d   | j                  ||      d}| j                  |d      |d<   | j	                  |d      }|d   | j                  |d      }d}	|#| j                  |      }	| j	                  |d      }| j                  |      j                         }
| j                  |      j                         }d}|	|	d   }|
dk(  r|t        | j                  dz   |z         |dk(  r|t        | j                  dz   |z         | j                  | j                  d	i       }|
|v}||v}|r|	|
}|r|	|}|s|r|
d
k(  xs |
dk(  }|d
k(  xs |dk(  }|
dk(  }|dk(  }|
dk(  xs |dk(  }|
dk(  xs |dk(  }|xs
 |xs |xs |}|s|r#|r!t        | j                  dz   |z   dz   |z         |r
|rd}
||d<   n1|r
|rd}||d<   n%|r|r|
|d<   ||d<   d}
d}n|r||d<   d}
|r||d<   d}|
dz   |z   |d<   n|
dz   |z   |d<   | j                  | j                  ||            }| j                  ||      S )a  
        transfer currency internally between wallets on the same account

        https://developers.binance.com/docs/wallet/asset/user-universal-transfer

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: exchange specific transfer type
        :param str [params.symbol]: the unified symbol, required for isolated margin transfers
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        rN   re  r  rp  Nr{  ISOLATEDz: transfer() requires params["symbol"] when fromAccount is z8 transfer() requires params["symbol"] when toAccount is r&  r  r  r  r  r  z- transfer() does not allow transfers between z and ISOLATED_MARGIN
fromSymboltoSymbolISOLATEDMARGINr  )r  r3  r  r  r  r  convert_type_to_accountrx  r4   rN   r  r  r5   sapiPostAssetTransferr  r  )rl  r  r  r  r  r  r3  r  r{  r  fromIdtoIdisolatedSymbolr&  fromIsolated
toIsolated
fromFuturetoFuturefromSpottoSpotr  r\   prohibitedWithIsolatedr  s                           rn  r   zbinance.transferH   s
    	==&d^00v>
 **66:66*6?"%%fh7FF!V,68411+>DDFF//	:@@BD!N!!'#>+DGG6r,r  vA  -A  B  Bz!>+DGG6p,ps|,|}}>>$,,KL &, 6L"l2J!'v~!%z#z1IVz5I
:-C1C!V+ I-B1B8+?tx/?)3)Tx)T7)Tf& J4J$TWW/^%^al%lov%v  zC  &C  D  D.F,:GL)*,D*8GJ'#
06-.2
+!1/'4BGL1%5F%2@GJ/#3D"(3,"5"(3,"5--dkk'6.JK ""8X66ro  c                    | j                          | j                  |d      }| j                  |d      }d}| j                  |dd      \  }}|r|s| j	                  d||||      S d}|| j                  |      }i }d}	|s;| j                  | j                  ddd      }
| j                  |d	|
      }|d
k(  rdnd
}| j                  |d|      }| j                  |d      }| j                  | j                  di       }| j                  ||      }| j                  ||      }||Ct        |j                               }t        | j                  dz   dj                  |      z         |Ct        |j                               }t        | j                  dz   dj                  |      z         |dz   |z   }||d<   d}	||||	<   |||d<   | j                  |d      }|| j                  |d      }||d<   d}|r"| j!                  | j#                  ||            }n!| j%                  | j#                  ||            }| j'                  |ddg       }| j)                  ||||      S )a  
        fetch a history of internal transfers made on an account

        https://developers.binance.com/docs/wallet/asset/query-user-universal-transfer

        :param str code: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for
        :param int [limit]: the maximum number of transfers structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch transfers for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :param boolean [params.internal]: default False, when True will fetch pay trade history
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
        r  Fr   r  Nr  r  rX   r  r[   r  rp  r%  z& fromAccount parameter must be one of z, z$ toAccount parameter must be one of r  sizer
  r  r  r  r[  )r  r  r  r  rM  r3  r  r  r  r  r  r  r0   rN   joinr  sapiGetPayTransactionsr  sapiGetAssetTransferr  parse_transfers)rl  r  r  r  r  r  r  r3  r  limitKeyr  r  	defaultTor  rp  r%  r  r  r  r  r  r  s                         rn  fetch_transferszbinance.fetch_transfers   s    	>>&*56:.88AQS]^&H445EtUTY[abb}}T*H,,T\\;K]\bcK**6=+NK#.(#:I((iHI##FF3D!^^DLL:JBON%%nkBF##NI>D|> 3 3 56D'2Z(Z]a]f]fgk]l(lmm< 3 3 56D'2X(X[_[d[dei[j(jkk|d*"GFOH %GH#(GK !!&'2YYvw/F!&GI224;;w3OPHv 00Wf1MNH  &&"=##D(E5AAro  c                 n   | j                          | j                  |      }d|d   i}| j                  | j                  di       }| j	                  |d      }| j                  |||      }|||d<   | j                  |d      }| j                  | j                  ||            }| j                  ||      S )a  
        fetch the deposit address for a currency associated with self account

        https://developers.binance.com/docs/wallet/capital/deposite-address

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network]: network for fetch deposit address
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r  rN   r'  r  )
r  r3  r  r  r  r  r  sapiGetCapitalDepositAddressr  parse_deposit_address)rl  r  r  r3  r  r'  r  r  s           rn  fetch_deposit_addresszbinance.fetch_deposit_address%!  s     	==&HTN
 >>$,,
B?((;""8Wg>!(GIYYvy1F44T[[&5QR ))(H==ro  c                 .   | j                  |d      }| j                  |d      }| j                  |d      }| j                  ||      }| j                  ||      }| j                  |dd      }t        |      dk(  rd }| j	                  |       |||||dS )Nr  r  r3  r  r  r   )r  r3  r  r  r  )r  r  get_network_code_by_network_urlr  check_address)	rl  r  r3  r  r  r  r  r  r  s	            rn  r  zbinance.parse_deposit_addressM!  s     x/""8Y7%%h
;
&&z8< ::4Ex3s8q=C7#"
 	
ro  codesc                    | j                          | j                  |      }i }t        dt        |            D ]  }||   }| j	                  |d      }| j                  |      }| j                  |dg       }	i ||<   t        dt        |	            D ]D  }
|	|
   }| j	                  |d      }| j                  |      }| j                  |d      }|||   |<   F  |i |dS )a  
 @deprecated
        please use fetchDepositWithdrawFees instead

        https://developers.binance.com/docs/wallet/capital/all-coins-info

        :param str[]|None codes: not used by binance fetchTransactionFees()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
        r   r  r  r  r  )r   r  r  )r  r  r  r  r  r  r  r  )rl  r  r  r  withdrawFeesr  r  r  r  r  r  networkEntry	networkIdr  r  s                  rn  fetch_transaction_feeszbinance.fetch_transaction_feesi!  s    	226:d  q#h-( 	6AQKE))%8J**:6D..rBK!#L1c+./ 6*1~ ,,\9E	"55i@&&|]C25T";/6	6 %
 	
ro  c                 j    | j                          | j                  |      }| j                  ||d      S )a  
        fetch deposit and withdraw fees

        https://developers.binance.com/docs/wallet/capital/all-coins-info

        :param str[]|None codes: not used by binance fetchDepositWithdrawFees()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
        r  )r  r  parse_deposit_withdraw_fees)rl  r  r  r  s       rn  fetch_deposit_withdraw_feesz#binance.fetch_deposit_withdraw_fees!  s8     	226:V //%HHro  c                 T   | j                  |dg       }| j                  |      }t        dt        |            D ]k  }||   }| j	                  |d      }| j                  |      }| j                  |d      }	| j                  |d      }
|
du r|	d d|d<   |	d dd d dd	|d
   |<   m |S )Nr  r   r  r  r  T)r  r  r   r  r'  )r  deposit_withdraw_feer  r  r  r  r  r  )rl  r  r3  r  r  r  r  r  r  r  r  s              rn  parse_deposit_withdraw_feez"binance.parse_deposit_withdraw_fee"  s    R nnS-<**3/q#k*+ 	A&q>L((yAI11)<K**<GK|[AID &"&&z" '"&
  "&	/F:{+	* ro  r  c                    | j                  ||      \  }}| j                  |       | j                          | j                  |      }|d   || j	                  ||      d}|||d<   | j                  | j                  di       }| j                  |d      }	| j                  ||	|	      }	|	|	|d<   | j                  |d      }| j                  | j                  ||            }
| j                  |
|      S )a  
        make a withdrawal

        https://developers.binance.com/docs/wallet/capital/withdraw

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        rN   )r  r  r  r  r'  r  )handle_withdraw_tag_and_paramsr
  r  r3  r  r  r  r  r  r  sapiPostCapitalWithdrawApplyr  r  )rl  r  r  r  r  r  r3  r  r'  r  r  s              rn  r   zbinance.withdrawT"  s     99#vFV7#==&TN00v>
 ?$'GL!>>$,,
B?((;""8Wg>!(GIYYvy1F44T[[&5QR%%h99ro  r  c                     | j                  |d      }| j                  ||d d      }||| j                  |dd      | j                  |dd      d d dS )Nr{  rX   makerCommissionmakerCommissionRatetakerCommissiontakerCommissionRate)r  r{  r  r  r  r  )r  r|  rO  )rl  r  r  r  r{  s        rn  parse_trading_feezbinance.parse_trading_feex"  sj    $ ##C2!!(FD&A''->@UV''->@UV
 	
ro  c                    | j                          | j                  |      }|d   }d}| j                  d||      \  }}d}| j                  |dddd      \  }}| j	                  ||      }| j                  ||      }d|d   i}	d}
|rF|r"| j                  | j                  |	|            }
n| j                  | j                  |	|            }
ni|rF|r"| j                  | j                  |	|            }
nC| j                  | j                  |	|            }
n!| j                  | j                  |	|            }
|
}t        |t              r| j                  |d	i       }| j                  ||      S )
a  
        fetch the trading fees for a market

        https://developers.binance.com/docs/wallet/asset/trade-fee
        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/User-Commission-Rate
        https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/User-Commission-Rate
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-User-Commission-Rate-for-UM
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-User-Commission-Rate-for-CM

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch trading fees in a portfolio margin account
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        rp  Nr   r  re  Fr{  rN   r   )r  r  r  r  rw  ru  papiGetUmCommissionRater  fapiPrivateGetCommissionRatepapiGetCmCommissionRatedapiPrivateGetCommissionRatesapiGetAssetTradeFeer  r  r  r  )rl  r{  r  r  rp  rq  r~  isLinear	isInverser  r  r[  s               rn  fetch_trading_feezbinance.fetch_trading_fee"  ss     	V$f~99:KVU[\ $($C$CFL]_egxz  %A!6>>$0OOD'2	fTl
  77GV8TU<<T[[RX=YZ 77GV8TU<<T[[RX=YZ00Wf1MNH( dD!>>$2.D%%dF33ro  c                 t   | j                          d}| j                  dd|      \  }}d}| j                  dd|d      \  }}|dk(  xs |dk(  }| j                  ||      }| j	                  ||      }d}|r| j                  |      }n'|r| j                  |      }n|r| j                  |      }|r<i }t        dt        |            D ]   }	| j                  ||	         }
|
d   }|
||<   " |S |rt        | j                  j                               }i }| j                  |d      }| j                  d   d	   d
   }|d   |   d   }|d   |   d   }t        dt        |            D ](  }	||	   }| j                  |   }|d   sd|i|||d||<   * |S |rt        | j                  j                               }i }| j                  |d      }| j                  d   d	   d
   }|d   |   d   }|d   |   d   }t        dt        |            D ](  }	||	   }| j                  |   }|d   sd|i|||d||<   * |S y)a  
        fetch the trading fees for multiple markets

        https://developers.binance.com/docs/wallet/asset/trade-fee
        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Information-V2
        https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Account-Information
        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Config

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        Nr   r  rX   rY   r   r{  feeTierr  r  r  r  r  )r  r{  r  r  r  )r  r  r  rw  ru  r%  fapiPrivateGetAccountConfigr  r  r  r  r  r  r  r  r  )rl  r  rp  rq  isSpotOrMarginr&  r'  r  r  r  r  r{  r  r*  feeTiersr  r  r  s                     rn  fetch_trading_feeszbinance.fetch_trading_fees"  s    	99:LdTZ[f99:LdTZ\de&.?dh.>>>$0OOD'2	008H77?H11&9Hb  F1c(m, %,,Xa[9X!$v% M, 4<<,,./GF'')<Gyy*95g>HW%g.q1EW%g.q1E1c'l+  f-(# &w! #)!&!&&F6N	 M 4<<,,./GF'')<Gyy+I6w?HW%g.q1EW%g.q1E1c'l+  f-)$ &w! #)!&!&&F6N	 Mro  c                     |dk  s|dkD  rt        | j                  dz         | j                          | j                  |      }|d   ||d}| j	                  | j                  ||            }| j                  ||      S )u  
 @ignore
        transfer between futures account

        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/New-Future-Account-Transfer

        :param str code: unified currency code
        :param float amount: the amount to transfer
        :param str type: 1 - transfer from spot account to USDT-Ⓜ futures account, 2 - transfer from USDT-Ⓜ futures account to spot account, 3 - transfer from spot account to COIN-Ⓜ futures account, 4 - transfer from COIN-Ⓜ futures account to spot account
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float params.recvWindow:
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=futures-transfer-structure>`
        r  r  z type must be between 1 and 4rN   )re  r  rp  )r4   rN   r  r3  sapiPostFuturesTransferr  r  )rl  r  r  rp  r  r3  r  r  s           rn  futures_transferzbinance.futures_transfer#  s     1H$(#DGG.M$MNN==&d^

 //GV0LM ""8X66ro  c                 Z   | j                          | j                  |      }d|d   i}d}|d   r"| j                  | j                  ||            }n?|d   r"| j	                  | j                  ||            }nt        | j                  dz         |d   r|d   }| j                  ||      S )a  
        fetch the current funding rate

        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-and-Mark-Price

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        r{  rN   Nr  r  z> fetchFundingRate() supports linear and inverse contracts onlyr   )r  r  r  r  r  r?   rN   parse_funding_raterl  r{  r  r  r  r  s         rn  fetch_funding_ratezbinance.fetch_funding_rate#  s     	V$fTl
 (55dkk'66RSHI55dkk'66RSHtww)iijj){H &&x88ro  c                 V   | j                          i }d}| j                  |dd      \  }}|r| j                  d|||d|      S | j                  | j                  ddd      }| j                  |d|      }d}	|| j                  |      }	|	d	   }|	d
   |d	<   d}
| j                  d|	|d      \  }
}| j                  |d      }|||d<   | j                  |d      }| j                  |d|      }| j                  |ddg      }|||d<   |||d<   d}| j                  ||
      r"| j                  | j                  ||            }nR| j                  ||
      r"| j                  | j                  ||            }nt        | j                   dz   |z   dz         | j#                  ||	||      S )a  
        fetches historical funding rate prices

        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Get-Funding-Rate-History
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Get-Funding-Rate-History-of-Perpetual-Futures

        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: timestamp in ms of the earliest funding rate to fetch
        :param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>` to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest funding rate
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :param str [params.subType]: "linear" or "inverse"
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
        Fr   r  r   r  r[   rp  Nr{  rN   r  r
  r  r  r  z0 fetchFundingRateHistory() is not supported for  markets)r  r  r  r  r  r  r  r  r  r  rw  fapiPublicGetFundingRater  ru  dapiPublicGetFundingRater?   rN   parse_funding_rate_histories)rl  r{  r  r  r  r  r  r  rp  r  rq  r  r  r  s                 rn  fetch_funding_rate_historyz"binance.fetch_funding_rate_history#  s     	88AZ\fg&::;TV\^cejlprxyy((7PR_aij<[[(FH%F &tGH99:SU[]cemn66*#(GK !!&'2##FIu=6Iw#78!(GI$GG>>$(44T[[&5QRH__T7+44T[[&5QRHtww)[[^bbeoopp 0065%PPro  c                     | j                  |d      }|| j                  | j                  |d      d d d      | j                  |d      || j	                  |      dS )NfundingTimer{  rZ   rX  )r  r{  rX  r  r  )r  r|  r  r  rP  )rl  r  r  r  s       rn  parse_funding_rate_historyz"binance.parse_funding_rate_history#  se     %%h>	&&t'7'7('KTSWY_`++HmD"Y/
 	
ro  c                    | j                          | j                  |      }| j                  | j                  ddd      }| j	                  |d|      }d}| j                  dd|d      \  }}| j                  |d      }d}| j                  ||      r| j                  |      }n<| j                  ||      r| j                  |      }nt        | j                  dz         | j                  ||      S )a  
        fetch the funding rate for multiple markets

        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-and-Mark-Price

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rates-structure>`, indexed by market symbols
        r   r  r[   rp  Nr  z? fetchFundingRates() supports linear and inverse contracts only)r  r  r  r  r  r  r  rw  r  ru  r  r?   rN   parse_funding_rates)rl  r  r  r  rp  rq  r  r  s           rn  fetch_funding_rateszbinance.fetch_funding_rates$  s     	%%g.((7JM[cd<99:MtU[]ef		&&)>>$(55e<H__T7+55e<Htww)jjkk'''::ro  c                 .   | j                  |d      }| j                  |d      }| j                  ||d d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	| j                  |d      }
| j                  |d	      }| j                  |d
      }d }||dz   }i d|d|d|d|d|d|	d|d| j	                  |      d|
d|d| j	                  |      dd dd dd dd dd dd d|iS )NrM  r{  r  r  r  interestRateestimatedSettlePricelastFundingRatenextFundingTimefundingIntervalHourshr  r  r  rX  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer  )r  r  r|  r  rP  )rl  r  r  r  r  r{  r  r  rC  rD  rX  r=  r  intervalStrings                 rn  r3  zbinance.parse_funding_rate+$  s   4 %%h7	##Hh7!!(FD*E$$X{;	%%h=
''.A#//:PQ&&x1BC''2CD##H.DE%^N
H
f
 
 *	

 L
 #$8
 
 Y/
 ;
 
 t||K8
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 	
ro  c           	         | j                  |d      }| j                  |dg       }i }t        dt        |            D ]j  }||   }| j                  |d      }| j	                  |      }	| j                  |d      }
| j                  |d      }t        j                  |
|      |
d||	<   l g }t        dt        |            D ]  }||   }| j                  |d      }| j                  |d d d	      }|d
   r|d   n|d   }	| j                  |d      }|dk7  xr |dk7  }|r|s`|	|v se| j                  | j                  |||	   d   ||	   d   d      |      }|j                  |        |S )N	positionsrt  r   re  crossWalletBalance
crossUnPnl)crossMarginrT  r{  r  r  r  r  maintMarginr  z
0.00000000rV  )r  r  r  r  r  rI   rb  r  parse_account_positionr  r  )rl  rt  filterClosedrS  rt  rr  r  r  r  r  rT  rU  r  r  r  r  maintenanceMarginisPositionOpenparseds                      rn  parse_account_positionszbinance.parse_account_positionsg$  s   NN7K8	26q#f+& 		A1IE))%9J**:6D!%!1!1%9M!N))%>J&112DjQ&8HTN		 q#i.) 	*A |H''(;H%%hdJGF&,X&66'?F6ND $ 0 0= I/36_=NR^=^N>8#!88X'/~m'D.6tn=Q.RP :  F MM&)	*  ro  c           
         | j                  |d      }| j                  ||d d      }| j                  |d      }| j                  |d      }|t        |      nd }| j                  |d      }| j                  |      }d }	|Xt	        j
                  d|d      }	| j                  d|z        }
|
s+t	        j
                  t	        j                  |	d      dd      }	d	|v }| j                  |d
      }| j                  |      }| j                  |d      }| j                  |      }| j                  |d	d      }t	        j                  |      }| j                  |      }| j                  |d      }t	        j                  |      }|}t	        j                  t	        j                  ||      |      }| j                  |d      }t	        j
                  ||      }t	        j
                  t	        j                  |d      dd      }| j                  |      }| j                  | j                  di       }| j                  ||g       }d }t        dt        |            D ]'  }||   }t	        j                   ||d         r n|d   }) | j                  |      }| j                  |d      }| j                  |      }| j#                  |d      } | dk(  rd } | j%                  |d      }!|!)| j                  |d      }"t	        j&                  |"d       }!d }#d }$d }%|!r+d}#| j                  |d      }%t	        j                  |%|      }$n&d}#| j                  |d      }%| j                  |d      }$| j                  |$      }&d }'d }(d })d }*d }+| j)                  |d      },| j+                  |,      }-t	        j,                  |d      rd }nt	        j                   |d      rdnd}(| j                  t	        j
                  t	        j                  t	        j
                  ||$      d      dd            }'| j                  t	        j                  t	        j
                  ||d      d             })|rd }.|}/|(dk(  rt	        j                  d|      }.n,t	        j                  d!|      }.t	        j                  d!|/      }/t	        j
                  |%t	        j                  ||.            }0t	        j
                  |/|.      }1t	        j                  |0|1      }*nd }.|}/|(dk(  rt	        j.                  d|      }.n,t	        j.                  d!|      }.t	        j                  d!|/      }/t	        j                  ||-      }2t	        j                  |2|.      }0t	        j.                  t	        j                  t	        j
                  d|/      |2      |%      }1t	        j
                  |0|1      }*| j1                  | j                  |d"   d#            }3|3dz   }4t3        |4      }5t	        d$|5z         }6t3        |6      }7t	        j                  |7|*      }8t	        j
                  |8d|3      }9|9d   d%k(  rd }9| j                  |9      }+| j                  |d&      }:|:d'k7  };i d(|d)d d|d*| d+| j5                  |       d|d,| j                  |	      d-|d.|d|d	|d| j                  |      d/|d0|d|,d1|'d2|+d |&|#|(|;|)d3S )4Nr{  r  r  rz  r,  r  rR  1e-8rI  rW  
entryPricenotionalValuepositionAmtr  z0.5r   leverageBracketsr  unrealizedProfitrq  r1  isolatedMarginr  isolatedWalletr  rT  rV  shortlong5e-5r  r  r6  r  r  z5e-r~  r  BOTHr  rN   r  r  initialMarginPercentagerZ  maintenanceMarginPercentageunrealizedPnl	contractsmarginRatioliquidationPrice)r  
collateralr6  r4  r>  r  )r  r  intrj  rI   r  is_round_numberrb  r  
string_absr  r  r  r  r  r  	string_ltr  r  r  r  r  string_equals
string_subprecision_from_stringr  rP  )<rl  r  r  r  r{  leverageStringr  initialMarginStringrz  initialMarginPercentageStringrationalusdmmaintenanceMarginStringrZ  entryPriceStringr`  notionalStringnotionalStringAbsrI  contractsStringcontractsStringAbsentryNotionalcontractSizeNewrn  rc  rx  !maintenanceMarginPercentageStringr  bracketrl  unrealizedPnlStringrm  r  r1  isolatedMarginRawr6  collateralStringwalletBalancerq  ro  r4  r  liquidationPriceStringRawrp  r  contractSizeString(onePlusMaintenanceMarginPercentageStringentryPriceSignStringleftSide	rightSider  r7  pricePrecisionPlusOnepricePrecisionPlusOneStringrounderrounderStringliquidationPriceRoundedStringtruncatedLiquidationPricer  r>  s<                                                               rn  rX  zbinance.parse_account_position$  s   p ##Hh7!!(FD*E!!&(3))(J?+9+E3~&D"..xI))*=>(,%%,3,>,>sNTU,V)++D8O<H070B0B7CUCUVsu{C|  B  DE  1F-h&"&"2"28]"K --.EF++HlC&&'78
++Hj/R#..~>$$%67**8]C$//@"#..w/A/A.Re/fhxyM"..v~FO%00PO!(!3!3G4F4FX]4^`cef!g%%&89	>>$,,8JBO..)962F,0)q#o./ 	;A%a(G  !2GAJ?07
-		;
 '+&7&78Y&Z#"..x9KL))*=>%%h=	>I>>(J7 $ 0 0;K L",,->DDH
#J ,,X7GHM&11-ATU J ,,X7KLM#//-H&&'78

$(!v~>!22<@  5J%//D7&D++G,>,>w?Q?QRYRdRde|  O  SP  RX  @Y  [^  `a  -b  cK**7+=+=g>P>PQdfy{|>}  @E  ,F  GJ <@8'7$7??F?Q?QRUWx?y<?F?Q?QRVXy?z<+2+=+=dDX+Y("--mW=O=OPb  eM  >N  O#../CEmn	,3,>,>x,S) <@8'7$7??F?Q?QRUWx?y<?F?Q?QRVXy?z<+2+=+=dDX+Y())*<>PQ"--d4\]#..w/A/A'BTBTUXZnBoqu/v  yF  G	,3,>,>x,S)!778H8HP[I\^e8fgN$2Q$6!*-.C*D'e&AABGLM,3,>,>}Ng,h)(/(:(:;XZ]_m(n%(+s2 -1)#001JK''.A'
H
$
 f
 	

 Y/
 ]
 &t'8'89V'W
  !2
 *+F
 *
 
 )).9
 ]
 
 L
  ;!
"  0#
$ $$$/
 	
ro  c                    | j                  |d      }| j                  ||d d      }| j                  |d      }| j                  |d      }| j                  | j                  di       }| j	                  ||g       }| j                  |dd      }t        j                  |      }	d }
t        dt        |            D ]'  }||   }t        j                  |	|d         r n|d   }
) | j                  |	      }t        j                  | j                  |d	            }| j                  |      }| j                  |d
      }| j                  |      }| j                  | j                  |d            }| j                  |      }d }| j                  |d      }||t        j                  |d      rdnd}d }t        j                  |d      rd}nt        j                  |d      rd}| j                  |d      }| j                  |      }| j                  |d      }| j!                  |      }d|v }|dk(  r | j                  |di       }| j                  |d      }| j                  |dd      }|d u xr |d u }|s|rd } |}!|dk(  r-t        j"                  d|
      } t        j$                  d|!      }!nt        j"                  d|
      } t        j$                  ||       }"t        j"                  |"|!      }#| j'                  | j                  |dd            }$|$.t        j(                  t        j$                  |#|      d|$      }nd } |}!|dk(  rt        j*                  d|
      } n,t        j*                  d|
      } t        j$                  d|!      }!t        j$                  ||      }#t        j*                  t        j(                  d|!      t        j(                  | |            }%| j'                  | j                  |d            }&|&>t        j(                  t        j$                  |#|%      d|&      }n| j                  |d      }|dn|}| j                  |      }'| j                  | j                  | j                  |d                  }(| j-                  |d      })|)dk(  rd })| j                  |
      }*t        j$                  |
|	      }+|+| j                  |d      }+| j                  |+      },d }-d }.| j                  |d      }/|/|t/        |/      }0| j1                  d|0z        }1t        j(                  d|/d      }.|1st        j"                  |.d       }.t        j$                  |	|.      }2t        j(                  |2dd      }-n?| j                  |d!      }-t        j$                  |-d      }2t        j(                  |2|	d      }.d }3d }4t        j2                  |d      s| j                  t        j(                  t        j"                  t        j(                  |+|      d"      dd#            }3| j                  t        j$                  t        j(                  ||-d#      d$            }4| j                  |d%      }5|5d&k7  }6i d'|d(d d|d)|d|d*|d| j                  |/      d|d+|'d|d|(d|d,|)d!| j                  |-      d-| j                  |.      d.|,d/|*|3| j5                  |)      ||||6|4d d d0	S )1Nr{  r  re  rc  rI  ra  r   r  rb  unRealizedProfitrp  r  r  r  r1  rh  rg  r`  r  r  r  r  r  r,  r6  r  rq  rW  r  rR  r  r_  rz  ri  r  r  r  rj  r  rN   rn  rm  rq  r  rk  rZ  rl  )	ro  r  r6  r  r4  r>  r  r:  r;  )r  r  r  r  r  r  rI   rt  r  r  ru  rj  r  r  r  r  r  rb  r  rx  r  rw  r  rr  rs  rv  rP  )7rl  r  r  r  r{  isolatedMarginStringrc  rx  r  r  r  r  r  rI  contractsAbsrn  r  rm  liquidationPriceStringrp  r  r6  r4  r  r`  r  r  r  r  basePrecisionValuequotePrecisionValueprecisionIsUndefinedr  r  innerr  r:  r  basePrecisionrq  r  r  rl  r~  rZ  rz  r{  ry  r  r|  	unroundedro  r  r  r>  s7                                                          rn  parse_position_riskzbinance.parse_position_riskt%  s   l ##Hh7!!(FD*E!!&(3#//:JK>>$,,8JBO..)962F++Hj/R#..~>,0)q#o./ 	;A%a(G  !2GAJ?07
-		;
 $$%67))$*:*:8]*ST%%l3	"..x9KL))*=>!%0@0@K]0^!_,,-CD%%h=
"6"B$+$5$56JC$PV`J^S1D~s3D++HlC&&'78
v~>!22<@( v{B?I!%!1!1)V!D"&"4"4Y"Q$6$$>#aEX\`E` '?C<+;(wCJCUCUVY[|C}@/6/A/A$H\/],CJCUCUVZ\}C~@#../EGopE&11%9MNH%)%?%?@R@RS\^egn@o%pN%1+2+=+=g>P>PQY[g>hjmo}+~( @D<+;(wCJCUCUVY[|C}@CJCUCUVZ\}C~@/6/A/A$H\/],&11,@RSH ' 2 273E3EcK_3`bibtbt  v^  `v  cw  !xI$($>$>t?O?OPY[a?b$cM$0+2+=+=g>P>PQY[d>egjly+z(#//:JK#3#;3BR&&'78
%%dnnT5E5EhP[5\&]^	%%h=	>I&*&7&78Y&Z#")"4"45VXi"j"*&*&6&6x&O# --.EF"(,%))(J?%>*H++D8O<H,3,>,>sNTU,V)070B0BC`bh0i-**+<>[\I")"4"4YQ"G"&"2"28_"M**+>DI,3,>,>yJ[]^,_)
$$%5s;++G,>,>w?Q?QRYRdRde|  O  SP  RX  @Y  [^  `a  -b  cK**7+=+=g>P>PQdfy{|>}  @E  ,F  GJ''.A'
H
$
 f
 	

 L
 ]
 )).9
  0
 *
 
 
 *
 
 T../BC
 &t'8'89V'W
   !2!
" *+F#
$ 'Y/$$$!#5
 	
ro  c                 $   | j                          | j                  | j                  d      }||r| j                  | j                  dd      }| j                  |d|      }| j	                  |d      }d }| j                  dd |d      \  }}d }| j                  |dddd	      \  }}d }	| j                  ||      r&|r| j                  |      }	nb| j                  |      }	nP| j                  ||      r&|r| j                  |      }	n*| j                  |      }	nt        | j                  d
z         i | j                  d<   t        dt!        |	            D ]  }
|	|
   }| j                  |d      }| j#                  |d d d      }| j%                  |dg       }g }t        dt!        |            D ]?  }||   }| j'                  |dd      }| j                  |d      }|j)                  ||g       A || j                  d   |<    | j                  d   S )Nrc  r  r[   rp  loadLeverageBracketsr  r  re  FzB loadLeverageBrackets() supports linear and inverse contracts onlyr   r{  r  bracketsnotionalFloorqtyFloormaintMarginRatio)r  r  r  r  r  r  r  rw  papiGetUmLeverageBracketfapiPrivateGetLeverageBracketru  papiGetCmLeverageBracketdapiPrivateV2GetLeverageBracketr?   rN   r  r  r|  r  r  r  )rl  reloadr  rc  r  rp  r  rq  r~  r  r  r  r  r{  r  r  r  r  
floorValuerl  s                       rn  load_leverage_bracketszbinance.load_leverage_bracketsR&  s7     >>$,,8JK$&**4<<QK##FFK@DIIff-EG"==>TVZ\bdlmOGV $(,(G(GPfhn  qB  DI  )J%vH~~dG,$#<<UCH#AA%HHw/$#<<UCH#CCEJH"477-q#qrr/1DLL+,1c(m, B ++E8<))(D$
K>>%R@q#h-0 MA&qkG!%!3!3G_j!YJ262B2B7L^2_/MM:/J"KL	M
 <B/08B ||.//ro  c                    | j                          d}| j                  dd|      \  }}d}| j                  dd|d      \  }}d}| j                  |dddd      \  }}d}| j	                  ||      r&|r| j                  |      }nb| j                  |      }nP| j                  ||      r&|r| j                  |      }n*| j                  |      }nt        | j                  dz         | j                  ||d      S )	aH  
        retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes

        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Notional-and-Leverage-Brackets
        https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Notional-Bracket-for-Pair
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/UM-Notional-and-Leverage-Brackets
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/CM-Notional-and-Leverage-Brackets

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch the leverage tiers for a portfolio margin account
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a dictionary of `leverage tiers structures <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`, indexed by market symbols
        Nr   r  r  re  Fz@ fetchLeverageTiers() supports linear and inverse contracts onlyr{  )r  r  r  r  rw  r  r  ru  r  r  r?   rN   parse_leverage_tiers)rl  r  r  rp  rq  r~  r  s          rn  fetch_leverage_tierszbinance.fetch_leverage_tiers{&  s    	99:NPTV\]f99:NPTV\^fg $($C$CFL`bhj{  ~C  %D!6>>$( 88@==fE__T7+ 88@??Gtww)kkllN ((7HEEro  c                    | j                  |d      }| j                  ||dd      }| j                  |dg       }g }t        dt	        |            D ]  }||   }|j                  | j                  |d      | j                  ||      |d   | j                  |dd	      | j                  |d
d      | j                  |d      | j                  |d      |d        |S )zs
 @ignore
        :param dict info: Exchange response for 1 market
        :param dict market: CCXT market
        r{  Nr  r  r   r  r  r  r  notionalCapqtyCapr  initialLeverage)tierr{  r3  rH  rJ  maintenanceMarginRatemaxLeverager  )	r  r  r  r  r  r  r  r|  rO  )rl  r  r  r  r  r  r  r  s           rn  parse_market_leverage_tiersz#binance.parse_market_leverage_tiers&  s    , ##D(3!!(FD*E>>$
B7q#h-( 	AqkGLL(()<**8V<"7O#11'?JW#11'=(S)-)9)9'CU)V#//9JK	 		 ro  c                     | j                          | j                  |      }|d   st        | j                  dz         d|d   i}| j	                  | j                  ||            }| j                  |d   |      S )a  
        fetch data on an open position

        https://developers.binance.com/docs/derivatives/option/trade/Option-Position-Information

        :param str symbol: unified market symbol of the market the position is held in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        r\   z- fetchPosition() supports option markets onlyr{  rN   r   )r  r  r?   rN   eapiPrivateGetPositionr  parse_positionr4  s         rn  fetch_positionzbinance.fetch_position&  s     	V$htww)XXYYfTl
 ..t{{7F/KL0 ""8A;77ro  c                    | j                          | j                  |      }i }d}|[d}t        |t              r.t	        |      }|dkD  rt        | j                  dz         |d   }n|}| j                  |      }|d   |d<   | j                  | j                  ||            }g }t        dt	        |            D ]&  }	|j                  | j                  ||	   |             ( | j                  |d|d      S )a  
        fetch data on open options positions

        https://developers.binance.com/docs/derivatives/option/trade/Option-Position-Information

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
        Nr  zD fetchPositions() symbols argument cannot contain more than 1 symbolr   rN   r{  F)r  r  r  r  r  r5   rN   r  r  r  r  r  r  filter_by_array_positions)
rl  r  r  r  r  r{  symbolsLengthr  r  r  s
             rn  fetch_option_positionszbinance.fetch_option_positions'  s    	%%g.F'4( #G 1$$TWW/u%uvv  [[(F &tGH..t{{7F/KL0 q#h-( 	DAMM$--hqk6BC	D--fhOOro  r  c           
      p   | j                  |d      }| j                  ||d d      }|d   }| j                  |d      }| j                  |d      }|dk7  rt        j                  d|      }| j                  |d      }| j                  i d|d	d d|d
| j                  |d
      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d|d| j                  |      dd d|d| j                  |      dd dd dd dd d d d d d d d      S )Nr{  rZ   r4  r'  rh  r6  rM  r  rN   r`  r  rI  	markValuerq  positionCostrm  unrealizedPNLrn  r  r  r  r>  rZ  rl  rz  )rk  r  rp  ro  r6  r  )
r  r  rK  rI   r  r  safe_positionr  rj  rP  )rl  r  r  r  r{  r4  r'  r  s           rn  r  zbinance.parse_positionO'  s   , ##Hh7!!(FD&A!%%h7##Hj96>))$9H%%h7	!! #
H#
$#
 f#
 $**8\B	#

 ))(K@#
 ((;?#
 $**8^D#
 T--hH#
 D#
 **84#
 D#
 #
 Y/#
 d#
  #
  *4!#
" T##
$ (, $/#
  	ro  c                 x   d}| j                  |dd      \  }}|>| j                  | j                  d      }|| j                  | j                  dd      }nd}|dk(  r| j	                  ||      S |dk(  r| j                  ||      S |dk(  r| j                  ||      S t        | j                  dz   |z   dz         )	a  
        fetch all open positions

        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Information-V2
        https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Account-Information
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Position-Information-V2
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Position-Information
        https://developers.binance.com/docs/derivatives/option/trade/Option-Position-Information

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param dict [params.params]: extra parameters specific to the exchange API endpoint
        :param str [params.method]: method name to call, "positionRisk", "account" or "option", default is "positionRisk"
        :param bool [params.useV2]: set to True if you want to use the obsolete endpoint, where some more additional fields were provided
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Nr   rH  ru  rt  r\   z<.options["fetchPositions"]["method"] or params["method"] = "zJ" is invalid, please choose between "account", "positionRisk" and "option")	r  r  r  r  fetch_positions_riskfetch_account_positionsr  r?   rN   )rl  r  r  defaultMethodr  s        rn  fetch_positionszbinance.fetch_positions'  s    "  $ = =fFVX` av nnT\\3CDG $ 0 0?OQ_ ` .N*,,Wf==i'//@@h&..w??tww)ggjww  {G   G  H  Hro  c                    |(t        |t              st        | j                  dz         | j	                          | j                  d|       | j                  | j                  dd      }| j                  |d|      }| j                  |d      }d}| j                  dd|d      \  }}d}| j                  |dd	d
d      \  }}d}| j                  ||      rS|r| j                  |      }nd}| j                  |ddd      \  }}|s| j                  |      }nb| j                  |      }nP| j!                  ||      r&|r| j#                  |      }n*| j%                  |      }nt'        | j                  dz         d}	| j                  |ddd      \  }	}| j)                  ||	      }
| j+                  |      }| j-                  |
d|d      S )a   
 @ignore
        fetch account positions

        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Information-V2
        https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Account-Information
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Position-Information-V2
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Position-Information
        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Information-V3

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch positions in a portfolio margin account
        :param str [params.subType]: "linear" or "inverse"
        :param boolean [params.filterClosed]: set to True if you would like to filter out closed positions, default is False
        :param boolean [params.useV2]: set to True if you want to use obsolete endpoint, where some more additional fields were provided
        :returns dict: data on account positions
        Nz8 fetchPositions() requires an array argument for symbolsFr  r[   rp  fetchAccountPositionsr  r  re  r  z< fetchPositions() supports linear and inverse contracts onlyrY  r{  )r  r  r4   rN   r  r  r  r  r  r  r  rw  papiGetUmAccountr  r  r  ru  papiGetCmAccountr  r?   r]  r  r  )rl  r  r  r  rp  rq  r~  r  r  rY  r  s              rn  r  zbinance.fetch_account_positions'  s   & gt,'2l(lmm##E62&&t||]HM<66*99:QSWY_aij $($C$CFLcekm~  AF  %G!6>>$( 008 $ = =fF]_fhm nv#;;FCH#;;FCHF __T7+ 00855f=tww)gghh#<<VE\^lnstf--hE%%g.--fhOOro  c                    |(t        |t              st        | j                  dz         | j	                          | j                  d|       i }d}| j                  | j                  d|      }| j                  |d|      }d}| j                  dd|d      \  }}d}| j                  |dd	d
d      \  }}| j                  |d      }d}| j                  ||      ru|r"| j                  | j                  ||            }nd}	| j                  |ddd      \  }	}| j                  ||      }|	s| j                  |      }n| j!                  |      }np| j#                  ||      rF|r"| j%                  | j                  ||            }n:| j'                  | j                  ||            }nt)        | j                  dz         g }
t+        dt-        |            D ]S  }||   }| j                  |d      }t/        j0                  |d      s1|
j3                  | j5                  ||                U | j7                  |      }| j9                  |
d|d      S )az  
 @ignore
        fetch positions risk

        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Position-Information-V2
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Position-Information
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-UM-Position-Information
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-CM-Position-Information
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Position-Information-V3

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch positions for a portfolio margin account
        :param str [params.subType]: "linear" or "inverse"
        :param bool [params.useV2]: set to True if you want to use the obsolete endpoint, where some more additional fields were provided
        :returns dict: data on the positions risk
        Nz< fetchPositionsRisk() requires an array argument for symbolsFr[   r  rp  r   r  r  re  r  z@ fetchPositionsRisk() supports linear and inverse contracts onlyr   r`  r  r{  )r  r  r4   rN   r  r  r  r  r  r  r  rw  papiGetUmPositionRiskr  r  fapiPrivateV3GetPositionRiskfapiPrivateV2GetPositionRiskru  papiGetCmPositionRiskdapiPrivateGetPositionRiskr?   r  r  rI   r  r  r  r  r  )rl  r  r  r  r  rp  rq  r~  r  r  r  r  rawPositionr  s                 rn  r  zbinance.fetch_positions_risk"(  sW   $ gt,'2p(pqq##E62&&t||]KP<99:NPTV\^fg $($C$CFL`bhj{  ~C  %D!666*>>$( 55dkk'66RS $ = =fFZ\cej kvWf5#@@HH#@@HH6 __T7+ 55dkk'66RS::4;;wPV;WXtww)kklld q#h-( 	EA"1+K#//\J  !137d66x{CD		E
 %%g.--fhOOro  c                    | j                          d}ddi}|6| j                  |      }|d   |d<   |d   st        | j                  dz         d}| j	                  d||d	      \  }}d}| j                  |dd
dd      \  }}| j                  d||      \  }}|||d<   |||d<   | j                  | j                  ddd      }	| j                  |d|	      }
| j                  |d      }d}| j                  |
|      rF|r"| j                  | j                  ||            }n| j                  | j                  ||            }np| j                  |
|      rF|r"| j!                  | j                  ||            }n:| j#                  | j                  ||            }nt        | j                  dz         | j%                  ||||      S )a  
        fetch the history of funding payments paid and received on self account

        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Income-History
        https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Income-History
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Income-History
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-CM-Income-History

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch funding history for
        :param int [limit]: the maximum number of funding history structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest funding history entry
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch the funding history for a portfolio margin account
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
        N
incomeTypeFUNDING_FEErN   r{  rZ   z3 fetchFundingHistory() supports swap contracts onlyr   r  r  re  Fr  r
  r  r  r[   rp  zA fetchFundingHistory() supports linear and inverse contracts only)r  r  r?   rN   r  r  r)  r  r  r  r  rw  papiGetUmIncomer  fapiPrivateGetIncomeru  papiGetCmIncomedapiPrivateGetIncomeparse_incomes)rl  r{  r  r  r  r  r  rq  r~  r  rp  r  s               rn  fetch_funding_historyzbinance.fetch_funding_history(  s   $ 	-
 [[(F &tGH&>"477-b#bcc99:OQWY_aij $($C$CFLacik|  D  %E!6229gvN#(GK $GG((7Lm]ef<66*>>$( //GV0LM44T[[&5QR__T7+ //GV0LM44T[[&5QRtww)llmm!!(FE5AAro  r  c                 h   |t        | j                  dz         |dk  s|dkD  rt        | j                  dz         | j                          | j	                  |      }|d   |d}d}| j                  |dd	d
d      \  }}d}|d   rH|r#| j                  | j                  ||            }|S | j                  | j                  ||            }|S |d   rH|r#| j                  | j                  ||            }|S | j                  | j                  ||            }|S t        | j                  dz         )a|  
        set the level of leverage for a market

        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Initial-Leverage
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Change-Initial-Leverage
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-UM-Initial-Leverage
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-CM-Initial-Leverage

        :param float leverage: the rate of leverage
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.portfolioMargin]: set to True if you would like to set the leverage for a trading pair in a portfolio margin account
        :returns dict: response from the exchange
        Nz) setLeverage() requires a symbol argumentr  }   z% leverage should be between 1 and 125rN   )r{  r  r   r  re  Fr  r  z9 setLeverage() supports linear and inverse contracts only)r4   rN   r5   r  r  r  papiPostUmLeverager  fapiPrivatePostLeveragepapiPostCmLeveragedapiPrivatePostLeverager?   )rl  r  r{  r  r  r  r~  r  s           rn  set_leveragezbinance.set_leverage )  sV    >#DGG.Y$YZZ qLhnTWW'NNOOV$Tl 
 !$($C$CFM[actv{$|!6( 224;;w3OP   77GV8TU  I 224;;w3OP
   77GV8TU  tww)ddeero  r6  c                 p   |t        | j                  dz         |j                         }|dk(  rd}|dk7  r|dk7  rt        | j                  dz         | j	                          | j                  |      }|d   |d}d}	 |d	   r#| j                  | j                  ||            }|S |d
   r#| j                  | j                  ||            }|S t        | j                  dz         # t        $ rD}t        |t              r'| j                  | j                  dd      }|r|ddd}n|Y d}~|S d}~ww xY w)a	  
        set margin mode to 'cross' or 'isolated'

        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Margin-Type
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Change-Margin-Type

        :param str marginMode: 'cross' or 'isolated'
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        Nz+ setMarginMode() requires a symbol argumentCROSSCROSSEDr  z, marginMode must be either isolated or crossrN   )r{  r  r  r  z; setMarginMode() supports linear and inverse contracts onlyr  Fi2No need to change margin type.)r  msg)r4   rN   rx  r5   r  r  fapiPrivatePostMarginTyper  dapiPrivatePostMarginTyper?   	Exceptionr  r8   r  r  )	rl  r6  r{  r  r  r  r  er  s	            rn  set_margin_modezbinance.set_margin_mode,)  s]    >#DGG.[$[\\  %%'
 "J*$:+BTWW'UUVVV$Tl$
 	h99$++gv:VW& % 	"99$++gv:VW"  #477-j#jkk 	 !12,0NN4<<Idfk,l),G(-6VWH  	s$    &C( (&C( C( (	D519D00D5r>  c                    | j                  | j                  dd      }| j                  |d|      }| j                  |dg      }d}| j                  dd|      \  }}d}| j	                  |dddd      \  }}d}|rd	}nd
}d|i}	d}
| j                  ||      rH|r#| j                  | j                  |	|            }
|
S | j                  | j                  |	|            }
|
S | j                  ||      rH|r#| j                  | j                  |	|            }
|
S | j                  | j                  |	|            }
|
S t        | j                  dz         )a  
        set hedged to True or False for a market

        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Position-Mode
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Change-Position-Mode
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Current-Position-Mode
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-CM-Current-Position-Mode

        :param bool hedged: set to True to use dualSidePosition
        :param str symbol: not used by binance setPositionMode()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.portfolioMargin]: set to True if you would like to set the position mode for a portfolio margin account
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: response from the exchange
        r  r[   rp  Nr   r  re  FtruefalsedualSidePositionz= setPositionMode() supports linear and inverse contracts only)r  r  r  r  r  ru  papiPostCmPositionSideDualr  dapiPrivatePostPositionSideDualrw  papiPostUmPositionSideDualfapiPrivatePostPositionSideDualr5   rN   )rl  r>  r{  r  r  rp  rq  r~  r  r  r  s              rn  set_position_modezbinance.set_position_moded)  s     &&t||]HM<6F8,99:KTSYZ $($C$CFL]_egxz  %A!6%& 0
 ??4) ::4;;wPV;WX    ??GU[@\]  ^^D'* ::4;;wPV;WX   ??GU[@\]  TWW'ffggro  c                 `   | j                          | j                  d|       d}| j                  dd|      \  }}d}| j                  dd|d      \  }}d}| j	                  |dddd      \  }}d}| j                  ||      r&|r| j                  |      }nb| j                  |      }nP| j                  ||      r&|r| j                  |      }n*| j                  |      }nt        | j                  dz         | j                  |dg       }t        |t              r|}| j!                  ||d	      S )
a  
        fetch the set leverage for all markets

        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Information-V2
        https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Account-Information
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Account-Detail
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-CM-Account-Detail
        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Symbol-Config

        :param str[] [symbols]: a list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a list of `leverage structures <https://docs.ccxt.com/#/?id=leverage-structure>`
        FNr   r  r  re  z< fetchLeverages() supports linear and inverse contracts onlyrS  r{  )r  r  r  r  r  rw  r  fapiPrivateGetSymbolConfigru  r  r  r?   rN   r  r  r  parse_leverages)rl  r  r  rp  rq  r~  r  	leveragess           rn  fetch_leverageszbinance.fetch_leverages)  s;    	##E6299:JDRXYf99:JDRXZbc $($C$CFL\^dfwy~$!6>>$( 008::6B__T7+ 00855f=tww)gghhNN8["=	h% I##IwAAro  c                 N   | j                  |d      }| j                  |d      }d }||rdnd}| j                  |d      }|	|dk(  rdnd}| j                  |d      }d }d }	| j                  |d      }
||dk(  r|
}|
}	n|d	k(  r|
}n|d
k(  r|
}	|| j	                  ||      |||	dS )Nr{  r1  r  r  crossedr  r  bothrh  rg  )r  r{  r6  longLeverageshortLeverage)r  r  rK  r  r|  )rl  r  r  r  marginModeRawr6  marginTypeRawr4  r  r  leverageValues              rn  parse_leveragezbinance.parse_leverage)  s    ##Hh7x<
$'4'J..xF$%2i%?jJ%%h?))(J?Ldfn(L)MV^(LW_)M&&x8$(*
 	
ro  c                    | j                          |dn| j                  |      }d}| j                  d||      \  }}|dk7  rt        | j                  dz         i }||d   }|d   |d   z   |d<   |||d	<   |||d
<   | j                  | j                  ||            }| j                  ||      }	| j                  |	d      }
| j                  |
|||      S )a  
        fetches historical settlement records

        https://developers.binance.com/docs/derivatives/option/market-data/Historical-Exercise-Records

        :param str symbol: unified market symbol of the settlement history
        :param int [since]: timestamp in ms
        :param int [limit]: number of records, default 100, max 100
        :param dict [params]: exchange specific params
        :returns dict[]: a list of `settlement history objects <https://docs.ccxt.com/#/?id=settlement-history-structure>`
        Nr   r\   z6 fetchSettlementHistory() supports option markets onlyr{  r  r  r  r
  r  r  )
r  r  r  r?   rN   eapiPublicGetExerciseHistoryr  parse_settlementsrV  filter_by_symbol_since_limitrl  r{  r  r  r  r  rp  r  r  settlementssorteds              rn  fetch_settlement_historyz binance.fetch_settlement_history)  s    	 .t{{6/B99:RTZ\bcf8tww)aabbH%F$*8$4vi7H$HGL!#(GK $GG44T[[&5QR ,,Xv>k;700NNro  c                    | j                          |dn| j                  |      }d}| j                  d||      \  }}|dk7  rt        | j                  dz         i }||d   |d<   |||d<   |||d<   | j                  | j                  ||            }| j                  ||      }	| j                  |	d	      }
| j                  |
|d   ||      S )
a  
        fetches historical settlement records of the user

        https://developers.binance.com/docs/derivatives/option/trade/User-Exercise-Record

        :param str symbol: unified market symbol of the settlement history
        :param int [since]: timestamp in ms
        :param int [limit]: number of records
        :param dict [params]: exchange specific params
        :returns dict[]: a list of [settlement history objects]
        Nr   r\   z8 fetchMySettlementHistory() supports option markets onlyrN   r{  r
  r  r  )
r  r  r  r?   rN   eapiPrivateGetExerciseRecordr  r  rV  r  r  s              rn  fetch_my_settlement_historyz#binance.fetch_my_settlement_history*  s     	 .t{{6/B99:TV\^def8tww)ccdd &tGH#(GK $GG44T[[&5QR* ,,Xv>k;7009I5RWXXro  c                     | j                  |dd      }| j                  |d      }|| j                  ||      | j                  |dd      || j	                  |      dS )Nr#  
createDater{  realStrikePriceexercisePrice)r  r{  r  r  r  )rL  r  r|  rO  rP  )rl  
settlementr  r  r  s        rn  parse_settlementzbinance.parse_settlement9*  si    > ''
L,O	##J9&&x8''
4EW"Y/
 	
ro  c                     g }t        dt        |            D ]&  }|j                  | j                  ||   |             ( |S )Nr   )r  r  r  r  )rl  r  r  r  r  s        rn  r  zbinance.parse_settlementsb*  sI    F q#k*+ 	IAMM$//AGH	Iro  c                 p   | j                          d}| j                  dd|      \  }}|dk7  rt        | j                  dz         | j	                  d|d       | j                  |      }||d   d}| j                  | j                  ||            }| j                  |d|      }| j                  ||      S )	a  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

        https://developers.binance.com/docs/derivatives/option/account/Account-Funding-Flow

        :param str id: the identification number of the ledger entry
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
        Nr   r\   z4 fetchLedgerEntry() can only be used for type optionr  rN   )recordIdr3  r   )
r  r  r5   rN   check_required_argumentr3  eapiPrivateGetBillr  r  parse_ledger_entry)	rl  rN   r  r  rp  r3  r  r  firsts	            rn  fetch_ledger_entryzbinance.fetch_ledger_entry*  s     	99:LdTZ[f8TWW']]^^$$%7vF==& 
 **4;;w+GH xH5&&uh77ro  c           	         | j                          d}| j                  |dd      \  }}|r| j                  d||||dd      S d}d}d}|| j                  |      }i }	| j	                  dd|      \  }}| j                  dd|      \  }}|||	d<   |||	d<   | j                  |d      }
|
| j                  |d      }|
|	d<   d}| j                  |dd	d
d      \  }}d}|dk(  r=| j                  d|d       |d   |	d<   | j                  | j                  |	|            }n| j                  ||      rF|r"| j                  | j                  |	|            }n| j                  | j                  |	|            }np| j                  ||      rF|r"| j!                  | j                  |	|            }n:| j#                  | j                  |	|            }nt%        | j&                  dz         | j)                  ||||      S )a  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

        https://developers.binance.com/docs/derivatives/option/account/Account-Funding-Flow
        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Income-History
        https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Income-History
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Income-History
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-CM-Income-History

        :param str [code]: unified currency code
        :param int [since]: timestamp in ms of the earliest ledger entry
        :param int [limit]: max number of ledger entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest ledger entry
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch the ledger for a portfolio margin account
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
        Fr   r  Nr
  r  r  r  r  re  r\   r  rN   r3  z- fetchLedger() supports contract wallets only)r  r  rM  r3  r  r  r  r  r  r  r  r  rw  r  r  ru  r  r  r?   rN   parse_ledger)rl  r  r  r  r  r  rp  rq  r3  r  r  r~  r  s                rn  fetch_ledgerzbinance.fetch_ledger*  s(   ( 	88PZ[&44]D%QVX^`dfkll}}T*H99-vVf99-vV#(GK $GG!!&'2YYvw/F!&GI $($C$CFM[actv{$|!68((fE"*4.GJ..t{{7F/KLH^^D'* //GV0LM44T[[&5QR__T7+ //GV0LM44T[[&5QRtww)XXYY:   8UEBBro  itemc                 &   | j                  |dd      }d }t        j                  |d      rd}t        j                  d|      }nd}| j	                  |d      }| j                  ||      }| j                  ||      }| j                  |dd	      }| j                  |d
d      }| j                  || j                  |dd      |d d | j	                  |d      | j                  |      || j                  |      || j                  |      d d d d d|      S )Nr  rw  r  outr6  inre  r  rM  rp  r  rN   r  r9  )r  rN   	directionrt  referenceAccountreferenceIdrp  r3  r  r  r  beforeafterr(  r  )r  rI   	string_ler  r  r  safe_currencyrL  safe_ledger_entryparse_ledger_entry_typerj  rP  )	rl  r&  r3  r  r*  r  r  r  rp  s	            rn  r   zbinance.parse_ledger_entry	+  s,   2 ##D(H=	VS)I''f5FI%%dG4
&&z8<%%j(;''lFC	!!$=%%$$T4:" $++D)<006''/"Y/'
  ! 	ro  c                     i ddddddddddddd	d
dd
dd
ddddddddddddddddddd}| j                  |||      S )NFEEr  r  OPTIONS_PREMIUM_FEEPOSITION_LIMIT_INCREASE_FEECONTRACTr"  REALIZED_PNLTRANSFERr   CROSS_COLLATERAL_TRANSFERINTERNAL_TRANSFERCOIN_SWAP_DEPOSITr  COIN_SWAP_WITHDRAWr  OPTIONS_SETTLE_PROFITr  DELIVERED_SETTELMENTWELCOME_BONUScashbackCONTEST_REWARDCOMMISSION_REBATErebate
API_REBATEr  r1  )REFERRAL_KICKBACK
COMMISSIONr  )rl  rp  
ledgerTypes      rn  r2  zbinance.parse_ledger_entry_type@+  s    
5
5
 "5
 *5	

 
 G
 

 (
  
  
 !,
 $\
 #L
 Z
 j
   !
" (#
$ ",&'

* 
D$77ro  currencyCode
depositUrlc                 d   |y d }| j                  |      }| j                  |di       }t        |j                               }t	        dt        |            D ]U  }||   }| j                  ||   di       }	| j                  |	d      }
|
3|j                  | j                  |
            sT|}W |S )Nr'  r   r  contractAddressUrl)	r3  r  r  r  r  r  r  
startswithget_base_domain_from_url)rl  rI  rJ  r  r3  r'  networkCodesr  currentNetworkCoder  siteUrls              rn  r	  z'binance.get_network_code_by_network_urlX+  s    ==.>>(J;HMMO,q#l+, 	1A!-a>>(+=">KD&&t-ABG"z'<'<T=Z=Z[b=c'd0	1 ro  r  c                     |y |j                  d      }| j                  |d      }|y | j                  |d      }|y |dz   |z   dz   S )Nr  r   r  z//)r  r  )rl  r  urlPartsschemedomains        rn  rN  z binance.get_base_domain_from_urli+  s_    ;99S>!!(A.>!!(A.>}v%++ro  r  GETc                 
   | j                   }||d   vrt        | j                  dz   |z   dz         | j                   d   |   }|d|z   z  }|dk(  r3| j                  rd| j                  i}nt	        | j                  dz         |dk(  xs |d	k(  }	|	rL| j                  r(| j                  d
d}|dk7  r| j                  |      }nt	        | j                  dz         |dk(  sC|dk(  s>|dk(  r|dk7  s4|dk(  s/|dk(  s*|dk(  s%|dk(  s |dk(  s|dk(  s|dk(  s|dk(  s|dk(  r*|dk7  r$| j                          |dk(  r|dk(  s|dk(  r| j                  |d      }
|
m|j                  d      d kD  xs |dk(  }|rd!nd"}|sd#nd$}| j                  | j                  d%i       }| j                  |||      }|| j                         z   |d<   d }|d&k(  r|dk(  s|d'k(  r| j                  |d&      }|}|dk(  r|dk(  rg }t        d(t        |            D ]v  }||   }| j                  |d      }
|
Jd#}| j                  | j                  d%i       }| j                  |d"|      }|| j                         z   }
|
|d<   |j                  |       x | j!                  |      }||d&<   | j#                  | j                  d)      }| j%                  d*| j'                         i|      }|||d)<   | j#                  |d)      }|||d)<   |dk(  r|d+k(  r| j)                  |      }n|d&k(  sA|j                  d,      d(k\  s-|d-k(  s(|j                  d.      d(k\  s|j                  d/      d(k\  r|d0k(  r|d&k(  r| j                  |d1g       }| j                  |d2g       }| j+                  |d1d2g      }| j-                  |      }t        |      }t        |      }|d(kD  r|d3z   d4z   d5j/                  |      z   d6z   }|d(kD  rA|d3z   d7z   d5j/                  |      z   d6z   }n#| j-                  |      }n| j                  |      }d }| j0                  j                  d8      d kD  rt        | j0                        d9kD  r-| j3                  | j5                  || j0                  d:            }n| j3                  | j7                  | j9                  |      | j0                  d;            }nI| j;                  | j9                  |      | j9                  | j0                        t<        j>                        }|d<|z   z  }d| j                  i}|dk(  s|d0k(  r	|d=|z   z  }n!|}d
|d><   n|r|d=| j                  |      z   z  }||||d?S )@Nr  z) does not have a testnet/sandbox URL for z
 endpointsr  rU  X-MBX-APIKEYz7 historicalTrades endpoint requires `apiKey` credentialr>  r  z!application/x-www-form-urlencoded)rX  Content-TyperV  z5 userDataStream endpoint requires `apiKey` credentialr  r
  r  r  r  r  r  r   r   r   r   r  r  rL  POSTro  r  r_  r  rX   r[   r  r  r$  r  PUTr   r  r  r<  zsub-accountr=  stakingzsimple-earnDELETEru  origclientorderidlist&zorderidlist=%5Bz%2Cz%5Dzorigclientorderidlist=%5BzPRIVATE KEYx   sha256ed25519z&signature=?rY  )r  rH  bodyheaders) r   r?   rN   apiKeyr1   	urlencoder  r  r  r  r  rz  r  r  r  r  r  r  r  r  urlencode_with_array_repeatr  	rawencoder  secretencode_uri_componentrsaeddsaencodehmachashlibra  )rl  pathr  rH  r  re  rd  r   r  r>  r_  r,  r  r  r$  r  r  r  checkedBatchOrdersr  
batchOrder
queryBatchdefaultRecvWindowextendedParamsr  ru  r^  orderidlistLengthorigclientorderidlistLength	signatures                                 rn  signzbinance.signu+  s}   yytE{"tww)TTWZZ]iijjiis#sTz%%{{"DKK *$''4m*mnn"22L8K{{ %)KK$G U?>>&1D)$''4k*kllYC=$8cVmPTXgPgmpt|m|  CF  JR  CR  X[  _g  Xg  mp  tA  mA  GJ  N]  G]  cf  jw  cw  }@  DS  }S  Y\  `o  Yo  ux  |B  uB  GK  OU  GU++-dgo4;;N#'#3#3F<N#O #+&)hhv&6&;&Osi?ON+9xJ5C,I!^^DLL(BGF#//
INH19DKKM1IF-.E%Vv-=6U?"nnV]C%0"V#}(<)+&"1c+&67 	>%0^
+/+;+;JHZ+[(+3(4I%)^^DLL(B%OF'+'7'7)'TH/7$++-/G,=MJ'9:*11*=	> #ii(:;
(2}% $ 1 1$,, M![[TZZ\*N !,/@|,**6<@J%/9|,vDL$888H-'TYY}-E-JPTXpPpvzvv  AJ  wK  OP  wP  VZ  V_  V_  `m  Vn  rs  Vsh&T]-B"&..PR"SK,0NN>Kbdf,g)%)YY~Of?g%hN NN>:E(+K(8%256K2L/(1, %.? ?%**[BY Y\a a2Q6 %.I IEJJWlLm mpu u NN>:E~6I{{.3t{{#c) $ 9 9$((5$++W_:` aI $ 9 9$**T[[QVEWY]YdYdfo:p qI IIdkk%&8$++dkk:RT[TbTbc	')33EG %Vx%7sU{"*M'sT^^F333fdwOOro  exactOrBroadc                 
   d }| j                   | j                   nd}|j                  d|z   dz         s|j                  d      rd}n|j                  d|z   dz         s|j                  d      rd}n^|j                  d	|z   dz         s|j                  d
      rd}n3|j                  d|z   dz         rd}n|j                  d|z   dz         rd}|0| j                  | j                  |i       }| j                  ||i       S i S )Nzbinance.comzhttps://api.r  zhttps://testnet.binance.visionrX   zhttps://dapi.z&https://testnet.binancefuture.com/dapir  zhttps://fapi.z&https://testnet.binancefuture.com/fapir  zhttps://eapi.r\   zhttps://papi.re  )hostnamerM  r  rQ  )rl  r  r{  r  r}  exceptionsForMarketTypes         rn  get_exceptions_by_urlzbinance.get_exceptions_by_url+  s    
%)]]%>4==]>>.83c9:cnnMm>nJ^^Oh6<=PxAy"J^^Oh6<=PxAy!J^^Oh6<=!J^^Oh6<=*J!&*nnT__jRT&U#>>"9<LL	ro  reasonrH  re  rd  c
                 "   |dk(  s|dk(  r0t        | j                  dz   t        |      z   dz   |z   dz   |z         |dk\  r|j                  d      dk\  rt	        | j                  dz   |z         |j                  d      dk\  rt	        | j                  d	z   |z         |j                  d
      dk\  rt	        | j                  dz   |z         |y | j                  |dd      }
|
s0| j                  |d      }d }|	 t        j                  |      }||}| j                  |d      }|| j                  | j                  |d      || j                  dz   |z          | j                  | j                  d   || j                  dz   |z          | j                  | j                  |d      || j                  dz   |z          | j                  | j                  d   || j                  dz   |z          | j                  |d      }||dk(  st        j                  |d      ry |dk(  r*| j                   d   rt        | j                  dz   |z         | j                  dz   |z   }|dk(  rt#        |      | j                  | j                  |d      ||       | j                  | j                  d   ||       t%        |      |
st%        | j                  dz   |z         t'        |t(              rt+        |      }|dk(  r||d   }| j                  |d      }|c| j                  | j                  |d      || j                  dz   |z          | j                  | j                  d   || j                  dz   |z          y # t        $ r}d }Y d }~xd }~ww xY w)Ni  i  rk  i  zPrice * QTY is zero or lessr   z- order cost = amount * price is zero or less rC  z5 order amount should be evenly divisible by lot size r?  z order price is invalid, i.e. exceeds allowed price precision, exceeds min price or max price limits or is invalid value in general, use self.price_to_precision(symbol, amount) successTr  rR  rf  r  200r  rc  r  r  r  )rA   rN   r  r  r;   r  r  r  loadsr  throw_exactly_matched_exceptionr  rQ  throw_broadly_matched_exceptionrI   rv  r  r8   r0   r  r  r  )rl  r  r  r  rH  re  rd  r  requestHeadersrequestBodyr  
messageNewparsedMessager  messageerrorfeedbackarrayLengthelement	errorCodes                       rn  handle_errorszbinance.handle_errors+  s   CKTS[ 3T!:S!@6!IC!ORV!VWW 3;yy671<"477-\#\_c#cddyy$)"477-d#dgk#kllyy(A-"477  .a  $a  dh  $h  i  i..9d;))(E:J M%)$(JJz$:M !,,H""8U3001K1KCQX1Y[bdhdkdknqdqt{d{|001I7TXT[T[^aTadkTkl001K1KCQX1Y[bdhdkdknqdqt{d{|001I7TXT[T[^aTadkTkl  62 7#8#8#D  dll3X&Y$TWWs]T%9::ww}t+H:: +844001K1KCQX1Y[`bjk001I5RZ[))# 455h%h-Ka"1+ ,,Wf=	(889S9STWY`9aclnrnunux{n{  C  oC  D889QS\^b^e^ehk^knr^rs[ ! )$(M)s   <M8 8	NN		Nc                     d|v r	d|vr|d   S d|v r	d|vr|d   S d|v r	d|vr|d   S d|v r<d|v r8|d   }|d   }t        d	t        |            D ]  }||   }	||	d	   k  s|	d
   c S  | j                  |dd
      S )Nr&  r  r`  r{  r6  poolIdrS  r  r   r  r%  )r  r  r  )
rl  r  rH  rq  r  configr  rS  r  r  s
             rn  calculate_rate_limiter_costz#binance.calculate_rate_limiter_cost7,  s    6)9(##F"X-?*%%F"X-?*%%6!6(97OEY'G1c'l+ $
E!H$ 8O$ vvq11ro  c           	      \    | j                  |||||||      }|dk(  rd| j                  d<   |S )Nr  Tr  )fetch2r  )	rl  rq  r  rH  r  re  rd  r  r  s	            rn  r  zbinance.requestG,  s8    ;;tS&&'4P)BFDLL>?ro  c                     | j                  | j                  dd      }|dk(  rd}| j                  |d|      }|dk(  s|dk(  rt        | j                  dz         | j	                          | j                  |      }| j                  ||      }||d   |d}d }	d }
|d	   r'|d
   }
| j                  | j                  ||            }	n&|d   }
| j                  | j                  ||            }	| j                  | j                  |	|      d|
i      S )Nr  r[   rX   rp  rY   z@ add / reduce margin only supported with type future or deliveryrN   )rp  r{  r  r  r  r  r  )r  r  r?   rN   r  r  r|  fapiPrivatePostPositionMarginr  dapiPrivatePostPositionMarginparse_margin_modification)rl  r{  r  addOrReducer  r  rp  r  r  r  r  s              rn  modify_margin_helperzbinance.modify_margin_helperN,  s'   &&t||]HM& "K<H$&.tww)kkllV$))&&9Tl

 ('?D99$++gv:VWH&>D99$++gv:VWH {{499(FKDN
  	ro  r[  c                 d   | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  ||d d      }|d u }|dk(  }||d   |dk(  rdnd	d
| j                  |d      | j                  |d      d |s|rdnd|| j	                  |      d
S )Nrp  r  r{  rM  rZ   r  r  addreducer1  r  re  r  r  )
r  r{  rp  r6  r  r  ro  r(  r  r  )r  r  r  r  rP  )	rl  r[  r  rawTyper  r  r  noErrorCoder  s	            rn  r  z!binance.parse_margin_modificationr,  s    0 ##D&1$$T62	##D(3%%dF3	!!(FD&A4'u$X&%lE$&&tX6$$T73&+dH"Y/
 	
ro  c                 *    | j                  ||d|      S )aO  
        remove margin from a position

        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Modify-Isolated-Position-Margin
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Isolated-Position-Margin

        :param str symbol: unified market symbol
        :param float amount: the amount of margin to remove
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=reduce-margin-structure>`
        r  r  rl  r{  r  r  s       rn  reduce_marginzbinance.reduce_margin,       ((FCCro  c                 *    | j                  ||d|      S )a2  
        add margin

        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Modify-Isolated-Position-Margin
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Isolated-Position-Margin

        :param str symbol: unified market symbol
        :param float amount: amount of margin to add
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
        r  r  r  s       rn  
add_marginzbinance.add_margin,  r  ro  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |d      }| j                  |      S )a  
        fetch the rate of interest to borrow a currency for margin trading

        https://developers.binance.com/docs/margin_trading/borrow-and-repay/Query-Margin-Interest-Rate-History

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `borrow rate structure <https://docs.ccxt.com/#/?id=borrow-rate-structure>`
        re  rN   r   )r  r3   sapiGetMarginInterestRateHistoryr  r  parse_borrow_rate)rl  r  r  r3  r  r  r  s          rn  fetch_cross_borrow_ratezbinance.fetch_cross_borrow_rate,  sn     	==&Xd^
 88Wf9UV ~~h*%%d++ro  c                 p    d|i}| j                  | j                  ||            }| j                  ||      S )aH  
        fetch the rate of interest to borrow a currency for margin trading

        https://developers.binance.com/docs/margin_trading/account/Query-Isolated-Margin-Fee-Data

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint

 EXCHANGE SPECIFIC PARAMETERS
        :param dict [params.vipLevel]: user's current specific margin data will be returned if viplevel is omitted
        :returns dict: an `isolated borrow rate structure <https://docs.ccxt.com/#/?id=isolated-borrow-rate-structure>`
        r{  )fetch_isolated_borrow_ratesr  r  )rl  r{  r  r  borrowRatess        rn  fetch_isolated_borrow_ratez"binance.fetch_isolated_borrow_rate,  s>     f
 66t{{7F7ST~~k622ro  c                    | j                          i }| j                  |d      }| j                  |d      }|| j                  |      }|d   |d<   | j	                  | j                  ||            }| j                  |      S )a.  
        fetch the borrow interest rates of all currencies

        https://developers.binance.com/docs/margin_trading/account/Query-Isolated-Margin-Fee-Data

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param dict [params.symbol]: unified market symbol

 EXCHANGE SPECIFIC PARAMETERS
        :param dict [params.vipLevel]: user's current specific margin data will be returned if viplevel is omitted
        :returns dict: a `borrow rate structure <https://docs.ccxt.com/#/?id=borrow-rate-structure>`
        r{  rN   )r  r  r  r  sapiGetMarginIsolatedMarginDatar  parse_isolated_borrow_rates)rl  r  r  r{  r  r  s         rn  r  z#binance.fetch_isolated_borrow_rates,  s     	!!&(368,[[(F &tGH77GV8TU, //99ro  c                 ~   | j                          |d}n|dkD  rt        | j                  dz         | j                  |      }|d   |d}|<||d<   | j	                  ||dz        dz
  }| j                         }t        ||      |d<   | j                  | j                  ||            }	| j                  |	|||      S )	a  
        retrieves a history of a currencies borrow interest rate at specific time slots

        https://developers.binance.com/docs/margin_trading/borrow-and-repay/Query-Margin-Interest-Rate-History

        :param str code: unified currency code
        :param int [since]: timestamp for the earliest borrow rate
        :param int [limit]: the maximum number of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>` to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>`
        ]   z: fetchBorrowRateHistory() limit parameter cannot exceed 92rN   )re  r  r
   \&r  r  )
r  r5   rN   r3  r  r  r  r  r  parse_borrow_rate_history)
rl  r  r  r  r  r3  r  r  r  r  s
             rn  fetch_borrow_rate_historyz!binance.fetch_borrow_rate_history-  s     	=ERZTWW'ccdd==&d^
 #(GK hhueh&67!;G##%C!$Wc!2GI88Wf9UV --heUKKro  c                     | j                  |d      }| j                  |d      }| j                  ||      | j                  |d      d|| j	                  |      |dS )Nr  re  dailyInterestRater  )r3  r  periodr  r  r  )r  r  r  r  rP  )rl  r  r3  r  r  s        rn  r  zbinance.parse_borrow_rate@-  sh     %%dK8	%%dG4
//
HE$$T+>?"Y/
 	
ro  r  c           
      r   | j                  |d      }| j                  ||d d      }| j                  |d      }| j                  |d      }| j                  |d      }|| j                  |d      | j                  |d      | j	                  |d      | j                  |d      | j	                  |d      dd d d		S )
Nr{  rX   r[  r   r  r  dailyInterestr  )	r  r{  r  baseRater  	quoteRater  r  r  )r  r  r  r  r  )rl  r  r  r  r[  baseInfo	quoteInfos          rn  parse_isolated_borrow_ratez"binance.parse_isolated_borrow_rateT-  s    ( ##D(3!!(FD&A~~dF+>>$*NN4+	&&vx8$$Xv6((?C%%i8)))_E

 
	
ro  c                    | j                          | j                  |      }|d   |d}| j                  | j                  ||            }| j	                  |d      }| j                  |d      }| j                  |d      }	||	|||dS )a~  
        create gift code

        https://developers.binance.com/docs/gift_card/market-data/Create-a-single-token-gift-card

        :param str code: gift code
        :param float amount: amount of currency for the gift
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: The gift code id, code, currency and amount
        rN   )tokenr  r[  r  referenceNo)r  rN   r  r3  r  )r  r3  sapiPostGiftcardCreateCoder  r  r  )
rl  r  r  r  r3  r  r  r[  giftcardCoderN   s
             rn  create_gift_codezbinance.create_gift_codey-  s     	==& d^
 224;;w3OP ~~h/''f5dM2 
 	
ro  c                 P    d|i}| j                  | j                  ||            }|S )a)  
        redeem gift code

        https://developers.binance.com/docs/gift_card/market-data/Redeem-a-Binance-Gift-Card

        :param str giftcardCode:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        r  )sapiPostGiftcardRedeemCoder  )rl  r  r  r  r  s        rn  redeem_gift_codezbinance.redeem_gift_code-  s4     L
 224;;w3OP ro  c                 P    d|i}| j                  | j                  ||            }|S )aE  
        verify gift code

        https://developers.binance.com/docs/gift_card/market-data/Verify-Binance-Gift-Card-by-Gift-Card-Number

        :param str id: reference number id
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        r  )sapiGetGiftcardVerifyr  )rl  rN   r  r  r  s        rn  verify_gift_codezbinance.verify_gift_code-  s4     2
 --dkk'6.JK ro  c                    | j                          d}| j                  |dddd      \  }}i }d}|| j                  |      }	|	d   |d<   |||d<   |||d	<   | j                  d
||      \  }}d}
|r"| j	                  | j                  ||            }
n<|| j                  |      }|d   |d<   | j                  | j                  ||            }
| j                  |
d      }| j                  ||      }| j                  ||||      S )a  
        fetch the interest owed by the user for borrowing currency for margin trading

        https://developers.binance.com/docs/margin_trading/borrow-and-repay/Get-Interest-History
        https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Margin-BorrowLoan-Interest-History

        :param str [code]: unified currency code
        :param str [symbol]: unified market symbol when fetch interest in isolated markets
        :param int [since]: the earliest time in ms to fetch borrrow interest for
        :param int [limit]: the maximum number of structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch the borrow interest in a portfolio margin account
        :returns dict[]: a list of `borrow interest structures <https://docs.ccxt.com/#/?id=borrow-interest-structure>`
        Nr   r  re  FrN   re  r
  r  r  r  r  )r  r  r3  r)  "papiGetMarginMarginInterestHistoryr  r  sapiGetMarginInterestHistoryr  parse_borrow_interestsfilter_by_currency_since_limit)rl  r  r{  r  r  r  r~  r  r  r3  r  r  r_  s                rn  fetch_borrow_interestzbinance.fetch_borrow_interest-  s@    	 $($C$CFLacik|  D  %E!6}}T*H'~GG#(GK #GFO229gvN>>t{{7TZ?[\H!V,,24L()88Wf9UVHJ ~~h/..tV<228T5%PPro  c                 *   | j                  |d      }| j                  |d      }|dnd}||| j                  | j                  |d            | j                  |d      | j                  |d      | j                  |d      ||| j	                  |      d		S )
Nr  interestAccuredTimer  r1  re  r_  rC  	principal)	r  r{  r3  r_  rC  amountBorrowedr6  r  r  r  r  r  r  rP  )rl  r  r  r{  r  r6  s         rn  parse_borrow_interestzbinance.parse_borrow_interest.  s    !!$(89%%d,AB	!'Wj
//0@0@w0OP((z: ,,T>B"..t[A$"Y/

 
	
ro  c                    | j                          | j                  |      }|d   | j                  ||      d}d}d}| j                  |dddd      \  }}|rbd}| j                  |ddd	      \  }}|d
k(  r"| j	                  | j                  ||            }nM| j                  | j                  ||            }n+d|d<   d|d<   | j                  | j                  ||            }| j                  ||      S )a.  
        repay borrowed margin and interest

        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Repay
        https://developers.binance.com/docs/margin_trading/borrow-and-repay/Margin-Account-Borrow-Repay
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Repay-Debt

        :param str code: unified currency code of the currency to repay
        :param float amount: the amount to repay
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.portfolioMargin]: set to True if you would like to repay margin in a portfolio margin account
        :param str [params.repayCrossMarginMethod]: *portfolio margin only* 'papiPostRepayLoan'(default), 'papiPostMarginRepayDebt'(alternative)
        :param str [params.specifyRepayAssets]: *portfolio margin papiPostMarginRepayDebt only* specific asset list to repay debt
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        rN   r  Nr   r  re  FrepayCrossMarginMethodrH  papiPostMarginRepayDebtFALSEr(  REPAYrp  )	r  r3  r  r  r  r  papiPostRepayLoansapiPostMarginBorrowRepayparse_margin_loan)	rl  r  r  r  r3  r  r  r~  rH  s	            rn  repay_cross_marginzbinance.repay_cross_margin..  s     	==&d^00v>
  $($C$CFL^`fhy  |A  %B!6F!<<VEWYqs{|NFF2277GV8TU  11$++gv2NO %,GL!%GFO55dkk'66RSH %%h99ro  c                    | j                          | j                  |      }| j                  |      }|d   | j                  ||      |d   ddd}| j	                  | j                  ||            }| j                  ||      S )a   
        repay borrowed margin and interest

        https://developers.binance.com/docs/margin_trading/borrow-and-repay/Margin-Account-Borrow-Repay

        :param str symbol: unified market symbol, required for isolated margin
        :param str code: unified currency code of the currency to repay
        :param float amount: the amount to repay
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        rN   TRUEr  re  r  r{  r(  rp  r  r3  r  r  r  r  r  	rl  r{  r  r  r  r3  r  r  r  s	            rn  repay_isolated_marginzbinance.repay_isolated_margini.  s     	==&V$d^00v>Tl 
 11$++gv2NO %%h99ro  c                 n   | j                          | j                  |      }|d   | j                  ||      d}d}d}| j                  |dddd      \  }}|r"| j	                  | j                  ||            }n+d|d	<   d
|d<   | j                  | j                  ||            }| j                  ||      S )a  
        create a loan to borrow margin

        https://developers.binance.com/docs/margin_trading/borrow-and-repay/Margin-Account-Borrow-Repay
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Borrow

        :param str code: unified currency code of the currency to borrow
        :param float amount: the amount to borrow
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.portfolioMargin]: set to True if you would like to borrow margin in a portfolio margin account
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        rN   r  Nr^   r  re  Fr  r(  BORROWrp  )r  r3  r  r  papiPostMarginLoanr  r  r  )rl  r  r  r  r3  r  r  r~  s           rn  borrow_cross_marginzbinance.borrow_cross_margin.  s     	==&d^00v>
  $($C$CFL_agiz  }B  %C!6..t{{7F/KLH$+GL!&GFO55dkk'66RSH %%h99ro  c                    | j                          | j                  |      }| j                  |      }|d   | j                  ||      |d   ddd}| j	                  | j                  ||            }| j                  ||      S )a  
        create a loan to borrow margin

        https://developers.binance.com/docs/margin_trading/borrow-and-repay/Margin-Account-Borrow-Repay

        :param str symbol: unified market symbol, required for isolated margin
        :param str code: unified currency code of the currency to borrow
        :param float amount: the amount to borrow
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        rN   r  r  r  r  r  s	            rn  borrow_isolated_marginzbinance.borrow_isolated_margin.  s     	==&V$d^00v>Tl 
 11$++gv2NO %%h99ro  c                     | j                  |d      }| j                  |d      }| j                  |d      | j                  ||      | j                  |d      d || j	                  |      |dS )Nre  rq  r  r  )rN   r3  r  r{  r  r  r  r  )rl  r  r3  r  r  s        rn  r  zbinance.parse_margin_loan.  sw    " %%dG4
%%dL9	##D(3//
HE&&tX6"Y/
 	
ro  r   c           	      6   |dk(  rt        | j                  dz         | j                          d}| j                  |ddd      \  }}|r| j	                  d|||||d      S | j                  |      }d| j                  | j                  ||      i}|||d	<   |d
   rdnd}	|d   ||	<   |d   r| j                  |dd      |d<   |||d<   | j                  |d      }
| j                  |d|
      }| j                  |ddg      }|r||d<   n2|r0|d}| j                  |      }| j                  |||z  dz        |d<   d}|d   r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  ||||      S )aP  
        Retrieves the open interest history of a currency

        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Open-Interest-Statistics
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Open-Interest-Statistics

        :param str symbol: Unified CCXT market symbol
        :param str timeframe: "5m","15m","30m","1h","2h","4h","6h","12h", or "1d"
        :param int [since]: the time(ms) of the earliest record to retrieve unix timestamp
        :param int [limit]: default 30, max 500
        :param dict [params]: exchange specific parameters
        :param int [params.until]: the time(ms) of the latest record to retrieve unix timestamp
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict: an array of `open interest structure <https://docs.ccxt.com/#/?id=open-interest-structure>`
        r   z5 fetchOpenInterestHistory cannot use the 1m timeframeFr   r  rQ  r  Nr  r  r{  r	  rN   r  r!  CURRENT_QUARTERr
  r  r  r)  rR  )r5   rN   r  r  r  r  r  r   r  r  r  r  dapiDataGetOpenInterestHistr  fapiDataGetOpenInterestHistparse_open_interests_history)rl  r{  r  r  r  r  r  r  r  	symbolKeyr  r  r  r  s                 rn  fetch_open_interest_historyz#binance.fetch_open_interest_history.  s     TWW'^^__88A[]gino&::;UW]_dfkmvx~  AD  E  EV$d&&t	9M
 $GG &x 0Hf	#D\	)&*&6&6v~O`&aGN##(GK !!&'2##FIu=6Iw#78!(GI}++I6H!%%E1AD1H!IGI)77GV8TUH77GV8TUH 0065%PPro  c                 x   | j                          | j                  |      }i }|d   r@|d   |d<   |d   t        | j                  dz   |z         | j	                  |d         |d<   n|d   |d	<   d}|d   r"| j                  | j                  ||            }nH|d
   r"| j                  | j                  ||            }n!| j                  | j                  ||            }|d   rC|d	   }| j                  ||      }t        dt        |            D ]  }||   }|d	   |k(  s|c S  y| j                  ||      S )ac  
        retrieves the open interest of a contract trading pair

        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Open-Interest
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Open-Interest
        https://developers.binance.com/docs/derivatives/option/market-data/Open-Interest

        :param str symbol: unified CCXT market symbol
        :param dict [params]: exchange specific parameters
        :returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
        r\   r  underlyingAssetr  Nz$ fetchOpenInterest does not support 
expirationrN   r{  r  r   )r  r  r?   rN   rM  eapiPublicGetOpenInterestr  dapiPublicGetOpenInterestfapiPublicGetOpenInterestr  r  r  parse_open_interest)	rl  r{  r  r  r  r  r  r  r&  s	            rn  fetch_open_interestzbinance.fetch_open_interest'/  sa    	V$()/)9G%&h'"477-S#SV\#\]]$(KKx0@$AGL! &tGH(55dkk'66RSHI55dkk'66RSH55dkk'66RSH> (H%F66xHF1c&k*  ay>V+K   ++Hf==ro  c                    | j                  |dd      }| j                  |d      }| j                  |dd      }| j                  |dd      }| j                  | j	                  ||d d      |d	   rd n|||||| j                  |      |d
|      S )Nr  rM  r{  sumOpenInterestrd  sumOpenInterestValuesumOpenInterestUsdr  r  )r{  r  r  openInterestAmountopenInterestValuer  r  r  )rL  r  rO  safe_open_interestr|  rP  )rl  r_  r  r  rN   r  values          rn  r  zbinance.parse_open_interestm/  s    ''+vF	h1##H.?P""8-CEYZ &&&&r64D"("3$ "(!&"Y/	(
 	 		ro  c           	      :   | j                          d}| j                  |dd      \  }}|r| j                  d||||dd      S d}|| j                  |      }d}| j	                  d||      \  }}d}| j                  d||d      \  }}d}	| j                  |ddd	d      \  }	}i }
|d
k7  rd|
d<   ||d
   rdnd}|	s|d   |
|<   |||
d<   ||d
k(  r||
d<   n||
d<   | j                  d|
|      \  }
}d}|d
k(  rF|	r"| j                  | j                  |
|            }n| j                  | j                  |
|            }n|dk(  rF|	r"| j                  | j                  |
|            }n| j                  | j                  |
|            }nl|dk(  rF|	r"| j                  | j                  |
|            }nC| j                  | j                  |
|            }n!t        | j                   dz   |d   z   dz         | j#                  |d|      }| j%                  ||||      S )a&  
        retrieves the users liquidated positions

        https://developers.binance.com/docs/margin_trading/trade/Get-Force-Liquidation-Record
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Users-Force-Orders
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Users-Force-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-UM-Force-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-CM-Force-Orders

        :param str [symbol]: unified CCXT market symbol
        :param int [since]: the earliest time in ms to fetch liquidations for
        :param int [limit]: the maximum number of liquidation structures to retrieve
        :param dict [params]: exchange specific parameters for the binance api endpoint
        :param int [params.until]: timestamp in ms of the latest liquidation
        :param boolean [params.paginate]: *spot only* default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch liquidations in a portfolio margin account
        :param str [params.type]: "spot"
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: an array of `liquidation structures <https://docs.ccxt.com/#/?id=liquidation-structure>`
        Fr   r  currentrP  Nr  r  re  rX   LIQUIDATIONautoCloseTyper  r{  rN   r
  r  r  r  r  z( fetchMyLiquidations() does not support rp  r7  r  )r  r   fetch_paginated_call_incrementalr  r  r  r  r)  papiGetMarginForceOrdersr   sapiGetMarginForceLiquidationRecpapiGetUmForceOrdersfapiPrivateGetForceOrderspapiGetCmForceOrdersdapiPrivateGetForceOrdersr?   rN   r  parse_liquidations)rl  r{  r  r  r  r  r  rp  rq  r~  r  r  r  liquidationss                 rn  fetch_my_liquidationszbinance.fetch_my_liquidations/  s   * 	88AVXbc&889NPVX]_dflnwy|}}[[(F99:OQWY_`f99:OQWY_aij $($C$CFLacik|  D  %E!66>'4GO$,26N(I$%+D\	"#(GK v~"'#( 229gvN6> 88Wf9UV@@WV\A]^  44T[[&5QR99$++gv:VW	! 44T[[&5QR99$++gv:VWtww)SSV\]cVddgqqrr\ ~~hA&&|VUEJJro  c                 `   | j                  |d      }| j                  |dd      }| j                  || j                  ||      | j	                  |d      | j	                  |d      | j	                  |d      | j	                  |d      | j	                  |d      || j                  |      d		      S )
Nr{  updatedTimerq  r  r  r  r  r  )	r  r{  rn  r  r  	baseValue
quoteValuer  r  )r  rL  safe_liquidationr|  r  rP  )rl  liquidationr  r  r  s        rn  parse_liquidationzbinance.parse_liquidation0  s    J ##K:'']LQ	$$&&x8))+}E ,,V^D%%k:>))+yA**;
C"Y/
&
 
 
	ro  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |d   |      S )a  
        fetches an option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract

        https://developers.binance.com/docs/derivatives/option/market-data/Option-Mark-Price

        :param str symbol: unified symbol of the market to fetch greeks for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `greeks structure <https://docs.ccxt.com/#/?id=greeks-structure>`
        r{  rN   r   )r  r  eapiPublicGetMarkr  parse_greeksr4  s         rn  fetch_greekszbinance.fetch_greeksf0  sd     	V$fTl
 ))$++gv*FG$   !f55ro  greeksc                    | j                  |d      }| j                  ||      }i d|dd dd d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      dd d	d d
d d| j                  |d      d| j                  |d      d| j                  |d      dd dd d| j                  |d      dd d |dS )Nr{  r  r  deltagammathetavegarhobidSizeaskSizebidImpliedVolatilitybidIVaskImpliedVolatilityaskIVmarkImpliedVolatilitymarkIVr  r  r  r  )underlyingPricer  )r  r|  r  )rl  r"  r  r  r{  s        rn  r   zbinance.parse_greeks0  so     ##FH5!!(F3
f

 
 T%%fg6	

 T%%fg6
 T%%fg6
 D$$VV4
 4
 t
 t
 #D$4$4VW$E
 #D$4$4VW$E
 $T%5%5fh%G
 
 
  ))&+>!
" #
$  $'
 	
ro  c                     | j                         }i }t        dt        |            D ],  }||   }|d   }|| j                  ||      s"|d   d   ||<   . |S )Nr   r{  r  r  )r  r  r  r
  )rl  r  r  r  tradingLimitsr  r  r{  s           rn  fetch_trading_limitszbinance.fetch_trading_limits0  sr    $$& q#g,' 	CAQZFH%FT]]67%C(.x(8(Bf%		C
 ro  c                    d}|| j                  |      }d}| j                  d||      \  }}d}|dk(  r| j                  |      }n/|dk(  r| j                  |      }nt	        | j
                  dz         | j                  |d      }||dS )a  
        fetchs the position mode, hedged or one way, hedged for binance is set identically for all linear markets or all inverse markets

        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Current-Position-Mode
        https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Current-Position-Mode

        :param str symbol: unified symbol of the market to fetch the order book for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: an object detailing whether the market is in hedged or one-way mode
        Nr   r  r  zI fetchPositionMode requires either a symbol argument or params["subType"]r  )r  r>  )r  r  fapiPrivateGetPositionSideDualdapiPrivateGetPositionSideDualr5   rN   r  )rl  r{  r  r  rq  r  r  s          rn  fetch_position_modezbinance.fetch_position_mode0  s     [[(F99:MvW]^h::6BH	!::6BHTWW'rrss  >>(4FG&
 	
ro  c                    | j                          d}|%| j                  |      }| j                  |d         }d}| j                  d||      \  }}d}|dk(  r| j	                  |      }n/|dk(  r| j                  |      }nt        | j                  dz         | j                  |dg       }t        |t              r|}| j                  ||dd	      S )
a6  
        fetches margin modes("isolated" or "cross") that the market for the symbol in in, with symbol=None all markets for a subType(linear/inverse) are returned

        https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Account-Information
        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Information-V2
        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Symbol-Config

        :param str[] symbols: unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a list of `margin mode structures <https://docs.ccxt.com/#/?id=margin-mode-structure>`
        Nr   r   r  r  z= fetchMarginModes() supports linear and inverse subTypes onlyrS  r{  rZ   )r  r  r  r  r  r  r5   rN   r  r  r  parse_margin_modes)rl  r  r  r  rq  r  rt  s          rn  fetch_margin_modeszbinance.fetch_margin_modes0  s     	))'2G[[,F99:KVU[\h66v>H 	!11&9Hd TWW'ffgg+r:h%F&&vw&IIro  c                 h   | j                          | j                  |      }d}| j                  d||      \  }}d}|dk(  r)d|d   i}| j                  | j	                  ||            }n5|dk(  r| j                  |g|      }||   S t        | j                  dz         | j                  |d   |      S )	ac  
        fetches the margin mode of a specific symbol

        https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Symbol-Config
        https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Account-Information

        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a `margin mode structure <https://docs.ccxt.com/#/?id=margin-mode-structure>`
        Nr   r  r{  rN   r  z< fetchMarginMode() supports linear and inverse subTypes onlyr   )	r  r  r  r  r  r;  r5   rN   parse_margin_mode)rl  r{  r  r  rq  r  r  fetchMarginModesResponses           rn  fetch_margin_modezbinance.fetch_margin_mode:1  s     	V$99:KVU[\h&,G 66t{{7F7STH 	!'+'>'>x'P$+F33TWW'eeff%%hqk6::ro  c                     | j                  |d      }| j                  ||      }| j                  |d      }d }||rdnd}| j                  |d      }|	|dk(  rdnd}||d   |dS )Nr{  r1  r  r  r  )r  r{  r6  )r  r  r  rK  )rl  r6  r  r  r  reMarginModer  s          rn  r=  zbinance.parse_margin_modeb1  s    ##J9!!(F3z:>$)6:GL..z<H$'4	'A7
LX&&
 	
ro  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  |d|      S )a  
        fetches option data that is commonly found in an option chain

        https://developers.binance.com/docs/derivatives/option/market-data/24hr-Ticker-Price-Change-Statistics

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `option chain structure <https://docs.ccxt.com/#/?id=option-chain-structure>`
        r{  rN   r   N)r  r  r  r  r  parse_option)rl  r{  r  r  r  r  chains          rn  fetch_optionzbinance.fetch_optionr1  st     	V$fTl
 ++DKK,HI2 xB/  f55ro  rD  c                    | j                  |d      }| j                  ||      }i d|dd d|d   dd dd dd dd d| j                  |d      d	| j                  |d	      d
d dd d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      dd S )Nr{  r  r3  r  r  impliedVolatilityrd  r  r  midPricer  r  r1  r  r  r  r  r  r  r  r  )r  r  r  )rl  rD  r3  r  r  s        rn  rC  zbinance.parse_option1  s[   . ##E84!!(F3
E

 fX&
 	

 
  
 D
 ((
;
 ((
;
 
 
 ))%=
 t//G
 d&&um<
 $**52FG
  $**5(;!
" 4#
 	
ro  c                 :   | j                          |t        | j                  dz         | j                  |      }| j	                  |d      }| j                  |d      }d|d   i}||dk(  rdnd|d	<   |||d
<   |||d<   |||d<   d}	|d   r"| j                  | j                  ||            }	nE|d   r"| j                  | j                  ||            }	nt        | j                  dz   |d	   z         | j                  |	      }
| j                  |
|||      S )a_  
        fetches the history of margin added or reduced from contract isolated positions

        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Get-Position-Margin-Change-History
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Get-Position-Margin-Change-History

        :param str symbol: unified market symbol
        :param str [type]: "add" or "reduce"
        :param int [since]: timestamp in ms of the earliest change to fetch
        :param int [limit]: the maximum amount of changes to fetch
        :param dict params: extra parameters specific to the exchange api endpoint
        :param int [params.until]: timestamp in ms of the latest change to fetch
        :returns dict[]: a list of `margin structures <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        Nz: fetchMarginAdjustmentHistory() requires a symbol argumentr  r{  rN   r  r  r  rp  r
  r  r  r  r  zE fetchMarginAdjustmentHistory() is not supported for markets of type )r  r4   rN   r  r  r  #fapiPrivateGetPositionMarginHistoryr  #dapiPrivateGetPositionMarginHistoryr5   parse_margin_modificationsr  )rl  r{  rp  r  r  r  r  r  r  r  modificationss              rn  fetch_margin_adjustment_historyz'binance.fetch_margin_adjustment_history1  sP    	>#DGG.j$jkkV$!!&'267+fTl
 $(EMaGFO#(GK $GG!&GI(??GU[@\]HI??GU[@\]HTWW'nnqwx~q  A  A  77A00uUUro  c                 l   | j                          | j                  |      }i }t        dt        |            D ]x  }||   }| j	                  |d      }| j                  |      }|||ddddddd| j                  | j                  | j	                  |d                  dddddddddddd||<   z |S )aG  
        fetches all available currencies that can be converted

        https://developers.binance.com/docs/convert/market-data/Query-order-quantity-precision-per-asset

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r   re  Nfractionr  )r  r   r  )r  rN   r  r'  rp  rO   r  r  r   r  r  r  r>  )r  sapiGetConvertAssetInfor  r  r  r  rj  rQ  )rl  r  r  r  r  r  rN   r  s           rn  fetch_convert_currenciesz binance.fetch_convert_currencies2  s     	//7 q#h-( 	AQKE!!%1B**2.D  !..t/C/CDDTDTUZ\fDg/hi  $#
  $#!
  $#   5F4L		@ ro  fromCodetoCodec                    |t        | j                  dz         | j                          |||d}| j                  | j	                  ||            }| j                  |      }| j                  |      }| j                  |||      S )a  
        fetch a quote for converting from one currency to another

        https://developers.binance.com/docs/convert/trade/Send-quote-request

        :param str fromCode: the currency that you want to sell and convert from
        :param str toCode: the currency that you want to buy and convert into
        :param float amount: how much you want to trade in units of the from currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.walletType]: either 'SPOT' or 'FUNDING', the default is 'SPOT'
        :returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
        z0 fetchConvertQuote() requires an amount argument)r  toAsset
fromAmount)r4   rN   r  sapiPostConvertGetQuoter  r3  parse_conversion)	rl  rS  rT  r  r  r  r  fromCurrency
toCurrencys	            rn  fetch_convert_quotezbinance.fetch_convert_quote92  s     >#DGG.`$`aa! 

 //GV0LM }}X.]]6*
$$X|ZHHro  c                    | j                          i }d}|dk(  s|dk(  rP|t        | j                  dz         ||d<   ||d<   ||d<   ||d<   | j                  | j	                  ||            }n&||d<   | j                  | j	                  ||            }| j                  |      }| j                  |      }	| j                  |||	      S )	ao  
        convert from one currency to another

        https://developers.binance.com/docs/convert/trade/Accept-Quote

        :param str id: the id of the trade that you want to make
        :param str fromCode: the currency that you want to sell and convert from
        :param str toCode: the currency that you want to buy and convert into
        :param float [amount]: how much you want to trade in units of the from currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
        Nr#  z1 createConvertTrade() requires an amount argumentclientTranIdre  targetAssetr  r  )r  r4   rN   sapiPostAssetConvertTransferr  sapiPostConvertAcceptQuoter3  rY  )
rl  rN   rS  rT  r  r  r  r  rZ  r[  s
             rn  create_convert_tradezbinance.create_convert_trade]2  s     	Ff$4~'2e(eff&(GN#'GG%+GM" &GH88Wf9UVH "$GI66t{{7F7STH }}X.]]6*
$$X|ZHHro  c                 b   | j                          i }d}|dk(  rad}| j                         }|| j                  |      }|d   |d<   ||d<   ||z
  |d<   ||d<   | j                  | j	                  ||            }n&||d	<   | j                  | j	                  ||            }|}	|dk(  r&| j                  |d
g       }
| j                  |
di       }	| j                  |	dd      }| j                  |	dd      }d}d}|| j                  |      }|| j                  |      }| j                  |	||      S )a  
        fetch the data for a conversion trade

        https://developers.binance.com/docs/convert/trade/Order-Status

        :param str id: the id of the trade that you want to fetch
        :param str [code]: the unified currency code of the conversion trade
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
        Nr#  r  rN   re  r  r
  r  r:  r  r   deductedAssetr  r_  rV  )
r  r  r3  &sapiGetAssetConvertTransferQueryByPager  sapiGetConvertOrderStatusr  r  r  rY  )rl  rN   r  r  r  r  msInDayr  r3  r[  r  fromCurrencyIdtoCurrencyIdrZ  r[  s                  rn  fetch_convert_tradezbinance.fetch_convert_trade2  s\    	6>G##%C==.#+D>  "GH#&=GK !$GIBB4;;wX^C_`H( "$GI55dkk'66RSH 6>>>(FB7D>>$2.D++D/;O))$yI
%==8L#|4J$$T<DDro  c                 r   | j                          i }d}| j                         }|||d<   n||z
  |d<   | j                  |dd      }|||d<   n||d<   | j                  |d      }d}	d}
d}d}|dk(  rH| j	                  |      }|d   |d<   |||d	<   d
}d}d}
| j                  | j                  ||            }	nT|d   |d   z
  |kD  rt        | j                  dz         |||d<   d}d}d}
| j                  | j                  ||            }	| j                  |	|
g       }| j                  ||||||      S )a  
        fetch the users history of conversion trades

        https://developers.binance.com/docs/convert/trade/Get-Convert-Trade-History

        :param str [code]: the unified currency code
        :param int [since]: the earliest time in ms to fetch conversions for
        :param int [limit]: the maximum number of conversion structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest conversion to fetch
        :returns dict[]: a list of `conversion structures <https://docs.ccxt.com/#/?id=conversion-structure>`
        l    H4 Nr
  r  r  r#  rN   re  r  rd  r_  r  zV fetchConvertTradeHistory() the max interval between startTime and endTime is 30 days.r  r  rV  r  )r  r  rL  r  r3  re  r  r5   rN   sapiGetConvertTradeFlowr  parse_conversions)rl  r  r  r  r  r  msInThirtyDaysr  r  r  responseQueryfromCurrencyKeytoCurrencyKeyr3  r  s                  rn  fetch_convert_trade_historyz#binance.fetch_convert_trade_history2  s    	#!#(GK #&#7GK %%fiA!(GI!$GI67+6>}}T*H'~GG "'-O)M"MBB4;;wX^C_`H( 	"W[%99^K   ,D  "D  E  E #( )O%M"M33DKK4PQH. ~~hr:%%dD/=RWY^__ro  
conversionrZ  r[  c                 ^   | j                  |g d      }| j                  |dd      }| j                  ||      }| j                  |dd      }| j                  ||      }||| j                  |      | j	                  |g d      || j                  |dd      || j                  |d	d
      d d d
S )N)rM  validTimestampr  rd  r  r_  rV  )r  r:  r  deductedAmountrW  targetAmounttoAmount)
r  r  r  rN   rZ  rW  r[  rx  r  r  )r  r  r  rP  rB  rO  )	rl  rs  rZ  r[  r  fromCurrS  torT  s	            rn  rY  zbinance.parse_conversion-3  s    N ''
4\]	$$Z+N**7LA
M9E((Z8"Y/$$Z1QR$,,Z9I<X **:~zR
 	
ro  c                    | j                          d}|%| j                  |      }| j                  |d         }d}d}| j                  d||d      \  }}d}| j	                  ||      r| j                  |      }n<| j                  ||      r| j                  |      }nt        | j                  dz         | j                  ||      S )av  
        fetch the funding rate interval for multiple markets

        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Get-Funding-Rate-Info
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Get-Funding-Info

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        Nr   rZ   r   r  zH fetchFundingIntervals() supports linear and inverse swap contracts only)r  r  r  r  rw  fapiPublicGetFundingInforu  dapiPublicGetFundingInfor?   rN   r@  r  s          rn  fetch_funding_intervalszbinance.fetch_funding_intervals3  s     	))'2G[[,F99:QSY[ackl>>$(44V<H__T7+44V<Htww)sstt '''::ro  r  c                    | j                          | j                  |      }|d}d|i}| j                  d||      \  }}|||d<   |||d<   d}| j                  d||      \  }}d}	|dk(  r*|d	   |d
<   | j	                  | j                  ||            }	nJ|dk(  r-|d   d   |d<   | j                  | j                  ||            }	nt        | j                  dz         | j                  |	|      S )a  
        fetches the long short ratio history for a unified market symbol

        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Long-Short-Ratio
        https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Long-Short-Ratio

        :param str symbol: unified symbol of the market to fetch the long short ratio for
        :param str [timeframe]: the period for the ratio, default is 24 hours
        :param int [since]: the earliest time in ms to fetch ratios for
        :param int [limit]: the maximum number of long short ratio structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest ratio to fetch
        :returns dict[]: an array of `long short ratio structures <https://docs.ccxt.com/#/?id=long-short-ratio-structure>`
        Nr   r  r  r
  r  r   r  rN   r{  r  r  r	  zG fetchLongShortRatioHistory() supports linear and inverse subTypes only)
r  r  r)  r  &fapiDataGetGlobalLongShortAccountRatior  &dapiDataGetGlobalLongShortAccountRatior5   rN   parse_long_short_ratio_history)
rl  r{  r  r  r  r  r  r  rq  r  s
             rn  fetch_long_short_ratio_historyz&binance.fetch_long_short_ratio_history3  s(    	V$Ii
 229gvN#(GK $GG99:VX^`fgh &tGHBB4;;wX^C_`H 	!$VnV4GFOBB4;;wX^C_`H TWW'ppqq228VDDro  c           	          | j                  |d      }| j                  |d      }|| j                  ||d d      || j                  |      d | j	                  |d      dS )Nr{  r  r  longShortRatio)r  r{  r  r  r  r  )r  safe_integer_omit_zeror|  rP  r  )rl  r  r  r  r  s        rn  parse_long_short_ratiozbinance.parse_long_short_ratio3  sl    , ##D(3//kB	&&xzJ"Y/"..t5EF
 	
ro  )N)NNNN)NNF)F)NN)__name__
__module____qualname__r   ri  r  r#   boolru  rw  rz  r  r-   r  r   r  r  r  r  r   r  r
   r  r/   r  dictr  rc  r   r  r  r   r  r%   r  r  r  r$   r  r  r  r&   r  r  r  r  r  r!  r)   rE  rS  r!   r    floatr   r\  rW  r  r  r  r   r  r  r   rY  r  r  r  r  r  r  r#  r4  rA  rJ  rQ  rT  rZ  rf  rr  rx  r{  rz  r  r?  r,   r  r  r  r   r  r  r.   r  r  r   r  r   r  r  r  r  r  r   r*   r  r(  r+   r.  r1  r'   r5  r;  r>  r(   rA  r3  r]  rX  r  r  r   r  r   r  r  r  r  r"   r  r  r  r  r  r  r  r   r   r   r	  r  r  r  r  r   r"  r%  r   r2  r	  rN  rz  r  rr  r  r  r  r  r   r  r  r  r	   r  r   r  r   r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r   r  r  r  r   r!  r   r4  r8  r   r;  r   r?  r=  r   rE  rC  rN  rR  r   r\  rb  rj  rr  rY  r~  r   r  r  __classcell__)rm  s   @rn  rK   rK   (   sr   J(# J(XP(s (S (D ('c 'C '4 '-t -;
3 ;
z-LS -L_ -L^YC Y YRU Yjm Y  zI YK.D !# 9s 94 ') ^Z ^@ $& Z$v, Zxg4 gF gRdAem dAL $& @X( @XD :>b Es E3 EY EN_4 _ _6 _B #% 
2 02 %33 %3f %3N 26b  5w  5D 48 :9 :9x&
f &
P 04B $5W $57 $5L 46 3s 3& 3@ 48 5 5w 58=
 =
4 =
~ 26DW[df v# vc vQT vkoptku vp~ ~v ~ ~@ 6:UW IA3 IAs IA# IA\`af\g IAV sw  @B ?.# ?.s ?.) ?.9 ?.^c ?.lo ?.B {  HJ g,# g,s g,) g,S\ g,fk g,tw g,R C  LN c 3 i W` jo x{ $ w{  DF A2c A23 A2i A2y A2bg A2ps A2F `drv  @B [S [# [Y [i [Y\ [lo [4 >@ M+$|"4 M+^: :k kv k kZ @B K+D$6 K+Z gksu `23 `2i `2y `2RW `2`c `2D os{} @33 @3i @3y @3Z_ @3hk @3D _a _C _y _PU _* RT ` `5 `( SU O OE O$ 26b ?2c ?23 ?2B *.Dt\^ AA3 AAc AA AAcghmcn AAF /3TXac QA QA3 QAc QAhlmrhs QAf 7;2 J23 J2 J2X 154VZce H# HS HPS Hjnotju H: 37TX\eg HC Hs HRU H: >BPTcgpr Fs F# F]` Fw{  }B  xC F@ 37r O2s O2C O2b /32 \ \| ;?r B3c B3C B3H 9=4^bkm XS X# XS XX[ X: -1tRV_a SAc SA SAC SAj 26DW[df C@3 C@c C@QT C@JA
f A
F *.Dt\^ dI3 dIc dI dIcghsct dIL -1tRV_a yIc yI yIC yIfjkvfw yIv$:Lx
T x
X x
Q\ x
t:C :C :c
t c
x c
= c
J
6 
4 [] U7S U7% U7c U7c U7an U7n +/TPT]_ DBC DBs DB# DBdhivdw DBL 79 &># &>^ &>P
 
N 
8 7;2 o
G o
b <@ 6I 6Ip@ @D DHPR ":S ":% ":# ":Wb ":H
T 
6 
EX 
: 57 ?4 ?4;N ?4B )+ g{ gR @B 7S 7> 68 %9 %9K %9N 8<$]ajl 7Q 7QC 7QWZ 7Qr
6 
" 6:" ;7 ; ;8:
6 :
[ :
xBj
v j
X\
F \
| -2" '0R 7;2 IFG IF- IFV& &$|J\ &P 24 )8S )8V 9=R 4Pg 4Pl6t 6V 6p 26b  Hw  HT(^  HD :>b wPw wPr 7;2 ePG ePN 37TX\eg 5BC 5Bs 5BRU 5Bn 9=R *S *# *X >B" 6# 6s 6p =A 2 2c 2h 26b 'Bw 'BY 'BR
t 
V 
x 
8 6:[_hj (Os (O# (OUX (OT 9=4^bkm 0Y# 0YS 0YX[ 0Yd'
R&P 7;2 #8S #8 #8+ #8J (,$TZ\ XC XCC XCs XCaefqar XCt5t 5x 5; 5n80C S \_ "
,C 
,C 
, &eBSW hPT C $D# Ds D Dc DTX D`c DL MO 2  !)r4VZce  MO "3 "H*
d *
F *
N` *
X @B DC D DFX D =? D De DCU D 9; ,C , ,< >@ 3 3DV 3& 24 *:8K *:X AESW`b 'Lc 'L# 'LS 'LR
 
(#
t #
V #
Oa #
J :< $
S $
L 57 6 02 3 0 15DW[jnwy JQ# JQc JQQT JQdg JQ  C  DR  S JQX
$ 
 
. 
  <> 9:s 9:v LN :C :s :> DF ": ":U ":H TV :S : :U :>
 
: BFTXgktv =Q# =Qc =Qad =Q~ 79 D# DLF $ 37TX\eg RKC RKs RKRU RKhQV Qf 02 !63 !6f !6F&
4 &
 &
6 &
P 7;2 	G 	 15R !
# !
F 59 YJ' YJ YJv 57 &; &;: &;P
D 
* 
  02 )63 )6f )6V+
$ +
( +
6 +
]c +
Z =Adaetx  BD 7Vc 7V 7V[^ 7Vnq 7V  IM  N`  Ia 7Vr /1 4Z 4l MQY[ "IC "I "Ic "I`j "IH W[ce *Is *Ic *I3 *IPS *Ijt *IX 8<B FEc FE FE: FEP 7;\`ik Z` Z`3 Z`VY Z`ptu  qA Z`xW
4 W
x W
\d W
pz W
r :>b &;w &;\ &;P <@RVeix|  FH <ES <EC <E_b <Eru <E  MQ  R`  Ma <E|
4 
 
> 
ro  rK   )Qccxt.base.exchanger   ccxt.abstract.binancer   rp  r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   typingr/   ccxt.base.errorsr0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   ccxt.base.decimal_to_precisionrG   rH   ccxt.base.preciserI   rK   rs  ro  rn  <module>r     s    ( -   T  T  T  T  T  T  T  T  T  T  T  * 0 - - . ' & . 1 ) . ) * 5 - ) , + . * ) + ( 3 4 %cO
h cO
ro  