
    eiv
                    D   d dl mZ d dlmZ d dlZd dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/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          ZQdS )"    )Exchange)ImplicitAPIN)+AnyADL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d Zdef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*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dee.         f
d/Z0dd0edede1fd1Z2ddi fd
ed.ededee1         fd2Z3di fd3ed
ede4d4e5d5e6d6e7fd7Z8di fd3ed
ede4d4e5d5e6d6e7fd8Z9di fd3ed
ede4d4e5d5e6d6e7fd9Z:di fd3ed
ede4d4e5d5e6d6e7fd:Z;ddi fd3ed
ede4d4e5d5e7d6e7fd;Z<i fd<ee=         fd=Z>d>efd?Z?defd@Z@ddAededeAfdBZBi fd<ee=         fdCZCdi fd
ede4d4e5d5e6d6e7f
dDZDdi fd
ede4d4e5d5e6d6e7f
dEZEi fd
ed4e5dFe6fdGZFi fd
edFe6fdHZGi fd
edFe6fdIZHdi fd3ed
efdJZIdddi fd
ed.ededeeA         fdKZJdddi fd
ed.ededeeA         fdLZKdi fd3ed
efdMZLdddi fd
ed.ededeeA         fdNZMdddi fd
ed.edefdOZNdddi fd
ed.ededeeA         fdPZOdi fd3ed
efdQZPdi fd
efdRZQdi fdSee         d
efdTZRdddi fd3ed
ed.edefdUZSdddi fd
ed.edefdVZTdddi fd
ed.edefdWZUddefdXZVdddi fdYed.ededeeW         fdZZXdddi fdYed.ededeeW         fd[ZYdd\ZZdd]ed^e[deWfd_Z\d>edefd`Z]ddaed^e[de^fdbZ_ddefdcZ`i fdYed5e6ddedeede^f
dfZadddi fdYed.ededee^         fdgZbi fdYedecfdhZddd^e[decfdiZedi fdje%fdkZfdi fdje%fdlZgdd^e[fdmZhdi fdYed5e6dnedoedeWf
dpZiddqededejfdrZki fd
edejfdsZli fdemfdtZni fdYefduZoi fd
edepfdvZqdddi fd
ed.edefdwZrddefdxZsdi fd#e%detfdyZuddedepfdzZvdd{Zwddefd|Zxddefd}Zydi fd~Zzdi fd#e%de{fdZ|ddedee}         fdZ~i fd
efdZdi fd#e%fdZddedefdZd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ded
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d3edYedefdZdddi fdYed.ededee         fdZdded^e[defdZd ZddededefdZdedefdZddi ddfdZdedefdZdYede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d5e6defdZi fd
ed5e6defdZi fdYedefdZi fd
edefdZi fdefdZddi fdYed.edefdZdd^e[fdZddededefdZi fdYefdZi fdZi fd3efdZddddi fdYed
ed.ededee         f
dZddededefdZi fdYefdZi fd
edYefdZi fdYed5e6fdZi fd
edYed5e6fdZdd^e[f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ǄZdi fd#e%dee         f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^e[dedefd҄Zddddi fd
eded.e7de7dee         f
dӄZi fdefdԄZdi fdeded5e7defdׄZdi fd3ededed5e7def
d؄Zdi fd3edYedefdلZdddi fdYed.ededee         fdڄZddede[de[defdބZdi fd#e%detfd߄Zddddi fd
ed-ed.ededee         f
dZddededefdZi fd
edefdZdi fd#e%dee         fdZddededefdZڈ xZS )binancereturnc                 Vu   |                      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	d8dd9d	d:d;d<d;d=dd>d;d?d	d@d	i dAd	dBd	dCd	dDddEd	dFddGd	dHddIddJd	dKddLd;dMd	dNd	dOd;dPd	dQd	i dRd	dSd	dTd	dUd	dVd;dWd	dXddYd	dZd	d[d	d\d;d]d	d^d	d_dd`ddad	dbd	i dcd	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	dd	dd	dd	dd	dd;dd;dd	dddddd	dddddddddd	ddd	d	d	d	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dddddddddddddi ddddddddddddddœddœddȓddʓdd̓ddΓddГdd̓ddΓddГddՓddddddڜ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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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/d0d/d1d2d3d,d4d,d5d,d6d,d7d,d8d,i d9d:d;d<d=d,d>d,d?d,d@d,dAd,dBd:dCdDdEdݓdFddGdݓdHdIdJddKddLddMdݓi dNdݓdOdݓdPddQddRddSd dTddUddVd#dWd dXdݓdYdݓdZdݓd[dݓd\dd]dݓd^di d_dݓd`dݓdaddbddcdݓddddedݓdfdݓdgdݓdhddidjdkd dldݓdmddndݓdodjdpdji dqdݓdrdjdsdtdudjdvdݓdwdݓdxdݓdydݓdzdݓ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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dݐdޓi dߐdޓddݓddݓddݓddݓddݓddݓddݓddݓddݓddݓddݓddݓddݓddݓddݓddݓ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ݓddddddݐdi ddddݓddddݓddddݓd	dݓd
ddRd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ݓdgdݓddݓddݓddݓi ddݓddݓddݓdFdݓddݓddݓd dݓd!d"d#d"dd"d$dd%dݓd&dݓddddddddi ddd'dd(dddd)dd*dddddddddddd+dd,dd-dddd.dddi d/dd0dd1dݓd2dݓd3dݓd4d d5d d6d d7dݓd8dݓd9dݓd:dd;dd<dd=dd>dd?di d@ddAd dBd2dCd2dDd2dEd2dFd2dGd2dHd2dId2dJd2dKdLdMdԓdNdԓdOdLdPdޓdQdi dRdޓdאdޓdSdޓdTd	dUd	dVdޓdߐdޓdWdݓdXdݓdYdݓdZdݓd[dݓd\dݓd]dݓd^dݓd_dݓd`ddddddݐdaddݐdbdݐdtdtdddddddݐd dcdddddddݐd<d,d,d,d,d,ddedd d2d2d2dfdgddhdjidididgddjdhdjiiddji dkddlddmddndddgdodgdpdgdqd	ggdrdsddtd	dud	dvddwddxddydgdzdgdqdgd{dggdrd|ddydgdzdgdqdgd{dggdrd}ddydgdzdgdqdgd{dggdrd~ddydgdzdgdqdgd{dggdrdddydgdzdgdqdgd{dggdrddd,dddddddddddddidɐdjddddddddidi dd<dddddddddddd	d,ddddddddd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dddddddddddddddddddddǐdjddiidːdji dkddlddmddndddgdodgdpdgdqd	ggdrdd	dsddtd	dud	dxddydgdzdgdqdgd{dggdrd|ddydgdzdgdqdgd{dggdrd~ddydgdzdgdqdgd{dggdrd}ddydgdzdgdqdgd{dggdrdddydgdzdgdqdgd{dggdrdwddddvdddd,ddddddddddddddddddddddidԐdjddddddddidi dd	ddddddddd,ddddddddddddddd<dddd<dd	dddddd<i ddddddddddddddddddddddddqddddqddddqddddddddd,ddddi dddddddddddddddddddddddddddKddMd	dddddddddddddddd͐djddiidҐdjddddidϐdji idӐdjddddidĐdjdddddddddd	dؐdؐdidi ddؓddddd,d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iddddddddddȜ	dddɜdddddddʜdddːdddodgdpdgdqdgddggdrdddd͐d͐d͐dΐdd͐dΐddϐd͐dϐdd͐dϐddd͐dМddiddiddi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 dkd˓ddddddd,ddېdddddddd,ddߐd	ddddd,dddddd,dddddd,ddddd,i ddddddoddddo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ddd	dddddddddddddddd˓dddddddddddd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ddi ddddddddddddoddodddd˓dd˓dd˓dd˓ddޓddޓddޓddޓdd˓ddddddddddddddddddddːddddjddiidddjdd	|                     d          |                     d          ddd d	d	|                     d!          |                     d"          |                     d#          |                     d$          g|                     d%          |                     d$          g|                     d&          |                     d'          g|                     d(          |                     d)          g|                     d*          |                     d+          g|                     d,          |                     d-          g|                     d.          |                     d/          g|                     d0          |                     d1          g|                     d2          |                     d"          g|                     d3          |                     d4          gg
|                     d#          |                     d"          g|                     d%          |                     d5          g|                     d&          |                     d6          g|                     d(          |                     d7          g|                     d*          |                     d8          g|                     d,          |                     d9          g|                     d.          |                     d:          g|                     d0          |                     d;          g|                     d2          |                     d<          g|                     d3          |                     d#          gg
d=d>idd?d	d	|                     d!          |                     d8          |                     d#          |                     d!          g|                     d%          |                     d@          g|                     d&          |                     d$          g|                     d(          |                     d+          g|                     d*          |                     d/          g|                     d,          |                     dA          g|                     d.          |                     dA          g|                     d0          |                     dA          g|                     d2          |                     dA          g|                     d3          |                     dA          gg
|                     d#          |                     d8          g|                     d%          |                     d9          g|                     d&          |                     dB          g|                     d(          |                     dC          g|                     d*          |                     d#          g|                     d,          |                     dD          g|                     d.          |                     dE          g|                     d0          |                     dF          g|                     d2          |                     dG          g|                     d3          |                     dH          gg
d=d>ii dIdJdK|                     dKdK|                     d          dL          idMdNdOdPdQt          dRi dSddTd	dfdUg dVidWddEd	dXdYdZdd[d d\dd]d	d^t          d_dd}dd`d{daddbddcddddded	dfdfdgdhdgdhdhdidjdjdkdldldmdndmdmdndodpddqddrdsddti dudvdvdvdwdxdxdxdydz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ddddddddddwd|duddddudvidwdxidi dd	dd	dd	dd	dd	dd	dd	dd	dd	dd	dd	dd	dd	dd	dd	dd	dd	d	d	d	d	d	d	d	d	d	d	d	d	d	d	d	dddidd
dd	dd	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dqd dd	dd	ddd	dd	d ddddd	dqd d{ddd	dd	dqd d d{ddd	ddÐdqi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 dqdd	dɜdddd	dd	dpddddd	dqdʐdddd	dd	dq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          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          d't          i d(t          d)t          d*t          d+t"          d,t"          d-t          d.t          d/t"          d0t          d1t          d2t          d3t          d4t"          d5t          d6t          d7t          d8t$          i d9t$          d:t$          d;t$          d<t$          d=t$          d>t$          d?t$          d@t$          dAt$          dBt$          dCt$          dDt          dEt$          dFt$          dGt$          dHt$          dIt$          i dJt$          dKt$          dLt$          dMt$          dNt$          dOt$          dPt$          dQt$          dRt$          dSt$          dTt$          dUt$          dVt$          dWt$          dXt$          dYt$          dZt$          i d[t$          d\t$          d]t$          d^t$          d_t$          d`t$          dat$          dbt$          dct$          ddt$          det$          dft$          dgt$          dht$          dit$          djt$          dkt$          i dlt$          dmt$          dnt$          dot$          dpt$          dqt$          drt$          dst$          dtt$          dut$          dvt$          dwt$          dxt$          dyt$          dzt$          d{t$          d|t$          i d}t$          d~t$          dt$          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          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"          d t           dt           dt          i dt(          dt          dt          dt           dt          dt          dt          dt          dGt          dHt          dIt          dJt          dMt          dNt          dOt          dPt          dQt          i dRt          dSt          dTt          dUt          dVt          dWt          dXt"          dYt          d]t          d_t"          d`t"          dwt          dxt          dyt          dzt          d{t          dt          i dt          dt          dt          d	t          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"          i dt"          dt"          dt          dt          dt          dt          dt"          dt"          dt"          dt"          dt*          dt*          d t          d!t          d"t          d#t          d$t          t          t          t          t          t          d%idi dt"          dt"          dt          dt          dt          dt          d&t          dt          dt          d t           dt           dt          dt(          dt          dt          dt          dt          i dt          dt          dt          d^t          d_t          d`t          dat"          d't"          dtt          d(t          dut          dvt          dt          d)t          d*t          d+t          d,t          t          t          t"          t"          t"          t          t          t          t          t"          t"          t          d-idi d.t$          dt$          d/t$          d0t$          dt&          d1t$          d2t$          dt$          d3t$          d4t$          d&t          d5t          dt          d6t$          d t           dt           dt          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$          d0t$          d1t$          d2t$          i d3t$          d4t$          d5t$          d6t$          d7t$          d8t$          d9t$          d:t$          d;t$          d<t$          d=t$          d>t$          d@t$          dAt$          dBt$          dCt$          dDt$          i dEt$          dFt$          dGt$          dHt$          dIt$          dJt$          dKt$          dLt$          dMt$          dNt$          dOt$          dPt$          dQt$          dRt$          dSt$          dTt$          dUt$          i dVt$          dWt$          dXt$          dYt$          dZt$          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$          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$          d7
idi d8t          d9t$          d:t"          d.t&          dt          dt"          d/t          d0t          dt          d1t$          dt"          d2t$          d;t          d<t          d=t,          d>t,          d?t          i d@t          dt          dt          dAt          dBt          dCt          dDt          dEt          dFt          dGt          dt          dt          dt          dHt          d3t          dt          d4t          i dIt          dJt          dKt          dLt          dMt          dNt          dOt          dPt          dQt          d&t          dRt          dt          dt          dt          dt          dt          dSt          i d6t          dTt.          dUt          dVt          dt          d t          dt          dt*          dt(          dt          dt          dt          dt          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          d4t          i d5t          d6t          d7t          d8t          d9t          d:t          d;t          d<t          d=t          d>t          d?t          d@t"          dAt"          dBt          dCt          dDt          dEt          i dFt          dGt          dHt          dIt          dJt          dKt          dLt          dMt          dNt          dOt          dPt          dQt          dRt          dSt          dTt          dUt          dVt          i dWt          dXt"          dYt          dZt          d[t          d\t,          d]t          d^t          d_t"          d`t"          dnt          dwt          dxt          d{t          dt          dt          dt          i dt          dt          dt(          dt          dt(          dt          dWt          d	t          d
t          dt          dt          dXt          dt*          dt*          d$t          dYt&          ii d8t          d9t          d:t          d.t&          dt          d/t          d0t0          d1t          d2t          d;t          d<t&          d=t          d>t          d?t2          d@t          dAt          dBt          i dCt          dDt          dEt          dFt          dGt          dt          dHt          d3t          d4t          dIt          dJt          dKt          dLt          dMt          dNt          dOt          dPt          i dQt          d&t          dRt          dSt          d6t.          dTt.          dUt          dVt          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          d4t          d5t          d6t          d7t          d8t          d9t          d:t           d;t           d<t          i d=t          d>t          d?t          d@t          dAt          dBt          dCt          dDt          dEt          dFt          dKt          dLt          dZt          d[t          d\t          d^t          dnt          i dt          dt          dt          dt          dt(          dZt          d[t          d\t          d]t          d^t          d_t          d`t          dat          dbt          dct4          ddt          det"          i dft          dgt(          dht(          dit(          djt           dkt"          dlt"          dmt"          dnt6          dot&          dpt          dqt          drt          dst          dtt"          dut"          t"          t          t          dvdwdxdyi          S (z  NidrL   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fetchADLRankfetchAllGreeks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fetchPositionADLRankfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsADLRank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v1z%https://demo-dapi.binance.com/dapi/v1z%https://demo-dapi.binance.com/dapi/v2z%https://demo-fapi.binance.com/fapi/v1z%https://demo-fapi.binance.com/fapi/v2z%https://demo-fapi.binance.com/fapi/v3z#https://demo-api.binance.com/api/v3z#https://demo-api.binance.com/api/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/v1z https://papi.binance.com/papi/v2)r  r  r	  papipapiV2zhttps://www.binance.comz1https://accounts.binance.com/register?ref=CCXTCOMg?)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demo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/ifNewUserzapiReferral/customizationz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portfolio/earn-asset-balance   zportfolio/delta-modez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/collateralRecord)zdci/product/listzdci/product/positionszdci/product/accountszaccumulator/product/listz!accumulator/product/position/listzaccumulator/product/sum-holding
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/isolateduserListenTokenz 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/repayzconvert/getQuotegK=U?zconvert/acceptQuotezconvert/limit/placeOrderzconvert/limit/cancelOrderzportfolio/auto-collectionzportfolio/asset-collectionzportfolio/bnb-transferz(portfolio/repay-futures-negative-balancezportfolio/mintzportfolio/redeemzportfolio/earn-asset-transferz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/setAutoSubscribe)z#simple-earn/locked/setAutoSubscribez"simple-earn/locked/setRedeemOptionzdci/product/subscribezdci/product/auto_compound/editzaccumulator/product/subscribe)rD  rE  )r'  r&  r+  r*  rD  rE  r>  rH  zalgo/spot/orderzalgo/futures/orderz.sub-account/subAccountApi/ipRestriction/ipList)getpostputdelete)r<  r7  r8  r9  r/  r1  r2  r3  zloan/flexible/loanable/datazloan/flexible/collateral/datar?  )rI  r:  zloan/flexible/borrowrJ  rK  )rL  rM  zsub-account/assetszasset/getUserAssetrL  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   )rq  rs  batchOrderscountdownCancelAllleverage
marginTypepositionMargin	listenKey)r  rs  r  )rs  allOpenOrdersr  r  rpiDepthri  )re  rf  rh  	indexInfo
assetIndexrg  apiTradingStatus	lvtKlinesr4  insuranceBalancesymbolAdlRisktradingSchedule)rj  rk  rl  rm  rn  takerlongshortRatiorp  rateLimit/orderr  multiAssetsMarginzapiReferral/traderNumzapiReferral/overviewzapiReferral/tradeVolzapiReferral/rebateVolzapiReferral/traderSummaryr  r  r  r  r  r  )feeBurnsymbolConfigaccountConfigr5  	algoOrderopenAlgoOrdersallAlgoOrderszstock/contractr  r  r  
order/testr  r  r  r     r  )r  rs  r  r  r  algoOpenOrdersr   )rx  rw  ry  )rP  rQ  rR  indextickermarkrS  r]  rX  rY  exerciseHistoryrh  positionhistoryOrdersexerciseRecordbillmarginAccountmmpzblock/order/ordersblock/order/executezblock/user-tradesblockTrades	comission)	rs  r  r  mmpSetmmpResetr  countdownCancelAllHeartBeatblock/order/creater  )r  r  )rs  r  r  allOpenOrdersByUnderlyingr  r  g?i  g?   g?)rP  rQ  rS  rX  rZ  rY  r]  uiKlinesrc  r  zticker/tradingDayre  rf  rR  avgPrice)rL  rN  rM  rO  g333333?   )allOrderListopenOrderList	orderListrs  ru  rv  rx  myTradesr  myPreventedMatchesmyAllocationszaccount/commission)z	order/ocozorderList/ocozorderList/otozorderList/otocozorderList/opozorderList/opoco	sor/orderzsor/order/testrs  zorder/cancelReplacer  )ru  r  rs  )rL  rM  rO  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-balancei  )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  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)rO   code	precisioncommonCurrenciesBCCYOYOW)r  YOYOprecisionModeoptionssandboxModefetchMarginstypesrY   r  r  loadAllOptionsdefaultTimeInForceGTCdefaultTypedefaultSubType#hasAlreadyAuthenticatedSuccessfully"warnOnFetchOpenOrdersWithoutSymbolcurrencyToPrecisionRoundingModethrowMarginModeAlreadySet
recvWindowtimeDifferenceadjustForTimeDifferencenewOrderRespTypeFULL)marketlimit
x-TKT5PX2Fz
x-cvBPrNm9
x-xcKtGhcu)rY   rZ   r\   deliveryr[   r]   r  MAINFUNDINGMARGINUMFUTURECMFUTUREOPTION)mainrY   fundingrZ   crossr\   r  r  r[   r  r]   r  r  r  )r  r  r  r   r  r  ERC20ETHTRC20TRXBEP2BNBBSCBEP20EOSSPLSOLARBONEARBITRUMAVAXCMATICBASESUIOPOPTIMISMNEARAPTSCROLLKAVAXLMRSKSEITONADAALGORUNEOSMOCELOHBAR	ZKSYNCERAKLAYACASTXXTZMETISEGLDASTRCFXSCRTONT)r*  r+  r,  r-  r.  r/  r0  r1  )r	  r  r  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>)
quoteOrderQtybrokeraccountsByTypeaccountsByIdnetworksnetworksByIdimpliedNetworks
legalMoneylegalMoneyCurrenciesByIddefaultWithdrawPrecisionfeaturesr  )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)rf  r  daysBack	untilDayssymbolRequired)rf  triggerrr  rv  )rf  r  rw  rr  rv  )rf  r  rt  ru  rw  rr  rv  )rf  r  rt  daysBackCanceledru  rw  rr  rv  r  )
r   r   ro   rp   r   r   r   r   r   r   )r  lastr  )rf  rg  rh  rj  rk  rl  rm  rn  rq  rr  icebergr  rp  ro  max   )rf  rt  r  ru  rv  Z   i  )	r   ro   rp   r   r   r   r   r   r   extendsforDerivatives)r  r  )rY   r  r[   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-4188r  z-4194z-4195z-4196z-4197z-4198z-4199z-4200z-4201r  z-1003z-1006z-1007z-1010z-1013z-1112z-1114z-1129z-2011)
r  -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-4408r  r  r  r  r  r  r  r  r  r  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PERCENT_PRICE_BY_SIDE)rY   r  r  r]   portfolioMarginr  broadrollingWindowSizeg     L@)deep_extendsuperrL   describeparse_numbersafe_currency_structurerI   rH   rA   r2   r6   r7   r8   rG   r<   r4   r;   r3   r1   rC   r>   r?   r@   r=   rF   rE   rD   r:   )self	__class__s    J/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/binance.pyr  zbinance.describe*   sy   gt 4 4 = = ? ? @*B
)@*B
I@*B
 @*B
 	@*B

 @*B
 4@*B
  TTT $T 	T
 $T $T TT $TT 'T "4T tT T $UT  T %dT  '!T" &t#T T$ '%T& ''T( /)T* ,T+T, (-T. 0/T0 t1T2 3T4 75T6 &t7T8 (9T: ';T< &t=T> (?T@ "4ATB (CTD -dET T TF %dGTH TITJ dKTL  MTN OTP !$QTR STT  UTV &tWTX +EYTZ )$[T\ /
]T^ &z_T` #EaTb $ZcTd )$eTf $TgT T Th $TiTj +DkTl 'mTn (oTp "4qTr sTt &tuTv (wTx 1%yTz  {T| +E}T~ *:T@ +DATB &tCTD '
ETF (GTH #DIT T TJ *4KTL $TMTN tOTP "4QTR *:STT +DUTV #EWTX "4YTZ t[T\ #D]T^  _T` !$aTb %dcTd $UeTf &ugTh -diTj /kT T Tl "4mTn #DoTp +JqTr sTt !$uTv !$wTx "4yTz &t{T| +D}T~  T@ dATB $TCTD +DETF !$GTH "4ITJ tKTL #EMT T TN dOTP !$QTR "5STT tUTV #DWTX  YTZ '[T\ ']T^ $T_T` !$aTb (cTd (eTf %dgTh )$iTj )$kTl tmTn toT T Tp qTr TsTt tuTv "4wTx #DyTz %j{T| &z}T~ 'T@ $UATB  CTD !$ETF (GTH )%ITJ )%KTL "5MTN #DOTP +EQT TR !%$('+#"!%#'  gT T T@*B
z  dd d d	
 u u d d d d d u d d d  d!{@*B
^ i"M#N%P"M$O$O#N%P%PEFA  #J#J%L"I$K$K#J%L%LCD? =? ? ?	
 !"D "#E !"D "#E $%G  G !"D #$F #$F "#E $%G  $%G!"  G#$ ??:>@-  0 1N # 
 8 #bA@ @_@*B
`  GX8!X 9!X (	X *3X 'X 'X &qX +CX *3X ,QX /X .qX  )#!X" )##X$ ,S%X& )#'X( I&)X X* =h+X, /-X. 9!/X0 .q1X2 &q3X4 '5X6 )!7X8 *39X: 1#;X< 5c=X> '?X@ ,QAXB +BCXD *1EXF /GXH 1!IXJ ,QKX X XL 3CMXN 21OXP /QXR 3ASXT 7UXV 5cWXX +AYXZ .r[X\ /]X^ 13#2N2N_X` 4cQ5O5OaXb 4ScXd 1!eXf *3gXh &viXj <RkXl :6mX X Xn B6oXp ;FqXr .rsXt 1"uXv 5fwXx 1#yXz 1"{X| 3B}X~ 0X@ 8AXB &vCXD .rEXF 6rGXH .rIXJ -bKXL -bMXN /OX X XP 5cQXR 7SXT 7UXV 6rWXX ?YXZ 22[X\ 1"]X^ 6s_X` &vaXb (cXd +AeXf /gXh *6iXj 0kXl 21mXn 7oXp 1#qX X Xr 5csXt 4SuXv 3AwXx 8yXz =f{X| ,V}X~ /X@ ,RAXB .vCXD 8EXF )#GXH 3CIXJ @KXL "3MXN 6qOXP =cQXR ;ASX X XT ?UXV +CWXX 5aYXZ <Q[X\ 23]X^ -a_X` ;CaXb >scXd 8eXf STUgXh =giXj B6kXl 3CmXn =coXp FsqXr I'sXt @uX X Xv 9#wXx 27yXz =h{X| =g}X@ 5cAXB 6sCXD <SEXF 7GXH 0IXJ 7KXL 9#MXN 8OXP /QXR 8SXV A"WXX DRYXZ A"[X X X\ 0]X^ >r_X` .raXb @cXd B2eXf FrgXh A"iXj DRkXl FrmXn >roXp .rqXr 0sXv .swXx .syXz /{X| -c}X~ .sX X X@ 8AXB 6sCXD -cEXH &sIXJ *CQ+G+GKXL -fMXN &wOXP %fQXR .wSXT 4WUXV 7WXX 1%YXZ /[X^ )#_X` 0aXb -ccXd )#eX X Xh 0iXj 4QkXl 8mXn :1oXp >qqXr <QsXt @uXx /yXz ,Q{X| B1}X~ FqX@ &qAXB *1CXD 21EXF 5aGXH 9!IXJ ;AKX X XL 8MXN 8OXP :1QXR ;ASXT =aUXV =aWXX 3AYX^ 23_Xb >scXf 3FgXh .viXj /kXl ,VmXn +FoXp *3qXr ?sXt 7uX X Xv /wXx 5cyXz .s{X| 23}X~ 8X@ 1#AXB ,SCXD 3AEXF +FGXH 5fIXJ 6sKXL 9!MXN :1OXP ,QQXR EaSXT 3AUXV 7WX X XX /YX\ .s]X^ +C_X` 0aXb 4ScXd @eXf DSgXh 8iXj @kXl 8mXn 6soXp ;CqXr 9#sXt A#uXv =cwXx =cyXz @{X X X~ 4RX@ 22AXB A"CXD ?EXF CBGXH A"IXJ CBKXL 8MXN 6rOXP .rQXR J2SXT HUXV HWXX FrYXZ Eb[X\ CB]X^ H_X Xb -0140347=@;>oX X XrK$gK(#K )&K 23	K
 1(K <SK ;CK 1&K =fK 7K .vK *6K &vK  '!K" '#K$ +H%K& &v'K K( :6)K, 3F-K. 26/K0 .s1K2 "33K4 85K6 6v7K8 4S9K: 5c;K< 7=K> ??K@ 8AKB ;CCKD 8EKF 5cGKH 5cIKJ 6sKK K KL )#MKN 23OKP *3QKR +CSKV ;CWKX 1#YKZ /[K^ -b_K` 0aKb %bcKd -eeKh )#iKj &skKn 4QoKp 8qKr >qsKt @uK K Kv ,QwKx 3AyKz 4Q{K| /}K~ :1K@ :1AKB B1CKD FqEKF *1GKH 21IKJ 9!KKL 9!MKN CAOKP 1!QKR =aSKT DQUKV 3AWK K KX LQYKZ I![K^ .s_K` .saKb +CcKd 1&eKf 26gKh 4ViKl +CmKn )#oKp 1#qKt 0uKv 1"wKx 1"yKz 0{K| 1"}K@ 6sAK K KB =cCKD *6EKF )&GKH *6IKJ &vKKL %fMKN *6OKP 5fQKR .vSKT 3FUKV )&WKX +FYKZ .v[K\ 3F]K^ 4V_K` 4SaKb 5acK K Kd 1#eKf 9#gKh CCiKj )"kKl +BmKn 8oKp /qKr 7sKt 8uKv ?wKx 6syKz 5c{K~ 9#K@ 7AKB 6sCKD 4SEKF @GK KH @B>?14:=9<UK K KZ +.36  .1(0,439*-3601EF+..1JP _~ ~GB /17:>?<?8:8:79@B799;-.  24CI06/54:  CGn ,g -c	 oG~ ,gGH   '  !"a3(SRTIX\^`Wa8b!c!c	
 !! +B $R ' &q !12q'C8dTUYY^`bXc9d"e"e +QRGcSTXX\^_W`chjlbmCn,o,o +QRGcSTXX\^_W`chjlbmCn,o,o *AB7SRSHW[]^V_bgikalBm+n+n -qr1gPSUVxZ^`aYbejlndoEp.q.q &r'B'B  '(B(B!" ,aQ-G-G#$ )*()'()  IGx *+,-455678+,!" 
yGN +R(!   $Q	
 %qa&@&@ $bb%A%A "1 "1 1! ' %rr&B&B !" *1 &'C'C &q  )"!" &q#$ +,&)),&)),*-),1  6 ./!"'(.0$%&'*+%&	 	 &'!"'(  "#)*'(%&	 U0  0 OGp  )1"qGz   '  !"a3(SRTIX\^`Wa8b!c!c	
 #B !! +B $R !12q'C8dTUYY^`bXc9d"e"e +QRGcSTXX\^_W`chjlbmCn,o,o *AB7SRSHW[]^V_bgikalBm+n+n +QRGcSTXX\^_W`chjlbmCn,o,o -qr1gPSUVxZ^`aYbejlndoEp.q.q &q &q  '!" &r'B'B#$ 23(B(B67Q-G-G()%&/0b&A&A()56B,G,G%&01,-)*+,;   {G| *+,-455678/0!" 
}GR -%'C'C-#Q- $Q- %qb&A&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 $%())*/0%&34"*E*E)**,Y- - -\%q+Q )! %a	
   %a #A $Q -b ,Q 4Q 8 "1 +C  .r!$ $Q%* &'!"'(  ()!")*%&%&*+ QQ  Q SGv &!wG@  #$#$() "AGN 2!OGT  #$#$() "UGb  ! !()!""# !!""#"#,.+,() cGB !1"A %qb&A&A (	
 %a )!  &q )! ( q -a   -a .q  ,Q!" &q#$ $Q% * "#'(%&"#$%./79.//0
 
 &'./ 
 "#'()*56%&./ I,  , CGd !$ #*+#qC8dTVZZ^`bYc8d!e!e"#%(,-"%$'03'D'D+.B"?"?-014#(F(F69s-K-K()$' $ )# )# )#5 @ )*),%(!$/2&C&C%&#$$%+,./)*./  &)),),+.),+.%(*-!$/2&)  '*%(!$ 9! !NDD"AD 'D (!)D)D	D
 'D #AD 'D (!)D)DD 'D 3AD 4aR5P5PD 6qD 3QB4O4OD 3AD 4aR5P5PD  6q!D" 3B#D 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 D DF -cGDH -cIDJ -aKDL )22*F*FMDN )22*F*FODP ./K/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 D 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 DJ"A. #A /	
 ' %c $S +A &s &s / / *3 ' /  9#!" $S#$ -.-1&')  . &)$%$%  %&01,-89$%01,-89()01,-%( Ks sj $aEG G Ga@*B
p% $!&"&!..w77!..w77  #*%)&*!%!2!2:!>!>!%!2!2:!>!> "&!2!23!7!79J9J:9V9V W!%!2!25!9!94;L;LZ;X;X Y!%!2!26!:!:D<M<Mj<Y<Y Z!%!2!26!:!:D<M<Mj<Y<Y Z!%!2!27!;!;T=N=Nz=Z=Z [!%!2!27!;!;T=N=Nz=Z=Z [!%!2!28!<!<d>O>OPZ>[>[ \!%!2!28!<!<d>O>OPZ>[>[ \!%!2!28!<!<d>O>OPZ>[>[ \!%!2!28!<!<d>O>OPZ>[>[ \& "&!2!23!7!79J9J:9V9V W!%!2!25!9!94;L;LZ;X;X Y!%!2!26!:!:D<M<Mj<Y<Y Z!%!2!26!:!:D<M<Mj<Y<Y Z!%!2!27!;!;T=N=Nz=Z=Z [!%!2!27!;!;T=N=Nz=Z=Z [!%!2!28!<!<d>O>OPZ>[>[ \!%!2!28!<!<d>O>OPZ>[>[ \!%!2!28!<!<d>O>OPZ>[>[ \!%!2!28!<!<d>O>OPS>T>T U&" "     "H #)%)&*!%!2!2:!>!>!%!2!2:!>!> "&!2!23!7!79J9J:9V9V W!%!2!25!9!94;L;LZ;X;X Y!%!2!26!:!:D<M<Mj<Y<Y Z!%!2!26!:!:D<M<Mj<Y<Y Z!%!2!27!;!;T=N=Nz=Z=Z [!%!2!27!;!;T=N=Nz=Z=Z [!%!2!28!<!<d>O>OPZ>[>[ \!%!2!28!<!<d>O>OPZ>[>[ \!%!2!28!<!<d>O>OPZ>[>[ \!%!2!28!<!<d>O>OPZ>[>[ \& "&!2!23!7!79J9J:9V9V W!%!2!25!9!94;L;LZ;X;X Y!%!2!26!:!:D<M<Mj<Y<Y Z!%!2!26!:!:D<M<Mk<Z<Z [!%!2!27!;!;T=N=Ns=S=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 Oq%@*B
P( 55Wgdhduduv}d~d~66  A  AQ(@*B
V( ! !W(@*B
^( Y_(@*B
b(  suss    !s !%s "4s %es  v!s" !$#s$ 6u%s& 5d's( 28)s4 ,U5s6 !.7s8 i9s: !!;s< *5=s> #$#% %?sF "&(** ,(*+  #"(&%( *(&)&# # #(& ( )&! !?U?5? U? 5	?
 E? 5? U? 5? 5? 5? j? W?  W!?" F#?$ 5%?& *'?( 
)? ?* F+?, 5-?. h/?0 F1?2 53?< 5=?> 5??B 5C?D 5E?J FK?L FM?N FO?R FS?T FU?Z  [?\ F]?b 5c? ?d ! $""  # }? ? ?B #""  $! ! $U+#U+$ $!4!4! 4! 4	!
 4! 4! 4! 4! 4! 4! 4! 4! 4! 4! 4!  4!!" 4#!$  A! ! !F E- -7es s sc(@*B
J. #!4( '+(,,0,1)-+/6:#'#'"&#(	( ( #'$)+/27,0,0+/$(	0 0 %*)-3$ $6 %)&+!%$(%&*.& & '+#($)*.	# # '+!%#($)*/( ( '+!%$(%*#($)*.$ $ '+!%$(,0%*#($)*.	* 	*  #QK KZ  $&+(,$($(%*- -
 *.+/6:#'#'"&#'	( ( #'/3$(#($)27+/3$ $8 q% ',$(!%%&*.& & ',#($)*.	# # '+!$#($)*/( ( '+!%$&%&#($)*.$ $ '+!%$&,-%&#($)*.	* 	*  #OJ# J#Z "#3 "#3 	  "#3 "#3 	 Ah hK.@*B
\3  M  	M
  M  !4M  M  M  M  M  M  M   !4!M"  !2#M$  %M&  'M(  )M0  1M2  !43M4  5M M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 M 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 M 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 M 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 M 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 M 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 M 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 M 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 M 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 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 M 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 M 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 M 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 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 M 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 M 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 M@
 #-"-"3"3"1"1 #-",%8%8Y
M M 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 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 g 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 g 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 g 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 gD ",!+!+!+!0Mg g 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 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 8X ",!+!1!1!1!+!2!2!+!1!1!2o8 8 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.  /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 y 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 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 y 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 y 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 y 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 y 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 y 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 y 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 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 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 Y 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 Y 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 Y 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 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 Y 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 Y 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 Yv 3C$.-9 W P P]3@*B
~S  S@*B
 @*B
 @* @* @*	    NtypesubTypec                     ||dk    S |dk    S )Nr  r   r  r  r  s      r  
is_inversezbinance.is_inverse
  s    ?:%&i''r  c                 *    ||dk    p|dk    S |dk    S )Nr\   r[   r  r  r  s      r  	is_linearzbinance.is_linear
  s&    ?8#88h&&r  enablec                 l    t          t          |                               |           || j        d<   d S )Nr  )r  rL   set_sandbox_moder  )r  r  r  s     r  r  zbinance.set_sandbox_mode
  s3    gt--f555&,]###r  symbolc                     d}|                     d          }|                     d          }d }|                    d          dk    r|                     |d          }n|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }	|                     |          }
|                     |
          }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@  rO   r  :r  r  baseIdquoteIdactiver  r]   r  r  rY   Fr[   r\   TrZ   contractcontractSizeCcallrN  )amountpriceminr{  )r  r  r,  )	expiryexpiryDatetime
optionTypestrikesettlesettleIdr  limitsinfo)splitfindsafe_stringsafe_integerconvert_expire_date	parse8601)r  r  r  optionParts
symbolBaser  r  r  strikeAsStringr  datetime	timestamps               r  create_expired_option_marketz$binance.create_expired_option_market
  s   ll3''\\#&&
;;sb  ##J22DD##K33D!!+q11"";22))+q99%%k155
++F3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%6&&U    
   
     U+
 +
 +
 +	
r  c                    | j         t          | j        dz             |                     | j        d          }|                     | j        d          }|dk    }|dk    }|p|}t          |t                    rv|| j         v rK| j         |         }|r:|d         r2|r|d         n|d         }|d	z   |z   }	|	| j         v r| j         |	         S n$|S || j        v rW| j        |         }
|rd
}n	|rd}n||}t          dt          |
                    D ]}|
|         }||         r|c S |
d         S |
                    d          dk    rb|
                    d	          dk     rI|F|dk    r@|                    d          \  }}|dk    r|n|}|d	z   |z   }	|	| j         v r| j         |	         S nG|
                    d          dk    s|
                    d          dk    r|                     |          S t          | j        dz   |z             )Nz markets not loadedr  r  r\   r  rY   r  r  r  r  r  r   r  r  r=  -C-Pz does not have market symbol )marketsr1   rO   r  r  
isinstancestrmarkets_by_idrangelenr  r  r  r7   )r  r  r  r  isLegacyLinearisLegacyInverseisLegacyr  r  futuresSymbolr  ir  r  s                 r  r  zbinance.market
  so   <*? ?@@@&&t|]CC))$,8HII$0%3!4_fc"" $	A%%f- "v "0>RVG__F6NF$*SL6$9M$44#|M:: 5 "M4---,V4! 1"*KK$ 1"+KK ("0Kq#g,,// & &A$QZFk* &%&qz!++c""R''fkk#.>.>.B.B++2G2G"(,,s"3"3KD%&+unnTT5F$*SL6$9M$44#|M::++d##b((fkk$.?.?".D.D88@@@"AAFJKKKr  marketIdr  	delimiter
