
    eiV                    8   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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ADLBalancesCurrencyIntLedgerEntryLeverage	Leverages
MarginModeMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateTradeTradingFeeInterfaceTransactionTransferEntry)List)ExchangeError)AuthenticationError)ArgumentsRequired)
BadRequest)InsufficientFunds)InvalidOrder)RateLimitExceeded)ExchangeNotAvailable)	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ddd
ededefdZi fde
defdZi fde
defdZdi fdedefdZdddededefdZddi fde
dededee         fdZdddedefdZdddi fde
de
dededee         f
dZdddi fdededefdZdddedefdZi fde
defdZd Z d Z!d Z"dddedede#fdZ$i fde%fd Z&di fde
d!e'd"e(d#e)d$e*f
d%Z+d&efd'Z,ddd(edede-fd)Z.di fde
d!e'd"e(d#e)d$e*de-fd*Z/ddi fde
d!e'd"e(d#e*d$e*f
d+Z0di fd,e
defd-Z1i fd.ee2         dee-         fd/Z3dddi fdedededee-         fd0Z4dddi fdedededee         fd1Z5dddi fd2edededee6         fd3Z7dddi fd2edededee6         fd4Z8dddi fd2edededee9         fd5Z:ddd6ed7e;de6fd8Z<d&efd9Z=d: Z>ddd;ed7e;de9fd<Z?d= Z@di fd>ee
         defd?ZAi fd2e
