
    E#iG                    x   S SK Jr  S SKJr  S SKrS SKrS SKJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r J!r!  S SK"J#r#  S SK$J%r%  S SK$J&r&  S SK$J'r'  S S	K$J(r(  S S
K$J)r)  S SK$J*r*  S SK$J+r+  S SK$J,r,  S SK$J-r-  S SK$J.r.  S SK$J/r/  S SK$J0r0  S SK$J1r1  S SK2J3r3  S SK4J5r5   " S S\\5      r6g)    )Exchange)ImplicitAPIN)AnyBalances
CurrenciesCurrencyDepositAddressIntLeverage
MarginModeMarginModificationMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTradingFeeInterfaceTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)OperationFailed)DDoSProtection)	TICK_SIZE)Precisec                   J	  ^  \ rS rSrS\4U 4S jjr0 4S\4S jjr0 4S\4S jjr	S\
\   4S jrS rS rS	\S\4S
 jr0 4S\
\   4S jjrSSS0 4S\S\S\S\S\
\   4
S jjrSS	\S\4S jjrSS0 4S\S\S\S\
\   4S jjrSS\S	\S\4S jjrS0 4S\S\S\4S jjr0 4S\S\4S jjrS0 4S\S\4S jjrSS	\S\4S jjr SSS0 4S\!S\S\4S jjr"SS	\4S jjr#0 4S\4S jjr$SS	\4S jjr%0 4S\S\&4S  jjr'S0 4S\S\(4S! jjr)0 4S\S\&4S" jjr*S0 4S\S\(4S# jjr+SS$\S	\S\&4S% jjr,0 4S\-4S& jjr.S\-4S' jr/SS0 4S\S\S\S\
\0   4S( jjr1S0 4S\S\
\0   4S) jjr20 4S\4S* jjr3SS+\S	\4S, jjr40 4S\S-\5S.\64S/ jjr70 4S\S.\64S0 jjr80 4S\S.\64S1 jjr9S0 4S\S2\:S-\5S3\6S4\;4
S5 jjr<S0 4S\S2\:S-\5S3\6S4\;4
S6 jjr=0 4S7\
\>   4S8 jjr?S9 r@S2\!4S: jrASS;\S	\S\B4S< jjrCS=\!4S> jrDS0 4S?\S\!4S@ jjrES0 4S\!4SA jjrFS0 4SB\
\   S\!4SC jjrG0 4SD\4SE jjrHS0 4S?\S\!4SF jjrISSS0 4S\!S\S\S\
\B   4SG jjrJSSS0 4S\!S\S\S\
\B   4SH jjrKSSS0 4S\!S\S\S\
\B   4SI jjrLSSS0 4S\!S\S\4SJ jjrMSSS0 4S\!S\S\4SK jjrN0 4SL\S3\6SM\SN\S\O4
SO jjrPSSS0 4SL\!S\S\S\
\O   4SP jjrQSSQ\SR\RS\O4SS jjrSS=\!S\4ST jrT0 4SL\S\
\U   4SU jjrV0 4SL\S\U4SV jjrWSSR\RS\U4SW jjrXSSS0 4SL\!S\S\S\
\Y   4SX jjrZSSS0 4SL\!S\S\S\
\Y   4SY jjr[SSZ\SR\RS\Y4S[ jjr\S=\4S\ jr]S0 4S]\S\!4S^ jjr^0 4S\S3\6S\_4S_ jjr`0 4S\S3\6S\_4S` jjra0 4S\S3\6S\_4Sa jjrbSSb\S	\S\_4Sc jjrc0 4S\S\d4Sd jjreSSe\S	\S\d4Sf jjrfS0 4Se\gS\!4Sg jjrhSSS0 4S\!S\S\4Sh jjriSSR\R4Si jjrjS0 4Sj\4Sk jjrkS0 4SL\S3\6Sl\Sm\!S\Y4
Sn jjrlSo rmSSS0 4S\!S\S\4Sp jjrnSS	\4Sq jjroS0 4S\S-\5S\B4Sr jjrp0 4S\
\0   4Ss jjrqS0 4S\!4St jjrrS0 4Su\sS\!4Sv jjrtSS0 4S?\S\S2\:S-\5S3\;S4\;S\B4Sw jjru0 4S\S\v4Sx jjrwSS]\S\v4Sy jjrx0 4S\S\y4Sz jjrzSS{\S	\S\y4S| jjr{S} r|S~S0 SS4S jr}S r~S\s4U 4S jjrS\gS\S\S\S\S\4S jrSrU =r$ )bingx   returnc                 	  > U R                  [        [        U ]  5       0 SS_SS_SS/_SS_S	S
_SS_SS_S0 SS _SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S_0 S!S_S"S_S#S_S$S_S%S_S&S_S'S_S(S_S)S_S*S_S+S_S,S_S-S_S.S_S/S_S0S_S1S_E0 S2S_S3S_S4S_S5S_S6S_S7S_S8S_S9S_S:S_S;S_S<S_S=S_S>S_S?S@_SAS_SBS_SCS_E0 SDS_SES_SFS_SGS_SHS_SIS_SJS_SKS_SLS_SMS_SNS_SOS_SPS_SQS_SRS_SSS_STS_E0 SUS_SVS_SWS_SXS_SYS_SZS_S[S_S\S_S]S_S^S_S_S_S`S_SaS_SbS_ScS_SdS_SeS_ESSSSSSSSSSSf.
E_SgSh_SiSjSkSkSkSkSkSkSkSkSkSkSkSl.SSm0SnSoSpSq._SrSSsU R	                  St5      U R	                  St5      Su.SvU R	                  Sw5      U R	                  Sx5      Su.Sy._SzSSS{._S|S
S}SsS~S0000SsSSSSSSSSS.0SSSSSSSSSS.	SSSSSSSSSS.	S.S.SSsSSS.00S}SSSSS.SS0S.0S.SsSSSSSS.0SSSSSSSSSSSS.SSSSSSSSSSS.
S.S.SsSSSSSSSSSSSS.0SSSSSSSSSSSSSSSS.SSSSSSSSS.SSSS.S.S.SsSS00SsSS00S.S.S
SsSSSSSSS.0SSSSSSSSSSS.
SSSSSSS.SSS.S.S.0S
S}SsSSSS.000S
S}SSSSSSSS.SSSSS.S.00S
S}SSSS.SSSSSS.S.00S}SSSSS.SS0S.0S
S}SS0SSS.S.00S.SS}SS0SS0SS0S.00S
S}SS0SSSS.S.00S}SSSSS.SS0S.0S
SSS00SsSS00S.0S.S
S}SsSSSSSSSSS.000S._SSSSSSSSSSSSSSSS._S[
        _S0 S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _[        [        [        [        [        [        [        [        [        [        [         [        [        S.E0 S._SSSSSSS._SSSSSSSS.SSSSSS.SSSSSSSS.SSSSSS.S.SSSSSSS.SSSSSSS.SS.SSSSS.SSSSSSSS.SS0SSSSSS.SSSSS.SS SSSS.SSGS GSSSSGS.SSS S GSSSSGS.GSGS0GS.	GSSS S GS.S GS	.GSS}S0S S SGS
.SSSGS.S SS GS.GS.GSGS0GSGS0GS.GSS GS.GSGS0GSGS0GS.GS.GS.E5      $ (  Nidr1   nameBingX	countriesUS	rateLimitd   versionv1	certifiedTprohasCORSspotmarginFswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMarginborrowMargincancelAllOrderscancelAllOrdersAftercancelOrdercancelOrderscloseAllPositionsclosePositioncreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrders$createOrderWithTakeProfitAndStopLosscreateReduceOnlyOrdercreateStopLossOrdercreateStopOrdercreateTakeProfitOrdercreateTrailingAmountOrdercreateTrailingPercentOrdercreateTriggerOrder	editOrderfetchAllGreeksfetchBalancefetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchCanceledOrdersfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchLiquidationsfetchMarginAdjustmentHistoryfetchMarginModefetchMarketsfetchMarkOHLCVfetchMarkPricefetchMarkPricesfetchMyLiquidationsfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsHistoryfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTransfersfetchVolatilityHistory)
fetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMarginsandboxsetLeverage	setMarginsetMarginModesetPositionModetransferhostnamez	bingx.comurlszwhttps://github-production-user-asset-6210df.s3.amazonaws.com/1294454/253675376-6983b72e-4999-4549-b177-33b374c195e3.jpgz#https://open-api.{hostname}/openApi)fundrB   rD   contractwalletsuser
subAccountaccountcopyTradingcswapapiz'https://open-api-vst.{hostname}/openApizhttps://bingx.com/z!https://bingx-api.github.io/docs/zhttps://bingx.com/invite/OHETOM)logor   testwwwdocreferralfeesgetz0.001)feeSidemakertakerquotez0.0002z0.0005)	tierBasedrB   rD   requiredCredentials)apiKeysecretr   privateaccount/balance   )server/timezcommon/symbolszmarket/tradesmarket/depthmarket/klinezticker/24hrticker/pricezticker/bookTicker      )	ztrade/querytrade/openOrdersztrade/historyOrdersztrade/myTradesuser/commissionRater   zoco/orderListzoco/openOrderListzoco/historyOrderList)	trade/orderztrade/canceltrade/batchOrdersztrade/order/cancelReplaceztrade/cancelOrdersztrade/cancelOpenOrderstrade/cancelAllAfterz	oco/orderz
oco/cancel)r   post)publicr   r   )r   r   )zget/asset/transferasset/transfercapital/deposit/hisreccapital/withdraw/historyzpost/asset/transfer)r=   v2v3)r   zmarket/historicalTradeszmarket/markPriceKlinesztrade/multiAssetsRulestradingRules)positionSide/dualtrade/batchCancelReplaceztrade/fullOrdermaintMarginRatioztrade/positionHistoryzpositionMargin/historyztwap/openOrdersztwap/historyOrdersztwap/orderDetailtrade/assetModezuser/marginAssets)
ztrade/cancelReplacer   r   ztrade/closePositionztrade/getVstz
twap/orderztwap/cancelOrderr   ztrade/reverseztrade/autoAddMargin)r   zquote/contractszquote/pricezquote/depthzquote/tradeszquote/premiumIndexzquote/fundingRatequote/klineszquote/openInterestzquote/tickerquote/bookTicker)user/balanceuser/positionszuser/incomer   ztrade/openOrderr   trade/marginTypetrade/leveragetrade/forceOrdersztrade/allOrderstrade/allFillOrdersztrade/fillHistoryzuser/income/exportr   r   )r   r   trade/closeAllPositionsr   r   r   trade/positionMarginztrade/order/test)r   r   trade/allOpenOrders)r   r   deleter   r   )zmarket/contractszmarket/premiumIndexzmarket/openInterestzmarket/klinesr   zmarket/ticker)
r   r   r   r   ztrade/orderDetailztrade/orderHistoryr   r   r   r   )r   r   r   r   r   r   )r   ztrade/cancelOrder)allPosition	allOrdersbalance)zcapital/config/getallzcapital/deposit/addresszcapital/innerTransfer/recordsz"capital/subAccount/deposit/addresszcapital/deposit/subHisrecz(capital/subAccount/innerTransfer/recordszcapital/deposit/riskRecords)zcapital/withdraw/applyzcapital/innerTransfer/applyz%capital/subAccountInnerTransfer/applyz capital/deposit/createSubAddress
   )listassetsallAccountBalance)createzapiKey/createzapiKey/editz