marketTypec                    |d uo1|                     d          dk    p|                     d          dk    }|r|| j        vr|                     |          S t          t          |                               ||||          S )Nr  r  r  )r  r  r  r  rL   safe_market)r  r  r  r  r  isOptionr  s         r  r  zbinance.safe_market*  s    D(hd0C0Cb0H/ghmm\`NaNadfNf 	?X);;;44X>>>Wd##//&)ZXXXr  c                     |                      |t          | j        |         d         d         | j        | j                  S )Nr  r  )decimal_to_precisionrH   r  r  paddingMode)r  r  r,  s      r  cost_to_precisionzbinance.cost_to_precision1  sE    ((xf9Mk9Z[b9ceiewy}  zJ  K  K  	Kr  c                 F    |                                  | j        d         z
  S )Nr  )millisecondsr  )r  s    r  noncezbinance.nonce4  s!      ""T\2B%CCCr  c                 0   | j         rt          | j        dz             |r+| j        d         | j        d<   | j        d         | j        d<   n@d| j        v r7| j        d         | j        d<   |                     | j        d          }|| _        || j        d<   dS )a(  
        enables or disables demo trading mode

        https://www.binance.com/en/support/faq/detail/9be58f73e5e14338809e3b705b9687dd
        https://demo.binance.com/en/my/settings/api-management

        :param boolean [enable]: True if demo trading should be enabled, False otherwise
        z demo trading is not supported in the sandbox environment. Please check https://www.binance.com/en/support/faq/detail/9be58f73e5e14338809e3b705b9687dd to see the differencesr  apiBackupDemoTradingr  enableDemoTradingN)isSandboxModeEnabledr@   rO   r   omitr  )r  r  newUrlss      r  enable_demo_tradingzbinance.enable_demo_trading7  s     $ 	Ztw  *Y   Y  Z  Z  Z 	 04	%0@DI,-#y0DIe#ty00#y)?@DIeii	+ABBGDI,2()))r  c                    |                      | j        ddd          }|                     |d|          }|                     |d          }d}|                     dd|          \  }}d}|                     ||          r|                     |          }nA|                     ||          r|                     |          }n| 	                    |          }| 
                    |d          S )a  
        fetches the current integer timestamp in milliseconds from the exchange server

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :returns int: the current integer timestamp in milliseconds from the exchange server
        r   r  rY   r  N
serverTime)safe_string_2r  r  r  handle_sub_type_and_paramsr  fapiPublicGetTimer  dapiPublicGetTimepublicGetTimer  )r  paramsr  r  queryr  responses          r  
fetch_timezbinance.fetch_timeK  s     (({MSYZZ<<		&&))99+tVTT>>$(( 	1--e44HH__T7++ 	1--e44HH))%00H  <888r  c                    |                      | j        d          }|si S |                     d          si S |                     | j        d          }|i S |                      | j        dd          ri S |                     |          g}|                      | j        dd          }|r(|                    |                     |                     |}|d         }d}|r|d         }	|                     |	d	          }i }
t          dt          |                    D ]}||         }|                     |d
          }|                     |d          }|                     |          }|                      |d          }d}d}d}|                     |dg           }i }d}i }t          dt          |                    D ]}||         }|                     |d          }|                     |          }|dk    }|                     |d          }|                      |d          }|                      |d          }|p|}|p|}|||<   |                      |d          } | s||}|                     |d          }!|!}"t!          j        |!d          s||!nt!          j        ||!          }nJ|sH|sF|                     |                     |d                    }"|"|                     | j        d          }"||||o|||||                     |"          |                     |d          |                     |d          d|                     |d          dddd	||<   |                      |d          }#|o|o|#}$|                     ||i           }%||||rd nd!|                     |          ||$|||||| j        |                      |%d"          d#|
|<   |
S )$a~  
        fetches all available currencies on an exchange

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r   F	apiBackupNr  r  r   r#  	assetNamecoinrP   isLegalMoneyTnetworkListnetworkETFwithdrawFeedepositEnablewithdrawEnable	isDefaultwithdrawIntegerMultipler  withdrawInternalMinr\  withdrawMinwithdrawMaxr  depositDustr   deposit)	r  rO   r  r  r  r   feer  r  r  fiatcryptoisBorrowable)rO   rP   r  r  r  r  r  r  r   rW  r  r  r  rZ   )	safe_boolr  check_required_credentials
safe_valuer   sapiGetCapitalConfigGetallappendsapiGetMarginAllPairsindex_byr  r  r  safe_currency_code	safe_listnetwork_id_to_codesafe_numberrJ   	string_eq
string_min	omit_zeror  	safe_dictr  )&r  r  fetchCurrenciesEnabledr   promisesr  resultsresponseCurrenciesmarginablesByIdresponseMarginablesresultr  entryrO   rP   r  isFiatminPrecisionisWithdrawEnabledisDepositEnabledr  r  r  rW  jnetworkItemr  networkCodeisETFr  r  r	  r
  precisionTickwithdrawPrecisionr  r  marginEntrys&                                         r  fetch_currencieszbinance.fetch_currenciese  s    "&>O!P!P% 	I
 ..u55 	IOODI{;;	 I>>$,(;UCC 	I33F;;<~~dlNEJJ 	@OOD66v>>???$QZ 	N")!*"mm,?MMOq#01122 {	 {	A@ 'q)E!!%00B##E622D**2..D^^E>::FL $#..rBBKDCH1c+..// 2 2)!n**;	BB"55g>> E)"..{MJJ ${O L L!%=M!N!N#3#D} $5$G! +W NN;DD	 &%C
 !% 0 0>W X X$1!(<< k5A5I==PWPbcoq~PPLL! k% k -1NN4;K;KKYn;o;o,p,p),4040@0@Oi0j0j-'!*+>, .&!%!2!23D!E!E $(#3#3K#O#O#'#3#3K#O#O% %
 $(#3#3K#O#O#'$ $	 	) )%%( nnUI66G'H,<HF.."bAAK "(6h!..|<< +-$+..nEE F4LL  r  c                 @   g }d}g d}|                      | j        d          }||                     |d|          }n|                     | j        d|          }|                     | j        dd          }|r+|                     d|          s|                    d           |                     | j        dd          }|                     | j        d	d          }|p|}	g }
t          d
t          |                    D ](}||         }|dk    r|	r|
                    |           )|                     | j        dd          }t          d
t          |
                    D ]M}|
|         }|dk    r|                    |                     |                     |rg| 	                    d          rR|	sP|                    | 
                    |                     |                    |                     |                     |dk    r)|                    |                     |                     |dk    r*|                    |                     |                     |dk    r*|                    |                     |                     2t          | j        dz   |z   dz             |}g }g | j        d<   g | j        d<   t          d
t          |                    D ]}|                     ||          }|rt%          |t&                    rkt'          |                     |d                                                    }t          | j        d                   }|d
k    r|| j        d<   || j        d<   |                     |ddg           }|                     ||          }| j        d         r|                                  g }t          d
t          |                    D ]0}|                    |                     ||                              1|S )a  
        retrieves data on all markets for binance

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Nr  r   r  r  Fr]   r  r  r   r  rY   r  r  z+ fetchMarkets() self.options fetchMarkets "z " is not a supported market typecrossMarginPairsDataisolatedMarginPairsDatar  symbolsoptionSymbolsr  )r$  r  r  r  in_arrayr  r  r  publicGetExchangeInfor  r  sapiGetMarginIsolatedAllPairsfapiPublicGetExchangeInfodapiPublicGetExchangeInfoeapiPublicGetExchangeInfor1   rO   r  r  listr  keyssafe_list_2array_concatload_time_differenceparse_market)r  r  promisesRawrawFetchMarketsdefaultTypesfetchMarketsOptionsr  r  demoMode	isDemoEnvr   r  r  r  r  r'  r  reskeysListlengthresultMarketsr+  s                         r  fetch_marketszbinance.fetch_marketsH  s`    444"nnT\>JJ*"nn-@'<XXOO #nnT\><XXO6FNN 	1==?;; 1&&x000nnT\=%HH>>$,0CUKK+	q#o..// 	& 	&A"1%DxI%%%%~~dlNEJJq#l++,, 	O 	OA%aJV##""4#=#=f#E#EFFF SD$C$CE$J$J SS\ S&&t'A'A&'I'IJJJ&&t'I'I&'Q'QRRRx''""4#A#A&#I#IJJJJy((""4#A#A&#I#IJJJJx''""4#A#A&#I#IJJJJ#DG.[$[^h$h  lN  %N  O  O  O/1+,24./q#g,,'' 	D 	DA//'1--C 
D
3 5 5 
Dc8 < < A A C CDDT\*@ABBQ;;;CDL!788>FDL!:;; $ 0 0iRT U U++G]CCr <12 	(%%'''q#g,,'' 	9 	9AMM$++GAJ778888r  c                    d}d}d}|                      |d          }|                      |d          }|                    d          }|                      |d          }|                     |d          }	|                      |d|          }
|                      |d          }|                     |
          }|                     |          }|                      |d          }d|v }|                     |d	d
          }|                      |d          }|dk    s|dk    rd }d}n|d}d}|dn|}n|d}|                     |          }| }|                     |dg           }|                     |d          }|                     |dd          }d }| j        }d }d }|dz   |z   }d }|r|r	|dz   |z   }n|r"|dz   |z   dz   | 	                    |          z   }n|r}| 
                    |                     |                      |d                              }|dz   |z   dz   | 	                    |          z   dz   |z   dz   |                      |d          z   }|                     |dd|                     d                    }||k    }||k    }|rdnd}|                     | j        |i           }|dk    }|rG|                     |dg           }t          dt!          |                    D ]} ||          dk    rd} n|                     |d d          }!d }"|rH|                     || j        d!                   }#|                     || j        d"                   }$|#|$d#}"n	|s|rddd#}"d }%|rd$}%n|rd%}%n|rd&}%n|rd'}%d }d }&||                     |          }&i d(|d)|	d|d*|d+|d,|d-|
d.|d/|d0|%d$|d1|o|!d2|"d%|d&|d'|d3|||||d4         d5         |d4         d6         |||                     |          |&|                     |d7          |                     |                     |                     |d8d9                              |                     |                     |                     |d:d;                              |                     |                     |                      |d<                              |                     |                     |                      |d=                              d>d d d?|                     |d@          |                     |dA          d?d d d?d d d?dB||                     |dC          dD}'dE|v rl|                     |dEi           }(|                     |(dF          |                     |(dG          d?|'dH         dI<   |                     |(dJ          |'dK         dI<   dL|v rl|                     |dLi           }(|                     |(dM          |'dK         dN<   |                     |(d@          |                     |(dA          d?|'dH         dN<   dO|v rM|                     |dOi           }(|                     |(d@          |                     |(dA          d?|'dH         dP<   dQ|v sdR|v rc|                     |dQdRi           }(|                     |(dSdT          |'dH         dU         dV<   |                     |(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  isolatedrY   r[   r\   r]   rO   lowercaseIdr  r  r  r  r  r  r  rZ   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  maxNotionalr{  )r  r  safe_string_lowerr  safe_integer_2r  r  r  r  yymmddnumber_to_stringparse_to_numericsafe_number_2r  r$  r  r  r  r>  r  iso8601parse_precisionr   r  safe_dict_2))r  r  r[   r\   r]   rV  rO   r  
optionBaserj  r  r  r  r  rY  r  r  r  r  rY   r^  filtersByTyper`  r  r  r  r  r  r  feesTyper  rf  r1  rh  rk  hasCrossMarginhasIsolatedMarginunifiedTypeparsedStriker,  filters)                                            r  rI  zbinance.parse_marketm  s	   %%fl;;
fh//hhsmm%%k155
,,VX>>!!&+zBB""6<88&&v..''00''??"f,$$V^\JJ##FM::K''V}-D-DFDD#HF"*"2vvHHF((22|..B77g|<<##FH6FGGye# 	; C#. C#.4t{{67J7JJ C..t/D/DTEUEUV\^kElEl/m/mnn#.4t{{67J7JJSPSYY\__bfbrbrs~  AB  cC  cC  C--fnfdN_N_`cNdNdeeLu_FnG#)8xxyH>>$)Xr::DI% 	..CCK1c+..//  q>]22"FE 3 "&8PRW!X!X 	!]]2t|<R/STTN $b$,?X2Y Z Z'- KK  	w 	  K  	 KK 	 KK 	"KK 	"KF008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2"00@@++D,@,@ASASTZ\o  rA  BB  BB  -C  -C  D  D**4+?+?@R@RSY[kmy@z@z+{+{||))$*>*>t?O?OPVXl?m?m*n*noo**4+?+?@P@PQWYi@j@j+k+kll	    
  ++FH==++FH== 
   
    $ ((??k6
 6
 6
n ]**^^M>2FFF ''
;;''
;;( (E(OG$ +/*:*:6:*N*NE+w'&&^^M:rBBF+/+;+;FJ+O+OE+x(''99''99) )E(OH% --^^M3DbIIF''99''99) )E(OH% m++}1L1L%%m^ZQSTTF-1-?-?Wa-b-bE(OF#E*-1-=-=fm-T-TE(OF#E*r  c                    |                                  }|                     |d          |d<   |                     |d          |d<   |                     |d          }|                     |d          }t          j        ||          |d<   |S )Nlockedusedfreeinterestborroweddebt)rx  r  rJ   
string_add)r  r,  rx  r  r  s        r  parse_balance_helperzbinance.parse_balance_helper  s    ,,..**5(;;**5&99##E:66z22!,T8<<r  Fc                 <   d|i}d }|dk    }|dk    p|dk    }|rt          dt          |                    D ]}	||	         }
|                                 }|                     |
d          }|                     |          }|dk    r4|                     |
d          |d	<   |                     |
d
          |d<   n;|dk    r4|                     |
d          |d	<   |                     |
d          |d<   n|r|                     |
d          }|                     |
d          }t          j        ||          |d<   |                     |
d          |d	<   |                     |
d          |d<   |                     |
d          |d<   no|                     |
d
          }|                     |
d          }t          j        ||          }|                     |
d          }t          j        ||          |d<   |||<   Ɛn|s|dk    s|r|                     |d          }|                     |ddg           }t          dt          |                    D ]}	||	         }|                     |d          }|                     |          }|                                 }|                     |d	          |d	<   |                     |d          |d<   |rD|                     |d          }|                     |d          }t          j        ||          |d<   |||<   ǐn|r:| 	                    |d          }t          dt          |                    D ]}	||	         }|                     |d          }| 
                    |d d d          }|                     |d i           }|                     |d!i           }|                     |                     |d                    }|                     |                     |d                    }i }|                     |          ||<   |                     |          ||<   |                     |          ||<   n|d"k    r| 	                    |d#g           } t          dt          |                     D ]n}	| |	         }
|                     |
d          }|                     |          }|                                 }|                     |
d$          }!|!|d<   |!|d<   |||<   on|d%k    rt          dt          |                    D ]}	||	         }
|                                 }|                     |
d          }|                     |          }|                     |
d	          |d	<   |                     |
d&          }"|                     |
d'          }#|                     |
d          }$t          j        |"t          j        |$|#                    |d<   |||<   n|}t          |t                    s| 	                    |dg           }t          dt          |                    D ]}	||	         }|                     |d          }|                     |          }|                                 }|                     |d(          |d	<   |                     |d)          |d<   |                     |d*d+          |d<   |||<   ||d,<   |                     |          |d-<   |r|n|                     |          S ).Nr  ri  rZ   r  r   assetr  umWalletBalancer  umUnrealizedPNLr  r  cmWalletBalancecmUnrealizedPNLcrossMarginBorrowedcrossMarginInterestr  crossMarginFreecrossMarginLockedcrossMarginAssettotaltotalWalletBalancerY   
updateTimebalances
userAssetsr  r  r  assetsr  rW  rX  savingspositionAmountVosr  r  freezewithdrawingavailableBalanceinitialMarginmarginBalancerw  r  r  )r  r  rx  r  r  rJ   r  r  rF  r  safe_symbolr$  r  safe_balancer  rD  r  r  )%r  r  r  rf  isPortfolioMarginr+  r  ri  r  r  r,  rx  
currencyIdr  r  r  
usedLinearusedInverse	totalUsedr  r  rw  r  r  r  r  r  r  r  baseCode	quoteCode	subResultr  usedAndTotalfrozenr  r  s%                                        r  parse_balance_customzbinance.parse_balance_custom  sp   H
 	+!=zW'< Z	'1c(mm,, ' ' ,,..!--eW==
..z::8##&*&6&6u>O&P&PGFO&*&6&6u>O&P&PGFOOY&&&*&6&6u>O&P&PGFO&*&6&6u>O&P&PGFOO Y#//7LMMH#//7LMMH&-&88&L&LGFO&*&6&6u>O&P&PGFO&*&6&6u>Q&R&RGFO'+'7'7?Q'R'RGG$$!%!1!1%9J!K!KJ"&"2"25:K"L"LK ' 2:{ K KI)-)9)9%AU)V)V&'.'9)EW'X'XGG$&t1'2  @	'5))(LAAI''*lBOOH1c(mm,, ' '"1+!--gw??
..z::,,.."&"2"27F"C"C"&"2"27H"E"E I++GZ@@D#//DDH&-&8x&H&HGFO&t'  1	'^^Hh77F1c&kk** > >q	++E8<<))(D$GG~~e["==ulB??2243C3CD'3R3RSS 33D4D4DUG4T4TUU	"$	&*&?&?&E&E	(#'+'@'@'G'G	)$!%!2!29!=!=v> Y $x9Lb Q Q1c"34455 ' ')!,!--eW==
..z::,,..#//x@@#/ ".&t' Y1c(mm,, 
' 
' ,,..!--eW==
..z::"&"2"25&"A"A))%::"..umDD))%::")"4VW=OPVXc=d=d"e"e&t
'  Hh-- B>>(HbAA1c(mm,, ' '"1+!--gw??
..z::,,.."&"2"27<N"O"O"&"2"27O"L"L#'#5#5gPY#Z#Z &t'{!\\)44z!@vvt'8'8'@'@@r  c                 $   |                                   |                     | j        ddd          }|                     |d|          }d}|                     dd|          \  }}d}|                     |dddd          \  }}d}d}|                     d|          \  }}|                     |d          }d}i }	|s|dk    r^|                     ||          rd	}n| 	                    ||          rd
}d}| 
                    |                     |	|                    }nZ|                     ||          red	}d}
|                     |ddd          \  }
}|                     |	|          }|
s|                     |          }n|                     |          }n| 	                    ||          r-d
}|                     |                     |	|                    }n|dk    r|                     |d          }|                     |d          }|d}t#          |t$                    ra|                     |d                   }t)          dt+          |                    D ]'}||         }|                     |          }|d|z   z  }(n|}||	d<   |                     |                     |	|                    }n|dk    s|dk    r*|                     |                     |	|                    }n|dk    r*|                     |                     |	|                    }nY|dk    r*|                     |                     |	|                    }n)|                     |                     |	|                    }|                     ||||          S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

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

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

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#order-book       # spot
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Order-Book     # swap
        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Order-Book-RPI  # swap rpi
        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
        :param boolean [params.rpi]: *future only* set to True to use the RPI endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/?id=order-book-structure>` indexed by market symbols
        r  rO   Nr  r]   r  rpiFrV  r  TlastUpdateIdur  )r  r  eapiPublicGetDepthr  r  r  fapiPublicGetRpiDepthfapiPublicGetDepthdapiPublicGetDepthpublicGetDepthr  parse_order_bookr  )
r  r  r  r  r  r  r  r  r  	orderbooks
             r  fetch_order_bookzbinance.fetch_order_book  s     	V$$fTl
 $GG( 	I..t{{7F/K/KLLHHH 	I//&%77CYYvu--F Q#' 55dkk'66R6RSS224;;w3O3OPPI 	I..t{{7F/K/KLLHH**4;;w+G+GHHHJ %%h44	))(FIFF	!00>3OO	'r  r  c           
      |   |                      |dd          }d }d|v rd}|d|v rdnd}|                     |d          }|                     ||d |          }|                     |d          }|                     |d          }d	|v }	d }
d }|	r,|                     |d	          }
t          j        |
|          }n-|                     |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(|          S ))N	closeTimerQ  r  bidQtyrY   r  	lastPriceweightedAvgPrice
baseVolumevolumequoteVolumer  r  r  high	highPricelowlowPricebidbidPrice	bidVolumeaskaskPrice	askVolumeaskQtyvwapopen	openPriceclosery  previousCloseprevClosePricechangepriceChanger  priceChangePercentaverage	markPrice
indexPrice)r  r  r  r  r  )r  r  r  rJ   
string_mulr  safe_tickerr  )r  r  r  r  r  r  r  ry  wAvgisCoinmr  r  s               r  parse_tickerzbinance.parse_ticker  s   V ''VDD	
f#J$,$6$6ZJ##FH55!!(FD*EE44(:;;6)
 	N))&,??J!,Z>>KK))&(;;J,,V]HMMK !
f!
!
 Y//!
 D&&v{FCC	!

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

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

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

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

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.rolling]:(spot only) default False, if True, uses the rolling 24 hour ticker endpoint /api/v3/ticker
        :returns dict: a `ticker structure <https://docs.ccxt.com/?id=ticker-structure>`
        r  rO   Nr]   r  r  rollingFr   )r  r  eapiPublicGetTickerr  fapiPublicGetTicker24hrdapiPublicGetTicker24hrr  r  publicGetTickerpublicGetTicker24hrr  rD  r$  r  )r  r  r  r  r  r  r  firstTickers           r  fetch_tickerzbinance.fetch_ticker  s    	V$$fTl
 ( 	R//GV0L0LMMHHH 
	R33DKK4P4PQQHHI 	R33DKK4P4PQQHHnnVY>>GYYvy11F R//GV0L0LMM33DKK4P4PQQh%% 	:..1b99K$$[&999  6222r  r<  c                    |                                   |                     |dddd          }|                     |          }d}|                     d||          \  }}d}|                     d||          \  }}d}|                     ||          r|                     |          }n|                     ||          r|                     |          }n||dk    rYi }|+| 	                    | 
                    |                    |d<   |                     |                     ||                    }nt          | j        dz   |z   dz             |                     ||          S )aa  
        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   rY   r<  z" fetchBidsAsks() does not support  markets yet)r  market_symbolsget_market_from_symbolshandle_market_type_and_paramsr  r  fapiPublicGetTickerBookTickerr  dapiPublicGetTickerBookTickerjson
market_idspublicGetTickerBookTickerr  r@   rO   parse_tickers)r  r<  r  r  r  r  r  r  s           r  fetch_bids_askszbinance.fetch_bids_asks  st    	%%gtT4FF--g6699/6SYZZf99/6SYZZ>>$(( 
	g99&AAHH__T7++ 	g99&AAHHV^^G"%)YYtw/G/G%H%H	"55dkk'66R6RSSHHtw)MMPTTWeefff!!(G444r  c                 H   |                                   |                     |dddd          }|                     |          }d}|                     d||          \  }}d}|                     d||          \  }}d}|                     ||          r|                     |          }ne|                     ||          r|                     |          }n9|dk    r| 	                    |          }nt          | j        dz   |z   dz             |                     ||          S )a  
        fetches the last price for multiple markets

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

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

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

        :param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :param str [params.type]: 'spot', 'option', use params["subType"] for swap and future markets
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/?id=ticker-structure>`
        NTr   rY   r  Fr<  r]   z! fetchTickers() does not support r  )r  r  r  r  r  r  r  r  r  r  r  r!  r"  r  r  parse_tickers_for_rollingr  r  r@   rO   r$  )	r  r<  r  r  r  r  r  r  r  s	            r  fetch_tickerszbinance.fetch_tickersU  s4    	%%gtT4FF--g6699.&RXYYf99.&RXYY>>$(( 	f33F;;HH__T7++ 	f33F;;HHV^^nnVY>>GYYvy11F R--g66tyy)A)ABB!  //GV0L0LMM55hHHH "&)-4??73K3K)L)LGI&33DKK4P4PQQX//77HHtw)LLtSVddeee!!(G444r  c                 R   g }t          dt          |                    D ]q}|                     ||         d          }|                     |d d d          }|                     ||                   }|d         |d<   |                    |           r|                     |d|          S )Nr   r  rY   )r  r  r  r  r  r  filter_by_array)r  r  r<  r'  r  r  tickerMarketparsedTickers           r  r1  z!binance.parse_tickers_for_rolling  s    q#h--(( 	) 	)A''X>>H++HdD&IIL,,Xa[99L%1(%;L"NN<((((##GXw???r  c                    |                                   |                     |          }d}|                     d||d          \  }}d}|                     d||d          \  }}d|d         i}d}|                     ||          r*|                     |                     ||                    }n]|                     ||          r*|                     |                     ||                    }nt          | j
        dz   |z   dz             t          |t                    r+|                     |                     |d	i           |          S |                     ||          S )
ai  
        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   r[   r  r  rO   z# fetchMarkPrice() does not support r  r   )r  r  r  r  r  fapiPublicGetPremiumIndexr  r  dapiPublicGetPremiumIndexr@   rO   r  rD  r  r$  )r  r  r  r  r  r  r  r  s           r  fetch_mark_pricezbinance.fetch_mark_price  sm    	V$$99:JFTZ\bccf99:JFTZ\deefTl
 >>$(( 	h55dkk'66R6RSSHH__T7++ 	h55dkk'66R6RSSHHtw)NNQUUXffgggh%% 	N$$T^^Ha%D%DfMMM  6222r  c                    |                                   |                     |dddd          }|                     |          }d}|                     d||d          \  }}d}|                     d||d          \  }}d}|                     ||          r|                     |          }nI|                     ||          r|                     |          }nt          | j
        dz   |z   dz             |                     ||          S )a  
        fetches mark prices for multiple markets

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

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

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

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.price]: "mark" or "index" for mark price and index price candles
        :param int [params.until]: timestamp in ms of the latest candle to fetch
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Fr   paginaterV  rU  r  untilN)intervalr  rO   r  _r   pairr  	startTimer  r#  endTimer]   r  r[  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)r  r  rB  rC  r  r  rE  r  defaultLimitmaxLimitr  rF  r  r  partsrI  durationrK  nowr  candless                        r  fetch_ohlcvzbinance.fetch_ohlcv  s   2 	88z[`aa& 	x::<QVX]_hjprvwwwV$$   11!!&'226GW#566!2u}E!&S5I5I(()YOO
 
 $<GNN3''E##E1--D"GFOO (GH#(GK 
 i  ;199#33I>>H"hhueh.>.E.IJJG++--C),S'):):GI&!&GI( 	J//GV0L0LMMHHf__i  [<<T[[RX=Y=YZZ<<T[[RX=Y=YZZgi  \==dkk'SY>Z>Z[[==dkk'SY>Z>Z[[n$$i  ^??GU[@\@\]]??GU[@\@\]]H 	J//GV0L0LMMHHI 	J//GV0L0LMMHH++DKK,H,HIIH6 ##HfiNNr  tradec                 <   d|v r|                      ||          S |                     |dd          }|                     |dd          }|                     |d|          }|                     |d          }d|v pd	|v pd
|v pd|v }|rdnd}|                     ||d |          }|d         }d }	|                     |dd          }
d }|
|
rdnd}	n+d|v r|                     |d          }	nd|v r|d         rdnd}	d }d|v r@|                     |d          |                     |                     |d                    d}d|v r|d         rdnd}d|v r|d         rdnd}d|v s|d         r|                     |                     |dd                    }|                     |d          }d|v r|                     |d          |d}|	dk    r|	dk    r
|	dk    rdnd}	d|v r|	dk    rt          j	        d |          }| 
                    |||                     |          ||                     |g d!          |                     |d"          |                     |d#          |	||                     |d$d%          ||                     |d&d'          |d(|          S ))NisDustTrader  rQ  qqtyquantityr  
isIsolatedMorderListIdisMakerrY   r  misBuyerMakersellbuyrl  isBuyer
commissioncommissionAsset)r,  currencyr  r  
optionSider]   rX  r  	liquidityr  rd  -1)tatradeIdrO   orderIdr  pr  quoteQtybaseQty)r  r  r  r  rO   rs  r  rl  takerOrMakerr  r  r,  r  )parse_dust_trader  r  r  r  safe_bool_2r  r  rJ   r  
safe_trader  safe_string_n)r  ra  r  r  r  r  isSpotTrader  r  rl  
buyerMakerr}  r  r  s                 r  parse_tradezbinance.parse_trade  sV   E!!((777J ''sF;;	##E366!!%V<<##E844#u,s#,sMUZDZs`imr`r*:VV

!!(FD*EE!%%eS.AA
!'266UDDu__))%88DDE!! %i 0<uuf5  ((== 33D4D4DUL]4^4^__ C &+I&6C77GLe&+GnA77'LE!!fX&6!,,T-=-=e\SY-Z-Z[[F11%EEL~~ ,,UE:: &  DFNN!%uu6u$$5==$/f==F"Y//$$U,G,G,GHH%%eY77**5&99(''sG<<&&uj)DD 
  
   	r  c                 d   |                                   d}|                     |dd          \  }}|r|                     d||||          S |                     |          }d|d         i}|d         s=|||d<   |                     |d	          |d
<   |                     |d          }|||d
<   |                     | j        d          }	|                     |dd|	          }	|J|d         p|d         }
|	duo|		                    d          dk    }|rdnd}|
rt          ||          n||d<   |                     |ddg          }d}|d         s|	dk    r*|                     |                     ||                    }n|d         s|	dk    r*|                     |                     ||                    }na|d         s|	dk    r*|                     |                     ||                    }n)|                     |                     ||                    }|                     ||||          S )a_  
        get the list of most recent trades for a particular symbol
 Default fetchTradesMethod

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

 Other fetchTradesMethod

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

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

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

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

        :param str id: cancel order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit' or 'STOP_LOSS' or 'STOP_LOSS_LIMIT' or 'TAKE_PROFIT' or 'TAKE_PROFIT_LIMIT' or 'STOP'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated', for spot margin trading
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        rY   z" editSpotOrder() does not support r   ordersnewOrderResponse)r  r  r@   rO   edit_spot_order_requestprivatePostOrderCancelReplacer$  parse_order)r  rO   r  r  rl  r  r  r  r  payloadr  datas               r  edit_spot_orderzbinance.edit_spot_order  s    " 	V$$f~ 	ltw)MMPVW]P^^ajjkkk..r64vuV\]]55g>>P ~~h(:;;f---r  c                    |                      |          }|                     |g d          }	|d         |                                d}
|                                }|}|                     |dk    |dk    |          }|rd}|                     |dd          }||dk    rd	}n|d
k    rd}||
d<   |                     |d         d          }|                     ||          sL||k    r#t          | j        dz   |z   dz   |z   dz             t          | j        dz   |z   dz   |z   dz             |	P| 	                    | j
        d          }|2|                     |d          }|||                                 z   |
d<   n|	|
d<   |                     | j
        d         |d          |
d<   d}d}d}d}|dk    r|                     | j
        dd          }|r|                     |dd          }|d         d         }|&|                     |t"          || j                  |
d<   n|e|                     |          }|                     |          }t)          j        ||          }|                     |t"          || j                  |
d<   nCd}n@d}n=|d
k    rd}d}d}n0|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|                     ||          |
d!<   |r8|t          | j        d"z   |z   d#z             |                     ||          |
d<   |r&|                     |d$          | j
        d%         |
d$<   |r8|t          | j        d&z   |z   d#z             |                     ||          |
d<   d'|
d(<   |                     |d)d*          }|||
d+<   |                     |d$          d,k    r|                     |d$g          }|                     |g d-          }|                     |
|          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origClientOrderIdrO   r  rl  MARKETLIMIT_MAKER	stopPricerg  N	STOP_LOSSLIMITSTOP_LOSS_LIMITr  r  
orderTypes+ triggerPrice parameter is not allowed for  r  # is not a valid order type for the  marketrT  rY   r  r  RESULTFrS  Tr,  r  r  TAKE_PROFITTAKE_PROFIT_LIMITrf  z- editOrder() requires a price argument for a  orderrm  r  z7 editOrder() requires a triggerPrice extra param for a STOP_ON_FAILUREcancelReplaceModecancelNewClientOrderIdcancelOrigClientOrderIdcancelOrderIdr`  )rS  r,  r  r  r  postOnly)r  r  upperis_post_onlyr  r  r>  r<   rO   r$  r  r  uuid22r  r  safe_value_2r  rH   r  r  rJ   r  amount_to_precisionprice_to_precisionr  r  r  )r  rO   r  r  rl  r  r  r  r  r  r  initialUppercaseTypeuppercaseTyper  rg  validOrderTypesrT  brokerIdtimeInForceIsRequiredpriceIsRequiredtriggerPriceIsRequiredquantityIsRequiredrS  quoteOrderQtyNewr  amountStringpriceStringquoteOrderQuantitycancelIds                                r  r  zbinance.edit_spot_order_requestO  s    V$$**63m3m3mnnTlJJLL
 
  $zz||,$$%9X%EG[_lGlntuu 	*)M))&+~NN#(( +')) 1'..FF}}]O<< 	v#}44"47-Z#Z]c#cfi#ilp#ps|#|}}}"47S=4#7:_#_bh#hkt#tuuu ^^DL(;;F!++FF;;'2:T[[]]2JG./*7G&'&*oodlCU6VX\^f&g&g"# %!&"H$$ NN4<$OOM *#'#4#4V_f#U#U ";/8	#//3/H/HIY[cenpt  qC  0D  0DGO,,&#'#8#8#@#@L"&"7"7">">K)0);L+)V)V&/3/H/HI[]egprv  sE  0F  0FGO,,)-&&%)""g%%"O$(!!%{**0N0N%)"!%000mGZ6Z6Z!%%)""O$(!!m++"O!% 	K"&":":66"J"JGJ 	F}"47-\#\_c#cfn#nooo#66vuEEGG  	Hd&6&6v}&M&M&U%)\2F%GGM"! 	U#"47-f#fim#mpx#xyyy'+'>'>v|'T'T$'8#$%%f.FHabb')GO$FM22d::YYv77F6#z#z#z{{{{7F+++r  c                    |                      |          }|d         s#t          | j        dz   |d         z   dz             |d         |                                ||                     ||          d}	|                     |g d          }
||                     ||          |	d<   |
|
|	d	<   |                     |d
dg          }|	S )Nr  z& editContractOrder() does not support r  r  rO   )r  rl  ry  rf  r  r  r  r  r  )r  r@   rO   r  r  r  r  r  )r  rO   r  r  rl  r  r  r  r  r  r  s              r  edit_contract_order_requestz#binance.edit_contract_order_request  s    V$$j! 	ptw)QQTZ[aTbbennoooTlJJLL00@@	
 
 **63m3m3mnn#66vuEEGG$+8G'(6O5G#HIIr  c           	         |                                   |                     |          }d}	|                     |dddd          \  }	}|d         s|	r|d|vrt          | j        dz             |                     |||||||          }
d}|d         rV|	r*|                     |                     |
|                    }n|                     |                     |
|                    }n]|d	         rU|	r*| 	                    |                     |
|                    }n)| 
                    |                     |
|                    }|                     ||          S )
a  
        edit a trade order

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

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

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

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

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

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r   r  rO   r  rl  r  r  r  Nr|   r  r  Fz6 editOrders() does not support portfolio margin ordersTrY   r]   z editOrders() does not support r  r  r  r  )r  r  r  r  r  r  r$  r  r@   rO   r  r  r  r  fapiPrivatePutBatchOrdersdapiPrivatePutBatchOrdersparse_orders)r  r  r  ordersRequestsorderSymbolsr  rawOrderr  rO   r  rl  r  r  orderParamsr  orderRequestr  r  r  s                      r  edit_orderszbinance.edit_orders'  sl    	q#f++&& 	0 	0AayH''(;;H)))!!(D11B##Hf55D##Hf55D__Xx88FOOHg66E..8R@@K $-1-L-L[Zfhn  qB  DI  .J  .J*{  g"47-e#efff;;B$PTV\^cepqqL!!,////**<udDQQ\!_--&> 	iVH- 	itw)JJVTZ^[^gghhh>
 ++gv..( 	?55g>>HHI 	?55g>>HF   ***r  r`  c                 P    dddddddddddddd}|                      |||          S )Nr  closedcanceled	cancelingrejectedexpired)NEWPARTIALLY_FILLEDACCEPTED
TRIGGERINGFILLED	TRIGGEREDFINISHEDCANCELED	CANCELLEDPENDING_CANCELREJECTEDEXPIREDEXPIRED_IN_MATCHr  r  r`  statusess      r  parse_order_statuszbinance.parse_order_statusv  sO     & ! "#)"  )
 
 &&999r  c                 B    ddddddd}|                      |||          S )Nr  r  )limit_makerstopstop_markettake_profittake_profit_markettrailing_stop_marketr  )r  r  r  s      r  parse_order_typezbinance.parse_order_type  s:    "#""*$,
 
 tT222r  rs  c           
         |                      |d          }|A|                      |d          }|dk    r%|dk    s|dk    s|                     |dd|          S |                     |                     |g d                    }|                      |d	          }d
|v pd|v }|rdnd}|                     ||d |          }	|                      |dd          }
|                     |g d          }d }d|v sd|v r=|                     |dd          }|dk    rt          j        |
d          r|}n|dk    r|}|                     |dd          }|                      |d          }|                      |d          }| 	                    |dd          }| 	                    |dd          }|                      |d|          }| 
                    |dd          }|                     |d          }|                     |dg           }|                      |d          }|d k    rd!}|d"k    p|d!k    }| 	                    |d#d$          }|                     |                     |                    }|                     |d%          }d }||                      |d&          |d d'}|                     i d(|d)|                     |g d*          d+|                     |g d,          d-|d.|                     |          d/|d0|d	|	d|                     |          d|d1|d2|                     |d2          d|d|d$|d3|d4|||
d |||d5|          S )6Nr  msg200successz/The operation of cancel all open order is done.r  )r  r`  )r`  strategyStatus
algoStatusr  positionSidecumQuoter  rY   executedQtyr  )rQ  
createTimeworkingTimetransactTimer  r  r  r  r  r  r  origQtyrf  cummulativeQuoteQtycumBaser  	orderTyperl  fillsrm  GTXr`  r  r  rg  r  rX  )rr  r,  rater  rO   )
strategyIdry  algoIdr  )r  newClientStrategyIdclientAlgoIdr  r  lastTradeTimestamplastUpdateTimestampr  
reduceOnlyr  r,  )r  filled	remainingr`  r  rX  )r  
safe_orderr  r  r  safe_integer_nr  rJ   	string_gtr  safe_string_lower_2r  r  r  r#  r   r  r  r  )r  rs  r  r  r  r`  r  
isContractr  r  r  r  r  timestampValuer  r  r  r  r,  r  rl  r  rm  r  stopPriceStringrg  feeCostr  s                               r  r  zbinance.parse_order  sj   P v..""5%00C	)9)9sFw?w?w'L'LfUUU((););ECmCmCm)n)noo##E844$-G:3F
#-9ZZ6
!!(FD*EE!!%<<''/r/r/rss	!e##)>)>!00nUUN$VS11 8)7&8##%3""11%VV""5*55  00##E9jAA !!%)>
KKy$77''v{CC%%eV44ugr22&&um<<%KM)C{d/B,,UKPP(()H)HII""5%00 ,,ULAA C
   
E 
$$$U,O,O,OPP 
 T//7o7o7opp 
 	 

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

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

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r   r  r  rl  r  r  r  NFTrY   z! createOrders() does not support r  r  r  r]   )r  r  r  r  r  r  r$  create_order_requestr  r  r@   rO   r  fapiPrivatePostBatchOrderseapiPrivatePostBatchOrdersdapiPrivatePostBatchOrdersr  )r  r  r  r  r  r  r  r  r  rl  r  r  r  r  r  r  r  s                    r  create_orderszbinance.create_orders  s    	q#f++&& 
	0 
	0AayH''(;;H)))##Hf55D##Hf55D__Xx88FOOHg66E..8R@@K44XtT6SXZeffL!!,////**<udDQQ\!_--&> 	ktw)LLvV\~]`iijjj>
 ++gv..( 	@66w??HHH 	@66w??HH66w??HF   ***r  c                    |                                   |                     |          }|                     |d|d                   }|                     |d          }	|                     | j        ddd          }
|                     |dd|
          }|                     |dd          }|                     |d          }|                     |d	          }|                     |d
d          }|du}|du}|du}|dup|p|p|}|                     |ddd          }|                     |dd          }|                     |g d          }|                     ||||||          }d}|d         r| 	                    |          }nP|r0|r| 
                    |          }n5|                     |          }n|d         rc|r.|r|                     |          }n|                     |          }n|rd|d<   |                     |          }n|                     |          }n|d         rF|r.|r|                     |          }n|                     |          }n{|                     |          }ne|dk    s|	|r.|r|                     |          }nC|                     |          }n-|r|                     |          }n|                     |          }|                     ||          S )a  
        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
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/New-Algo-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, one of NONE, EXPIRE_MAKER, EXPIRE_TAKER or EXPIRE_BOTH
        :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
        :param str [params.clientOrderId]: the clientOrderId of the order
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r  rf  r  r  Frg  r  rj  rk  trailingPercentcallbackRateNsorSORr  )r-  r.  r  r]   r  CONDITIONALalgoTyper  rZ   )r  r  r  r  r  r  r  r  r%  eapiPrivatePostOrderprivatePostSorOrderTestprivatePostSorOrderpapiPostUmConditionalOrderpapiPostUmOrderfapiPrivatePostAlgoOrderfapiPrivatePostOrderpapiPostCmConditionalOrderpapiPostCmOrderdapiPrivatePostOrderpapiPostMarginOrdersapiPostMarginOrderprivatePostOrderTestprivatePostOrderr  )r  r  r  rl  r  r  r  r  r  rf  porfolioOptionsValuer  rg  rj  rk  r+  isTrailingPercentOrder
isStopLossisTakeProfitisConditionalr-  r  r  r  s                           r  create_orderzbinance.create_order2  s^   T 	V$$%%fffVnEE
%%fl;;
#//fFWY^__ ,,VV=NPdee))&.+NN((AA**63DEE,,V5FWW!0!<"$.
&d2%T1j6LjPZj^jvueU;;~~ffe446#9#9#9:: ++FD$vVV( $	:0099HH "	: =77@@33G<<H 	:  
B  =#>>wGGHH#33G<<HH  B*7GJ'#<<WEEHH#88AAHHI 	:  >  =#>>wGGHH#33G<<HH44W==8##z'=AR'=  =33G<<33G<< :44W==0099&111r  c                 P   |                      |          }|                     |d|d                   }|                     |g d          }	|                                }
|
dk    }|
dk    }|d         |                                d}d}|                     |dd	d
d          \  }}d}|                     d|          \  }}|                     |dd          }|r+|dk    s
|d         s||                     |d          }d|d<   |                     |dd          }|                     |d|          }|                     |d          }|                     |d          }|                     |dd          }|                     |g d          }|                     |d          }|du}|dup|du}|du}|du}|p|p|p|}|o|}|du}d}|                                } d}!|r|d         r$d} ||d<   || 	                    ||          |d<   n| dk    r| dk    r| d k    r}| d!k    rw|                     |d"          }"|                     |d"          }|"d#k    r |"d$k    rt          | j        |z   d%z             |r|"d#k    rd} n|"d$k    rd} n|"d#k    rd } n|"d$k    rd!} | dk    s| dk    rd}|| 	                    ||          }!t          j        |d&          }#|#|d<   nC|r |}!|r|d         rd'nd} n0|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    r#t          | j        d,z   |z   d-z   |z   d.z             n~|                     |d/         d0          }$|                     | |$          sL|
| k    r#t          | j        d1z   |z   d,z   |z   d2z             t          | j        d,z   |z   d-z   |z   d.z             |rd3nd4}%|d5         r|d         r|r|sd6}%|	x|                     | j        d7i           }&|d         rd8nd9}'d:}(|d         r|d         r
|d5         rdnd;}(|                     |&|(|'          })|)|                                 z   ||%<   n|	||%<   d}*|s9|                     ||
d<k    |          }*|d:         s|dk    r|*rd<} |d=k    rd|d><   n-|                     ||
d<k    |          }*|*r|d         sd<} nd?|d@<   |d:k    s|dk    r(|s&|                     | j        dA         |dB          |dA<   ndC|dA<   |rdDnd}+| ||+<   |                     |dEd          },d}-d}.d}/d}0| dk    r|d:         r|                     | j        dFd          }1|1r|                     |dFdG          }2|dH         dI         }3|2'|                     |2t*          |3| j                  |dF<   n|e|                     |          }4|                     |          }5t          j        |4|5          }6|                     |6t*          |3| j                  |dF<   nd}0nd}0nd}0n| dk    rd}.d}-d}0n| dk    s| dk    rd}/d}0|d5         s|d;         r|rd}.ni| d k    s| d!k    r	d}0d}/d}.d}-nT| d<k    rd}.d}0nI| d(k    rd}0d}/d}.n<| d'k    s| d)k    r|,sd}0d}/n)| dk    r#|,sd}0|t          | j        dJz   |z   dKz             |0rT|                     |dH         dL          }7|7du}8|8r|                     ||          |dM<   n|                     |          |dM<   |.ru|ss|t          | j        dNz   |z   dKz             |                     |dH         dI          }9|9du}:|:r| 	                    ||          |dI<   n|                     |          |dI<   |/r|d         r |!t          | j        dOz   |z   dKz             n#|!|!|t          | j        dPz   |z   dKz             |!E|d5         r$|d         r|s| 	                    ||!          |d<   n| 	                    ||!          |d<   |-rJ|                     |d@          4|                     |d@          |                     | j        dQ          |d@<   |s|d         r|*rd?|d@<   |                     |d@          dRk    r|                     |d@          }|                     |dSd          };|d:         s9|d*         s1|;r/|r |                     |d          }|dTk    rdUndT}|dTk    rdVndW|dX<   d}<|                     |ddY          \  }<}|<|d:         r|<                                |dZ<   |                     |d[          }=|=!|d:         r|                     ||=          |d\<   |                     |g d]          }>|                     ||>          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
        r  )r  r  r  r  r  rO   r  Nro   r  r  Fr  rZ   r  
AUTO_REPAYsideEffectTyperg  r  rj  rk  trailingDeltatrailingTriggerPriceactivationPrice)r+  r,  rH  r  Tr[   TRAILING_STOP_MARKETr,  r  r  r  r  stopLossOrTakeProfitstopLoss
takeProfitza trailingPercent orders require a stopLossOrTakeProfit parameter of either stopLoss or takeProfit100STOP_MARKETSTOPTAKE_PROFIT_MARKETr]   r  r  r  r  r  r  r  r  r  r  r  r  rT  r  r  rY   r  r  ri  rg  r  rm  r  r  r  strategyTypere   rS  r,  r  r  z6 createOrder() requires a trailingPercent param for a r  r  rf  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  r`  rn  rn  rm  LONGSHORTr  rq  selfTradePreventionModers  
icebergQty)r  r  r  r  rj  rk  r  rg  rI  r+  rS  r,  r  rn  rs  )r  r  r  r  r  r  r  r  r  r  r<   rO   rJ   r  r  r>  r$  r  r  r  r  rH   r  r  r  r  r  r   r  )?r  r  r  rl  r  r  r  r  r  r  r  isMarketOrderisLimitOrderr  r  rf  r  rg  rj  rk  rH  rI  r+  r  r@  rA  rB  isTriggerOrderrC  isPortfolioMarginConditionalisPriceMatchpriceRequiredForTrailingr  r  rL  trailingPercentConvertedr  clientOrderIdRequestrT  	defaultIdidMarketTyper  r  typeRequestre   r  r  r  r  rS  r  r  r  r  r  marketAmountPrecisionisPrecisionAvailablero  isPricePrecisionAvailablern  rq  rs  requestParamss?                                                                  r  r%  zbinance.create_order_request  s    V$$%%fffVnEE
**63h3h3hii#zz||,8+w6TlJJLL
 
 !$($C$CFM[actv{$|$|!6
!??vVV
F^^FL%@@
 	9X%%fZ.@%jF\6<88,8()))&.+NN((,OO**63DEE((AA#11&:PRcdd,,V5i5i5ijj%%fl;;
!0!<"$.K-t2K
&d2%T1&^*@^J^R^(9(Km$!-#' 

	! )	]f~ D 6*9''3151H1HQe1f1fG-.![00}7U7U\im~\~\~  FS  Wj  Fj  Fj+/+;+;FDZ+[+[(!YYv/EFFF,
::AUYeAeAe*47V+;  ?b  ,b  c  c  c$ 	@/:==,7MM1\AA,9M/:==,=MM1\AA,?M![00m}6T6T/4,'3 $ 7 7@T U UI+2+=ou+U+U(+C(( 	]%I T17
1C T T*0*< SBS 	]'I ]8>z8J ] 4 4P] ]17
1C \I\( 		zx"47S=4#7:_#_bh#hkt#tuuu   #nnVF^\JJO==@@ z'=88&tw1^'^ag'gjm'mpt't  xA  (A  B  B  B&tw}t';>c'cfl'lox'xyyy8Tl44Zl( 	2v 	2= 	2IZ 	2#1  ^^DL(B??F)/
);N,I!Lj! ^*0.]VH=M]vvT]''iHHH,4t{{}},DG()),9G()  	3((8LP]8]_effHf~ 1x!7!7 2$1M++,0GL)((8LP]8]_effH 3j) 3$1MM-2GM*6!!zX'='=HY'=*.*:*:4<HZ;[]aci*j*jG&'' +3G&'(DPnn&,vFF %!&"* H$$f~ * $t|_d S S  .'+'9'9&/SY'Z'Z$ &{ 3G <I'3373L3LM]_girtx  uG  4H  4H00*'+'<'<V'D'D&*&;&;E&B&B-4-?k-Z-Z*373L3LM_aiktvz  wI  4J  4J00-1**)-&&%)""g%%"O$(!!%{**0N0N%)"!%x  'F9$5 ';S '"&000mGZ6Z6Z!%%)""O$(!!m++"O!%f$$!%%)""OO},,-CW2W2W  *%)"%)""444  *%)"&"47-e#ehl#low#wxxx 	D$($4$4VK5H($S$S!$9$E # D&*&>&>vv&N&N
##&*&;&;F&C&C
# 	@< 	@}"47-^#^ae#ehp#pqqq!--f[.A7KKN)7t)C%( @#'#:#:65#I#I  #'#8#8#?#? ! 	Vj! \$&tw1l'los'sv~'~ % !(Y->?CZ&tw  2I  (I  LP  (P  S[  ([  \  \  \$(# Vv V?P V.2.E.Efi.X.XGN+++/+B+B69+U+UGK(  	Zd&6&6v}&M&M&U\`\l\lmt  wD  ]E  ]E  ]M%)%5%5dlDX%Y%YGM"  	+VJ%7 	+H 	+%*GM"FM22d::YYv}55F%88f~ 	MfX&6 	M6 	M <6<88"&%--vve15ffWGN#"&*&C&CFM[p&q&q#V*f~ Q5H5N5N5P5P12((AA$f~ X(,(@(@(W(W%		&  +L  +L  +L  M  M{{7M222r  r,  c                     |                                   |                     |          }|d         st          | j        dz             d|i}|                     |d||d|                     ||                    S )a6  
        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>`
        rY   z6 createMarketOrderWithCost() supports spot orders onlyr,  r  Nr  r  r@   rO   rD  r  )r  r  rl  r,  r  r  reqs          r  create_market_order_with_costz%binance.create_market_order_with_cost  s     	V$$f~ 	ctw)aabbbD
   4tT[[QTV\E]E]^^^r  c                     |                                   |                     |          }|d         st          | j        dz             d|i}|                     |dd|d|                     ||                    S )a  
        create a market buy order by providing the symbol and cost

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

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

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

        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        rY   z: createMarketSellOrderWithCost() supports spot orders onlyrS  r  rm  N)r  r  r@   rO   rD  )r  r  r,  r  r  s        r  "create_market_sell_order_with_costz*binance.create_market_sell_order_with_cost  sr     	V$$f~ 	gtw)eefff"&  64vNNNr  c                 4   |t          | j        dz             |                                  |                     |          }|                     | j        ddd          }|                     |d|          }d}|                     d|          \  }}d}|                     |dddd	          \  }}d
|d         i}	| 	                    |g d          }
| 
                    |g d          }|.|d         r||	d<   n?|d         r|d         r
|
r|s||	d<   n%||	d<   n|d         r|d         r
|
r|s||	d<   n||	d<   |                     |g d          }d}|d         r+|                     |                     |	|                    }n~|d         r|r+|                     |                     |	|                    }nI|
r+|                     |                     |	|                    }n|                     |                     |	|                    }n|d         rV|r*|                     |                     |	|                    }n|                     |                     |	|                    }n|dk    s||ra|r*|                     |                     |	|                    }n^|dk    rd|	d<   |                     |                     |	|                    }n)|                     |                     |	|                    }|                     ||          S )a  
        fetches information on an order made by the user

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#query-order-user_data
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-Order
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Query-Order
        https://developers.binance.com/docs/derivatives/option/trade/Query-Single-Order
        https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Order
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-Algo-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
        :param boolean [params.trigger]: set to True if you would like to fetch a trigger or conditional order
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nz( fetchOrder() requires a symbol argumentr   r  rY   r  r  r  Fr  rO   r  rw  conditional)r  r  r  r]   r  r  r[   r  r  r  ry  )r  r  r  r  rw  rq  r  r  rZ   ri  Trg  )r5   rO   r  r  r  r  r  r  r  safe_bool_nr  r  eapiPrivateGetOrderr  papiGetUmOrderfapiPrivateGetAlgoOrderfapiPrivateGetOrderpapiGetCmOrderdapiPrivateGetOrderpapiGetMarginOrdersapiGetMarginOrderprivateGetOrderr  )r  rO   r  r  r  r  r  rf  r  r  rC  r  r  s                r  fetch_orderzbinance.fetch_order  s   * >#DG.X$XYYYV$$((|]TZ[[<<
!??fUU
F $($C$CFLZ`bsuz${${!6fTl
 ((1S1S1STT**63i3i3ijj$h =+8((! =fVn = =O` =*7''/<+,,H 	$&. 	$] 	$K\ 	$ "GH!#GI6  $D  $D  $D  E  E( 	J//GV0L0LMMHHH 	J  V..t{{7F/K/KLL  V#;;DKKQW<X<XYYHH#77GV8T8TUUHHI 	J  R..t{{7F/K/KLL33DKK4P4PQQhJ$:?P$:  Q224;;w3O3OPP++,0GL)224;;w3O3OPP++DKK,H,HIIH&111r  c                    |t          | j        dz             |                                  d}|                     |dd          \  }}|r|                     d||||          S |                     |          }|                     | j        dd|d                   }|                     |d|          }d}	| 	                    d|          \  }	}d}
| 
                    |ddd	d          \  }
}|                     |g d
          }|                     |g d          }d|d         i}|                     d||          \  }}|||d<   |||d<   d}|d         r+|                     |                     ||                    }n|d         r|
rX|r+|                     |                     ||                    }n|                     |                     ||                    }nt|r+|                     |                     ||                    }nG|                     |                     ||                    }n|d         r|
rV|r*|                     |                     ||                    }n|                     |                     ||                    }n|                     |                     ||                    }n|
r*|                     |                     ||                    }nf|dk    s|	5|	dk    rd|d<   |                     |                     ||                    }n)|                     |                     ||                    }|                     ||||          S )a  
        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
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-All-Algo-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   rE  r  r  r  r  rp  )r  rw  rq  r  r  rO   rK  rJ  r  r]   r  r  rZ   ri  Trg  )r5   rO   r  r  r  r  r  r  r  r  r  rr  r  handle_until_optioneapiPrivateGetHistoryOrdersr  papiGetUmConditionalAllOrderspapiGetUmAllOrdersfapiPrivateGetAllAlgoOrdersfapiPrivateGetAllOrderspapiGetCmConditionalAllOrderspapiGetCmAllOrdersdapiPrivateGetAllOrderspapiGetMarginAllOrderssapiGetMarginAllOrdersprivateGetAllOrdersr  )r  r  rC  r  r  rE  r  r  r  rf  r  rC  r  r  s                 r  fetch_orderszbinance.fetch_orders,  s   4 >#DG.Y$YZZZ88PZ[[& 	b44]FESXZ`aaaV$$((}mU[\bUcdd<<
!??vVV
F $($C$CFM[actv{$|$|!6((1S1S1STT6#M#M#MNNfTl
 229gvNN#(GK $GG( 	R77GV8T8TUUHHH 	R  	Z  U#AA$++gW]B^B^__HH#66t{{7F7S7STTHH  Z#??GU[@\@\]]HH#;;DKKQW<X<XYYHHI 	R  V  U#AA$++gW]B^B^__HH#66t{{7F7S7STTHH77GV8T8TUU  R66t{{7F7S7STT!!Z%;++,0GL)66t{{7F7S7STT33DKK4P4PQQj   65%@@@r  c                    |                                   d}d}i }d}|                     d|          \  }}d}	|                     |dddd          \  }	}|                     |g d          }
|c|                     |          }|d         |d<   |                     | j        dd	d
          }d|v r|d         n|}|                     |d|          }nc| j        d         r"t          | j	        dz   | j	        z   dz             |                     | j        dd	d
          }|                     |d|          }d}| 
                    d||          \  }}|                     |g d          }d}|dk    r9|||d<   |||d<   |                     |                     ||                    }n|                     ||          r|	rX|
r+|                     |                     ||                    }n|                     |                     ||                    }n|
r+|                     |                     ||                    }nq|                     |                     ||                    }nF|                     ||          r|	rW|
r+|                     |                     ||                    }n|                     |                     ||                    }n|                     |                     ||                    }n|dk    s||	rz|	r*|                     |                     ||                    }nw|dk    rd|d<   |t1          | j	        dz             |                     |                     ||                    }n)|                     |                     ||                    }|                     ||||          S )a  
        fetch all unfilled currently open orders

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#current-open-orders-user_data
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Current-All-Open-Orders
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Current-All-Open-Orders
        https://developers.binance.com/docs/derivatives/option/trade/Query-Current-Open-Option-Orders
        https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-Open-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Conditional-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-CM-Open-Orders
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-CM-Open-Conditional-Orders
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Current-All-Algo-Open-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  r  Frp  rO   r  r  rY   r  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.r  r  rw  rq  r]   rJ  r  rZ   ri  Trg  zB fetchOpenOrders() requires a symbol argument for isolated markets)r  r  r  rr  r  r  r  r  r1   rO   r  r  eapiPrivateGetOpenOrdersr  r  papiGetUmConditionalOpenOrderspapiGetUmOpenOrdersfapiPrivateGetOpenAlgoOrdersfapiPrivateGetOpenOrdersr  papiGetCmConditionalOpenOrderspapiGetCmOpenOrdersdapiPrivateGetOpenOrderspapiGetMarginOpenOrdersr5   sapiGetMarginOpenOrdersprivateGetOpenOrdersr  )r  r  rC  r  r  r  r  r  rf  r  rC  r  r  r  r  s                  r  fetch_open_orderszbinance.fetch_open_orders3  sC   2 	
!??@QSYZZ
F $($C$CFL]_egxz  %A  %A!6((1S1S1STT[[((F &tGH,,T\;Lm]cddK,2f,<,<;J##FFJ??DD\>? 	A  +Z  !Z  ]a  ]d  !d  gA  !A  B  B  B,,T\;Lm]cddK##FFK@@D99:KVU[\\6#M#M#MNN8 ',$ #( 44T[[&5Q5QRRHH^^D'** 	O  	[  V#BB4;;wX^C_C_``HH#77GV8T8TUUHH  [#@@WV\A]A]^^HH#<<T[[RX=Y=YZZHH__T7++ 	O  W  V#BB4;;wX^C_C_``HH#77GV8T8TUUHH88Wf9U9UVVX!7;L!7  V77GV8T8TUU++,0GL)~/:~0~77GV8T8TUU00Wf1M1MNNH  65%@@@r  c                 *   |t          | j        dz             |                                  |                     |          }d|d         i}d}|                     |dddd          \  }}|                     |g d	          }|                     |g d	          }|o|}|rd
nd}	|||	<   d}
|d         r|rW|r+|                     |                     ||                    }
n| 	                    |                     ||                    }
n| 
                    |                     ||                    }
n|d         r|rV|r*|                     |                     ||                    }
n|                     |                     ||                    }
nh|                     |                     ||                    }
n>|d         rt          | j        dz             |d         rt          | j        dz             |                     |
|          S )a  
        fetch an open order by the id

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

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

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

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

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

        :param str symbol: unified market symbol of the market the orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch orders in a portfolio margin account
        :param boolean [params.trigger]: set to True if you would like to fetch portfolio margin account trigger or conditional orders
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nz1 fetchCanceledOrders() requires a symbol argumentr`  r  r  r  s          r  fetch_canceled_orderszbinance.fetch_canceled_orderss  se    . >#DG.a$abbb""65$??*EE)).%GGGr  c                 F   |t          | j        dz             |                     ||d|          }|                     |dd          }|                     |dd          }|                     ||          }|                     |d          }	|                     |	||          S )r  Nz: fetchCanceledAndClosedOrders() requires a symbol argumentr`  r  r  r  )r5   rO   r  r  rG  sort_byr  )
r  r  rC  r  r  r  canceledOrdersclosedOrdersr  sortedOrderss
             r   fetch_canceled_and_closed_ordersz(binance.fetch_canceled_and_closed_orders  s    . >#DG.j$jkkk""65$??*EE~~fhAA**><HH||NK@@)),uEEEr  c                    |t          | j        dz             |                                  |                     |          }|                     | j        ddd          }|                     |d|          }d}|                     d|          \  }}d}|                     |dddd	          \  }}| 	                    |g d
          }	d|d         i}
| 
                    |g d          }|8|d         r||
d<   nS|d         r|d         r
|	r|s||
d<   n9|r|	r||
d<   n/||
d<   n)|r|	r||
d<   n|d         r|d         r
|	r|s||
d<   n||
d<   |                     |g d          }d}|d         r+|                     |                     |
|                    }n|d         r|rX|	r+|                     |                     |
|                    }n|                     |                     |
|                    }nv|	r+|                     |                     |
|                    }nI|                     |                     |
|                    }n|d         r|rV|	r*|                     |                     |
|                    }n|                     |                     |
|                    }n|                     |                     |
|                    }n|dk    s||ra|r*|                     |                     |
|                    }n^|dk    rd|
d<   |                     |                     |
|                    }n)|                     |                     |
|                    }|                     ||          S )a  
        cancels an open order

        https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-order-trade
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-Order
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Cancel-Order
        https://developers.binance.com/docs/derivatives/option/trade/Cancel-Option-Order
        https://developers.binance.com/docs/margin_trading/trade/Margin-Account-Cancel-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-UM-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-CM-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-UM-Conditional-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-CM-Conditional-Order
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-Order
        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-Algo-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 argumentrb   r  rY   r  r  r  Frp  r  rO   )r  r  r  r  r]   r  r  r[   r  r  r  r  r  ry  )r  r  r  r  r  rw  rq  r  r  rZ   ri  Trg  )r5   rO   r  r  r  r  r  r  r  rr  r  r  eapiPrivateDeleteOrderr  papiDeleteUmConditionalOrderpapiDeleteUmOrderfapiPrivateDeleteAlgoOrderfapiPrivateDeleteOrderpapiDeleteCmConditionalOrderpapiDeleteCmOrderdapiPrivateDeleteOrderpapiDeleteMarginOrdersapiDeleteMarginOrderprivateDeleteOrderr  )r  rO   r  r  r  r  r  rf  r  rC  r  r  r  s                r  cancel_orderzbinance.cancel_order  sI   . >#DG.Y$YZZZV$$((}mU[\\<<
!??vVV
F $($C$CFM[actv{$|$|!6((1S1S1STTfTl
 **6  4A  4A  4A  B  B$h A+8((! AfVn A AO` A*7''$ A A5BG1223@G/00  (] ((*%%! (fVn ( (O` ($&!!%'	"6  $[  $[  $[  \  \( 	M224;;w3O3OPPHHH 	M  	Y  T#@@WV\A]A]^^HH#55dkk'66R6RSSHH  Y#>>t{{7TZ?[?[\\HH#::4;;wPV;W;WXXHHI 	M  U  T#@@WV\A]A]^^HH#55dkk'66R6RSSHH66t{{7F7S7STThJ$:?P$:  T55dkk'66R6RSS++,0GL)55dkk'66R6RSS..t{{7F/K/KLLH&111r  c                 F   |t          | j        dz             |                                  |                     |          }d|d         i}d}|                     |dddd          \  }}|                     |g d	          }|                     |d
|d
                   }|                     |g d          }d}|                     d|          \  }}d}	|d         r+| 	                    | 
                    ||                    }	n|d         r|rX|r+|                     | 
                    ||                    }	n|                     | 
                    ||                    }	nv|r+|                     | 
                    ||                    }	nI|                     | 
                    ||                    }	n|d         r|rV|r*|                     | 
                    ||                    }	n|                     | 
                    ||                    }	n|                     | 
                    ||                    }	n|dk    s||ra|r*|                     | 
                    ||                    }	n^|dk    rd|d<   |                     | 
                    ||                    }	n)|                     | 
                    ||                    }	t+          |	t,                    r|                     |	|          S |                     d|	i          gS )a  
        cancel all open orders in a market

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

        :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  rO   ra   r  r  Frp  r  r  r]   r  r  rZ   ri  Trg  r  )r5   rO   r  r  r  rr  r  r  r  eapiPrivateDeleteAllOpenOrdersr  $papiDeleteUmConditionalAllOpenOrderspapiDeleteUmAllOpenOrdersfapiPrivateDeleteAlgoOpenOrdersfapiPrivateDeleteAllOpenOrders$papiDeleteCmConditionalAllOpenOrderspapiDeleteCmAllOpenOrdersdapiPrivateDeleteAllOpenOrderspapiDeleteMarginAllOpenOrderssapiDeleteMarginOpenOrdersprivateDeleteOpenOrdersr  rD  r  r  )
r  r  r  r  r  r  rC  r  rf  r  s
             r  cancel_all_orderszbinance.cancel_all_orders	  sx   . >#DG.]$]^^^V$$fTl
 !$($C$CFL]_egxz  %A  %A!6((1S1S1STTv??6#M#M#MNN
!??@QSYZZ
F( c	R::4;;wPV;W;WXXHH H [	R  a  	\#HHU\^dIeIeffHH  $==dkk'SY>Z>Z[[HH ! 	a#CCDKKPWY_D`D`aaHH  $BB4;;wX^C_C_``HH I 8	R  ]  	\#HHU\^dIeIeffHH  $==dkk'SY>Z>Z[[HH  >>t{{7TZ?[?[\\ hJ$:?P$:  Y==dkk'SY>Z>Z[[++,0GL)::4;;wPV;W;WXX0 33DKK4P4PQQH, h%% 	$$Xv666 H!   r  idsc                 D   |t          | j        dz             |                                  |                     |          }|d         st	          | j        dz             d|d         i}|                     |dd          }||                     |dg          }||d<   n||d	<   d}|d
         r*|                     |                     ||                    }n1|d         r)| 	                    |                     ||                    }| 
                    ||          S )aR  
        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
        :param str[] [params.clientOrderIds]: alternative to ids, array of client order ids

 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.r  rO   origClientOrderIdListclientOrderIdsorderidlistr  r  )r5   rO   r  r  r6   rF  r  fapiPrivateDeleteBatchOrdersr  dapiPrivateDeleteBatchOrdersr  )r  r  r  r  r  r  r  r  s           r  cancel_orderszbinance.cancel_orders  sE   " >#DG.Z$Z[[[V$$j! 	\TW'ZZ[[[fTl
 !% 0 09PRb c c ,YYv(8'9::F/DG+,,%(GM"( 	W88Wf9U9UVVHHI 	W88Wf9U9UVVHH   6222r  c           	         |t          | j        dz             |                                  |                     |          }|                     |d|d                   }|                     |d          }|dk    rt          | j        dz             d|i}|                     ||||                     ||                    S )a  
        fetch all the trades made from a single order

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

        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Nz. fetchOrderTrades() requires a symbol argumentr  rY   z. fetchOrderTrades() supports spot markets onlyry  )	r5   rO   r  r  r  r  r@   fetch_my_tradesr  )	r  rO   r  rC  r  r  r  r  r  s	            r  fetch_order_tradeszbinance.fetch_order_trades  s      >#DG.^$^___V$$v??66**6>>tw)YYZZZr
 ##FE5$++gv:V:VWWWr  c                 r   |                                   d}|                     |dd          \  }}|r|                     d||||          S i }d}d}d}	| |                     |          }|d         |d<   |                     d||          \  }}|                     |dd          }
|V|}||d	<   |                                 }d
}||z
  |k    r0|
.|d         r&|                     ||          }
t          |
|          }
|
|
|d<   | 	                    |ddg          }|#|dk    s|d         rt          |d          }||d<   d}|dk    r+| 
                    |                     ||                    }n|t          | j        dz             |                     d|          \  }	}d}|                     |dddd          \  }}|dk    s|dk    r|r+|                     |                     ||                    }n"|dk    s|	5|	dk    rd|d<   |                     |                     ||                    }n|                     |                     ||                    }n|d         rV|r*|                     |                     ||                    }n|                     |                     ||                    }n]|d         rU|r*|                     |                     ||                    }n)|                     |                     ||                    }|                     ||||          S )aR  
        fetch all trades made by the user

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

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch trades for a portfolio margin account
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Fr   rE  NrO   r  rF  rK  rJ  i $r  r]   r  rV  r  z+ fetchMyTrades() requires a symbol argumentr  r  rY   rZ   ri  Trg  r  )r  r  r  r  r  r  r  rN  r  r  eapiPrivateGetUserTradesr  r5   rO   r  r  papiGetMarginMyTradessapiGetMarginMyTradesprivateGetMyTradespapiGetUmUserTradesfapiPrivateGetUserTradespapiGetCmUserTradesdapiPrivateGetUserTradesr  )r  r  rC  r  r  rE  r  r  r  rf  rK  rJ  currentTimestamponeWeekr  r  s                   r  r  zbinance.fetch_my_trades  s   * 	88R\]]& 	d44_feUZ\bccc
[[((F &tGH99/6SYZZf%%fgyAAI#,GK   $0022-G 9,88O)9O"hhy'::G!'+;<<G!(GIYYv	7';<<F  VJ%7 E4(($GG844T[[&5Q5QRRHH~'2_(_```!%!C!COU[!\!\J $(,(G(GP_agiz  }B  )C  )C%vv~~!1!1$ U#99$++gv:V:VWWHHh&&J,B!Z//04-#99$++gv:V:VWWHH#66t{{7F7S7STTHH! 	[$ [#77GV8T8TUUHH#<<T[[RX=Y=YZZHH	" [$ [#77GV8T8TUUHH#<<T[[RX=Y=YZZHD   65%@@@r  c                    |                                   i }|||d<   |                     |d          |d<   |                     |d          }|                     |d          }|||d<   |                     |                     ||                    }|                     |dg           }|                     |dd	          }	g }
t          d	|	          D ]e}|                     ||         d
g           }t          d	t          |                    D ](}d||         d<   |

                    ||                    )f|                     |
d||          }|                     |||          S )aS  
        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>`
        NrJ      X rK  r  accountTypeuserAssetDribbletsr  r   userAssetDribbletDetailsTrc  )r  rN  safe_string_upperr  sapiGetAssetDribbletr  r  r  r  r  r  r  r  )r  r  rC  r  r  r  r  r  r'  rowsr  r  logsr1  rX  s                  r  fetch_my_dust_tradeszbinance.fetch_my_dust_trades  s   & 	#(GK !%%!<!<GI,,VV<<66**"%0GM",,T[[&-I-IJJ< ..+?DD  7A66q$ 	% 	%A>>'!*.H"MMD1c$ii(( % %)-Q&DG$$$$% ""4ue<<))&%???r  c                 X   |                      |d          }|                     |d          }|                      |d          }|                     |          }|                     d          }|d         }|dz   |z   }	d}
|	| j        v rd}
|                      |d	          }||                     |          d
}d }d }d }d }|
r1|	}|                      |d          }|                      |d          }d}n6|dz   |z   }|                      |d          }|                      |d          }d}d }||rt          j        ||          }d }|                     |          }|                     |          }|                     |          }d }d }|||                     |          ||||||||||dS )NtransIdoperateTime	fromAssetr  r  r  FTserviceChargeAmountrr  r,  transferedAmountr  rn  rm  )rO   r  r  r  rs  r  r}  rl  r  r  r,  r  r  )	r  r  r  rr  r  r  rJ   
string_divr  )r  ra  r  ry  r  r  tradedCurrencybnbearnedCurrencyapplicantSymboltradedCurrencyIsQuotefeeCostStringr  r  r  
costStringrl  r  rO   r  r  r,  r  r}  s                           r  r~  zbinance.parse_dust_trade3  s    ""5)44%%e];;	%%e[99
00<<mmE""V(3.? %dl**$(!((0EFF&%%m44
 
 
  		$F++E3EFFL))%::JDD#c)N:F++E8<<L))%1CDDJD! K%0\JJ""<00!!+..  ,,"Y//(
 
 	
r  r  c                    |                                   d}|                     |dd          \  }}|r|                     d||||          S d}d}i }|                     | j        di           }	|                     |dd          }
|                     |d          }|                     |d          }|                     |d          }|
s||	v rk||                     |          }d	|d
<   |||d<   |||d<   | 	                    | 
                    ||                    }|                     |dg           }n| |                     |          }|d         |d<   |2||d<   |                     |d          }|t          ||          }||d<   |||d<   |                     | 
                    ||                    }t          d	t!          |                    D ]}d||         d<   |                     ||||          S )a   
        fetch all deposits made to an account

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

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

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

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

 Y//
 w
 w
 
 4
 3
 S
 t
 D
 f
 
  f!
" w#
$ !)
 
 
 	
r  c                 8    ddi}|                      |||          S )N	CONFIRMEDr
  r  r  s      r  parse_transfer_statuszbinance.parse_transfer_status   s(    
 &&999r  r   c           
         |                      |dd          }|                      |dd          }|                     ||          }|                     |d          }|                     |d          }d }d }	|                     | j        di           }
|o|                    d          }|                     |d	          }|                     |d
          }	|                     |
||          }|                     |
|	|	          }	|                     |d          }|Z|                     |di           }|                     |di           }|                     |d          }|                     |d          }	| 	                    |dd          }| 
                    |                     |d                    }||||                     |          ||||	|d	S )NtranIdtransactionIdr  rr  r  r  rV  rH  r   r#  
walletType	payerInforeceiverInfo	accountIdr  transactionTimer`  )	r  rO   r  r  rr  r  fromAccount	toAccountr`  )r  r  r   r  r$  r  r  r  r  r  r4  r  )r  r   rr  rO   r  r  r  r  r=  r>  rV  r\  r8  payerreceiverr  r`  s                    r  parse_transferzbinance.parse_transfer   s   F (ODD''':FF
&&z8<<!!(H55&11	~~dlNBGGJJsOOE//%33Kq11I**<kRRK((y)LLI&&x>>
!NN8["==E~~hCCH**5+>>K((;??I''+?PQQ	++D,<,<Xx,P,PQQ"Y//&"

 

 
	
r  c           
      b   |                      |d          }|                      |d          }|                     |d          }||                     ||d d          |                     |          ||                     |          |                      |d          |                     |d          dS )Nr  r  rQ  r[   r6  r{  )r  r  r  r  r  rO   r  )r  r  r  r  r  r   )r  r{  r  r  r  r  s         r  parse_incomezbinance.parse_incomec!  s     ##FH55%%fg66
%%ff55	&&xvFF++J77"Y//""6844&&vx88
 
 	
r  r=  r>  c                 *   |                                   |                     |          }|d         |                     ||          d}|                     |d          |d<   |                     |d          }|d         |                     |d          }d}	|+|                     |          }	|                     |d          }|                     |                                          }
|                     |                                          }d}|	|	d         }|
dk    r|t          | j	        dz   |z             |dk    r|t          | j	        dz   |z             | 
                    | j        d	i           }|
