
    !:hʺ                    ,   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 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.y)    )Exchange)ImplicitAPIN)Any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                   6    e Zd Zdef fdZi fdee   fdZdedefdZ	di fde
dedefd	Zd_d
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d_dededefdZddi fde
dededee   fdZd_dedefdZdddi fde
dededee   fdZdddi fdededefdZd_dedefdZi fde
defdZd Z d Z!d Z"d_d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,d_d'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d/Z4dddi fdedededee   fd0Z5dddi fd1edededee6   fd2Z7dddi fd1edededee6   fd3Z8dddi fd1edededee9   fd4Z:d_d5ed6e;de6fd7Z<d%efd8Z=d9 Z>d_d:ed6e;de9fd;Z?d< Z@di fdefd=ZAi fd1e
d"e)d>e
d?e
deBf
d@ZCd_dAed6e;deBfdBZDi fde
deEfdCZFdi fdedeeE   fdDZGd_dEedefdFZHdi fdedeIfdGZJi fde
deKfdHZLd_dIededeKfdJZMdi fdIedefdKZNdi fde
d!e(de-fdLZOdddi fdedededee-   fdMZPi fde
deQfdNZRd_dOededeQfdPZSdi fdOe
defdQZTdi fdefdRZUdi fdSeVdefdTZWdUeXdVe
dWe
dXe
dYedZe
fd[ZYd\d]i ddfd^ZZ xZ[S )`blofinreturnc                 b	   | j                  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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| j	                  d      | j	                  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da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fetchPositionModefetchPositions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  )	sandboxrH   rI   r}   r   r   r   r\   r~   default)r   triggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfithedged)extendsrH   )r   pricer   forDerivatives)linearinverse)r   r9   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;   r0  r<   r1  r2  r9   accountsById)r0  r/  r1  r2  r9   defaultNetworkERC20defaultNetworksBTCTRC20)ETHr7  USDTnetworksBitcoinBSC)r7  BEP20r5  r8  )r   r   r   r   5Mr   r   r   timezoneUTCmethodprivateGetAccountPositionsprivatePostTradeOrder!createMarketBuyOrderRequiresPricedefaultTypeprivateGetAssetBillsprivateGetTradeOrdersPending!privatePostTradeCancelBatchOrdersprivateGetTradeOrdersHistory)r   pwdSPOTSWAP)r9   r;   rL  rM  )r\   r   exchangeType)deep_extendsuperr*   describeparse_numberr"   r    r   r%   r$   r#   r&   r'   )self	__class__s    E/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/blofin.pyrQ  zblofin.describe   s   fd < > QA
(QA
HQA
 $QA
 t	QA

 QA
 4QA
  rrr %r 	r
 %r %r Ur r "5r tr r $Ur  r 'r /r  0!r" t#r$ %r& 7'r( &u)r* (+r, '-r. &t/r0 (1r2 "53r4 (5r6 %d7r8 U9r:  ;r< =r>  ?r@ &uArB +ECrD )%ErF &uGrH #EIrJ $TKrL 'MrN (OrP "5QrR SrT &uUrV (WrX 1%YrZ  [r\ +E]r^ *:_r` +Earb &tcrd #Derf *4grh $Uirj ukrl "5mrn *5orp +Eqrr #Esrt turv #Dwrx  yrz !${r| %e}r~ "4r@ #EArB +ECrD ErF !%GrH +EIrJ  KrL dMrN $UOrP +EQrR !$SrT "4UrV dWrX !$YrZ "5[r\ u]r^ #D_r`  arb $Tcrd !$erf *5grh %eirj )%krl )%mrn uorp tqrr srt Uurv twrx "5yrz #E{r| %e}r~ &ur@ 'ArB $UCrD  ErF !%GrH (IrJ )%KrL "5MrN %),1 %$)#"!%#' !crQA
t uQA
V (WQA
X i8 E N $ 00YQA
v ./*+())**+-./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wQA
L !..y9!..y9MQA
X " $YQA
b $ $(#'"&#(	( %*27+0/4$)#($ r% ',!$$*%+*/& #'&+!$#'$)*/( $(&+!%$*,-%+#'$)*/	*  #[0d  )&+(-,0,1).+06:"'	$  )&*(-,0,1)-+/04%)7 #'$#$ "#3  $	 ##kYcQA
V
 +:+.+ =+ :	+
 :+ :+ ,+ 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W
QA
z +{QA
@ YAQA
B  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CQA
 Q Q	    c                 l    | j                  |      }| j                  |dg       }| j                  |      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)rS  paramsresponserX  s       rU  fetch_marketszblofin.fetch_markets  s7     226:~~h3!!$''rV  marketc                    | j                  |d      }| j                  |d      }|dk(  }|dk(  }|dk(  }|dk(  }|xs |}| j                  |d      }	| j                  |d      }
| j                  |d      }| j                  |      }| j                  |	      }| j                  |
      }|d	z   |z   }|r|d
z   |z   }d }d }d }| j                  |d      }| j                  | j                  |di       }| j                  |d      }| j                  |d      }| j                  |dd      }t        j                  |d      }| j                  |d      dk(  }| j                  i d|d|d|d|d|	d|
d|d|d|d|d|d|xr t        j                  |d      d|d|d|d|d|||r|
|k(  nd |r|	|k(  nd |r| j                  |d      nd ||||| j                  |d       | j                  |d!      | j                  |      d"| j                  d      | j                  |      d#| j                  |d$      d d#d d d#d d d#d%|d&      S )'NinstIdinstTyper9   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   rz  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_integerrR  )rS  r_  r-   ru  r9   r<   r;   r=   r~  rq  rr  rt  rs  ro  rp  rn  r  strikePricer  rg  r   r   r   ri  isActives                            rU  parse_marketzblofin.parse_market  s@   fh/%%fj9("(">6!!&.9""6?;##FO<((2&&v.''0e#c\F*F
##FJ7		4B?  w/  w/&&v}eD((c:$$VW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 1+s C2+
 D2+
 f2+
 h2+
  U!2+
" U#2+
$ !/7w(*T/7(*TIQD,,V_EW[$!$((<**69=**84  ,,S1,,[9
  ++FI>
  
  $ c2+
 2 2	rV  Nrn  r   c                 D   | j                          | j                  |      }d|d   i}|dn|}|||d<   | j                  | j                  ||            }| j	                  |dg       }| j                  |di       }| j                  |d      }	| j                  |||	      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
        ra  r-   2   sizerX  r   ts)load_marketsr_  publicGetMarketBooksextendrZ  	safe_dictr  parse_order_book)