apiKey/delupdateStatus)uidzapiKey/queryaccount/apiPermissionsr   z!innerTransfer/authorizeSubAccountz subAccount/asset/transferHistory)z%subAccount/transferAsset/supportCoinszsubAccount/transferAsset)r=   r   authuserDataStream)r   putr   zswap/trace/currentTrack)zswap/trace/closeTrackOrderzswap/trace/setTPSLzspot/trader/sellOrder)r   zasset/transferRecordr   r   r   r   ztransfer/supportCoins)r   r   )r   asset)zaccount/inviteAccountListzreward/commissionDataListzaccount/inviteRelationCheckzasset/depositDetailListzreward/third/commissionDataListzasset/partnerDatazcommissionDataList/referralCodezaccount/superiorCheck)r   rB   rD   r   r   r   r   r   r   r   r   agent
timeframes1m3m5m15m30m1h2h4h6h12h1d3d1w1M)r   r   r   r   r   r   r   r   r   r   r   r   r   r   precisionMode
exceptions400401403404429418500504100001100412100202100204100400100410100421100440100500)1005038000180012800148001680017100414100419100437101204110425zInsufficient assetszillegal transferType)exactbroadcommonCurrenciesSnowmanOmniCatz$NAP	TRUMPMAGATRUMP)SNOWOMNINAPr$  TRUMPSOLr   
stdFutures	USDTMPerp	coinMPerp)fundingrB   rE   rD   linearinverser,  r-  r.  )r   rB   r)  r*  r+  i  CCXTETHERC20BTCLTC)r0  USDTUSDCr2  r3  ARBPOLYGON	ZKSYNCERAzAVAX-CHEDERA)ARBITRUMMATICZKSYNCAVAXCHBAR)defaultTypeaccountsByTypeaccountsById
recvWindowbrokerdefaultNetworksnetworks)lastmarkindex)triggerPriceTypeprice)IOCFOKPOGTD)
marginModetriggerPricerI  triggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyRequiresPricemarketBuyByCostselfTradePreventionicebergmaxi      )rO  limitdaysBack	untilDayssymbolRequired)rO  triggerrW  rb  )rO  r_  rc  rW  rb    i N     )rO  r_  r`  ra  rc  rW  rb  )rO  r_  r`  daysBackCanceledra  rc  rW  rb  r_    )	r   rT   rU   r   r   r   r   rh   r   defaultForLinear)r_  r`  ra  )extendsr   r   )rI  rT  rW  )r_  ra  )ri  rk   rT   r   r   rh   ri  defaultForInverse)r-  r.  )ri  r   defaultForFuture)rh  rj  rB   rD   rk  rE   )optionsfeatures)deep_extendsuperr1   describeparse_numberr.   r&   r"   r#   r-   r!   r(   r,   r'   r*   r$   r)   )self	__class__s    D/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/bingx.pyrp  bingx.describe   s   eT ; = c@
'c@
Gc@
 $c@
 	c@

 tc@
 c@
 4c@
  ``` %` 	`
 %` %` T` $U` '` ` "4` '` t` ` $T`   !`" /#`$ ,T%`& 0'`( t)`* +`, 7-`. (/`0 &t1`2 "43`4 (5`6 ,T7`8 -d9`: %d;`< T=`> !%?`@ A`B &uC`D "5E`F +EG`H )%I`J #EK`L ,UM`N &tO`P $TQ`R 'S`T (U`V "4W`X &tY`Z ([`\ 1$]`^  _`` *:a`b +Dc`d #De`f *4g`h $Ti`j uk`l *5m`n +Eo`p  q`r $Us`t /u`v "4w`x y`z !${`| !$}`~ "4`@ &tA`B  C`D dE`F $TG`H "4I`J uK`L #EM`N dO`P !$Q`R tS`T  U`V 'W`X $TY`Z !$[`\ (]`^ t_`` a`b Tc`d te`f "4g`h !$i`j )%k`l %) $$)',#!!%#' `c@
R Sc@
T  RAAA EDA"GD#HB@ E ,:=)Uc@
@ !$!..w7!..w7  '!..x8!..x8Ac@
Z "$[c@
b !! 11$$ "/023120101/00156	$# 014578237834125689
$ 010156=>67:;89-../
%$%N !!0101$# "6723:;<=	$ !6q%
$_<@ "01;<:;:;01$# 67<=34459::;3467453456$ 8956<=7801./45341278%$%P "/034/0/001675601670145$#" 1223/04534/0452356347856677845$$ 0156;<8945238945	% 015678'9!$!2j " .$# " .$$ufP !457878120112$	# 34567845566745782301$ 012378;<4589% 8956'+$%'R !!/0-.+,$$
 !9:;<ABFG=>LM?@$ ;<?@IJDE	%$, !(**+56$ +-12/0./02%$( "'(01:;56	$ !DQ%
$ %$F(" NO@A)"	(
!: ! 0!% !1!$ !1!'
$  ! 91$ ?@679;%		$   "2389:;<=	$ !6q%
$  &$.)"( !&$;Q("'< !!=>=>?@;<CD56CD9:	$$}
ncc@
@ Ac@
` Yac@
b :. + :	
 > + = = 1 1 / j j o i  m!" o#$ ,'.'**..(/*+<,6=@ C"cc@
h !!$#!ic@
x  &%"*')*# &""*!)!*! '  ##  $ !&&)%$5!H  $&+(,$($(%)-
 -2)-+/ )-(,)-1
 &*7 $(#'"&#(	( #'$($)27+//4#(? $D q% ',!$$&%'*.& ',#($)*.	# ',!%#($)*/( ',!%$)%&#($)*.$ ',!%$(,0%&#($)*.	*  #[P%d  2!%$(%)&
 $(&  2!4( -16:$)$ "&$%%&&
 $(!$%)*!. "#5 "#6 	  2#'% "#5 "#5 	{E{c@
 c c	    c                 l    U R                  U5      nU R                  US5      nU R                  US5      $ )a;  
fetches the current integer timestamp in milliseconds from the bingx server

https://bingx-api.github.io/docs/#/swapV2/base-info.html#Get%20Server%20Time

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int: the current integer timestamp in milliseconds from the bingx server
data
serverTime)swapV2PublicGetServerTime	safe_dictsafe_integer)rr  paramsresponserx  s       rt  
fetch_timebingx.fetch_time  s9     11&9 ~~h/  |44rv  c                 "   U R                  S5      (       d  0 $ U R                  U R                  SS5      nU(       a  0 $ U R                  U5      nU R	                  US/ 5      n0 n[        S[        U5      5       GH  nXF   nU R                  US5      nU R                  U5      n	U R                  US5      n
U R	                  US5      n0 n[        S[        U5      5       H  nX   nU R                  US5      nU R                  U5      nU R                  US	5      U R                  US
5      S.U R                  US5      SS.S.nU R                  U R                  U R                  US5      5      5      nUUUU R                  US5      SU R                  US5      U R                  US5      UUS.	UU'   M     X;  a  UU	USU
SSSUSSSS.XY'   GMW  XY   nU R                  US0 5      n[        UR                  5       5      n[        S[        U5      5       H  nUU   nUU;  d  M  UU   UU'   M     UXY   S'   GM     [        UR                  5       5      n[        S[        U5      5       H  nUU   n	XY   nU R!                  U5      XY'   M!     U$ )z
fetches all available currencies on an exchange

https://bingx-api.github.io/docs/#/common/account-api.html#All%20Coins

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
FsandboxModerx  r   coinr6   networkListnetworkwithdrawMinwithdrawMaxminr]  
depositMinN)withdrawdepositwithdrawPrecisionwithdrawFeedepositEnablewithdrawEnable)	infor5   r  feeactiver  r  	precisionlimitscrypto)r  coder5   r  r6   r  r  r  rE  r  r  typerE  )check_required_credentials	safe_boolrl  &walletsV1PrivateGetCapitalConfigGetall	safe_listrangelensafe_stringsafe_currency_codenetwork_id_to_codesafe_numberrq  parse_precisionr{  r   keyssafe_currency_structure)rr  r}  	isSandboxr~  rx  resultientry
currencyIdr  r6   r  rE  j
rawNetworkr  networkCoder  r  existingexistingNetworksnewNetworkCodesnewNetworkCodecodescurrencys                            rt  fetch_currenciesbingx.fetch_currencies  s    ..u55INN4<<F	I>>vFN ~~h3q#d)$AGE))%8J**:6D##E62D..>KH1c+./(^
**:yA"55g>  $//
MJ#//
MJ!
  $//
LI# 	  !--d.B.B4CSCST^`sCt.uv	&!*++JF"#~~j/J $z;K L!*$
)% 04 N! $!% "# $ ("$  "<#'>>(J#K "&x}}"7q#o"67A%4Q%7N*.>>;CN;S(8 8 ,<Z(q %r V[[]#q#e*%A8D|H77AFL & rv  c                     U R                  U5      nU R                  US5      nU R                  US/ 5      nU R                  U5      $ )Nrx  symbols)spotV1PublicGetCommonSymbolsr{  r  parse_markets)rr  r}  r~  rx  marketss        rt  fetch_spot_marketsbingx.fetch_spot_markets  sG    44V<8 ~~h/..y"5!!'**rv  c                 l    U R                  U5      nU R                  US/ 5      nU R                  U5      $ Nrx  )swapV2PublicGetQuoteContractsr  r  rr  r}  r~  r  s       rt  fetch_swap_marketsbingx.fetch_swap_markets  s8    55f=@ ..626!!'**rv  c                 l    U R                  U5      nU R                  US/ 5      nU R                  U5      $ r  )cswapV1PublicGetMarketContractsr  r  r  s       rt  fetch_inverse_swap_markets bingx.fetch_inverse_swap_markets  s7    77?& ..626!!'**rv  marketc                    U R                  US5      nUR                  S5      nUS   nUS   nU R                  U5      nU R                  U5      nU R                  US5      nSn	Sn
U R                  US5      nUb  UnSn	Sn
U R                  U5      nU R                  US	5      nUc0  U R	                  U R                  U R                  US
5      5      5      nU R                  US5      nUc0  U R	                  U R                  U R                  US5      5      5      nUb  SOSnUS:H  nUS:H  nUS-   U-   nUb  USU-   -  nU R                  U R                  U0 5      nU(       a  U R	                  S5      OS nSnU R                  US5      S:X  a  U R                  US5      S:X  a  SnOFU R                  US5      (       a/  U R                  US5      (       a  U R                  US5      S:X  a  SnU(       a  S OU	nU(       a  S OU
nS nU(       d  U R                  USS5      nU R                  US5      nUS:X  a  S nU R                  0 SU_SU_SU_SU_SU_SU_S U_S!U_S"U_SU_S#S_SU_S$S_S%S_S&U_S'U_S(U_UU R                  US)5      U R                  US*5      U R                  US+5      US S S S UUS,.S S S-.US S-.US S-.U R                  U/ S.Q5      U R                  US/5      S-.S0.UUS1.E5      $ )2Nsymbol-r   r   r  FTminTickSizetickSizepricePrecisionstepSizequantityPrecisionrD   rB   /:1apiStateOpentrueapiStateCloseapiStateSellapiStateBuystatusminQtytradeMinQuantity
timeOnliner5   baser   settlebaseIdquoteIdsettleIdr  rC   rE   rF   r  r   r-  r   r   r   )amountrJ  r  )minNotionaltradeMinUSDTminTradeValuemaxNotional)rX  r  rJ  cost)r.  r   r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper  r  createdr  )r  splitr  r  rq  r  r{  r   r  safe_number_2r|  safe_market_structuresafe_number_n)rr  r  r5   symbolPartsr  r  r  r   r  checkIsInversecheckIsLinearr  r  r  r  r  rB   rD   r  r   r  isActive	isInverseisLinear	minAmountr  s                             rt  parse_marketbingx.parse_market  s   fh/hhsmQa.&&v.''0##FJ7&&v}="H!N!M((2))&*=!!..t/C/CDDTDTU[]mDn/opN ,,VZ@$ $ 1 1$2F2FtGWGWX^`sGt2u v ,v6v~v~e#cFl"F~~diir226t((-TV^4>TEUEUV\^mEnrxExH^^FN33v}8]8]cgcscstz  }E  dF  JM  dMH!D	 4}	**68=OPI&&v|<
?J)) 3+
"3+
f3+
 D3+
 U	3+

 f3+
 f3+
 w3+
 3+
 D3+
 D3+
 e3+
 D3+
 e3+
 e3+
 h3+
  !3+
" h#3+
$ !%%dG4%%dG4''i8("+'  
 %
 '
  --f6fg++FMB$ "e3+
 3 3	rv  c                    U R                  U5      /nU R                  U R                  SS5      nU(       d@  UR                  U R	                  U5      5        UR                  U R                  U5      5        UnU R                  US/ 5      nU R                  US/ 5      nU R                  US/ 5      nU R                  XV5      nU R                  Xx5      $ )a  
retrieves data on all markets for bingx

https://bingx-api.github.io/docs/#/spot/market-api.html#Query%20Symbols
https://bingx-api.github.io/docs/#/swapV2/market-api.html#Contract%20Information
https://bingx-api.github.io/docs/#/en-us/cswap/market-api.html#Contract%20Information

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
r  Fr   r   r   )r  r  rl  appendr  r  r  array_concat)	rr  r}  requestsr  promiseslinearSwapMarketsinverseSwapMarketsspotMarketsswapMarketss	            rt  fetch_marketsbingx.fetch_marketsO  s     ++F34NN4<<F	OOD;;FCDOOD33F;< NN8Q;!^^Ha<nnXq"5''(9N  ::rv  r   Nr  	timeframesincer_  c           	         U R                  5         SnU R                  USSS5      u  peU(       a  U R                  SXXBUS5      $ U R                  U5      nSUS   0nU R	                  U R
                  X"5      US'   Ub  [        US	-
  S
5      US'   Ub  XHS'   U R                  USS5      n	U	b  U R                  US/5      nXS'   Sn
US   (       a!  U R                  U R                  X5      5      n
OUS   (       a!  U R                  U R                  X5      5      n
OkU R	                  US5      nU R                  US5      nUS:X  a!  U R                  U R                  X5      5      n
O U R                  U R                  X5      5      n
U R                  U
S/ 5      n[        U[         5      (       d  U/nU R#                  XX#U5      $ )a  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://bingx-api.github.io/docs/#/swapV2/market-api.html#K-Line%20Data
https://bingx-api.github.io/docs/#/spot/market-api.html#Candlestick%20chart%20data
https://bingx-api.github.io/docs/#/swapV2/market-api.html#%20K-Line%20Data
https://bingx-api.github.io/docs/#/en-us/swapV2/market-api.html#Mark%20Price%20Kline/Candlestick%20Data
https://bingx-api.github.io/docs/#/en-us/cswap/market-api.html#Get%20K-line%20Data

: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 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   paginaterg  r  r5   intervalNr   r   	startTimer_  untilendTimerB   r.  rJ  rG  rx  )load_marketshandle_option_and_params"fetch_paginated_call_deterministicr  r  r   r]  safe_integer_2omitspotV1PublicGetMarketKlineextendcswapV1PublicGetMarketKlines$swapV1PublicGetMarketMarkPriceKlinesswapV3PublicGetQuoteKlines
safe_value
isinstancer   parse_ohlcvs)rr  r  r  r  r_  r}  r  r  requestr  r~  rJ  ohlcvss                rt  fetch_ohlcvbingx.fetch_ohlcvf  s   & 	88z[`a::<X]jprvwwV$fTl
 #..t	U
#&uqy!#4GK $G##FGY?YYvy1F!&I&>66t{{77STHi <<T[[=YZ((9673F?#HHU\IefH#>>t{{7?[\HH 626&$''XF  5IIrv  c           	         [        U[        5      (       ah  U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ U R	                  USS5      U R                  US	5      U R                  US
5      U R                  US5      U R                  US5      U R                  US5      /$ )Nr   r   r         r   time	closeTimeopenhighlowclosevolume)r  r   r|  r  r  )rr  ohlcvr  s      rt  parse_ohlcvbingx.parse_ohlcv  s    D eT""!!%+  *  *  *  *  *  v{;UF+UF+UE*UG,UH-
 	
rv  c                 ~   U R                  5         U R                  U5      nSUS   0nUb  [        US5      US'   SnSnU R                  SXT5      u  pUS:X  a!  U R	                  U R                  Xd5      5      nO U R                  U R                  Xd5      5      nU R                  US/ 5      n	U R                  XX#5      $ )	ae  
get the list of most recent trades for a particular symbol

https://bingx-api.github.io/docs/#/spot/market-api.html#Query%20transaction%20records
https://bingx-api.github.io/docs/#/swapV2/market-api.html#The%20latest%20Trade%20of%20a%20Trading%20Pair

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
r  r5   Nr;   r_  r   rB   rx  )	r  r  r  handle_market_type_and_paramsspotV1PublicGetMarketTradesr  swapV2PublicGetQuoteTradesr  parse_trades)
rr  r  r  r_  r}  r  r  r~  
marketTypetradess
             rt  fetch_tradesbingx.fetch_trades  s     	V$fTl
 "5#GG
!??v^
77G8TUH66t{{77STHD &"5  >>rv  tradec                    U R                  U/ SQ5      nU R                  US5      nUb  U R                  U5      nUS:X  a  S nU R                  US5      nU R                  U/ SQ5      nU R	                  U5      nU R                  US5      nU R                  USS5      n	U R                  U/ S	Q5      n
S nU
c  Ub  U
(       d  U(       a  S
OSnU R                  USS5      nUc  U
c  Ub  U
(       d  U(       a  SOSnSnU R                  US5      nUb  U(       a  SOSnU R                  US5      nUb  U(       a  S
OSnU R                  U/ SQ5      nUbN  US   (       aD  SU;   a>  U R                  US   S5      nU R                  US5      n[        R                  " UU5      nU R                  U R                  USS/5      UUU R                  U5      U R                  XS5      U R                  USS5      U R                  US5      U R                  U5      UU R                  U/ SQ5      UUU R!                  [        R"                  " U R                  USS5      5      5      US .S!.U5      $ )"N)r!  filledTmT	tradeTimer6  r   quoteQty)r  NcommissionAssetmsr  )
buyerMakerisBuyerMakerr   r   r   sideSsellbuyisBuyerisMaker)qtyr  qrD   r'  r  r  r5   tr  orderIdr  o)rJ  p
tradePrice
commissionn)r  r  )r5   r  	timestampdatetimer  orderr  r@  takerOrMakerrJ  r  r  r  )safe_integer_nr  	parse8601safe_string_nr  r  safe_string_2safe_bool_nsafe_string_lower_2r/   
string_mul
safe_tradeiso8601safe_symbolsafe_string_lowerparse_order_siderq  
string_abs)rr  r4  r  r!  
datetimeIdr  r  currencyCoder<  marketIdr?  takeOrMakerr@  rD  rE  r  r  r'  s                     rt  parse_tradebingx.parse_trade3  sp   X ""5*PQ%%eZ8
!>>*-D19Dz2''/ST
..z:NN5#&%%eS(;''/VW$!-&2a'gK''vs;<(am".!v%%..	2#5D..	2%,''K##E+ABF6NE8I++F6N<NOL%%eX6F''=F$$UT3K8T*&&x=''y#>**5#6))$/'''/KL))'*<*<T=O=OPUWceh=i*jk( 
" # 	rv  c           	      "   U R                  5         U R                  U5      nSUS   0nUb  X%S'   SnSnU R                  SXC5      u  psUS:X  a!  U R                  U R	                  XS5      5      nOKUS   (       a!  U R                  U R	                  XS5      5      nO U R                  U R	                  XS5      5      nU R                  US0 5      nU R                  US	5      n	U R                  US
S5      n
U R                  XS   U
SSSS5      nXS'   U$ )a  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://bingx-api.github.io/docs/#/spot/market-api.html#Query%20depth%20information
https://bingx-api.github.io/docs/#/swapV2/market-api.html#Get%20Market%20Depth
https://bingx-api.github.io/docs/#/en-us/cswap/market-api.html#Query%20Depth%20Data

:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: the maximum amount of order book entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
r  r5   Nr_  r   rB   r.  rx  lastUpdateIdr7  tsbidsasksr   r   nonce)r  r  r,  spotV1PublicGetMarketDepthr  cswapV1PublicGetMarketDepthswapV2PublicGetQuoteDepthr{  r|  r  parse_order_book)rr  r  r_  r}  r  r  r~  r0  	orderbookrk  rO  r  s               rt  fetch_order_bookbingx.fetch_order_book  s#    	V$fTl
 $G
!??@PRXa
66t{{77STHi ;;DKK<XY99$++g:VWV NN8VR8	!!)^<''	3=	&&y2BIvW]_`bcdwrv  c                 2   U R                  5         U R                  U5      nSUS   0nSnUS   (       a!  U R                  U R                  XB5      5      nO U R	                  U R                  XB5      5      nU R                  US5      nU R                  Xc5      $ )a  
fetch the current funding rate

https://bingx-api.github.io/docs/#/swapV2/market-api.html#Current%20Funding%20Rate
https://bingx-api.github.io/docs/#/en-us/cswap/market-api.html#Price%20&%20Current%20Funding%20Rate

: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  r5   Nr.  rx  )r  r  "cswapV1PublicGetMarketPremiumIndexr   swapV2PublicGetQuotePremiumIndexr{  parse_funding_raterr  r  r}  r  r  r~  rx  s          rt  fetch_funding_ratebingx.fetch_funding_rateB  s     	V$fTl
 )>>t{{7?[\H<<T[[=YZH" ~~h/&&t44rv  r  c                     U R                  5         U R                  USS5      nU R                  U R                  U5      5      nU R	                  US/ 5      nU R                  XA5      $ )ax  
fetch the current funding rate for multiple symbols

https://bingx-api.github.io/docs/#/swapV2/market-api.html#Current%20Funding%20Rate

:param str[] [symbols]: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
rD   Trx  )r  market_symbolsru  r  r  parse_funding_rates)rr  r  r}  r~  rx  s        rt  fetch_funding_ratesbingx.fetch_funding_ratesj  s`     	%%gvt<88V9LM~~h3''66rv  c                 \   U R                  US5      nU R                  US5      n0 SU_SU R                  X2SS5      _SU R                  US5      _SU R                  US5      _SS _S	S _S
S _SS _SU R                  US5      _SS _SS _SS _SU_SU R	                  U5      _SS _SS _SS _SS 0E$ )Nr  nextFundingTimer  r  rD   	markPrice
indexPriceinterestRateestimatedSettlePricerO  rP  fundingRatelastFundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer	  )r  r|  r\  r  r[  )rr  r   r  rb  r  s        rt  rv  bingx.parse_funding_ratez  sJ    ##Hh7#00;LM
H
d&&xfE
 ))(K@
 $**8\B	

 D
 #D
 
 
 4++H6GH
 
 t
 t
 #$8
 "4<<0D#E
 "4
  '!
" &t#
$ %
 	
rv  c                    Uc  [        U R                  S-   5      eU R                  5         SnU R                  USS5      u  pTU(       a  U R	                  SXUSU5      $ U R                  U5      nSUS   0nUb  X'S'   Ub  X7S	'   U R                  US
S5      nUb  U R                  US
/5      nXS'   U R                  U R                  Xt5      5      n	U R                  U	S/ 5      n
U R                  XX#5      $ )a  
fetches historical funding rate prices

https://bingx-api.github.io/docs/#/swapV2/market-api.html#Funding%20Rate%20History

: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 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 [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
z5 fetchFundingRateHistory() requires a symbol argumentFrt   r  8hr  r5   r
  r_  r  rx  )r%   r5   r  r  r  r  r  r  swapV2PublicGetQuoteFundingRater  r  parse_funding_rate_histories)rr  r  r  r_  r}  r  r  r  r  r~  rx  s              rt  fetch_funding_rate_history bingx.fetch_funding_rate_history  s    >#DGG.e$eff88AZ\fg::;TV\ejlprxyyV$fTl
 #(K $G##FG[AYYvy1F#(K 77G8TU ~~h300uLLrv  c                     U R                  US5      nUU R                  U R                  US5      USS5      U R                  US5      UU R	                  U5      S.$ )NfundingTimer  r  rD   r  )r  r  r  rO  rP  )r|  r\  r  r  r[  )rr  r   r  rO  s       rt  parse_funding_rate_history bingx.parse_funding_rate_history  se     %%h>	&&t'7'7('KVUXZ`a++HmD"Y/
 	
rv  c                    U R                  5         U R                  U5      nSUS   0nSnUS   (       a!  U R                  U R                  XB5      5      nO U R	                  U R                  XB5      5      n0 nUS   (       a'  U R                  US/ 5      nU R                  US0 5      nOU R                  US0 5      nU R                  Xc5      $ )a  
retrieves the open interest of a trading pair

https://bingx-api.github.io/docs/#/swapV2/market-api.html#Get%20Swap%20Open%20Positions
https://bingx-api.github.io/docs/#/en-us/cswap/market-api.html#Get%20Swap%20Open%20Positions

: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  r5   Nr.  rx  r   )r  r  "cswapV1PublicGetMarketOpenInterestr   swapV2PublicGetQuoteOpenInterestr  r{  parse_open_interest)rr  r  r}  r  r  r~  r  rx  s           rt  fetch_open_interestbingx.fetch_open_interest  s     	V$fTl
 )>>t{{7?[\H<<T[[=YZH: )>>(FB7D^^D!R0F^^Hfb9F''77rv  c                     U R                  USS5      nU R                  US5      nU R                  XBSS5      nU R                  US5      nU R	                  US S S UUU R                  U5      US.U5      $ )Nr!  rO  r  r  rD   openInterest)r  
baseVolumequoteVolumeopenInterestAmountopenInterestValuerO  rP  r  )r  r  r\  r  safe_open_interestr[  )rr  interestr  rO  r5   r  r  s          rt  r  bingx.parse_open_interest  s    $ ''&+F	h1!!"c6:''.A&&"&!-"Y/	(
 	 		rv  c                    U R                  5         U R                  U5      nSUS   0nSnUS   (       a!  U R                  U R                  XB5      5      nOKUS   (       a!  U R	                  U R                  XB5      5      nO U R                  U R                  XB5      5      nU R                  US5      nUb$  U R                  US0 5      nU R                  Xs5      $ U R                  US0 5      nU R                  X5      $ )ao  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://bingx-api.github.io/docs/#/en-us/swapV2/market-api.html#Get%20Ticker
https://bingx-api.github.io/docs/#/en-us/spot/market-api.html#24-hour%20price%20changes
https://bingx-api.github.io/docs/#/en-us/cswap/market-api.html#Query%2024-Hour%20Price%20Change

:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
r  r5   NrB   r.  rx  r   )	r  r  spotV1PublicGetTicker24hrr  cswapV1PublicGetMarketTickerswapV2PublicGetQuoteTickerr  r{  parse_ticker)	rr  r  r}  r  r  r~  rx  firstdataDicts	            rt  fetch_tickerbingx.fetch_ticker9  s     	V$fTl
 &>55dkk'6RSHi <<T[[=YZ::4;;w;WX: ~~h/NN4B/E$$U33>>(FB7  22rv  c                    U R                  5         SnUb7  U R                  U5      nU R                  US5      nUb  U R                  U5      nSnU R	                  SX25      u  pRSnU R                  SX25      u  pbSnUS:X  a  U R                  U5      nO)US:X  a  U R                  U5      nOU R                  U5      nU R                  US5      nU R                  X5      $ )a  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://bingx-api.github.io/docs/#/en-us/swapV2/market-api.html#Get%20Ticker
https://bingx-api.github.io/docs/#/en-us/spot/market-api.html#24-hour%20price%20changes
https://bingx-api.github.io/docs/#/en-us/cswap/market-api.html#Query%2024-Hour%20Price%20Change

:param str[]|None 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
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr   r   rB   r.  rx  )r  r{  r  r  r,  handle_sub_type_and_paramsr  r  r  r  parse_tickers)	rr  r  r}  r  firstSymbolr  subTyper~  tickerss	            rt  fetch_tickersbingx.fetch_tickersu  s     	))'2G**7A6K&[199.&Y99.&Y6>55f=H)#<<VD::6B< ..62!!'33rv  c                    U R                  5         U R                  U5      nSnU R                  SX2S5      u  pBSUS   0nSnUS:X  a!  U R                  U R	                  XR5      5      nO U R                  U R	                  XR5      5      n[        US   [        5      (       a&  U R                  U R                  US   S0 5      U5      $ U R                  US   U5      $ )	a  
fetches mark prices for the market

https://bingx-api.github.io/docs/#/en-us/swapV2/market-api.html#Mark%20Price%20and%20Funding%20Rate

:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr   r-  r  r5   r.  rx  r   )
r  r  r  rt  r  ru  r  r   r  r{  )rr  r  r}  r  r  r  r~  s          rt  fetch_mark_pricebingx.fetch_mark_price  s     	V$99:JF\defTl
 i>>t{{7?[\H$ <<T[[=YZH hv&--$$T^^HV4Da%LfUU  &!16::rv  c                 d   U R                  5         SnUb7  U R                  U5      nU R                  US5      nUb  U R                  U5      nSnU R	                  SX2S5      u  pRSnUS:X  a  U R                  U5      nOU R                  U5      nU R                  US5      nU R                  Xq5      $ )a  
fetches mark prices for multiple markets

https://bingx-api.github.io/docs/#/en-us/swapV2/market-api.html#Mark%20Price%20and%20Funding%20Rate

: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
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr   r   r-  r.  rx  )	r  r{  r  r  r  rt  ru  r  r  )rr  r  r}  r  r  r  r~  r  s           rt  fetch_mark_pricesbingx.fetch_mark_prices  s     	))'2G**7A6K&[199:KV]efi>>vFH<<VDH< ..62!!'33rv  tickerc           
         U R                  US5      nU R                  US5      nUc  SOSnU R                  X2S U5      nUS   nU R                  US5      nU R                  US5      nU R                  US5      n	U R                  US5      n
U R                  US	5      nU R                  US
5      nU R                  US5      nUb  UR                  SS5      nU R                  US5      nU R                  US5      nUS:X  a  S nU R	                  U5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  0 SU_SU_SU_SU_SU	_SU_SU_SU_SU_SS _SU_SU
_S S _S!S _S"U_S#U_S$S _UUU R                  US%5      U R                  US&5      US'.EU5      $ )(Nr  lastQtyrB   rD   	openPrice	highPricelowPrice	lastPricer  r'  priceChangePercent% priceChanger"  r   bidPricebidQtyaskPriceaskQtyrO  rP  r$  r%  bid	bidVolumeask	askVolumevwapr#  r&  rF  previousClosechange
percentageaverager  r  )r  r  r  r  r  )r  safe_marketreplacer|  r[  safe_ticker)rr  r  r  rb  r  r  r  r#  r$  r%  r&  r  r  r  r  rh  rP  r  r  r  r  s                        rt  r  bingx.parse_ticker#  s   d ##FH5""695 "/v!!(D$?!44vz2  5&&v}=%%fh7
%%f.BC
!#++C4J!!&-8v{37B<<#vz2$$VX6	vz2$$VX6	 !
f!
!
 !
 D	!

 3!
 3!
 !
 3!
 !
 D!
 D!
 U!
 D!
 T!
 f!
  *!!
" t#!
$ %&))&+>**6<@-!
. / 	rv  c                    U R                  5         SnSnU R                  USSS5      u  p1SnU R                  SSU5      u  pAU R                  SSU5      u  pVU(       a  U R	                  U5      nO_US:X  d  US:X  a  U R                  U5      nOAUS:X  a  U R                  U5      nO)US:X  a  U R                  U5      nOU R                  U5      nU R                  U5      $ )	a  
query for balance and get the amount of funds available for trading or funds locked in orders