|v}||v}|r|	|
}|r|	|}|s|r|
d
k    p|
dk    }|d
k    p|dk    }|
dk    }|dk    }|
dk    p|dk    }|
dk    p|dk    }|p|p|p|}|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<   |                     |                     ||                    }|                     ||          S )a  
        transfer currency internally between wallets on the same account

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

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

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

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

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

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

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

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

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

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

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

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

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

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch trading fees in a portfolio margin account
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a `fee structure <https://docs.ccxt.com/?id=fee-structure>`
        r  Nr   r  r  Fr  rO   r   )r  r  r  r  r  r  papiGetUmCommissionRater  fapiPrivateGetCommissionRatepapiGetCmCommissionRatedapiPrivateGetCommissionRatesapiGetAssetTradeFeer  rD  r$  r{  )r  r  r  r  r  r  r  isLinear	isInverser  r  r  s               r  fetch_trading_feezbinance.fetch_trading_fee#  s     	V$$f~99:KVU[\\ $($C$CFL]_egxz  %A  %A!6>>$00OOD'22	fTl
  	O  [77GV8T8TUU<<T[[RX=Y=YZZ 	O  [77GV8T8TUU<<T[[RX=Y=YZZ00Wf1M1MNNH( dD!! 	/>>$2..D%%dF333r  c                 n   |                                   d}|                     dd|          \  }}d}|                     dd|d          \  }}|dk    p|dk    }|                     ||          }|                     ||          }d}|r|                     |          }n/|r|                     |          }n|r|                     |          }|rLi }t          dt          |                    D ]*}	| 
                    ||	                   }
