
    eir                    ,   d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZ d dlm Z  d dlm!Z! d dlm"Z" d d	lm#Z# d d
lm$Z$ d dlm%Z% d dlm&Z& d dlm'Z' d dl(m)Z) d dl*m+Z+  G d dee          Z,dS )    )Exchange)ImplicitAPIN)AnyBalancesCurrencyIntLeverage
MarginModeMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateTradeTransactionFundingRateHistoryTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)InsufficientFunds)NotSupported)RateLimitExceeded)	TICK_SIZE)Precisec                       e Zd Zdef fdZi fdee         fdZdedefdZ	di fde
dedefd	Zdedefd
Zddi fde
dededee         fdZdddi fdedededee         fdZdfdededefdZdedefdZdddi fde
dededee         fdZdfdedefdZdi fdedefdZi fde
defdZdfdededefdZi fde
defdZdfdedefdZ dddi fdedededee!         fdZ"dfdefdZ#di fde
de$de%de&d e'de(fd!Z)di fde
de$de%de&d e'f
d"Z*d#edefd$Z+i fd%ee,         fd&Z-ddi fd'e
de
de$de%de'd e'de(fd(Z.i fd%ee,         dee(         fd)Z/ddi fd'e
de
de$de%de'd e'fd*Z0di fdedee(         fd+Z1dddi fdedededee(         fd,Z2di fd'e
defd-Z3dddi fdedededee(         fd.Z4di fd/e
dedefd0Z5dfd1edede(fd2Z6dedefd3Z7d4edefd5Z8d6edefd7Z9di fd8e:defd9Z;i fde
de<fd:Z=dfd8edede<fd;Z>di fdedee?         fd<Z@i fde
dee?         fd=ZAdfd>edefd?ZBdedefd@ZCddi fde
dededee?         fdAZDdddi fdedededee?         fdBZEi fde
deFfdCZGdfdDededeFfdEZHdi fdDe
defdFZIdi fdGeJdefdHZKdi fdefdIZLi fdeMfdJZNdeMfdKZOi fdLe
de&dMe
dNe
dePf
dOZQdddi fdLedededeeP         fdPZRdfdQedReSdePfdSZTd6edefdTZUdddi fdLedededeeV         fdUZWdddi fdLedededeeV         fdVZXdW ZYdfdXedReSdeVfdYZZd6edefdZZ[d[d\i ddfd]ed^ed_efd`Z\dae:dbe
dce
dde
d^ed_e
fdeZ] xZ^S )gbydfireturnc                    |                      t          t          |                                           i ddddddgddd	d
dddddi dd ddddddddddddddddddddddddddddddd di d!dd"dd#dd$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1di d2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBdi dCddDddEddFddGddHddIddJddKddLddMddNddOddPddQddRddSdi dTddUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcddddi deddfddgddhddiddjddkddlddmddnddoddpddqddrddsddtddudi dvddwddxddyddzdd{dd|dd}dd~dddddddddddddddddi ddddddddddddddddddddddddddddddddddi dddddddddddddddddddddddddddddddddddddddddddddddddddi ddddddddddddddii dddddddddddddddddddddddddddddddddddddddddȜddddddddddddɜdʜddd ddddddd̜ddd ddddd͜ddddddddΜddiddddddԜd ddddd՜dddddd֜d ddddddddלd ddidٜd dڜd d dڜdۜddddddddddddddt          di dt
          dt
          dt          dt          dt
          dt          dt          dt          dt          dt
          dt          dt          dt          dt          dt          dt          dt          dt          iddi dd didddddddd	d
ddddddd          S (  Nidr(   nameBYDFi	countriesSG	rateLimit2   versionv1	certifiedFproThasCORSspotmarginswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMarginborrowMargincancelAllOrderscancelOrdercancelOrderscancelOrdersWithClientOrderIdcancelOrderWithClientOrderIdcloseAllPositionsclosePositioncreateDepositAddresscreateLimitBuyOrdercreateLimitOrdercreateLimitSellOrdercreateMarketBuyOrdercreateMarketBuyOrderWithCostcreateMarketOrdercreateMarketOrderWithCostcreateMarketSellOrdercreateMarketSellOrderWithCostcreateOrdercreateOrders$createOrderWithTakeProfitAndStopLosscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopLossOrdercreateStopMarketOrdercreateStopOrdercreateTakeProfitOrdercreateTrailingAmountOrdercreateTrailingPercentOrdercreateTriggerOrderdeposit	editOrder
editOrderseditOrderWithClientOrderIdfetchAccountsfetchBalancefetchBidsAsksfetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchCanceledAndClosedOrdersfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchConvertCurrenciesfetchConvertQuotefetchConvertTradefetchConvertTradeHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchIsolatedPositionsfetchL2OrderBookfetchL3OrderBookfetchLastPricesfetchLedgerfetchLedgerEntryfetchLeveragefetchLeveragesfetchLeverageTiersfetchLiquidationsfetchLongShortRatiofetchLongShortRatioHistoryfetchMarginAdjustmentHistoryfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricesfetchMyLiquidationsfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrderfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrdersByStatusfetchOrderTradesfetchOrderWithClientOrderIdfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTradingLimitsfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransferfetchTransfersfetchUnderlyingAssetsfetchVolatilityHistoryfetchWithdrawAddressesfetchWithdrawalfetchWithdrawalsfetchWithdrawalWhitelistreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeverage	setMarginsetMarginMode)setPositionModesignIntransferwatchMyLiquidationsForSymbolswithdrawwsurlszOhttps://github.com/user-attachments/assets/bfffb73d-29bd-465d-b75b-98e210491769zhttps://api.bydfi.com/api)publicprivatezhttps://bydfi.com/z https://developers.bydfi.com/en/z$https://partner.bydfi.com/j/DilWutCI)logoapiwwwdocreferralfeesr   get   )zv1/public/api_limitszv1/fapi/market/exchange_infozv1/fapi/market/depthzv1/fapi/market/tradeszv1/fapi/market/klineszv1/fapi/market/ticker/24hrzv1/fapi/market/ticker/pricezv1/fapi/market/mark_pricezv1/fapi/market/funding_ratez#v1/fapi/market/funding_rate_historyzv1/fapi/market/risk_limitzv1/account/assetszv1/account/transfer_recordszv1/spot/deposit_recordszv1/spot/withdraw_recordszv1/fapi/trade/open_orderzv1/fapi/trade/plan_orderv1/fapi/trade/leveragezv1/fapi/trade/history_orderzv1/fapi/trade/history_tradezv1/fapi/trade/position_historyzv1/fapi/trade/positionszv1/fapi/account/balancezv1/fapi/user_data/assets_margin$v1/fapi/user_data/position_side/dualzv1/agent/teamszv1/agent/agent_linkszv1/agent/regular_overview)zv1/agent/agent_sub_overviewzv1/agent/partener_user_depositzv1/agent/partener_users_datazv1/agent/affiliate_uidszv1/agent/affiliate_commissionz#v1/agent/internal_withdrawal_status)zv1/account/transferzv1/fapi/trade/place_orderzv1/fapi/trade/batch_place_orderzv1/fapi/trade/edit_orderzv1/fapi/trade/batch_edit_orderzv1/fapi/trade/cancel_all_orderr   z#v1/fapi/trade/batch_leverage_marginzv1/fapi/user_data/margin_typer   zv1/agent/internal_withdrawal)r   postfeatures)marklastindex)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypestopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedselfTradePreventiontrailingicebergleveragemarketBuyRequiresPricemarketBuyByCostmax           )r   daysBacklimit	untilDayssymbolRequired)r   triggerr   r  )r   r   r  r   r  )r   r   r   r  r  r   r  r   )sandboxrR   rS   r   r   r   r   r   rl   ro   r   )linearinverse)r8   r:   r;   
timeframes1m3m5m15m30m1h2h4h6h12h1d)r  r	  r
  r  r  r  r  r  r  r  r  precisionMode
exceptions101001101103102001102002401500501506510511513514600zPosition does not existz Requires transaction permissionszService errorztransfer failedz
is missing)exactbroadcommonCurrenciesoptionsERC20ETHGTCr   r   	POST_ONLY)r(  r   r   r   SPOTUMFUTUREFUNDINGCMFUTURE)r8   r:   fundingr  r.  r  )r*  r+  r,  r-  )networksr   accountsByTypeaccountsById)deep_extendsuperr(   describer%   r   r!   r   r   r$   r"   r    )self	__class__s    H/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/bydfi.pyr4  zbydfi.describe   s   eT 2 2 ; ; = = y@
'y@
Gy@
 $y@
 	y@

 ty@
 y@
 4y@
  ``` %` 	`
 %` %` U` $U` '` ` "4` u` ` 0` /`  $U!`"  #` `$ '%`& &u'`( #D)`* '+`, '-`. //`0 $T1`2 ,U3`4 (5`6 07`8 t9`: ;`< 7=`> &t?`@ (A`B 'C`D &tE` ` `F (G`H "5I`J (K`L ,UM`N -dO`P %eQ`R 5S`T TU`V dW`X -dY`Z  [`\ ]`^  _`` &ua`b "5c`d +Ee`f )%g` ` `h #Ei`j ,Uk`l /m`n &uo`p #Eq`r $Us`t )%u`v $Uw`x $Uy`z +E{`| '}`~ (`@ "5A`B C`D &uE`F (G`H 1%I` ` `J  K`L +EM`N *5O`P +EQ`R &uS`T 'U`V (W`X #DY`Z *4[`\ $U]`^ u_`` "5a`b *5c`d +Ee`f )%g`h #Di`j #Ek` ` `l "5m`n uo`p #Eq`r  s`t !%u`v %ew`x $Uy`z &u{`| -e}`~ /`@ "4A`B #EC`D +EE`F G`H !%I`J "5K`L &uM` ` `N +EO`P  Q`R dS`T $UU`V +EW`X %eY`Z !%[`\ "4]`^ u_`` #Ea`b ec`d !$e`f "5g`h ui`j &uk`l #Em`n .uo` ` `p  q`r 's`t $Tu`v !$w`x *4y`z ({`| %e}`~ )%`@ )%A`B uC`D tE`F G`H UI`J tK`L "5M`N #EO`P %eQ` ` `R &uS`T 'U`V $UW`X  Y`Z !$[`\ (]`^ )%_`` )%a`b "5c`d #De`f +Eg`h i`j #Ek`l &um`n to`p Uq`r  s` `t $( 16!` ` `y@
R i9:  ,9B	 	Sy@
f  gy@
j 018901121267785678?@56  +Q5q 21 3A	
 3A 3A 1! 6q 6q 9! 21 21 :1 ? )!  /!" 4Q#$ 89:;89349:?@/  4 0156;<45:;:;23?@9:@A89 5' '!8 8ky@
\  $)*/,1(,(,).1 1
 .2/3:>'+'+&*',	, , '+38(,',(-6;/4/( (4 "1) +0(+%()*.3* * '+*/'+(-.2	+ + +0%('+(-.2, , (,*/%((+)*',(-.39 9 .2#S'}A AD  $GD DL ## OK K]y@
t	  u	y@
N
 YO
y@
P
 11 j .	
 . = = = , . : : : .z 78H  $]!" &'8#( !"3) Q
y@
@  !Ay@
D U !  %	    #&()	# # # &( )	! !! Ey@
 y y y	    c                     |                      |          }|                     |dg           }|                     |          S )a.  
        retrieves data on all markets for bydfi

        https://developers.bydfi.com/en/futures/market#fetching-trading-rules-and-pairs

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        data)!publicGetV1FapiMarketExchangeInfo	safe_listparse_markets)r5  paramsresponser:  s       r7  fetch_marketszbydfi.fetch_markets  sC     99&AAN ~~h33!!$'''r8  marketc                    |                      |d          }|                      |d          }|                      |d          }|                      |d          }|                     |          }|                     |          }|                     |          }|dz   |z   dz   |z   }	|                     |d          }
|                      |d          }|                      |d	          }t          j        ||          }|                      |d
          }|                      |d          }t          j        ||          }|                      |d          }|                     |                      |d                    }|                     |                      |d                    }t          j        ||          }|                     |                      |d                    }|                     |d          }|                     |d          }|                     |d          }|                      |d          }| 	                    i d|d|	d|d|d|d|d|d|dddddd dd d!dd"dd#|d$k    d%d d&|
 |
||| 
                    |          d d d d | 
                    |          | 
                    |          | 
                    |          d'd |d(| 
                    |          | 
                    |          d(d d d(d d d(d)|                     |                      |d*                    |d+          S ),Nsymbol	baseAsset
quoteAssetmarginAsset/:reverselimitMaxQtymarketMaxQtymarketMinQtylimitMinQtycontractFactorpriceOrderPrecisionvolumePrecisionbasePrecisionfeeRateTakerfeeRateMakermaxLeverageLevelstatusr+   basequotesettlebaseIdquoteIdsettleIdtyper:   r8   Fr9   Tr;   r<   activeNORMALcontractr  )amountpricerV  )minr   )r   r`  ra  cost	createdAt)r  takermakercontractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedinfo)safe_stringsafe_currency_code	safe_boolr&   
string_max
string_minparse_precision
string_divsafe_numbersafe_market_structureparse_number	parse8601)r5  rA  r+   rY  rZ  r[  rV  rW  rX  rC  r  rJ  rK  maxAmountStringrL  rM  minAmountStringrg  pricePrecisionrawAmountPrecisionamountPrecisionrQ  re  rf  maxLeveragerU  s                             r7  parse_marketzbydfi.parse_market  s   @ fh//!!&+66""6<88##FM::&&v..''00((22e#c)F2..33&&v}==''??!,[,GG''??&&v}==!,\;GG''0@AA--d.>.>vG\.].]^^!11$2B2B6K\2]2]^^!,-?NN,,T-=-=fo-V-VWW  88  88&&v/ABB!!&(33)) 3+
"3+
f3+
 D3+
 U	3+

 f3+
 f3+
 w3+
 3+
 F3+
 E3+
 d3+
 D3+
 e3+
 e3+
 f(3+
  !3+
" 'k#3+
$  --l;;"++O<<**>::))-88   & 
  ,,_==,,_== 
   
    $ ~~d&6&6v{&K&KLLe3+
 3+
 3+
 3 3 3	r8  NrC  r   c           	         |                                   |                     |          }d|d         i}||                     |          |d<   |                     |                     ||                    }|                     |di           }|                                 }|                     ||d         |dddd	          }	|                     |d
          |	d<   |	S )a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://developers.bydfi.com/en/futures/market#depth-information

        :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, could be 5, 10, 20, 50, 100, 500 or 1000(default 500)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.loc]: crypto location, default: us
        :returns dict: A dictionary of `order book structures <https://github.com/ccxt/ccxt/wiki/Manual#order-book-structure>` indexed by market symbols
        rC  r+   Nr   r:  bidsasksra  r`  lastUpdateIdnonce)	load_marketsrA  get_closest_limitpublicGetV1FapiMarketDepthextend	safe_dictmillisecondsparse_order_booksafe_integer)
r5  rC  r   r>  rA  requestr?  r:  	timestamp	orderBooks
             r7  fetch_order_bookzbydfi.fetch_order_book5  s     	V$$fTl
 #55e<<GG224;;w3O3OPP6 ~~h33%%''	))$x0@)VU[]dfnoo	!..t^DD	'r8  c                 ~    g d}d}t          dt          |                    D ]}|||         k    r
||         } n|S )N)r   
      r1   d   r     r  r   )rangelen)r5  r   rm  resultis        r7  r  zbydfi.get_closest_limiti  sZ    000q#f++&& 	 	Aq	!! " r8  sincec                 &   |                                   |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |dg           }|                     ||||          S )a  
        get the list of most recent trades for a particular symbol

        https://developers.bydfi.com/en/futures/market#recent-trades

        :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(default 500, max 1000)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.fromId]: retrieve from which trade ID to start. Default to retrieve the most recent trade records
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=public-trades>`
        rC  r+   Nr   r:  )r  rA  publicGetV1FapiMarketTradesr  r<  parse_trades)	r5  rC  r  r   r>  rA  r  r?  r:  s	            r7  fetch_tradeszbydfi.fetch_tradesr  s     	V$$fTl
 $GG33DKK4P4PQQ$ ~~h33  vue<<<r8  c           	         |                                   |                     |dd          }|rad}|                     |d          }|                     |ddi          }|                     d|||||d          }|                     |d          S d	}|                     |dd
|          \  }}d
|i}	d}
| |                     |          }
|
d         |	d<   |                     d||          }|||	d<   | 	                    |                     |	|                    }| 
                    |dg           }|                     ||
||          S )a  
        fetch all trades made by the user

        https://developers.bydfi.com/en/futures/trade#historical-trades-query

        :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]: the latest time in ms to fetch trades for
        :param str [params.contractType]: FUTURE or DELIVERY, default is FUTURE
        :param str [params.wallet]: The unique code of a sub-wallet
        :param str [params.orderType]: order type('LIMIT', 'MARKET', 'LIQ', 'LIMIT_CLOSE', 'MARKET_CLOSE', 'STOP', 'TAKE_PROFIT', 'STOP_MARKET', 'TAKE_PROFIT_MARKET' or 'TRAILING_STOP_MARKET')
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        paginateFr   paginationDirectionbackwardr   Tr  FUTUREcontractTypeNr+   rC  r   r:  )r  rr  omitr  fetch_paginated_call_dynamicsort_byhandle_option_and_paramsrA  handle_since_and_until!privateGetV1FapiTradeHistoryTrader<  r  r5  rC  r  r   r>  r  maxLimitpaginatedResponser  r  rA  r?  r:  s                r7  fetch_my_tradeszbydfi.fetch_my_trades  s|     	>>&*e<< 	@HYYvz22F[[*?)LMMF $ A A/SY[`bgioqy{  !A  !A<< 1;???#<<V_VdfrssfL
 [[((F &tGH,,_eVLL$GG99$++gv:V:VWW6 ~~h33  vue<<<r8  tradec                 x   |                      |d          }|                     ||          }|                     |d          }d }|                      |d          }|                      |d          }|||d         d}|                      |d          }d }	||                     |d          }	|                     |||                     |          |d         |                      |d	          ||                     |          |	d |                     |d
d          |                     |dd          d |d|          S )NrC  timer\  feerX  rc  currencyorderIdsider+   ra  	dealPricequantity
dealVolume)ro  r  datetimerC  r+   orderr\  r  takerOrMakerra  r`  rc  r  )rp  safe_marketr  safe_string_lower
safe_tradeiso8601parse_trade_typesafe_string_2)
r5  r  rA  marketIdr  r  rawTypefeeCostr  r  s
             r7  parse_tradezbydfi.parse_trade  sd   > ##E844!!(F33%%eV44	""5&11""5%00"8, C ""5)44?))%88D"Y//X&""5$//))'22 ''wDD((
LII 
  
   	r8  r\  c                 <    dddd}|                      |||          S )Nr   rA  liquidation)123rp  r5  r\  typess      r7  r  zbydfi.parse_trade_type  s1    
 

 tT222r8  r  c           	         |                                   d}d}|                     |dd          \  }}|r|                     d||||||          S |                     |          }|                     | j        ||          }	|d         |	d}
|}|r|n|}d}|                     |dd          \  }}|                                 }|                     |          d	z  }||z  }|
|||z
  }|}n|||z   }||k    r|}n|||z
  }||
d
<   ||
d<   |||
d<   |                     | 	                    |
|                    }| 
                    |dg           }|                     |||||          }|S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://developers.bydfi.com/en/futures/market#candlestick-data

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch(max 500)
        :param dict [params]: extra parameters specific to the bitteam api endpoint
        :param int [params.until]: timestamp in ms of the latest candle to fetch
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        r   Fr   r  r+   )rC  intervalNuntilr  	startTimeendTimer   r:  )r  r  "fetch_paginated_call_deterministicrA  rp  r  r  parse_timeframepublicGetV1FapiMarketKlinesr  r<  parse_ohlcvs)r5  rC  	timeframer  r   r>  r  r  rA  r  r  r  numberOfCandlesr  nowduration	timeDeltar?  r:  r  s                       r7  fetch_ohlcvzbydfi.fetch_ohlcv$  s    	88zZZ& 	|::<QVX]_hjprz{{{V$$##DOY	JJTl 
 
 	#(6%%h55flGTTv!!''	22T9.	iIEE]	)Es{{	)I("	$GG33DKK4P4PQQ& ~~h33""4E5IIr8  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Ntohlcv)r  rw  )r5  ohlcvrA  s      r7  parse_ohlcvzbydfi.parse_ohlcvi  s     eS))UC((UC((UC((UC((UC((
 	
r8  symbolsc                     |                                   |                     |          }|                     |dg           }|                     ||          S )a%  

        https://developers.bydfi.com/en/futures/market#24hr-price-change-statistics

        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :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>`
        r:  )r  publicGetV1FapiMarketTicker24hrr<  parse_tickers)r5  r  r>  r?  r:  s        r7  fetch_tickerszbydfi.fetch_tickers~  sV     	77??& ~~h33!!$000r8  c                 B   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     |di           }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://developers.bydfi.com/en/futures/market#24hr-price-change-statistics

        :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>`
        rC  r+   r:  r   )r  rA  r  r  r<  r  parse_ticker)r5  rC  r>  rA  r  r?  r:  tickers           r7  fetch_tickerzbydfi.fetch_ticker  s     	V$$fTl
 77GV8T8TUU~~h33a,,  000r8  r  c           	      P   |                      |dd          }|                     ||          }|                     |dd          }|                      |dd          }|                     i d|                     ||          d|d|                     |          d	|                      |d	d
          d|                      |dd          dd dd dd dd dd d|                      |dd          d|d|dd dd dd dd |                      |dd          d d d |d|          S )NrC  sr  Er   r  r  r  highr  lowr  bid	bidVolumeask	askVolumevwapopenr  closepreviousClosechange
percentageaveragevolr  )
baseVolumequoteVolume	markPrice
indexPricero  )r  r  safe_integer_2safe_tickersafe_symbolr  )r5  r  rA  r  r  r   s         r7  r  zbydfi.parse_ticker  s    %%fh<<!!(F33''<<	!!&&#66 !
d&&x88!
!
 Y//!
 D&&vvs;;	!

 4%%feS99!
 4!
 !
 4!
 !
 D!
 D&&vvs;;!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ ,,VUC@@-!
 !
 !
. /  	r8  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d          }|                     ||          S )ah  
        fetch the current funding rate

        https://developers.bydfi.com/en/futures/market#recent-funding-rate

        :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>`
        rC  r+   r:  )r  rA   publicGetV1FapiMarketFundingRater  r  parse_funding_rate)r5  rC  r>  rA  r  r?  r:  s          r7  fetch_funding_ratezbydfi.fetch_funding_rate  s     	V$$fTl
 88Wf9U9UVV ~~h//&&tV444r8  c                    |                      |d          }|                     ||          }|                     |d          }|                     |d          }i d|d|dd dd dd dd d	|d
|                     |          d|                     |d          dd dd dd d|d|                     |          dd dd dd dd iS )NrC  r  nextFundingTimero  r  r  interestRateestimatedSettlePricer  r  fundingRatelastFundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer  )rp  r	  r  r  rw  )r5  r_  rA  r  rC  r  r  s          r7  r  zbydfi.parse_funding_rate  sh    ##Hh77!!(F33%%h77	#00;LMM
H
f
 
 $	

 D
 #D
 
 Y//
 4++H6GHH
 
 t
 t
 #$8
 "4<<0D#E#E
 "4
  '!
" &t#
$ %
 
 	
r8  c                    |t          | j        dz             |                                  |                     |          }d|d         i}|||d<   |||d<   d}|                     |dd          \  }}|||d	<   |                     |                     ||                    }|                     |d
g           }	|                     |	|||          S )a  
        fetches historical funding rate prices

        https://developers.bydfi.com/en/futures/market#historical-funding-rates

        :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
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/?id=funding-rate-history-structure>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentrC  r+   r  r   r   r  r  r:  )	r    r+   r  rA  r  'publicGetV1FapiMarketFundingRateHistoryr  r<  parse_funding_rate_histories)
r5  rC  r  r   r>  rA  r  r  r?  r:  s
             r7  fetch_funding_rate_historyz bydfi.fetch_funding_rate_history  s     >#DG.e$efffV$$fTl
 #(GK $GG55f>WY`aav!&GI??GU[@\@\]]  ~~h3300vueLLLr8  c                     |                      |d          }|                     |d          }||                     ||          |                     |d          ||                     |          dS )NrC  fundingTimer  )ro  rC  r  r  r  )rp  r  r	  rw  r  )r5  r_  rA  r  r  s        r7  parse_funding_rate_historyz bydfi.parse_funding_rate_historyN  sx     ##Hh77%%h>>	&&x88++HmDD"Y//
 
 	
r8  r  r`  ra  c                 v   |                                   |                     |          }|                     ||||||          }d}	|                     |dd|	          \  }	}|                     |d|	i          }|                     |          }
|                     |
di           }|                     ||          S )aD  
        create a trade order

        https://developers.bydfi.com/en/futures/trade#placing-an-order

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.wallet]: The unique code of a sub-wallet. W001 is the default wallet and the main wallet code of the contract
        :param bool [params.hedged]: True for hedged mode, False for one way mode, default is False
        :param str [params.clientOrderId]: Custom order ID, must be unique for open orders
        :param str [params.timeInForce]: 'GTC'(Good Till Cancelled), 'FOK'(Fill Or Kill), 'IOC'(Immediate Or Cancel), 'PO'(Post Only)
        :param bool [params.postOnly]: True or False, whether the order is post-only
        :param bool [params.reduceOnly]: True or False, True or False whether the order is reduce-only
        :param float [params.stopLossPrice]: The price a stop loss order is triggered at
        :param float [params.takeProfitPrice]: The price a take profit order is triggered at
        :param float [params.trailingTriggerPrice]: the price to activate a trailing order, default uses the price argument or market price if price is not provided
        :param float [params.trailingPercent]: the percent to trail away from the current market price
        :param str [params.triggerPriceType]: 'MARK_PRICE' or 'CONTRACT_PRICE', default is 'CONTRACT_PRICE', the price type used to trigger stop orders
        :param bool [params.closePosition]: True or False, whether to close all positions after triggering, only supported in STOP_MARKET and TAKE_PROFIT_MARKET; not used with quantity
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        W001rR   walletr:  )r  rA  create_order_requestr  r   privatePostV1FapiTradePlaceOrderr  parse_order)r5  rC  r\  r  r`  ra  r>  rA  orderRequestr%  r?  r:  s               r7  create_orderzbydfi.create_ordera  s    4 	V$$00tVUTZ[[66v}hX^__{{<(F1CDD88FF> ~~h33f---r8  c                    |                      |          }|d         |                                d}|                     |d          }	|	d u}
|                     |d          }|d u}|                     |d          }|d u}d }|
s|r8|
r|	n|}|                     |ddg          }|                     ||          |d<   n|r}|                     |dg          }||d<   |                     |          }|                     |d|          \  }}|0|                     ||          |d	<   |                     |dg          }|                                }|d
k    p|dk    p|dk    p|dk    }|r|d
k    r|
rd}nK|rd}nF|rd}nA|t          | j        dz   |z   dz             |                     ||          |d<   |
rd}n|rd}||d<   d}| 	                    |dd|          \  }}| 
                    |dd          }|r5|                     |d          }|dk    r
|rdnd|d<   n|dk    r	|rdnd|d<   | 
                    |dd          }|s0|                     |d          }|                     ||          |d<   n#|dk    r|dk    rt          | j        dz             |                     |          }d}|                     ||d k    |          \  }}|rd }|||d!<   |                     |d!          }|
s|s|r5d"}| 	                    |dd#|          \  }}|                     |          |d$<   |                     ||          S )%Nr+   )rC  r  r   r   trailingPercent	stopPricecallbackRatetrailingTriggerPriceactivationPriceMARKETSTOP_MARKETTAKE_PROFIT_MARKETTRAILING_STOP_MARKETz/ createOrder() requires a price argument for a z orderra  STOPTAKE_PROFITr\  FrR   r   
reduceOnlybuySHORTLONGpositionSidesellrG   r  zX createOrder() closePosition is only supported for stopLoss and takeProfit market ordersr)  r   CONTRACT_PRICEr   workingType)rA  upperrp  r  price_to_precisionnumber_to_stringhandle_param_stringr    r+   r  rr  amount_to_precisionr#   handle_time_in_forcehandle_post_onlyencode_working_typer  )r5  rC  r\  r  r`  ra  r>  rA  r  r   isStopLossOrderr   isTakeProfitOrderr,  isTailingStopOrderr-  r/  isMarketOrderr   r7  rG   r   postOnlyr>  s                           r7  r&  zbydfi.create_order_request  sa   V$$TlJJLL
 
  ((AA(4**63DEE,D8**63DEE-T9	 	E/ 	E)8MoIYYv9J'KLLF#'#:#:69#M#MGK   	EYYv(9':;;F&5GN##'#8#8#?#? +/+C+CFLbdx+y+y( &#/-1-D-DVMa-b-b)*6,B+CDDzz||(*  M0E  M4SgKg  Mmq  vL  nL 	%x" 2(DD& 2/DD' 21D}'2c(cfj(jmu(uvvv#66vuEEGG %" %$66v}hX^__^^FL%@@
 	LYYv|44Fu}}5?*K''V''4>*K&&G'vFF 	EYYv77F"&":":66"J"JGJm##$2F*F*Ftw  *D   D  E  E  E//7700{@Z\bcc& 	&%K"%0GM"YYv}55F 	K/ 	K3E 	K*K"&"?"?Wikv"w"wK%)%=%=k%J%JGM"{{7F+++r8  r>  c                 @    dddddd}|                      |||          S )N
MARK_PRICEr=  )r  r   contractPricer_  r   r  )r5  r>  r  s      r7  rF  zbydfi.encode_working_type  s7    % -($
 
 {K@@@r8  ordersc           	      ,   |                                   t          |          }|dk    rt          | j        dz             g }t	          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d          }	|                     |d          }
|                     |d          }|                     |d	i           }|                     |||	|
||          }|	                    |           d
}| 
                    |dd|          \  }}||d}|                     |                     ||                    }|                     |dg           }|                     |          S )aa  
        create a list of trade orders

        https://developers.bydfi.com/en/futures/trade#batch-order-placement

        :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 str [params.wallet]: The unique code of a sub-wallet. W001 is the default wallet and the main wallet code of the contract
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r   z- createOrders() accepts a maximum of 5 ordersr   rC  r\  r  r`  ra  r>  r$  rR   r%  )r%  rO  r:  )r  r  r!   r+   r  rp  rw  r  r&  appendr  %privatePostV1FapiTradeBatchPlaceOrderr  r<  parse_orders)r5  rO  r>  lengthordersRequestsr  rawOrderrC  r\  r  r`  ra  orderParamsr)  r%  r  r?  r:  s                     r7  create_orderszbydfi.create_orders  s    	VA::TW'VVWWWq#f++&& 		0 		0AayH%%h99F##Hf55D##Hf55D%%h99F$$Xw77E..8R@@K44VT4QVXcddL!!,////66v}hX^__$
 
 ==dkk'SY>Z>Z[[~~h33  &&&r8  r+   c           	      &   |                                   |                     ||d||||          }d}	|                     |dd|	          \  }	}|	|d<   |                     |          }
|                     |
di           }|                     |          S )a  
        edit a trade order

        https://developers.bydfi.com/en/futures/trade#order-modification

        :param str id: order id(mandatory if params.clientOrderId is not provided)
        :param str [symbol]: unified symbol of the market to create an order in
        :param str [type]: not used by bydfi editOrder
        :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 for the order, 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 identifier for the order(could be alternative to id)
        :param str [params.wallet]: The unique code of a sub-wallet. W001 is the default wallet and the main wallet code of the contract
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r   r$  r`   r%  r:  )r  create_edit_order_requestr  privatePostV1FapiTradeEditOrderr  r(  )r5  r+   rC  r\  r  r`  ra  r>  r  r%  r?  r:  s               r7  
edit_orderzbydfi.edit_order&  s    " 	00VWdFTY[abb66v{HV\]]"77@@~~h33%%%r8  c           
      .   |                                   t          |          }|dk    rt          | j        dz             g }t	          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d          }	|                     |d          }
|                     |d          }|                     |d	i           }|                     ||d
|	|
||          }|	                    |           d}| 
                    |dd|          \  }}||d}|                     |                     ||                    }|                     |dg           }|                     |          S )aV  
        edit a list of trade orders

        https://developers.bydfi.com/en/futures/trade#batch-order-modification

        :param Array orders: list of orders to edit, each object should contain the parameters required by editOrder, namely id, symbol, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.wallet]: The unique code of a sub-wallet. W001 is the default wallet and the main wallet code of the contract
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r   z+ editOrders() accepts a maximum of 5 ordersr   r+   rC  r  r`  ra  r>  r   r$  r`   r%  )r%  ra   r:  )r  r  r!   r+   r  rp  rw  r  rZ  rQ  r  $privatePostV1FapiTradeBatchEditOrderr  r<  rS  )r5  rO  r>  rT  rU  r  rV  r+   rC  r  r`  ra  rW  r)  r%  r  r?  r:  s                     r7  edit_orderszbydfi.edit_orders@  s    	VA::TW'TTUUUq#f++&& 		0 		0AayH!!(D11B%%h99F##Hf55D%%h99F$$Xw77E..8R@@K99"fgtU[]bdoppL!!,////66v{HV\]](
 
 <<T[[RX=Y=YZZ~~h33  &&&r8  c                    |                      |d          }i }	||t          | j        dz             |||	d<   |                     |          }
|
d         |	d<   ||                                |	d<   ||                     ||          |	d<   ||                     ||          |	d<   |                     |	|          S )	NclientOrderIdzA editOrder() requires an id argument or a clientOrderId parameterr  r+   rC  r  r  ra  )rp  r    r+   rA  r?  rC  r@  r  )r5  r+   rC  r\  r  r`  ra  r>  ra  r  rA  s              r7  rZ  zbydfi.create_edit_order_requestd  s    ((AAJ]2#DG.q$qrrr^!#GIV$$"4L"jjllGFO"&":":66"J"JGJ#66vuEEGG{{7F+++r8  c                    |t          | j        dz             |                                  |                     |          }d}|                     |dd|          \  }}|d         |d}|                     |                     ||                    }|                     |dg           }|                     ||          S )	a  
        cancel all open orders in a market

        https://developers.bydfi.com/en/futures/trade#complete-order-cancellation

        :param str symbol: unified market symbol of the market to cancel orders in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.wallet]: The unique code of a sub-wallet. W001 is the default wallet and the main wallet code of the contract
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nz- cancelAllOrders() requires a symbol argumentr$  rA   r%  r+   rC  r%  r:  )	r    r+   r  rA  r  $privatePostV1FapiTradeCancelAllOrderr  r<  rS  r5  rC  r>  rA  r%  r  r?  r:  s           r7  cancel_all_orderszbydfi.cancel_all_ordersu  s     >#DG.]$]^^^V$$66v?PRZ\bccTl
 
 <<T[[RX=Y=YZZB ~~h33  v...r8  c                    |t          | j        dz             |                                  |                     |          }d}|                     |dd|          \  }}|d         |d}d}d}	|                     |dd	|	          \  }	}|	s*|                     |                     ||                    }n)|                     |                     ||                    }|                     |d
g           }
| 	                    |
|||          S )aY  
        fetch all unfilled currently open orders

        https://developers.bydfi.com/en/futures/trade#pending-order-query
        https://developers.bydfi.com/en/futures/trade#planned-order-query

        :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 bool [params.trigger]: True or False, whether to fetch conditional orders only
        :param str [params.wallet]: The unique code of a sub-wallet. W001 is the default wallet and the main wallet code of the contract
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nz- fetchOpenOrders() requires a symbol argumentr$  r   r%  r+   rc  Fr  r:  )
r    r+   r  rA  r  privateGetV1FapiTradeOpenOrderr  privateGetV1FapiTradePlanOrderr<  rS  )r5  rC  r  r   r>  rA  r%  r  r?  r  r:  s              r7  fetch_open_orderszbydfi.fetch_open_orders  s*    >#DG.]$]^^^V$$66v?PRZ\bccTl
 
 77@QS\^eff #	YB ::4;;wPV;W;WXXHH::4;;wPV;W;WXXH~~h33  vue<<<r8  c                    |t          | j        dz             |                                  |                     |          }d|d         i}|                     |d          }||t          | j        dz             |||d<   d}|                     |d	d
|          \  }}||d
<   d}d}	|                     |d	d|	          \  }	}|	s*|                     |                     ||                    }n)|                     |                     ||                    }| 	                    |dg           }
| 
                    |
di           }|                     ||          S )aF  
        fetch an open order by the id

        https://developers.bydfi.com/en/futures/trade#pending-order-query
        https://developers.bydfi.com/en/futures/trade#planned-order-query

        :param str id: order id(mandatory if params.clientOrderId is not provided)
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.trigger]: True or False, whether to fetch conditional orders only
        :param str [params.clientOrderId]: a unique identifier for the order(could be alternative to id)
        :param str [params.wallet]: The unique code of a sub-wallet. W001 is the default wallet and the main wallet code of the contract
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nz, fetchOpenOrder() requires a symbol argumentrC  r+   ra  zF fetchOpenOrder() requires an id argument or a clientOrderId parameterr  r$  r   r%  Fr  r:  r   )r    r+   r  rA  rp  r  rh  r  ri  r<  r  r(  )r5  r+   rC  r>  rA  r  ra  r%  r?  r  r:  r  s               r7  fetch_open_orderzbydfi.fetch_open_order  s    >#DG.\$\]]]V$$fTl
 ((AAJ]2#DG.v$vwww^!#GI66v?OQY[abb"77@PR[]dee 	Y::4;;wPV;W;WXXHH::4;;wPV;W;WXXH~~h33tQ++v...r8  c           	         |                                   |                     |dd          }|rad}|                     |d          }|                     |ddi          }|                     d|||||d          }|                     |d          S d	}|                     |dd
|          \  }}d
|i}	d}
| |                     |          }
|
d         |	d<   |                     d||          }|||	d<   | 	                    |                     |	|                    }| 
                    |dg           }|                     ||
||          S )a  
        fetches information on multiple canceled and closed orders made by the user

        https://developers.bydfi.com/en/futures/trade#historical-orders-query

        :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]: timestamp in ms of the latest order
        :param str [params.contractType]: FUTURE or DELIVERY, default is FUTURE
        :param str [params.wallet]: The unique code of a sub-wallet
        :param str [params.orderType]: order type('LIMIT', 'MARKET', 'LIQ', 'LIMIT_CLOSE', 'MARKET_CLOSE', 'STOP', 'TAKE_PROFIT', 'STOP_MARKET', 'TAKE_PROFIT_MARKET' or 'TRAILING_STOP_MARKET')
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        r  Fr   r  r  rl   Tr  r  r  Nr+   rC  r   r:  )r  rr  r  r  r  r  r  rA  r  !privateGetV1FapiTradeHistoryOrderr<  rS  r  s                r7   fetch_canceled_and_closed_ordersz&bydfi.fetch_canceled_and_closed_orders  s     	>>&*e<< 	@HYYvz22F[[*?)LMMF $ A AB`bhjoqvx~  AI  KO  !P  !P<< 1;???#<<VEces  vB   C   CfL
 [[((F &tGH,,-KUTZ[[$GG99$++gv:V:VWW\ ~~h33  vue<<<r8  
methodNamec                     d }|                      ||dd          \  }}|                                 }d}|}||||z
  }|}n||z
  }n|||z
  }||k    r||z   }n|}||d}	|                     |	|          S )Nr  r   $)r  r  )handle_option_and_params_2r  r  )
r5  rp  r  r>  r  r  	sevenDaysr  deltar  s
             r7  r  zbydfi.handle_since_and_untilo  s    77
GU^__v!!+		})O	 "I-		])OEy  !I-"
 
 {{7F+++r8  r  c                    |                      |d          }|                     ||          }|                     |dd          }|                      |d          }|                     |g d          }|dk    p|dk    p|dk    }|d	k    p|d
k    }|                      |d          }	|                     |	          }
d }|
dk    rd}|                      |d          }i }|                     |d          }|||d<   |d         |d<   |                     i d|d|                      |d          d|                      |d          d|d|                     |          dd d|                     |dd          d|                     |          d|d         d| 	                    |          d|
d|d| 
                    |d          d |                     |d           d!|                      |d!          d"|d#|r|nd |r|nd |                      |d$          |                      |d%          d d d ||                     |                      |d&                    d'|          S )(NrC  
createTimectime	orderType)r-  activatePricer   r5  r2  r4  r6  r3  r   r   TrU  quoteFeerc  rW  r  ro  r+   r  ra  r  r  lastTradeTimestamplastUpdateTimestamp
updateTimemtimer\  rK  r7  r  ra  r   r   origQtyexecutedQtyavgPrice)r   r`  filled	remainingrc  tradesr  r  )rp  r  r  safe_string_nparse_order_time_in_forcerw  
safe_orderr  parse_order_statusparse_order_typerr  r  	omit_zero)r5  r  rA  r  r  r  r-  rG  rH  rawTimeInForcer   rK  	rawStatusr  r{  s                  r7  r(  zbydfi.parse_order  s!   B ##E844!!(F33''|WEE	""5+66&&u.\.\.\]]	"f,r']2JrPW[qPq$5[7FZ;Z))%??44^DD$H$$UH55	##E:66"CK$WoC
O  
E 
$""5)44 
 T--e_EE 
 	 

 Y// 
 !$ 
 "4#6#6ulG#T#T 
 d--i88 
 fX& 
 D))'22 
 ; 
  
 $..== 
 D**5&99 
 T%%eW55 
  I! 
" /CYYt# 
$ ->Gyy4&&ui88&&um<<~~d&6&6uj&I&IJJ3 
  
  
4 5  	r8  c                 D    dddddddd}|                      |||          S )Nr   rA  )LIMITr1  r5  r2  r6  r3  r4  r  r  s      r7  r  zbydfi.parse_order_type  s=    #""*$,
 
 tT222r8  r   c                 @    dddddd}|                      |||          S )Nr(  r   r   r   )r(  r   r   r)  TRAILING_STOPr  )r5  r   timeInForcess      r7  r  zbydfi.parse_order_time_in_force  s7    "
 
 k;GGGr8  rU  c           	      F    ddddddddd}|                      |||          S )Nr  closedcanceled)NEWPARTIALLY_FILLEDFILLEDEXPIREDPART_FILLED_CANCELLEDCANCELEDr  4r  r5  rU  statusess      r7  r  zbydfi.parse_order_status  s@     &!%/"	
 	
 &&999r8  r   c                 \   |t          | j        dz             |                                  |                     |          }d}|                     |dd|          \  }}|d         ||d}|                     |                     ||                    }|                     |di           }|S )	a
  
        set the level of leverage for a market

        https://developers.bydfi.com/en/futures/trade#set-leverage-for-single-trading-pair

        :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.wallet]: The unique code of a sub-wallet. W001 is the default wallet and the main wallet code of the contract
        :returns dict: response from the exchange
        Nz) setLeverage() requires a symbol argumentr$  r   r%  r+   )rC  r   r%  r:  )r    r+   r  rA  r  privatePostV1FapiTradeLeverager  r  )	r5  r   rC  r>  rA  r%  r  r?  r:  s	            r7  set_leveragezbydfi.set_leverage  s     >#DG.Y$YZZZV$$66v}hX^__Tl 
 

 66t{{7F7S7STT~~h33r8  c                    |t          | j        dz             |                                  |                     |          }d}|                     |dd|          \  }}|d         |d}|                     |                     ||                    }|                     |di           }|                     ||          S )	a  
        fetch the set leverage for a market

        https://developers.bydfi.com/en/futures/trade#get-leverage-for-single-trading-pair

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.wallet]: The unique code of a sub-wallet. W001 is the default wallet and the main wallet code of the contract
        :returns dict: a `leverage structure <https://docs.ccxt.com/?id=leverage-structure>`
        Nz+ fetchLeverage() requires a symbol argumentr$  r   r%  r+   rc  r:  )	r    r+   r  rA  r  privateGetV1FapiTradeLeverager  r  parse_leveragere  s           r7  fetch_leveragezbydfi.fetch_leverage7  s     >#DG.[$[\\\V$$66vPXZ`aaTl
 
 55dkk'66R6RSS ~~h33""4000r8  c                     |                      |d          }||                     ||          d |                     |d          |                     |d          dS )NrC  r   )ro  rC  r   longLeverageshortLeverage)rp  r	  r  )r5  r   rA  r  s       r7  r  zbydfi.parse_leverage\  se    ##Hh77&&x88 --h
CC!..xDD
 
 	
r8  c                    |                                   d}|                     |dd|          \  }}d|i}|                     |                     ||                    }|                     |dg           }|                     ||          S )a  
        fetch all open positions

        https://developers.bydfi.com/en/futures/trade#positions-query

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.contractType]: FUTURE or DELIVERY, default is FUTURE
        :param str [params.settleCoin]: the settlement currency(USDT or USDC or USD)
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/?id=position-structure>`
        r  r   r  r:  )r  r  privateGetV1FapiTradePositionsr  r<  parse_positions)r5  r  r>  r  r  r?  r:  s          r7  fetch_positionszbydfi.fetch_positionsf  s     	#<<VEUWegsttfL
 66t{{7F7S7STT. ~~h33##D'222r8  c                 ^   |                                   |                     |          }d}|                     |dd|          \  }}||d         d}|                     |                     ||                    }|                     |dg           }|                     ||d         g          S )a  
        fetch open positions for a single market

        https://developers.bydfi.com/en/futures/trade#positions-query

        fetch all open positions for specific symbol
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.contractType]: FUTURE or DELIVERY, default is FUTURE
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/?id=position-structure>`
        r  r   r  r+   )r  rC  r:  rC  )r  rA  r  r  r  r<  r  )r5  rC  r>  rA  r  r  r?  r:  s           r7  fetch_positions_for_symbolz bydfi.fetch_positions_for_symbol  s     	V$$#<<VEUWegsttf(Tl
 
 66t{{7F7S7STT~~h33##D6(+;*<===r8  positionc                 >   |                      |d          }|                     ||          }|                      |d          }|                     |d          }|                     |          }d }d}|d}|dk    r|}d}nd}|                      |d          }	|                     |dd	          }
|st          j        |
|	          }
|                     |d
          }|                     i d|d|                      |d          d|d         d| 	                    |                     |dd                    d| 	                    |                      |d                    d| 	                    |                      |d                    d| 	                    |                      |d                    dd d| 	                    |                      |d                    d| 	                    |                      |d                    d|d| 	                    |
          d| 	                    |	          d|d| 
                    |          d|                     |d          d|| 	                    |                      |d                     d | 	                    |                      |d!                    d | 	                    |                      |d"                    | 	                    |                      |d#                    d d d d$	          S )%NrC  r  r;  FTbothrg  volumeopenPositionVolumerw  ro  r+   
entryPriceavgOpenPositionPricer  r  	lastPriceavgClosePositionPricenotionalclosePositionCost
collateralunrealizedPnlunPnlrealizedPnlpositionProfits	contractsr  r  r}  r~  r   mmimr   liqPrice)	maintenanceMarginmaintenanceMarginPercentageinitialMargininitialMarginPercentager   liquidationPricemarginRatior   r   )rp  r  r  parse_position_sider  r&   rv  r  safe_positionry  r  )r5  r  rA  r  	buyOrSellrawPositionSider;  r   isFetchPositionsHistoryrg  r  r  s               r7  parse_positionzbydfi.parse_position  s   h ##Hh77!!(F33$$Xv66	00>JJ//	::"'&&*#&((.''??&&x;OPP	& 	D*9lCCI%%h==	!! #
H#
$""8T22#
 fX&#
 $++D,>,>xI_ak,l,lmm	#

 **4+;+;Hk+R+RSS#
 **4+;+;HF]+^+^__#
 ))$*:*:8EX*Y*YZZ#
 $#
 T..t/?/?'/R/RSS#
 4,,T-=-=hHY-Z-Z[[#
 L#
 **955#
 D--l;;#
 #
 Y//#
  "4#4#4X|#L#L!#
" f##
$ "&!2!243C3CHd3S3S!T!T+/!..t/?/?$/O/OPP'+))$*:*:8Z*P*PQQ $ 1 1$2B2B8Z2X2X Y Y5#
 #
 #
   	r8  c                 :    ddd}|                      |||          S )Nlongshort)BUYSELLr  )r5  r  sidess      r7  r  zbydfi.parse_position_side  s.    
 
 tT222r8  c                    |                                   |                     |          }d}|                     |dd|          \  }}|d         |d}|                     d||          }|||d<   |                     |                     ||                    }|                     |dg           }	|                     |	          }
|                     |
||          S )	a  
        fetches historical positions

        https://developers.bydfi.com/en/futures/trade#query-historical-position-profit-and-loss-records

        :param str symbol: a unified market symbol
        :param int [since]: timestamp in ms of the earliest position to fetch , params["until"] - since <= 7 days
        :param int [limit]: the maximum amount of records to fetch(default 500, max 500)
        :param dict params: extra parameters specific to the exchange api endpoint
        :param int [params.until]: timestamp in ms of the latest position to fetch , params["until"] - since <= 7 days
        :param str [params.contractType]: FUTURE or DELIVERY, default is FUTURE
        :param str [params.wallet]: The unique code of a sub-wallet. W001 is the default wallet and the main wallet code of the contract
        :returns dict[]: a list of `position structures <https://docs.ccxt.com/?id=position-structure>`
        r  r   r  r+   )rC  r  Nr   r:  )	r  rA  r  r  $privateGetV1FapiTradePositionHistoryr  r<  r  filter_by_since_limit)r5  rC  r  r   r>  rA  r  r  r?  r:  	positionss              r7  fetch_position_historyzbydfi.fetch_position_history  s     	V$$#<<VE\^lnz{{fTl(
 
 ,,-DeVTT$GG<<T[[RX=Y=YZZ ~~h33((..	)))UEBBBr8  c                    |                                   d}|                     |dd|          \  }}d|i}|                     d||          }|||d<   |                     |                     ||                    }|                     |dg           }|                     ||          }	|                     |	||          S )a  
        fetches historical positions

        https://developers.bydfi.com/en/futures/trade#query-historical-position-profit-and-loss-records

        :param str[] symbols: a list of unified market symbols
        :param int [since]: timestamp in ms of the earliest position to fetch , params["until"] - since <= 7 days
        :param int [limit]: the maximum amount of records to fetch(default 500, max 500)
        :param dict params: extra parameters specific to the exchange api endpoint
        :param int [params.until]: timestamp in ms of the latest position to fetch , params["until"] - since <= 7 days
        :param str [params.contractType]: FUTURE or DELIVERY, default is FUTURE
        :param str [params.wallet]: The unique code of a sub-wallet. W001 is the default wallet and the main wallet code of the contract
        :returns dict[]: a list of `position structures <https://docs.ccxt.com/?id=position-structure>`
        r  r   r  Nr   r:  )r  r  r  r  r  r<  r  r  )
r5  r  r  r   r>  r  r  r?  r:  r  s
             r7  fetch_positions_historyzbydfi.fetch_positions_history7  s     	#<<VE\^lnz{{fL
 ,,-DeVTT$GG<<T[[RX=Y=YZZV ~~h33((w77	)))UEBBBr8  c                    |                                   |                     |          }d}|                     |dd|          \  }}d}|                     |dd|          \  }}||d         |d}|                     |                     ||                    }|                     |di           }|                     ||          S )	aj  
        fetches the margin mode of a trading pair

        https://developers.bydfi.com/en/futures/user#margin-mode-query

        :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
        :param str [params.contractType]: FUTURE or DELIVERY, default is FUTURE
        :param str [params.wallet]: The unique code of a sub-wallet. W001 is the default wallet and the main wallet code of the contract
        :returns dict: a `margin mode structure <https://docs.ccxt.com/?id=margin-mode-structure>`
        r  r   r  r$  r%  r+   )r  rC  r%  r:  )r  rA  r  $privateGetV1FapiUserDataAssetsMarginr  r  parse_margin_mode)	r5  rC  r>  rA  r  r%  r  r?  r:  s	            r7  fetch_margin_modezbydfi.fetch_margin_mode~  s     	V$$#<<VEVXfhtuuf66v?PRZ\bcc(Tl
 

 <<T[[RX=Y=YZZ ~~h33%%dF333r8  r   c                     |                      |d          }||                     ||          |                     |d          dS )NrC  
marginType)ro  rC  r   )rp  r	  r  )r5  r   rA  r  s       r7  r  zbydfi.parse_margin_mode  sO    ##J99&&x8800\JJ
 
 	
r8  c                    |t          | j        dz             |                                }|dk    r|dk    rt          | j        dz             |                                  |                     |          }d}|                     |dd|          \  }}d	}|                     |dd
|          \  }}||d         |                                |d}|                     | 	                    ||                    S )aW  
        set margin mode to 'cross' or 'isolated'

        https://developers.bydfi.com/en/futures/user#change-margin-type-cross-margin

        :param str marginMode: 'cross' or 'isolated'
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.contractType]: FUTURE or DELIVERY, default is FUTURE
        :param str [params.wallet]: The unique code of a sub-wallet. W001 is the default wallet and the main wallet code of the contract
        :returns dict: response from the exchange
        Nz+ setMarginMode() requires a symbol argumentisolatedcrossz@ setMarginMode() marginMode argument should be isolated or crossr  r   r  r$  r%  r+   )r  rC  r  r%  )
r    r+   lowerr!   r  rA  r  r?  #privatePostV1FapiUserDataMarginTyper  )r5  r   rC  r>  rA  r  r%  r  s           r7  set_margin_modezbydfi.set_margin_mode  s    >#DG.[$[\\\%%''
##
g(=(=TW'iijjjV$$#<<VEVXfhtuuf66v?PRZ\bcc(Tl$**,,	
 
 77GV8T8TUUUr8  r   c                 v   |t          | j        dz             |                                  |rdnd}d}|                     |dd|          \  }}d}|                     |dd	|          \  }}d
}|                     |dd|          \  }}||||d}|                     |                     ||                    S )a"  
        set hedged to True or False for a market, hedged for bydfi is set identically for all markets with same settle currency

        https://developers.bydfi.com/en/futures/user#change-position-mode-dual

        :param bool hedged: set to True to use dualSidePosition
        :param str [symbol]: not used by bydfi setPositionMode()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.contractType]: FUTURE or DELIVERY, default is FUTURE
        :param str [params.wallet]: The unique code of a sub-wallet. W001 is the default wallet and the main wallet code of the contract
        :param str [params.settleCoin]: The settlement currency - USDT or USDC or USD(default is USDT)
        :returns dict: response from the exchange
        Nz setPositionMode() does not support a symbol argument. The position mode is set identically for all markets with same settle currencyHEDGEONEWAYr$  r   r%  r  r  USDT
settleCoin)r  r%  positionTyper  )r#   r+   r  r  )privatePostV1FapiUserDataPositionSideDualr  )	r5  r   rC  r>  r  r%  r  r  r  s	            r7  set_position_modezbydfi.set_position_mode  s     tw  *q   q  r  r  r"(6wwh66v?PRZ\bcc#<<VEVXfhtuuf
!::6CTVbdnoo
F(($	
 
 ==dkk'SY>Z>Z[[[r8  c                    |                                   d}|                     |dd|          \  }}d}|                     |dd|          \  }}d}||                     |dd|          \  }}n|                     |          }|d	         }|||d
}|                     |                     ||                    }|                     |di           }	|                     |	d          dk    }
||
dS )aR  
        fetchs the position mode, hedged or one way, hedged for bydfi is set identically for all markets with same settle currency

        https://developers.bydfi.com/en/futures/user#get-position-mode

        :param str [symbol]: unified symbol of the market to fetch the order book for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.contractType]: FUTURE or DELIVERY, default is FUTURE
        :param str [params.wallet]: The unique code of a sub-wallet. W001 is the default wallet and the main wallet code of the contract
        :param str [params.settleCoin]: The settlement currency - USDT or USDC or USD(default is USDT or settle currency of the market if market is provided)
        :returns dict: an object detailing whether the market is in hedged or one-way mode
        r$  r   r%  r  r  r  Nr  r[  )r  r  r%  r:  r  r  )ro  r   )r  r  rA  (privateGetV1FapiUserDataPositionSideDualr  r  rp  )r5  rC  r>  r%  r  r  rA  r  r?  r:  r   s              r7  fetch_position_modezbydfi.fetch_position_mode  s(    	66v?RT\^dee#<<VEXZhjvwwf
>!%!>!>vGZ\hjt!u!uJ[[((F
+J($
 

 @@WV\A]A]^^$ ~~h33!!$777B
 
 	
r8  c                    |                                   d}|                     dd|          \  }}d}|                     |dd          \  }}i }d}|b|                     | j        di           }|                     |||          }||d<   |                     |                     ||                    }n.||d<   |                     |                     ||                    }| 	                    |dg           }| 
                    |          S )a2  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://developers.bydfi.com/en/account#asset-inquiry
        https://developers.bydfi.com/en/futures/user#asset-query

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.account]: the type of account to fetch the balance for, either 'SPOT' or 'UMFUTURE'  or 'CMFUTURE'  or 'COPY'  or 'GRID'  or 'FUNDING'(default is 'SPOT')
        :param str [params.wallet]: *swap only* The unique code of a sub-wallet. W001 is the default wallet and the main wallet code of the contract
        :param str [params.asset]: currency id for the balance to fetch
        :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
        Nrd   r%  r0  
walletTyper:  )r  handle_market_type_and_paramsr  r  r%  safe_string_upperprivateGetV1AccountAssetsr  privateGetV1FapiAccountBalancer<  parse_balance)	r5  r>  r\  r%  r  r?  r%  parsedAccountTyper:  s	            r7  fetch_balancezbydfi.fetch_balance*	  s    	99.$PVWWf66v~xXX>nnT\3CRHHG $ 6 6wd K K$5GL!" 55dkk'66R6RSSHH &GH: ::4;;wPV;W;WXXH~~h33!!$'''r8  c                    |                                  }|||                     |          d}t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |dd          |d<   |                     |dd          |d<   |||<   |                     |          S )	N)ro  r  r  r   assettotalbalance	availableavailableBalancefree)	r  r  r  r  rp  rq  accountr  safe_balance)	r5  r?  r  r  r  r  rC  coder  s	            r7  r  zbydfi.parse_balanceu	  s    %%''	"Y//
 

 q#h--(( 	# 	#AqkG%%gw77F**622DllnnG#11'7INNGG"00+GYZZGFO"F4LL  (((r8  r  fromAccount	toAccountc                    |                                   |                     |          }|                     | j        di           }|                     |||          }|                     |||          }	|d         |                     ||          ||	d}