https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Assets
https://bingx-api.github.io/docs/#/en-us/swapV2/account-api.html#Query%20account%20data
https://bingx-api.github.io/docs/#/standard/contract-interface.html#Query%20standard%20contract%20balance
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Account%20Assets

:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.standard]: whether to fetch standard contract balances
:param str [params.type]: the type of balance to fetch(spot, swap, funding) default is `spot`
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nr`   standardFr,  r   rB   r.  )
r  r  r  r,  contractV1PrivateGetBalancefundV1PrivateGetAccountBalancespotV1PrivateGetAccountBalancecswapV1PrivateGetUserBalanceswapV3PrivateGetUserBalanceparse_balance)rr  r}  r~  r  r  r0  marketTypeQuerys          rt  fetch_balancebingx.fetch_balance  s     	88Q[]bc99.$PVW&*&H&HY]_e&f#
77HH& I%:+?::?KH 6!::?KH$ )#<<_M*  ;;OL( !!(++rv  c                    SU0nU R                  US5      nU R                  US5      nUS LnU R                  US0 5      nU R                  USS/ 5      nU(       a  [        S[	        U5      5       H  nX8   n	U R                  U	S5      n
U
c    OU R                  U
5      nU R                  5       nU R                  U	SS5      US	'   U R                  U	S
5      US'   U R                  U	S5      US'   XU'   M     O[        S[	        U5      5       Hh  nXx   n	U R                  U	S5      n
U R                  U
5      nU R                  5       nU R                  U	S	5      US	'   U R                  U	S5      US'   XU'   Mj     U R                  U5      $ )Nr  rx  r   balancesr   r   availableMarginavailableBalancefree
usedMarginusedmaxWithdrawAmounttotallocked)
r  r{  safe_list_2r  r  r  r  r   rV  safe_balance)rr  r~  r  contractBalancesfirstContractBalances
isContractspotDataspotBalancesr  r   r  r  r   s                rt  r  bingx.parse_balance  s   ^ )>>(F; $/? C*$6
>>(FB7''*hK1c"234*-!--gw?
%..z:,,."&"4"4W>OQc"d"&"2"27L"I#'#3#3G=P#Q &t 5 1c,/0&/!--gw?
..z:,,."&"2"27F"C"&"2"27H"E&t 1   ((rv  c                    U R                  5         U R                  U5      nSUS   0nUb  X6S'   Ub  X&S'   U R                  SXd5      u  pdSnUS   (       a!  U R                  U R	                  Xd5      5      nO[        U R                  S-   5      eU R                  US	0 5      nU R                  US
/ 5      n	U R                  U	5      n
U R                  XX#5      $ )a  
fetches historical positions

https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Position%20History

:param str symbol: unified contract symbol
:param int [since]: the earliest time in ms to fetch positions for
:param int [limit]: the maximum amount of records to fetch
:param dict [params]: extra parameters specific to the exchange api endpoint
:param int [params.until]: the latest time in ms to fetch positions for
:returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
r  r5   NpageSizestartTsendTsr-  zC fetchPositionHistory() is not supported for inverse swap positionsrx  positionHistory)r  r  handle_until_option$swapV1PrivateGetTradePositionHistoryr  r+   r5   r{  r  parse_positionsfilter_by_symbol_since_limit)rr  r  r  r_  r}  r  r  r~  rx  records	positionss              rt  fetch_position_historybingx.fetch_position_historyj	  s     	V$fTl
 "'J!&I227GL(@@WA]^Htww)nnoo: ~~h3..'8"=((1	00EQQrv  c                    U R                  5         U R                  U5      nSnU R                  USSS5      u  p2SnU(       a  U R                  U5      nO{SnUb7  U R                  U5      nU R	                  US5      nUb  U R                  U5      nSnU R                  SXR5      u  prUS:X  a  U R                  U5      nOU R                  U5      nU R                  US/ 5      nU R                  X5      $ )aP  
fetch all open positions

https://bingx-api.github.io/docs/#/en-us/swapV2/account-api.html#Query%20position%20data
https://bingx-api.github.io/docs/#/en-us/standard/contract-interface.html#position
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20warehouse

:param str[]|None symbols: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.standard]: whether to fetch standard contract positions
:returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
Nr   r  Fr   r.  rx  )r  r{  r  contractV1PrivateGetAllPositionr  r  r  cswapV1PrivateGetUserPositionsswapV2PrivateGetUserPositionsr  r   )	rr  r  r}  r  r~  r  r  r  r  s	            rt  fetch_positionsbingx.fetch_positions	  s    	%%g.88AQS]_de;;FCHF"--g6"..w:*![[5FG"==>NPV_OG)#>>vF8  ==fE@ NN8VR8	##I77rv  c                    U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nSnUS   (       a!  U R	                  U R                  XB5      5      nO U R                  U R                  XB5      5      nU R                  US/ 5      nU R                  US0 5      nU R                  Xs5      $ )	a  
fetch data on a single open contract trade position

https://bingx-api.github.io/docs/#/en-us/swapV2/account-api.html#Query%20position%20data
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20warehouse

: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>`
rD   z+ fetchPosition() supports swap markets onlyr  r5   Nr.  rx  r   )
r  r  r&   r5   r  r  r	  r  r{  parse_position)rr  r  r}  r  r  r~  rx  r  s           rt  fetch_positionbingx.fetch_position
  s     	V$f~TWW'TTUUfTl
 )::4;;w;WXH8 99$++g:VWH@ ~~h3tQ+""511rv  positionc                    U R                  USS5      nUR                  SS5      nU R                  US5      nS nUb  U(       a  SOSnU R                  US5      nU R	                  0 SU_S	U R                  US
5      _SU R                  X2SS5      _SU R                  US5      _SU_SS _SU R                  USS5      _SU R                  US5      _SU R                  US5      _SS _SU R                  US5      _SS _SU R                  US5      _SS _SU R                  US5      _SS _SU_U R                  U5      U R                  US 5      S S S U R                  US!5      S U R                  US"5      S S S S#.E5      $ )$Nr  r  r  r  isolatedcrossopenTimer  r5   
positionIdrD   notionalpositionValuerO  liquidationPrice
entryPriceavgPriceunrealizedPnlunrealizedProfitrealizedPnlrealisedProfitr  	contractspositionAmtr  r  r  r@  positionSiderV  rO  
updateTimeinitialMarginrX  )rP  lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralr#  initialMarginPercentagerX  marginRatiorR  rS  )
r  r  r  r|  safe_positionr\  r  r  r]  r[  )rr  r  r  rb  r  rO  rO  s          rt  r  bingx.parse_positionX
  s   f ##Hh;##C->>(J7