|
d         }|
||<   +|S |rt          | j                                                  }i }|                     |d          }| j        d         d	         d
         }|d         |         d         }|d         |         d         }t          dt          |                    D ]+}	||	         }| j        |         }|d         rd|i|||d||<   ,|S |rt          | j                                                  }i }|                     |d          }| j        d         d	         d
         }|d         |         d         }|d         |         d         }t          dt          |                    D ]+}	||	         }| j        |         }|d         rd|i|||d||<   ,|S dS )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  rY   rZ   r   r  feeTierr  r  r  r#  r  )r  r  r  r  r  )r  r  r  r  r  r  fapiPrivateGetAccountConfigr  r  r  r{  rD  r  rE  r  r  )r  r  r  r  isSpotOrMarginr  r  r  r+  r  r  r  r<  r  feeTiersr  r  r  s                     r  fetch_trading_feeszbinance.fetch_trading_fees$  s2    	99:LdTZ[[f99:LdTZ\dee&.?dh.>>>$00OOD'22	 	:0088HH 	:77??HH 	:11&99Hb  Z	 F1c(mm,, % %,,Xa[99X!$vM E	, 4<,,..//GF'')<<Gy*95g>HW%g.q1EW%g.q1E1c'll++   f-(#  &w! #)!&!&& &F6N M 	 4<,,..//GF'')<<Gy+I6w?HW%g.q1EW%g.q1E1c'll++   f-)$  &w! #)!&!&& &F6N Mtr  c                 0   |dk     s|dk    rt          | j        dz             |                                  |                     |          }|d         ||d}|                     |                     ||                    }|                     ||          S )u  
 @ignore
        transfer between futures account

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

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

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

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

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

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

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

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

 L
 #$8
 
 Y//
 ;
 
 t||K88
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 
 	
