
    !:h&l
                    @   d dl mZ d dlmZ d dl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/m0Z0m1Z1 d dl2m3Z3 d dl4m5Z5 d dl4m6Z6 d dl4m7Z7 d d	l4m8Z8 d d
l4m9Z9 d dl4m:Z: d dl4m;Z; d dl4m<Z< d dl4m=Z= d dl4m>Z> d dl4m?Z? d dl4m@Z@ d dl4mAZA d dl4mBZB d dl4mCZC d dl4mDZD d dl4mEZE d dl4mFZF d dl4mGZG d dl4mHZH d dl4mIZI d dl4mJZJ d dl4mKZK d dlLmMZM d dlLmNZN d dlOmPZP  G d  d!ee      ZQy)"    )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    T/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/async_support/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_inverse7
  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_modeC
  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_marketG
  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                   K   | j                  | j                  ddd      }| j                  |d|      }| j                  |d      }d}| j	                  dd|      \  }}d}| j                  ||      r| j                  |       d{   }nE| j                  ||      r| j                  |       d{   }n| j                  |       d{   }| j                  |d      S 7 \7 27 w)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>>$(!33E::H__T7+!33E::H!//66H  <88 ;:6s6   BC)C#+C)2C%3C)C'C)%C)'C)c                   K   | j                  | j                  d      }|sy| j                  d      sy| j                  | j                  d      }|y| j                  |      g}| j                  | j                  dd      }|r |j                  | j                  |             t        j                  |  d{   }|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-                  |      ||$|||||| j0                  | j                  |%d!      d"|
|<   l |
S 7 w)#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asynciogather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>?11$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 G 2s   B7M'9M$:J+M'c                   K   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          t!        j"                  |  d{   }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       }| j1                  ||      } | j                  d   r| j3                          d{    g }t        dt        |            D ]%  }|j	                  | j5                  ||                ' |S 7 W7 Hw)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 typeNcrossMarginPairsDataisolatedMarginPairsDatar{  symbolsoptionSymbolsr  )r  r  r  in_arrayr  r  r  publicGetExchangeInfor  r  sapiGetMarginIsolatedAllPairsfapiPublicGetExchangeInfodapiPublicGetExchangeInfoeapiPublicGetExchangeInfor0   rN   r  r  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  sF     ..~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  44/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] 5T .s9   DM8 M82M85C'M8M3DM8-M6.AM86M8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  
optionBaser4  r  r  r  r  r#  r  r  r  r  rX   r(  filtersByTyper*  r  r  r  r  r{  r  feesTyper  r0  r   r2  r5  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  ra  rc  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  r3  rY   r  r   assetr  umWalletBalancer`  umUnrealizedPNLr_  r  cmWalletBalancecmUnrealizedPNLcrossMarginBorrowedcrossMarginInterestrc  crossMarginFreecrossMarginLockedcrossMarginAssettotaltotalWalletBalancerX   
updateTimebalances
userAssetsr^  rb  ra  assetsr{  r!  r"  savingspositionAmountVosr  r  freezewithdrawingavailableBalanceinitialMarginmarginBalancers  r  r  )r  r  rt  r  r  rI   rd  r  r  r  safe_symbolr  re  safe_balancer  r  r  rR  )%rl  r  rp  r6  isPortfolioMarginr  r  r3  r  r  r  rt  
currencyIdr  rb  ra  
usedLinearusedInverse	totalUsedrr  rt  rs  rc  rv  rg  r  r{  r  r  baseCode	quoteCode	subResultrx  usedAndTotalfrozenrz  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                   K   | j                          d{    | 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(  rV| j                  ||      rd	}n| j                  ||      rd
}d}| j                  | j                  |	|             d{   }n,| j                  ||      red	}d}
| j                  |ddd      \  }
}| j                  |	|      }|
s| j                  |       d{   }n| j                  |       d{   }n| j                  ||      r-d
}| j                  | j                  |	|             d{   }nv|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                  |	|             d{   }n|dk(  s|dk(  r*| j/                  | j                  |	|             d{   }n|dk(  r*| j1                  | j                  |	|             d{   }nX|dk(  r*| j3                  | j                  |	|             d{   }n)| j5                  | j                  |	|             d{   }| j7                  ||||      S 7 47 J7 7 7 7 7 7 7 W7 /w)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>`
        Nr}   r  rX   rp  r  re  Fr  r  TuseV2r3  r
   r   r  ,rY   r  rw  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  sc    * !!!((~}V\]<99.$PVW $($C$CFN\bduw|$}!6
 >>~vV
E		%(~~dG,w/  $!00We1LMMH^^D'*DE 99&.RY[`aME6[[%0F!%!=!=f!EE!%!=!=f!EE__T7+D!77GU8STTH:%>>&)<LIIeY/E'lD1"nn\!_=G"1c,&78 ,!-a!^^F338+,
 +G%,	"!>>t{{7TY?Z[[HhJ'$9!66t{{7E7RSSHY!<<T[[RW=XYYHY!>>t{{7TY?Z[[H!33DKK4OPPHj ((4EVWWW 	"& N FE U \SY[Ps   M#M
C,M#MAM#M M#:M;>M#9M:B;M#5M63M#)M*.M#M.M#M)M#1M!2M#M#M#M#M#M#M#M#M#!M#r  c                 x  K   | j                          d{    | j                  |      }d|d   i}|||d<   d}|d   r*| j                  | j                  ||             d{   }n|d   r*| j	                  | j                  ||             d{   }nX|d   r*| j                  | j                  ||             d{   }n)| j                  | j                  ||             d{   }| j                  |d      }| j                  |||      }| j                  |d	d
      |d<   |S 7 7 7 7 r7 Jw)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
        Nr{  rN   r  r\   r  r  TlastUpdateIdur  )
r  r  eapiPublicGetDepthr  fapiPublicGetDepthdapiPublicGetDepthpublicGetDepthr  parse_order_bookrN  )	rl  r{  r  r  r  r  r  r  	orderbooks	            rn  fetch_order_bookzbinance.fetch_order_book  s@     !!!V$fTl
 $GG(!44T[[&5QRRHH!44T[[&5QRRHI!44T[[&5QRRH!00Wf1MNNHJ %%h4	))(FIF	!00>3O	'o 	" SRRNsY   D:D/AD:%D2&.D:D4.D:D6)D:-D8.AD:2D:4D:6D:8D: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  )rN  r  r~  rI   
string_mulr  safe_tickerrR  )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                    K   | j                  |       d{   }| j                  |d      }| j                  ddd||      ddd|dS 7 2w)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>`
        Nr*  okmaintenance)r  r.  )r*  updatedetar  r  )sapiGetSystemStatusr  )rl  r  r  	statusRaws       rn  fetch_statuszbinance.fetch_status  sb      11&99 $$Xx8	&&T'F	S\]
 	
 :s   AA
3Ac                 &  K   | j                          d{    | j                  |      }d|d   i}d}|d   r*| j                  | j                  ||             d{   }n|d   r*| j	                  | j                  ||             d{   }n|d   r*| j                  | j                  ||             d{   }nz| j                  |dd      }| j                  |d      }|r*| j                  | j                  ||             d{   }n)| j                  | j                  ||             d{   }t        |t              r%| j                  |d	i       }| j                  ||      S | j                  ||      S 7 m7 (7 7 7 7 Ww)
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>`
        Nr{  rN   r\   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  ss     !!!V$fTl
 (!55dkk'66RSSHH!99$++gv:VWWHI!99$++gv:VWWHnnVY>GYYvy1F!%!5!5dkk'66R!SS!%!9!9$++gv:V!WWh%..1b9K$$[&99  622- 	" TWW
 TWsl   FFAFF.FF	.F<F=AFF)F7F8AFF	FFFFr
  c                   K   | j                          d{    | j                  |dddd      }| j                  |      }d}| j                  d||      \  }}d}| j	                  d||      \  }}d}| j                  ||      r| j                  |       d{   }n| j                  ||      r| j                  |       d{   }nt|dk(  rQi }|#| j                  | j                  |            |d<   | j                  | j                  ||             d{   }nt        | j                  dz   |z   dz         | j                  ||      S 7 ;7 7 7 <w)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  s]     !!!%%gtT4F--g699/6SYZf99/6SYZ>>$(!??GGH__T7+!??GGHV^G"%)YYtw/G%H	"!;;DKKQW<XYYHtww)MMPTTWeeff!!(G44' 	" HG
 ZsG   EEBEE+EEAEE6EEEEc                 J  K   | j                          d{    | j                  |dddd      }| j                  |      }d}| j                  d||      \  }}d}| j	                  d||      \  }}d}| j                  ||      r| j                  |       d{   }ni| j                  ||      r| j                  |       d{   }n=|dk(  r| j                  |       d{   }nt        | j                  dz   |z   dz         | j                  ||      S 7 7 7 Y7 <w)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_pricesA  s5     !!!%%gtT4F--g699:KVU[\f99:KVU[\>>$(!<<VDDH __T7+!::6BBH V^!66v>>H tww)OORVVYgghh%%h88[ 	" E C ?sF   D#DBD#D+D#DD#$D!%6D#D#D#!D#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  r6  r  )r  r  r  rR  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                   K   | j                          d{    | j                  |dddd      }| j                  |      }d}| j                  d||      \  }}d}| j	                  d||      \  }}d}| j                  ||      r| j                  |       d{   }n| j                  ||      r| j                  |       d{   }n|dk(  rQi }|#| j                  | j                  |            |d<   | j                  | j                  ||             d{   }n=|dk(  r| j                  |       d{   }nt        | j                  dz   |z   dz         | j!                  ||      S 7 Z7 7 7 [7 >w)	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  sz     !!!%%gtT4F--g699.&RXYf99.&RXY>>$(!99&AAH__T7+!99&AAHV^G"%)YYtw/G%H	"!55dkk'66RSSHX!55f==Htww)LLtSVddee!!(G44+ 	" BA
 T=sY   E;E0BE;E3+E;E5AE;E7E;:E9;6E;3E;5E;7E;9E;c                   K   | j                          d{    | j                  |      }d}| j                  d||d      \  }}d}| j                  d||d      \  }}d|d   i}d}| j	                  ||      r*| j                  | j                  ||             d{   }nZ| j                  ||      r*| j                  | j                  ||             d{   }nt        | j                  dz   |z   dz         t        |t              r#| j                  | j                  |d	i       |      S | j                  ||      S 7 ,7 7 mw)
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  sK     !!!V$99:JFTZ\bcf99:JFTZ\defTl
 >>$(!;;DKKQW<XYYH__T7+!;;DKKQW<XYYHtww)NNQUUXffggh%$$T^^Ha%DfMM  622% 	" ZYs5   E	EBE	E;E	EA)E	E	E	c                 
  K   | j                          d{    | j                  |dddd      }| j                  |      }d}| j                  d||d      \  }}d}| j	                  d||d      \  }}d}| j                  ||      r| j                  |       d{   }nJ| j                  ||      r| j                  |       d{   }nt        | j                  dz   |z   dz         | j                  ||      S 7 7 c7 9w)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>>$(!;;FCCH__T7+!;;FCCHtww)OORVVYgghh!!(G44 	" DCs4   DC=BDC?+DD6D?DD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  rN  rQ  )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           	        K   | j                          d{    d}| j                  |ddd      \  }}|r| j                  d|||||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                  ||             d{   }n|
dk(  r[|d   r+| j                  | j                  ||             d{   }no| j!                  | j                  ||             d{   }nD|
dk(  rZ|d   r+| j#                  | j                  ||             d{   }n| j%                  | j                  ||             d{   }n|
dk(  rY|d   r*| j'                  | j                  ||             d{   }n| j)                  | j                  ||             d{   }n|d   r*| j+                  | j                  ||             d{   }nX|d   r*| j-                  | j                  ||             d{   }n)| j/                  | j                  ||             d{   }| j1                  |||||      }|S 7 L7 7 7 7 n7 <7 7 7 7 7 `7 8w)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
        NFr   paginaterR  rQ  rN  r  until)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_ohlcvF  s    2 !!!88z[`a&@@vW\^cenpvx|}}}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(!55dkk'66RSSHf_i !%!B!B4;;wX^C_!``!%!B!B4;;wX^C_!``gi !%!C!CDKKPWY_D`!aa!%!C!CDKKPWY_D`!aan$i !%!E!EdkkRY[aFb!cc!%!E!EdkkRY[aFb!ccH!55dkk'66RSSHI!55dkk'66RSSH!11$++gv2NOOH6 ##HfiN{ 	" ~P T a` ba dcSSOs   NM"9NM%EN M(!4NM+*N M.4N5M16*N M4!3NM7)N>M9?.N-M;..NM=)NM?N%N(N+N.N1N4N7N9N;N=N?N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buyr6  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  r6  takerOrMakerr  r  r%  r  )parse_dust_traderN  r  r  r  safe_bool_2rM  r  rI   r  
safe_traderR  safe_string_n)rl  r$  r  r  r  r  isSpotTrader  r{  r6  
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                 (  K   | j                          d{    d}| j                  |dd      \  }}|r| j                  d||||       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                  ||             d{   }n|d   s|	dk(  r*| j                  | j                  ||             d{   }n]|d   s|	dk(  r*| j                  | j                  ||             d{   }n)| j!                  | j                  ||             d{   }| j#                  ||||      S 7 7 7 7 ~7 L7 $w)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>`
        NFr   r  r{  rN   r\   r  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  rL  r  rM  rN  publicGetAggTradesparse_trades)rl  r{  r  r  r  r  r  r  r  rJ  isFutureOrSwapisHistoricalEndpointmaxLimitForContractHistoricalr  s                 rn  fetch_tradeszbinance.fetch_trades  sR    @ !!!88PZ[&::=&RWY^`fggg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)>>!55dkk'66RSSHH+C!C!88Wf9UVVHI&,D"D!88Wf9UVVH!44T[[&5QRRHF   65%@@S 	" h8 TVVRsj   HH6HHDHH
3HH3HH)H+H,HH
HHHHrN   r6  r  r  c           	      X  K   | j                          d{    | j                  |      }|d   s!t        | j                  dz   |d   z   dz         | j	                  |||||||      }	| j                  |	       d{   }
| j                  |
d      }| j                  ||      S 7 7 *w)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>`
        NrX   z" editSpotOrder() does not support rp   ordersnewOrderResponse)r  r  r?   rN   edit_spot_order_requestprivatePostOrderCancelReplacer  parse_order)rl  rN   r{  rp  r6  r  r  r  r  payloadr  datas               rn  edit_spot_orderzbinance.edit_spot_orderI  s     " !!!V$f~tww)MMPVW]P^^ajjkk..r64vuV\];;GDDP ~~h(:;f--] 	"
 Es"   B*B&A&B*=B(>)B*(B*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{  r6  MARKETLIMIT_MAKERrp  	stopPricer7  	STOP_LOSSLIMITSTOP_LOSS_LIMITr  
orderTypes+ triggerPrice parameter is not allowed for  rW  # is not a valid order type for the  marketr$  rX   ra  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%  rg  ra  rb  postOnly)r  rD  upperis_post_onlyrQ  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  r6  r  r  r  r  rb  r  initialUppercaseTypeuppercaseTypery  r7  validOrderTypesr$  brokerIdtimeInForceIsRequiredpriceIsRequiredtriggerPriceIsRequiredquantityIsRequiredr  quoteOrderQtyNewr  amountStringpriceStringquoteOrderQuantitycancelIds                                rn  rY  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  rW  rN   )r{  r6  r<  r)  r`  r  rc  rb  ra  )r  r?   rN   rz  r~  rD  r  r  )rl  rN   r{  rp  r6  r  r  r  r  r  rb  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           	        K   | j                          d{    | j                  |      }d}	| j                  |dddd      \  }	}|d   s|	r|d|vrt        | j                  dz         | j                  |||||||      }
d}|d   rV|	r*| j                  | j                  |
|             d{   }n| j                  | j                  |
|             d{   }nZ|d	   rU|	r*| j                  | j                  |
|             d{   }n)| j                  | j                  |
|             d{   }| j                  ||      S 7 57 7 v7 G7 w)
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dapiPrivatePutOrderr[  )rl  rN   r{  rp  r6  r  r  r  r  r  r  r  s               rn  edit_contract_orderzbinance.edit_contract_order  sq    & !!!V$ $($C$CFL_agiz  }B  %C!6(0(>'  3B  )B  C  C222vtT6SXZ`a( !%!4!4T[[&5Q!RR!%!9!9$++gv:V!WWI !%!4!4T[[&5Q!RR!%!9!9$++gv:V!WW8 &11] 	" SW SWsX   EEBE/E0)EE0E
E)E4E5EEEEEc           	      :  K   | j                          d{    | j                  |      }|d   r!t        | j                  dz   |d   z   dz         |d   r| j	                  |||||||       d{   S | j                  |||||||       d{   S 7 ~7 %7 w)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>`
        Nr\   z editOrder() does not support rp  rW  rX   )r  r  r?   rN   r^  r  )	rl  rN   r{  rp  r6  r  r  r  r  s	            rn  
edit_orderzbinance.edit_orderH  s     " !!!V$(tww)IIFSYNZ]ffgg&>--b&$feU[\\\11"fdD&RWY_``` 	"
 ]`s4   BBAB1B2BBBBBordersc           
        K   | j                          d{    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                  |       d{   }n|d   r| j                  |       d{   }| j!                  |      S 7 7 77 w)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>`
        Nr   r{  rN   rp  r6  r  r  r  r{   r  re  Fz6 editOrders() does not support portfolio margin ordersTrX   r\   z editOrders() does not support rW  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  r6  r  r  orderParamsr  orderRequestr  r  r  s                      rn  edit_orderszbinance.edit_ordersb  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.(!;;GDDHI!;;GDDHF   **E 	": EDs4   G+G$FG+/G'0G+G)G+'G+)G+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transactTimers  r  rs  r  r  r  r  origQtyr)  cummulativeQuoteQtycumBaserp  r6  fillsr=  GTXr0  limit_makerr  rg  r  r"  )r5  r%  rater  rN   
strategyIdr<  rb  newClientStrategyIdr  r  lastTradeTimestamplastUpdateTimestampry  
reduceOnlyr7  r  r%  )r  filled	remainingr*  r  rT  )r  
safe_orderr  r  r~  safe_integer_nrN  rI   	string_gtrM  r  rj  r  r  rR  r  )rl  ro  r  r  r*  r  
isContractr  r{  r  r  r  timestampValuer  r  r  r  r%  rp  r6  r  r=  ry  stopPriceStringr7  feeCostr  s                              rn  r[  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           	      z  K   | j                          d{    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                  |       d{   }n8|d   r| j                  |       d{   }n| j                  |       d{   }| j!                  |      S 7 7 Q7 47 w)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>`
        Nr   r{  rp  r6  r  r  r  FTrX   z! createOrders() does not support rW  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  r6  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.(!<<WEEHH!<<WEEH!<<WEEHF   ** 	"0 FEEsF   F;F2EF;#F5$F;F7F;F9F;5F;7F;9F;c                   K   | j                          d{    | 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                  |       d{   }n\|r8|r| j                  |       d{   }n=| j                  |       d{   }n"|d   rR|r6|r| j                  |       d{   }n| j                  |       d{   }n| j                  |       d{   }n|d   rR|r6|r| j                  |       d{   }n| j!                  |       d{   }n| j#                  |       d{   }nt|dk(  s|	|r6|r| j%                  |       d{   }nO| j'                  |       d{   }n5|r| j)                  |       d{   }n| j+                  |       d{   }| j-                  ||      S 7 7 x7 \7 D7 #7 7 7 7 7 7 7 h7 N7 6w)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>`
        Nrp  r6  r  re  Fr7  rg  r:  r;  trailingPercentcallbackRatesorSORr  )r  r  r  r\   r  r  rY   )r  r  r  rB  r  r  r  r  r  eapiPrivatePostOrderprivatePostSorOrderTestprivatePostSorOrderpapiPostUmConditionalOrderpapiPostUmOrderfapiPrivatePostOrderpapiPostCmConditionalOrderpapiPostCmOrderdapiPrivatePostOrderpapiPostMarginOrdersapiPostMarginOrderprivatePostOrderTestprivatePostOrderr[  )rl  r{  rp  r6  r  r  r  r  r  r6  porfolioOptionsValuer  r7  r:  r;  r  isTrailingPercentOrder
isStopLossisTakeProfitisConditionalr  r  r  r  s                           rn  create_orderzbinance.create_order:  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(!66w??H!%!=!=g!FF!%!9!9'!BBH  %)%D%DW%MMH%)%9%9'%BBH!%!:!:7!CCI  %)%D%DW%MMH%)%9%9'%BBH!%!:!:7!CC8#z'=AR !%!9!9'!BB!%!9!9'!BB!%!:!:7!CC!%!6!6w!??&11q 	"0 @ GB  NBC  NBC CB D?s   K/KEK/KK/7K8K/K#K/6K7K/KK/*K+"K/K!K/'K#(K/K%$K/&K''K/ K)K/K+K/6K-7K/K/K/K/K/K/K/!K/#K/%K/'K/)K/+K/-K/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  ra  rb  re  ri  rN   rd  Nrn   r  re  Fr  rY   r  
AUTO_REPAYsideEffectTyper7  rg  r:  r;  trailingDeltatrailingTriggerPriceactivationPrice)r  r  r  r  rZ   TRAILING_STOP_MARKETr  z. trailingPercent orders are not supported for rm  rW  stopLossOrTakeProfitstopLoss
takeProfitza trailingPercent orders require a stopLossOrTakeProfit parameter of either stopLoss or takeProfitrj  rr  100STOP_MARKETrh  STOPTAKE_PROFIT_MARKETrq  r\   r  rn  ro  r  rk  rl  r  r$  r  r  rX   r  r  rf  r3  Tr*  r  r=  r  r  rp  strategyTyperd   r  r%  r  r  z6 createOrder() requires a trailingPercent param for a rs  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>  r1  r0  LONGSHORTr  rA  selfTradePreventionModerC  
icebergQty)rp  ra  rb  ry  r:  r;  rg  r7  r  r  r  r%  r  r>  rA  rC  )r  r  r  rz  r  r  r  r  rD  r  r;   rN   rI   r  r  r  r  r  r|  r{  r  rG   r  r  rP  r~  r  r  )>rl  r{  rp  r6  r  r  r  r  r  rb  r  isMarketOrderisLimitOrderr  r  r6  r  r7  r:  r;  r  r  r  r  r  r  r  isTriggerOrderr  isPortfolioMarginConditionalisPriceMatchr  rg  r  trailingPercentConvertedr  clientOrderIdRequestr$  	defaultIdidMarketTyper  ry  typeRequestrd   r  r  r  r  r  r  r  r  r  r  marketAmountPrecisionisPrecisionAvailabler9  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                   K   | j                          d{    | j                  |      }|d   st        | j                  dz         d|i}| j	                  |d||d| j                  ||             d{   S 7 d7 w)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>`
        NrX   z6 createMarketOrderWithCost() supports spot orders onlyr%  r  r  r  r?   rN   r  r  )rl  r{  r6  r%  r  r  reqs          rn  create_market_order_with_costz%binance.create_market_order_with_cost  s      !!!V$f~tww)aabbD
 &&vxtT4;;WZ\bKcddd 	" e"   A?A;AA?6A=7A?=A?c                   K   | j                          d{    | j                  |      }|d   st        | j                  dz         d|i}| j	                  |dd|d| j                  ||             d{   S 7 d7 w)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>`
        NrX   z9 createMarketBuyOrderWithCost() supports spot orders onlyr%  r  r1  r  )rl  r{  r%  r  r  r  s         rn  !create_market_buy_order_with_costz)binance.create_market_buy_order_with_cost  s      !!!V$f~tww)ddeeD
 &&vxdDKKX[]cLdeee 	" fr  c                    K   | j                          d{    | j                  |      }|d   st        | j                  dz         ||d<   | j	                  |dd|d|       d{   S 7 U7 w)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>`
        NrX   z: createMarketSellOrderWithCost() supports spot orders onlyr  r  r0  )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  sx      !!!V$f~tww)eeff"&&&vxtVTTT 	"
 Us"   A0A,AA0'A.(A0.A0c                 &  K   |t        | j                  dz         | j                          d{    | 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                  |	|             d{   }nI|d   rW|r+| j                  | j                  |	|             d{   }n| j                  | j                  |	|             d{   }n|d   rV|r*| j                  | j                  |	|             d{   }n| j                  | j                  |	|             d{   }n|dk(  s||r`|r*| j!                  | j                  |	|             d{   }n]|dk(  rd|	d<   | j#                  | j                  |	|             d{   }n)| j%                  | j                  |	|             d{   }| j'                  ||      S 7 K7 e7 67 7 7 7 7 R7 *w)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   rc  rb  r\   r<  )rp  rb  rc  r  r  rY   r3  Tr*  )r4   rN   r  r  r  r  r  r  r  r  eapiPrivateGetOrderr  papiGetUmOrderfapiPrivateGetOrderpapiGetCmOrderdapiPrivateGetOrderpapiGetMarginOrdersapiGetMarginOrderprivateGetOrderr[  )rl  rN   r{  r  r  r  rp  r6  r  r  rb  r  s               rn  fetch_orderzbinance.fetch_order  s    & >#DGG.X$XYY!!!V$((|]TZ[<