rS  rn  r   r\  r_  requestr]  rX  first	timestamps
             rU  fetch_order_bookzblofin.fetch_order_bookI  s     	V$fTl
 }5#GFO,,T[[&-IJ, ~~h3tQ+%%eT2	$$UFI>>rV  tickerc           
         | j                  |d      }| j                  |d      }| j                  ||d      }|d   }| j                  |d      }| j                  |d      }| j                  |dd      }|r| j                  |d	      nd }	| j                  |d
      }
| j                  |d      }| j                  |d      }| j	                  i d|d|d| j                  |      d|d|d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      dd d|d|d|dd dd dd dd |
|	| j                  |d       | j                  |d!      |d"|      S )#Nr  ra  -rn  lastopen24hr9   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)rS  r  r_  r  marketIdrn  r  r  r9   r  r  r  r  s                rU  parse_tickerzblofin.parse_tickerw  s   ( %%fd3	##FH5!!(FC8!/	2~~ffe4DHd&&v/?@d%%fh7
	2vx0 !
f!
!
 Y/!
 D	!

 3!
 4##FJ7!
 ))&)<!
 4##FJ7!
 ))&)<!
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&**6<@))&+>-!
. / 	rV  c                    | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j                  |di       }| j                  ||      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>`
        ra  r-   rX  r   )r  r_  publicGetMarketTickersr  rZ  r  r  rS  rn  r\  r_  r  r]  rX  r  s           rU  fetch_tickerzblofin.fetch_ticker  s     	V$fTl
 ..t{{7F/KL~~h3tQ+  //rV  c                    | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j                  |di       }| j                  ||      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>`
        rn  r-   rX  r   )r  r_  publicGetMarketMarkPricer  rZ  r  r  r  s           rU  fetch_mark_pricezblofin.fetch_mark_price  s     	V$fTl
 00Wf1MN~~h3tQ+  //rV  symbolsc                     | j                          | j                  |      }| j                  |      }| j                  |dg       }| j	                  ||      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>`
        rX  )r  market_symbolsr  rZ  parse_tickers)rS  r  r\  r]  tickerss        rU  fetch_tickerszblofin.fetch_tickers  sU     	%%g...v6..626!!'733rV  tradec                    | j                  |d      }| j                  |d      }| j                  ||d      }|d   }| j                  |d      }| j                  |dd      }| j                  |dd	      }| j                  |d
      }	| j                  |d      }
| j                  |d      }d }|||d   d}| j	                  ||| j                  |      |||
d d |	||d |d|      S )NtradeIdra  r  rn  r  r   	fillPricer  fillSizesideorderIdfeers  r}  currency)r  r  r  rn  r-   orderru  takerOrMakerr  r   rz  r}  r  )r  r  r  safe_string_2
safe_trader  )rS  r  r_  r-   r  rn  r  r   rz  r  r  feeCostr  s                rU  parse_tradezblofin.parse_trade  s    8 eY/##E84!!(FC8!%%eT2	""5';?##E6:>v.""5)4""5%0"8,C "Y/  
  	rV  sincec                    | j                          d}| j                  |dd      \  }}|r| j                  d||||dddd	      S | j                  |      }d|d	   i}d}|||d
<   d}	| j                  |ddd      \  }	}|	dk(  r!| j	                  | j                  ||            }| j                  |dg       }
| j                  |
|||      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  afterNr5   ra  r-   r   rB  publicGetMarketTradesrX  )r  handle_option_and_paramsfetch_paginated_call_cursorr_  r  r  rZ  parse_trades)rS  rn  r  r   r\  r  r_  r  r]  rB  rX  s              rU  fetch_tradeszblofin.fetch_trades$  s     	88PZ[&33M65RWY_ajlsuy{~V$fTl
 $GG66v}hXop,,11$++gv2NOH~~h3  vue<<rV  c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr   r               )r  r  )rS  ohlcvr_  s      rU  parse_ohlcvzblofin.parse_ohlcvD  sn     eQ'UA&UA&UA&UA&UA&
 	
rV  r   c           	         | j                          | j                  |      }d}| j                  |dd      \  }}|r| j                  d|||||d      S |d}|d   | j	                  | j
                  ||      |d}| j                  |d      }	|	|	|d	<   | j                  |d      }d}
| j                  | j                  ||            }
| j                  |
d
g       }| j                  |||||      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  r5   Nr-   )ra  barr   untilr  rX  )r  r_  r  "fetch_paginated_call_deterministicr  r   r  omitpublicGetMarketCandlesr  rZ  parse_ohlcvs)rS  rn  	timeframer  r   r\  r_  r  r  r  r]  rX  s               rU  fetch_ohlcvzblofin.fetch_ohlcv[  s    	V$88zZ&::<QVX]_hjpruvv=ETl##DOOY	J

 !!&'2$GGYYvw/F..t{{7F/KL~~h3  vy%GGrV  c           
         |t        | j                  dz         | j                          d}| j                  |dd      \  }}|r| j	                  d|||d|      S | j                  |      }d|d   i}|t        |dz
  d	      |d
<   |||d<   | j                  | j                  ||            }g }	| j                  |dg       }
t        d	t        |
            D ]R  }|
|   }| j                  |d      }|	j                  ||d   | j                  |d      || j                  |      d       T | j!                  |	d      }| j#                  ||d   ||      S )av  
        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)
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
        z5 fetchFundingRateHistory() requires a symbol argumentFrk   r  r   ra  r-   r   r   beforer   rX  fundingTimern  fundingRate)r  rn  r  r  r  r  )r!   r-   r  r  r  r_  r   !publicGetMarketFundingRateHistoryr  rZ  rangelenr  appendr  r  sort_byfilter_by_symbol_since_limit)rS  rn  r  r   r\  r  r_  r  r]  ratesrX  irater  sorteds                  rU  fetch_funding_rate_historyz!blofin.fetch_funding_rate_history  s    >#DGG.e$eff88AZ\fg&::;TV\^cejlprxyyV$fTl
  #EAIq 1GH$GG99$++gv:VW~~h3q#d)$ 		A7D))$>ILL *#//mD& LL3 		 e[1009I5RWXXrV  c                 <   | j                  |d      }| j                  ||      }| j                  |d      }i d|d|dd dd d| j                  d      d	d d