r  c           	         |                      |d          }|                      |dg           }i }t          dt          |                    D ]|}||         }|                     |d          }|                     |          }	|                     |d          }
|                     |d          }t          j        |
|          |
d||	<   }g }t          dt          |                    D ]}||         }|                     |d          }|                     |d d d	          }|d
         r|d         n|d         }	|                     |d          }|dk    o|dk    }|r|r^|	|v rZ|                     | 	                    |||	         d         ||	         d         d          |          }|
                    |           |S )N	positionsr  r   r  crossWalletBalance
crossUnPnl)crossMarginr  r  r  r  r  r  maintMarginr  z
0.00000000r  )r  r  r  r  r  rJ   r  r  parse_account_positionr  r  )r  rx  filterClosedr  r  r  r  r,  r  r  r  r  r+  r  r  r  maintenanceMarginisPositionOpenparseds                      r  parse_account_positionszbinance.parse_account_positions%  s   NN7K88	266q#f++&& 		 		A1IE))%99J**:66D!%!1!1%9M!N!N))%>>J&12DjQQ&8 HTNN q#i..)) 	* 	*A |H''(;;H%%hdJGGF&,X&6J6'??F6ND $ 0 0= I I/36_=NR^=^N *> *8##!88X'/~m'D.6tn=Q.RP P : :    F MM&)))r  c           
         |                      |d          }|                     ||d d          }|                      |d          }|                      |d          }|t          |          nd }|                      |d          }|                     |          }d }	|Yt	          j        d|d          }	|                     d|z            }