|                     |                     |
|                    }|                     ||          }|                     | j        di           }| 	                    |dd          }|rE| 
                                }||d<   |                     |          |d<   ||d	<   ||d
<   ||d<   ||d<   |S )a-  
        transfer currency internally between wallets on the same account

        https://developers.bydfi.com/en/account#asset-transfer-between-accounts

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: 'spot', 'funding', or 'swap'
        :param str toAccount: 'spot', 'funding', or 'swap'
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/?id=transfer-structure>`
        r0  r+   )r  r`  fromTypetoTyper   fillResponseFromRequestTr  r  r  r  r  r`  )r  r  r  r%  rp  currency_to_precisionprivatePostV1AccountTransferr  parse_transferrr  r  r  )r5  r  r`  r  r  r>  r  r0  fromIdtoIdr  r?  r   transferOptionsr  r  s                   r7  r   zbydfi.transfer	  sh    	==&&6FKK!!.+{KK	9EEd^00v>>	
 
 44T[[&5Q5QRR &&x::..z2FF"&..B[]a"b"b" 	())++I$-H[!#'<<	#:#:HZ #'HZ &1H]#$-H[!!'HXr8  c           	         |t          | j        dz             |                                  |                     |          }|                     |dd          }|rgd}|                     |d          }|                     |ddi          }|                     d|d	         ||||d
          }|                     |d          S d|d         i}	d}