!??fU
F $($C$CFLZ`bsuz${!6fTl
 **63FX$h+8(/<+,!#GI6#QR(!55dkk'66RSSHH !%!4!4T[[&5Q!RR!%!9!9$++gv:V!WWI !%!4!4T[[&5Q!RR!%!9!9$++gv:V!WWhJ$:?P !%!8!8Wf9U!VV+,0GL)!%!8!8Wf9U!VV!11$++gv2NOOH&11U 	", T SW SW W WOs   .JI;C(JI>1JJ*J6J70J'J()JJ	4JJ3J:J;)J$J%J>JJJJ	JJJJc                 z  K   |t        | j                  dz         | j                          d{    d}| j                  |dd      \  }}|r| j	                  d||||       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                  ||             d{   }n|d   r|
rX|r+| j!                  | j                  ||             d{   }nm| j#                  | j                  ||             d{   }nB| j%                  | j                  ||             d{   }n|d   r|
rV|r*| j'                  | j                  ||             d{   }n| j)                  | j                  ||             d{   }n| j+                  | j                  ||             d{   }n|
r*| j-                  | j                  ||             d{   }nd|dk(  s|	4|	dk(  rd|d<   | j/                  | j                  ||             d{   }n)| j1                  | j                  ||             d{   }| j3                  ||||      S 7 7 7 7 7 i7 A7 7 7 7 7 ]7 5w)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   r3  Tr*  )r4   rN   r  r  rO  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  sI    2 >#DGG.Y$YZZ!!!88PZ[&::=&RWY^`fgggV$((}mU[\bUcd<
!??vV
F $($C$CFM[actv{$|!6((1ST6#MNfTl
 229gvN#(GK $GG(!==dkk'SY>Z[[HH  %)%G%GT[]cHd%eeH%)%<%<T[[RX=Y%ZZH!%!=!=dkk'SY>Z![[I  %)%G%GT[]cHd%eeH%)%<%<T[[RX=Y%ZZH!%!=!=dkk'SY>Z![[ !%!<!<T[[RX=Y!ZZ!Z%;+,0GL)!%!<!<T[[RX=Y!ZZ!%!9!9$++gv:V!WWj   65%@@M 	" h( \  fZ[  fZ[ [ [Ws   .L;L6L;'L(C8L; L"!3L;L%*L;?L( *L;*L++3L;L.)L;L1	)L;2L33+L;L5:L;L7)L;L9L;L;"L;%L;(L;+L;.L;1L;3L;5L;7L;9L;c                 :  K   | j                          d{    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(  r9|||d<   |||d<   | j                  | j                  ||             d{   }n| j                  ||      r|	rX|
r+| j                  | j                  ||             d{   }n| j!                  | j                  ||             d{   }nl| j#                  | j                  ||             d{   }nA| j%                  ||      r|	rW|
r+| j'                  | j                  ||             d{   }n | j)                  | j                  ||             d{   }n| j+                  | j                  ||             d{   }n|dk(  s||	rz|	r*| j-                  | j                  ||             d{   }nw|dk(  rd|d<   |t/        | j                  dz         | j1                  | j                  ||             d{   }n)| j3                  | j                  ||             d{   }| j5                  ||||      S 7 h7 7 7 7 h7 *7 7 7 7 [7 3w)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   r3  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  s    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;;wPV;WXXH^^D'*  %)%H%HU\^dIe%ffH%)%=%=dkk'SY>Z%[[H!%!>!>t{{7TZ?[!\\__T7+  %)%H%HU\^dIe%ffH%)%=%=dkk'SY>Z%[[H!%!>!>t{{7TZ?[!\\X!7;L !%!=!=dkk'SY>Z![[+,0GL)~/:~0~!%!=!=dkk'SY>Z![[!66t{{7F7STTH  65%@@s 	": Y  g[\  g[\ \ \Ts   NM>E4NNA NN*N7N8*N"N
#A N#N$*NN)N8N94N-N.AN;N<)N%N&NNNN
NNNNNNNc                    K   |t        | j                  dz         | j                          d{    | j                  |      }d|d   i}d}| j	                  |dddd      \  }}| j                  |g d	      }| j                  |g d	      }|xr |}|rd
nd}	|||	<   d}
|d   r|rW|r+| j                  | j                  ||             d{   }
n| j                  | j                  ||             d{   }
n| j                  | j                  ||             d{   }
n|d   r|rV|r*| j                  | j                  ||             d{   }
n| j                  | j                  ||             d{   }
nd| j                  | j                  ||             d{   }
n:|d   rt        | j                  dz         |d   rt        | j                  dz         | j                  |
|      S 7 7 17 	7 7 7 7 `w)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?   r[  )rl  rN   r{  r  r  r  r  r  r	  orderIdRequestr  s              rn  fetch_open_orderzbinance.fetch_open_orderp  s    $ >#DGG.\$\]]!!!V$fTl
 !$($C$CFL\^dfwy~$!6((1ST6#EF(9(Km$)E9"$(  %)%G%GT[]cHd%eeH%)%<%<T[[RX=Y%ZZH!%!=!=dkk'SY>Z![[I  %)%G%GT[]cHd%eeH%)%<%<T[[RX=Y%ZZH!%!=!=dkk'SY>Z![[h"477-`#`aa"477-^#^__j &11m 	"   fZ[  fZ[s}   .HG=BHH *H:H;)H$H%2HH)HH
)H+H,AH HHHH
HHc                    K   |t        | j                  dz         | j                  ||d|       d{   }| j                  |dd      }| j	                  |||      S 7 *w)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   r7  	filter_byfilter_by_since_limitrl  r{  r  r  r  r  filteredOrderss          rn  fetch_closed_orderszbinance.fetch_closed_orders<  sh     . >#DGG._$_``((fEE(C)).%GG F   2A!A+A!c                    K   |t        | j                  dz         | j                  ||d|       d{   }| j                  |dd      }| j	                  |||      S 7 *w)  
        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  rO  rR  s          rn  fetch_canceled_orderszbinance.fetch_canceled_ordersY  sh     . >#DGG.a$abb((fEE*E)).%GG FrU  c                 4  K   |t        | j                  dz         | j                  ||d|       d{   }| j                  |dd      }| j                  |dd      }| j	                  ||      }| j                  |d      }	| j                  |	||      S 7 aw)rW  Nz: fetchCanceledAndClosedOrders() requires a symbol argumentr*  r  r  r  )r4   rN   r7  rP  r  sort_byrQ  )
rl  r{  r  r  r  r  canceledOrdersclosedOrdersrS  sortedOrderss
             rn   fetch_canceled_and_closed_ordersz(binance.fetch_canceled_and_closed_ordersv  s     . >#DGG.j$jkk((fEE*E~~fhA**><H||NK@)),uEE Fs   2BBA"Bc                 8  K   |t        | j                  dz         | j                          d{    | 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                  |
|             d{   }n|d   r|rX|	r+| j                  | j                  |
|             d{   }no| j                  | j                  |
|             d{   }nD| j!                  | j                  |
|             d{   }n|d   r|rV|	r*| j#                  | j                  |
|             d{   }n| j%                  | j                  |
|             d{   }n| j'                  | j                  |
|             d{   }n|dk(  s||r`|r*| j)                  | j                  |
|             d{   }n]|dk(  rd|
d<   | j+                  | j                  |
|             d{   }n)| j-                  | j                  |
|             d{   }| j/                  ||      S 7 7 7 7 f7 >7 7 7 7 7 X7 0w)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   )rc  rb  r  r\   rb  r  rc  r  r<  )rp  rc  rb  r  r)  rG  r*  r  r  rY   r3  Tr*  )r4   rN   r  r  r  r  r  r  r  r+  rD  r  eapiPrivateDeleteOrderr  papiDeleteUmConditionalOrderpapiDeleteUmOrderfapiPrivateDeleteOrderpapiDeleteCmConditionalOrderpapiDeleteCmOrderdapiPrivateDeleteOrderpapiDeleteMarginOrdersapiDeleteMarginOrderprivateDeleteOrderr[  )rl  rN   r{  r  r  r  rp  r6  r  r  r  rb  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(!88Wf9UVVHH  %)%F%Ft{{SZ\bGc%ddH%)%;%;DKKQW<X%YYH!%!<!<T[[RX=Y!ZZI  %)%F%Ft{{SZ\bGc%ddH%)%;%;DKKQW<X%YYH!%!<!<T[[RX=Y!ZZhJ$:?P !%!;!;DKKQW<X!YY+,0GL)!%!;!;DKKQW<X!YY!44T[[&5QRRH&11o 	": W  eYZ  eYZ Z ZRs   .LK>DLL3L6L7*L!L"*LL
3L L)L*L+)LL4L	L
3L=L>)L'L(LLLL
LLLLLLLc                   K   |t        | j                  dz         | j                          d{    | 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                  ||             d{   }	n|d   r|rX|r+| j                  | j                  ||             d{   }	no| j                  | j                  ||             d{   }	nD| j                  | j                  ||             d{   }	n|d   r|rV|r*| j                  | j                  ||             d{   }	n| j                  | j                  ||             d{   }	n| j!                  | j                  ||             d{   }	n|dk(  s||r`|r*| j#                  | j                  ||             d{   }	n]|dk(  rd|d<   | j%                  | j                  ||             d{   }	n)| j'                  | j                  ||             d{   }	t)        |	t*              r| j-                  |	|      S | j/                  d|	i      gS 7 7 7 7 7 b7 17 
7 7 7 }7 Uw)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  r9  r\   r  r  rY   r3  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(!@@WV\A]^^H H  %)%N%Nt{{[bdjOk%llH &*%C%CDKKPWY_D`%aaH "&!D!DT[[QXZ`Ea!bb I  %)%N%Nt{{[bdjOk%llH &*%C%CDKKPWY_D`%aaH "&!D!DT[[QXZ`Ea!bb hJ$:?P !%!C!CDKKPWY_D`!aa+,0GL)!%!@!@WV\A]!^^0 "99$++gv:VWWH, h%$$Xv66 H!  A 	" _  m  b c  m  b c b _0 Xs   .K$KB6K$'K
(3K$K*K$K*K$1K23K$%K&)K$K)K$9K:4K$.K/3K$"K #)K$K";K$
K$K$K$K$K$K$K$K$ K$"K$idsc                   K   |t        | j                  dz         | j                          d{    | j                  |      }|d   st	        | j                  dz         |d   |d}d}|d   r*| j                  | j                  ||             d{   }n.|d   r)| j                  | j                  ||             d{   }| j                  ||      S 7 7 G7 w)	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  rw  r{  r  r  r  r  s          rn  cancel_orderszbinance.cancel_orders  s       >#DGG.Z$Z[[!!!V$j!TWW'ZZ[[Tl
 (!>>t{{7TZ?[\\HI!>>t{{7TZ?[\\HH   622a 	" ]\s4   .C"CA%C"C.C"C C"C" C"c           	        K   |t        | j                  dz         | j                          d{    | j                  |      }| j	                  |d|d         }| j                  |d      }|dk7  rt        | j                  dz         d|i}| j                  |||| j                  ||             d{   S 7 7 w)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>`
        Nz. 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
 ))&%GU[@\]]] 	" ^s"   .B?B;BB?6B=7B?=B?c                 2  K   | j                          d{    d}| j                  |dd      \  }}|r| j                  d||||       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                  ||             d{   }n|t        | j                  dz         | j                  d|      \  }	}d}| j                  |dddd      \  }}|dk(  s|dk(  r|r+| j!                  | j                  ||             d{   }n|dk(  s|	4|	dk(  rd|d<   | j#                  | j                  ||             d{   }n| j%                  | j                  ||             d{   }n|d   rV|r*| j'                  | j                  ||             d{   }n| j)                  | j                  ||             d{   }nZ|d   rU|r*| j+                  | j                  ||             d{   }n)| j-                  | j                  ||             d{   }| j/                  ||||      S 7 7 7 7 >7 7 7 7 7 W7 /w)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>`
        NFr   r  rN   r{  r  r  r  i $r  r\   r  rR  r  z+ fetchMyTrades() requires a symbol argumentr  re  rX   rY   r3  Tr*  r  )r  r  rO  r  r  rN  r  r  r  r  eapiPrivateGetUserTradesr  r4   rN   r  r  papiGetMarginMyTradessapiGetMarginMyTradesprivateGetMyTradespapiGetUmUserTradesfapiPrivateGetUserTradespapiGetCmUserTradesdapiPrivateGetUserTradesrQ  )rl  r{  r  r  r  r  r  r  rp  r6  r  r  currentTimestamponeWeekr  r  s                   rn  r~  zbinance.fetch_my_trades  sq    * !!!88R\]&::?FTY[`bhiii
[[(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;;wPV;WXXH~'2_(_``!%!C!COU[!\J $(,(G(GP_agiz  }B  )C%vv~!1$%)%?%?GU[@\%]]Hh&J,B!Z/04-%)%?%?GU[@\%]]H%)%<%<T[[RX=Y%ZZH!$%)%=%=dkk'SY>Z%[[H%)%B%B4;;wX^C_%``H	"$%)%=%=dkk'SY>Z%[[H%)%B%B4;;wX^C_%``HD   65%@@} 	" j> Y  ^  ^Z  \`  \`s   LK>6LLC;L	L
A?L	L
;LL
)L/L00L L!)L
L0L;L<)L%L&LLLL
LLLLLLc                   K   | j                          d{    i }|||d<   | j                  |d      |d<   | j                  |d      }| j                  |d      }|||d<   | j	                  | j                  ||             d{   }| 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 7 #7 w)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userAssetDribbletsrq  r   userAssetDribbletDetailsTr&  )r  r  safe_string_upperr  sapiGetAssetDribbletr  r  r  r  r  r  rQ  rQ  )rl  r{  r  r  r  r  r  r  r  rowsr]  r  logsr   rT  s                  rn  fetch_my_dust_tradeszbinance.fetch_my_dust_trades  s`    & !!!#(GK !%%!<GI,,VV<66*"%0GM"224;;w3OPP< ..+?D  7A6q$ 	%A>>'!*.H"MD1c$i( %)-Q&DG$%	%
 ""4ue<))&%??a 	" Qs#   D>D9A1D>D<	B1D><D>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r5  r%  transferedAmountr  r1  r0  )rN   r  r  r{  ro  rp  r@  r6  r  r  r%  r  r  )	r  r  r  r5  r  rj  rI   
string_divrR  )rl  r$  r  r<  r  r  tradedCurrencybnbearnedCurrencyapplicantSymboltradedCurrencyIsQuotefeeCostStringr  r{  r  
costStringr6  r  rN   r  r  r%  rp  r@  s                           rn  rA  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                   K   | j                          d{    d}| j                  |dd      \  }}|r| j                  d||||       d{   S d}d}i }| j                  | j                  di       }	| j                  |dd      }
| j                  |d      }| j                  |d      }| j                  |d      }|
s||	v rc|| j                  |      }d	|d
<   |||d<   |||d<   | j                  | j                  ||             d{   }| j                  |dg       }nw|| j                  |      }|d   |d<   |*||d<   | j                  |d      }|t        ||      }||d<   |||d<   | j                  | j                  ||             d{   }t        d	t!        |            D ]
  }d||   d<    | j#                  ||||      S 7 7 7 7 Bw)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>`
        NFr   r  r*  r  fiatOnlyr  r   transactionType	beginTimer  r]  rN   r  r  r  r  r  rp  )r  r  rO  r  r  r  r  r  r5  sapiGetFiatOrdersr  r  r  r  sapiGetCapitalDepositHisrecr  r  parse_transactions)rl  r  r  r  r  r  r5  r  r  r*  r  r  rawr  r  s                  rn  fetch_depositszbinance.fetch_depositsC  s(      !!!88R\]&::?DRWY^`fggg^^DLL,C
>>&&%86:.!!&'267+
*==.)*G%& ',$ %*	"..t{{7F/KLLC~~c626H* ==."*4. ',$((5*5$!'51G%,	" #( !==dkk'SY>Z[[H6 q#h-( 	,A"+HQK	,&&x5%HHi 	" h" MD \sG   GG6GGC GGB
GG;GGGGc                   K   | j                          d{    d}| j                  |dd      \  }}|r| j                  d||||       d{   S | j                  | j                  di       }| j                  |dd      }| j                  |d      }i }| j                  |d      }	|	| j                  |d      }|	|d	<   d}
d}|s||v r\|| j                  |      }d
|d<   |||d<   | j                  | j                  ||             d{   }| j                  |dg       }
ng|| j                  |      }|d   |d<   |||d<   | j                  |d      |d	<   |||d<   | j                  | j                  ||             d{   }
t        dt        |
            D ]
  }d|
|   d<    | j!                  |
|||      S 7 7 z7 7 Bw)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>`
        NFr   r  r*  r  r  r  r  r  r  r  r]  rN   r  r  r  r  r   