|
s)t	          j        t	          j        |	d          dd          }	d	|v }|                      |d
          }|                     |          }|                      |d          }|                     |          }|                     |d	d          }t	          j	        |          }|                     |          }|                      |d          }t	          j	        |          }||t	          j
        t	          j
        ||          |          }|                      |d          }t	          j        ||          }t	          j        t	          j        |d          dd          }|                     |          }|                     | j        di           }|                     ||g           }d }t          dt          |                    D ]/}||         }t	          j        ||d                   r n	|d         }0|                     |          }|                      |d          }|                     |          }|                     |d          } | dk    rd } |                     |d          }!|!,|                      |d          }"t	          j        |"d           }!d }#d }$d }%|!r.d}#|                      |d          }%t	          j        |%|          }$n.d}#|                      |d          }%|                      |d          }$|                     |$          }&d }'d }(d })d }*d }+|                     |d          },|                     |,          }-t	          j        |d          rd }nt	          j        |d          rdnd}(|                     t	          j        t	          j        t	          j        ||$          d          dd                    }'|                     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          }*|                     |                      |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|                     |9          }+|                      |d&          }:|:d'k    };i d(|d)d d|d*| d+|                     |           d|d,|                     |	          d-|d.|d|d	|d|                     |          d/|d0|d|,d1|'d2|+d |&|#|(|;|)d3S )4Nr  r  r  r  rd  r  rV  1e-8r  r  
entryPricenotionalValuepositionAmtr  z0.5r   leverageBracketsr#  unrealizedProfitr  ri  isolatedMarginr  isolatedWalletr  r  r  shortlong5e-5r  rO  ru  r  r  z5e-r  r  BOTHr  rO   r  r  initialMarginPercentager  maintenanceMarginPercentageunrealizedPnl	contractsmarginRatioliquidationPrice)r  
collateralrf  rl  rn  r  )r  r  intr  rJ   r  is_round_numberr  r  
string_absr  r$  r  r  r  r  	string_ltr  r  r!  r  r  string_equals
string_subprecision_from_stringr  r  )<r  r  r  r  r  leverageStringr  initialMarginStringr  initialMarginPercentageStringrationalusdmmaintenanceMarginStringr  entryPriceStringr  notionalStringnotionalStringAbsr  contractsStringcontractsStringAbsentryNotionalcontractSizeNewr  r  r|  !maintenanceMarginPercentageStringr  bracketr  unrealizedPnlStringr  r  ri  isolatedMarginRawrf  collateralStringwalletBalancer  r  rl  r  liquidationPriceStringRawr  r  contractSizeString(onePlusMaintenanceMarginPercentageStringentryPriceSignStringleftSide	rightSiderY  ro  pricePrecisionPlusOnepricePrecisionPlusOneStringrounderrounderStringliquidationPriceRoundedStringtruncatedLiquidationPricer  rn  s<                                                               r  r  zbinance.parse_account_position%  s   p ##Hh77!!(FD*EE!!&(33))(J??+9+E3~&&&D"..xII))*=>>(,%%,3,>sNTU,V,V)++D8O<<H F070B7CUVsu{C|C|  B  DE  1F  1F-h&"&"2"28]"K"K --.EFF++HlCC&&'788
++Hj/RR#.~>>$$%677**8]CC$/@@"#.w/A.Re/f/fhxyyM"..v~FFO%0PPO!(!3G4FX]4^4^`cef!g!g%%&899	>>$,8JBOO..)962FF,0)q#o..// 	; 	;A%a(G !2GAJ?? 07
--&*&7&78Y&Z&Z#"..x9KLL))*=>>%%h==	>>I>>(J77 $ 0 0;K L L",->DDDH
 	I#J ,,X7GHHM&1-ATUU J ,,X7KLLM#//-HH&&'788

$(!v~>>!22<@@ 55 4	LJJ%/DDP77&D++G,>w?QRYRde|  O  SP  SP  RX  @Y  @Y  [^  `a  -b  -b  c  cK**7+=g>PQdfy{|>}>}  @E  ,F  ,F  G  GJ !T <@8'7$7???F?QRUWx?y?y<<?F?QRVXy?z?z<+2+=dDX+Y+Y("-mW=OPb  eM  >N  >N  O  O#./CEmnn	,3,>x,S,S)) <@8'7$7???F?QRUWx?y?y<<?F?QRVXy?z?z<+2+=dDX+Y+Y()*<>PQQ"-d4\]]#.w/A'BTUXZnBoBoqu/v/v  yF  G  G	,3,>x,S,S)!778H8HP[I\^e8f8fggN$2Q$6!*-.C*D*D'e&AABBGLLM,3,>}Ng,h,h)(/(:;XZ]_m(n(n%(+s22 -1)#001JKK''.AA'
H
$
 f
 	

 Y//
 ]
 &t'8'89V'W'W
  !2
 *+F
 *
 
 )).99
 ]
 
 L
  ;!
"  0#
$ $$$/
 
 
 	
r  c                 h   |                      |d          }|                     ||d d          }|                      |d          }|                      |d          }|                     | j        di           }|                     ||g           }|                     |dd          }t          j        |          }	d }
t          dt          |                    D ]/}||         }t          j
        |	|d                   r n	|d         }
0|                     |	          }t          j        |                      |d	                    }|                     |          }|                      |d
          }|                     |          }|                     |                      |d                    }|                     |          }d }|                      |d          }||t          j        |d          rdnd}d }t          j        |d          rd}nt          j
        |d          rd}|                      |d          }|                     |          }|                     |d          }|                     |          }d|v }|dk    r|                     |di           }|                      |d          }|                     |dd          }|d u o|d u }|s|rd } |}!|dk    r+t          j        d|
          } t          j        d|!          }!nt          j        d|
          } t          j        ||           }"t          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        | |                    }%|                     |                      |d                    }&|&)t          j        t          j        |#|%          d|&          }n|                      |d          }|dn|}|                     |          }'|                     |                     |                      |d                              }(|                     |d          })|)dk    rd })|                     |
          }*t          j        |
|	          }+|+|                      |d          }+|                     |+          },d }-d }.|                      |d          }/|/t/          |/          }0|                     d|0z            }1t          j        d|/d          }.|1st          j        |.d           }.t          j        |	|.          }2t          j        |2dd          }-nA|                      |d!          }-t          j        |-d          }2t          j        |2|	d          }.d }3d }4t          j        |d          s|                     t          j        t          j        t          j        |+|          d"          dd#                    }3|                     t          j        t          j        ||-d#          d$                    }4|                      |d%          }5|5d&k    }6|                     i d'|d(d d|d)|d|d*|d|                     |/          d|d+|'d|d|(d|d,|)d!|                     |-          d-|                     |.          d.|,d/|*|3|                     |)          ||||6|4d d d0	          S )1Nr  r  r  r  r  r  r   r#  r  unRealizedProfitr  r  r  r  ri  r  r  r  r  r  r  r  r  rd  ru  r  r  r  r  rV  r  r  r  r  r  rO  r  r  r  rO   r  r  r  r  r  r  r  )	r  r  rf  r  rl  rn  r  rj  rk  )r  r  r$  r  r  r  rJ   r  r  r  r  r  r#  r!  r  r  r  r  r  r  r  r  r  r  r  r  safe_positionr  )7r  r  r  r  r  isolatedMarginStringr  r|  r  r  r  r  r  r  contractsAbsr  r  r  liquidationPriceStringr  r  rf  rl  r  r  r  r  r  r  basePrecisionValuequotePrecisionValueprecisionIsUndefinedr  r  innerr  rr  r  basePrecisionr  r  r  r  r  r  r  r  r  r  r  	unroundedr  r  r  rn  s7                                                          r  parse_position_riskzbinance.parse_position_risk&  s   l ##Hh77!!(FD*EE!!&(33#//:JKK>>$,8JBOO..)962FF++Hj/RR#.~>>,0)q#o..// 	; 	;A%a(G !2GAJ?? 07
--$$%677)$*:*:8]*S*STT%%l33	"..x9KLL))*=>>!%0@0@K]0^0^!_!_,,-CDD%%h==
"6"B$+$56JC$P$P`V`J^S11 	DD~s33 	D++HlCC&&'788
v~>>!22<@@(  v{B??I!%!1!1)V!D!D"&"4"4Y"Q"Q$6$$>#aEX\`E` ' { {?C<+;(wCJCUVY[|C}C}@/6/A$H\/]/],,CJCUVZ\}C~C~@#./EGoppE&1%9MNNH%)%?%?@R@RS\^egn@o@o%p%pN%1+2+=g>PQY[g>h>hjmo}+~+~( @D<+;(wCJCUVY[|C}C}@@CJCUVZ\}C~C~@/6/A$H\/]/],&1,@RSSH ' 273EcK_3`3`bibt  v^  `v  cw  cw  !x  !xI$($>$>t?O?OPY[a?b?b$c$cM$0+2+=g>PQY[d>e>egjly+z+z(#//:JKK#3#;33BR&&'788
%%dnnT5E5EhP[5\5\&]&]^^	%%h==	>>I&*&7&78Y&Z&Z#")"45VXi"j"j"*&*&6&6x&O&O# --.EFF"(,%))(J??%>**H++D8O<<H,3,>sNTU,V,V) j070BC`bh0i0i-*+<>[\\I")"4YQ"G"G"&"2"28_"M"M*+>DDI,3,>yJ[]^,_,_)
$%5s;; 	G++G,>w?QRYRde|  O  SP  SP  RX  @Y  @Y  [^  `a  -b  -b  c  cK**7+=g>PQdfy{|>}>}  @E  ,F  ,F  G  GJ''.AA'!! #
H#
$#
 f#
 	#

 L#
 ]#
 )).99#
  0#
 *#
 #
 #
 *#
 #
 T../BCC#
 &t'8'89V'W'W#
   !2!#
" *+F##
$ 'Y//$$$!#5#
 #
 #
   	r  c                    |                                   |                     | j        d          }||r,|                     | j        dd          }|                     |d|          }|                     |d          }d }|                     dd |d          \  }}d }|                     |dddd	          \  }}d }	|                     ||          r.|r|                     |          }	nq| 	                    |          }	n[| 
                    ||          r.|r|                     |          }	n-|                     |          }	nt          | j        d
z             |                                 | j        d<   t!          dt#          |	                    D ]}
|	|
         }|                     |d          }|                     |d d d          }|                     |dg           }g }t!          dt#          |                    D ]N}||         }|                     |dd          }|                     |d          }|                    ||g           O|| j        d         |<   | j        d         S )Nr  r  r\   r  loadLeverageBracketsr  r  r  FzB loadLeverageBrackets() supports linear and inverse contracts onlyr   r  r  bracketsnotionalFloorqtyFloormaintMarginRatio)r  r$  r  r  r  r  r  r  papiGetUmLeverageBracketfapiPrivateGetLeverageBracketr  papiGetCmLeverageBracketdapiPrivateV2GetLeverageBracketr@   rO   create_safe_dictionaryr  r  r  r  r  r  )r  reloadr  r  r  r  r  r  r  r  r  r,  r  r  r  r+  r1  r  
floorValuer  s                       r  load_leverage_bracketszbinance.load_leverage_brackets'  s     >>$,8JKK$&$**4<QQK##FFK@@DIIff--EG"==>TVZ\bdlmmOGV $(,(G(GPfhn  qB  DI  )J  )J%vH~~dG,, s$ I#<<UCCHH#AA%HHHHw// s$ K#<<UCCHH#CCEJJHH"47-q#qrrr/3/J/J/L/LDL+,1c(mm,, B B ++E8<<))(D$
KK>>%R@@q#h--00 M MA&qkG!%!3!3G_j!Y!YJ262B2B7L^2_2_/MM:/J"KLLLL;A/088|.//r  c                 H   |                                   d}|                     dd|          \  }}d}|                     dd|d          \  }}d}|                     |dddd          \  }}d}|                     ||          r.|r|                     |          }nq|                     |          }n[|                     ||          r.|r|                     |          }n-| 	                    |          }nt          | j        dz             |                     ||d          S )	aF  
        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  r  Fz@ fetchLeverageTiers() supports linear and inverse contracts onlyr  )r  r  r  r  r  r  r  r  r	  r
  r@   rO   parse_leverage_tiers)r  r<  r  r  r  r  r  s          r  fetch_leverage_tierszbinance.fetch_leverage_tiers'  s^    	99:NPTV\]]f99:NPTV\^fgg $($C$CFL`bhj{  ~C  %D  %D!6>>$(( 	m  F88@@==fEE__T7++ 	m  H88@@??GGtw)kklllN ((7HEEEr  c                     |                      |d          }|                     ||dd          }|                     |dg           }g }t          dt	          |                    D ]}||         }|                    |                     |d          |                     ||          |d         |                     |dd	          |                     |d
d          |                     |d          |                     |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  rr  r  r  maintenanceMarginRatemaxLeverager  )	r  r  r  r  r  r  r   r  r  )r  r  r  r  r  r  r1  r  s           r  parse_market_leverage_tiersz#binance.parse_market_leverage_tiers'  s"   , ##D(33!!(FD*EE>>$
B77q#h--(( 	 	AqkGLL(()<<**8V<<"7O#11'?JWW#11'=(SS)-)9)9'CU)V)V#//9JKK	 	 	 	 	 	 r  c                 0   |                                   |                     |          }|d         st          | j        dz             d|d         i}|                     |                     ||                    }|                     |d         |          S )a  
        fetch data on an open position

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

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

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

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `position structures <https://docs.ccxt.com/?id=position-structure>`
        Nr#  zD fetchPositions() symbols argument cannot contain more than 1 symbolr   rO   r  F)r  r  r  rD  r  r6   rO   r  r  r  r  r  r  filter_by_array_positions)
r  r<  r  r  r  r  symbolsLengthr  r+  r  s
             r  fetch_option_positionszbinance.fetch_option_positionsN(  s7    	%%g..F'4(( ! #G 1$$$TW/u%uvvv  [[((F &tGH..t{{7F/K/KLL0 q#h--(( 	K 	KAMM$44Xa[&IIJJJJ--fhOOOr  r  c           
         |                      |d          }|                     ||d d          }|d         }|                     |d          }|                      |d          }|dk    rt          j        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 d          S )Nr  r[   rl  rf  r  ru  rQ  r  rO   r  r  r  	markValuer  positionCostr  unrealizedPNLr  r  r  r  rn  r  r  r  )r  r  r  r  rf  r  )
r  r  r  rJ   r  r  r  r   r  r  )r  r  r  r  r  rl  rf  r  s           r  r  zbinance.parse_option_position(  s   , ##Hh77!!(FD&AA!%%h77##Hj996>>)$99H%%h77	!! #
H#
$#
 f#
 $**8\BB	#

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

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

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param dict [params.params]: extra parameters specific to the exchange API endpoint
        :param str [params.method]: method name to call, "positionRisk", "account" or "option", default is "positionRisk"
        :param bool [params.useV2]: set to True if you want to use the obsolete endpoint, where some more additional fields were provided
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/?id=position-structure>`
        Nr   r  ry  rx  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@   rO   )r  r<  r  defaultMethodr  s        r  fetch_positionszbinance.fetch_positions(  s    "  $ = =fFVX` a av nnT\3CDDG $ 0 0?OQ_ ` ` .N**,,Wf===i''//@@@h&&..w???tw)ggjww  {G   G  H  H  Hr  c                 &   |,t          |t                    st          | j        dz             |                                  |                     d|           |                     | j        dd          }|                     |d|          }|                     |d          }d}| 	                    dd|d          \  }}d}| 
                    |dd	d
d          \  }}d}|                     ||          rc|r|                     |          }nd}|                     |ddd          \  }}|s|                     |          }nq|                     |          }n[|                     ||          r.|r|                     |          }n-|                     |          }nt'          | j        dz             d}	|                     |ddd          \  }	}|                     ||	          }
|                     |          }|                     |
d|d          S )a   
 @ignore
        fetch account positions

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

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

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

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

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

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch funding history for
        :param int [limit]: the maximum number of funding history structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest funding history entry
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch the funding history for a portfolio margin account
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a `funding history structure <https://docs.ccxt.com/?id=funding-history-structure>`
        N
incomeTypeFUNDING_FEErO   r  r[   z3 fetchFundingHistory() supports swap contracts onlyr   r  r  r  FrK  rJ  r  r  r\   r  zA fetchFundingHistory() supports linear and inverse contracts only)r  r  r@   rO   r  r  r~  r  r  r  r  r  papiGetUmIncomer  fapiPrivateGetIncomer  papiGetCmIncomedapiPrivateGetIncomeparse_incomes)r  r  rC  r  r  r  r  r  r  r  r  r  s               r  fetch_funding_historyzbinance.fetch_funding_history)  sO   $ 	-
 [[((F &tGH&> d"47-b#bccc99:OQWY_aijj $($C$CFLacik|  D  %E  %E!6229gvNN#(GK $GG((7Lm]eff<<66**>>$(( 	n  S//GV0L0LMM44T[[&5Q5QRR__T7++ 	n  S//GV0L0LMM44T[[&5Q5QRRtw)llmmm!!(FE5AAAr  r  c                    |t          | j        dz             |dk     s|dk    rt          | j        dz             |                                  |                     |          }|d         |d}d}|                     |dd	d
d          \  }}d}|d         rV|r*|                     |                     ||                    }n|                     |                     ||                    }nu|d         rV|r*| 	                    |                     ||                    }nA| 
                    |                     ||                    }nt          | j        dz             |S )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 125rO   )r  r  r   r  r  Fr  r  z9 setLeverage() supports linear and inverse contracts only)r5   rO   r6   r  r  r  papiPostUmLeverager  fapiPrivatePostLeveragepapiPostCmLeveragedapiPrivatePostLeverager@   )r  r  r  r  r  r  r  r  s           r  set_leveragezbinance.set_leverage5*  s    >#DG.Y$YZZZ qLLhnnTW'NNOOOV$$Tl 
 
 !$($C$CFM[actv{$|$|!6( 	f  V224;;w3O3OPP77GV8T8TUUI 	f  V224;;w3O3OPP77GV8T8TUUtw)ddeeer  rf  c                    |t          | j        dz             |                                }|dk    rd}|dk    r|dk    rt          | j        dz             |                                  |                     |          }|d         |d}d}	 |d	         r*|                     |                     ||                    }nI|d
         r*|                     |                     ||                    }nt          | j        dz             nT# t          $ rG}t          |t                    r&|                     | j        dd          }|r|ddd}n|Y d}~nd}~ww xY w|S )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CROSSEDrF  z, marginMode must be either isolated or crossrO   )r  r  r  r  z; setMarginMode() supports linear and inverse contracts onlyr  Fi2No need to change margin type.)r  r  )r5   rO   r  r6   r  r  fapiPrivatePostMarginTyper  dapiPrivatePostMarginTyper@   	Exceptionr  r9   r  r  )	r  rf  r  r  r  r  r  er  s	            r  set_margin_modezbinance.set_margin_modea*  s    >#DG.[$[\\\  %%''
  "J*$$:+B+BTW'UUVVVV$$Tl$
 
 	h l99$++gv:V:VWW	" l99$++gv:V:VWW"47-j#jkkk 	 	 	 !122 ,0NN4<Idfk,l,l), XG(-6VWWHH HHHH	 s   A;D 
E=EErn  c                    d}||                      |          }d}|                     d||          \  }}d}|                     d||          \  }}d}|                     |dddd          \  }}d}|rd}nd}d|i}	d}
|                     ||          rV|r*|                     |                     |	|                    }
n|                     |                     |	|                    }
n|                     ||          rV|r*| 	                    |                     |	|                    }
nA| 
                    |                     |	|                    }
nt          | j        d	z             |
S )
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
        Nr   r  r  FtruefalsedualSidePositionz= setPositionMode() supports linear and inverse contracts only)r  r  r  r  r  papiPostCmPositionSideDualr  dapiPrivatePostPositionSideDualr  papiPostUmPositionSideDualfapiPrivatePostPositionSideDualr6   rO   )r  rn  r  r  r  r  r  r  rR  r  r  s              r  set_position_modezbinance.set_position_mode*  s     [[((F99:KVU[\\f99:KVU[\\ $($C$CFL]_egxz  %A  %A!6 	'%& 0
 ??4)) 	h  ^::4;;wPV;W;WXX??GU[@\@\]]^^D'** 	h  ^::4;;wPV;W;WXX??GU[@\@\]]TW'ffggg r  c                    |                                   |                     d|           d}|                     dd|          \  }}d}|                     dd|d          \  }}d}|                     |dddd          \  }}d}|                     ||          r.|r|                     |          }nq|                     |          }n[|                     ||          r.|r| 	                    |          }n-| 
                    |          }nt          | j        dz             |                     |dg           }t          |t                    r|}|                     ||d	          S )
a  
        fetch the set leverage for all markets

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

        :param str[] [symbols]: a list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a list of `leverage structures <https://docs.ccxt.com/?id=leverage-structure>`
        FNr   r  r  r  z< fetchLeverages() supports linear and inverse contracts onlyr  r  )r  r  r  r  r  r  papiGetUmAccountfapiPrivateGetSymbolConfigr  r.  r  r@   rO   r  r  rD  parse_leverages)r  r<  r  r  r  r  r  	leveragess           r  fetch_leverageszbinance.fetch_leverages*  s    	##E622299:JDRXYYf99:JDRXZbcc $($C$CFL\^dfwy~$$!6>>$(( 	i  C0088::6BB__T7++ 	i  >008855f==tw)gghhhNN8["==	h%% 	! I##IwAAAr  c                    |                      |d          }|                     |d          }d }||rdnd}|                     |d          }|
|dk    rdnd}|                     |d          }d }d }	|                     |d          }
||dk    r|
}|
}	n|d	k    r|
}n|d
k    r|
}	||                     ||          |||	dS )Nr  ri  r  r  crossedr  r  bothr  r  )r  r  rf  longLeverageshortLeverage)r  r  r  r  r  )r  r  r  r  marginModeRawrf  marginTypeRawrl  ra  rb  leverageValues              r  parse_leveragezbinance.parse_leverage*  s
   ##Hh77x<<
$'4A'J..xFF$%2i%?%?jJ%%h??))(J??Ldfnn(L)MMV^^(LLW__)M&&x88$(*
 
 	
r  c                    |                                   |dn|                     |          }d}|                     d||          \  }}|dk    rt          | j        dz             i }||d         }|d         |d         z   |d<   |||d	<   |||d
<   |                     |                     ||                    }|                     ||          }	|                     |	d          }
| 	                    |
|||          S )a  
        fetches historical settlement records

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

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

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

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

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

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

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

        :param str [code]: unified currency code
        :param int [since]: timestamp in ms of the earliest ledger entry
        :param int [limit]: max number of ledger entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest ledger entry
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch the ledger for a portfolio margin account
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a `ledger structure <https://docs.ccxt.com/?id=ledger-entry-structure>`
        Fr   rE  NrJ  r  rF  rK  r  r  r]   r  rO   rr  z- fetchLedger() supports contract wallets only)r  r  r  rr  r  r  r  r  r  r{  r|  r  r  r9  r:  r  r;  r<  r@   rO   parse_ledger)r  r  rC  r  r  rE  r  r  rr  r  rF  r  r  s                r  fetch_ledgerzbinance.fetch_ledger+  s   ( 	88PZ[[& 	m44]D%QVX^`dfklll}}T**H99-vVVf99-vVV#(GK $GG!!&'22YYvw//F!&GI $($C$CFM[actv{$|$|!68((fEEE"*4.GJ..t{{7F/K/KLLHH^^D'** 	Z  S//GV0L0LMM44T[[&5Q5QRR__T7++ 	Z  S//GV0L0LMM44T[[&5Q5QRRtw)XXYYY:   8UEBBBr  itemc                    |                      |dd          }d }t          j        |d          rd}t          j        d|          }nd}|                     |d          }|                     ||          }|                     ||          }|                     |dd	          }|                      |d
d          }|                     ||                      |dd          |d d |                     |d          | 	                    |          || 
                    |          ||                     |          d d d d d|          S )Nr  r{  r  outru  inr  rs  rQ  r  r7  rO   r6  rx  )r  rO   	directionrx  referenceAccountreferenceIdr  rr  r  r  r  beforeafterr`  r  )r  rJ   	string_ler  r  r  safe_currencyr  safe_ledger_entryparse_ledger_entry_typer  r  )	r  r  rr  r  r  r  r  r  r  s	            r  r}  zbinance.parse_ledger_entryA,  s^   2 ##D(H==	VS)) 	I'f55FFI%%dG44