| 	                    |ddd          \  }
}|
| 
                                }
|d}||	d<   |
|	d<   |||	d<   |                     |                     |	|                    }|                     |dg           }|                     ||||          S )a  
        fetch a history of internal transfers made on an account

        https://developers.bydfi.com/en/account#query-wallet-transfer-records

        :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)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/?id=transfer-structure>`
        Nz* fetchTransfers() requires a code argumentr  Fr1   r  r  r   r  Tr  r  r+   r  r  r   r  rowsr:  )r    r+   r  r  rr  r  r  r  r  rs  r  "privateGetV1AccountTransferRecordsr<  parse_transfers)r5  r  r  r   r>  r  r  r  r  r  r  r?  r:  s                r7  fetch_transferszbydfi.fetch_transfers	  s    <#DG.Z$Z[[[==&&>>&*e<< 	@HYYvz22F[[*?)LMMF $ A ABRT\]cTdfkmrtz  }E  GK  !L  !L<< 1;???Xd^
 77@PRY[deev=%%''E=E$"	#GFO::4;;wPV;W;WXX( ~~h33##D(E5AAAr8  r   r  c                 P   |                      |dd          }|                     | j        di           }|                     |d          }|                     |d          }|                     |||          }|                     |||          }|                     |d          }	|                     |d          }
||                     |d          |	|                     |	          |                     |
|          |                     |d	          ||| 	                    |          d
	S )NmessagerU  r1  sourceWallettargetWalletr  r  txIdr`  )	ro  r+   r  r  r  r`  r  r  rU  )
safe_string_upper_2r  r%  r  rp  r  r  rq  rw  parase_transfer_status)r5  r   r  rU  r1  r  r  r  r  r  
currencyIds              r7  r  zbydfi.parse_transfer	  s(   * ))(IxHH~~dlNBGG''.AA%%h??&&|VVDD$$\4>>	%%h<<	%%h88
""8V44"Y////
HEE&&x::&"11&99

 

 
	
r8  c                 <    dddd}|                      |||          S )Nokpendingfailed)SUCCESSWAITFAILEDr  r  s      r7  r  zbydfi.parase_transfer_status
  1    
 

 &&999r8  c                 4    |                      d||||          S )a  
        fetch all deposits made to an account

        https://developers.bydfi.com/en/spot/account#query-deposit-records

        :param str code: unified currency code(mandatory)
        :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>`
        r_   fetch_transactions_helperr5  r  r  r   r>  s        r7  fetch_depositszbydfi.fetch_deposits 
  s      --iueVTTTr8  c                 4    |                      d||||          S )a*  
        fetch all withdrawals made from an account

        https://developers.bydfi.com/en/spot/account#query-withdrawal-records

        :param str code: unified currency code(mandatory)
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawal 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>`
        
withdrawalr(  r*  s        r7  fetch_withdrawalszbydfi.fetch_withdrawals.
  s!     --lD%PVWWWr8  c           	         |dk    rdnd}|t          | j        dz   |z   dz             |                                  |                     |          }|                     |dd          }|rgd}	|                     |d          }|                     |d	d
i          }|                     ||d         ||||	d          }
|                     |
d          S d|d         i}d }| 	                    |ddd          \  }}| 
                                }d}|}||||z
  }|}n||z
  }n|||z
  }||k    r||z   }n|}||d<   ||d<   |||d<   d }|dk    r*|                     |                     ||                    }n)|                     |                     ||                    }|                     |dg           }d|i}|                     ||          }|                     |||||          S )Nr_   r{   r    z() requires a code argumentr  Fr1   r  r  r  Tr  r  r+   r   r  r  rr  r  r   r:  r\  )r    r+   r  r  rr  r  r  r  r  rs  r  privateGetV1SpotDepositRecordsprivateGetV1SpotWithdrawRecordsr<  parse_transactions)r5  r\  r  r  r   r>  rp  r  r  r  r  r  r  r  rt  r  ru  r?  r:  transactionParamss                       r7  r)  zbydfi.fetch_transactions_helper<
  sm   )-):):__AS
<#DGcMJ$>A^$^___==&&>>&*e<< 	@HYYvz22F[[*?)LMMF $ A A*hW]N^`eglntv~  AE  !F  !F<< 1;???Xd^
 77@PRY[deev!!+		})O	 "I-		])OEy  !I-("	$GG9, ::4;;wPV;W;WXXHH
 ;;DKKQW<X<XYYH~~h33D#
 V%677&&tXueVLLLr8  transactionc                    |                      |d          }|                     ||          }|                     |d          }|                     |d          }d }|                     |d          }||d d}i d|d|                      |d          d	|                      |d
          dd d|d|                     |                      |d                    d|                     |d          d|                     |          d|d|                     |          d|                      |d          dd dd d|                      |d          dd dd d|                     |d          d |ddS )Nr  rU  rw  r  r  ro  r+   r  txidr  r\  r  networkr`  r  r  addressaddressFrom	addressTotag
addressTagtagFromtagToupdated
finishTimeF)commentr  internal)rp  rq  r  r  rw  network_id_to_codeparse_transaction_statusr  )	r5  r5  r  r  r  r  r  r  r  s	            r7  parse_transactionzbydfi.parse_transaction
  s     %%k7;;
&&z8<<**;AA	%%k<@@	"";66  C
K
$"";	::
 D$$[&99
 D	

 
 t..t/?/?Y/W/WXX
 d&&{H==
 d33I>>
 
 Y//
 t''Y??
 4
 
 4##K>>
 t
  T!
" t((lCC#
$ )
 
 
 	
r8  c                 <    dddd}|                      |||          S )Nr   r!  r"  )successwaitr"  r  r  s      r7  rE  zbydfi.parse_transaction_status
  r&  r8  r   GETr   headersbodyc                 *   | j         d         |         }d|z   }d}	|                     |          }
|dk    r0|                     |
          }	t          |	          dk    r|d|	z   z  }|dk    r|                                  t          |                                           }|dk    rf| j        |z   |	z   }|                     | 	                    |          | 	                    | j
                  t          j        d          }| j        ||d	}n{|                     |
          }| j        |z   |z   }|                     | 	                    |          | 	                    | j
                  t          j        d          }d
| j        ||d}||z  }||||dS )Nr   rG   rJ  r   ?r   hex)	X-API-KEYX-API-TIMESTAMPX-API-SIGNATUREzapplication/json)zContent-TyperQ  rR  rS  )urlmethodrL  rK  )r   keysort	urlencoder  check_required_credentialsstrr  apiKeyhmacencodesecrethashlibsha256json)r5  pathr   rU  r>  rK  rL  rT  endpointquerysortedParamsr  payload	signatures                 r7  signz
bydfi.sign
  s   is#:||F++U??NN<00E5zzQC%K')++---D--//00I+	1E9 IIdkk'&:&:DKK<T<TV]Vdfkll	!%'0'0  yy..+	1D8 IIdkk'&:&:DKK<T<TV]Vdfkll	$6!%'0'0	  	xfdwOOOr8  httpCodereasonrT  rU  c
                 v   |d S |                      |d          }
|                      |d          }|
dk    r| j        dz   |z   }|                     | j        d         ||           |                     | j        d         ||           |                     | j        d         |
|           t          |          d S )Nr  r  200r0  r"  r#  )rp  r+   throw_exactly_matched_exceptionr  throw_broadly_matched_exceptionr   )r5  rh  ri  rT  rU  rK  rL  r?  requestHeadersrequestBodyr  r  feedbacks                r7  handle_errorszbydfi.handle_errors
  s    4 &11""8Y775==w}t+H001I7T\]]]001I7T\]]]001I4QYZZZ)))tr8  )N)___name__
__module____qualname__r   r4  r   r   r@  dictr  rY  r   r   r  r  r   r  r   r  r  r  listr  r  r   r   r  r   r  r  r   r  r  r   r  r"  r   r   floatr   r   r*  r&  rF  r   rX  r\  r_  rZ  rf  rj  rl  ro  r  r(  r  r  r  intr  r	   r  r  r   r  r  r  r  r  r  r
   r  r  r  boolr  r  r   r  r  r   r   r  r   r  r  r   r+  r.  r)  rF  rE  rg  rq  __classcell__)r6  s   @r7  r(   r(      sI       z# z z z z z zx $& 1( 1($v, 1( 1( 1( 1(fk4 kF k k k kZ :>b 2 2s 23 2Y 2 2 2 2hs s     6:UW '= '=3 '=s '=# '=\`af\g '= '= '= '=R -1tRV_a @= @=c @= @=C @=fjkpfq @= @= @= @=D= = =v = = = = =~3S 3S 3 3 3 3 26DW[df C C# Cc CQT Ckoptku C C C CJ
 
 
4 
 
 
 
* 04B 1 1W 17 1 1 1 1B 02 1 13 1f 1 1 1 1(( (4 ( (6 ( ( ( (T 68 5 5 5K 5 5 5 5@ 
  
6  
[  
  
  
  
D 8<$]ajl -M -M -MC -MWZ -Mqu  wI  rJ -M -M -M -M^
 
6 
 
 
 
& gksu @. @.3 @.i @.y @.RW @.`c @.z @. @. @. @.D os{} S, S,3 S,i S,y S,Z_ S,hk S, S, S, S,jAs As A A A A @B "' "'D$6 "' "' "' "'H `drv  @B & &S &# &Y &i &Y\ &lo &  GL & & & &4 >@ "' "'$|"4 "'DK "' "' "' "'H os  BF  OQ , ,C , ,I ,U^ ,hk ,{~ , , , ," /32 7/ 7/ 7/$u+ 7/ 7/ 7/ 7/r /3TXac A= A= A=3 A=c A=hlmrhs A= A= A= A=F 7;2 '/ '/3 '/ '/ '/ '/ '/R >BPTcgpr S= S=s S=# S=]` S=w{  }B  xC S= S= S= S=j DHPR , , ,S ,W[ , , , ,6m m mv m m m m m^
3S 
3S 
3 
3 
3 
3HS HS H H H H: : : : : : 9=R  S #    6 24 #1 #1S #1 #1 #1 #1 #1J
 
t 
V 
x 
 
 
 
 26b *3 *3w *3T(^ *3 *3 *3 *3X >@ > > >DN > > > >0c ct cV c c c cJ3 3 3 3 3 3 @DRV_a C CS C CC Cfjksft C C C CB :>D_cln EC ECw ECc ECY\ ECsw  yA  tB EC EC EC ECN 57 %4 %4 %4: %4 %4 %4 %4N
 
D 
& 
J 
 
 
 
 >B" V V# Vs V V V V@ =A %\ %\ %\c %\ %\ %\ %\N 15R 4
 4
# 4
 4
 4
 4
l $& I( I(( I( I( I( I(V) ) ) ) )" [] + +S +% +c +c +an + + + +Z +/TPT]_ :B :BC :Bs :B# :Bdhivdw :B :B :B :Bx'
 '
t '
x '
= '
 '
 '
 '
R:S :S : : : : *.Dt\^ U U3 Uc U Ucghsct U U U U -1tRV_a X Xc X XC Xfjkvfw X X X XJM JM JMX0
 0
T 0
X 0
Q\ 0
 0
 0
 0
d:s :s : : : : %-U2VZhl P Pc PPS Pbe P P P PBc 3 S # X\ dg        r8  r(   )-ccxt.base.exchanger   ccxt.abstract.bydfir   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   typingr   ccxt.base.errorsr   r   r   r    r!   r"   r#   r$   ccxt.base.decimal_to_precisionr%   ccxt.base.preciser&   r(    r8  r7  <module>r     sf   ( ' ' ' ' ' + + + + + +                                                                                                           * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . ' ' ' ' ' ' . . . . . . ) ) ) ) ) ) . . . . . . 4 4 4 4 4 4 % % % % % %]+ ]+ ]+ ]+ ]+Hk ]+ ]+ ]+ ]+ ]+r8  