'/WJ%%h
;	!! #
H#
$""8\:#
 d&&xfE#
 ((?C	#

 *#
 #
 $,,Xz<P#
 T--h8JK#
 4++H6FG#
 $#
 ))(MB#
 D#
 ))(K@#
 #
 D**8^D#
  d!#
" ##
$ Y/#'#4#4X|#L!%+/!--hH'+((:>!#9#
  	rv  r@  r  c                 4    X4S'   U R                  USX#SU5      $ )a  
create a market order by providing the symbol, side and cost
: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>`
quoteOrderQtyr  Ncreate_order)rr  r  r@  r  r}  s        rt  create_market_order_with_cost#bingx.create_market_order_with_cost
  s%     #'  4tVLLrv  c                 6    X#S'   U R                  USSUSU5      $ )an  
create a market buy order by providing the symbol and cost
: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>`
r-  r  rC  Nr.  rr  r  r  r}  s       rt  !create_market_buy_order_with_cost'bingx.create_market_buy_order_with_cost
  s'     #'  5$fMMrv  c                 6    X#S'   U R                  USSUSU5      $ )ao  
create a market sell order by providing the symbol and cost
: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>`
r-  r  rB  Nr.  r3  s       rt  "create_market_sell_order_with_cost(bingx.create_market_sell_order_with_cost
  s'     #'  64vNNrv  r  r  rJ  c           
      @   U R                  U5      nSnSn	U R                  SXv5      u  pUR                  5       nUS   UUR                  5       S.n
US:H  nU	S:H  nUS:H  nU(       a  U(       a  [        U R                  S-   5      eU R                  US	5      nU R                  US
5      nU R                  USS5      nUSLnUSLnUSLnU(       a  SOSnU R                  UUS5      nUb  UU
U'   U R                  US5      nU R                  UUS:H  U5      u  pU(       d  US:X  a  SU
S'   OUS:X  a  SU
S'   OUS:X  a  SU
S'   U(       Ga  U R                  USS5      nU R                  US5      nUb%  U R                  U R                  UU5      5      U
S'   OwU(       aM  UbJ  [        R                  " U R                  U5      U R                  U5      5      nU R                  U5      U
S'   O#U R                  U R                  X5      5      U
S'   U(       d#  U R                  U R!                  X5      5      U
S'   Uba  U(       a+  U R                  U
S5      c  [#        U R                  S-   5      eU R!                  UU5      U
S'   US:X  a  SU
S'   GOkUS:X  a  SU
S'   GO^Uc  UbB  Ub  UOUnUS:X  a  SU
S'   OUS:X  a  SU
S'   U R                  U R!                  UU5      5      U
S'   GOU(       ae  U
S   U
S    US!:X  a  S"OS#U R                  U R!                  UU5      5      U R                  U R                  X5      5      S$.nU R%                  UU5      $ US%:X  a  S%U
S'   U R                  US&5      nU R                  US'S(5      nU R                  US)S*5      nUSLnUSLnU=(       d    Un U R'                  US+5      n!U R'                  US,5      n"U!SLn#U"SLn$US:X  d  US:X  d  US-:X  d  US.:X  a*  U (       d#  U R                  U R!                  X5      5      U
S'   U R)                  US/S05      n%U(       aK  U R                  U R!                  UU5      5      U
S'   U(       d  US:X  a  SU
S'   GOUS:X  d  US:X  a  SU
S'   GOU(       d  U(       a  S1n%U(       aH  U R                  U R!                  X5      5      U
S'   U(       d  US2:X  a  S2U
S'   OUS:X  d  US-:X  a  S-U
S'   OU(       aG  U R                  U R!                  X5      5      U
S'   U(       d  US3:X  a  S3U
S'   OlUS:X  d  US.:X  a  S.U
S'   OZU (       aS  UU
S'   U(       a  U R                  U5      U
S'   O2U(       a+  [        R*                  " US45      n&U R                  U&5      U
S('   U#(       d  U$(       Ga  U R                  U5      n'U#(       a  U R                  U!SSU!5      n(U R                  U!S5S65      n)U R                  U!SS25      n*U R                  U R!                  UU(5      5      U)U*S7.n+U R                  U!S5      n,U,b$  U R                  U R!                  UU,5      5      U+S'   U R                  U!SU'5      n-U R                  U R                  UU-5      5      U+S'   U R-                  U+5      U
S+'   U$(       a  U R                  U"SSU"5      n.U R                  U"S5S65      n/U R                  U"SS35      n0U R                  U R!                  UU.5      5      U/U0S7.n1U R                  U"S5      n,U,b$  U R                  U R!                  UU,5      5      U1S'   U R                  U"SU'5      n2U R                  U R                  UU25      5      U1S'   U R-                  U15      U
S,'   Sn3U R)                  US8S05      n4U4(       a/  U R                  US/5      nU%(       a  US!:X  a  S#OS"n3OUS!:X  a  S"OS#n3OS9n3U3U
S:'   Un5US;   (       d   U R                  U R                  X5      5      n5U5U
S'   U R                  U/ S<Q5      nU R%                  X5      $ )=aB  
@ignore
       helper function to build 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 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: request to be sent to the exchange
       NrT   r5   )r  r  r@  MARKETrB   TWAPz6 createOrder() twap order supports swap contracts onlyrR  rS  	stopPricerP  newClientOrderIdclientOrderIDclientOrderIdrU  PostOnlyrK  GTCr  r-  quantityrJ  zl createOrder() requires the cost parameter(or the amount + price) for placing spot market-buy trigger ordersLIMITTRIGGER_LIMITr  TRIGGER_MARKETTAKE_STOP_LIMITTAKE_STOP_MARKETr  r@  rC  LONGSHORT)r  r@  r!  rP  totalAmountrL  trailingAmounttrailingPercent	priceRatetrailingTypeTRAILING_STOP_MARKETstopLoss
takeProfitSTOPTAKE_PROFIT
reduceOnlyFTSTOP_MARKETTAKE_PROFIT_MARKET100workingType
MARK_PRICE)r<  rX  r  rV  BOTHr!  r.  )
rV  rP  rR  rS  rK  rL  rN  rQ  rP  r?  )r  r,  upperr'   r5   r  rV  safe_string_upperhandle_post_onlyr  parse_to_numericcost_to_precisionr/   rY  number_to_stringamount_to_precisionprice_to_precisionr%   r  r  r  
string_divjson)6rr  r  r  r@  r  rJ  r}  r  postOnlyr0  r  isMarketOrderisSpotisTwapOrderrR  rS  rP  isTriggerOrderisStopLossPriceOrderisTakeProfitPriceOrderexchangeClientOrderIdr?  rU  r  calculatedCoststopTakePricetwapRequestrK  rL  rN  isTrailingAmountOrderisTrailingPercentOrder
isTrailingrP  rQ  
isStopLossisTakeProfitrT  requestTrailingPercentstringifiedAmountslTriggerPriceslWorkingTypeslType	slRequestslPrice
slQuantitytkTriggerPricetkWorkingTypetpType	tpRequest
tkQuantityr!  rV  	amountReqs6                                                         rt  create_order_requestbingx.create_order_request
  s    V$
!??v^
zz|TlJJL

 (v%fn6DGG&^^__((A**63DE))&+~N%T1,D8!0!<6< 2/**63H/Z$-:G)*,,V]C00z@Y[abz1%/GM"E!%*GM"E!%*GM"%%ffoFDYYvv.F+/+@+@AWAWX^`dAe+f( e&7%,%7%78M8Mf8UW[WlWlmrWs%tN/3/D/D^/TGO,*.*?*?@X@XY_@h*iGJ' #'#8#89P9PQW9_#` ' T%5%5g%O%W+DGG  7e  -e  f  f'+'>'>v|'T$7?&5GFOX%&6GFO+1L2?2KRa7?&7GFOX%&8GFO'+'<'<T=T=TU[]j=k'l$%h/#FO/3u}F7$($9$9$:Q:QRXZf:g$h#'#8#89Q9QRX9a#b%$ {{;77e#).&!--f6FGN"009JKXO++FNDZ[L$2$$>!%4D%@".H2HJvz:H>J!-J%T1Ldo&=46>W[_lWl  xB#'#8#89P9PQW9_#` eDJ'+'<'<T=T=TU[]i=j'k$ T-=%=&6GFOgo4?+B&5GFO%)?!
'+/+@+@AXAXY_Ao+pGK($)>*7'/tv~*0++/+@+@AXAXY_Aq+rGK($1E)E*>'/t}/D*7".('+'<'<^'LGG$+-4-?-?QV-W*+/+@+@AW+XGK(\$($9$9&$A!%)%7%7.R]_g%hN$($4$4X}l$[M!--hNF%)%:%:4;R;RSY[i;j%k'4 &'I
 #..xAG*-1-B-B4CZCZ[acjCk-l	'*!%!1!1(JHY!ZJ,0,A,A$BZBZ[acmBn,oIj)*.))I*>GJ'%)%7%7
NT_ak%lN$($4$4ZP\$]M!--j&BVWF%)%:%:4;R;RSY[i;j%k'4 &'I
 #..z7CG*-1-B-B4CZCZ[acjCk-l	'*!%!1!1*jJ[!\J,0,A,A$BZBZ[acmBn,oIj),0IIi,@GL)L^^FHe<F6<8/3u}76L.2em6'L%&2GN#I)$ 11$2J2J62Z[	"+GJ6  $B  C{{7++rv  c                    U R                  5         U R                  U5      nU R                  USS5      nU R                  US5      nU R	                  XX4XV5      n	Sn
US   (       a_  U(       a  U R                  U	5      n
OWUS   (       a  U R                  U	5      n
O;US:X  a  U R                  U	5      n
O#U R                  U	5      n
OU R                  U	5      n
[        U
[        5      (       a"  U R                  U
5      n
U R                  U
5      n
U R                  U
S0 5      n0 nUS   (       a!  US   (       a  U
nOU R                  USU5      nOUnU R                  X5      $ )	a	  
create a trade order

https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Trade%20order
https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Create%20an%20Order
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Trade%20order
https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Place%20TWAP%20Order

: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 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.clientOrderId]: a unique id for the order
:param bool [params.postOnly]: True to place a post only order
:param str [params.timeInForce]: spot supports 'PO', 'GTC' and 'IOC', swap supports 'PO', 'GTC', 'IOC' and 'FOK'
:param bool [params.reduceOnly]: *swap only* True or False whether the order is reduce only
:param float [params.triggerPrice]: triggerPrice at which the attached take profit / stop loss order will be triggered
:param float [params.stopLossPrice]: stop loss trigger price
:param float [params.takeProfitPrice]: take profit trigger price
:param float [params.cost]: the quote quantity that can be used alternative for the amount
:param float [params.trailingAmount]: *swap only* the quote amount to trail away from the current market price
:param float [params.trailingPercent]: *swap only* the percent to trail away from the current market price
:param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered
:param float [params.takeProfit.triggerPrice]: take profit trigger price
:param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered
:param float [params.stopLoss.triggerPrice]: stop loss trigger price
:param boolean [params.test]: *swap only* whether to use the test endpoint or not, default is False
:param str [params.positionSide]: *contracts only* "BOTH" for one way mode, "LONG" for buy side of hedged mode, "SHORT" for sell side of hedged mode
:param boolean [params.hedged]: *swap only* whether the order is in hedged mode or one way mode
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r   FNrD   r.  twaprx  rQ  )r  r  r  r  r  swapV2PrivatePostTradeOrderTestcswapV1PrivatePostTradeOrderswapV1PrivatePostTwapOrderswapV2PrivatePostTradeOrderspotV1PrivatePostTradeOrderr  strfix_stringified_json_members
parse_jsonr{  parse_order)rr  r  r  r@  r  rJ  r}  r  r   r  r~  rx  r  s                rt  r/  bingx.create_order  sF   D 	V$~~ffe466*++F$V&>??H	"<<WE::7C;;GD77@HB h$$ 88BHx0H~~h3&>i !gt<F//rv  ordersc           	          U R                  5         / n/ n[        S[        U5      5       H  nX   nU R                  US5      nU R                  US5      nUR	                  U5        U R                  US5      n	U R                  US5      n
U R                  US5      nU R                  US0 5      nU R                  XxXX5      nUR	                  U5        M     U R                  USS	S
S
5      n[        U5      nU R                  US   5      n0 nSnUS   (       aD  US:  a  [        U R                  S-   5      eU R                  U5      US'   U R                  U5      nODU R                  USS	5      nU(       a  S
US'   U R                  U5      US'   U R                  U5      n[!        U["        5      (       a"  U R%                  U5      nU R'                  U5      nU R                  US0 5      nU R)                  US/ 5      nU R+                  UU5      $ )a  
create a list of trade orders

https://bingx-api.github.io/docs/#/spot/trade-api.html#Batch%20Placing%20Orders
https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Bulk%20order

: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
:param boolean [params.sync]: *spot only* if True, multiple orders are ordered serially and all orders do not require the same symbol/side/type
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r   r  r  r@  r  rJ  r}  NFTrD   r   zJ createOrders() can not create more than 5 orders at once for swap marketsbatchOrderssyncrx  r  )r  r  r  r  r  r  r{  r  r{  r  r)   r5   rd  !swapV2PrivatePostTradeBatchOrdersr  !spotV1PrivatePostTradeBatchOrdersr  r  r  r  r  parse_orders)rr  r  r}  ordersRequests	marketIdsr  rawOrderrb  r  r@  r  rJ  orderParamsorderRequestr  symbolsLengthr  r  r~  r  rx  r  s                         rt  create_ordersbingx.create_orders3  s     		q#f+&AyH''(;H##Hf5DX&##Hf5D%%h9F$$Xw7E..8R@K44XTSXfL!!,/ ' %%iudDIGWQZ(&>q "477-y#yzz%)YY~%>GM"==gFH>>&&%8D"&"ii7GFO==gFH\ h$$ 88BHx0H~~h3h3  00rv  c                 8    SSSSSSS.nU R                  X!U5      $ )NrC  rB  )BUYSELLrI  rH  r  r  r  )rr  r@  sidess      rt  r^  bingx.parse_order_side  s0    
 T22rv  c                 8    SSSSSSS.nU R                  X!U5      $ )Nr  r_  )trigger_markettrigger_limit
stop_limitstop_markettake_profit_marketstopr  )rr  r  typess      rt  parse_order_typebingx.parse_order_type  s0    &$!#"*
 T22rv  rQ  c                 D   UnU R                  USS5      nUb  UnU R                  USS5      nUc  SOSnU R                  USS5      nUc  U R                  US S U5      nU R                  US	S
5      nU R	                  U/ SQ5      n	U R                  USS5      n
U R                  U/ SQ5      nU R                  USS5      nU R                  U/ SQ5      nUc!  US   (       a  US:X  a  US   nOUS   nOUS   nU R                  US5      nS nUb'  US:w  a!  U R                  U R                  US5      5      nUbl  [        U[        R                  5      (       dM  US:w  aG  [        U[        5      (       a  U R                  U5      nU R                  U R                  US5      5      nU R                  US5      nS nUb'  US:w  a!  U R                  U R                  US5      5      nUbl  [        U[        R                  5      (       dM  US:w  aG  [        U[        5      (       a  U R                  U5      nU R                  U R                  US5      5      nU R                  USS5      nU R                  U R                  USS5      5      nUnUb8  UR!                  S5      S:  a  Uc  UnS nUR!                  S5      S:  a  Uc  UnS nU R#                  0 SU_S U R                  U/ S!Q5      _S"U R                  U/ S#Q5      _SU R%                  XrS$U5      _S%U	_S&U R'                  U	5      _S'U
_S(U R)                  US5      _SU R+                  U5      _S)U R                  US)5      _S*S _S	U R-                  U5      _S+U R                  US+S,5      _S-U_S.U_S/U_S0U R                  US1S25      _U R                  US35      U R                  U/ S4Q5      U R                  US5S65      S U R/                  U5      U[0        R2                  " U5      S7.S U R5                  US8S95      S:.EU5      $ );NnewOrderResponseorderOpenResponser!  psrB   rD   r  r=  r@  rA  )r!  transactTimeEcreatedTimer"  r7  )r  XorderStatusfeeAssetr:  )r  rM  rN  rC  r  r   rP  r  r<  rQ  r  rJ  	StopPricer  taker  r5   )rI  r  mainOrderIdr?  )r>  r?  origClientOrderIdcr  rO  rP  lastTradeTimestampr$  rU  re  rJ  rK  rP  rR  rS  r  r  apcummulativeQuoteQty)origQtyrG  rB  rJ  executedQtyz)r  r  rT  ro)r  r  filled	remainingr  r  r1  rT  )safe_dict_2rV  r  rX  rS  r  safe_string_upper_nrU  r  	omit_zeror  r  numbersRealr  r  find
safe_orderr\  r[  r|  r  r^  parse_order_statusr/   r_  safe_bool_2)rr  rQ  r  r  newOrderr!  r0  rb  r@  rO  r  statusIdfeeCurrencyCodefeeCostrP  rR  rQ  rS  rawTyper<  rP  s                        rt  r  bingx.parse_order  s   v ##E+=?RSE))%F , 4V6
%%eXs;>%%hdJGF''vs;''/[\	!00cJ++E3QR,,UJD$$U,FG#f~5=&,VnO&,WoO"(/??5*5 x2~ NN4+;+;Hj+QRM Jx,N,NV^bdVd(C((??84 NN4+;+;Hk+RSM__UL9
!zR'7"nnT-=-=j,-WXO"jW\\.R.RZdhjZj*c**!__Z8
"nnT-=-=j+-VWO**5&#>NN4#5#5e[+#VW	  V$r)0E )#V$r)0G"+#  
D 
$$$U,KL 
 T//7st 
 d&&xjI	 

  
 Y/ 
 !"4 
 "4#4#4UL#I 
 D))'2 
 4++E=A 
  
 D))$/ 
 T''w< 
 L 
 ] 
  ! 