&&z8<<%%j(;;''lFCC	!!$==%%$$T4::" $++D)<<0066''//"Y//'
 '
  !  	r  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}|                      |||          S )NFEEr  r8  OPTIONS_PREMIUM_FEEPOSITION_LIMIT_INCREASE_FEECONTRACTra  REALIZED_PNLTRANSFERr   CROSS_COLLATERAL_TRANSFERINTERNAL_TRANSFERCOIN_SWAP_DEPOSITr  COIN_SWAP_WITHDRAWr  OPTIONS_SETTLE_PROFITrv  DELIVERED_SETTELMENTWELCOME_BONUScashbackCONTEST_REWARDCOMMISSION_REBATErebate
API_REBATEr  rp  )REFERRAL_KICKBACK
COMMISSIONr  )r  r  
ledgerTypes      r  r  zbinance.parse_ledger_entry_typex,  s   
5
5
 "5
 *5	

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

* 
D$777r  currencyCode
depositUrlc                    |d S d }|                      |          }|                     |di           }t          |                                          }t	          dt          |                    D ]i}||         }|                     ||         di           }	|                     |	d          }
|
*|                    |                     |
                    r|}j|S )NrW  r   r  contractAddressUrl)	rr  r$  rD  rE  r  r  r  
startswithget_base_domain_from_url)r  r  r  r3  rr  rW  networkCodesr  currentNetworkCoder  siteUrls              r  rf  z'binance.get_network_code_by_network_url,  s    4==..>>(J;;HMMOO,,q#l++,, 	1 	1A!-a>>(+=">KKD&&t-ABBG"z'<'<T=Z=Z[b=c=c'd'd"0r  r  c                     |d S |                     d          }|                     |d          }|d S |                     |d          }|d S |dz   |z   dz   S )Nr  r   r  z//)r  r  )r  r  urlPartsschemedomains        r  r  z binance.get_base_domain_from_url,  sm    ;499S>>!!(A..>4!!(A..>4}v%++r  r  GETc                 l   | j         }||d         vrt          | j        dz   |z   dz             | j         d         |         }|d|z   z  }|dk    r(| j        r
d| j        i}nt	          | j        dz             |dk    p|d	k    p|d
k    }	|	rE| j        r'| j        dd}|dk    r|                     |          }nt	          | j        dz             |dk    sV|dk    sP|dk    r|dk    sD|dk    s>|dk    s8|dk    s2|dk    s,|dk    s&|dk    s |dk    s|dk    s|dk    s|dk    rl|dk    re|                                  |                    d          dk    r9| j        r2| 	                    | j
        d           st          | j        d!z             |d"k    r|d#k    s|d$k    r|                     |d%          }
|
x|                    d          dk    p|dk    }|rd&nd'}|sd(nd)}|                     | j
        d*i           }|                     |||          }||                                 z   |d%<   d }|d+k    r|d"k    s|d,k    r|                     |d+          }|}|d"k    r|dk    rg }t          d-t!          |                    D ]}||         }|                     |d%          }
|
Qd(}|                     | j
        d*i           }|                     |d'|          }||                                 z   }
|
|d%<   |                    |           |                     |          }||d+<   |                     | j
        d.          }|                     d/|                                 i|          }|||d.<   |                     |d.          }|||d.<   |dk    r|d0k    r|                     |          }n|d+k    sR|                    d1          d-k    s9|d2k    s3|                    d3          d-k    s|                    d4          d-k    rE|d5k    r(|d+k    r!|                     |d6g           }|                     |d7d8g           }|                     |g d9          }d:|v r|                     |d:                   |d:<   |                     |          }t!          |          }t!          |          }|d-k    r!|d;z   d<z   d=                    |          z   d>z   }|d-k    rWg }t          d-|          D ]#}|                    d?||         z   d?z              $|d;z   d@z   d=                    |          z   d>z   }n+|                     |          }n|                     |          }d }| j                            dA          dk    rt!          | j                  dBk    r0|                     |                     || j        dC                    }n|                     |                     |                     |          | j        dD                    }nL|                      |                     |          |                     | j                  tB          j"                  }|dE|z   z  }d| j        i}|dk    s|d5k    r	|dF|z   z  }n%|}d|dG<   n|r|dF|                     |          z   z  }||||dHS )INr  z) does not have a testnet/sandbox URL for z
 endpointsr  rY  X-MBX-APIKEYz7 historicalTrades endpoint requires `apiKey` credentialrD  r  rF  z!application/x-www-form-urlencoded)r  Content-Typer  z5 userDataStream endpoint requires `apiKey` credentialr  r  r
  r   r  r  r  r   r   r  r  r  r  r  rP  ztestnet.binancefuture.comr  disableFuturesSandboxWarningz testnet/sandbox mode is not supported for futures anymore, please check the deprecation announcement https://t.me/ccxt_announcements/92 and consider using the demo trading instead.POSTrs  r  r  rY   r\   r  r  rT  r  PUTr   r  r  rB  zsub-accountrC  stakingzsimple-earnDELETEr  origclientorderidlistr  )r  r  r  r  &zorderidlist=%5Bz%2Cz%5Dz%22zorigclientorderidlist=%5BzPRIVATE KEYx   sha256ed25519z&signature=?r  )r  r  bodyheaders)#r   r@   rO   apiKeyr2   	urlencoder  r  r  r  r  r  r$  r  r  r  r  r  r!  r  r  r  urlencode_with_array_repeatrF  r  encode_uri_component	rawencoderZ  secretrsaeddsaencodehmachashlibr  )r  pathr  r  r  r  r  r   r  rD  r  r  r  r`  rT  r  r  r  checkedBatchOrdersr  
batchOrder
queryBatchdefaultRecvWindowextendedParamsr  r  r  orderidlistLengthorigclientorderidlistLengthnewClientOrderIds	signatures                                  r  signzbinance.sign,  s   ytE{""tw)TTWZZ]iijjjis#sTz%%%{ o"DK *$'4m*mnnn"22k8KkQUYjQj a	4{ 	m %)K$G  U??>>&11D)$'4k*klllYC=$8$8cVmmPTXgPgPgmpt|m|m|  CF  JR  CR  CR  X[  _g  Xg  Xg  mp  tA  mA  mA  GJ  N]  G]  G]  cf  jw  cw  cw  }@  DS  }S  }S  Y\  `o  Yo  Yo  ux  |D  uD  uD  HK  OU  HU  HU  Z^  bh  Zh  Zh++---455::@Y:cgcqcqrvr~  A_  d`  d`:"47  .e  $e  f  f  fdgoo4;;N;N#'#3#3F<N#O#O #+&)hhv&6&6&;&Osi?ON+9!GxJ5C V,I!^^DL(BGGF#//
INNH19DKKMM1IF-.E%%Vv-=-=6U??"nnV]CC%0"V##}(<(<)+&"1c+&6&677 	> 	>%0^
+/+;+;JHZ+[+[(+3(4I%)^^DL(B%O%OF'+'7'7)'T'TH/7$++--/G,=MJ'9:*11*===="ii(:;;
(2}% $ 1 1$, M M![[TZZ\\* N !,/@|,**6<@@J%/9|,vDL$8$888HH-''TYY}-E-E-J-JPTXpPpPpvzvv  AJ  wK  wK  OP  wP  wP  VZ  V_  V_  `m  Vn  Vn  rs  Vs  Vsh&&T]-B-B"&..PR"S"SK,0,<,<^Mdf}  @B  -C  -C)%)YY~  @A  @A  @A  &B  &BN>11373L3L^\dMe3f3fx0 NN>::E(+K(8(8%256K2L2L/(1,, %.? ?%**[BYBY Y\a a2Q66,.)!&q*E!F!F _ _A-44U=RST=U5UX]5]^^^^ %.I IEJJWhLiLi ilq q NN>::EE~66I{..33t{##c)) $ 9 9$((5$+W_:`:` a aII $ 9 9$**T[[QVEWEWY]Ydfo:p:p q qII IIdkk%&8&8$++dk:R:RT[Tbcc	')33EG %Vx%7%7sU{"*M'' 4sT^^F3333fdwOOOr  exactOrBroadc                    d }| j         | j         nd}|                    d|z   dz             s*|                    d          s|                    d          rd}n|                    d|z   dz             s*|                    d          s|                    d	          rd
}n|                    d|z   dz             s*|                    d          s|                    d          rd}n;|                    d|z   dz             rd}n|                    d|z   dz             rd}|3|                     | j        |i           }|                     ||i           S i S )Nzbinance.comzhttps://api.r  zhttps://demo-apizhttps://testnet.binance.visionrY   zhttps://dapi.zhttps://demo-dapiz&https://testnet.binancefuture.com/dapir  zhttps://fapi.zhttps://demo-fapiz&https://testnet.binancefuture.com/fapir  zhttps://eapi.r]   zhttps://papi.r  )hostnamer  r$  r  )r  r  r  r  r  exceptionsForMarketTypes         r  get_exceptions_by_urlzbinance.get_exceptions_by_url-  s   
%)]%>4==]>>.83c9:: 		+cnnM_>`>` 		+dgdrdr  tT  eU  eU 		+JJ^^Oh6<== 	+PcAdAd 	+hkhvhv  x`  ia  ia 	+"JJ^^Oh6<== 	+PcAdAd 	+hkhvhv  x`  ia  ia 	+!JJ^^Oh6<== 	+!JJ^^Oh6<== 	+*J!&*nnT_jRT&U&U#>>"9<LLL	r  reasonr  r  r  c
                    |dk    s|dk    r3t          | j        dz   t          |          z   dz   |z   dz   |z             |dk    r|                    d          dk    rt	          | j        dz   |z             |                    d          dk    rt	          | j        d	z   |z             |                    d
          dk    rt	          | j        dz   |z             |d S |                     |dd          }
|
sM|                     |d          }d }|3	 t          j        |          }n# t          $ r}d }Y d }~nd }~ww xY w||}|                     |d          }|| 
                    |                     |d          || j        dz   |z              | 
                    | j        d         || j        dz   |z              |                     |                     |d          || j        dz   |z              |                     | j        d         || j        dz   |z              |                     |d          }||dk    st          j        |d          rd S |dk    r'| j        d         rt          | j        dz   |z             | j        dz   |z   }|dk    rt#          |          | 
                    |                     |d          ||           | 
                    | j        d         ||           t%          |          |
st%          | j        dz   |z             t'          |t(                    rt+          |          }|dk    r|d         }|                     |d          }|c| 
                    |                     |d          || j        dz   |z              | 
                    | j        d         || j        dz   |z              d S )Ni  i  r  i  zPrice * QTY is zero or lessr   z- order cost = amount * price is zero or less r{  z5 order amount should be evenly divisible by lot size rw  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) r  Tr  r  r  r  r  r  r  r  rI  r#  )rB   rO   r  r  r<   r  r  r!  loadsrL  throw_exactly_matched_exceptionr  r  throw_broadly_matched_exceptionrJ   r  r  r9   r1   r  rD  r  )r  r  r  r  r  r  r  r  requestHeadersrequestBodyr  
messageNewparsedMessagerM  messageerrorfeedbackarrayLengthelement	errorCodes                       r  handle_errorszbinance.handle_errors1-  sk   CKKTS[[ 3T!:S!@6!IC!ORV!VWWW 3;;yy6771<<"47-\#\_c#cdddyy$$))"47-d#dgk#klllyy((A--"47  .a  $a  dh  $h  i  i  i4..9d;; 
	-))(E::J M%)$(Jz$:$:MM  ) ) )$(MMMMMM) !,,H""8U33001K1KCQX1Y1Y[bdhdknqdqt{d{|||001I7TXT[^aTadkTklll001K1KCQX1Y1Y[bdhdknqdqt{d{|||001I7TXT[^aTadkTklll  622 7#8#D#Dt   dl3X&Y $TWs]T%9:::w}t+H::: +8444001K1KCQX1Y1Y[`bjkkk001I5RZ[[[))) 	6# 4555h%% 	th--Ka"1+ ,,Wf==	(889S9STWY`9a9aclnrnux{n{  C  oC  D  D  D889QS\^b^ehk^knr^rsssts   D, ,
E6D==E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 rRd|v rN|d         }|d         }t          d	t          |                    D ] }||         }	||	d	         k    r
|	d
         c S !|                     |dd
          S )Nr-  r  rd  r  r=  poolIdrW  r  r   r#  r,  )r  r  r  )
r  r  r  r  r  configr  rW  r  r,  s
             r  calculate_rate_limiter_costz#binance.calculate_rate_limiter_costw-  s    6)9)9(##F""X-?-?*%%F""X-?-?*%%6!!6(9(97OEY'G1c'll++ $ $
E!H$$ 8OOO %vvq111r  c           	      \    |                      |||||||          }|dk    r
d| j        d<   |S )Nr  Tr  )fetch2r  )	r  r  r  r  r  r  r  r  r  s	            r  r  zbinance.request-  s<    ;;tS&&'4PP)BFDL>?r  c                    |                      | j        dd          }|dk    rd}|                      |d|          }|dk    s|dk    rt          | j        dz             |                                  |                     |          }|                     ||          }||d         |d}d }	d }
|d	         r2|d
         }
|                     |                     ||                    }	n1|d         }
| 	                    |                     ||                    }	|                     | 
                    |	|          d|
i          S )Nr  r\   rY   r  rZ   z@ add / reduce margin only supported with type future or deliveryrO   )r  r  r  r  r  r  r  )r  r  r@   rO   r  r  r  fapiPrivatePostPositionMarginr  dapiPrivatePostPositionMarginparse_margin_modification)r  r  r  addOrReducer  r  r  r  r  r  r  s              r  modify_margin_helperzbinance.modify_margin_helper-  sa   &&t|]HMM&  "K<<H$&..tw)kklllV$$))&&99Tl
 

 ( 	X'?D99$++gv:V:VWWHH&>D99$++gv:V:VWWH {{499(FKKDN
   	r  r  c                    |                      |d          }|                     |d          }|                     |d          }|                      |d          }|                     ||d d          }|d u }|dk    }||d         |dk    rdnd	d
|                     |d          |                     |d          d |s|rdnd||                     |          d
S )Nr  r  r  rQ  r[   r  r#  addreduceri  r  r  r
  r
  )
r  r  r  rf  r  r  r  r`  r  r  )r  r  r  r   r  )	r  r  r  rawTyper  r  r  noErrorCoder  s	            r  r  z!binance.parse_margin_modification-  s    0 ##D&11$$T622	##D(33%%dF33	!!(FD&AA4'u$X&%llEE$&&tX66$$T733&D+DddH"Y//
 
 	
r  c                 2    |                      ||d|          S )aF  
        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=margin-structure>`
        r  r  r  r  r  r  s       r  reduce_marginzbinance.reduce_margin-       ((FCCCr  c                 2    |                      ||d|          S )a,  
        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=margin-structure>`
        r#  r  r  s       r  
add_marginzbinance.add_margin-  r  r  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d          }|                     |          S )a  
        fetch the rate of interest to borrow a currency for margin trading

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        :param str symbol: unified market symbol, required for isolated margin
        :param str code: unified currency code of the currency to repay
        :param float amount: the amount to repay
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/?id=margin-loan-structure>`
        rO   TRUEr=  r  r  r  rg  r  r  rr  r  rK  r?  r  r@  	r  r  r  r  r  rr  r  r  r  s	            r  repay_isolated_marginzbinance.repay_isolated_margin/  s     	==&&V$$d^00v>>Tl 
 
 11$++gv2N2NOO %%h999r  c                    |                                   |                     |          }|d         |                     ||          d}d}d}|                     |dddd          \  }}|r*|                     |                     ||                    }n3d|d	<   d
|d<   |                     |                     ||                    }|                     ||          S )a  
        create a loan to borrow margin

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

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

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

        :param str symbol: unified market symbol, required for isolated margin
        :param str code: unified currency code of the currency to borrow
        :param float amount: the amount to borrow
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/?id=margin-loan-structure>`
        rO   rC  rI  rD  rE  rF  s	            r  borrow_isolated_marginzbinance.borrow_isolated_margin/  s     	==&&V$$d^00v>>Tl 
 
 11$++gv2N2NOO %%h999r  c                    |                      |d          }|                     |d          }|                     |d          |                     ||          |                     |d          d ||                     |          |dS )Nr  r  r6  r  )rO   rr  r  r  r  r  r  r7  )r  r  rr  r  r  s        r  r@  zbinance.parse_margin_loan0  s    " %%dG44
%%dL99	##D(33//
HEE&&tX66"Y//
 
 	
r  r   c           	         |dk    rt          | j        dz             |                                  d}|                     |ddd          \  }}|r|                     d|||||d          S |                     |          }d|                     | j        ||          i}|||d	<   |d
         rdnd}	|d         ||	<   |d         r|                     |dd          |d<   |||d<   |                     |d          }
|                     |d|
          }| 	                    |ddg          }|r||d<   n:|r8|d}| 
                    |          }|                     |||z  dz            |d<   d}|d         r*|                     |                     ||                    }n)|                     |                     ||                    }|                     ||||          S )aN  
        Retrieves the open interest history of a currency

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

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

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

        :param str symbol: unified CCXT market symbol
        :param dict [params]: exchange specific parameters
        :returns dict} an open interest structure{@link https://docs.ccxt.com/?id=open-interest-structure:
        r]   r  underlyingAssetr  Nz$ fetchOpenInterest does not support 
expirationrO   r  r  r   )r  r  r@   rO   r  eapiPublicGetOpenInterestr  dapiPublicGetOpenInterestfapiPublicGetOpenInterestrS  r  r  parse_open_interest)	r  r  r  r  r  r  r+  r  r  s	            r  fetch_open_interestzbinance.fetch_open_interestg0  s    	V$$( 	-)/)9G%&h'"47-S#SV\#\]]]$(KKx0@$A$AGL!! &tGH( 	T55dkk'66R6RSSHHI 	T55dkk'66R6RSSHH55dkk'66R6RSSH> ( 	>H%F66xHHF1c&kk**    ay>V++KKK , 
 ++Hf===tr  c                 \   |                      |dd          }|                     |d          }|                     |dd          }|                     |dd          }|                     |                     ||d d          |d	         rd n||||||                     |          |d
|          S )Nr  rQ  r  sumOpenInterestrh  sumOpenInterestValuesumOpenInterestUsdr  r  )r  r  r  openInterestAmountopenInterestValuer  r  r  )r  r  r  safe_open_interestr  r  )r  r  r  r  rO   r  values          r  r\  zbinance.parse_open_interest0  s    ''+vFF	h11##H.?PP""8-CEYZZ &&&&r64DD"("3?$$ "(!&"Y//	(
 	(
 	 	 		r  c           	         |                                   d}|                     |dd          \  }}|r|                     d||||dd          S d}||                     |          }d}|                     d||          \  }}d}|                     d||d          \  }}d}	|                     |ddd	d          \  }	}i }
|d
k    rd|
d<   ||d
         rdnd}|	s|d         |
|<   |||
d<   ||d
k    r||
d<   n||
d<   |                     d|
|          \  }
}d}|d
k    rW|	r+|                     | 	                    |
|                    }n| 
                    | 	                    |
|                    }n|dk    rV|	r*|                     | 	                    |
|                    }n|                     | 	                    |
|                    }n|dk    rV|	r*|                     | 	                    |
|                    }nM|                     | 	                    |
|                    }n#t          | j        dz   |d         z   dz             |                     |d|          }|                     ||||          S )a$  
        retrieves the users liquidated positions

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

        :param str [symbol]: unified CCXT market symbol
        :param int [since]: the earliest time in ms to fetch liquidations for
        :param int [limit]: the maximum number of liquidation structures to retrieve
        :param dict [params]: exchange specific parameters for the binance api endpoint
        :param int [params.until]: timestamp in ms of the latest liquidation
        :param boolean [params.paginate]: *spot only* default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch liquidations in a portfolio margin account
        :param str [params.type]: "spot"
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: an array of `liquidation structures <https://docs.ccxt.com/?id=liquidation-structure>`
        Fr   rE  currentrT  Nr  r  r  rY   LIQUIDATIONautoCloseTyperP  r  rO   rJ  rY  r  rK  r  z( fetchMyLiquidations() does not support r  r  r  )r  r   fetch_paginated_call_incrementalr  r  r  r  r~  papiGetMarginForceOrdersr   sapiGetMarginForceLiquidationRecpapiGetUmForceOrdersfapiPrivateGetForceOrderspapiGetCmForceOrdersdapiPrivateGetForceOrdersr@   rO   r  parse_liquidations)r  r  rC  r  r  rE  r  r  r  r  r  rT  r  liquidationss                 r  fetch_my_liquidationszbinance.fetch_my_liquidations0  s   * 	88AVXbcc& 	~889NPVX]_dflnwy|}}}[[((F99:OQWY_``f99:OQWY_aijj $($C$CFLacik|  D  %E  %E!66>>'4GO$,26NH((I$ 2%+D\	"#(GK v~~"'#( 229gvNN6>>  _88Wf9U9UVV@@WV\A]A]^^    X44T[[&5Q5QRR99$++gv:V:VWW	!!  X44T[[&5Q5QRR99$++gv:V:VWWtw)SSV\]cVddgqqrrr\ ~~hAA&&|VUEJJJr  c                    |                      |d          }|                     |dd          }|                     ||                     ||          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d	          ||                     |          d

          S )Nr  updatedTimer  r  r  r  rl  r  r  )
r  r  r  r  r  rl  	baseValue
quoteValuer  r  )r  r  safe_liquidationr  r   r  r  )r  liquidationr  r  r  s        r  parse_liquidationzbinance.parse_liquidationS1  s    J ##K::'']LQQ	$$&&x88))+}EE ,,V^DD%%k:>>**;??))+yAA**;
CC"Y//&
 &
   	r  c                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d         |          S )a  
        fetches an option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract

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

        :param str symbol: unified symbol of the market to fetch greeks for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `greeks structure <https://docs.ccxt.com/?id=greeks-structure>`
        r  rO   r   )r  r  eapiPublicGetMarkr  parse_greeksr  s         r  fetch_greekszbinance.fetch_greeks1  sv     	V$$fTl
 ))$++gv*F*FGG$   !f555r  c                 \   |                                   |                     |dddd          }i }d}|;t          |          }|dk    r&|                     |d                   }|d         |d<   |                     |                     ||                    }|                     ||          S )a  
        fetches all 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[] [symbols]: unified symbols of the markets to fetch greeks for, all markets are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `greeks structure <https://docs.ccxt.com/?id=greeks-structure>`
        NTr#  r   rO   r  )r  r  r  r  r|  r  parse_all_greeks)r  r<  r  r  r  r   r  s          r  fetch_all_greekszbinance.fetch_all_greeks1  s     	%%gtT4FFLLM!!WQZ00$*4L!))$++gv*F*FGG$ $$Xw777r  greeksc                    |                      |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 |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   )r  r  r  r  r  s        r  r}  zbinance.parse_greeks1  s     ##FH55!!(F33