withdrawalrp  )r  r  rO  r  r  r  r  r  r5  r  r  r  r  sapiGetCapitalWithdrawHistoryr  r  r  )rl  r  r  r  r  r  r*  r  r  r  r  r5  r  r  s                 rn  fetch_withdrawalszbinance.fetch_withdrawals  s      !!!88ASU_`&::;MtUZ\acijjj^^DLL,C
>>&&%86:.!!&'2YYvw/F!&GI
*==.)*G%& ',$..t{{7F/KLLC~~c626H@ ==."*4. ',$%)XXeZ%@	" #( !??GU[@\]]HP q#h-( 	/A".HQK	/&&x5%HHS 	" k" MT ^sG   GG6GGC GG
A:G	G
;GG
GG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  transactionr5  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successTimers  rp  r  r  r  r  r+  r*  r  transactionFeetotalFeer  transferTypeTFr  r  txidr  r  	addressToaddressFromtagtagTotagFromr5  r  )internalcommentr  )r  r  r  r  r  rN  r  r  r  r  r  rQ  r  rR  )rl  r  r5  rN   r  r  r  r  r  r  r  rp  txTyper+  r*  r  r  r  internalIntegerr  r  s                        rn  parse_transactionzbinance.parse_transactionJ  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transactionIdrg  r5  r  rp  r&  r
  r   r  
walletType	payerInforeceiverInfo	accountIdr  transactionTimer*  )	r  rN   r  r  r5  r  fromAccount	toAccountr*  )r  r  r  r  r  r  r  r  r  rN  r  rR  )rl  r   r5  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{  rg  rM  rZ   r  rw  )r  r{  r  r  r  rN   r  )r  r  r~  r  rR  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                   K   | j                          d{    | 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                  ||             d{   }| j                  ||      S 7 R7 w)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>`
        NrN   rg  r  rp  r{  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  r5  r  r  r  r  convert_type_to_accountrz  r4   rN   r  r  r5   sapiPostAssetTransferr  r  )rl  r  r  r  r  r  r5  r  r{  r  fromIdtoIdisolatedSymbolr&  fromIsolated
toIsolated
fromFuturetoFuturefromSpottoSpotr  r\   prohibitedWithIsolatedr  s                           rn  r   zbinance.transferI   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33DKK4PQQ ""8X66M 	"@ Rs"   I-I(H:I-I+I-+I-c                 &  K   | j                          d{    | j                  |d      }| j                  |d      }d}| j                  |dd      \  }}|r|s| j	                  d||||       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#                  ||             d{   }n)| j%                  | j#                  ||             d{   }| j'                  |ddg       }| j)                  ||||      S 7 q7 7 \7 4w)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>`
        Nr  Fr   r  r  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  rO  r5  r  r  r  r  r  r  r0   rN   joinr  sapiGetPayTransactionsr  sapiGetAssetTransferr  parse_transfers)rl  r  r  r  r  r  r  r5  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::;KTSXZ_aghhh}}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!88Wf9UVVHv "66t{{7F7STTH  &&"=##D(E5AAk 	" iF Wv UsG   JJAJ3J