" t))%TB# 
$ $$U,AB((0[\((sC--h7+**73 **5,E9 
: ; 	rv  r  c           	      <    SSSSSSSSS.nU R                  X!U5      $ )Nr#  closedcanceled)NEWPENDINGPARTIALLY_FILLEDRUNNINGFILLEDCANCELED	CANCELLEDFAILEDr  rr  r  statusess      rt  r  bingx.parse_order_status  s6     &"# 	
 &99rv  r5   c                 8   U R                  5         U R                  USS5      nU R                  US5      nSnSnU(       a%  SU0nU R                  U R	                  Xs5      5      nOUc  [        U R                  S-   5      eU R                  U5      nSUS   0nU R                  USS	5      n	U R                  US/5      nU	b  XS	'   OXS
'   Sn
SnU R                  SXc5      u  pU R                  SXc5      u  pU
S:X  a!  U R                  U R	                  X5      5      nOGUS:X  a!  U R                  U R	                  X5      5      nO U R                  U R	                  X5      5      nU R                  US0 5      nU R                  USU5      nU R                  X5      $ )a  
cancels an open order

https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Cancel%20Order
https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Cancel%20Order
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Cancel%20an%20Order
https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Cancel%20TWAP%20Order

: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 str [params.clientOrderId]: a unique id for the order
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r  FNr  z) cancelOrder() requires a symbol argumentr  r5   r?  r>  rI  rM   rB   r.  rx  rQ  )r  r  r   swapV1PrivatePostTwapCancelOrderr  r%   r5   r  rV  r,  r  spotV1PrivatePostTradeCancel$cswapV1PrivateDeleteTradeCancelOrderswapV2PrivateDeleteTradeOrderr{  r  )rr  r5   r  r}  rh  r~  r  ro  r  r?  r  r  rx  rQ  s                 rt  cancel_orderbingx.cancel_order$  s    	nnVVU;66*r!K <<T[[=]^H4 ~'2](]^^[[(F&,G !..vXMYYv'89F(+8(%'	"DG==mV\LD"==mV\OGv~<<T[[=YZi'#HHU\IefH#AA$++gB^_HF ~~h3tWd3..rv  c                 .   Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nSnUS   (       a!  U R	                  U R                  XB5      5      nOnUS   (       aL  US   (       a!  U R                  U R                  XB5      5      nO9U R                  U R                  XB5      5      nO[        U R                  S-   5      eU R                  US	0 5      nU R                  US
S/ 5      nU R                  U5      $ )a<  
cancel all open orders

https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Cancel%20orders%20by%20symbol
https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Cancel%20All%20Orders
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Cancel%20all%20orders

:param str [symbol]: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nz- cancelAllOrders() requires a symbol argumentr  r5   rB   rD   r.  z= cancelAllOrders is only supported for spot and swap markets.rx  successr  )r%   r5   r  r  &spotV1PrivatePostTradeCancelOpenOrdersr  &cswapV1PrivateDeleteTradeAllOpenOrders%swapV2PrivateDeleteTradeAllOpenOrdersr&   r{  r  r  )rr  r  r}  r  r  r~  rx  r  s           rt  cancel_all_ordersbingx.cancel_all_orders  s    >#DGG.]$]^^V$fTl
 &>BB4;;wC_`H. F^i FFt{{SZGcdr  EEdkkRYFbc> TWW'ffgg~~h3!!$	8R@  ((rv  idsc                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nU R	                  US5      nU R                  US5      nUnUSLnU(       a  Un/ n	[        S[        U5      5       H#  n
Xz   n[        U5      nU	R                  U5        M%     SnUS   (       a?  U(       a  SOS	nS
R                  U	5      X^'   U R                  U R                  XS5      5      nO@U(       a  U R                  U	5      US'   OXS'   U R                  U R                  XS5      5      nU R                  US0 5      nU R!                  USS/ 5      nU R#                  U5      $ )a  
cancel multiple orders

https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Cancel%20a%20Batch%20of%20Orders
https://bingx-api.github.io/docs/#/spot/trade-api.html#Cancel%20a%20Batch%20of%20Orders

:param str[] ids: order ids
:param str symbol: unified market symbol, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str[] [params.clientOrderIds]: client order ids
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nz* cancelOrders() requires a symbol argumentr  r5   clientOrderIdsr   rB   clientOrderIDsorderIds,clientOrderIDListorderIdListrx  r  r  )r%   r5   r  r  r  r  r  r  r  r  join"spotV1PrivatePostTradeCancelOrdersr  rd  #swapV2PrivateDeleteTradeBatchOrdersr{  r  r  )rr  r  r  r}  r  r  r  
idsToParseareClientOrderIds	parsedIdsr  r5   stringIdr~  
spotReqKeyrx  r  s                    rt  cancel_ordersbingx.cancel_orders^  ss    >#DGG.Z$Z[[V$fTl
 1AB6#34
+47'J	q#j/*AB2wHX& + &>->)JJ"%((9"5G>>t{{7?[\H8 !/3yy/C+,)2&??G@\]H< ~~h3""4HbA  ))rv  timeoutc                    U R                  5         US:  nU(       a  SOSU(       a  U R                  US-  5      OSS.nSnSnU R                  SSU5      u  pbUS:X  a"  U R                  U R	                  XB5      5      nU$ US	:X  a"  U R                  U R	                  XB5      5      nU$ [        U R                  S
-   U-   S-   5      e)a  
dead man's switch, cancel all orders after the given timeout

https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Cancel%20all%20orders%20in%20countdown
https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Cancel%20all%20orders%20in%20countdown

:param number timeout: time in milliseconds, 0 represents cancel the timer
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.type]: spot or swap market
:returns dict: the api result
r   ACTIVATECLOSErd  )r  timeOutNrL   rB   rD   z- cancelAllOrdersAfter() is not supported for  markets)r  parse_to_intr,  $spotV1PrivatePostTradeCancelAllAfterr  $swapV2PrivatePostTradeCancelAllAfterr+   r5   )rr  r  r}  r  r  r~  r  s          rt  cancel_all_orders_afterbingx.cancel_all_orders_after  s     	aK#+J'?G))'D.9a
 99:PRVX^_6>@@WA]^H   V^@@WA]^H  tww)XX[__bllmmrv  c                    U R                  5         U R                  USS5      nU R                  US5      nSnSnU(       a%  SU0nU R                  U R	                  Xs5      5      nOUc  [        U R                  S-   5      eU R                  U5      nUS   US.nSn	Sn
U R                  SXc5      u  pU R                  SXc5      u  pU	S	:X  a!  U R                  U R	                  X5      5      nOGU
S
:X  a!  U R                  U R	                  X5      5      nO U R                  U R	                  X5      5      nU R                  US0 5      nU R                  USU5      nU R                  X5      $ )a  
fetches information on an order made by the user

https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20details
https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20details
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Order
https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#TWAP%20Order%20Details

: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 boolean [params.twap]: if fetching twap order
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r  FNr  z( fetchOrder() requires a symbol argumentr5   )r  rI  r   rB   r.  rx  rQ  )r  r  r  swapV1PrivateGetTwapOrderDetailr  r%   r5   r  r,  r  spotV1PrivateGetTradeQuery!cswapV1PrivateGetTradeOrderDetailswapV2PrivateGetTradeOrderr{  r  )rr  r5   r  r}  rh  r~  r  ro  r  r  r  rx  rQ  s                rt  fetch_orderbingx.fetch_order  sl    	nnVVU;66*r!K ;;DKK<\]H6 ~'2\(\]][[(F ,G DG==lF[LD"==lF[OGv~::4;;w;WX0 i'#EEdkkRYFbcHj  $>>t{{7?[\H6 ~~h3tWd3..rv  c                    U R                  5         0 nSnUb  U R                  U5      nUS   US'   SnU R                  SXd5      u  ptUS:w  a  [        U R                  S-   5      eUb  X5S'   Ub  X%S'   U R                  S	XT5      u  pTU R                  U R                  XT5      5      nU R                  US
0 5      n	U R                  U	S/ 5      n
U R                  XX#5      $ )a#  
fetches information on multiple orders made by the user

https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#All%20Orders
https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history(returns less fields than above)

: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 int [params.until]: the latest time in ms to fetch entries for
:param int [params.orderId]: Only return subsequent orders, and return the latest order by default
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr5   r  r   rD   z1 fetchOrders() is only supported for swap marketsr_  r
  r  rx  r  )r  r  r,  r+   r5   r  swapV1PrivateGetTradeFullOrderr  r{  r  r  )rr  r  r  r_  r}  r  r  r  r~  rx  r  s              rt  fetch_ordersbingx.fetch_orders  s     	[[(F &tGH99-X6>tww)\\]]$G#(K 229gN66t{{77STj ~~h3h3  >>rv  c                    U R                  5         Sn0 nUb  U R                  U5      nUS   US'   SnSnSn	U R                  SXT5      u  ptU R                  SXT5      u  pUS:X  a!  U R	                  U R                  Xd5      5      n	OU R                  USS5      n
U R                  US5      nU
(       a!  U R                  U R                  Xd5      5      n	OGUS:X  a!  U R                  U R                  Xd5      5      n	O U R                  U R                  Xd5      5      n	U R                  U	S	0 5      nU R                  US
S/ 5      nU R                  XX#5      $ )aC  
fetch all unfilled currently open orders

https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Current%20Open%20Orders
https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Current%20All%20Open%20Orders
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20all%20current%20pending%20orders
https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20TWAP%20Entrusted%20Order

: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 order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.twap]: if fetching twap open orders
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr5   r  r   rB   r  Fr.  rx  r  r   )r  r  r,  r  spotV1PrivateGetTradeOpenOrdersr  r  r  swapV1PrivateGetTwapOpenOrders cswapV1PrivateGetTradeOpenOrdersswapV2PrivateGetTradeOpenOrdersr{  r  r  )rr  r  r  r_  r}  r  r  r  r  r~  rh  rx  r  s                rt  fetch_open_ordersbingx.fetch_open_orders  sK     	[[(F &tGH99:KV\99:KV\6>;;DKK<XYH..?KYYvv.F>>t{{7?[\I%@@WA]^??G@\]X ~~h3!!$&"=  >>rv  c                 l    U R                  5         U R                  XX45      nU R                  USS5      $ )a  
fetches information on multiple closed orders made by the user

https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20history
https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#User's%20History%20Orders
https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order

:param str symbol: unified market symbol of the closed orders
:param int [since]: timestamp in ms of the earliest order
:param int [limit]: the max number of closed orders to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch orders for
:param boolean [params.standard]: whether to fetch standard contract orders
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
r  r  r   fetch_canceled_and_closed_orders	filter_byrr  r  r  r_  r}  r  s         rt  fetch_closed_ordersbingx.fetch_closed_orders  s5    " 	66veT~~fh99rv  c                 l    U R                  5         U R                  XX45      nU R                  USS5      $ )a  
fetches information on multiple canceled orders made by the user

https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20history
https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#User's%20History%20Orders
https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order

:param str symbol: unified market symbol of the canceled orders
:param int [since]: timestamp in ms of the earliest order
:param int [limit]: the max number of canceled orders to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch orders for
:param boolean [params.standard]: whether to fetch standard contract orders
:returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
r  r  r$  r'  s         rt  fetch_canceled_ordersbingx.fetch_canceled_orders  s5    " 	66veT~~fh
;;rv  c                    U R                  5         Sn0 nUb  U R                  U5      nUS   US'   SnSnSn	Sn
U R                  SXT5      u  ptU R                  SXT5      u  pU R	                  USSS5      u  pU	(       a"  U R                  U R                  Xd5      5      n
GOUS:X  a(  Ub  X6S'   U R                  U R                  Xd5      5      n
OU R                  US	S5      nU R                  US	5      nU(       aq  S
US'   Uc  SOUUS'   Uc  S
OUUS'   U R                  USU R                  5       5      nU R                  US5      nXS'   U R                  U R                  Xd5      5      n
OGUS:X  a!  U R                  U R                  Xd5      5      n
O U R                  U R                  Xd5      5      n
U R                  U
S0 5      nU R!                  USS/ 5      nU R#                  XX#5      $ )aC  
fetches information on multiple closed orders made by the user

https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20history
https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#User's%20History%20Orders
https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20TWAP%20Historical%20Orders

: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 int [params.until]: the latest time in ms to fetch orders for
:param boolean [params.standard]: whether to fetch standard contract orders
:param boolean [params.twap]: if fetching twap orders
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr5   r  rh   r  FrB   r  r  r   	pageIndexr;   r
  r  r  r.  rx  r  r   )r  r  r,  r  r  contractV1PrivateGetAllOrdersr  "spotV1PrivateGetTradeHistoryOrdersr  r  r|  milliseconds!swapV1PrivateGetTwapHistoryOrders"cswapV1PrivateGetTradeOrderHistoryswapV2PrivateGetTradeAllOrdersr{  r  r  )rr  r  r  r_  r}  r  r  r  r  r  r~  rh  r  rx  r  s                  rt  r%  &bingx.fetch_canceled_and_closed_orders  s   & 	[[(F &tGH99:Mv^99:Mv^88ATV`bgh99$++g:VWHV^ &+
#>>t{{7?[\H4 ..?KYYvv.F'($.3mc%
#-2]q$))&'4;L;L;NO673%*	"AA$++gB^_< I%BB4;;wC_`n  >>t{{7?[\: ~~h3!!$&"=  >>rv  r  fromAccount	toAccountc           
         U R                  5         U R                  U5      nU R                  U R                  S0 5      nSnU R	                  SSU5      u  pU R                  XsU5      n	U R                  XtU5      n
U	S:X  a  US:X  a  Sn	OSn	U
S:X  a  US:X  a  Sn
OSn
U	U
US   U R                  X5      S	.nU R                  U R                  X5      5      nUU R                  US
5      SSUUUUSS.	$ )aA  
transfer currency internally between wallets on the same account

https://bingx-api.github.io/docs/#/en-us/common/account-api.html#Asset%20Transfer%20New

:param str code: unified currency code
:param float amount: amount to transfer
:param str fromAccount: account to transfer from(spot, swap, futures, or funding)
:param str toAccount: account to transfer to(spot, swap(linear or inverse), future, or funding)
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
r@  Nr   rD   r.  r+  r*  r5   )r6  r7  r   r  
transferId	r  r5   rO  rP  r  r  r6  r7  r  )	r  r  r{  rl  r  r  currency_to_precisionapiAssetV1PrivatePostTransferr  )rr  r  r  r6  r7  r}  r  r@  r  fromIdtoIdr  r~  s                rt  r   bingx.transfer  s    	==&6FK99*dFS!!.{K9EV)#$$6>)#""!d^00>	
 55dkk'6RS ""8\:&"

 
	