d dd d| j	                  |d      d|d| j                  |      dd dd dd dd dd dd dd iS )Nra  r  r  rn  r  r  interestRate0estimatedSettlePricer  r  r  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r  safe_symbolr  rR  r  r  )rS  r~  r_  r  rn  r  s         rU  parse_funding_ratezblofin.parse_funding_rate  s9    ##Hh7!!(F3''-@
H
f
 
 $	

 D--c2
 #D
 
 
 4++HmD
 
 t||K8
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 	
rV  c                 >   | j                          | j                  |      }|d   st        | j                  dz         d|d   i}| j	                  | j                  ||            }| j                  |dg       }| j                  |di       }| j                  ||      S )aP  
        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 marketsra  r-   rX  r   )	r  r_  r   r-   publicGetMarketFundingRater  rZ  r  r  )rS  rn  r\  r_  r  r]  rX  entrys           rU  fetch_funding_ratezblofin.fetch_funding_rate  s     	V$f~*^ ^__fTl
 224;;w3OP ~~h3tQ+&&uf55rV  c                     | j                  |d      }|!t        |t              r| j                  |      S | j	                  |      S )NrX  )rZ  
isinstancelistparse_funding_balanceparse_balance)rS  r]  rX  s      rU  parse_balance_by_typezblofin.parse_balance_by_type  sC    ~~h/*T4"8--h77%%h//rV  c                 6   d|i}| j                  |di       }| j                  |d      }| j                  |dg       }t        dt	        |            D ]  }||   }| j                  |d      }| j                  |      }	| j                         }
| j                  |d      }| j                  |d      }||+| j                  |d	      |
d
<   | j                  |d      |
d<   n
||
d<   ||
d
<   |
||	<    ||d<   | j                  |      |d<   | j                  |      S )Nr  rX  r  detailsr   r  equity	availableavailableEquityfreefrozenusedtotalr  r  )
r  r  rZ  r  r  r  r  accountr  safe_balance)rS  r]  resultrX  r  r%  r  balance
currencyIdcoder-  eqavailEqs                rU  r"  zblofin.parse_balance  s:   > )~~h3%%dD1	..y"5q#g,' 	#AajG))':>J**:6DllnG!!'84B&&w<G
"&"2"27<M"N"&"2"27H"E#% ")"F4L	# ({!\\)4z  ((rV  c                 ~   d|i}| j                  |dg       }t        dt        |            D ]~  }||   }| j                  |d      }| j	                  |      }| j                         }| j                  |d      |d<   | j                  |d      |d<   | j                  |d	      |d
<   |||<    | j                  |      S )Nr  rX  r   r  r0  r,  r'  r)  r*  r+  )rZ  r  r  r  r  r-  r.  )	rS  r]  r/  rX  r  r0  r1  r2  r-  s	            rU  r!  zblofin.parse_funding_balance-  s      )~~h3q#d)$ 		#A1gG))':>J**:6DllnG#//CGG"..wDGFO"..wAGFO"F4L		#   ((rV  r  c                     || j                  d |      | j                  t        j                  | j	                  |dd                  | j                  t        j                  | j	                  |dd                  d d dS )Nr   makerUr   takerU)r  rn  r   r   r  	tierBased)r  rR  r(   
string_negr  )rS  r  r_  s      rU  parse_trading_feezblofin.parse_trading_feeK  sy    &&tV4&&w'9'9$:L:LSRY[c:d'ef&&w'9'9$:L:LSRY[c:d'ef
 	
rV  c                 |   | j                          d}| j                  |ddd      \  }}i }d}|\|dk7  rW| j                  | j                  di       }| j	                  |||      }||d<   | j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |      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>`
        NrU   accountTyperu  r;   r.  )	r  handle_option_and_params_2r  r+  r  privateGetAssetBalancesr  privateGetAccountBalancer#  )rS  r\  r=  r  r]  r+  parsedAccountTypes          rU  fetch_balancezblofin.fetch_balanceV  s     	"==fnVceklV
"{f'<nnT\\3CRHG $ 0 0+{ S%6GM"33DKK4PQH44T[[&5QRH))(33rV  ru  r  rz  r   c           	      t   | j                  |      }|d   ||| j                  ||      | j                  | j                  dd      d}d }	| j	                  d|d      \  }	}|	|d<   | j                  |d      }
| j                  |d	d
      }| j                  |dd      }|r|dk(  rdnd|d<   |dk(  }| j                  |d	g      }|dk(  xs |dk(  }|xr |}|s|rd|d<   n|
dnd}| j                  ||      ||<   d}| j                  ||dk(  |      \  }}|rd|d<   | j                  |d      }| j                  |d      }| j                  |g d      }|d u}|d u}|s|r|rP| j                  |dd      }| j                  ||      |d<   | j                  |dd      }| j                  ||      |d<   |rt| j                  |dd      }| j                  ||      |d <   | j                  |dd      }| j                  ||      |d!<   n#|
!d"|d<   | j                  ||
      |d<   |rd|d<   | j                  ||      S )#Nr-   r,  r-  )ra  r  	orderTyper  r,  rH   crossr   r   r   GTCr   FbuylongshortpositionSider_  r   iocrD  
orderPricer   	post_onlyru  stopLoss
takeProfit)rN  rO  r   	stopPriceslTriggerPrice-1slOrderPricetpTriggerPricetpOrderPricer   )r_  amount_to_precisionr  r+  handle_margin_mode_and_paramsr  r  price_to_precisionhandle_post_onlyr  r  r  )rS  rn  ru  r  rz  r   r\  r_  r  r   r   r   isHedgedisMarketOrderrK  	marketIOCkeypostOnlyrN  rO  
isStopLossisTakeProfitrQ  rS  rT  tpPrices                             rU  create_order_requestzblofin.create_order_requestp  s   V$Tl,,VV<((zCUV
 
!??vW^_
F *''?&&v}eD>>&(E:15fWGN#(6M?3e#7"*s	I#+GK #/#;,'C2265AGCL00@SU[\&)GFO>>&*5^^FL9
6#GHT)
!-!%!3!3Hnk!Z,0,C,CFN,[()#//'4H*.*A*A&,*W'!%!3!3JP[!\,0,C,CFN,[()**:wE*.*A*A&'*R'%#,GK &*&=&=fl&SGN#(,%{{7F++rV  statusc                 :    ddddddd}| j                  |||      S )Ncanceledr  closed)re  order_failedrm  partially_filledfilled	effectiver  rS  rc  statusess      rU  parse_order_statuszblofin.parse_order_status  s2    "& &!
 &&99rV  r  c                    | j                  |g d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }d }	d }
|dk(  rd}	d	}n|d
k(  rd}
d	}n	|dk(  rd}
d	}| j                  |d      }| j                  ||      }| j	                  ||d      }| j                  |d      }| j                  |dd      }| j                  |d      }| j                  | j                  |d            }| j                  |d      }| j                  |d      }| j                  |dd      }| j                  |d      }t        j                  ||      }d }|,t        j                  ||      }t        j                  ||      }d }|Mt        j                  |      }| j                  |dd      }| j                  |      }| j                  |      |d}| j                  |d      }|t        |      dk  rd }| j                  |d      }| j                  |d       }| j                  |d!      }| j                  |d"      }| j                  |d#      } | d$k(  }!| j                  i d%|d&|d|d'|d(| j!                  |      d)|d*|d+|d,|d-|
d.|	d|d|d/|d0|d1|d2|||||d ||d |!d3	|      S )4N)tpslIdr  algoId
createTime
updateTimefillTimer  rD  rM  Tr   fokr   rK  r   ra  r  
filledSizepxr   averagePricerl  r  r  r   rk  r  feeCcyr:  r  clientOrderIdr   rQ  rS  rT  rU  
reduceOnlytruer  r-   r  r  lastTradeTimestamplastUpdateTimestamprn  ru  r   r^  stopLossTriggerPricetakeProfitTriggerPricer   r   )	r  r}  rz  ri  	remainingrc  r  tradesr{  )safe_string_nr  r  r  r  r  rn  r(   
string_mul
string_div
string_absr  rR  r  r  
safe_orderr  )"rS  r  r_  r-   r  r~  r}  r  ru  r^  r   r  rn  ri  r   r  rc  feeCostStringrz  r   r  
baseAmountr}  r  feeCostSignedfeeCurrencyIdfeeCurrencyCoderz  r  r   r  r   reduceOnlyRawr{  s"                                     rU  parse_orderzblofin.parse_order  s   H 'FG%%e\:	"//|D!..ujAv.{3;HDU]KDU]KD##E84!!(F3!!(FC8!!%6""5$8""5.9(()9)9%)IJ((6!!%0##E:s;''?''f=
%%gz:D%%dH5D$#..}=M ,,UHfEM"55mDO))-8+C ((@%C,>,B M#//7GH((?!%!1!1%9I!J**5.A((=#v-
  
E 
" 
 ] 
 	 

 Y/ 
 !"4 
 "#6 
 f 
 D 
 ; 
  
 D 
 U 
 #$8 
 %&< 
  ]! 
" # 
$ $5 
6 7 	rV  c                 r   | j                          | j                  |      }| j                  |dd      }| j                  |d      }d}	| j	                  |ddd      \  }	}| j                  |d      du}
| j                  |d      du}| j                  |d	      du}|
xs |}d}| j                  |d
      }|	|rdnd|d
<   |s|	dk(  s|r(| j                  ||||||      }| j                  |      }nV|s|	dk(  r(| j                  ||||||      }| j                  |      }n'| j                  ||||||      }| j                  |      }|s|	dk(  r'| j                  |di       }| j                  ||      }|S | j                  |dg       }| j                  |d      }| j                  ||      }||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>`
        tpslFNrH   rB  rD  r   r   r   r{  r|  falseprivatePostTradeOrderTpslprivatePostTradeOrderAlgorX  r   ru  r  )r  r_  r  r  r  r  create_tpsl_order_requestr  rb  r  rD  r  r  rZ  )rS  rn  ru  r  rz  r   r\  r_  r  rB  isStopLossPriceDefinedisTakeProfitPriceDefinedisTriggerOrderisType2Orderr]  r{  tpslRequesttriggerRequestr  dataDicttriggerOrderrX  r  r  s                           rU  create_orderzblofin.create_order%  s   < 	V$~~ffe466*66v}hXop!%!1!1&/!JRV!V#'#3#3F<M#NVZ#Z ))&.AM.J2J^^FL9
!-76WF< F99l88tVUZ\bcK55kBH*E E!66vtT6SXZ`aN55nEH//dFESYZG11':Hf(CC~~h;H++Hf=L~~h3tQ'  /ffrV  c                    | j                  |      }| j                  |dd      }|d   ||| j                  | j                  dd      d}	|| j                  ||      |	d<   | j                  |dd	      }
|
d	k7  r|
d
k7  rt	        | j
                  dz         | j                  |d      }| j                  |d      }|6| j                  ||      |	d<   |dk(  rd|	d<   nM| j                  ||      |	d<   n7|5| j                  ||      |	d<   |dk(  rd|	d<   n| j                  ||      |	d<   |
|	d<   | j                  |ddg      }| j                  |	|      S )NrJ  netr-   r,  r-  )ra  r  rJ  r,  r  r   rE  isolatedzX createTpslOrder() requires a marginMode parameter that must be either cross or isolatedr   r   rQ  r_  rR  rS  rT  rU  )	r_  r  r+  rV  r"   r-   rX  r  r  )rS  rn  ru  r  rz  r   r\  r_  rJ  r  r   r   r   s                rU  r  z blofin.create_tpsl_order_requeste  s   V$''FTl(((zCUV	
 "66vvFGFO%%flGD
 Z:%=TWW  (B  B  C  C((A**63DE$(,(?(?(VG$%x*.'*.*A*A&%*P'((,(?(?(XG$%x*.'*.*A*A&%*P' *6O5F#GH{{7F++rV  r-   c                 ,   |t        | j                  dz         | j                          | j                  |      }d|d   i}| j	                  |dgd      }| j                  |ddd      }| j                  |d      }|||d<   n4|s|st        |      |d	<   n!|rt        |      |d
<   n|rt        |      |d<   | j                  |g d      }	|r(| j                  |g||      }
| j                  |
d      }|S |rE| j                  | j                  ||	            }| j                  |d      }| j                  ||      S | j                  | j                  ||	            }| j                  |dg       }| j                  |d      }| j                  ||      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>`
        z) cancelOrder() requires a symbol argumentra  r-   r   Fr  TPSLrz  r  rp  rq  )r  rz  stopr   r  r   rX  )r!   r-   r  r_  safe_bool_nsafe_bool_2r  strr  cancel_ordersr  privatePostTradeCancelAlgor  r  privatePostTradeCancelOrderrZ  )rS  r-   rn  r\  r_  r  	isTriggerisTpslrz  querytpslResponser  triggerResponsetriggerDatar]  rX  r  s                    rU  cancel_orderzblofin.cancel_order  s    >#DGG.Y$YZZV$fTl
 $$Vi[%@	!!&&&%@((A$'4GO$V%(W	"$'G!$'G!		&"YZ--rdFFCLNN<3EL"==dkk'SX>YZO..&AK##K8833DKK4OP~~h3tQ'v..rV  ordersc           	         | j                          g }t        dt        |            D ]  }||   }| j                  |d      }| j                  |d      }| j                  |d      }| j	                  |d      }	| j	                  |d      }
| j                  |di       }| j                  ||      }| j                  ||||	|
|      }|j                  |        | j                  |      }| j                  |dg       }| j                  |      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   rn  ru  r  rz  r   r\  rX  )r  r  r  r  
safe_valuer  r  rb  r  privatePostTradeBatchOrdersrZ  parse_orders)rS  r  r\  ordersRequestsr  rawOrderr  ru  r  rz  r   orderParamsextendedParamsorderRequestr]  rX  s                   rU  create_orderszblofin.create_orders  s    	q#f+& 
	0AayH''(;H##Hf5D##Hf5D__Xx8FOOHg6E..8R@K![[f=N44XtT6SXZhiL!!,/
	0 33NC~~h3  &&rV  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||      S i }d}|| j                  |      }|d   |d<   |||d<   | j	                  |dd	gd      }| j                  |d
dd      }	d}
| j                  |ddd      \  }
}| j                  |g d      }d}|	s|
dk(  r"| j                  | j                  ||            }nO|s|
dk(  r'd	|d<   | j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |dg       }| j                  ||||      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-   ra  r   r  r   r  r  rB  rH  rB  r  r   r  r   privateGetTradeOrdersTpslPending privateGetTradeOrdersAlgoPendingrD  rX  )r  r  fetch_paginated_call_dynamicr_  r  r  r  r  r  r  rH  rZ  r  )rS  rn  r  r   r\  r  r  r_  r  isTpSlrB  r  r]  rX  s                 rU  fetch_open_orderszblofin.fetch_open_orders  s     	88ART^_&445FPUW\^dee
[[(F &tGH$GG$$Vfi-@%H	!!&&&%@66v?PRZ\z{		&"OPf BB<<T[[RW=XYH6%GG#,GK <<T[[RW=XYH88We9TUH~~h3  vue<<rV  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||      S i }d}|| j                  |      }|d   |d<   | j	                  d||      \  }}|||d<   | j                  | j                  ||            }| j                  |d	g       }	| j                  |	|||      S )
a9  
        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-   ra  endr   rX  )	r  r  r  r_  handle_until_optionprivateGetTradeFillsHistoryr  rZ  r  )
rS  rn  r  r   r\  r  r  r_  r]  rX  s
             rU  fetch_my_tradeszblofin.fetch_my_trades  s     	88R\]&44_feUZ\bcc
[[(F &tGH225'6J$GG33DKK4PQ~~h3  vue<<rV  r2  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||      S i }d}|| j                  |      }|d   |d<   |t	        |dz
  d      |d	<   |||d
<   | j                  d||      \  }}| j                  | j                  ||            }| j                  |dg       }	| j                  |	||||      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>`
        Frd   r  Nr-   r  r   r   r  r   r  rX  )
r  r  r  r  r   r  privateGetAssetDepositHistoryr  rZ  parse_transactions
rS  r2  r  r   r\  r  r  r  r]  rX  s
             rU  fetch_depositszblofin.fetch_deposits  s    	88R\]&44_dESXZ`aa
}}T*H"*4.GJ #EAIq 1GH$GG227GVL55dkk'66RS~~h3&&tXueVLLrV  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||      S i }d}|| j                  |      }|d   |d<   |t	        |dz
  d      |d	<   |||d
<   | j                  d||      \  }}| j                  | j                  ||            }| j                  |dg       }	| j                  |	||||      S )aI  
        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  rX  )
r  r  r  r  r   r   privateGetAssetWithdrawalHistoryr  rZ  r  r  s
             rU  fetch_withdrawalszblofin.fetch_withdrawals>  s    	88ASU_`&445GuV[]cdd
}}T*H"*4.GJ #EAIq 1GH$GG227GVL88Wf9UV~~h3&&tXueVLLrV  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||      S i }|||d<   d}|| j                  |      }|d   |d<   | j	                  d||      \  }}d}| j                  | j                  ||            }| j                  |d	g       }	| j                  |	|||      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>`
        Frr   r  Nr   r-   r  r  rX  )	r  r  r  r  r  rG  r  rZ  parse_ledgerr  s
             rU  fetch_ledgerzblofin.fetch_ledger`  s     	88PZ[&44]D%QVX^__
$GG}}T*H"*4.GJ225'6J,,T[[&-IJ~~h3  x>>rV  transactionr  c                    d }d }| j                  |d      }| j                  |d      }| j                  |d      }|}| j                  |d      }	|d}|}n|}d}| j                  |d      }
| j                  |
      }| j                  |d      }| j                  | j                  |d	            }| j                  |d
      }| j	                  |d      }| j                  |d      }| j                  |      }| j                  |d      }i d|d|d|d|dd dd d|d|dd d|	d|	d|d|dd d|d|d| j                  |      d d ||ddS )N
withdrawId	depositIdaddresstag
withdrawaldepositr  rz  rl  txIdr  feeCurrencyr  r  r-   networkaddressFrom	addressTotagFromtagTorc  ru  updatedtxidr  r  )r  r}  )internalcommentr  )r  r  r  parse_transaction_statusr  r  )rS  r  r  ru  r-   withdrawalIdr  r  r  r  r1  r2  rz  rc  r  r  r  feeCoder  s                      rU  parse_transactionzblofin.parse_transaction  s   H ''\B$$[+>	$$[)<	  e4#DBBD%%k:>
&&z2!!+x8..t/?/?W/UVV4%%k48	((mD))-8"";6
K
"
 
 f	

 t
 4
 
 w
 t
 U
 5
 f
 D
 t
 D
  !
" Y/#
$ #)
 	
rV  c                 6    ddddd}| j                  |||      S )Npendingokfailed)r  rk  23rk  rl  s      rU  r  zblofin.parse_transaction_status  s,    	
 &&99rV  c                 D    dddddddddddd}| j                  |||      S )Nr   r  rebater  )rk  r  r  4567891011rk  )rS  ru  typess      rU  parse_ledger_entry_typezblofin.parse_ledger_entry_type  sA    
 tT22rV  itemc                    | j                  |d      }| j                  ||      }| j                  ||      }| j                  |d      }| j	                  || j                  |d      d d | j                  |d      d | j                  | j                  |d            || j                  |d      || j                  |      d d dd d|      S )	Nr  r  
transferIdclientIdru  rz  r  )r  r-   	directionr-  referenceIdreferenceAccountru  r  rz  r  r  r  r  rc  r  )r  r  safe_currencyr  safe_ledger_entryr  r  r  )rS  r  r  r1  r2  r  s         rU  parse_ledger_entryzblofin.parse_ledger_entry  s    %%dJ7
&&z8<%%j(;%%dD1	%%""46++D*= $001A1A$1OP&&tX6"Y/'
  ! 	rV  c                 H    t        |t              r|j                  d      S |S )zg
 @ignore
        :param string[]|str ids: order ids
        :returns str[]: list of order ids
        ,)r  r  split)rS  idss     rU  	parse_idszblofin.parse_ids  s!     c399S>!JrV  c                    |t        | j                  dz         | j                          | j                  |      }g }| j	                  | j
                  di       }| j                  |dd      }| j                  |d|      }| j                  | j                  |d            }	| j                  | j                  |d            }
| j                  |g d      }|rd	}|	| j                  |      }|
4t        d
t        |
            D ]  }|j                  |
|   |d   d        t        d
t        |            D ]9  }|r|j                  ||   |d   d        |j                  ||   |d   d       ; n4t        d
t        |	            D ]  }|j                  |d   |	|   d        d}|d	k(  r| j                  |      }n| j                  |      }| j                  |dg       }| j!                  ||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 argumentrB   rB  rI  rz  rp  )r  r   r  privatePostTradeCancelTpslr   r-   )rp  ra  )r  ra  )ra  rz  rX  )r!   r-   r  r_  r  r+  r  r
  r  r  r  r  r  r  rI  rZ  r  )rS  r	  rn  r\  r_  r  r+  defaultMethodrB  clientOrderIdstpslIdsr   r  r]  
ordersDatas                  rU  r  zblofin.cancel_orders  s    >#DGG.Z$Z[[V$..~rB(((<_`!!&(MB(PQ..!BC""6+FG1F!..%C"q#g,/ ANN")!*"(,$ 
 1c#h' 
NN"%a&"(,$ 
 NN#&q6"(,$ 
 1c.12 $Tl%3A%6  
 1166w?H==gFH^^Hfb9
  VT4HHrV  fromAccount	toAccountc                    | j                          | j                  |      }| j                  | j                  di       }| j	                  |||      }| j	                  |||      }	|d   | j                  ||      ||	d}
| j                  | j                  |
|            }| j                  |di       }| j                  ||      S )aJ  
        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>`
        r.  r-   )r  rz  r  r  rX  )	r  r  r  r+  r  currency_to_precisionprivatePostAssetTransferr  parse_transfer)rS  r2  rz  r  r  r\  r  r.  fromIdtoIdr  r]  rX  s                rU  r   zblofin.transferL  s     	==&6FK!!.+{K	9E 00v>!	
 00Wf1MN~~h3""422rV  r   c           
      >    | j                  |d      }||d d d d d d d d	S )Nr  )	r  r-   r  r  r  rz  r  r  rc  rk  )rS  r   r  r-   s       rU  r  zblofin.parse_transferh  s9    h5

 
	
rV  c                    | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j                  |d      }|y| j                  ||      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>`
        ra  r-   rX  r   N)r  r_  rC  r  rZ  r  parse_position)rS  rn  r\  r_  r  r]  rX  positions           rU  fetch_positionzblofin.fetch_positionv  s     	V$fTl
 224;;w3OP~~h3>>$*""8V44rV  c                     | j                          | j                  |      }| j                  |      }| j                  |dg       }| j	                  |      }| j                  |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>`
        rX  rn  F)r  r  rC  rZ  parse_positionsfilter_by_array_positions)rS  r  r\  r]  rX  r/  s         rU  fetch_positionszblofin.fetch_positions  si     	%%g.226:~~h3%%d+--fhOOrV  r  c                    | j                  |d      }| j                  ||      }|d   }| j                  |d      }t        j                  |      }| j                  |d      }|dk7  }| j	                  |      }	|9|dk(  r4t        j
                  |d      rd}nt        j                  |d      rd}nd }| j                  |d	      }
| j                  |
      }| j                  |d
      }| j                  |d      }|d   r*t        j                  t        j                  ||      |      }| j	                  |      }| j                  |d      }d }| j                  |d      }| j                  |d      }| j                  |d      }d }d }|dk(  r)| j                  |d      }t        j                  ||      }n-|dk(  r(t        j                  d|      }| j                  |d      }| j                  |d      }| j	                  |      }t        j                  ||      }|'| j	                  t        j                  ||d            }n|t        j                  ||      }d}| j	                  t        j                  t        j                  ||      dd            }| j                  |d      }| j                  |d      }| j	                  t        j                  |d            }| j                  |d      }| j	                  t        j                  ||d            }| j                  i d|dd d|d|d|d|d | j	                  |      d| j	                  |      d!|d"|	d	|
d
| j	                  |      d#d d$|d%|d&|d'| j                  |      d ||| j	                  |      | j	                  |      | j	                  |      | j	                  |      |d d d(
      S ))Nra  rn  	positionsrJ  r  r  rH  rI  r  r  notionalUsdr   r   rx  unrealizedPnlr   rE  initialMarginr  rk  r:   maintenanceMarginr  z0.00005liquidationPriceunrealizedPnlRatiorj  rs  r  r-   notional
entryPricer  	contracts	lastPricer  r   r  r  )
r~  r'  maintenanceMarginPercentage
collateralr&  initialMarginPercentager   marginRatior   r   )r  r  r(   r  rR  r  	string_ltr  number_to_stringr  r  
string_addr  safe_positionr  ) rS  r  r_  r  rn  poscontractsAbsr  r   r,  r  contractSizeStringmarkPriceStringnotionalStringr*  r   initialMarginStringentryPriceStringunrealizedPnlStringleverageStringr0  collateralStringmaintenanceMarginStringr'  !maintenanceMarginPercentageStringrounderr.  r(  percentageStringr  r  r1  s                                    rU  r  zblofin.parse_position  s   6 ##Hh7!!(F3!x5))#..9%%l3	?u}$$S#.!D&&sC0"DD''?!22<@**8[A))(MB)$//0B0B<Qc0dfuvN$$^4%%h=
"++HnE"..xI))(J?"& "&"2"28_"M&112EGZ[:%&-&8&8n&M##//(C"&"2"28=P"Q --.EF,3,>,>?VXf,g)"*&*&7&78J8JK^`npq8r&s# (")"4"45Ln"]&*&7&78J8J7K]K]^  BI  LJ  LO  QR  9S  'T#++H6HI++H6JK&&w'9'9:JE'RS
%%h=	''(:(:;RTdfg(hi!! #
H#
$#
 f#
 	#

 *#
  0#
 $++,<=#
 T../BC#
 *#
 #
 L#
 **?;#
 #
 D#
 f#
  !#
" Y/##
$ $(!2+F++,<=!../BC'+'8'89P'Q)).9&!#7#
  	rV  c                 B   | j                          |t        | j                  dz         d}| j                  d|      \  }}|| j	                  |dd      }|dk7  r|dk7  rt        | j                  dz         | j                  |      }d}t        d	t        |            D ]1  }||   }| j                  |      }|d	kD  r|d
z   |d   z   }*||d   z   }3 ||d}| j                  | j                  ||            }	| j                  |	dg       }
| j                  |
|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 argumentru   r   rE  r  zW fetchLeverages() requires a marginMode parameter that must be either cross or isolated r   r  r-   ra  r   rX  ra  )r  r!   r-   rW  r  r"   r  r  r  r_  "privateGetAccountBatchLeverageInfor  rZ  parse_leverages)rS  r  r\  r   instIdsr  r  entryMarketr  r]  	leveragess              rU  fetch_leverageszblofin.fetch_leverages
  sW    	?#DGG.]$]^^
!??@PRXY
F))&,HJ'!
j(@TWW  (A  A  B  B%%g.q#g,' 	6AAJE++e,K1u!C-+d*;;!K$55	6 $
 ::4;;wPV;WX NN8VR8	##IwAArV  c                 |   | j                          d}| j                  d|      \  }}|| j                  |dd      }|dk7  r|dk7  rt        | j                  dz         | j                  |      }|d   |d}| j                  | j                  ||            }| j                  |d	i       }| j                  ||      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>`
        Nrt   r   rE  r  zV fetchLeverage() requires a marginMode parameter that must be either cross or isolatedr-   rF  rX  )
r  rW  r  r"   r-   r_  privateGetAccountLeverageInfor  r  parse_leverage)rS  rn  r\  r   r_  r  r]  rX  s           rU  fetch_leveragezblofin.fetch_leverage<  s     	
!??QWX
F))&,HJ'!
j(@TWW'  A  AV$Tl$
 55dkk'66RS ~~h3""400rV  r   c                     | j                  |d      }| j                  |d      }|| j                  ||      | j                  |d      ||dS )Nra  r   r   )r  rn  r   longLeverageshortLeverage)r  r  r  r  )rS  r   r_  r  leverageValues        rU  rO  zblofin.parse_leverageb  sY    ##Hh7))(J?&&x800<H)*
 	
rV  c                    |t        | j                  dz         |dk  s|dkD  rt        | j                  dz         | j                          | j	                  |      }d}| j                  d|d      \  }}|dk7  r|dk7  rt        | j                  d	z         |||d
   d}| j                  | j                  ||            }|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   rE  r  zT setLeverage() requires a marginMode parameter that must be either cross or isolatedr-   )r   r   ra  )r!   r-   r"   r  r_  rW  privatePostAccountSetLeverager  )rS  r   rn  r\  r_  r   r  r]  s           rU  set_leveragezblofin.set_leveragem  s     >#DGG.Y$YZZ qLhnTWW'\\]]V$
!??vW^_
F'!
j(@TWW'}}~~ $Tl

 55dkk'66RSrV  c                    | j                          | j                  |      }| j                  |d      }d}| j                  d|d      \  }}|d   |d}|||d<   | j	                  | j                  ||            }| j                  |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>`
        rz  NrD   rE  r-   rF  rX  )r  r_  r  rW  privatePostTradeClosePositionr  r  )	rS  rn  r  r\  r_  rz  r   r  r]  s	            rU  close_positionzblofin.close_position  s    $ 	V$((A
!??QWY`a
FTl$
 $'4GO$55dkk'66RS~~h//rV  c                 D   | j                          d}| j                  |dd      \  }}|r| j                  d||||      S i }d}|| j                  |      }|d   |d<   |||d<   |||d<   | j	                  |g d	d      }d}	| j                  |d
dd      \  }	}| j                  |g d      }
d}|s|	dk(  r"| j                  | j                  ||
            }n!| j                  | j                  ||
            }| j                  |dg       }| j                  ||||      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-   ra  r   begin)r  r   r  r  r   rB  rJ  r   privateGetTradeOrdersTpslHistoryrX  )r  r  r  r_  r  r  r^  r  rJ  rZ  r  )rS  rn  r  r   r\  r  r  r_  r  rB  r  r]  rX  s                rU  fetch_closed_orderszblofin.fetch_closed_orders  sW    	88ATV`a&445H&RWY^`fgg
[[(F &tGH$GG$GG$$V-PRWX	66v?PRZ\z{		&"OP6%GG<<T[[RW=XYH88We9TUH~~h3  vue<<rV  c                     | j                          | j                  |      }| j                  |      }| j                  |di       }| j	                  ||      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>`
        rX  )r  r_  privateGetAccountMarginModer  parse_margin_mode)rS  rn  r\  r_  r]  rX  s         rU  fetch_margin_modezblofin.fetch_margin_mode  sU     	V$33F; ~~h3%%dF33rV  r   c                 N    || j                  |d      | j                  |d      dS )Nrn  r   )r  rn  r   rk  )rS  r   r_  s      rU  rb  zblofin.parse_margin_mode  s/    &&vx8**:|D
 	
rV  c                    | j                  d|dddg       | j                          d}|| j                  |      }d|i}| j                  | j	                  ||            }| j                  |di       }| j                  ||      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   rE  r  NrX  )check_required_argumentr  r_  privatePostAccountSetMarginModer  r  rb  )rS  r   rn  r\  r_  r  r]  rX  s           rU  set_margin_modezblofin.set_margin_mode  s     	$$_j,QXZdPef[[(F*
 77GV8TU ~~h3%%dF33rV  c                 ~    | j                  |      }| j                  |di       }| j                  |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
        rX  positionModelong_short_mode)r  r   )privateGetAccountPositionModer  r  )rS  rn  r\  r]  rX  rj  s         rU  fetch_position_modezblofin.fetch_position_mode	  sP     55f=~~h3''n= "&77
 	
rV  r   c                 T    d|rdndi}| j                  | j                  ||            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
        rj  rk  net_mode)!privatePostAccountSetPositionModer  )rS  r   rn  r\  r  s        rU  set_position_modezblofin.set_position_mode3	  s3     -Z
 55dkk'66RSSrV  httpCodereasonr   rB  headersbodyc
                    |y | j                  |d      }
| j                  |d      }| j                  dz   |z   }|
p|
dk7  rk| j                  | j                  d   ||       | j                  | j                  d   |
|       | j	                  | j                  d   ||       t        |      | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }|e|dk7  r`| j                  | j                  d   ||       | j                  | j                  d   ||       | j	                  | j                  d   ||       y )	Nr2  msg r  r'  r(  rX  r   )r  r-   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   rZ  r  )rS  rr  rs  r   rB  rt  ru  r]  requestHeadersrequestBodyr2  messagefeedbackrX  r  	insideMsg
insideCodes                    rU  handle_errorszblofin.handle_errorsL	  sX    &1""8U377S=4'001I7T\]001I4QYZ001I7T\])) ~~h/tQ'$$UE2	%%eV4
!jC&7001I:W_`001I9V^_001I9V^_rV  r   GETc                 n   d| j                   z   dz   | j                  ||      z   }| j                  || j                  |            }| j	                  | j
                  d   d         |z   }	|dk(  r+| j                  |      s.|	d| j                  |      z   z  }	n|dk(  r| j                          t        | j                               }
| j                  | j                  |
|
d}d	}|d
k(  r0| j                  |      sHd| j                  |      z   }|	|z  }	||z  }n)| j                  |      s| j                  |      }|}d|d<   ||z   |
z   |
z   |z   }| j                  | j                  | j!                  |      | j!                  | j"                        t$        j&                              }||d<   |	|||dS )Nz/api/re  r   r   r   ?r   )z
ACCESS-KEYzACCESS-PASSPHRASEzACCESS-TIMESTAMPzACCESS-NONCErE  r  zapplication/jsonzContent-TypezACCESS-SIGN)r   rB  ru  rt  )r2   implode_paramsr  extract_paramsimplode_hostnamer   is_empty	urlencodecheck_required_credentialsr  millisecondsr   r   jsonstring_to_base64hmacencoder   hashlibsha256)rS  pathr   rB  r\  rt  ru  r  r  r   r  	sign_bodyurlencodedQueryauth	signatures                  rU  signzblofin.signl	  s   DLL(3.1D1DT61RR		&$"5"5d";<##DIIe$4V$<=G(?=='sT^^E222I++-D--/0I"kk%)]]$- )	G I}}U+&)DNN5,A&AO?*C.G}}U+99U+D $I*<'V#i/);iGD--diiD8I4;;W[WbWbKceleses.tuI%.GM"fdwOOrV  )N)\__name__
__module____qualname__r   rQ  r   r   r^  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   rB  r   r   floatr   rb  rn  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   rL  r
   rP  rO  rX  r[  r_  r   rc  rb  rh  rm  boolrq  intr  r  __classcell__)rT  s   @rU  r*   r*      s   R# Rh $& ($v, (M4 MF M^ :>b ,?s ,?3 ,?Y ,?\64 6 66 6p 02 03 0f 0( 46 0s 0& 0* 04B 4W 47 4 : :v : :x 6:UW =3 =s =# =\`af\g =@
 
4 
. 26DW[df #H# #Hc #HQT #Hkoptku #HJ 8<$]ajl *Y *YC *YWZ *YX
6 
[ 
B 68 !6 !6K !6F04)l)<	
T 	
6 	
EX 	
 $& 4( 44 os{} 3,3 3,i 3,y 3,Z_ 3,hk 3,j	: 	:s sv s sj gksu >3 >i >y >RW >`c >z >@ 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3  Mc  M  Mcghsct  MD -1tRV_a  Mc  M  MC  Mfjkvfw  MD (,$TZ\  ?  ?C  ?s  ?aefqar  ?DR
T R
X R
Q\ R
h:s :3 t x ; .	 04B 9I 9Iv [] 3S 3% 3c 3c 3an 38
t 
x 
= 
 24 5S 5 5. 26b Pw PT(^ P$it iV iV 26b 0Bw 0BY 0Bd 24 $1S $1 $1L	
t 	
V 	
x 	
 9=R S # B =A 0S 0	 0PU 0@ 154VZce (=# (=S (=PS (=jnotju (=T 57 4 4: 42
D 
& 
J 
 >B" 4# 4s 4@ 15R 
# 
6 =A T Tc T2c 3 S # X\ dg @ &eBSW PrV  r*   )/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   typingr   ccxt.base.errorsr   r    r!   r"   r#   r$   r%   r&   ccxt.base.decimal_to_precisionr'   ccxt.base.preciser(   r*    rV  rU  <module>r     sm    ( ,  X  X  X  X  X  X  X  * 0 . ' . ) . 1 4 %t%PX{ t%PrV  