d#e)d@e
dAe
deBf
dBZCdddCed7e;deBfdDZDi fde
deEfdEZFdi fdedeeE         fdFZGdddGedefdHZHdi fdedeIfdIZJi fde
deKfdJZLdddKededeKfdLZMdi fdKeNdefdMZOdi fde
d"e(de-fdNZPdddi fdedededee-         fdOZQi fde
deRfdPZSdddQededeRfdRZTdi fdQe
defdSZUdi fdefdTZVdi fdUeWdefdVZXdi fdedeeY         fdWZZdddXededeYfdYZ[dZeNd[e
d\e
d]e
d^ed_e
fd`Z\dadbi ddfdcZ] xZ^S )eblofinreturnc                 
   |                      t          t          |                                           i ddddddgddd	d
dddi dd ddddddddddddddddddddddddddddddddi d dd!dd"dd#dd$dd%dd&dd'dd(dd)dd*dd+dd,dd-d d.dd/dd0di d1dd2dd3dd4dd5dd6dd7dd8dd9d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ddddddddddddddvdwdxdydzd{d|d}d~dddddddddddddddiddidddddddddddddddddii ddddddddddddddddddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddddddddddddd|                     d          |                     d          didddddĜdddddddƜdddddddǜddidd
dddd˜d dd
dddd̜d dddddddddΜddidќ	dddd dddd ddӜdԜdddd dddd dd՜ddӜdԜddid d؜d d d؜dٜdi dt
          dt          dt          dt
          dt
          dt
          dt          dt
          dt
          dt
          dt
          dt
          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          t          t          t          t
          t
          t
          t          t          dt          t          ddd dt          idt          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dWdwdzd}dddzd}dddidUddidbddidddddQdgdddIddidYdd iddd!id1dd"idd"id d d#d$d%d$d%d&d'i          S ((  Nidr+   nameBloFin	countriesUSversionv1	rateLimitd   proThasCORSspotFmarginswapfutureoption	addMarginborrowMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrders$createOrderWithTakeProfitAndStopLosscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopLossOrdercreateStopMarketOrdercreateStopOrdercreateTakeProfitOrdercreateTriggerOrder	editOrderfetchAccountsfetchBalancefetchBidsAsksfetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL3OrderBookfetchLedgerfetchLedgerEntryfetchLeveragefetchLeveragesfetchLeverageTiersfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionADLRankfetchPositionModefetchPositionsfetchPositionsADLRankfetchPositionsForSymbolfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTradingLimitsfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransferfetchTransfersfetchUnderlyingAssets)fetchVolatilityHistoryfetchWithdrawalfetchWithdrawalsfetchWithdrawalWhitelistreduceMarginrepayCrossMarginsetLeverage	setMarginsetMarginModesetPositionModesignIntransferwithdraw
timeframes1m3m5m15m30m1H2H4H6H8H12H1D3D1W1M)r   r   r   r   r   1h2h4h6h8h12h1d3d1wr   hostnamezwww.blofin.comurlszOhttps://github.com/user-attachments/assets/518cdf80-f05d-4821-a3e3-d48ceb41d73brestzhttps://openapi.blofin.comz'https://demo-trading-openapi.blofin.comz0https://blofin.com/register?referral_code=f79EsSg?)urldiscountzhttps://www.blofin.comzhttps://blofin.com/docs)logoapitestreferralwwwdocr   get   )zmarket/instrumentszmarket/tickerszmarket/bookszmarket/tradeszmarket/candleszmarket/mark-pricezmarket/funding-ratezmarket/funding-rate-historyzasset/balancesztrade/orders-pendingztrade/fills-historyzasset/deposit-historyzasset/withdrawal-historyzasset/billszaccount/balancezaccount/positionszaccount/leverage-infozaccount/margin-modezaccount/position-modezaccount/batch-leverage-infoztrade/orders-tpsl-pendingztrade/orders-algo-pendingztrade/orders-historyztrade/orders-tpsl-historyztrade/orders-algo-history)ztrade/order/price-rangezuser/query-apikeyzaffiliate/basiczcopytrading/instrumentszcopytrading/account/balancez&copytrading/account/positions-by-orderz.copytrading/account/positions-details-by-orderz)copytrading/account/positions-by-contractz!copytrading/account/position-modez!copytrading/account/leverage-infoz copytrading/trade/orders-pendingz*copytrading/trade/pending-tpsl-by-contractz+copytrading/trade/position-history-by-orderz copytrading/trade/orders-historyz'copytrading/trade/pending-tpsl-by-orderzaccount/set-margin-modezaccount/set-position-modeztrade/orderztrade/order-algoztrade/cancel-orderztrade/cancel-algozaccount/set-leverageztrade/batch-ordersztrade/order-tpslztrade/cancel-batch-ordersztrade/cancel-tpslztrade/close-positionzasset/transferz%copytrading/account/set-position-modez copytrading/account/set-leveragezcopytrading/trade/place-orderzcopytrading/trade/cancel-order)z(copytrading/trade/place-tpsl-by-contractz)copytrading/trade/cancel-tpsl-by-contractz%copytrading/trade/place-tpsl-by-orderz&copytrading/trade/cancel-tpsl-by-orderz)copytrading/trade/close-position-by-orderz,copytrading/trade/close-position-by-contract)r   post)publicprivatefeesz0.00060z0.00020)takermakerrequiredCredentials)apiKeysecretpasswordfeatures)IOCFOKPOGTD)timeInForceleveragemarketBuyRequiresPricemarketBuyByCostselfTradePreventiontrailingicebergmax
   i )
marginModelimitdaysBack	untilDayssymbolRequired)r   r   triggerr   r   i  )r   r   r   daysBackCanceledr   r   r   r   r   i  )	sandboxrI   rJ   r~   r   r   r   r]   r   default)r   triggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfithedged)extendsrI   )r   pricer   forDerivatives)linearinverse)r   r:   r   r<   r=   
exceptions400401500404405406429152001152002152003152004152005152006152007152008152009150003150004542102002102005102014102015102022102037102038102039102040102047102048102049102050102051102052)102053102054102055102064102065102068103013z1Order failed. Insufficient USDT margin in account)zInternal Server Errorzserver error)exactbroadhttpExceptionsprecisionModeoptionsbrokerIdec6dd3a7dd982d0baccountsByTypefuturesfundingcopy_tradingearn)r<   r3  r=   r4  r5  r:   accountsById)r3  r2  r4  r5  r:   defaultNetworkERC20defaultNetworksBTCTRC20)ETHr:  USDTnetworksBitcoinBSC)r:  BEP20r8  r;  )r   r   r   r   5Mr   r   r   timezoneUTCmethodprivateGetAccountPositionsprivatePostTradeOrder!createMarketBuyOrderRequiresPricedefaultTypeprivateGetAssetBillsprivateGetTradeOrdersPending!privatePostTradeCancelBatchOrdersprivateGetTradeOrdersHistory)r   pwdSPOTSWAP)r:   r<   rO  rP  )r]   r   exchangeType)deep_extendsuperr+   describeparse_numberr#   r!   r    r&   r%   r$   r'   r(   )self	__class__s    I/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/blofin.pyrT  zblofin.describe   s   fd 3 3 < < > > SA
(SA
HSA
 $SA
 t	SA

 SA
 4SA
  ttt %t 	t
 %t %t Ut t "5t tt t $Ut  t 't /t  0!t" t#t t$ %t& 7't( &u)t* (+t, '-t. &t/t0 (1t2 "53t4 (5t6 %d7t8 U9t:  ;t< =t>  ?t@ &uAtB +ECtD )%Et t tF &uGtH #EItJ $TKtL 'MtN (OtP "5QtR StT &uUtV (WtX 1%YtZ  [t\ +E]t^ *:_t` +Eatb &tctd #Detf *4gt t th $Uitj uktl "5mtn *5otp +Eqtr #Estt tutv #Dwtx  ytz !${t| %e}t~ "4t@ #EAtB +ECtD EtF !%GtH +EIt t tJ  KtL dMtN $UOtP +EQtR !$StT "4UtV dWtX !$YtZ "5[t\ u]t^ #D_t`  atb 'ctd $Tetf !$gth (itj *5kt t tl %emtn )%otp )%qtr ustt tutv wtx Uytz t{t| "5}t~ #Et@ %eAtB &uCtD 'EtF $UGtH  ItJ !%KtL (Mt tN +0#($(,1 %$)#"!%#' !gt t tSA
x  ySA
Z ([SA
\ i8 E N $  00 ]SA
z ./*+())**+-./078	 	!(!!.! .q! 0	!
 3A! &q! *1! ,Q! 0! .q! 0! 6q! 4Q! 4Q! /!  4Q!!" 4Q#!$ 45-.+,3478BCJKEF=>=><=FGGH<=CDA! ! !D113Q &q +A	
 -a ,Q / -a +A 4Q ,Q / )! @ ;A  8!" 9!#$ EFEFABBCEFHI/  G< <J J{SA
P !..y99!..y99 QSA
\ " $ $]SA
f $ $(#'"&#(	( ( %*27+0/4$)#($ $ r% ',!$$*%+*/& & #'&+!$#'$)*/( ( $(&+!%$*,-%+#'$)*/	* 	*  #[0 0d  )&+(-,0,1).+06:"'	$ 	$   )&*(-,0,1)-+/04%)7 7 #'$ $# #$ "#3  $	  ## kY YgSA
Z
 +:+.+ =+ :	+
 :+ :+ ,+ j+ j+ j+ j+ j+ l+ l+ l+  l!+" l#+ +$ l%+& <'+( l)+* l++, l-+. l/+0 l1+2 l3+4 l5+6 l7+8 l9+: l;+< l=+> l?+@ lA+B lC+D lE+ +F +**(((+IZU+ + +Z .B$8 [1 1[
SA
~ +SA
D YESA
F  O.O %('$2""# #O (%$2""! !O" !'#O$ "" #$ $%O. $"$$	 /O: + """"""""	# 	#-;OR SOZ !:#[O` 6aOb 4UcOd eOf vgOh 4 iOn "<$oOt A!uOz &<({OB <& !%	  #"""	! !SO O OGSA
 SA
 S S S	    c                     |                      |          }|                     |dg           }|                     |          S )a  
        retrieves data on all markets for blofin

        https://blofin.com/docs#get-instruments

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        data)publicGetMarketInstruments	safe_listparse_markets)rV  paramsresponser[  s       rX  fetch_marketszblofin.fetch_markets  s@     226::~~h33!!$'''rY  marketc                 H   |                      |d          }|                     |d          }|dk    }|dk    }|dk    }|dk    }|p|}|                      |d          }	|                      |d          }
|                      |d          }|                     |          }|                     |	          }|                     |
          }|d	z   |z   }|r|d
z   |z   }d }d }d }|                      |d          }|                     | j        |di           }|                     |d          }|                     |d          }|                      |dd          }t          j        |d          }|                      |d          dk    }|                     i d|d|d|d|d|	d|
d|d|d|d|d|d|ot          j	        |d          d|d|d|d|d|||r|
|k    nd |r|	|k    nd |r|                     |d          nd ||||| 
                    |d           |                     |d!          |                     |          d"|                     d          |                     |          d#|                     |d$          d d#d d d#d d d#d%|d&          S )'NinstIdinstTyper:   r=   r<   r>   baseCurrencyquoteCurrency/:tickSizetradingr   r   maxLeverage1001stateliver.   symbolbasequotebaseIdquoteIdsettlesettleIdtyper;   activecontractValuelistTimelotSize)amountr   )minr   minSize)r   r}  r   cost)contractr   r   contractSizeexpiryexpiryDatetimestrike
optionTypecreated	precisionlimitsinfo)safe_stringsafe_string_lowersafe_currency_codesafe_dict_2r   safe_numberr)   
string_maxsafe_market_structure	string_gtsafe_integerrU  )rV  rb  r.   rx  r:   r=   r<   r>   r  rt  ru  rw  rv  rr  rs  rq  r  strikePricer  rj  r   r   r   rl  isActives                            rX  parse_marketzblofin.parse_market  s   fh//%%fj99("(">6!!&.99""6?;;##FO<<((22&&v..''00e# 	+c\F*F
##FJ77	4B??  w//  w//&&v}eDD(c::$$VW55?)) 2+
"2+
f2+
 D2+
 U	2+

 f2+
 w2+
 f2+
 2+
 D2+
 D2+
 f2+
 dD 1+s C C2+
 D2+
 f2+
 h2+
  U!2+
" U#2+
$ !/7Aw(**T/7A(**TIQ[D,,V_EEEW[$!$((<<**69==**844   ,,S11,,[99 
  ++FI>> 
   
    $ c2+
 2+
 2+
 2 2 2	rY  Nrq  r   c                    |                                   |                     |          }d|d         i}|dn|}|||d<   |                     |                     ||                    }|                     |dg           }|                     |di           }|                     |d          }	|                     |||	          S )	a"  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://blofin.com/docs#get-order-book

        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/?id=order-book-structure>` indexed by market symbols
        rd  r.   N2   sizer[  r   ts)load_marketsrb  publicGetMarketBooksextendr]  	safe_dictr  parse_order_book)
rV  rq  r   r_  rb  requestr`  r[  first	timestamps
             rX  fetch_order_bookzblofin.fetch_order_bookK  s     	V$$fTl
 }5#GFO,,T[[&-I-IJJ, ~~h33tQ++%%eT22	$$UFI>>>rY  tickerc           
         |                      |d          }|                     |d          }|                     ||d          }|d         }|                     |d          }|                     |d          }|                     |dd          }|r|                     |d	          n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"|          S )#Nr  rd  -rq  lastopen24hr:   FvolCurrency24hvol24hhigh24hlow24hr  datetimehighlowbidbidPrice	bidVolumebidSizeaskaskPrice	askVolumeaskSizevwapopenclosepreviousClosechange
percentageaverage
indexPrice	markPrice)
baseVolumequoteVolumer  r  r  )r  r  safe_market	safe_boolsafe_tickeriso8601)rV  r  rb  r  marketIdrq  r  r  r:   r  r  r  r  s                rX  parse_tickerzblofin.parse_tickery  sc   ( %%fd33	##FH55!!(FC88!//	22~~ffe44DHRd&&v/?@@@d%%fh77
	22vx00 !
f!
!
 Y//!
 D	!

 3!
 4##FJ77!
 ))&)<<!
 4##FJ77!
 ))&)<<!
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&**6<@@))&+>>-!
 !
 !
. /  	rY  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://blofin.com/docs#get-tickers

        :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>`
        rd  r.   r[  r   )r  rb  publicGetMarketTickersr  r]  r  r  rV  rq  r_  rb  r  r`  r[  r  s           rX  fetch_tickerzblofin.fetch_ticker  s     	V$$fTl
 ..t{{7F/K/KLL~~h33tQ++  ///rY  c                 B   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     |di           }|                     ||          S )a  
        fetches mark price for the market

        https://docs.blofin.com/index.html#get-mark-price

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/?id=ticker-structure>`
        rq  r.   r[  r   )r  rb  publicGetMarketMarkPricer  r]  r  r  r  s           rX  fetch_mark_pricezblofin.fetch_mark_price  s     	V$$fTl
 00Wf1M1MNN~~h33tQ++  ///rY  symbolsc                     |                                   |                     |          }|                     |          }|                     |dg           }|                     ||          S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://blofin.com/docs#get-tickers

        :param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/?id=ticker-structure>`
        r[  )r  market_symbolsr  r]  parse_tickers)rV  r  r_  r`  tickerss        rX  fetch_tickerszblofin.fetch_tickers  sg     	%%g....v66..6266!!'7333rY  tradec                 0   |                      |d          }|                      |d          }|                     ||d          }|d         }|                     |d          }|                     |dd          }|                     |dd	          }|                      |d
          }	|                      |d          }
|                      |d          }d }|||d         d}|                     |||                     |          |||
d d |	||d |d|          S )NtradeIdrd  r  rq  r  r   	fillPricer  fillSizesideorderIdfeerv  r  currency)r  r  r  rq  r.   orderrx  takerOrMakerr  r   r}  r  r  )r  r  r  safe_string_2
safe_trader  )rV  r  rb  r.   r  rq  r  r   r}  r  r  feeCostr  s                rX  parse_tradezblofin.parse_trade  sM   8 eY//##E844!!(FC88!%%eT22	""5';??##E6:>>v..""5)44""5%00"8, C "Y//  
  
   	rY  sincec                    |                                   d}|                     |dd          \  }}|r|                     d||||dddd	  	        S |                     |          }d|d	         i}d}|||d
<   d}	|                     |ddd          \  }	}|	dk    r)|                     |                     ||                    }|                     |dg           }
|                     |
|||          S )a  
        get the list of most recent trades for a particular symbol

        https://blofin.com/docs#get-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
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: *only applies to publicGetMarketHistoryTrades* default False, when True will automatically paginate by calling self endpoint multiple times
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=public-trades>`
        Fr   paginater  afterNr6   rd  r.   r   rE  publicGetMarketTradesr[  )r  handle_option_and_paramsfetch_paginated_call_cursorrb  r  r  r]  parse_trades)rV  rq  r  r   r_  r  rb  r  r`  rE  r[  s              rX  fetch_tradeszblofin.fetch_trades&  s"    	88PZ[[& 	@33M65RWY_ajlsuy{~V$$fTl
 $GG66v}hXopp,,,11$++gv2N2NOOH~~h33  vue<<<rY  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r               )r  r  )rV  ohlcvrb  s      rX  parse_ohlcvzblofin.parse_ohlcvF  s     eQ''UA&&UA&&UA&&UA&&UA&&
 	
rY  r   	timeframec           	      6   |                                   |                     |          }d}|                     |dd          \  }}|r|                     d|||||d          S |d}|d         |                     | j        ||          |d}|                     |d          }	|	|	|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://blofin.com/docs#get-candlesticks

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest candle to fetch
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Fr   r  r6   Nr.   )rd  barr   untilr  r[  )r  rb  r  "fetch_paginated_call_deterministicr  r   r  omitpublicGetMarketCandlesr  r]  parse_ohlcvs)rV  rq  r  r  r   r_  rb  r  r  r  r`  r[  s               rX  fetch_ohlcvzblofin.fetch_ohlcv]  s>    	V$$88zZZ& 	w::<QVX]_hjpruvvv=ETl##DOY	JJ
 

 !!&'22$GGYYvw//F..t{{7F/K/KLL~~h33  vy%GGGrY  c           
         |t          | j        dz             |                                  d}|                     |dd          \  }}|r|                     d|||d|d          S |                     |          }d|d	         i}|t          |d
z
  d          |d<   |||d<   |                     |d          }|||d<   |                     |d          }| 	                    | 
                    ||                    }	g }
|                     |	dg           }t          dt          |                    D ]h}||         }|                     |d          }|
                    ||d         |                     |d          ||                     |          d           i|                     |
d          }|                     ||d         ||          S )a  
        fetches historical funding rate prices

        https://blofin.com/docs#get-funding-rate-history

        :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 boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :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 argumentFrl   r  r   r6   rd  r.   r   r   beforer   r  r  r[  fundingTimerq  fundingRate)r  rq  r  r  r  r  )r"   r.   r  r  r  rb  r   r  r  !publicGetMarketFundingRateHistoryr  r]  rangelenappendr  r  sort_byfilter_by_symbol_since_limit)rV  rq  r  r   r_  r  rb  r  r  r`  ratesr[  irater  sorteds                   rX  fetch_funding_rate_historyz!blofin.fetch_funding_rate_history  s    >#DG.e$efff88AZ\fgg& 	::;TV\^cejlprxz}~~~V$$fTl
  #EAIq 1 1GH$GG!!&'22$GGYYvw//F99$++gv:V:VWW~~h33q#d))$$ 		 		A7D))$>>ILL *#//mDD& LL33      e[11009I5RWXXXrY  c                 l   |                      |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 iS )Nrd  r  r  rq  r  r  interestRate0estimatedSettlePricer  r  r  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r  safe_symbolr  rU  r  r  )rV  r  rb  r  rq  r  s         rX  parse_funding_ratezblofin.parse_funding_rate  sP    ##Hh77!!(F33''-@@
H
f
 
 $	

 D--c22
 #D
 
 
 4++HmDD
 
 t||K88
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 
 	
rY  c                    |                                   |                     |          }|d         st          | j        dz             d|d         i}|                     |                     ||                    }|                     |dg           }|                     |di           }|                     ||          S )aN  
        fetch the current funding rate

        https://blofin.com/docs#get-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>`
        r<   z2 fetchFundingRate() is only valid for swap marketsrd  r.   r[  r   )	r  rb  r    r.   publicGetMarketFundingRater  r]  r  r  )rV  rq  r_  rb  r  r`  r[  entrys           rX  fetch_funding_ratezblofin.fetch_funding_rate  s     	V$$f~ 	`*^ ^___fTl
 224;;w3O3OPP ~~h33tQ++&&uf555rY  c                     |                      |d          }|*t          |t                    r|                     |          S |                     |          S )Nr[  )r]  
isinstancelistparse_funding_balanceparse_balance)rV  r`  r[  s      rX  parse_balance_by_typezblofin.parse_balance_by_type  sR    ~~h//*T4"8"8--h777%%h///rY  c                    d|i}|                      |di           }|                     |d          }|                     |dg           }t          dt	          |                    D ]}||         }|                     |d          }|                     |          }	|                                 }
|                     |d          }|                     |d          }||3|                     |d	          |
d
<   |                     |d          |
d<   n
||
d<   ||
d
<   |
||	<   ||d<   |                     |          |d<   | 	                    |          S )Nr  r[  r  detailsr   r  equity	availableavailableEquityfreefrozenusedtotalr  r  )
r  r  r]  r  r  r  r  accountr  safe_balance)rV  r`  resultr[  r  r(  r
  balance
currencyIdcoder0  eqavailEqs                rX  r%  zblofin.parse_balance  sd   > )~~h33%%dD11	..y"55q#g,,'' 	# 	#AajG))':>>J**:66DllnnG!!'844B&&w<<G
"&"2"27<M"N"N"&"2"27H"E"E#% ")"F4LL'{!\\)44z  (((rY  c                    d|i}|                      |dg           }t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |                     |d	          |d
<   |||<   |                     |          S )Nr  r[  r   r  r3  r/  r*  r,  r-  r.  )r]  r  r  r  r  r0  r1  )	rV  r`  r2  r[  r
  r3  r4  r5  r0  s	            rX  r$  zblofin.parse_funding_balance4  s      )~~h33q#d))$$ 		# 		#A1gG))':>>J**:66DllnnG#//CCGG"..wDDGFO"..wAAGFO"F4LL  (((rY  r  c                 $   ||                      d |          |                     t          j        |                     |dd                              |                     t          j        |                     |dd                              d d dS )Nr   makerUr   takerU)r  rq  r   r   r  	tierBased)r  rU  r)   
string_negr  )rV  r  rb  s      rX  parse_trading_feezblofin.parse_trading_feeR  s    &&tV44&&w'9$:L:LSRY[c:d:d'e'eff&&w'9$:L:LSRY[c:d:d'e'eff
 
 	
rY  c                    |                                   d}|                     |ddd          \  }}i }d}|h|dk    rb|                     | j        di           }|                     |||          }||d<   |                     |                     ||                    }n)|                     |                     ||                    }|                     |          S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://blofin.com/docs#get-balance
        https://blofin.com/docs#get-futures-account-balance

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.accountType]: the type of account to fetch the balance for, either 'funding' or 'futures'  or 'copy_trading' or 'earn'
        :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
        NrV   accountTyperx  r<   r1  )	r  handle_option_and_params_2r  r.  r  privateGetAssetBalancesr  privateGetAccountBalancer&  )rV  r_  r@  r  r`  r.  parsedAccountTypes          rX  fetch_balancezblofin.fetch_balance]  s     	"==fnVcekllV
"{f'<'<nnT\3CRHHG $ 0 0+{ S S%6GM"33DKK4P4PQQHH44T[[&5Q5QRRH))(333rY  rx  r  r}  r   c           	      *   |                      |          }|d         |||                     ||          |                     | j        dd          d}d }	|                     d|d          \  }	}|	|d<   |                     |d          }
|                     |d	d
          }|                     |dd          }|r|dk    rdnd|d<   |dk    }|                     |d	g          }|dk    p|dk    }|o|}|s|rd|d<   n|
dnd}|                     ||          ||<   d}|                     ||dk    |          \  }}|rd|d<   | 	                    |d          }| 	                    |d          }|                     |g d          }|d u}|d u}|s|r|r`| 
                    |dd          }|                     ||          |d<   |                     |dd          }|                     ||          |d<   |r`| 
                    |dd          }|                     ||          |d <   |                     |dd          }|                     ||          |d!<   n'|
%d"|d<   |                     ||
          |d<   |rd|d<   |                     ||          S )#Nr.   r/  r0  )rd  r  	orderTyper  r/  rI   crossr   r   r   GTCr   FbuylongshortpositionSiderb  r   iocrG  
orderPricer   	post_onlyrx  stopLoss
takeProfit)rQ  rR  r   	stopPriceslTriggerPrice-1slOrderPricetpTriggerPricetpOrderPricer   )rb  amount_to_precisionr  r.  handle_margin_mode_and_paramsr  r  price_to_precisionhandle_post_onlyr  r  r  )rV  rq  rx  r  r}  r   r_  rb  r  r   r   r   isHedgedisMarketOrderrN  	marketIOCkeypostOnlyrQ  rR  hasStopLosshasTakeProfitrT  rV  rW  tpPrices                             rX  create_order_requestzblofin.create_order_requestw  s+   V$$Tl,,VV<<((zCUVV
 
 
!??vW^__
F *''??&&v}eDD>>&(E:: 	M15ffWGN#(6M?33e#7"*s	 	BI 	B#+GK  #/#;,,'C2265AAGCL00@SU[\\& 	*)GFO>>&*55^^FL99
6#G#G#GHHd*"$. 	-- 	- X!%!3!3Hnk!Z!Z,0,C,CFN,[,[()#//'4HH*.*A*A&,*W*W' S!%!3!3JP[!\!\,0,C,CFN,[,[()**:wEE*.*A*A&'*R*R'%#,GK &*&=&=fl&S&SGN# -(,%{{7F+++rY  statusc                 B    ddddddd}|                      |||          S )Ncanceledr  closed)rh  order_failedrp  partially_filledfilled	effectiver  rV  rf  statusess      rX  parse_order_statuszblofin.parse_order_status  s:    "& &!
 
 &&999rY  r  c                    |                      |g d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }d }	d }
|dk    rd}	d	}n|d
k    rd}
d	}n|dk    rd}
d	}n|dk    rd}|                     |d          }|                     ||          }|                     ||d          }|                     |d          }|                      |g d          }|                     |d          }|                     |                     |d                    }|                     |d          }|                     |d          }|                     |dd          }|                     |d          }t          j        ||          }d }|*t          j        ||          }t          j        ||          }d }|Xt          j	        |          }|                     |dd          }| 
                    |          }|                     |          |d}|                     |d          }|t          |          dk     rd }|                     |d           }|                     |d!          }|                     |d"          }|                     |d#          }|                     |d$          } | d%k    }!|                     i d&|d'|d|d(|d)|                     |          d*|d+|d,|d-|d.|
d/|	d|d0|d1|d2|d3|d4|||||d ||d |!d5	|          S )6N)tpslIdr  algoId
createTime
updateTimefillTimer  rG  rP  Tr   fokr   rN  r   conditionalr   rd  r  
filledSize)pxr   rO  averagePricero  r  r  r   rn  r  feeCcyr=  r  clientOrderIdr   rT  rV  rW  rX  
reduceOnlytruer  r.   r  r  lastTradeTimestamplastUpdateTimestamprq  rx  r   ra  r   stopLossTriggerPricetakeProfitTriggerPricer   r   )	r  r  r}  rl  	remainingrf  r  tradesr  )safe_string_nr  r  r  r  rq  r)   
string_mul
string_div
string_absr  rU  r  r  
safe_orderr  )"rV  r  rb  r.   r  r  r  r  rx  ra  r   r  rq  rl  r   r  rf  feeCostStringr}  r   r  
baseAmountr  r  feeCostSignedfeeCurrencyIdfeeCurrencyCoder~  r  r   r  r   reduceOnlyRawr  s"                                     rX  parse_orderzblofin.parse_order  s\   H 'F'F'FGG%%e\::	"//|DD!..ujAAv..{33;HDDU]]KDDU]]KDD]""D##E844!!(F33!!(FC88!!%66""5*G*G*GHH""5.99(()9)9%)I)IJJ((66!!%00##E:s;;''??'f==
%gz::D%dH55D$#.}==M ,,UHfEEM"55mDDO))-88+ C ((@@%C,>,>,B,B M#//7GHH((??!%!1!1%9I!J!J**5.AA((==#v-
  
E 
" 
 ] 
 	 

 Y// 
 !"4 
 "#6 
 f 
 D 
 ; 
  
 D 
 U 
 #$8 
 %&< 
  ]! 
" # 
$ $5 
  
  
6 7  	rY  c                    |                                   |                     |          }|                     |dd          }|                     |d          }d}	|                     |ddd          \  }	}|                     |d          du}
|                     |d          du}|                     |d	          du}|
p|}d}|                     |d
          }|	|rdnd|d
<   |p|	dk    p|}|p|	dk    }|r0|                     ||||||          }|                     |          }na|r0|                     ||||||          }| 	                    |          }n/|                     ||||||          }| 
                    |          }|s|r-|                     |di           }|                     ||          S |                     |dg           }|                     |d          }|                     ||          }||d<   ||d<   |S )a	  
        create a trade order

        https://blofin.com/docs#place-order
        https://blofin.com/docs#place-tpsl-order

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit' or 'post_only' or 'ioc' or 'fok'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.triggerPrice]: the trigger price for a trigger order
        :param bool [params.reduceOnly]: a mark to reduce the position size for margin, swap and future orders
        :param bool [params.postOnly]: True to place a post only order
        :param str [params.marginMode]: 'cross' or 'isolated', default is 'cross'
        :param float [params.stopLossPrice]: stop loss trigger price(will use privatePostTradeOrderTpsl)
        :param float [params.takeProfitPrice]: take profit trigger price(will use privatePostTradeOrderTpsl)
        :param str [params.positionSide]: *stopLossPrice/takeProfitPrice orders only* 'long' or 'short' or 'net' default is 'net'
        :param boolean [params.hedged]: if True, the positionSide will be set to long/short instead of net, default is False
        :param str [params.clientOrderId]: a unique id for the order
        :param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered
        :param float [params.takeProfit.triggerPrice]: take profit trigger price
        :param float [params.takeProfit.price]: take profit order price(if not provided the order will be a market order)
        :param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered
        :param float [params.stopLoss.triggerPrice]: stop loss trigger price
        :param float [params.stopLoss.price]: stop loss order price(if not provided the order will be a market order)
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        tpslFNrI   rE  rG  r   r   r   r  r  falseprivatePostTradeOrderTpslprivatePostTradeOrderAlgor[  r   rx  r  )r  rb  r  r  r  r  create_tpsl_order_requestr  re  r  rG  r  r  r]  )rV  rq  rx  r  r}  r   r_  rb  r  rE  isStopLossPriceDefinedisTakeProfitPriceDefinedhasTriggerPriceisType2Orderr`  r  isTpslOrderisTriggerOrdertpslRequesttriggerRequestr  dataDictr[  r  r  s                            rX  create_orderzblofin.create_order.  s]   < 	V$$~~ffe4466**66v}hXopp!%!1!1&/!J!JRV!V#'#3#3F<M#N#NVZ#Z **6>BB$N.J2J^^FL99
!-7#D66WF< Uv)DDU(SV7R-R 	;88tVUZ\bccK55kBBHH 	;!66vtT6SXZ`aaN55nEEHH//dFESYZZG11'::H 	6. 	6~~h;;H##Hf555~~h33tQ''  //ffrY  c                    |                      |          }|                     |dd          }|d         |||                     | j        dd          d}	||                     ||          |	d<   |                     |dd	          }
|
d	k    r|
d
k    rt	          | j        dz             |                     |d          }|                     |d          }|?|                     ||          |	d<   |dk    rd|	d<   nZ|                     ||          |	d<   n@|>|                     ||          |	d<   |dk    rd|	d<   n|                     ||          |	d<   |
|	d<   |                     |ddg          }|                     |	|          S )NrM  netr.   r/  r0  )rd  r  rM  r/  r  r   rH  isolatedzX createTpslOrder() requires a marginMode parameter that must be either cross or isolatedr   r   rT  rb  rU  rV  rW  rX  )	rb  r  r.  rY  r#   r.   r[  r  r  )rV  rq  rx  r  r}  r   r_  rb  rM  r  r   r   r   s                rX  r  z blofin.create_tpsl_order_requesto  s   V$$''FFTl(((zCUVV	
 
 "66vvFFGFO%%flGDD
  Z:%=%=TW  (B  B  C  C  C((AA**63DEE$(,(?(?(V(VG$%x*.''*.*A*A&%*P*P''((,(?(?(X(XG$%x*.''*.*A*A&%*P*P' *6O5F#GHH{{7F+++rY  r.   c                    |t          | j        dz             |                                  |                     |          }d|d         i}|                     |dgd          }|                     |ddd          }|                     |d	          }|||d	<   n@|s|st          |          |d
<   n)|rt          |          |d<   n|rt          |          |d<   |                     |g d          }	|r0| 	                    |g||          }
| 
                    |
d          }|S |rU|                     |                     ||	                    }| 
                    |d          }|                     ||          S |                     |                     ||	                    }|                     |dg           }| 
                    |d          }|                     ||          S )a;  
        cancels an open order

        https://blofin.com/docs#cancel-order
        https://blofin.com/docs#cancel-tpsl-order

        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: True if cancelling a trigger/conditional
        :param boolean [params.tpsl]: True if cancelling a tpsl order
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nz) cancelOrder() requires a symbol argumentrd  r.   r   Fr  TPSLr~  r  rs  rt  )r  r~  stopr   r  r   r[  )r"   r.   r  rb  safe_bool_nsafe_bool_2r  strr  cancel_ordersr  privatePostTradeCancelAlgor  r  privatePostTradeCancelOrderr]  )rV  r.   rq  r_  rb  r  	isTriggerisTpslr~  querytpslResponser  triggerResponsetriggerDatar`  r[  r  s                    rX  cancel_orderzblofin.cancel_order  s    >#DG.Y$YZZZV$$fTl
 $$Vi[%@@	!!&&&%@@((AA$'4GO$$ ,V ,%(WW	"" ,$'GG!! ,$'GG!		&"Y"Y"YZZ 	9--rdFFCCLNN<33EL 	9"==dkk'SX>Y>YZZO..&AAK##K88833DKK4O4OPP~~h33tQ''v...rY  ordersc           	         |                                   g }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d          }|                     |d          }	|                     |d          }
|                     |di           }|                     ||          }|                     ||||	|
|          }|                    |           | 	                    |          }| 
                    |dg           }|                     |          S )	a  
        create a list of trade orders

        https://blofin.com/docs#place-multiple-orders

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r   rq  rx  r  r}  r   r_  r[  )r  r  r  r  
safe_valuer  r  re  r  privatePostTradeBatchOrdersr]  parse_orders)rV  r  r_  ordersRequestsr
  rawOrderr  rx  r  r}  r   orderParamsextendedParamsorderRequestr`  r[  s                   rX  create_orderszblofin.create_orders  sB    	q#f++&& 
	0 
	0AayH''(;;H##Hf55D##Hf55D__Xx88FOOHg66E..8R@@K![[f==N44XtT6SXZhiiL!!,////33NCC~~h33  &&&rY  c                 D   |                                   d}|                     |dd          \  }}|r|                     d||||          S i }d}| |                     |          }|d         |d<   |||d<   |                     |dd	gd          }|                     |d
dd          }	d}
|                     |ddd          \  }
}|                     |g d          }d}|	s|
dk    r*|                     |                     ||                    }n`|s|
dk    r/d	|d<   | 	                    |                     ||                    }n)| 
                    |                     ||                    }|                     |dg           }|                     ||||          S )a  
        Fetch orders that are still open

        https://blofin.com/docs#get-active-orders
        https://blofin.com/docs#get-active-tpsl-orders
        https://docs.blofin.com/index.html#get-active-algo-orders

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of  open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.trigger]: True if fetching trigger or conditional orders
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Fr   r  Nr.   rd  r   r  r   r  r  rE  rK  rE  r  r   r  r   privateGetTradeOrdersTpslPending privateGetTradeOrdersAlgoPendingrG  r[  )r  r  fetch_paginated_call_dynamicrb  r  r  r  r  r  r  rK  r]  r  )rV  rq  r  r   r_  r  r  rb  r  isTpSlrE  r  r`  r[  s                 rX  fetch_open_orderszblofin.fetch_open_orders  s     	88ART^__& 	f445FPUW\^deee
[[((F &tGH$GG$$Vfi-@%HH	!!&&&%@@66v?PRZ\z{{		&"O"O"OPP 	Vf BBB<<T[[RW=X=XYYHH 	V6%GGG#,GK <<T[[RW=X=XYYHH88We9T9TUUH~~h33  vue<<<rY  c                    |                                   d}|                     |dd          \  }}|r|                     d||||          S i }d}| |                     |          }|d         |d<   |                     d||          \  }}|||d<   |                     |                     ||                    }|                     |d	g           }	|                     |	|||          S )
a7  
        fetch all trades made by the user

        https://blofin.com/docs#get-trade-history

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: Timestamp in ms of the latest time to retrieve trades for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Fr~   r  Nr.   rd  endr   r[  )	r  r  r  rb  handle_until_optionprivateGetTradeFillsHistoryr  r]  r  )
rV  rq  r  r   r_  r  r  rb  r`  r[  s
             rX  fetch_my_tradeszblofin.fetch_my_trades  s    	88R\]]& 	d44_feUZ\bccc
[[((F &tGH225'6JJ$GG33DKK4P4PQQ~~h33  vue<<<rY  r5  c                    |                                   d}|                     |dd          \  }}|r|                     d||||          S i }d}| |                     |          }|d         |d<   |t	          |dz
  d          |d	<   |||d
<   |                     d||          \  }}|                     |                     ||                    }|                     |dg           }	| 	                    |	||||          S )a<  
        fetch all deposits made to an account

        https://blofin.com/docs#get-deposite-history

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        Fre   r  Nr.   r  r   r   r   r   r  r[  )
r  r  r  r  r   r  privateGetAssetDepositHistoryr  r]  parse_transactions
rV  r5  r  r   r_  r  r  r  r`  r[  s
             rX  fetch_depositszblofin.fetch_deposits&  s+    	88R\]]& 	b44_dESXZ`aaa
}}T**H"*4.GJ #EAIq 1 1GH$GG227GVLL55dkk'66R6RSS~~h33&&tXueVLLLrY  c                    |                                   d}|                     |dd          \  }}|r|                     d||||          S i }d}| |                     |          }|d         |d<   |t	          |dz
  d          |d	<   |||d
<   |                     d||          \  }}|                     |                     ||                    }|                     |dg           }	| 	                    |	||||          S )aG  
        fetch all withdrawals made from an account

        https://blofin.com/docs#get-withdraw-history

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        Fr   r  Nr.   r  r   r   r   r   r  r[  )
r  r  r  r  r   r   privateGetAssetWithdrawalHistoryr  r]  r  r  s
             rX  fetch_withdrawalszblofin.fetch_withdrawalsH  s-    	88ASU_``& 	e445GuV[]cddd
}}T**H"*4.GJ #EAIq 1 1GH$GG227GVLL88Wf9U9UVV~~h33&&tXueVLLLrY  c                    |                                   d}|                     |dd          \  }}|r|                     d||||          S i }|||d<   d}| |                     |          }|d         |d<   |                     d||          \  }}d}|                     |                     ||                    }|                     |d	g           }	|                     |	|||          S )
a  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

        https://blofin.com/docs#get-funds-transfer-history

        :param str [code]: unified currency code, default is None
        :param int [since]: timestamp in ms of the earliest ledger entry, default is None
        :param int [limit]: max number of ledger entries to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated'
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict: a `ledger structure <https://docs.ccxt.com/?id=ledger-entry-structure>`
        Frs   r  Nr   r.   r  r  r[  )	r  r  r  r  r  rJ  r  r]  parse_ledgerr  s
             rX  fetch_ledgerzblofin.fetch_ledgerj  s    	88PZ[[& 	`44]D%QVX^___
$GG}}T**H"*4.GJ225'6JJ,,T[[&-I-IJJ~~h33  x>>>rY  transactionr  c                 $   d }d }|                      |d          }|                      |d          }|                      |d          }|}|                      |d          }	|d}|}n|}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S )N
withdrawId	depositIdaddresstag
withdrawaldepositr  r}  ro  txIdr  feeCurrencyr  r  r.   networkaddressFrom	addressTotagFromtagTorf  rx  updatedtxidr  r  )r  r  )internalcommentr  )r  r  r  parse_transaction_statusr  r  )rV  r  r  rx  r.   withdrawalIdr  r  r  r  r4  r5  r}  rf  r  r  r  feeCoder  s                      rX  parse_transactionzblofin.parse_transaction  sP   H ''\BB$$[+>>	$$[)<<	  e44#DBBBD%%k:>>
&&z22!!+x88..t/?/?W/U/UVVV44%%k488	((mDD))-88"";66
K
"
 
 f	

 t
 4
 
 w
 t
 U
 5
 f
 D
 t
 D
  !
" Y//#
$ # )
 
 
 	
rY  c                 >    ddddd}|                      |||          S )Npendingokfailed)r  rn  23rn  ro  s      rX  r  zblofin.parse_transaction_status  s4    	
 
 &&999rY  c                 L    dddddddddddd}|                      |||          S )Nr   r  rebater  )rn  r  r  4567891011rn  )rV  rx  typess      rX  parse_ledger_entry_typezblofin.parse_ledger_entry_type  sI    
 
 tT222rY  itemc                    |                      |d          }|                     ||          }|                     ||          }|                     |d          }|                     ||                      |d          d d |                      |d          d |                     |                      |d                    ||                     |d          ||                     |          d d dd d|          S )	Nr  r  
transferIdclientIdrx  r}  r  )r  r.   	directionr0  referenceIdreferenceAccountrx  r  r}  r  r  r   r  rf  r  )r  r  safe_currencyr  safe_ledger_entryr   r  r  )rV  r  r  r4  r5  r  s         rX  parse_ledger_entryzblofin.parse_ledger_entry  s   %%dJ77
&&z8<<%%j(;;%%dD11	%%""466++D*== $001A1A$1O1OPP&&tX66"Y//'
 '
  !  	rY  c                 Z    t          |t                    r|                    d          S |S )zg
 @ignore
        :param string[]|str ids: order ids
        :returns str[]: list of order ids
        ,)r"  r  split)rV  idss     rX  	parse_idszblofin.parse_ids  s+     c3 	99S>>!JrY  r  c                    |t          | j        dz             |                                  |                     |          }g }|                     | j        di           }|                     |dd          }|                     |d|          }|                     |                     |d                    }	|                     |                     |d                    }
| 	                    |g d          }|rd	}|	|                     |          }|
Dt          d
t          |
                    D ]&}|                    |
|         |d         d           't          d
t          |                    D ]M}|r%|                    ||         |d         d           )|                    ||         |d         d           NnDt          d
t          |	                    D ]&}|                    |d         |	|         d           'd}|d	k    r|                     |          }n|                     |          }|                     |dg           }|                     ||dd|          S )a  
        cancel multiple orders

        https://blofin.com/docs#cancel-multiple-orders

        :param str[] ids: order ids
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: whether the order is a stop/trigger order
        :returns dict: an list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nz* cancelOrders() requires a symbol argumentrC   rE  rL  r~  rs  )r  r   r  privatePostTradeCancelTpslr   r.   )rs  rd  )r  rd  )rd  r~  r[  )r"   r.   r  rb  r  r.  r  r  r  r  r  r  r  r  rL  r]  r  )rV  r  rq  r_  rb  r  r.  defaultMethodrE  clientOrderIdstpslIdsr   r
  r`  
ordersDatas                  rX  r  zblofin.cancel_orders  s    >#DG.Z$Z[[[V$$..~rBB(((<_``!!&(MBB(P(PQQ..!B!BCC""6+F+F+FGG 	21F!..%%C"q#g,,//  ANN")!*"(,$ $     1c#hh'' 
 
 	NN"%a&"(,$ $    
 NN#&q6"(,$ $    
 1c.1122  $Tl%3A%6        11166w??HH==gFFH^^Hfb99
  VT4HHHrY  fromAccount	toAccountc                    |                                   |                     |          }|                     | j        di           }|                     |||          }|                     |||          }	|d         |                     ||          ||	d}
|                     |                     |
|                    }|                     |di           }|                     ||          S )aH  
        transfer currency internally between wallets on the same account

        https://blofin.com/docs#funds-transfer

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from(funding, swap, copy_trading, earn)
        :param str toAccount: account to transfer to(funding, swap, copy_trading, earn)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/?id=transfer-structure>`
        r1  r.   )r  r}  r  r  r[  )	r  r  r  r.  r  currency_to_precisionprivatePostAssetTransferr  parse_transfer)rV  r5  r}  r  r  r_  r  r1  fromIdtoIdr  r`  r[  s                rX  r   zblofin.transferV  s     	==&&6FKK!!.+{KK	9EE 00v>>!	
 
 00Wf1M1MNN~~h33""4222rY  r   c           
      F    |                      |d          }||d d d d d d d d	S )Nr  )	r  r.   r  r  r  r}  r  r  rf  rn  )rV  r   r  r.   s       rX  r  zblofin.parse_transferr  sA    h55

 

 
	
rY  c                 H   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     |d          }|dS |                     ||          S )a  
        fetch data on a single open contract trade position

        https://blofin.com/docs#get-positions

        :param str symbol: unified market symbol of the market the position is held in, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.instType]: MARGIN, SWAP, FUTURES, OPTION
        :returns dict: a `position structure <https://docs.ccxt.com/?id=position-structure>`
        rd  r.   r[  r   N)r  rb  rF  r  r]  r  parse_position)rV  rq  r_  rb  r  r`  r[  positions           rX  fetch_positionzblofin.fetch_position  s     	V$$fTl
 224;;w3O3OPP~~h33>>$**4""8V444rY  c                    |                                   |                     |          }|                     |          }|                     |dg           }|                     |          }|                     |d|d          S )a  
        fetch data on a single open contract trade position

        https://blofin.com/docs#get-positions

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.instType]: MARGIN, SWAP, FUTURES, OPTION
        :returns dict: a `position structure <https://docs.ccxt.com/?id=position-structure>`
        r[  rq  F)r  r  rF  r]  parse_positionsfilter_by_array_positions)rV  r  r_  r`  r[  r2  s         rX  fetch_positionszblofin.fetch_positions  s~     	%%g..226::~~h33%%d++--fhOOOrY  r!  c                    |                      |d          }|                     ||          }|d         }|                      |d          }t          j        |          }|                      |d          }|dk    }|                     |          }	|8|dk    r2t          j        |d          rd}nt          j        |d          rd}nd }|                     |d	          }
|                     |
          }|                      |d
          }|                      |d          }|d         r(t          j	        t          j
        ||          |          }|                     |          }|                      |d          }d }|                      |d          }|                      |d          }|                      |d          }d }d }|dk    r,|                      |d          }t          j        ||          }n1|dk    r+t          j	        d|          }|                      |d          }|                      |d          }|                     |          }t          j	        ||          }|*|                     t          j	        ||d                    }n|t          j
        ||          }d}|                     t          j	        t          j        ||          dd                    }|                     |d          }|                      |d          }|                     t          j
        |d                    }|                     |d          }|                     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(
          S ))Nrd  rq  	positionsrM  r  r  rK  rL  r  r  notionalUsdr   r   r|  unrealizedPnlr   rH  initialMarginr  rn  r;   maintenanceMarginr  z0.00005liquidationPriceunrealizedPnlRatiorm  rv  r  r.   notional
entryPricer  	contracts	lastPricer  r   r  r  )
r  r,  maintenanceMarginPercentage
collateralr+  initialMarginPercentager   marginRatior   r   )r  r  r)   r  rU  r  	string_ltr  number_to_stringr  r  
string_addr  safe_positionr  ) rV  r!  rb  r  rq  poscontractsAbsr  r   r1  r  contractSizeStringmarkPriceStringnotionalStringr/  r   initialMarginStringentryPriceStringunrealizedPnlStringleverageStringr5  collateralStringmaintenanceMarginStringr,  !maintenanceMarginPercentageStringrounderr3  r-  percentageStringr  r  r6  s                                    rX  r   zblofin.parse_position  s7   6 ##Hh77!!(F33!x55)#...99%%l33	?u}}$S#..  !DD&sC00  "DDD''??!22<@@**8[AA))(MBB) 	w$/0B<Qc0d0dfuvvN$$^44%%h==
"++HnEE"..xII))(J??"&  "&"2"28_"M"M&12EGZ[[:%%&-&8n&M&M##//(CC"&"2"28=P"Q"Q --.EFF,3,>?VXf,g,g)"*&*&7&78JK^`npq8r8r&s&s## (")"45Ln"]"]&*&7&78J7K]^  BI  LJ  LJ  LO  QR  9S  9S  'T  'T#++H6HII++H6JKK&&w'9:JE'R'RSS
%%h==	''(:;RTdfg(h(hii!! #
H#
$#
 f#
 	#

 *#
  0#
 $++,<==#
 T../BCC#
 *#
 #
 L#
 **?;;#
 #
 D#
 f#
  !#
" Y//##
$ $(!2+F++,<==!../BCC'+'8'89P'Q'Q)).99&!#7#
 #
 #
   	rY  c                    |                                   |t          | j        dz             d}|                     d|          \  }}||                     |dd          }|dk    r|dk    rt          | j        dz             |                     |          }d}t          d	t          |                    D ]?}||         }| 	                    |          }|d	k    r|d
z   |d         z   }4||d         z   }@||d}| 
                    |                     ||                    }	|                     |	dg           }
|                     |
|d          S )a  
        fetch the set leverage for all contract markets

        https://docs.blofin.com/index.html#get-multiple-leverage

        :param str[] symbols: a list of unified market symbols, required on blofin
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated'
        :returns dict: a list of `leverage structures <https://docs.ccxt.com/?id=leverage-structure>`
        Nz- fetchLeverages() requires a symbols argumentrv   r   rH  r  zW fetchLeverages() requires a marginMode parameter that must be either cross or isolated r   r  r.   rd  r   r[  rd  )r  r"   r.   rZ  r  r#   r  r  r  rb  "privateGetAccountBatchLeverageInfor  r]  parse_leverages)rV  r  r_  r   instIdsr
  r  entryMarketr  r`  	leveragess              rX  fetch_leverageszblofin.fetch_leverages  s    	?#DG.]$]^^^
!??@PRXYY
F))&,HHJ'!!
j(@(@TW  (A  A  B  B  B%%g..q#g,,'' 	6 	6AAJE++e,,K1uu!C-+d*;;!K$55$
 
 ::4;;wPV;W;WXX NN8VR88	##IwAAArY  c                    |                                   d}|                     d|          \  }}||                     |dd          }|dk    r|dk    rt          | j        dz             |                     |          }|d         |d}|                     |                     ||                    }|                     |d	i           }| 	                    ||          S )
a  
        fetch the set leverage for a market

        https://docs.blofin.com/index.html#get-leverage

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated'
        :returns dict: a `leverage structure <https://docs.ccxt.com/?id=leverage-structure>`
        Nru   r   rH  r  zV fetchLeverage() requires a marginMode parameter that must be either cross or isolatedr.   rK  r[  )
r  rZ  r  r#   r.   rb  privateGetAccountLeverageInfor  r  parse_leverage)rV  rq  r_  r   rb  r  r`  r[  s           rX  fetch_leveragezblofin.fetch_leverageF  s     	
!??QWXX
F))&,HHJ'!!
j(@(@TW'  A  A  AV$$Tl$
 
 55dkk'66R6RSS ~~h33""4000rY  r   c                     |                      |d          }|                     |d          }||                     ||          |                     |d          ||dS )Nrd  r   r   )r  rq  r   longLeverageshortLeverage)r  r  r  r  )rV  r   rb  r  leverageValues        rX  rT  zblofin.parse_leveragel  sj    ##Hh77))(J??&&x8800<HH)*
 
 	
rY  c                    |t          | j        dz             |dk     s|dk    rt          | j        dz             |                                  |                     |          }d}|                     d|d          \  }}|dk    r|dk    rt          | j        d	z             |||d
         d}|                     |                     ||                    }|S )a  
        set the level of leverage for a market

        https://blofin.com/docs#set-leverage

        :param int 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.marginMode]: 'cross' or 'isolated'
        :param str [params.positionSide]: 'long' or 'short' - required for hedged mode in isolated margin
        :returns dict: response from the exchange
        Nz) setLeverage() requires a symbol argumentr   }   z3 setLeverage() leverage should be between 1 and 125r   rH  r  zT setLeverage() requires a marginMode parameter that must be either cross or isolatedr.   )r   r   rd  )r"   r.   r#   r  rb  rZ  privatePostAccountSetLeverager  )rV  r   rq  r_  rb  r   r  r`  s           rX  set_leveragezblofin.set_leveragew  s     >#DG.Y$YZZZ qLLhnnTW'\\]]]V$$
!??vW^__
F'!!
j(@(@TW'}}~~~ $Tl
 

 55dkk'66R6RSSrY  c                 Z   |                                   |                     |          }|                     |d          }d}|                     d|d          \  }}|d         |d}|||d<   |                     |                     ||                    }|                     |d          S )a'  
        closes open positions for a market

        https://blofin.com/docs#close-positions

        :param str symbol: Unified CCXT market symbol
        :param str [side]: 'buy' or 'sell', leave in net mode
        :param dict [params]: extra parameters specific to the blofin api endpoint
        :param str [params.clientOrderId]: a unique identifier for the order
        :param str [params.marginMode]: 'cross' or 'isolated', default is 'cross
        :param str [params.code]: *required in the case of closing cross MARGIN position for Single-currency margin* margin currency

 EXCHANGE SPECIFIC PARAMETERS
        :param boolean [params.autoCxl]: whether any pending orders for closing out needs to be automatically canceled when close position via a market order. False or True, the default is False
        :param str [params.tag]: order tag a combination of case-sensitive alphanumerics, all numbers, or all letters of up to 16 characters
        :returns dict[]: `A list of position structures <https://docs.ccxt.com/?id=position-structure>`
        r~  NrE   rH  r.   rK  r[  )r  rb  r  rZ  privatePostTradeClosePositionr  r  )	rV  rq  r  r_  rb  r~  r   r  r`  s	            rX  close_positionzblofin.close_position  s    $ 	V$$((AA
!??QWY`aa
FTl$
 
 $'4GO$55dkk'66R6RSS~~h///rY  c                    |                                   d}|                     |dd          \  }}|r|                     d||||          S i }d}| |                     |          }|d         |d<   |||d<   |||d<   |                     |g d	d          }d}	|                     |d
dd          \  }	}|                     |g d          }
d}|s|	dk    r*|                     |                     ||
                    }n)|                     |                     ||
                    }| 	                    |dg           }| 
                    ||||          S )a  
        fetches information on multiple closed orders made by the user

        https://blofin.com/docs#get-order-history
        https://blofin.com/docs#get-tpsl-order-history

        :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  orde structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.trigger]: True if fetching trigger or conditional orders
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Fr]   r  Nr.   rd  r   begin)r  r   r  r  r   rE  rM  r   privateGetTradeOrdersTpslHistoryr[  )r  r  r  rb  r  r  rc  r  rM  r]  r  )rV  rq  r  r   r_  r  r  rb  r  rE  r  r`  r[  s                rX  fetch_closed_orderszblofin.fetch_closed_orders  s    	88ATV`aa& 	h445H&RWY^`fggg
[[((F &tGH$GG$GG$$V-P-P-PRWXX	66v?PRZ\z{{		&"O"O"OPP 	V6%GGG<<T[[RW=X=XYYHH88We9T9TUUH~~h33  vue<<<rY  c                     |                                   |                     |          }|                     |          }|                     |di           }|                     ||          S )a  
        fetches the margin mode of a trading pair

        https://docs.blofin.com/index.html#get-margin-mode

        :param str symbol: unified symbol of the market to fetch the margin mode for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin mode structure <https://docs.ccxt.com/?id=margin-mode-structure>`
        r[  )r  rb  privateGetAccountMarginModer  parse_margin_mode)rV  rq  r_  rb  r`  r[  s         rX  fetch_margin_modezblofin.fetch_margin_mode  sg     	V$$33F;; ~~h33%%dF333rY  r   c                 ^    ||                      |d          |                      |d          dS )Nrq  r   )r  rq  r   rn  )rV  r   rb  s      rX  rg  zblofin.parse_margin_mode  s:    &&vx88**:|DD
 
 	
rY  c                 D   |                      d|dddg           |                                  d}||                     |          }d|i}|                     |                     ||                    }|                     |di           }|                     ||          S )a  
        set margin mode to 'cross' or 'isolated'

        https://docs.blofin.com/index.html#set-margin-mode

        :param str marginMode: 'cross' or 'isolated'
        :param str [symbol]: unified market symbol(not used in blofin setMarginMode)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        r   r   rH  r  Nr[  )check_required_argumentr  rb  privatePostAccountSetMarginModer  r  rg  )rV  r   rq  r_  rb  r  r`  r[  s           rX  set_margin_modezblofin.set_margin_mode	  s     	$$_j,QXZdPefff[[((F*
 77GV8T8TUU ~~h33%%dF333rY  c                     |                      |          }|                     |di           }|                     |d          }||dk    dS )a  
        fetchs the position mode, hedged or one way

        https://docs.blofin.com/index.html#get-position-mode

        :param str [symbol]: unified symbol of the market to fetch the position mode for(not used in blofin fetchPositionMode)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an object detailing whether the market is in hedged or one-way mode
        r[  positionModelong_short_mode)r  r   )privateGetAccountPositionModer  r  )rV  rq  r_  r`  r[  ro  s         rX  fetch_position_modezblofin.fetch_position_mode"	  s^     55f==~~h33''n== "&77
 
 	
rY  r   c                 d    d|rdndi}|                      |                     ||                    S )a  
        set hedged to True or False for a market

        https://docs.blofin.com/index.html#set-position-mode

        :param bool hedged: set to True to use hedged mode, False for one-way mode
        :param str [symbol]: not used by blofin setPositionMode()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        ro  rp  net_mode)!privatePostAccountSetPositionModer  )rV  r   rq  r_  r  s        rX  set_position_modezblofin.set_position_mode=	  s?     G--Z
 55dkk'66R6RSSSrY  c                     |                                   |                     |dddd          }|                     |          }|                     |dg           }|                     ||          S )a  
        fetches the auto deleveraging rank and risk percentage for a list of symbols

        https://docs.blofin.com/index.html#get-positions

        :param str[] [symbols]: a list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of `auto de leverage structures <https://docs.ccxt.com/?id=auto-de-leverage-structure>`
        NTr[  )r  r  rF  r]  parse_adl_ranks)rV  r  r_  r`  r[  s        rX  fetch_positions_adl_rankzblofin.fetch_positions_adl_rankV	  sq     	%%gtT4FF226::< ~~h33##D'222rY  r  c           	          |                      |d          }|                     |d          }||                     ||d d          |                     |d          d d ||                     |          dS )Nrd  ru  r  adl)r  rq  rankratingr  r  r  )r  safe_integer_omit_zeror  r  r  )rV  r  rb  r  r  s        rX  parse_adl_rankzblofin.parse_adl_rank	  s    4 ##D(33//lCC	&&xzJJ%%dE22"Y//
 
 	
rY  httpCodereasonr   rE  headersbodyc
                    |d S |                      |d          }
|                      |d          }| j        dz   |z   }|
{|
dk    ru|                     | j        d         ||           |                     | j        d         |
|           |                     | j        d         ||           t          |          |                     |d          }|                     |d          }|                      |d          }|                      |d          }|l|dk    rf|                     | j        d         ||           |                     | j        d         ||           |                     | j        d         ||           d S )	Nr5  msg r  r*  r+  r[  r   )r  r.   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr    r]  r  )rV  r  r  r   rE  r  r  r`  requestHeadersrequestBodyr5  messagefeedbackr[  r  	insideMsg
insideCodes                    rX  handle_errorszblofin.handle_errors	  s   4 &11""8U337S=4'001I7T\]]]001I4QYZZZ001I7T\]]]))) ~~h//tQ''$$UE22	%%eV44
!jC&7&7001I:W_```001I9V^___001I9V^___trY  r   GETc                    d| j         z   dz   |                     ||          z   }|                     ||                     |                    }|                     | j        d         d                   |z   }	|dk    r2|                     |          s|	d|                     |          z   z  }	n0|dk    r)|                                  t          | 
                                          }
| j        | j        |
|
d}d	}|d
k    r8|                     |          s"d|                     |          z   }|	|z  }	||z  }n1|                     |          s|                     |          }|}d|d<   ||z   |
z   |
z   |z   }|                     |                     |                     |          |                     | j                  t$          j                            }||d<   |	|||dS )Nz/api/rh  r   r   r   ?r   )z
ACCESS-KEYzACCESS-PASSPHRASEzACCESS-TIMESTAMPzACCESS-NONCErJ  r  zapplication/jsonzContent-TypezACCESS-SIGN)r   rE  r  r  )r3   implode_paramsr  extract_paramsimplode_hostnamer   is_empty	urlencodecheck_required_credentialsr  millisecondsr   r   jsonstring_to_base64hmacencoder   hashlibsha256)rV  pathr   rE  r_  r  r  r  r  r   r  	sign_bodyurlencodedQueryauth	signatures                  rX  signzblofin.sign	  s   DL(3.1D1DT61R1RR		&$"5"5d";";<<##DIe$4V$<==G(??=='' 3sT^^E2222I++---D--//00I"k%)]$- )	 G I}}U++ /&)DNN5,A,A&AO?*C.G}}U++ %99U++D $I*<'V#i/);iGD--diiD8I8I4;;W[WbKcKceles.t.tuuI%.GM"fdwOOOrY  )N)___name__
__module____qualname__r   rT  r   r   ra  dictr  r  r	   r   r  r   r  r  r  r   r   r  r   r  r  r#  r  r  r   r  r   r  r   r&  r%  r$  r   r>  r   rE  r   r   floatr   re  rq  r   r  r  r  r  r   r  r  r  r   r  r  r
   r  r   r  r  r   r
  r  r  r   r   r  r   r"  r&  r   r   rQ  r   rU  rT  intr]  r`  rd  r   rh  rg  rm  rr  boolrv  r   ry  r  r  r  __classcell__)rW  s   @rX  r+   r+      s       T# T T T T T Tl $& ( ($v, ( ( ( (M4 MF M M M M^ :>b ,? ,?s ,?3 ,?Y ,? ,? ,? ,?\6 64 6 66 6 6 6 6p 02 0 03 0f 0 0 0 0( 46 0 0s 0& 0 0 0 0* 04B 4 4W 47 4 4 4 4 : : :v : : : : :x 6:UW = =3 =s =# =\`af\g = = = =@
 
 
4 
 
 
 
. 9=4^bkm #H #H# #H# #HS #HX[ #Hrvw{r| #H #H #H #HJ 8<$]ajl /Y /Y /YC /YWZ /Y /Y /Y /Yb
 
6 
[ 
 
 
 
B 68 !6 !6 !6K !6 !6 !6 !6F0 0 04) 4) 4)l) ) )<	
 	
T 	
6 	
EX 	
 	
 	
 	
 $& 4 4( 4 4 4 44 os{} 3, 3,3 3,i 3,y 3,Z_ 3,hk 3, 3, 3, 3,j	: 	: 	: 	: 	:u u uv u u u u un gksu ? ?3 ?i ?y ?RW ?`c ?z ? ? ? ?B fjx|  FH , , ,9 ,I ,_b ,ru , , , ,@ 37r -/ -/s -/C -/ -/ -/ -/^ @B ' 'D$6 'd5k ' ' ' '6 /3TXac += += +=3 +=c +=hlmrhs += += += +=Z -1tRV_a = =c = =C =fjkpfq = = = =@ *.Dt\^  M  M3  Mc  M  Mcghsct  M  M  M  MD -1tRV_a  M  Mc  M  MC  Mfjkvfw  M  M  M  MD (,$TZ\  ?  ?  ?C  ?s  ?aefqar  ?  ?  ?  ?DR
 R
T R
X R
Q\ R
 R
 R
 R
h:s : : : :3 3 3  t x ;    .	 	 	 ;?r 9I 9Ic 9IC 9I 9I 9I 9Iv [] 3 3S 3% 3c 3c 3an 3 3 3 38
 
t 
x 
= 
 
 
 
 24 5 5S 5 5 5 5 5. 26b P Pw PT(^ P P P P$i it iV i i i iV 26b 0B 0Bw 0BY 0B 0B 0B 0Bd 24 $1 $1S $1 $1 $1 $1 $1L	
 	
t 	
V 	
x 	
 	
 	
 	
 9=R  S #    B =A 0 0S 0	 0PU 0 0 0 0@ 154VZce (= (=# (=S (=PS (=jnotju (= (= (= (=T 57 4 4 4: 4 4 4 42
 
D 
& 
J 
 
 
 
 >B" 4 4# 4s 4 4 4 4@ 15R 
 
# 
 
 
 
6 =A T T Tc T T T T2 ;?r +3 +3 +3dSVi +3 +3 +3 +3Z$
 $
4 $
 $
3 $
 $
 $
 $
Lc 3 S # X\ dg    @ &eBSW P P P P P P P PrY  r+   )0ccxt.base.exchanger   ccxt.abstract.blofinr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr    r!   r"   r#   r$   r%   r&   r'   ccxt.base.decimal_to_precisionr(   ccxt.base.preciser)   r+    rY  rX  <module>r     s   ( ' ' ' ' ' , , , , , ,  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]       * * * * * * 0 0 0 0 0 0 . . . . . . ' ' ' ' ' ' . . . . . . ) ) ) ) ) ) . . . . . . 1 1 1 1 1 1 4 4 4 4 4 4 % % % % % %Q'P Q'P Q'P Q'P Q'PX{ Q'P Q'P Q'P Q'P Q'PrY  