rv  c                    U R                  5         0 nSnUb  U R                  U5      nU R                  U R                  S0 5      nU R	                  US5      nU R	                  US5      n	U R	                  XxU5      n
U R	                  XyU	5      nU
b  Uc  [        U R                  S-   5      eUb  XS'   U	b  XS'   U R                  USS/5      nSnSnU R                  USS	S5      u  pU(       a  U R                  SSX#XL5      $ Ub  X%S
'   Ub  X5S'   U R                  SXT5      u  pTU R                  U R                  XT5      5      nU R                  US/ 5      nU R                  XX#5      $ )aX  
fetch a history of internal transfers made on an account

https://bingx-api.github.io/docs/#/en-us/common/account-api.html#Asset%20transfer%20records%20new

: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(default 10, max 100)
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str params.fromAccount:(mandatory) transfer from(spot, swap(linear or inverse), future, or funding)
:param str params.toAccount:(mandatory) transfer to(spot, swap(linear or inverse), future, or funding)
:param boolean [params.paginate]: whether to paginate the results(default False)
:returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
Nr@  r6  r7  z0 fromAccount & toAccount parameters are requiredr;   Fr   r  r
  r  r  rows)r  r  r{  rl  r  r!   r5   r  r  fetch_paginated_call_dynamicr  "apiV3PrivateGetAssetTransferRecordr  r  parse_transfers)rr  r  r  r_  r}  r  r  r@  r6  r7  r=  r>  maxLimitr  r~  rA  s                   rt  fetch_transfersbingx.fetch_transfers  s    	}}T*H6FK&&v}=$$V[9	!!.{K9E>T\*\ \]]"%+M" #'K 6M;#?@88AQS]_de445EtU[all#(K "'J229gN::4;;w;WX" ~~h3##DEAArv  r   r  c                    U R                  US5      nU R                  US5      nU R                  US5      nU R                  XR5      nU R                  US5      nU R                  U R                  S0 5      nU R                  US5      n	U R                  US5      n
U R                  XU	5      nU R                  XU
5      nUUUU R                  U5      UU R                  US5      UUU R                  U5      S	.	$ )
Nr9  rO  r   r  rA  r6  r7  r  r:  )r  r|  r  r{  rl  r[  r  parse_transfer_status)rr  r   r  tranIdrO  r  ra  r  rA  r=  r>  r6  r7  s                rt  parse_transferbingx.parse_transfer  s    !!(L9%%h<	%%h8
..zD!!(H5~~dllNBG!!(M:+6&&|VD$$\>	"Y/$&&x:&"008

 
	
rv  c                 .    SS0nU R                  X!U5      $ )N	CONFIRMEDokr  r  s      rt  rI  bingx.parse_transfer_status  s#    
 &99rv  c                    U R                  5         U R                  U5      nU R                  U R                  S5      nU R                  U R                  SU5      nUS   SSUS.nU R                  U R                  Xb5      5      nU R                  U R                  US5      S5      nU R                  XS   /S5      n	U R                  U	S	5      $ )
a  
fetch the deposit addresses for a currency associated with self account

https://bingx-api.github.io/docs/#/en-us/common/wallet-api.html#Query%20Main%20Account%20Deposit%20Address

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary `address structures <https://docs.ccxt.com/#/?id=address-structure>`, indexed by the network
rB  r5   r   rd  )r  offsetr_  rB  rx  r  Fr  )r  r  r|  rl  parse_params(walletsV1PrivateGetCapitalDepositAddressr  r  r{  parse_deposit_addressesindex_by)
rr  r  r}  r  defaultRecvWindowrB  r  r~  rx  parseds
             rt  "fetch_deposit_addresses_by_network(bingx.fetch_deposit_addresses_by_network  s     	==& --dllLI&&t'8'8,HYZ
TN$	
 @@WA]^& ~~dnnXv>G--df5E4FN}}VY//rv  c                    U R                  US5      nU R                  US/5      nU R                  X5      nUb  U R                  XC5      $ U R                  U R                  S5      nU R                  XQ5      nUb  U R                  XF5      $ [        UR                  5       5      nU R                  US5      nU R                  XH5      $ )a  
fetch the deposit address for a currency associated with self account

https://bingx-api.github.io/docs/#/en-us/common/wallet-api.html#Query%20Main%20Account%20Deposit%20Address

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.network]: The chain of currency. This only apply for multi-chain currency, and there is no need for single chain currency
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
r  rD  r   )r  r  rY  r{  rl  r   r  )	rr  r  r}  r  addressStructuresrl  defaultNetworkForCurrencyr  keys	            rt  fetch_deposit_addressbingx.fetch_deposit_addressI  s     ""6956I;/ CCDQ>>"3==nnT\\3DEG(,(8(8(G%(4~~&7SS-2245&&tQ/~~&7==rv  c                    U R                  US5      nU R                  US5      nU R                  XB5      nUS   nU R                  US5      nU R                  US5      nU R                  Xu5      nU R                  U5        UUUUUS.$ )Ntagr  r  addressWithPrefixr  )r  r  r  addressrb  )r  safe_currencyr  check_address)	rr  depositAddressr  rb  r  r  rd  
networkdIdr  s	            rt  parse_deposit_addressbingx.parse_deposit_addressc  s     ~u5%%nf=
%%j;"">3FG%%ni@
--j?7#""
 	
rv  c                     U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  X%S'   Ub  X5S'   U R                  U R                  XT5      5      nU R	                  XvX#5      $ )a  
fetch all deposits made to an account

https://bingx-api.github.io/docs/#/spot/account-api.html#Deposit%20History(supporting%20network)

: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
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr5   r  r
  r_  )r  r  $spotV3PrivateGetCapitalDepositHisrecr  parse_transactionsrr  r  r  r_  r}  r  r  r~  s           rt  fetch_depositsbingx.fetch_deposits}  s     	
}}T*H&tnGFO#(K $G<<T[[=YZ$ &&x5HHrv  c                     U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  X%S'   Ub  X5S'   U R                  U R                  XT5      5      nU R	                  XvX#5      $ )a  
fetch all withdrawals made from an account

https://bingx-api.github.io/docs/#/spot/account-api.html#Withdraw%20History%20(supporting%20network)