4F<J0J1)JJ-J
JJJc                   K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  di       }| j	                  |d      }| j                  |||      }|||d<   | j                  |d      }| j                  | j                  ||             d{   }| j                  ||      S 7 7 w)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>`
        Nr  rN   r'  r  )
r  r5  r  r  r  r  r  sapiGetCapitalDepositAddressr  parse_deposit_address)rl  r  r  r5  r  r'  r  r  s           rn  fetch_deposit_addresszbinance.fetch_deposit_address&!  s      !!!==&HTN
 >>$,,
B?((;""8Wg>!(GIYYvy1F::4;;wPV;WXX ))(H==7 	" Ys"   CC	BC2C3CCc                 .   | j                  |d      }| j                  |d      }| j                  |d      }| j                  ||      }| j                  ||      }| j                  |dd      }t        |      dk(  rd }| j	                  |       |||||dS )Nr  r  r5  r  r  r   )r  r5  r  r  r  )r  r  get_network_code_by_network_urlr  check_address)	rl  r  r5  r  r  r  r  r  r  s	            rn  r
  zbinance.parse_deposit_addressN!  s     x/""8Y7%%h
;
&&z8< ::4Ex3s8q=C7#"
 	
ro  codesc                   K   | j                          d{    | j                  |       d{   }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 7 7 ĭw)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>`
        Nr   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_feesj!  s     !!!88@@d  q#h-( 	6AQKE))%8J**:6D..rBK!#L1c+./ 6*1~ ,,\9E	"55i@&&|]C25T";/6	6 %
 	
A 	"@s    C6C2C6C4CC64C6c                    K   | j                          d{    | j                  |       d{   }| j                  ||d      S 7 07 w)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>`
        Nr  )r  r  parse_deposit_withdraw_fees)rl  r  r  r  s       rn  fetch_deposit_withdraw_feesz#binance.fetch_deposit_withdraw_fees!  sO      !!!88@@V //%HHY 	"@s   AAAA	A	A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  r5  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                   K   | j                  ||      \  }}| j                  |       | j                          d{    | j                  |      }|d   || j	                  ||      d}|||d<   | j                  | j                  di       }| j                  |d      }	| j                  ||	|	      }	|	|	|d<   | j                  |d      }| j                  | j                  ||             d{   }