f

 
 T%%fg66	

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

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

        :param str symbol: unified symbol of the market to fetch the order book for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: an object detailing whether the market is in hedged or one-way mode
        Nr   r  r  zI fetchPositionMode requires either a symbol argument or params["subType"]rR  )r  rn  )r  r  fapiPrivateGetPositionSideDualdapiPrivateGetPositionSideDualr6   rO   r  )r  r  r  r  r  r  rR  s          r  fetch_position_modezbinance.fetch_position_mode$2  s     [[((F99:MvW]^^h::6BBHH	!!::6BBHHTW'rrsss  >>(4FGG&
 
 	
r  c                    |                                   d}|0|                     |          }|                     |d                   }d}|                     d||          \  }}d}|dk    r|                     |          }n3|dk    r|                     |          }nt          | j        dz             |                     |dg           }t          |t                    r|}|                     ||dd	          S )
a4  
        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 onlyr  r  r[   )r  r  r  r  rZ  r  r6   rO   r  r  rD  parse_margin_modes)r  r<  r  r  r  r  r  s          r  fetch_margin_modeszbinance.fetch_margin_modesG2  s    	))'22G[[,,F99:KVU[\\h66v>>HH 	!!11&99HHd TW'ffggg+r::h%% 	F&&vw&IIIr  c                    |                                   |                     |          }d}|                     d||          \  }}d}|dk    r4d|d         i}|                     |                     ||                    }n<|dk    r|                     |g|          }||         S t          | j        dz             |                     |d         |          S )	aa  
        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  rO   r  z< fetchMarginMode() supports linear and inverse subTypes onlyr   )	r  r  r  rZ  r  r  r6   rO   parse_margin_mode)r  r  r  r  r  r  r  fetchMarginModesResponses           r  fetch_margin_modezbinance.fetch_margin_mode2  s     	V$$99:KVU[\\h&,G 66t{{7F7S7STTHH 	!!'+'>'>x'P'P$+F33TW'eefff%%hqk6:::r  c                     |                      |d          }|                     ||          }|                     |d          }d }||rdnd}|                     |d          }|
|dk    rdnd}||d         |dS )Nr  ri  r  r  r_  )r  r  rf  )r  r  r  r  )r  rf  r  r  rc  reMarginModerd  s          r  r  zbinance.parse_margin_mode2  s    ##J99!!(F33z:>>$)6C::GL..z<HH$'4	'A'A77
LX&&
 
 	
r  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     |d|          S )a  
        fetches option data that is commonly found in an option chain

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

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `option chain structure <https://docs.ccxt.com/?id=option-chain-structure>`
        r  rO   r   N)r  r  r  r  r$  parse_option)r  r  r  r  r  r  chains          r  fetch_optionzbinance.fetch_option2  s     	V$$fTl
 ++DKK,H,HII2 xB//  f555r  r  c                    |                      |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 S )Nr  r  rr  r  r  impliedVolatilityrh  r  r  midPricer  r  r  ru  r  r  r  r   r  r  r  )r  r  r   )r  r  rr  r  r  s        r  r  zbinance.parse_option3  sv   . ##E844!!(F33
E

 fX&
 	

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

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

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

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

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

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

        :param str fromCode: the currency that you want to sell and convert from
        :param str toCode: the currency that you want to buy and convert into
        :param float amount: how much you want to trade in units of the from currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.walletType]: either 'SPOT' or 'FUNDING', the default is 'SPOT'
        :returns dict: a `conversion structure <https://docs.ccxt.com/?id=conversion-structure>`
        Nz0 fetchConvertQuote() requires an amount argument)r  toAsset
fromAmount)r5   rO   r  sapiPostConvertGetQuoter  rr  parse_conversion)	r  r  r  r  r  r  r  fromCurrency
toCurrencys	            r  fetch_convert_quotezbinance.fetch_convert_quote3  s     >#DG.`$`aaa! 
 

 //GV0L0LMM }}X..]]6**
$$X|ZHHHr  c                    |                                   i }d}|dk    s|dk    rW|t          | j        dz             ||d<   ||d<   ||d<   ||d<   |                     |                     ||                    }n.||d<   |                     |                     ||                    }|                     |          }|                     |          }	|                     |||	          S )	am  
        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>`
        NrR  z1 createConvertTrade() requires an amount argumentclientTranIdr  targetAssetr  r  )r  r5   rO   sapiPostAssetConvertTransferr  sapiPostConvertAcceptQuoterr  r  )
r  rO   r  r  r  r  r  r  r  r  s
             r  create_convert_tradezbinance.create_convert_trade3  s    	Ff$4$4~'2e(efff&(GN#'GG%+GM" &GH88Wf9U9UVVHH "$GI66t{{7F7S7STTH }}X..]]6**
$$X|ZHHHr  c                    |                                   i }d}|dk    rtd}|                                 }| |                     |          }|d         |d<   ||d<   ||z
  |d<   ||d<   |                     |                     ||                    }n.||d	<   |                     |                     ||                    }|}	|dk    r.|                     |d
g           }
|                     |
di           }	|                     |	dd          }|                     |	dd          }d}d}||                     |          }||                     |          }| 	                    |	||          S )a  
        fetch the data for a conversion trade

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

        :param str id: the id of the trade that you want to fetch
        :param str [code]: the unified currency code of the conversion trade
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `conversion structure <https://docs.ccxt.com/?id=conversion-structure>`
        NrR  r  rO   r  r6  rJ  rK  ry  r  r   deductedAssetr  r  r  )
r  r  rr  &sapiGetAssetConvertTransferQueryByPager  sapiGetConvertOrderStatusr  r$  r  r  )r  rO   r  r  r  r  msInDayr^  rr  r  r  fromCurrencyIdtoCurrencyIdr  r  s                  r  fetch_convert_tradezbinance.fetch_convert_trade3  s    	6>>G##%%C==..#+D>  "GH#&=GK !$GIBB4;;wX^C_C_``HH( "$GI55dkk'66R6RSSH 6>>>>(FB77D>>$2..D++D/;OO))$yII
%==88L#|44J$$T<DDDr  c                    |                                   i }d}|                                 }|||d<   n||z
  |d<   |                     |dd          }|||d<   n||d<   |                     |d          }d}	d}
d}d}|dk    rW|                     |          }|d         |d<   |||d	<   d
}d}d}
|                     |                     ||                    }	nb|d         |d         z
  |k    rt          | j        dz             |||d<   d}d}d}
| 	                    |                     ||                    }	| 
                    |	|
g           }|                     ||||||          S )a  
        fetch the users history of conversion trades

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

        :param str [code]: the unified currency code
        :param int [since]: the earliest time in ms to fetch conversions for
        :param int [limit]: the maximum number of conversion structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest conversion to fetch
        :returns dict[]: a list of `conversion structures <https://docs.ccxt.com/?id=conversion-structure>`
        l    H4 NrJ  rK  rF  rR  rO   r  rY  r  r  r  zV fetchConvertTradeHistory() the max interval between startTime and endTime is 30 days.r  r  r  rD  )r  r  r  r  rr  r  r  r6   rO   sapiGetConvertTradeFlowr  parse_conversions)r  r  rC  r  r  r  msInThirtyDaysr^  rK  r  responseQueryfromCurrencyKeytoCurrencyKeyrr  r  s                  r  fetch_convert_trade_historyz#binance.fetch_convert_trade_history94  s    	#!!#(GK  #&#7GK %%fiAA!(GI!$GI67++6>>}}T**H'~GG "'-O)M"MBB4;;wX^C_C_``HH( 	"W[%99^KK   ,D  "D  E  E  E #( )O%M"M33DKK4P4PQQH. ~~hr::%%dD/=RWY^___r  
conversionr  r  c                    |                      |g d          }|                     |dd          }|                     ||          }|                     |dd          }|                     ||          }|||                     |          |                     |g d          ||                     |dd          ||                     |d	d
          d d d
S )N)rQ  validTimestampr	  r  r  r  r  )r6  ry  r  deductedAmountr  targetAmounttoAmount)
r  r  r  rO   r  r  r  r  r  r  )r  r  r  r  r  r  )	r  r  r  r  r  fromCurr  tor  s	            r  r  zbinance.parse_conversion4  s    N ''
4\4\4\]]	$$Z+NN**7LAA
M9EE((Z88"Y//$$Z1Q1Q1QRR$,,Z9I<XX **:~zRR
 
 	
r  c                    |                                   d}|0|                     |          }|                     |d                   }d}d}|                     d||d          \  }}d}|                     ||          r|                     |          }nC|                     ||          r|                     |          }nt          | j	        dz             | 
                    ||          S )at  
        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   r[   r   r  zH fetchFundingIntervals() supports linear and inverse swap contracts only)r  r  r  r  r  fapiPublicGetFundingInfor  dapiPublicGetFundingInfor@   rO   r  r+  s          r  fetch_funding_intervalszbinance.fetch_funding_intervals4  s     	))'22G[[,,F99:QSY[ackll>>$(( 	u44V<<HH__T7++ 	u44V<<HHtw)ssttt ''':::r  c                 B   |                                   |                     |          }|d}d|i}|                     d||          \  }}|||d<   |||d<   d}|                     d||          \  }}d}	|dk    r5|d	         |d
<   |                     |                     ||                    }	nX|dk    r;|d         d         |d<   |                     |                     ||                    }	nt          | j        dz             | 	                    |	|          S )a  
        fetches the long short ratio history for a unified market symbol

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

        :param str symbol: unified symbol of the market to fetch the long short ratio for
        :param str [timeframe]: the period for the ratio, default is 24 hours
        :param int [since]: the earliest time in ms to fetch ratios for
        :param int [limit]: the maximum number of long short ratio structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest ratio to fetch
        :returns dict[]: an array of `long short ratio structures <https://docs.ccxt.com/?id=long-short-ratio-structure>`
        Nr   r  rK  rJ  r  r   r  rO   r  r  r  rI  zG fetchLongShortRatioHistory() supports linear and inverse subTypes only)
r  r  r~  r  &fapiDataGetGlobalLongShortAccountRatior  &dapiDataGetGlobalLongShortAccountRatior6   rO   parse_long_short_ratio_history)
r  r  rB  rC  r  r  r  r  r  r  s
             r  fetch_long_short_ratio_historyz&binance.fetch_long_short_ratio_history5  sQ    	V$$Ii
 229gvNN#(GK $GG99:VX^`fggh &tGHBB4;;wX^C_C_``HH 	!!$VnV4GFOBB4;;wX^C_C_``HH TW'ppqqq228VDDDr  c           	          |                      |d          }|                     |d          }||                     ||d d          ||                     |          d |                     |d          dS )Nr  r  r  longShortRatio)r  r  r  r  rB  r  )r  safe_integer_omit_zeror  r  r   )r  r  r  r  r  s        r  parse_long_short_ratiozbinance.parse_long_short_ratioT5  s    , ##D(33//kBB	&&xzJJ"Y//"..t5EFF
 
 	
r  c                 ^   |                                   |                     |          }d|d         i}d}|                     d||          \  }}d}|dk    r*|                     |                     ||                    }nt          | j        dz             |                     ||          S )a  
        fetches the auto deleveraging rank and risk percentage for a symbol

        https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/ADL-Risk

        :param str symbol: unified symbol of the market to fetch the auto deleveraging rank for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `auto de leverage structure <https://docs.ccxt.com/?id=auto-de-leverage-structure>`
        r  rO   Nr~   r  z- fetchADLRank() supports linear subTypes only)r  r  r  fapiPublicGetSymbolAdlRiskr  r6   rO   parse_adl_rank)r  r  r  r  r  r  r  s          r  fetch_adl_rankzbinance.fetch_adl_ranku5  s     	V$$fTl
 99.&RXYYh66t{{7F7S7STTHH TW'VVWWW""8V444r  c                 (   |                                   |                     |dddd          }|                     |          }d}|                     d||          \  }}d}|                     |dddd          \  }}d}|dk    r.|r|                     |          }na|                     |          }nK|dk    r.|r|                     |          }n-|                     |          }nt          | j
        d	z             |                     ||          S )
a  
        fetches the auto deleveraging rank and risk percentage for a list of symbols that have open positions

        https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Position-ADL-Quantile-Estimation
        https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Position-ADL-Quantile-Estimation
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/UM-Position-ADL-Quantile-Estimation
        https://developers.binance.com/docs/derivatives/portfolio-margin/trade/CM-Position-ADL-Quantile-Estimation

        :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 for the portfolio margin account
        :returns dict[]: an array of `auto de leverage structure <https://docs.ccxt.com/?id=auto-de-leverage-structure>`
        NTr   r  r  Fr  r  zB fetchPositionsADLRank() supports linear and inverse subTypes only)r  r  r  r  r  papiGetUmAdlQuantilefapiPrivateGetAdlQuantilepapiGetCmAdlQuantiledapiPrivateGetAdlQuantiler6   rO   parse_adl_ranks)r  r<  r  r  r  r  r  s          r  fetch_positions_adl_rankz binance.fetch_positions_adl_rank5  sK    	%%gtT4FF--g6699:QSY[abb $($C$CFLcekm~  AF  %G  %G!6h  B44V<<99&AA	!!  B44V<<99&AATW'kklll ##Hg666r  c           	         |                      |di           }|                     |d          }|                     |d          }|                     |d          }d }||}n||||k    r|}n|}|                     |d          }|                     |dd          }	||                     ||d d          ||                     |d	          d |	|                     |	          d
S )Nr~  rT  rU  r  r  r  r  r  adlRisk)r  r  rankratingr  r  r  )r$  r   r  r  r  r  r  )
r  r  r  r~  longNumshortNumr`  r  r  r  s
             r  r  zbinance.parse_adl_rank5  s   * nnT="=="";77##K99V44DD"x';X%%"DD#D##D(33''k<HH	&&xzJJ,,T9=="Y//
 
 	
r  )N)NNNN)NNF)F)NN)__name__
__module____qualname__r   r  r  r$   boolr  r  r  r  r.   r  r   r  r  r  r  r   r  r   r8  r0   rT  dictrI  r  r   r  r  r   r  r&   r  r  r  r%   r%  r,  r/  r'   r2  r1  r:  r<  rD  rA  r`  r*   r  r  r"   r!   floatr   r  r  r  r  r  r    r  r  r  r   r  r)  rD  r%  rj  rl  rn  r|  r  r  r  r  r  r  r  r  r  r  r  r  r~  r-   r  r  r  r   r1  r4  r/   rA  rC  r   r`  r   rd  rc  rl  ro  rr  r   r+   r{  r  r,   r  r  r(   r  r  r  r)   r  r  r  r  r   r  r   r  r   r  r  r!  r  r#   r*  r(  r'  r>  r  rE  rN  rW  r   r]  r   rf  rn  rq  rw  ri  r   r  r  r}  r  rf  r  r  r  r  r  r  r  r   r  r  r  r
   r
  r   r  r   r  r  r	  r   r&  r)  r,  r   r2  r8  rA  rG  rK  rM  r@  rU  r]  r\  rs  rz  r   r~  r  r}  r  r  r   r  r   r  r  r   r  r  r  r  r	   r  r  r  r  r  r  r   r  r  r   r  r  r  __classcell__)r  s   @r  rL   rL   (   s'"       A*# A* A* A* A* A* A*FT( (s (S (D ( ( ( (' 'c 'C '4 ' ' ' '-t - - - - - -;
3 ;
 ;
 ;
 ;
z.LS .L_ .L .L .L .L`Y YC Y YRU Yjm Y  zI Y Y Y Y Y YK K KD D D3$ 3 3 3 3( !# 9 9s 9 9 9 94 ') a aZ a a a aF $& c c$v, c c c cJ	g4 gF g g g gR  dA dAem dA dA dA dAL $& @X @X( @X @X @X @XD :>b N Ns N3 NY N N N N`v v4 v v6 v v v vp #% 
 
 
 
2 02 %3 %33 %3f %3 %3 %3 %3N 26b  5  5w  5  5  5  5D 48 :9 :9 :9 :9 :9 :9x&
 &
f &
 &
 &
 &
P 04B /5 /5W /57 /5 /5 /5 /5b@ @ @ 46 3 3s 3& 3 3 3 3@ 48 5 5 5w 5 5 5 58=
 =
 =
4 =
 =
 =
 =
~ 9=4^bkm v v# v# vS vX[ vrvw{r| v v v vp~ ~ ~v ~ ~ ~ ~ ~@ 6:UW IA IA3 IAs IA# IA\`af\g IA IA IA IAV sw  @B ?. ?.# ?.s ?.) ?.9 ?.^c ?.lo ?. ?. ?. ?.B {  HJ g, g,# g,s g,) g,S\ g,fk g,tw g, g, g, g,R C  LN  c 3 i W` jo x{    $ w{  DF A2 A2c A23 A2i A2y A2bg A2ps A2 A2 A2 A2F `drv  @B [ [S [# [Y [i [Y\ [lo [ [ [ [4 >@ M+ M+$|"4 M+ M+ M+ M+^: : : : :$	3S 	3 	3 	3 	3P	 P	 P	v P	 P	 P	 P	 P	d @B K+ K+D$6 K+ K+ K+ K+Z gksu f2 f23 f2i f2y f2RW f2`c f2 f2 f2 f2P os{} J3 J33 J3i J3y J3Z_ J3hk J3 J3 J3 J3X _a _ _C _y _PU _ _ _ _* RT ` ` `5 ` ` ` `( SU O O OE O O O O$ 26b I2 I2c I23 I2 I2 I2 I2V *.Dt\^ EA EA3 EAc EA EAcghmcn EA EA EA EAN /3TXac UA UA UA3 UAc UAhlmrhs UA UA UA UAn 7;2 J2 J23 J2 J2 J2 J2 J2X 154VZce H H# HS HPS Hjnotju H H H H: 37TX\eg H HC Hs HRU H H H H: >BPTcgpr F Fs F# F]` Fw{  }B  xC F F F F@ 37r W2 W2s W2C W2 W2 W2 W2r /32 f f f f f fP ;?r I3 I3c I3C I3 I3 I3 I3V 9=4^bkm X XS X# XS XX[ X X X X: -1tRV_a SA SAc SA SAC SA SA SA SAj 26DW[df C@ C@3 C@c C@QT C@ C@ C@ C@JA
 A
f A
 A
 A
 A
F *.Dt\^ dI dI3 dIc dI dIcghsct dI dI dI dIL -1tRV_a yI yIc yI yIC yIfjkvfw yI yI yI yIv$: $: $: $:Ly
 y
T y
X y
Q\ y
 y
 y
 y
v:C :C : : : :c
 c
t c
x c
= c
 c
 c
 c
J
 
6 
 
 
 
4 [] U7 U7S U7% U7c U7c U7an U7 U7 U7 U7n +/TPT]_ DB DBC DBs DB# DBdhivdw DB DB DB DBL 79 &> &># &>^ &> &> &> &>P
 
 
N 
 
 
 
8 7;2 o
 o
G o
 o
 o
 o
b <@ 6I 6I 6I 6I 6I 6Ip@ @ @ @ @ @D KOWY ": ":S ":% ":# ":C ":^i ": ": ": ":H
 
T 
6 
EX 
 
 
 
: 57 ?4 ?4 ?4;N ?4 ?4 ?4 ?4B )+ g g{ g g g gR @B 7 7S 7 7 7 7> 68 %9 %9 %9K %9 %9 %9 %9N 8<$]ajl 7Q 7Q 7QC 7QWZ 7Q 7Q 7Q 7Qr
 
6 
 
 
 
" 6:" ; ;7 ; ; ; ; ;8:
 :
6 :
[ :
 :
 :
 :
x   Bj
 j
v j
 j
 j
 j
X\ \F \ \ \ \| -2" '0 '0 '0 '0R 7;2 IF IFG IF- IF IF IF IFV& & &$|J\ & & & &P 24 )? )?S )? )? )? )?V 9=R 4P 4Pg 4P 4P 4P 4Pl6 6d 6F 6 6 6 6p 26b  H  Hw  HT(^  H  H  H  HD :>b wP wPw wP wP wP wPr 7;2 eP ePG eP eP eP ePN 37TX\eg 5B 5BC 5Bs 5BRU 5B 5B 5B 5Bn 9=R * *S *# * * * *X >B" 6 6# 6s 6 6 6 6p =A 4 4 4c 4 4 4 4l 26b 'B 'Bw 'BY 'B 'B 'B 'BR
 
t 
V 
x 
 
 
 
8 6:[_hj (O (Os (O# (OUX (O (O (O (OT 9=4^bkm 1O 1O# 1OS 1OX[ 1O 1O 1O 1Of'
 '
 '
R& & &P 7;2 #8 #8S #8 #8+ #8 #8 #8 #8J (,$TZ\ XC XC XCC XCs XCaefqar XC XC XC XCt5 5t 5x 5; 5 5 5 5n8 8 80 C S \_    "
,C 
,C 
, 
, 
, 
, &eBSW pP pP pP pPd C    $D# Ds D Dc DTX D`c D D D DL MO 2 2 2 2  !)r4VZce     MO " "3 " " " "H*
 *
d *
F *
N` *
 *
 *
 *
X @B D DC D DFX D D D D =? D D De DCU D D D D 9; , ,C , , , , ,< >@ 3 3 3DV 3 3 3 3& 24 *: *:8K *: *: *: *:X AESW`b 'L 'Lc 'L# 'LS 'L 'L 'L 'LR
 
 
 
 
 
(#
 #
t #
V #
Oa #
 #
 #
 #
J :< $
 $
S $
 $
 $
 $
L 57    6 02  3    0 15DW[jnwy JQ JQ# JQc JQQT JQdg JQ  C  DR  S JQ JQ JQ JQX
 
$ 
 
. 
 
 
 
  <> 9: 9:s 9: 9: 9: 9:v LN : :C :s : : : :> DF ": ": ":U ": ": ": ":H TV : :S : :U : : : :>
 
 
 
 
 
: BFTXgktv =Q =Q# =Qc =Qad =Q =Q =Q =Q~ 79 D D# D D D DL F    $ 37TX\eg RK RKC RKs RKRU RK RK RK RKhR RV R R R Rh 02 !6 !63 !6f !6 !6 !6 !6F 37r %8 %8 %8d6l %8 %8 %8 %8N&
 &
4 &
 &
6 &
 &
 &
 &
P 7;2 	 	G 	 	 	 	 15R !
 !
# !
 !
 !
 !
F 59 YJ YJ' YJ YJ YJ YJ YJv 57 &; &; &;: &; &; &; &;P
 
D 
* 
 
 
 
  02 )6 )63 )6f )6 )6 )6 )6V+
 +
$ +
( +
6 +
]c +
 +
 +
 +
Z =Adaetx  BD 7V 7Vc 7V 7V[^ 7Vnq 7V  IM  N`  Ia 7V 7V 7V 7Vr /1 4 4Z 4 4 4 4l MQY[ "I "IC "I "Ic "I`j "I "I "I "IH W[ce *I *Is *Ic *I3 *IPS *Ijt *I *I *I *IX 8<B FE FEc FE FE: FE FE FE FEP 7;\`ik Z` Z` Z`3 Z`VY Z`ptu  qA Z` Z` Z` Z`xW
 W
4 W
x W
\d W
pz W
 W
 W
 W
r :>b &; &;w &;\ &; &; &; &;P <@RVeix|  FH <E <ES <EC <E_b <Eru <E  MQ  R`  Ma <E <E <E <E|
 
4 
 
> 
 
 
 
B 24 5 5S 5 5 5 5 5> ;?r .7 .7 .7dSVi .7 .7 .7 .7`,
 ,
4 ,
 ,
3 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
r  rL   )Rccxt.base.exchanger   ccxt.abstract.binancer   r  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.   r/   typingr0   ccxt.base.errorsr1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   ccxt.base.decimal_to_precisionrH   rI   ccxt.base.preciserJ   rL   r  r  r  <module>r	     s   ( ' ' ' ' ' - - - - - -   Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y       * * * * * * 0 0 0 0 0 0 - - - - - - - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . 1 1 1 1 1 1 ) ) ) ) ) ) . . . . . . ) ) ) ) ) ) * * * * * * 5 5 5 5 5 5 - - - - - - ) ) ) ) ) ) , , , , , , + + + + + + . . . . . . * * * * * * ) ) ) ) ) ) + + + + + + ( ( ( ( ( ( 3 3 3 3 3 3 4 4 4 4 4 4 % % % % % %HW
 HW
 HW
 HW
 HW
h HW
 HW
 HW
 HW
 HW
r  