: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
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr5   r  r
  r_  )r  r  &spotV3PrivateGetCapitalWithdrawHistoryr  rm  rn  s           rt  fetch_withdrawalsbingx.fetch_withdrawals  s     	
}}T*H&tnGFO#(K $G>>t{{7?[\( &&x5HHrv  transactionc                    U R                  US5      nUc  S OU R                  US5      nU R                  USU5      nU R                  US5      nU R                  US5      nU R                  USS5      nU R                  U5      n	Uc#  U R                  US5      n	U R	                  U	5      nU R                  US5      n
U R                  US	5      nU R                  X5      nUb/  X:w  a*  UR                  U
5      S
:  a  U
b  UR                  U
S5      nU R                  US5      nUS:X  a  SOSn0 SU_SU_SU R                  US5      _SU_SU_SU R                  U
5      _SU R                  US5      _SU R                  U R                  US5      5      _SU_SU	_SU_SS _SU_SU_SU_SS _SS _U R                  US5      UU R                  US5      S S.S S .E$ )!Nrx  r5   rd  
addressTag
insertTimerO  	applyTimer  r  r   r  transferType0r  
withdrawalr  txidtxIdr  r  r  r  rP  addressFrom	addressTorb  tagFromtagToupdatedtransactionFee)r  r  rate)commentr  internal)r  r  r  r[  rT  r  r  r  r  r  parse_transaction_status)rr  ru  r  rx  dataIdr5   rd  rb  rO  rP  r  r  r  r  r  s                  rt  parse_transactionbingx.parse_transaction  sx   ` {F3,T-=-=dD-Ik48"";	:{L9''\;O	<<	*''[AHx0I"";	:%%k6:
&&z<4?		'8Ja8O"||GR0"";?$^y,
K
"
 D$$[&9
 D	

 
 t..w7
 d&&{H=
 d33D4D4D[RZ4[\
 
 
 w
 4
 
 3
 s
  T!
" t#
$ ''V< ((6FG
 1
 	
rv  c                 H    SSSSSSSSSSSSSSS.nU R                  X!U5      $ )NpendingrO  rejected)r{  r  1020304050607023456r  r  s      rt  r  bingx.parse_transaction_status2  sH    
  &99rv  rO  c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUS   S:w  a  [	        U R                  S-   5      eUR                  5       nUS:X  a  SnUS:w  a  US:w  a  [        U R                  S	-   5      eUS
   US.nSnU R                  SXC5      u  pcUS:X  a   U R                  U R                  XS5      5      $ U R                  U R                  XS5      5      $ )a  
set margin mode to 'cross' or 'isolated'

https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Change%20Margin%20Type
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Set%20Margin%20Type

: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 argumentr  rD   z- setMarginMode() supports swap contracts onlyCROSSCROSSEDISOLATEDz@ setMarginMode() marginMode argument should be isolated or crossr5   )r  
marginTyper   r.  )r%   r5   r  r  r'   r[  r&   r  !cswapV1PrivatePostTradeMarginTyper   swapV2PrivatePostTradeMarginType)rr  rO  r  r}  r  r  r  s          rt  set_margin_modebingx.set_margin_modeE  s     >#DGG.[$[\\V$&>V#DGG&UUVV%%'
 "J#
i(?TWW'iijjTl$
 99/6Zi99$++g:VWW88W9UVVrv  c                 L    SS0nU R                  XU R                  XC5      5      $ )Nr  r   
set_marginr  rr  r  r  r}  r  s        rt  
add_marginbingx.add_marging  *    A
 vt{{7/KLLrv  c                 L    SS0nU R                  XU R                  XC5      5      $ )Nr  r   r  r  s        rt  reduce_marginbingx.reduce_marginm  r  rv  c                    U R                  US5      nUc  [        U R                  S-   5      eU R                  USS/5      (       d  [        U R                  S-   5      eU R	                  5         U R                  U5      nUS   U R                  US   U5      US.nU R                  U R                  Xc5      5      nU R                  Xu5      $ )a  
Either adds or reduces margin in an isolated position in order to set the margin to a specific value

https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Adjust%20isolated%20margin

:param str symbol: unified market symbol of the market to set margin in
:param float amount: the amount to set the margin to
:param dict [params]: parameters specific to the bingx api endpoint
:returns dict: A `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
r  zV setMargin() requires a type parameter either 1(increase margin) or 2(decrease margin)r   r   r5   r  )r  r  r  )
r|  r%   r5   in_arrayr  r  ra  $swapV2PrivatePostTradePositionMarginr  parse_margin_modification)rr  r  r  r}  r  r  r  r~  s           rt  r  bingx.set_margins  s       0<#DGG  /G  %G  H  H}}TAq6**#DGG  /G  %G  H  HV$Tl..vh/?H

 <<T[[=YZ --h??rv  rx  c                     U R                  US5      nUU R                  US5      US:X  a  SOSSU R                  US5      U R                  US5      U R                  US	5      S S S S
.
$ )Nr  r  r  addreducer  r  rC   r  )
r  r  r  rO  r  r  r  r  rO  rP  )r  r  )rr  rx  r  r  s       rt  r  bingx.parse_margin_modification  sz     f-&&vx8"ckE$&&tX6%%dH5$$VX6
 	
rv  c                 4   U R                  5         U R                  U5      nSUS   0nSnUS   (       a!  U R                  U R                  XB5      5      nO U R	                  U R                  XB5      5      nU R                  US0 5      nU R                  Xc5      $ )a  
fetch the set leverage for a market

https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Query%20Leverage
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Leverage

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `leverage structure <https://docs.ccxt.com/#/?id=leverage-structure>`
r  r5   Nr.  rx  )r  r  cswapV1PrivateGetTradeLeverager  swapV2PrivateGetTradeLeverager{  parse_leveragerw  s          rt  fetch_leveragebingx.fetch_leverage  s     	V$fTl
 )::4;;w;WXH$ 99$++g:VWH& ~~h3""400rv  rX  c                     U R                  US5      nUU R                  X25      S U R                  US5      U R                  US5      S.$ )Nr  longLeverageshortLeverage)r  r  rO  r  r  )r  r\  r|  )rr  rX  r  rb  s       rt  r  bingx.parse_leverage  sT    : ##Hh7&&x8 --hG!..xI
 	
rv  c                 p   Uc  [        U R                  S-   5      eU R                  US5      nU R                  SUS/ SQ5        U R	                  5         U R                  U5      nUS   UUS.nUS   (       a   U R                  U R                  Xc5      5      $ U R                  U R                  Xc5      5      $ )a  
set the level of leverage for a market

https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Switch%20Leverage
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Modify%20Leverage

: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 str [params.side]: hedged: ['long' or 'short']. one way: ['both']
:returns dict: response from the exchange
z) setLeverage() requires a symbol argumentr@  r   )rH  rI  rZ  r5   )r  r@  rX  r.  )	r%   r5   r\  check_required_argumentr  r  cswapV1PrivatePostTradeLeverager  swapV2PrivatePostTradeLeverage)rr  rX  r  r}  r@  r  r  s          rt  set_leveragebingx.set_leverage  s     >#DGG.Y$YZZ%%ff5$$]D&B[\V$Tl 

 )77G8TUU$ 66t{{77STTrv  c                 H   Uc  [        U R                  S-   5      eU R                  5         U R                  U5      n0 nSnSnSn	U R	                  SXT5      u  pU	S:X  ab  U R                  US5      n
U
c  [        U R                  S-   5      eU R                  U R                  Xd5      5      nU R                  US/ 5      nGOPUS   US	'   U R                  5       nUb  US
   (       a  SOSnX&U'   OUS   (       a  US-
  US'   U R                  US5      nU R                  US5      nUb  US
   (       a  SOSnXU'   OUS   (       a  XS'   US
   (       aN  Ub  X6S'   U R                  U R                  Xd5      5      nU R                  US0 5      nU R                  US/ 5      nOpU R                  USS5      nU R                  US5      nUUS'   U R                  U R                  Xd5      5      nU R                  US0 5      nU R                  US/ 5      nU R!                  XuX#U5      $ )a*  
fetch all trades made by the user

https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20transaction%20details
https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20historical%20transaction%20orders
https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20historical%20transaction%20details
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Order%20Trade%20Detail

: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 int [params.until]: timestamp in ms for the ending date filter, default is None
:param str params['trandingUnit']: COIN(directly represent assets such and ETH) or CONT(represents the number of contract sheets)
:param str params['orderId']: the order id required for inverse swap
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
Nz+ fetchMyTrades() requires a symbol argumentr   r.  rI  zE fetchMyTrades() requires an orderId argument for inverse swap tradesrx  r5   r  rB   r
  r  rD   l    H4 r  r  r  r_  fillstradingUnitCONTfill_orders)r%   r5   r  r  r  r  #cswapV1PrivateGetTradeAllFillOrdersr  r  r1  r|  r  spotV1PrivateGetTradeMyTradesr{  r\  "swapV2PrivateGetTradeAllFillOrdersr/  )rr  r  r  r_  r}  r  r  r  r~  r  rI  nowstartTimeReqr  
endTimeReqrx  r  s                    rt  fetch_my_tradesbingx.fetch_my_tradesI  s1   $ >#DGG.[$[\\V$99/6Zi&&vy9G'2y(yzz??G@\]HNN8VR8E8 !'tGH##%C .4Vn{)(-%%(+C%C	"%%fg6EYYvw/F *0.Yg
&+
##& f~$',G$==dkk'>Z[~~h;tWb94 #44V]FS6=9)4&BB4;;wC_`~~h;t]B?*   fEErv  c                 b   U R                  US0 5      n[        UR                  5       5      n[        U5      nUS S S.S S S.0 S.nUS:w  ad  [	        SU5       HT  nXG   nX8   n	S S S.U R                  U	S5      SS.S.US   U'   US:X  d  M4  U R                  U	S	5      US
   S'   SUS
   S'   MV     U$ )NrE  )r  r  )r  r  r  rE  r   r  F)r  r  r   r  r  r  )r{  r   r  r  r  r  )
rr  r  r  rE  networkCodesnetworksLengthr  r  r  r  s
             rt  parse_deposit_withdraw_fee bingx.parse_deposit_withdraw_fee  s     >>#z26HMMO,\*"
 " 
 Q1n-*o"/'+4@(,(8(8%(HX] ^3z";/ "Q&040@0@-0XF:&u-7<F:&|4 . rv  r  c                 "   U R                  5         U R                  U5      n0 n[        UR                  5       5      n[	        S[        U5      5       H9  nXV   nUb  U R                  Xq5      (       d  M"  X7   nU R                  U5      XG'   M;     U$ )aT  
fetch deposit and withdraw fees

https://bingx-api.github.io/docs/#/common/account-api.html#All%20Coins'%20Information

:param str[]|None codes: list of unified currency codes
: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  )	rr  r  r}  r~  depositWithdrawFeesresponseCodesr  r  r  s	            rt  fetch_deposit_withdraw_fees!bingx.fetch_deposit_withdraw_fees  s     	((0$&X]]_-q#m,-A #D4==#=#= ,0,K,KE,R#)	 .
 #"rv  rd  rb  c                 6   U R                  XE5      u  pEU R                  U5        U R                  5         U R                  U5      nSnSnU R	                  USSSU5      u  pSSSSSS	.n	U R                  XU5      nUS
   UU R                  X5      US.n
U R                  US5      nUb  U R                  U5      U
S'   Ub  XJS'   U R                  USS/5      nU R                  U R                  X5      5      nU R                  US5      nU R                  U5      $ )a  
make a withdrawal

https://bingx-api.github.io/docs/#/en-us/spot/wallet-api.html#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
:param int [params.walletType]: 1 fund(funding) account, 2 standard account, 3 perpetual account, 15 spot account
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
   Nr  r  
walletTyper   r   r  )r,  r   r  	perpetualrB   r5   )r  rd  r  r  r  rw  rx  )handle_withdraw_tag_and_paramsrf  r  r  handle_option_and_params_2r|  r;  r\  network_code_to_idr  (walletsV1PrivatePostCapitalWithdrawApplyr  r  r  )rr  r  r  rd  rb  r}  r  defaultWalletTyper  walletTypesr  r  r~  rx  s                 rt  r  bingx.withdraw  sA    99#F7#==&
!<<VZQWYegxy

 &&{@QR
TN00>$	
 ((;!%!8!8!AGI?$'L!6L)#<=@@WA]^x0 %%d++rv  c                 X   [        UR                  5       5      nU R                  U5      n[        S[	        U5      5       Hf  nX4   nX   n[        U[         5      (       d  M"  Sn[        S[	        U5      5       H   nXh   n	US:  a  US-  nU[        U	5      -  nM"     US-  nXqU'   Mh     U$ )Nr   [r  ]r   r  sortr  r  r  r  )
rr  r}  rawKeysr  r  r^  valuearrStrr  arrayElements
             rt  rS  bingx.parse_params7  s    v{{}%yy!q#d)$A'CKE%&&q#e*-A#(8L1u#c,//F	 .
 #$s % rv  c                    U R                  5         SS0nU R                  SXT5      u  pTSnUb  U R                  U5      nUS   US'   Ub  X%S'   Ub  X5S'   SnU R                  S	Xd5      u  ptSnSn	US
:X  a4  U R	                  U R                  XT5      5      nU R                  US/ 5      n	OFU R                  U R                  XT5      5      nU R                  US0 5      n
U R                  U
S/ 5      n	U R                  XX#5      $ )a  
retrieves the users liquidated positions

https://bingx-api.github.io/docs/#/swapV2/trade-api.html#User's%20Force%20Orders
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20force%20orders

: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 bingx api endpoint
:param int [params.until]: timestamp in ms of the latest liquidation
:returns dict: an array of `liquidation structures <https://docs.ccxt.com/#/?id=liquidation-structure>`
autoCloseTypeLIQUIDATIONr  Nr5   r  r
  r_  r   r.  rx  r  )
r  r  r  r  !cswapV1PrivateGetTradeForceOrdersr  r   swapV2PrivateGetTradeForceOrdersr{  parse_liquidations)rr  r  r  r_  r}  r  r  r  r~  liquidationsrx  s              rt  fetch_my_liquidationsbingx.fetch_my_liquidationsI  s!    	]
 229gN[[(F &tGH#(K $G99:OQW`i==dkk'>Z[H8  >>(FB?L<<T[[=YZH< >>(FB7D>>$"=L&&|UJJrv  c                    U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n[        R                  " XV5      n[        R                  " X5      n	U R	                  UU R                  X25      U R                  U5      U R                  U5      U R                  U5      U R                  U5      U R                  U	5      UU R                  U5      S.	5      $ )Nr  r!  r  r  r  )	r  r  r  r  rJ  	baseValue
quoteValuerO  rP  )r  r|  r/   rY  safe_liquidationr\  rq  r[  )
rr  liquidationr  rb  rO  contractsStringcontractSizeStringpriceStringbaseValueStringquoteValueStrings
             rt  parse_liquidationbingx.parse_liquidation  s    , ##K:%%k6:	**;F!--fnE&&{J?!,,_Q"--oK$$&&x8**?; --.@A&&{3**?;++,<="Y/
&
 
 
	rv  c                    U R                  5         U R                  U5      nU R                  US5      n0 nSnUb!  U R                  U R	                  Xc5      5      nOSUS   US'   US   (       a!  U R                  U R	                  Xc5      5      nO U R                  U R	                  Xc5      5      nU R                  US5      nU R                  X5      $ )a.  
closes open positions for a market

https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#One-Click%20Close%20All%20Positions
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Close%20all%20positions%20in%20bulk

:param str symbol: Unified CCXT market symbol
:param str [side]: not used by bingx
:param dict [params]: extra parameters specific to the bingx api endpoint
:param str|None [params.positionId]: the id of the position you would like to close
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r  Nr5   r  r.  rx  )	r  r  r  #swapV1PrivatePostTradeClosePositionr  (cswapV1PrivatePostTradeCloseAllPositions'swapV2PrivatePostTradeCloseAllPositionsr{  r  )	rr  r  r@  r}  r  r  r  r~  rx  s	            rt  close_positionbingx.close_position  s     	V$%%fl;
!??G@\]H$ !'tGHi HHU\Ief  GGT[Hde ~~h/--rv  c                    U R                  5         U R                  U R                  S5      nU R                  U R                  SU5      nSnU R	                  SSU5      u  pASnU R                  SSU5      u  pQUS:X  a  [        U R                  S-   U-   S-   5      eSU0nSnUS:X  a!  U R                  U R                  Xa5      5      nO U R                  U R                  Xa5      5      nU R                  US0 5      nU R                  US	/ 5      n	/ n
[        S
[        U	5      5       H)  nU R                  SX   05      nU
R!                  U5        M+     U
$ )a  
closes open positions for a market

https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#One-Click%20Close%20All%20Positions
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Close%20all%20positions%20in%20bulk

:param dict [params]: extra parameters specific to the bingx api endpoint
:param str [params.recvWindow]: request valid time window value
:returns dict[]: `a list of position structures <https://docs.ccxt.com/#/?id=position-structure>`
rB  NrO   rC   z% closePositions() cannot be used for r  r.  rx  r  r   r  )r  r|  rl  rS  r,  r  r&   r5   r  r  r  r{  r  r  r  r  r  )rr  r}  rW  rB  r0  r  r  r~  rx  r  r  r  r  s                rt  close_all_positionsbingx.close_all_positions  se    	 --dllLI&&t'8'8,HYZ