| j                  |
|      S 7 7 w)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>`
        NrN   )r  r  r  r  r'  r  )handle_withdraw_tag_and_paramsr  r  r5  r  r  r  r  r  r  sapiPostCapitalWithdrawApplyr  r  )rl  r  r  r  r  r  r5  r  r'  r  r  s              rn  r   zbinance.withdrawU"  s     99#vFV7#!!!==&TN00v>
 ?$'GL!>>$,,
B?((;""8Wg>!(GIYYvy1F::4;;wPV;WXX%%h99' 	"" Ys"   :DDB4D1D
2D
D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~  rQ  )rl  r  r  r  r{  s        rn  parse_trading_feezbinance.parse_trading_feey"  sj    $ ##C2!!(FD&A''->@UV''->@UV
 	
ro  c                 ^  K   | j                          d{    | j                  |      }|d   }d}| j                  d||      \  }}d}| j                  |dddd      \  }}| j	                  ||      }| j                  ||      }d|d   i}	d}
|rV|r*| j                  | j                  |	|             d{   }
n| j                  | j                  |	|             d{   }
n|rV|r*| j                  | j                  |	|             d{   }
nS| j                  | j                  |	|             d{   }
n)| j                  | j                  |	|             d{   }
|
}t        |t              r| j                  |d	i       }| j                  ||      S 7 7 7 7 7 n7 Fw)
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>`
        Nrp  r   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"  s      !!!V$f~99:KVU[\ $($C$CFL]_egxz  %A!6>>$0OOD'2	fTl
  !%!=!=dkk'SY>Z![[!%!B!B4;;wX^C_!`` !%!=!=dkk'SY>Z![[!%!B!B4;;wX^C_!``!66t{{7F7STTH( dD!>>$2.D%%dF33_ 	" \` \`Tsj   F-F B!F-8F#9)F-"F%#-F-F')F-:F);)F-$F+%<F-#F-%F-'F-)F-+F-c                   K   | j                          d{    d}| j                  dd|      \  }}d}| j                  dd|d      \  }}|dk(  xs |dk(  }| j                  ||      }| j	                  ||      }d}|r| j                  |       d{   }n7|r| j                  |       d{   }n|r| j                  |       d{   }|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7 F7 7 7 w)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	!66v>>H!==fEEH!77??Hb  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u 	" ?E?sT   I(IA=I(II(0I"1I(I%CI(%B%I(I(I("I(%I(c                 0  K   |dk  s|dkD  rt        | j                  dz         | j                          d{    | j                  |      }|d   ||d}| j	                  | j                  ||             d{   }| j                  ||      S 7 Y7 w)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 4NrN   )rg  r  rp  )r4   rN   r  r5  sapiPostFuturesTransferr  r  )rl  r  r  rp  r  r5  r  r  s           rn  futures_transferzbinance.futures_transfer#  s      1H$(#DGG.M$MNN!!!==&d^

 55dkk'66RSS ""8X66 	" Ts"   6BBAB;B<BBc                   K   | j                          d{    | j                  |      }d|d   i}d}|d   r*| j                  | j                  ||             d{   }nG|d   r*| j	                  | j                  ||             d{   }nt        | j                  dz         |d   r|d   }| j                  ||      S 7 7 j7 =w)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>`
        Nr{  rN   r  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
 (!;;DKKQW<XYYHI!;;DKKQW<XYYHtww)iijj){H &&x885 	" ZYs4   CCACC	.CC:C	CCc                   K   | j                          d{    i }d}| j                  |dd      \  }}|r| j                  d|||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                  ||             d{   }nZ| j                  ||
      r*| j                  | j                  ||             d{   }nt        | j                   dz   |z   dz         | j#                  ||	||      S 7 7 7 y7 ?w)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>`
        NFr   r  r   r  r[   rp  r{  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&@@AZ\bdikprvx~((7PR_aij<[[(FH%F &tGH99:SU[]cemn66*#(GK !!&'2##FIu=6Iw#78!(GI$GG>>$(!::4;;wPV;WXXH__T7+!::4;;wPV;WXXHtww)[[^bbeoopp 0065%PPO 	"
 @, YXsF   GG9GGDGG;GG8GGGG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  rR  )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                 (  K   | j                          d{    | j                  |      }| j                  | j                  ddd      }| j	                  |d|      }d}| j                  dd|d      \  }}| j                  |d      }d}| j                  ||      r| j                  |       d{   }nD| j                  ||      r| j                  |       d{   }nt        | j                  dz         | j                  ||      S 7 7 ]7 3w)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
        Nr   r  r[   rp  r  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		&&)>>$(!;;EBBH__T7+!;;EBBHtww)jjkk''':: 	" CBs4   DDBD0D1+DD0DDD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  rR  )rl  r  r  r  r  r{  r  r  rG  rH  rX  rA  r	  intervalStrings                 rn  r7  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	positionsrv  r   rg  crossWalletBalance
crossUnPnl)crossMarginrX  r{  r  r  r  r  maintMarginr  z
0.00000000rZ  )r  r  r  r  r  rI   rd  r  parse_account_positionr  r  )rl  rt  filterClosedrW  rv  rt  r  r  r  r  rX  rY  r  r  r  r  maintenanceMarginisPositionOpenparseds                      rn  parse_account_positionszbinance.parse_account_positionsh$  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  r|  r.  r  rR  1e-8rK  r[  
entryPricenotionalValuepositionAmtr  z0.5r   leverageBracketsr  unrealizedProfitrs  r3  isolatedMarginr  isolatedWalletr  rX  rZ  shortlong5e-5r  r  r8  r  r  z5e-r~  r  BOTHr  rN   r  r  initialMarginPercentager^  maintenanceMarginPercentageunrealizedPnl	contractsmarginRatioliquidationPrice)r  
collateralr6  r6  r>  r  )r  r  intrj  rI   r  is_round_numberrd  r  
string_absr  r  r  r  r  r  	string_ltr  r  r  r  r  string_equals
string_subprecision_from_stringr  rR  )<rl  r  r  r  r{  leverageStringr  initialMarginStringr|  initialMarginPercentageStringrationalusdmmaintenanceMarginStringr^  entryPriceStringrd  notionalStringnotionalStringAbsrK  contractsStringcontractsStringAbsentryNotionalcontractSizeNewrr  rg  rx  !maintenanceMarginPercentageStringr  bracketrp  unrealizedPnlStringrq  r  r3  isolatedMarginRawr6  collateralStringwalletBalanceru  rs  r6  r  liquidationPriceStringRawrt  r  contractSizeString(onePlusMaintenanceMarginPercentageStringentryPriceSignStringleftSide	rightSider   r9  pricePrecisionPlusOnepricePrecisionPlusOneStringrounderrounderStringliquidationPriceRoundedStringtruncatedLiquidationPricer  r>  s<                                                               rn  r\  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  ri  rg  rK  re  r   r  rf  unRealizedProfitrt  r  r  r  r3  rl  rk  rd  r  r  r  r  r  r.  r8  r  rs  r[  r  rR  r  rc  r|  rm  r  r  r  rn  r  rN   rr  rq  ru  r  ro  r^  rp  )	rs  r  r6  r  r6  r>  r  r:  r;  )r  r  r  r  r  r  rI   rx  r  r  ry  rj  r  r  r  r  r  rd  r  r|  r  r{  r  rv  rw  rz  rR  )7rl  r  r  r  r{  isolatedMarginStringrg  rx  r  r  r  r  r  rK  contractsAbsrr  r  rq  liquidationPriceStringrt  r  r6  r6  r  rd  r  r  r  r  basePrecisionValuequotePrecisionValueprecisionIsUndefinedr  r  innerr  r<  r  basePrecisionru  r  r  rp  r  r^  r~  r  r}  r  r  	unroundedrs  r  r  r>  s7                                                          rn  parse_position_riskzbinance.parse_position_risku%  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                   K   | j                          d {    | 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                  ||      r6|r| j                  |       d {   }	nz| j                  |       d {   }	n`| j                  ||      r6|r| j                  |       d {   }	n2| j                  |       d {   }	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 7 &7 d7 M7 "7 w)Nrg  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  rg  r  rp  r  rq  r  r  r  r  r  r{  r  r  r   r  
floorValuerp  s                       rn  load_leverage_bracketszbinance.load_leverage_bracketsS&  si    !!!  >>$,,8JK$&**4<<QK##FFK@DIIff-EG"==>TVZ\bdlmOGV $(,(G(GPfhn  qB  DI  )J%vH~~dG,$%)%B%B5%IIH%)%G%G%NNHw/$%)%B%B5%IIH%)%I%I%%PPH"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 ||.//M 	"  JN  JPsY   IH<CIH?I5I6-I#I$I=I>C?I?IIIIc                 `  K   | j                          d{    d}| j                  dd|      \  }}d}| j                  dd|d      \  }}d}| j                  |dddd      \  }}d}| j	                  ||      r6|r| j                  |       d{   }nz| j                  |       d{   }n`| j                  ||      r6|r| j                  |       d{   }n2| j                  |       d{   }nt        | j                  dz         | j                  ||d      S 7 7 7 }7 Q7 9w)	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|&  sH     !!!99:NPTV\]f99:NPTV\^fg $($C$CFL`bhj{  ~C  %D!6>>$( !%!>!>v!FF!%!C!CF!KK__T7+ !%!>!>v!FF!%!E!Ef!MMtww)kkllN ((7HEEu 	" GK GMsX   D.D#A9D.D&D.*D(+-D.D*D.2D,31D.&D.(D.*D.,D.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{  r5  rJ  rL  maintenanceMarginRatemaxLeverager  )	r  r  r  r  r  r  r  r~  rQ  )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                 (  K   | j                          d{    | j                  |      }|d   st        | j                  dz         d|d   i}| j	                  | j                  ||             d{   }| j                  |d   |      S 7 w7 w)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>`
        Nr\   z- fetchPosition() supports option markets onlyr{  rN   r   )r  r  r?   rN   eapiPrivateGetPositionr  parse_positionr8  s         rn  fetch_positionzbinance.fetch_position&  s      !!!V$htww)XXYYfTl
 44T[[&5QRR0 ""8A;77? 	" Ss"   BBAB4B5BBc                    K   | j                          d{    | j                  |      }i }d}|[d}t        |t              r.t	        |      }|dkD  rt        | j                  dz         |d   }n|}| j                  |      }|d   |d<   | j                  | j                  ||             d{   }g }t        dt	        |            D ]&  }	|j                  | j                  ||	   |             ( | j                  |d|d      S 7 7 Zw)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44T[[&5QRR0 q#h-( 	DAMM$--hqk6BC	D--fhOOU 	" Ss#   DD
BD1D2ADD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   r6  r)  rl  r8  rM  r  rN   rd  r  rK  	markValueru  positionCostrq  unrealizedPNLrr  r  r  r  r>  r^  rp  r|  )ro  r  rt  rs  r6  r  )
r  r  rM  rI   r  r  safe_positionr  rj  rR  )rl  r  r  r  r{  r6  r)  r  s           rn  r  zbinance.parse_positionP'  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                   K   d}| j                  |dd      \  }}|>| j                  | j                  d      }|| j                  | j                  dd      }nd}|dk(  r| j	                  ||       d{   S |dk(  r| j                  ||       d{   S |dk(  r| j                  ||       d{   S t        | j                  dz   |z   dz         7 `7 C7 &w)	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   rJ  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*227FCCCi'55gvFFFh&44WfEEEtww)ggjww  {G   G  H  H DFEs6   A3C5C6CCC3C4#CCCc                 ,  K   |(t        |t              st        | j                  dz         | j	                          d{    | j                  d|       d{    | j                  | j                  dd      }| j                  |d|      }| j                  |d      }d}| j                  dd|d      \  }}d}| j                  |dd	d
d      \  }}d}| j                  ||      rk|r| j                  |       d{   }nd}| j                  |ddd      \  }}|s| j                  |       d{   }nz| j                  |       d{   }n`| j!                  ||      r6|r| j#                  |       d{   }n2| j%                  |       d{   }nt'        | j                  dz         d}	| j                  |ddd      \  }	}| j)                  ||	      }
| j+                  |      }| j-                  |
d|d      S 7 7 7 7 7 7 7 |w)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 onlyr]  r{  )r  r  r4   rN   r  r  r  r  r  r  r  rw  papiGetUmAccountr  r  r  ru  papiGetCmAccountr  r?   ra  r  r  )rl  r
  r  r  rp  rq  r  r  r  r]  r  s              rn  r  zbinance.fetch_account_positions'  s(    & gt,'2l(lmm!!!))%888&&t||]HM<66*99:QSWY_aij $($C$CFLcekm~  AF  %G!6>>$( !%!6!6v!>> $ = =fF]_fhm nv%)%A%A&%IIH%)%A%A&%IIHF __T7+ !%!6!6v!>>!%!;!;F!CCtww)gghh#<<VE\^lnstf--hE%%g.--fhOOC 	"8 ?
  JIJ ?Cs   >H HHHB#H>H	?4H3H4HH-H;H<HHA.HH	HHHHHc                 @  K   |(t        |t              st        | j                  dz         | j	                          d{    | j                  d|       d{    i }d}| j                  | j                  d|      }| j                  |d|      }d}| j                  dd|d      \  }}d}| j                  |dd	d
d      \  }}| j                  |d      }d}| j                  ||      r|r*| j                  | j                  ||             d{   }nd}	| j                  |ddd      \  }	}| j                  ||      }|	s| j                  |       d{   }n| j!                  |       d{   }n| j#                  ||      rV|r*| j%                  | j                  ||             d{   }nB| j'                  | j                  ||             d{   }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 7 K7 47 7 ;7 $7 7 w)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   rd  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#(  s    $ gt,'2p(pqq!!!))%888&&t||]KP<99:NPTV\^fg $($C$CFL`bhj{  ~C  %D!666*>>$( !%!;!;DKKQW<X!YY $ = =fFZ\cej kvWf5%)%F%Fv%NNH%)%F%Fv%NNH6 __T7+ !%!;!;DKKQW<X!YY!%!@!@WV\A]!^^tww)kklld q#h-( 	EA"1+K#//\J  !137d66x{CD		E
 %%g.--fhOOa 	"8 Z  ON: Z^s   >J JJJB7JJAJJJ3J4=J1J2)JJA$JAJJJJJJJc                   K   | j                          d{    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                  |
|      rV|r*| j                  | j                  ||             d{   }n| j                  | j                  ||             d{   }n| j                  |
|      rV|r*| j!                  | j                  ||             d{   }nB| j#                  | j                  ||             d{   }nt        | j                  dz         | j%                  ||||      S 7 7 7 7 b7 :w)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*>>$( !%!5!5dkk'66R!SS!%!:!:4;;wPV;W!XX__T7+ !%!5!5dkk'66R!SS!%!:!:4;;wPV;W!XXtww)llmm!!(FE5AAG 	"2 TX TXsX   G<G1DG<-G4.)G<G6=G<G8)G<?G: 2G<4G<6G<8G<:G<r  c                   K   |t        | j                  dz         |dk  s|dkD  rt        | j                  dz         | j                          d{    | j	                  |      }|d   |d}d}| j                  |dd	d
d      \  }}d}|d   rX|r+| j                  | j                  ||             d{   }|S | j                  | j                  ||             d{   }|S |d   rX|r+| j                  | j                  ||             d{   }|S | j                  | j                  ||             d{   }|S t        | j                  dz         7 7 7 7 P7 'w)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)  s     >#DGG.Y$YZZ qLhnTWW'NNOO!!!V$Tl 
 !$($C$CFM[actv{$|!6( !%!8!8Wf9U!VV  "&!=!=dkk'SY>Z![[  I !%!8!8Wf9U!VV
  "&!=!=dkk'SY>Z![[  tww)ddee) 	" W[ W[s[   AE)EA$E)7E!8*E)"E##1E)E%*E)?E' E)!E)#E)%E)'E)r6  c                   K   |t        | j                  dz         |j                         }|dk(  rd}|dk7  r|dk7  rt        | j                  dz         | j	                          d{    | j                  |      }|d   |d}d}	 |d	   r+| j                  | j                  ||             d{   }|S |d
   r+| j                  | j                  ||             d{   }|S t        | j                  dz         7 7 P7 "# t        $ rD}t        |t              r'| j                  | j                  dd      }|r|ddd}n|Y d}~|S d}~ww xY w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   rz  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!%!?!?GU[@\!]]& % 	"!%!?!?GU[@\!]]"  #477-j#jkk 	" ^]  	 !12,0NN4<<Idfk,l),G(-6VWH  	sx   A'E)D*E
)D 3D4D 8E:)D #D$D (E*D ED D 	E9E
EEEr>  c                   K   | 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                  ||      rX|r+| j                  | j                  |	|             d{   }
|
S | j                  | j                  |	|             d{   }
|
S | j                  ||      rX|r+| j                  | j                  |	|             d{   }
|
S | j                  | j                  |	|             d{   }
|
S t        | j                  dz         7 7 7 M7 $w)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_modee)  s      &&t||]HM<6F8,99:KTSYZ $($C$CFL]_egxz  %A!6%& 0
 ??4) !%!@!@WV\A]!^^   "&!E!EdkkRY[aFb!cc  ^^D'* !%!@!@WV\A]!^^  "&!E!EdkkRY[aFb!cc  TWW'ffgg _c _csH   B=E;?E3 *E;*E5+>E;)E7**E;E9E;5E;7E;9E;c                   K   | j                          d{    | j                  d|       d{    d}| j                  dd|      \  }}d}| j                  dd|d      \  }}d}| j	                  |dddd      \  }}d}| j                  ||      r6|r| j                  |       d{   }nz| j                  |       d{   }n`| j                  ||      r6|r| j                  |       d{   }n2| j                  |       d{   }nt        | j                  dz         | j                  |dg       }t        |t              r|}| j!                  ||d	      S 7 L7 57 7 7 y7 aw)
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>`
        NFr   r  r  re  z< fetchLeverages() supports linear and inverse contracts onlyrW  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)  st     !!!))%88899:JDRXYf99:JDRXZbc $($C$CFL\^dfwy~$!6>>$( !%!6!6v!>>!%!@!@!HH__T7+ !%!6!6v!>>!%!;!;F!CCtww)gghhNN8["=	h% I##IwAA1 	"8 ?H ?Csi   E0E"E0E%A9E0*E(+E0E*-E02E,3E0E.AE0%E0(E0*E0,E0.E0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{  r3  r  r  crossedr  r  bothrl  rk  )r  r{  r6  longLeverageshortLeverage)r  r  rM  r  r~  )rl  r  r  r  marginModeRawr6  marginTypeRawr6  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                   K   | j                          d{    |dn| j                  |      }d}| j                  d||      \  }}|dk7  rt        | j                  dz         i }||d   }|d   |d   z   |d<   |||d	<   |||d
<   | j                  | j                  ||             d{   }| j                  ||      }	| j                  |	d      }
| j                  |
|||      S 7 7 >w)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_settlementsrZ  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;;wPV;WXX ,,Xv>k;700NN9 	" Ys"   C/C+BC/.C-/=C/-C/c                   K   | j                          d{    |dn| j                  |      }d}| j                  d||      \  }}|dk7  rt        | j                  dz         i }||d   |d<   |||d<   |||d<   | j                  | j                  ||             d{   }| j                  ||      }	| j                  |	d	      }
| j                  |
|d   ||      S 7 7 Aw)
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  rZ  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;;wPV;WXX* ,,Xv>k;7009I5RWXXI 	" Ys#   C'C#BC'#C%$A C'%C'c                     | j                  |dd      }| j                  |d      }|| j                  ||      | j                  |dd      || j	                  |      dS )Nr%  
createDater{  realStrikePriceexercisePrice)r  r{  r  r  r  )rN  r  r~  rQ  rR  )rl  
settlementr  r  r  s        rn  parse_settlementzbinance.parse_settlement:*  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_settlementsc*  sI    F q#k*+ 	IAMM$//AGH	Iro  c                   K   | j                          d{    d}| j                  dd|      \  }}|dk7  rt        | j                  dz         | j	                  d|d       | j                  |      }||d   d}| j                  | j                  ||             d{   }| j                  |d|      }| j                  ||      S 7 7 +w)	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   )recordIdr5  r   )
r  r  r5   rN   check_required_argumentr5  eapiPrivateGetBillr  r  parse_ledger_entry)	rl  rN   r  r  rp  r5  r  r  firsts	            rn  fetch_ledger_entryzbinance.fetch_ledger_entry*  s      !!!99:LdTZ[f8TWW']]^^$$%7vF==& 
 00Wf1MNN xH5&&uh771 	" Os"   CC
B	C C!*CCc           	        K   | j                          d{    d}| j                  |dd      \  }}|r| j                  d||||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(  rE| j                  d|d       |d   |	d<   | j                  | j                  |	|             d{   }n| j                  ||      rV|r*| j                  | j                  |	|             d{   }n| j                  | j                  |	|             d{   }n| j                  ||      rV|r*| j!                  | j                  |	|             d{   }nB| j#                  | j                  |	|             d{   }nt%        | j&                  dz         | j)                  ||||      S 7  7 7 7 7 7 h7 @w)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>`
        NFr   r  r  r  r  r  r  re  r\   r  rN   r5  z- fetchLedger() supports contract wallets only)r  r  rO  r5  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  r5  r  r  r  r  s                rn  fetch_ledgerzbinance.fetch_ledger*  sq    ( !!!88PZ[&::=$PUW\^dfjlqrrr}}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!44T[[&5QRRH^^D'* !%!5!5dkk'66R!SS!%!:!:4;;wPV;W!XX__T7+ !%!5!5dkk'66R!SS!%!:!:4;;wPV;W!XXtww)XXYY:   8UEBBI 	" s. S TX TXs|   IH68IH9C$I4H<5=I2H?3)II=II)II2I9I<I?IIII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  outr8  inrg  r  rM  rp  r  rN   r  r;  )r  rN   	directionrt  referenceAccountreferenceIdrp  r5  r  r  r  beforeafterr*  r  )r  rI   	string_ler  r  r  safe_currencyrN  safe_ledger_entryparse_ledger_entry_typerj  rR  )	rl  r*  r5  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  r3  )REFERRAL_KICKBACK
COMMISSIONr  )rl  rp  
ledgerTypes      rn  r6  zbinance.parse_ledger_entry_typeA+  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)	r5  r  r  r  r  r  r  
startswithget_base_domain_from_url)rl  rM  rN  r  r5  r'  networkCodesr  currentNetworkCoder  siteUrls              rn  r  z'binance.get_network_code_by_network_urlY+  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  rR  z binance.get_base_domain_from_urlj+  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)r\  Content-TyperZ  z5 userDataStream endpoint requires `apiKey` credentialr  r
  r  r  r  r  r  r   r   r   r   r  r  rL  POSTro  r  ra  r  rX   r[   r  r  r$  r  PUTr   r  r  r<  zsub-accountr=  stakingzsimple-earnDELETEry  origclientorderidlist&zorderidlist=%5Bz%2Cz%5Dzorigclientorderidlist=%5BzPRIVATE KEYx   sha256ed25519z&signature=?r]  )r  rJ  bodyheaders) r   r?   rN   apiKeyr1   	urlencoder  r  r  r  r  r|  r  r  r  r  r  r  r  r  urlencode_with_array_repeatr  	rawencoder  secretencode_uri_componentrsaeddsaencodehmachashlibre  )rl  pathr  rJ  r  ri  rh  r   r  r>  ra  r0  r  r  r$  r  r  r  checkedBatchOrdersr  
batchOrder
queryBatchdefaultRecvWindowextendedParamsr  ry  rb  orderidlistLengthorigclientorderidlistLength	signatures                                 rn  signzbinance.signv+  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  )hostnamerQ  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  reasonrJ  ri  rh  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  rm  i  zPrice * QTY is zero or lessr   z- order cost = amount * price is zero or less rE  z5 order amount should be evenly divisible by lot size rA  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   rz  r  r8   r0   r  r  r  )rl  r  r  r  rJ  ri  rh  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  rJ  ru  r  configr  rS  r  r  s
             rn  calculate_rate_limiter_costz#binance.calculate_rate_limiter_cost8,  s    6)9(##F"X-?*%%F"X-?*%%6!6(97OEY'G1c'l+ $
E!H$ 8O$ vvq11ro  c           	      x   K   | j                  |||||||       d {   }|dk(  rd| j                  d<   |S 7 w)Nr  Tr  )fetch2r  )	rl  ru  r  rJ  r  ri  rh  r  r  s	            rn  r  zbinance.requestH,  sE     T3vVV)BFDLL>?	 Ws   :8:c                 d  K   | j                  | j                  dd      }|dk(  rd}| j                  |d|      }|dk(  s|dk(  rt        | j                  dz         | j	                          d {    | j                  |      }| j                  ||      }||d   |d}d }	d }
|d	   r/|d
   }
| j                  | j                  ||             d {   }	n.|d   }
| j                  | j                  ||             d {   }	| j                  | j                  |	|      d|
i      S 7 7 Y7 ,w)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_helperO,  sL    &&t||]HM& "K<H$&.tww)kkll!!!V$))&&9Tl

 ('?D!??GU[@\]]H&>D!??GU[@\]]H {{499(FKDN
  	1 	" ^ ^s7   A-D0/D*0A"D0D,.D0D.)D0,D0.D0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reducer3  r  rg  r  r  )
r  r{  rp  r6  r  r  rq  r*  r  r  )r  r  r  r  rR  )	rl  r]  r  rawTyper  r  r  noErrorCoder  s	            rn  r  z!binance.parse_margin_modifications,  s    0 ##D&1$$T62	##D(3%%dF3	!!(FD&A4'u$X&%lE$&&tX6$$T73&+dH"Y/
 	
ro  c                 F   K   | j                  ||d|       d{   S 7 w)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  Nr  rl  r{  r  r  s       rn  reduce_marginzbinance.reduce_margin,  %      ..vvq&IIII   !!c                 F   K   | j                  ||d|       d{   S 7 w)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  Nr  r  s       rn  
add_marginzbinance.add_margin,  r  r  c                 
  K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  |d      }| j                  |      S 7 h7 )w)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>`
        Nrg  rN   r   )r  r5   sapiGetMarginInterestRateHistoryr  r  parse_borrow_rate)rl  r  r  r5  r  r  r  s          rn  fetch_cross_borrow_ratezbinance.fetch_cross_borrow_rate,  s      !!!==&Xd^
 >>t{{7TZ?[\\ ~~h*%%d++% 	" ]s"   BA?A BB(BBc                    K   d|i}| j                  | j                  ||             d{   }| j                  ||      S 7 w)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{  N)fetch_isolated_borrow_ratesr  r  )rl  r{  r  r  borrowRatess        rn  fetch_isolated_borrow_ratez"binance.fetch_isolated_borrow_rate,  sL      f
 !<<T[[RX=YZZ~~k622 [s   )AAAc                 8  K   | j                          d{    i }| j                  |d      }| j                  |d      }|| j                  |      }|d   |d<   | j	                  | j                  ||             d{   }| j                  |      S 7 7 w)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>`
        Nr{  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==dkk'SY>Z[[, //99; 	" \s"   BBA)B BBBc                   K   | j                          d{    |d}n|dkD  rt        | j                  dz         | j                  |      }|d   |d}|<||d<   | j	                  ||dz        dz
  }| j                         }t        ||      |d	<   | j                  | j                  ||             d{   }	| j                  |	|||      S 7 7 w)
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>`
        N]   z: fetchBorrowRateHistory() limit parameter cannot exceed 92rN   )rg  r  r   \&r  r  )
r  r5   rN   r5  r  r  r  r  r  parse_borrow_rate_history)
rl  r  r  r  r  r5  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>>t{{7TZ?[\\ --heUKK7 	"  ]s"   CCB!C8C9CCc                     | j                  |d      }| j                  |d      }| j                  ||      | j                  |d      d|| j	                  |      |dS )Nr  rg  dailyInterestRater  )r5  r  periodr  r  r  )r  r  r  r  rR  )rl  r  r5  r  r  s        rn  r  zbinance.parse_borrow_rateA-  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_rateU-  s    ( ##D(3!!(FD&A~~dF+>>$*NN4+	&&vx8$$Xv6((?C%%i8)))_E

 
	
ro  c                 B  K   | j                          d{    | j                  |      }|d   |d}| j                  | j                  ||             d{   }| j	                  |d      }| j                  |d      }| j                  |d      }	||	|||dS 7 7 Dw)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
        NrN   )tokenr  r]  r  referenceNo)r  rN   r  r5  r  )r  r5  sapiPostGiftcardCreateCoder  r  r  )
rl  r  r  r  r5  r  r  r]  giftcardCoderN   s
             rn  create_gift_codezbinance.create_gift_codez-  s      !!!==& d^
 88Wf9UVV ~~h/''f5dM2 
 	
' 	" Ws#   BBABBABBc                 l   K   d|i}| j                  | j                  ||             d{   }|S 7 w)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  N)sapiPostGiftcardRedeemCoder  )rl  r  r  r  r  s        rn  redeem_gift_codezbinance.redeem_gift_code-  sA      L
 88Wf9UVV  W   )424c                 l   K   d|i}| j                  | j                  ||             d{   }|S 7 w)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  N)sapiGetGiftcardVerifyr  )rl  rN   r  r  r  s        rn  verify_gift_codezbinance.verify_gift_code-  sA      2
 33DKK4PQQ  Rr  c                 V  K   | j                          d{    d}| j                  |dddd      \  }}i }d}|| j                  |      }	|	d   |d<   |||d<   |||d	<   | j                  d
||      \  }}d}
|r*| j	                  | j                  ||             d{   }
nD|| j                  |      }|d   |d<   | j                  | j                  ||             d{   }
| j                  |
d      }| j                  ||      }| j                  ||||      S 7 7 7 Aw)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   rg  r  r   r  r  r  )r  r  r5  r,  "papiGetMarginMarginInterestHistoryr  r  sapiGetMarginInterestHistoryr  parse_borrow_interestsfilter_by_currency_since_limit)rl  r  r{  r  r  r  r  r  r  r5  r  r  ra  s                rn  fetch_borrow_interestzbinance.fetch_borrow_interest-  sf     !!! $($C$CFLacik|  D  %E!6}}T*H'~GG#(GK #GFO229gvN!DDT[[QXZ`EabbH!V,,24L()!>>t{{7TZ?[\\HJ ~~h/..tV<228T5%PPw 	" c
 ]s5   D)D"B	D) D%!AD)%D'&=D)%D)'D)c                 *   | j                  |d      }| j                  |d      }|dnd}||| j                  | j                  |d            | j                  |d      | j                  |d      | j                  |d      ||| j	                  |      d		S )
Nr  interestAccuredTimer  r3  rg  ra  rG  	principal)	r  r{  r5  ra  rG  amountBorrowedr6  r  r  r  r  r  r  rR  )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                 H  K   | j                          d{    | j                  |      }|d   | j                  ||      d}d}d}| j                  |dddd      \  }}|rrd}| j                  |ddd	      \  }}|d
k(  r*| j	                  | j                  ||             d{   }n]| j                  | j                  ||             d{   }n3d|d<   d|d<   | j                  | j                  ||             d{   }| j                  ||      S 7 7 w7 O7 w)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>`
        NrN   r  r   r  re  FrepayCrossMarginMethodrJ  papiPostMarginRepayDebtFALSEr*  REPAYrp  )	r  r5  r  r  r  r  papiPostRepayLoansapiPostMarginBorrowRepayparse_margin_loan)	rl  r  r  r  r5  r  r  r  rJ  s	            rn  repay_cross_marginzbinance.repay_cross_margin/.  sM      !!!==&d^00v>
  $($C$CFL^`fhy  |A  %B!6F!<<VEWYqs{|NFF22!%!=!=dkk'SY>Z![[ "&!7!7GV8T!UU %,GL!%GFO!;;DKKQW<XYYH %%h99S 	" \ V ZsF   D"DBD"$D%)D"D3D"D D"D"D" D"c                 8  K   | j                          d{    | j                  |      }| j                  |      }|d   | j                  ||      |d   ddd}| j	                  | j                  ||             d{   }| j                  ||      S 7 7 w)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>`
        NrN   TRUEr  rg  r  r{  r*  rp  r  r5  r  r  r  r  r  	rl  r{  r  r  r  r5  r  r  r  s	            rn  repay_isolated_marginzbinance.repay_isolated_marginj.  s      !!!==&V$d^00v>Tl 
 77GV8TUU %%h99# 	" V"   BBA(B?B BBc                   K   | j                          d{    | j                  |      }|d   | j                  ||      d}d}d}| j                  |dddd      \  }}|r*| j	                  | j                  ||             d{   }n3d|d	<   d
|d<   | j                  | j                  ||             d{   }| j                  ||      S 7 7 L7 w)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>`
        NrN   r  r^   r  re  Fr  r*  BORROWrp  )r  r5  r  r  papiPostMarginLoanr  r  r  )rl  r  r  r  r5  r  r  r  s           rn  borrow_cross_marginzbinance.borrow_cross_margin.  s      !!!==&d^00v>
  $($C$CFL_agiz  }B  %C!6!44T[[&5QRRH$+GL!&GFO!;;DKKQW<XYYH %%h99+ 	" S Zs4   CCA/CC3C:C;CCCc                 8  K   | j                          d{    | j                  |      }| j                  |      }|d   | j                  ||      |d   ddd}| j	                  | j                  ||             d{   }| j                  ||      S 7 7 w)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>`
        NrN   r  r  r  r  r  s	            rn  borrow_isolated_marginzbinance.borrow_isolated_margin.  s      !!!==&V$d^00v>Tl 
 77GV8TUU %%h99# 	" Vr  c                     | j                  |d      }| j                  |d      }| j                  |d      | j                  ||      | j                  |d      d || j	                  |      |dS )Nrg  rs  r  r  )rN   r5  r  r{  r  r  r  r  )rl  r  r5  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           	        K   |dk(  rt        | j                  dz         | j                          d{    d}| j                  |ddd      \  }}|r| j	                  d|||||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                  ||             d{   }n)| j                  | j                  ||             d{   }| j                  ||||      S 7 7 S7 H7  w)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 timeframeNFr   r  rQ  r  r  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&@@A[]cejlqs|  E  GJ  K  K  KV$d&&t	9M
 $GG &x 0Hf	#D\	)&*&6&6v~O`&aGN##(GK !!&'2##FIu=6Iw#78!(GI}++I6H!%%E1AD1H!IGI)!==dkk'SY>Z[[H!==dkk'SY>Z[[H 0065%PPW 	" K2 \[sF   1GF=9G-G .DG:G;)G$G%G GGGc                   K   | j                          d{    | j                  |      }i }|d   r@|d   |d<   |d   t        | j                  dz   |z         | j	                  |d         |d<   n|d   |d	<   d}|d   r*| j                  | j                  ||             d{   }nX|d
   r*| j                  | j                  ||             d{   }n)| j                  | j                  ||             d{   }|d   rC|d	   }| j                  ||      }t        dt        |            D ]  }||   }|d	   |k(  s|c S  y| j                  ||      S 7 H7 7 7 ew)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:
        Nr\   r  underlyingAssetr  z$ fetchOpenInterest does not support 
expirationrN   r{  r  r   )r  r  r?   rN   rO  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(/  s     !!!V$()/)9G%&h'"477-S#SV\#\]]$(KKx0@$AGL! &tGH(!;;DKKQW<XYYHI!;;DKKQW<XYYH!;;DKKQW<XYYH> (H%F66xHF1c&k*  ay>V+K   ++Hf==o 	" ZYYsM   E'EBE'&E!'.E'E#)E'?E% AE'E'!E'#E'%E'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  )rN  r  rQ  safe_open_interestr~  rR  )rl  ra  r  r  rN   r  values          rn  r  zbinance.parse_open_interestn/  s    ''+vF	h1##H.?P""8-CEYZ &&&&r64D"("3$ "(!&"Y/	(
 	 		ro  c           	        K   | j                          d{    d}| j                  |dd      \  }}|r| j                  d||||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(  rW|	r+| j                  | j                  |
|             d{   }n| j                  | j                  |
|             d{   }n|dk(  rV|	r*| j                  | j                  |
|             d{   }n| j                  | j                  |
|             d{   }n||dk(  rV|	r*| j                  | j                  |
|             d{   }nK| j                  | j                  |
|             d{   }n!t        | j                   dz   |d   z   dz         | j#                  |d|      }| j%                  ||||      S 7 J7 7 57 7 7 7 7 _w)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>`
        NFr   r  currentrP  r  r  re  rX   LIQUIDATIONautoCloseTyper  r{  rN   r  r   r  r  r  z( fetchMyLiquidations() does not support rp  r;  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&>>?TV\^cejlrt}  @C  D  D  D[[(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> !%!>!>t{{7TZ?[!\\!%!F!Ft{{SZ\bGc!dd  !%!:!:4;;wPV;W!XX!%!?!?GU[@\!]]	! !%!:!:4;;wPV;W!XX!%!?!?GU[@\!]]tww)SSV\]cVddgqqrr\ ~~hA&&|VUEJJ{ 	" D8 ]d Y] Y]s   I4I 8I4I#C!I41I&2*I4I)0I4I,)I47I.80I4(I0))I4I2AI4#I4&I4)I4,I4.I40I42I4c                 `   | j                  |d      }| j                  |dd      }| j                  || j                  ||      | j	                  |d      | j	                  |d      | j	                  |d      | j	                  |d      | j	                  |d      || j                  |      d		      S )
Nr{  updatedTimers  r  r  r  r  r  )	r  r{  rr  r  r  	baseValue
quoteValuer  r  )r  rN  safe_liquidationr~  r  rR  )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                    K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  |d   |      S 7 Z7 w)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>`
        Nr{  rN   r   )r  r  eapiPublicGetMarkr  parse_greeksr8  s         rn  fetch_greekszbinance.fetch_greeksg0  s}      !!!V$fTl
 //GV0LMM$   !f55/ 	"
 Ns"   A5A1A A5A3A53A5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                    K   | j                          d {   }i }t        dt        |            D ],  }||   }|d   }|| j                  ||      s"|d   d   ||<   . |S 7 Lw)Nr   r{  r  r  )r  r  r  r  )rl  r
  r  r  tradingLimitsr  r  r{  s           rn  fetch_trading_limitszbinance.fetch_trading_limits0  s~     **,, q#g,' 	CAQZFH%FT]]67%C(.x(8(Bf%		C
  -s   A%A#<A%A%c                 J  K   d}|| j                  |      }d}| j                  d||      \  }}d}|dk(  r| j                  |       d{   }n7|dk(  r| j                  |       d{   }nt	        | j
                  dz         | j                  |d      }||dS 7 S7 6w)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!@@HHH	!!@@HHHTWW'rrss  >>(4FG&
 	
 IHs$   A	B#BB#*B!+5B#!B#c                   K   | j                          d{    d}|%| j                  |      }| j                  |d         }d}| j                  d||      \  }}d}|dk(  r| j	                  |       d{   }n7|dk(  r| j                  |       d{   }nt        | j                  dz         | j                  |dg       }t        |t              r|}| j                  ||dd	      S 7 7 w7 Zw)
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 onlyrW  r{  rZ   )r  r  r  r  r  r  r5   rN   r  r  r  parse_margin_modes)rl  r
  r  r  rq  r  rv  s          rn  fetch_margin_modeszbinance.fetch_margin_modes0  s     !!!))'2G[[,F99:KVU[\h!<<VDDH 	!!77??Hd TWW'ffgg+r:h%F&&vw&IIY 	" E @s5   C3C-A C37C/8C3C1AC3/C31C3c                   K   | j                          d{    | j                  |      }d}| j                  d||      \  }}d}|dk(  r1d|d   i}| j                  | j	                  ||             d{   }n=|dk(  r | j                  |g|       d{   }||   S t        | j                  dz         | j                  |d   |      S 7 7 Y7 :w)	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  rB  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 "<<T[[RX=YZZH 	!-1-D-DfXv-V'V$+F33TWW'eeff%%hqk6::5 	" [ (Ws4   CCAC6C7 CC7CCCc                     | j                  |d      }| j                  ||      }| j                  |d      }d }||rdnd}| j                  |d      }|	|dk(  rdnd}||d   |dS )Nr{  r3  r  r  r  )r  r{  r6  )r  r  r  rM  )rl  r6  r  r  r
  reMarginModer  s          rn  rD  zbinance.parse_margin_modec1  s    ##J9!!(F3z:>$)6:GL..z<H$'4	'A7
LX&&
 	
ro  c                   K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  |di       }| j                  |d|      S 7 k7 ,w)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>`
        Nr{  rN   r   )r  r  r  r  r  parse_option)rl  r{  r  r  r  r  chains          rn  fetch_optionzbinance.fetch_options1  s      !!!V$fTl
 11$++gv2NOO2 xB/  f55? 	"
 Ps"   BBA BB+BBrK  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  r5  r  r  impliedVolatilityrd  r  r  midPricer  r  r8  r  r  r  r  r  r  r  r  )r  r  r  )rl  rK  r5  r  r  s        rn  rJ  zbinance.parse_option1  s[   . ##E84!!(F3
E

 fX&
 	

 
  
 D
 ((
;
 ((
;
 
 
 ))%=
 t//G
 d&&um<
 $**52FG
  $**5(;!
" 4#
 	
ro  c                   K   | j                          d{    |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                  ||             d{   }	nM|d   r*| j                  | j                  ||             d{   }	nt        | j                  dz   |d	   z         | j                  |	      }
| j                  |
|||      S 7 !7 z7 Mw)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  ss     !!!>#DGG.j$jkkV$!!&'267+fTl
 $(EMaGFO#(GK $GG!&GI(!EEdkkRY[aFbccHI!EEdkkRY[aFbccHTWW'nnqwx~q  A  A  77A00uUUQ 	"& dcs5   D>D7B(D>?D: .D>.D</A	D>:D><D>c                   K   | j                          d{    | j                  |       d{   }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 7 7 w)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
        Nr   rg  fractionr  )r  r   r  )r  rN   r  r'  rp  rO   r  r  r   r  r  r  r@  )r  sapiGetConvertAssetInfor  r  r  r  rj  rS  )rl  r  r  r  r  r  rN   r  s           rn  fetch_convert_currenciesz binance.fetch_convert_currencies2  s     !!!55f== q#h-( 	AQKE!!%1B**2.D  !..t/C/CDDTDTUZ\fDg/hi  $#
  $#!
  $#   5F4L		@ W 	"=s    CCCC
BC
CfromCodetoCodec                 >  K   |t        | j                  dz         | j                          d{    |||d}| j                  | j	                  ||             d{   }| j                  |      }| j                  |      }| j                  |||      S 7 h7 ;w)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>`
        Nz0 fetchConvertQuote() requires an amount argument)r  toAsset
fromAmount)r4   rN   r  sapiPostConvertGetQuoter  r5  parse_conversion)	rl  rZ  r[  r  r  r  r  fromCurrency
toCurrencys	            rn  fetch_convert_quotezbinance.fetch_convert_quote:2  s      >#DGG.`$`aa!!!! 

 55dkk'66RSS }}X.]]6*
$$X|ZHH' 	" Ts!   .BB.BB :BBc                   K   | j                          d{    i }d}|dk(  s|dk(  rX|t        | j                  dz         ||d<   ||d<   ||d<   ||d<   | j                  | j	                  ||             d{   }n.||d<   | j                  | j	                  ||             d{   }| j                  |      }| j                  |      }	| j                  |||	      S 7 7 j7 =w)	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clientTranIdrg  targetAssetr  r  )r  r4   rN   sapiPostAssetConvertTransferr  sapiPostConvertAcceptQuoter5  r`  )
rl  rN   rZ  r[  r  r  r  r  ra  rb  s
             rn  create_convert_tradezbinance.create_convert_trade^2  s     !!!Ff$4~'2e(eff&(GN#'GG%+GM" &GH!>>t{{7TZ?[\\H "$GI!<<T[[RX=YZZH }}X.]]6*
$$X|ZHH; 	" ] [s4   C*C$A$C*;C&<.C**C(+:C*&C*(C*c                   K   | j                          d{    i }d}|dk(  rid}| j                         }|| j                  |      }|d   |d<   ||d<   ||z
  |d<   ||d<   | j                  | j	                  ||             d{   }n.||d	<   | j                  | j	                  ||             d{   }|}	|dk(  r&| j                  |d
g       }
| j                  |
di       }	| j                  |	dd      }| j                  |	dd      }d}d}|| j                  |      }|| j                  |      }| j                  |	||      S 7 57 7 w)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   rg  r  r  r  r<  r  r   deductedAssetr  rf  r]  )
r  r  r5  &sapiGetAssetConvertTransferQueryByPager  sapiGetConvertOrderStatusr  r  r  r`  )rl  rN   r  r  r  r  msInDayr!  r5  r]  r  fromCurrencyIdtoCurrencyIdra  rb  s                  rn  fetch_convert_tradezbinance.fetch_convert_trade2  s     !!!6>G##%C==.#+D>  "GH#&=GK !$GI!HHU\^dIeffH( "$GI!;;DKKQW<XYYH 6>>>(FB7D>>$2.D++D/;O))$yI
%==8L#|4J$$T<DDw 	" g* Zs5   EEA0EE.E6E7BEEEc                   K   | j                          d{    i }d}| j                         }|||d<   n||z
  |d<   | j                  |dd      }|||d<   n||d<   | j                  |d      }d}	d}
d}d}|dk(  rP| j	                  |      }|d   |d<   |||d	<   d
}d}d}
| j                  | j                  ||             d{   }	n\|d   |d   z
  |kD  rt        | j                  dz         |||d<   d}d}d}
| j                  | j                  ||             d{   }	| j                  |	|
g       }| j                  ||||||      S 7 =7 7 2w)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>`
        Nl    H4 r  r  r  r#  rN   rg  r   rk  rf  r  zV fetchConvertTradeHistory() the max interval between startTime and endTime is 30 days.r  r  r]  r  )r  r  rN  r  r5  rl  r  r5   rN   sapiGetConvertTradeFlowr  parse_conversions)rl  r  r  r  r  r  msInThirtyDaysr!  r  r  responseQueryfromCurrencyKeytoCurrencyKeyr5  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!HHU\^dIeffH( 	"W[%99^K   ,D  "D  E  E #( )O%M"M!99$++gv:VWWH. ~~hr:%%dD/=RWY^__[ 	"4 g6 Xs5   EEB1EE	AE%E&.EEE
conversionra  rb  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  rk  r  rf  r]  )r  r<  r  deductedAmountr^  targetAmounttoAmount)
r  r  r  rN   ra  r^  rb  r  r  r  )r  r  r  rR  rD  rQ  )	rl  rz  ra  rb  r  fromCurrZ  tor[  s	            rn  r`  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                   K   | j                          d{    d}|%| j                  |      }| j                  |d         }d}d}| j                  d||d      \  }}d}| j	                  ||      r| j                  |       d{   }nD| j                  ||      r| j                  |       d{   }nt        | j                  dz         | j                  ||      S 7 7 ]7 3w)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   rD  r  s          rn  fetch_funding_intervalszbinance.fetch_funding_intervals3  s      !!!))'2G[[,F99:QSY[ackl>>$(!::6BBH__T7+!::6BBHtww)sstt '''::5 	" CBs4   C)C#A0C)C%+C)3C'40C)%C)'C)r  c                 *  K   | j                          d{    | j                  |      }|d}d|i}| j                  d||      \  }}|||d<   |||d<   d}| j                  d||      \  }}d}	|dk(  r2|d	   |d
<   | j	                  | j                  ||             d{   }	nR|dk(  r5|d   d   |d<   | j                  | j                  ||             d{   }	nt        | j                  dz         | j                  |	|      S 7 7 k7 3w)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  sN     !!!V$Ii
 229gvN#(GK $GG99:VX^`fgh &tGH!HHU\^dIeffH 	!$VnV4GFO!HHU\^dIeffH TWW'ppqq228VDD[ 	"" g gs4   DDBD#D$9DD0DDD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~  rR  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  re  r   r  r  r   r  r%   r  r  r  r$   r  r  r  r&   r  r  r  r  r  r#  r)   rG  rU  r!   r    floatr   r^  rY  r  r  r  r   r  r  r   r[  r  r  r  r  r  r  r&  r7  rD  rM  rT  rX  r^  rj  rv  r|  r  r~  r  rA  r,   r  r  r  r   r  r  r.   r  r  r   r  r   r  r
  r  r  r  r   r*   r#  r,  r+   r2  r5  r'   r9  r?  rB  r(   rE  r7  ra  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$  r6  r  rR  r~  r  rv  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   rB  r   rF  rD  r   rL  rJ  rU  rY  r   rc  ri  rq  ry  r`  r  r   r  r  __classcell__)rm  s   @rn  rK   rK   )   s   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V Zxg4 gF gRdAem dAL *, @X @XD @DB ES E ES\ EN_4 _ _6 _B )+ 
2 68 %3 %3F %3N 8<B  5W  5D :>b :9w :9x&
f &
P 6:" $57 $5 $5L :< 3S 3 3@ :>b 5w 5W 58=
 =
4 =
~ 8<$]ajl v vC vWZ vquvzq{ vp~ ~v ~ ~@ <@d[] IA IAS IA IAbfglbm IAV y}  FH ?. ?.S ?.	 ?.QZ ?.di ?.ru ?.B {  HJ g,# g,s g,) g,S\ g,fk g,tw g,R C  LN c 3 i W` jo x{ $ }A  JL A2C A2 A2I A2U^ A2hm A2vy A2F fjx|  FH a3 a a9 aI a_b aru a4 DF M+\(: M+^: :k kv k kZ FH K+$|*< K+Z mqy{ `2 `2I `2Y `2X] `2fi `2D os{} @33 @3i @3y @3Z_ @3hk @3D eg e# eY eV[ e* XZ fc f f( Y[ Us U% U$ 8<B ?2C ?2 ?2B 04$UYbd AA AAC AAs AAimnsit AAF 59tZ^gi QAc QA QATW QAnrsxny QAf =A J2 J2c J2X 7;\`ik H H3 HVY Hptuzp{ H: 9=4^bkm H# HS HX[ H: DHVZimvx FS FPS Fcf F  ~B  CH  ~I F@ 9=R O2S O2# O2b 59 \c \| AER B3tCy B3# B3H ?CQUdhqs ^3 ^ ^3 ^^a ^: 37TX\eg SAC SAs SARU SAj 8<$]ajl C@ C@C C@WZ C@JA
f A
F 04$UYbd dI dIC dIs dIimnyiz dIL 37TX\eg yIC yIs yIRU yIlpq|l} yIv$:Lx
T x
X x
Q\ x
t:C :C :c
t c
x c
= c
J
6 
4 ac U73 U7 U7C U7TW U7gt U7n 154VZce DB# DBS DBPS DBjno|j} DBL =? &> &>> &>P
 
N 
8 =A o
' o
b BFb 6Iw 6Ip@ @D JNVX ":3 ": ": ":]h ":H
T 
6 
EX 
: ;= ?4c ?4AT ?4B /1 g[ gR FH 73 7> <> %9s %9+ %9N >BPTcgpr 7Qs 7Q# 7Q]` 7Qr
6 
" <@ ; ;| ;8:
6 :
[ :
xBj
v j
X\
F \
| 38 '0R =A IF' IFP] IFV& &$|J\ &P 8: )83 )8V ?C2 4PG 4Pl6t 6V 6p 8<B  HW  H4PX>  HD @DB wPW wPr =A eP' ePN 9=4^bkm 5B# 5BS 5BX[ 5Bn ?C2 *3 * *X DHPR 6 6S 6p CGr 2d 2C 2h 8<B 'BW 'B9 'BR
t 
V 
x 
8 <@daenp (OS (O (O[^ (OT ?CQUdhqs 0Y 0Y3 0Y^a 0Yd'
R&P =A #83 #8c #8P[ #8J .2SW`b XCs XC# XCS XCgklwgx 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  '/uRQU\`ik  SU " "H*
d *
F *
N` *
X FH J# Ju JL^ J CE Js JE JI[ J ?A ,# ,_ ,< DF 3s 3J\ 3& 8: *:>Q *:X GKY]fh 'LC 'L 'LSV 'LR
 
(#
t #
V #
Oa #
J @B $
3 $
L ;= 6 68  0 7;$]apt} JQ JQC JQWZ JQjm JQ  EI  JX  EY JQX
$ 
 
. 
  BD 9:S 9:v RT :# :S :> JL ":c ":5 ":H Z\ :3 :c :5 :>
 
: HLZ^mqz| =Q =QTW =Qgj =Q~ =? D DLF $ 9=4^bkm RK# RKS RKX[ RKhQV Qf 68 !6 !6F !6F&
4 &
 &
6 &
P =A 	' 	 7;2 !
 !
F ;?r YJ YJk YJv ;= &;c &; &;P
D 
* 
  68 )6 )6F )6V+
$ +
( +
6 +
]c +
Z CGTXgkz~  HJ 7VC 7Vc 7Vad 7Vtw 7V  OS  Tf  Og 7Vr 57 4: 4l SW_a "I# "Is "IC "Ifp "IH ]aik *IS *IC *I *IVY *Ipz *IX >B" FEC FEs FEQ[ FEP =Atbfoq Z`c Z` Z`\_ Z`vz  |F  wG Z`xW
4 W
x W
\d W
pz W
r @DB &;W &;S_ &;P BFX\ko  C  LN <E3 <ERU <Eeh <Ex{ <E  SW  Xf  Sg <E|
4 
 
> 
ro  rK   )R ccxt.async_support.base.exchanger   ccxt.abstract.binancer   r  rt  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    6 -    T  T  T  T  T  T  T  T  T  T  T  * 0 - - . ' & . 1 ) . ) * 5 - ) , + . * ) + ( 3 4 %cO
h cO
ro  