!??@SUY[ab
99:MtU[\!TWW'NNQ[[^hhii*
 iDDT[[QXEabH CCDKKPWD`aH ~~h3..y"5	q#g,'A**L'*+EFHX& ( rv  c                 ~    U R                  U5      nU R                  US0 5      nU R                  US5      nUUS:H  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://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Get%20Position%20Mode

: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
:returns dict: an object detailing whether the market is in hedged or one-way mode
rx  dualSidePositionr  )r  rV  ) swapV1PrivateGetPositionSideDualr{  r  )rr  r  r}  r~  rx  r  s         rt  fetch_position_modebingx.fetch_position_modeR  sQ     88@ ~~h3++D2DE'61
 	
rv  rV  c                 f    SnU(       a  SnOSnSU0nU R                  U R                  XS5      5      $ )ag  
set hedged to True or False for a market

https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Set%20Position%20Mode

:param bool hedged: set to True to use dualSidePosition
:param str symbol: not used by bingx setPositionMode()
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from the exchange
Nr  falser  )!swapV1PrivatePostPositionSideDualr  )rr  rV  r  r}  r  r  s         rt  set_position_modebingx.set_position_moden  sB      %& 0
 55dkk'6RSSrv  c                 \   U R                  5         U R                  U5      nU R                  X#XEXg5      n	XS'   SU	S'   Sn
US   (       a!  U R                  U R	                  X5      5      n
O U R                  U R	                  X5      5      n
U R                  U
S5      nU R                  X5      $ )a  
       cancels an order and places a new order

       https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Cancel%20order%20and%20place%20a%20new%20order  # spot
       https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Cancel%20an%20order%20and%20then%20Place%20a%20new%20order  # swap

       :param str id: 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 the currency you want to trade in units of the 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.triggerPrice]: Trigger price used for TAKE_STOP_LIMIT, TAKE_STOP_MARKET, TRIGGER_LIMIT, TRIGGER_MARKET order types.
       :param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered
       :param float [params.takeProfit.triggerPrice]: take profit trigger price
       :param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered
       :param float [params.stopLoss.triggerPrice]: stop loss trigger price

EXCHANGE SPECIFIC PARAMETERS
       :param str [params.cancelClientOrderID]: the user-defined id of the order to be canceled, 1-40 characters, different orders cannot use the same clientOrderID, only supports a query range of 2 hours
       :param str [params.cancelRestrictions]: cancel orders with specified status, NEW: New order, PENDING: Pending order, PARTIALLY_FILLED: Partially filled
       :param str [params.cancelReplaceMode]: STOP_ON_FAILURE - if the cancel order fails, it will not continue to place a new order, ALLOW_FAILURE - regardless of whether the cancel order succeeds or fails, it will continue to place a new order
       :param float [params.quoteOrderQty]: order amount
       :param str [params.newClientOrderId]: custom order id consisting of letters, numbers, and _, 1-40 characters, different orders cannot use the same newClientOrderId.
       :param str [params.positionSide]: *contract only* position direction, required for single position, for both long and short positions only LONG or SHORT can be chosen, defaults to LONG if empty
       :param str [params.reduceOnly]: *contract only* True or False, default=false for single position mode. self parameter is not accepted for both long and short positions mode
       :param float [params.priceRate]: *contract only* for type TRAILING_STOP_Market or TRAILING_TP_SL, Max = 1
       :param str [params.workingType]: *contract only* StopPrice trigger price types, MARK_PRICE(default), CONTRACT_PRICE, or INDEX_PRICE
       :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
       cancelOrderIdSTOP_ON_FAILUREcancelReplaceModeNrD   rx  )r  r  r  #swapV1PrivatePostTradeCancelReplacer  (spotV1PrivatePostTradeOrderCancelReplacer{  r  )rr  r5   r  r  r@  r  rJ  r}  r  r  r~  rx  s               rt  
edit_orderbingx.edit_order  s    @ 	V$++F$V#% '8#$&>??G@\]Hp DDT[[QXEabHL ~~h/--rv  c                 X   U R                  5         U R                  U5      nSUS   0nSnSnU R                  SX25      u  pRUS:X  a!  U R                  U R	                  XB5      5      nO U R                  U R	                  XB5      5      nU R                  US0 5      nU R                  Xs5      $ )a  
fetches the margin mode of the trading pair

https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Margin%20Type
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Margin%20Type

:param str symbol: unified symbol of the market to fetch the margin mode for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin mode structure <https://docs.ccxt.com/#/?id=margin-mode-structure>`
r  r5   Nr|   r.  rx  )r  r  r   cswapV1PrivateGetTradeMarginTyper  swapV2PrivateGetTradeMarginTyper{  parse_margin_mode)rr  r  r}  r  r  r  r~  rx  s           rt  fetch_margin_modebingx.fetch_margin_mode  s     	V$fTl
 99:KV\i<<T[[=YZH ;;DKK<XYH ~~h3%%d33rv  c                     U R                  US5      nU R                  US5      nUS:X  a  SOUnUU R                  X2SS5      US.$ )Nr  r  crossedr  r  rD   )r  r  rO  )r  r]  r\  )rr  rO  r  rb  r  s        rt  r'  bingx.parse_margin_modeA  sV    ##J9++JE
!+y!8Wz
&&xfE$
 	
rv  c                    U R                  5         U R                  U5      nSUS   0nSn0 nU R                  US0 5      nUS   (       a#  U R                  U R	                  XB5      5      nUnOBUS   (       a  U R                  U5      nUnO$U R                  U5      nU R                  US0 5      nU R                  Xc5      $ )a  
fetch the trading fees for a market

https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Trading%20Commission%20Rate
https://bingx-api.github.io/docs/#/en-us/swapV2/account-api.html#Query%20Trading%20Commission%20Rate
https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Trade%20Commission%20Rate

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
r  r5   Nrx  rB   r.  rM  )r  r  r{  "spotV1PrivateGetUserCommissionRater  #cswapV1PrivateGetUserCommissionRate"swapV2PrivateGetUserCommissionRateparse_trading_fee)rr  r  r}  r  r  r~  rM  rx  s           rt  fetch_trading_feebingx.fetch_trading_feeK  s     	V$fTl
 
~~h3&>>>t{{7?[\H Ji CCFK "
BB6J "^^D,C
%%j99rv  r  c                 h    Ub  US   OS nUUU R                  US5      U R                  US5      SSS.$ )Nr  makerCommissionRatetakerCommissionRateF)r  r  r   r   r  r   )r  )rr  r  r  r  s       rt  r1  bingx.parse_trading_fee  sM     '-&8!t%%c+@A%%c+@A
 	
rv  c                 <   [        UR                  5       5      nU R                  U5      nS nS n[        S[	        U5      5       H  nX6   nX   n[        U[         5      (       a  S n	[        S[	        U5      5       Hq  n
X   n[        U[        5      nU(       a/  U
S:  a  U	S[        U5      -   S-   -  n	M:  S[        U5      -   S-   n	MM  U
S:  a  U	S[        U5      -   -  n	Mf  [        U5      n	Ms     SU	-   S-   nUnUS:X  a
  US-   U-   nM  USU-   S-   U-   -  nM     U$ )	Nr   z,""r  r  r  =&r  )rr  r}  r  r  adjustedValuer  r  r^  r  r  r  r  isStrings                rt  custom_encodebingx.custom_encode  s+   v{{}%yy!q#d)$A'CKE%&&q#e*-A#(8L *< =Hq5"i#l2C&Cc&IIF%(3|+<%<s%BFq5"cC,=&==F%(%6F . !$fs 2%AvsU*#)c/E11/ %0 rv  r   GETc                    US   nUS   nUS   n	U R                  U R                  SS5      n
U
(       a$  US:w  a  [        U R                  S-   U-   S-   5      eU R	                  U R
                  S	   U   5      nU R                  X5      nUS
:H  nUS:H  nU(       d  U(       a  U(       a  SnOSnUS   nUS   n	US:w  a  US:X  a  US:X  a  US-  nOUSU-   -  nUSU-   S-   U-   -  nU R                  X@R                  U5      5      nU R                  5       US'   U R                  U5      nU	S:X  a   U(       a  USU R                  U5      -   -  nGO-U	S:X  Ga&  U R                  5         US:H  =(       d    US:H  =(       a    US:H  nS nS nU(       a  U R                  U5      nO#U R                  U5      nU R                  US5      nU R!                  U R#                  U5      U R#                  U R$                  5      [&        R(                  5      nU R*                  U R-                  U R                  SS5      S.nU(       a  SUS'   UUS '   U R/                  U5      nO#U R                  US5      nUSU-   S!-   S"-   U-   -  nXXeS#.$ )$Nr   r   r   r  FrD   z) does not have a testnet/sandbox URL for z
 endpointsr   r   r   zaccount/transferz	api/assetr  r   rB   r   z/apir  rO  r   ?r   r   POSTTrC  r/  )zX-BX-APIKEYzX-SOURCE-KEYzapplication/jsonzContent-Type	signaturer;  z
signature=)urlmethodbodyheaders)r  rl  r+   r5   implode_hostnamer   implode_paramsr  extract_paramsrk  keysort	urlencoder  r>  rS  	rawencodehmacencoder   hashlibsha256r   r  rd  )rr  pathsectionrF  r}  rH  rG  r  r<   accessr  rE  versionIsTransferversionIsAssetisJsonContentTypeparsedParamsencodeRequestrD  querys                      rt  sign
bingx.sign  s   qz!*NN4<<F	$&.tww)TTW[[^jjkk##DIIe$4T$:;""40$
2!W, )"ajGQZF++v~'T/vsTz!sW}s"T))6#6#6t#<="jjl{f%XsT^^F333y ++-#'<#7"XTEW=W!p_eio_oL M  $ 2 26 :#008 $|T B		$++m"<dkk$++>VX_XfXfgI#{{ $ 0 0x PG !*<'&/{#yy(|T:sU{S(<7)CCdOOrv  c                 "    U R                  5       $ N)r1  )rr  s    rt  rk  bingx.nonce  s      ""rv  enablec                 H   > [         [        U ]  U5        XR                  S'   g )Nr  )ro  r1   set_sandbox_moderl  )rr  ra  rs  s     rt  rc  bingx.set_sandbox_mode  s    eT+F3&,]#rv  httpCodereasonrE  rF  rH  rG  c
                    Uc  g U R                  US5      n
U R                  US5      nU R                  US5      nUc	  U
b  U
S:w  a  Ub  UnU R                  S-   U-   nU R                  U R                  S   X5        U R                  U R                  S   X5        U R	                  U R                  S   X5        [        U5      eg )Nr  msgtransferErrorMsgr{   r  r  )r  r5   throw_exactly_matched_exceptionr  throw_broadly_matched_exceptionr!   )rr  re  rf  rE  rF  rH  rG  r~  requestHeadersrequestBodyr  messageri  feedbacks                 rt  handle_errorsbingx.handle_errors  s     &1""8U3++H6HI(d.>43;+*ww}t+H001I7]001I4Z001I7]))rv   r_  )__name__
__module____qualname____firstlineno__r   rp  r
   r  r   r  r    r   r  r  r  dictr  r  r  r   r  r)  r   r2  rd  r   rq  r   rx  r   r   r}  rv  r   r  r  r  r  r   r  r   r  r  r  r  r   r  r  r   r  r
  r  r  r   floatr0  r4  r7  r   r   r  r/  r   r  r^  r  r   r  r  r  r  r  r  r  r  r!  r(  r+  r%  r   r   rF  r   rK  rI  r	   rY  r_  ri  r   ro  rs  r  r  r  r   r  r  r  r  r   r  r  intr  r  r  r  r  rS  r  r  r  r  r  boolr  r"  r   r(  r'  r   r2  r1  r>  r\  rk  rc  rq  __static_attributes____classcell__)rs  s   @rt  r1   r1      s
   d# dL !# 5s 5, ') uZ un+DL +B"+H+._4 _F _B $& ;$v, ;. 9=4^bkm XJ# XJ# XJS XJX[ XJrvw{r| XJt2
 2
4 2
h 6:UW =?3 =?s =?# =?\`af\g =?~^ ^v ^ ^@ :>b ms m3 mY m^ 68 &5 &5K &5P 6:" 77 7 7 
6 
[ 
B 8<$]ajl 1M 1MC 1MWZ 1Mf
6 
" 79 78# 78rF B 02 :33 :3f :3x 04B =4W =47 =4~ 46 5;s 5;& 5;n 48 64 64w 64pb4 b b6 bH $& u,( u,nj) j)X @DRV_a ;RS ;R ;RC ;Rfjksft ;Rz 26b [8w [8T(^ [8z 24 R2S R2hwt wV wr _a 
MC 
My 
MPU 
M RT 	N 	N5 	N SU 	O 	OE 	O os{} z,3 z,i z,y z,Z_ z,hk z,x gksu B03 B0i B0y B0RW B0`c B0H @B _1D$6 _1B	3	3S 	3k kv k kZ: : 37r m/s m/C m/^ /32 I) I)V ;?r c*c c*C c*J <> &s &P 26b j/c j/3 j/X *.Dt\^ U?3 U?c U? U?cghmcn U?n /3TXac s? s?3 s?c s?hlmrhs s?j 154VZce :# :S :PS :jnotju :* 37TX\eg <C <s <RU <* >BPTcgpr }?s }?# }?]` }?~ [] 5
S 5
% 5
c 5
c 5
an 5
n +/TPT]_ <BC <Bs <B# <Bdhivdw <B|
t 
x 
= 
.:C :C : DF )0s )0$~J^ )0V 79 ># >^ >4
h 
R` 
4 *.Dt\^ )I3 )Ic )I )Icghsct )IV -1tRV_a +Ic +I +IC +Ifjkvfw +IZ[
T [
X [
Q\ [
z:s :& >B"  W#  Ws  WD =? M Me MCU M @B MC M MFX M =?  @  @e  @CU  @D
d 
F 
N` 
. 24 81S 81 81t$
t $
V $
x $
L 9=R +US +U# +Uz -1tRV_a CFc CF CFC CFJ @ <@ # #* KOWY 2,S 2,% 2,# 2,C 2,^i 2,h$ 37TX\eg ^KC ^Ks ^KRU ^K@'V 'R =A B.S B.	 B.PU B.H *, :X :x 15R 
# 
8 =A T Tc T: `drv  @B F.S F.# F.Y F.i F.Y\ F.lo F.  GL F.P 57 ,4 ,4: ,4\
D 
* 
 57 @: @:;N @:D
T 
6 
EX 
"@ "*%DW[ 4Pl#-t -c 3 S # X\ dg  rv  r1   )7ccxt.base.exchanger   ccxt.abstract.bingxr   rQ  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   typingr    ccxt.base.errorsr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   ccxt.base.decimal_to_precisionr.   ccxt.base.preciser/   r1   rs  rv  rt  <module>r     s    ( +   ~  ~  ~  ~  ~  ~  ~  ~  * 0 - - . ' & . ) * ) , + 4 %tcHk tcrv  