
    E#i7                    ,   S SK Jr  S SKJr  S SKrS SKJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJr  S SKJ r   S SK!J"r"  S SK!J#r#  S SK!J$r$  S S	K!J%r%  S S
K!J&r&  S SK!J'r'  S SK!J(r(  S SK!J)r)  S SK*J+r+  S SK,J-r-   " S S\\5      r.g)    )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                     ^  \ rS rSrS\4U 4S jjr0 4S\\   4S jjrS\	S\4S jr
S0 4S\S	\S\4S
 jjrScS\	S\S\4S jjr0 4S\S\4S jjr0 4S\S\4S jjrS0 4S\S\4S jjrScS\	S\S\4S jjrSS0 4S\S\S	\S\\   4S jjrScS\S\4S jjrSSS0 4S\S\S\S	\S\\   4
S jjrSSS0 4S\S\S	\4S jjrScS\S\4S jjr0 4S\S\4S jjr S r!S r"S r#ScS\	S\S\$4S  jjr%0 4S\&4S! jjr'S0 4S\S"\(S#\)S$\*S%\+4
S& jjr,S'\4S( jr-ScS)\	S\S\.4S* jjr/S0 4S\S"\(S#\)S$\*S%\+S\.4S+ jjr0SS0 4S\S"\(S#\)S$\+S%\+4
S, jjr1S0 4S-\S\4S. jjr20 4S/\\3   S\\.   4S0 jjr4SSS0 4S\S\S	\S\\.   4S1 jjr5SSS0 4S\S\S	\S\\   4S2 jjr6SSS0 4S3\S\S	\S\\7   4S4 jjr8SSS0 4S3\S\S	\S\\7   4S5 jjr9SSS0 4S3\S\S	\S\\:   4S6 jjr;ScS7\	S8\<S\74S9 jjr=S'\4S: jr>S; r?ScS<\	S8\<S\:4S= jjr@S> rAS0 4S?\\   S\4S@ jjrB0 4S3\S$\*SA\SB\S\C4
SC jjrDScSD\	S8\<S\C4SE jjrE0 4S\S\F4SF jjrGS0 4S\S\\F   4SG jjrHScSH\	S\4SI jjrIS0 4S\S\J4SJ jjrK0 4S\S\L4SK jjrMScSL\	S\S\L4SM jjrNS0 4SL\OS\4SN jjrPS0 4S\S#\)S\.4SO jjrQSSS0 4S\S\S	\S\\.   4SP jjrR0 4S\S\S4SQ jjrTScSR\	S\S\S4SS jjrUS0 4SR\S\4ST jjrVS0 4S\4SU jjrWS0 4SV\XS\4SW jjrYSX\OSY\SZ\S[\S\\	S]\4S^ jrZS_S`0 SS4Sa jr[Sbr\U =r]$ )dblofin   returnc                 b	  > U R                  [        [        U ]  5       0 SS_SS_SS/_SS_S	S
_SS_S0 SS _SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_0 S S_S!S_S"S_S#S_S$S_S%S_S&S_S'S_S(S_S)S_S*S_S+S_S,S_S-S _S.S_S/S_S0S_E0 S1S_S2S_S3S_S4S_S5S_S6S_S7S_S8S_S9S_S:S_S;S_S<S_S=S>_S?S_S@S_SAS_SBS_E0 SCS_SDS_SES_SFS_SGS_SHS_SIS_SJS _SKS_SLS_SMS_SNS_SOS_SPS_SQS_SRS_SSS_E0 STS_SUS_SVS_SWS_SXS _SYS_SZS _S[S_S\S_S]S_S^S_S_S_S`S_SaS_SbS_ScS_SdS_E0 SeS_SfS_SgS_ShS_SiS_SjS_SkS_SlS_SmS_SnS_SoS_SpS_SqS_SrS_SsS_StS_SuS_ESSSSSSSSSSSSv.E_SwSxSySzS{S|S}S~SSSSSSSSS._SS_SSSS0SS0SSS.SSS._SSSSSSSSSSS.00 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSSSSSSSSSSSS.E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSSS.ES.S._SSU R	                  S5      U R	                  S5      S.0_SSSSS._SSSSSSS.SSSSSSS.SS0SS
SSSS.S SS
SSSS.S SSSSSSSSS.SS0S.	SSSS SSSS SS.S.SSSS SSSS SS.SS.S.SS0S S.S S S.S._S0 S[
        _S[        _S[        _S[
        _S[
        _S[
        _S[        _S[
        _S[
        _S[
        _S[
        _S[
        _S[        _S[        _S[        _S[        _S[        _0 S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _E[        [        [        [
        [
        [
        [        [        S.E[        [        S.S._GS S[        0_GS[        _GS0 GSGS_GSGSGSGSGSGS	SGS
._GSGSSGSGS	SGS._GSGS_GSGSGSGSGS._GSGSGSGSGSGS._SWSwSzS}SSSzS}SSGS.0_SUGSGS0_SaGSGS0_SGS_GSS_SQS/_GSS_SIGSGS0_SYGSGS 0_SGSGS!0_S1GSGS"0_GSGS"0S S GS#.GS$GS%GS$GS%GS&.GS'.E0E5      $ ((  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  )	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<   r1  r=   r2  r3  r:   accountsById)r1  r0  r2  r3  r:   defaultNetworkERC20defaultNetworksBTCTRC20)ETHr8  USDTnetworksBitcoinBSC)r8  BEP20r6  r9  )r   r   r   r   5Mr   r   r   timezoneUTCmethodprivateGetAccountPositionsprivatePostTradeOrder!createMarketBuyOrderRequiresPricedefaultTypeprivateGetAssetBillsprivateGetTradeOrdersPending!privatePostTradeCancelBatchOrdersprivateGetTradeOrdersHistory)r   pwdSPOTSWAP)r:   r<   rM  rN  )r]   r   exchangeType)deep_extendsuperr*   describeparse_numberr"   r    r   r%   r$   r#   r&   r'   )self	__class__s    E/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/blofin.pyrR  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    U R                  U5      nU R                  US/ 5      nU R                  U5      $ )z
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)rT  paramsresponserZ  s       rV  fetch_marketsblofin.fetch_markets  s7     226:~~h3!!$''rX  marketc                    U R                  US5      nU R                  US5      nUS:H  nUS:H  nUS:H  nUS:H  nU=(       d    UnU R                  US5      n	U R                  US5      n
U R                  US5      nU R                  U5      nU R                  U	5      nU R                  U
5      nUS	-   U-   nU(       a  US
-   U-   nS nS nS nU R                  US5      nU R                  U R                  US0 5      nU R                  US5      nU R                  US5      nU R                  USS5      n[        R                  " US5      nU R                  US5      S:H  nU R                  0 SU_SU_SU_SU_SU	_SU
_SU_SU_SU_SU_SU_SU=(       a    [        R                  " US5      _SU_SU_SU_SU_SU_UU(       a  X:H  OS U(       a  X:H  OS U(       a  U R                  US5      OS UUUUU R                  US 5      U R                  US!5      U R                  U5      S".U R                  S5      U R                  U5      S#.U R                  US$5      S S#.S S S#.S S S#.S%.US&.E5      $ )'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_integerrS  )rT  rb  r.   rx  r:   r=   r<   r>   r  rt  ru  rw  rv  rr  rs  rq  r  strikePricer  rj  r   r   r   rl  isActives                            rV  parse_market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	rX  Nrq  r   c                 B   U R                  5         U R                  U5      nSUS   0nUc  SOUnUb  X%S'   U R                  U R                  XS5      5      nU R	                  US/ 5      nU R                  US0 5      nU R                  US5      n	U R                  XU	5      $ )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.   2   sizerZ  r   ts)load_marketsrb  publicGetMarketBooksextendr\  	safe_dictr  parse_order_book)
rT  rq  r   r^  rb  requestr_  rZ  first	timestamps
             rV  fetch_order_bookblofin.fetch_order_bookI  s     	V$fTl
 }5#FO,,T[[-IJ, ~~h3tQ+%%eT2	$$UI>>rX  tickerc           
          U R                  US5      nU R                  US5      nU R                  XBS5      nUS   nU R                  US5      nU R                  US5      nU R                  USS5      nU(       a  U R                  US	5      OS n	U R                  US
5      n
U R                  US5      nU R                  US5      nU R	                  0 SU_SU_SU R                  U5      _SU_SU_SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SS _SU_SU_SU_SS _SS _SS _SS _U
U	U R                  US 5      U R                  US!5      US".EU5      $ )#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)rT  r  rb  r  marketIdrq  r  r  r:   r  r  r  r  s                rV  parse_tickerblofin.parse_tickerw  s   ( %%fd3	##FH5!!(C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<@))&+>-!
. / 	rX  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US/ 5      nU R                  US0 5      nU R                  Xs5      $ )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.   rZ  r   )r  rb  publicGetMarketTickersr  r\  r  r  rT  rq  r^  rb  r  r_  rZ  r  s           rV  fetch_tickerblofin.fetch_ticker  s~     	V$fTl
 ..t{{7/KL~~h3tQ+  //rX  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US/ 5      nU R                  US0 5      nU R                  Xs5      $ )ab  
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.   rZ  r   )r  rb  publicGetMarketMarkPricer  r\  r  r  r  s           rV  fetch_mark_priceblofin.fetch_mark_price  s~     	V$fTl
 00W1MN~~h3tQ+  //rX  symbolsc                     U R                  5         U R                  U5      nU R                  U5      nU R                  US/ 5      nU R	                  XA5      $ )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>`
rZ  )r  market_symbolsr  r\  parse_tickers)rT  r  r^  r_  tickerss        rV  fetch_tickersblofin.fetch_tickers  sS     	%%g...v6..626!!'33rX  tradec                    U R                  US5      nU R                  US5      nU R                  XBS5      nUS   nU R                  US5      nU R                  USS5      nU R                  USS	5      nU R                  US
5      n	U R                  US5      n
U R                  US5      nS nUb  UUS   S.nU R	                  UUU R                  U5      UUU
S S U	UUS US.U5      $ )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  )rT  r  rb  r.   r  rq  r  r   r}  r  r  feeCostr  s                rV  parse_tradeblofin.parse_trade  s   8 eY/##E84!!(C8!%%eT2	""5';?##E6:>v.""5)4""5%0"8,C "Y/  
  	rX  sincec                    U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX4SSSS5	      $ U R                  U5      nSUS	   0nSnUb  X7S
'   Sn	U R                  USSS5      u  pU	S:X  a   U R	                  U R                  Xt5      5      nU R                  US/ 5      n
U R                  XX#5      $ )ax  
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   rC  publicGetMarketTradesrZ  )r  handle_option_and_paramsfetch_paginated_call_cursorrb  r  r  r\  parse_trades)rT  rq  r  r   r^  r  rb  r  r_  rC  rZ  s              rV  fetch_tradesblofin.fetch_trades$  s     	88PZ[33M6RWajlsuy{~V$fTl
 $G66v}hXop,,11$++g2NOH~~h3  u<<rX  c           	          U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )Nr   r               )r  r  )rT  ohlcvrb  s      rV  parse_ohlcvblofin.parse_ohlcvD  sn     eQ'UA&UA&UA&UA&UA&
 	
rX  r   	timeframec           	         U R                  5         U R                  U5      nSnU R                  USS5      u  puU(       a  U R                  SXXBUS5      $ Uc  SnUS   U R	                  U R
                  X"5      US.nU R                  US5      n	U	b  XS	'   U R                  US5      nSn
U R                  U R                  X5      5      n
U R                  U
S
/ 5      nU R                  XX#U5      $ )ao  
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  rZ  )r  rb  r  "fetch_paginated_call_deterministicr  r   r  omitpublicGetMarketCandlesr  r\  parse_ohlcvs)rT  rq  r  r  r   r^  rb  r  r  r  r_  rZ  s               rV  fetch_ohlcvblofin.fetch_ohlcv[  s     	V$88zZ::<X]jpruvv=ETl##DOOYJ

 !!&'2$GYYvw/F..t{{7/KL~~h3  yGGrX  c           
         Uc  [        U R                  S-   5      eU R                  5         SnU R                  USS5      u  pTU(       a  U R	                  SXUSUS5      $ U R                  U5      nSUS   0nUb  [        US	-
  S
5      US'   Ub  X7S'   U R                  US5      nUb  XS'   U R                  US5      nU R                  U R                  Xt5      5      n	/ n
U R                  U	S/ 5      n[        S
[        U5      5       HR  nX   nU R                  US5      nU
R                  UUS   U R                  US5      UU R!                  U5      S.5        MT     U R#                  U
S5      nU R%                  XS   X#5      $ )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>`
z5 fetchFundingRateHistory() requires a symbol argumentFrl   r  r   r6   rd  r.   r   r   beforer   r  r  rZ  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)rT  rq  r  r   r^  r  rb  r  r  r_  ratesrZ  irater  sorteds                   rV  fetch_funding_rate_history!blofin.fetch_funding_rate_history  s    >#DGG.e$eff88AZ\fg::;TV\ejlprxz}~~V$fTl
  #EAIq 1GH$G!!&'2$GYYvw/F99$++g:VW~~h3q#d)$A7D))$>ILL *#//mD& LL3  % e[1009I5XXrX  c                 :   U R                  US5      nU R                  X25      nU R                  US5      n0 SU_SU_SS _SS _SU R                  S5      _S	S _S
S _SS _SU R	                  US5      _SU_SU R                  U5      _SS _SS _SS _SS _SS _SS _SS 0E$ )Nrd  r  r  rq  r  r  interestRate0estimatedSettlePricer  r  r  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r  safe_symbolr  rS  r  r  )rT  r  rb  r  rq  r  s         rV  parse_funding_rateblofin.parse_funding_rate  s7    ##Hh7!!(3''-@
H
f
 
 $	

 D--c2
 #D
 
 
 4++HmD
 
 t||K8
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 	
rX  c                 D   U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      nU R                  US/ 5      nU R                  US0 5      nU R                  Xs5      $ )a   
fetch 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.   rZ  r   )	r  rb  r   r.   publicGetMarketFundingRater  r\  r  r'  )rT  rq  r^  rb  r  r_  rZ  entrys           rV  fetch_funding_rateblofin.fetch_funding_rate  s     	V$f~*^ ^__fTl
 224;;w3OP ~~h3tQ+&&u55rX  c                     U R                  US5      nUb&  [        U[        5      (       a  U R                  U5      $ U R	                  U5      $ )NrZ  )r\  
isinstancelistparse_funding_balanceparse_balance)rT  r_  rZ  s      rV  parse_balance_by_typeblofin.parse_balance_by_type  sF    ~~h/*T4"8"8--h77%%h//rX  c                 4   SU0nU R                  US0 5      nU R                  US5      nU R                  US/ 5      n[        S[	        U5      5       H  nXV   nU R                  US5      nU R                  U5      n	U R                  5       n
U R                  US5      nU R                  US5      nUb  Uc+  U R                  US	5      U
S
'   U R                  US5      U
S'   OXS'   XS
'   XU	'   M     XBS'   U R                  U5      US'   U R                  U5      $ )Nr  rZ  r  detailsr   r  equity	availableavailableEquityfreefrozenusedtotalr  r  )
r  r  r\  r  r  r  r  accountr  safe_balance)rT  r_  resultrZ  r  r6  r  balance
currencyIdcoder>  eqavailEqs                rV  r2  blofin.parse_balance  s+   > )~~h3%%dD1	..y"5q#g,'AjG))':>J**:6DllnG!!'84B&&w<G
"&"2"27<M"N"&"2"27H"E#% ")"4L ( ({!\\)4z  ((rX  c                 ~   SU0nU R                  US/ 5      n[        S[        U5      5       H}  nX4   nU R                  US5      nU R	                  U5      nU R                  5       nU R                  US5      US'   U R                  US5      US'   U R                  US	5      US
'   XU'   M     U R                  U5      $ )Nr  rZ  r   r  rA  r=  r8  r:  r;  r<  )r\  r  r  r  r  r>  r?  )	rT  r_  r@  rZ  r  rA  rB  rC  r>  s	            rV  r1  blofin.parse_funding_balance2  s      )~~h3q#d)$AgG))':>J**:6DllnG#//CGG"..wDGFO"..wAGFO"4L %   ((rX  r  c                    UU R                  S U5      U R                  [        R                  " U R	                  USS5      5      5      U R                  [        R                  " U R	                  USS5      5      5      S S S.$ )Nr   makerUr   takerU)r  rq  r   r   r  	tierBased)r&  rS  r(   
string_negr  )rT  r  rb  s      rV  parse_trading_feeblofin.parse_trading_feeP  sy    &&tV4&&w'9'9$:L:LSRY[c:d'ef&&w'9'9$:L:LSRY[c:d'ef
 	
rX  c                 v   U R                  5         SnU R                  USSS5      u  p!0 nSnUbZ  US:w  aT  U R                  U R                  S0 5      nU R	                  XRU5      nXcS'   U R                  U R                  X15      5      nO U R                  U R                  X15      5      nU R                  U5      $ )a  
query for balance and get the amount of funds available for trading or funds locked in orders

https://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<   r/  )	r  handle_option_and_params_2r  r,  r  privateGetAssetBalancesr  privateGetAccountBalancer3  )rT  r^  rQ  r  r_  r,  parsedAccountTypes          rV  fetch_balanceblofin.fetch_balance[  s     	"==fnVcekl
"{f'<nnT\\3CRHG $ 0 0{ S%6M"33DKK4PQH44T[[5QRH))(33rX  rx  r  r}  r   c           	         U R                  U5      nUS   UUU R                  X5      U R                  U R                  SS5      S.nS n	U R	                  SUS5      u  pXS'   U R                  US5      n
U R                  US	S
5      nU R                  USS5      nU(       a  US:X  a  SOSUS'   US:H  nU R                  US	/5      nUS:H  =(       d    US:H  nU=(       a    UnU(       d  U(       a  SUS'   OU
b  SOSnU R                  X5      UU'   SnU R                  XS:H  U5      u  nnU(       a  SUS'   U R                  US5      nU R                  US5      nU R                  U/ SQ5      nUS LnUS LnU(       d  U(       a  U(       aP  U R                  USS5      nU R                  UU5      US'   U R                  USS5      nU R                  UU5      US'   U(       aP  U R                  USS5      nU R                  UU5      US '   U R                  USS5      nU R                  UU5      US!'   O(U
b%  S"US'   U R                  X5      US'   U(       a  SUS'   U R                  X5      $ )#Nr.   r-  r.  )rd  r  	orderTyper  r-  rI   crossr   r   r   GTCr   FbuylongshortpositionSiderb  r   iocrY  
orderPricer   	post_onlyrx  stopLoss
takeProfit)rc  rd  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  )rT  rq  rx  r  r}  r   r^  rb  r  r   r   r   isHedgedisMarketOrderr`  	marketIOCkeypostOnlyrc  rd  
isStopLossisTakeProfitrf  rh  ri  tpPrices                             rV  create_order_requestblofin.create_order_requestu  s   V$Tl,,V<((zCUV
 
!??vW^_
 *''?&&v}eD>>&(E:15fWGN#(6M?3e#7"*s	I#+GK #/#;,'C226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 &*&=&=f&SGN#(,%{{7++rX  statusc                 8    SSSSSSS.nU R                  X!U5      $ )Ncanceledr  closed)r{  order_failedrp  partially_filledfilled	effectiver  rT  ry  statusess      rV  parse_order_statusblofin.parse_order_status  s0    "& &!
 &99rX  r  c                    U R                  U/ SQ5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nS n	S n
US:X  a  Sn	S	nOUS
:X  a  Sn
S	nOUS:X  a  Sn
S	nOUS:X  a  SnU R                  US5      nU R                  X5      nU R	                  XS5      nU R                  US5      nU R                  U/ SQ5      nU R                  US5      nU R                  U R                  US5      5      nU R                  US5      nU R                  US5      nU R                  USS5      nU R                  US5      n[        R                  " UU5      nS nUb.  [        R                  " UU5      n[        R                  " UU5      nS nUbN  [        R                  " U5      nU R                  USS5      nU R                  U5      nU R                  U5      US.nU R                  US5      nUb  [        U5      S:  a  S nU R                  US 5      nU R                  US!5      nU R                  US"5      nU R                  US#5      nU R                  US$5      n U S%:H  n!U R                  0 S&U_S'U_SU_S(U_S)U R                  U5      _S*U_S+U_S,U_S-U_S.U
_S/U	_SU_S0U_S1U_S2U_S3U_S4U_UUUUS UUS U!S5.	EU5      $ )6N)tpslIdr  algoId
createTime
updateTimefillTimer  rY  rb  Tr   fokr   r`  r   conditionalr   rd  r  
filledSize)pxr   ra  averagePricero  r  r  r   rn  r  feeCcyr;  r  clientOrderIdr   rf  rh  ri  rj  
reduceOnlytruer  r.   r  r  lastTradeTimestamplastUpdateTimestamprq  rx  r   rs  r   stopLossTriggerPricetakeProfitTriggerPricer   r   )	r  r  r}  r  	remainingry  r  tradesr  )safe_string_nr  r  r  r&  r  r(   
string_mul
string_div
string_absr  rS  r  r  
safe_orderr  )"rT  r  rb  r.   r  r  r  r  rx  rs  r   r  rq  r  r   r  ry  feeCostStringr}  r   r  
baseAmountr  r  feeCostSignedfeeCurrencyIdfeeCurrencyCoder  r  r   r  r   reduceOnlyRawr  s"                                     rV  parse_orderblofin.parse_order  s   H 'FG%%e\:	"//|D!..ujAv.{3;HDU]KDU]KD]"D##E84!!(3!!(C8!!%6""5*GH""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 	rX  c                    U R                  5         U R                  U5      nU R                  USS5      nU R                  US5      nSn	U R	                  USSS5      u  pU R                  US5      SLn
U R                  US5      SLnU R                  US	5      SLnU
=(       d    UnSnU R                  US
5      nUb  U(       a  SOSUS
'   U=(       d    U	S:H  =(       d    UnU=(       d    U	S:H  nU(       a%  U R                  XX4XV5      nU R                  U5      nOPU(       a%  U R                  XX4XV5      nU R                  U5      nO$U R                  XX4XV5      nU R                  U5      nU(       d  U(       a%  U R                  US0 5      nU R                  UU5      $ U R                  US/ 5      nU R                  US5      nU R                  UU5      nUUS'   UUS'   U$ )aC  
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   rC  rE  r   r   r   r  r  falseprivatePostTradeOrderTpslprivatePostTradeOrderAlgorZ  r   rx  r  )r  rb  r  r  r  r  create_tpsl_order_requestr  rw  r  rE  r  r  r\  )rT  rq  rx  r  r}  r   r^  rb  r  rC  isStopLossPriceDefinedisTakeProfitPriceDefinedhasTriggerPriceisType2Orderr_  r  isTpslOrderisTriggerOrdertpslRequesttriggerRequestr  dataDictrZ  r  r  s                            rV  create_orderblofin.create_order,  s   < 	V$~~ffe466*66v}hXop!%!1!1&/!JRV!V#'#3#3F<M#NVZ#Z **6>B$N.J2J^^FL9
!-76WF< Uv)DDU(SV7R-R88tUZcK55kBH!66vTSXaN55nEH//dEZG11':H.~~h;H##Hf55~~h3tQ'  /ffrX  c                    U R                  U5      nU R                  USS5      nUS   UUU R                  U R                  SS5      S.n	Ub  U R                  X5      U	S'   U R                  USS	5      n
U
S	:w  a  U
S
:w  a  [	        U R
                  S-   5      eU R                  US5      nU R                  US5      nUb5  U R                  X5      U	S'   US:X  a  SU	S'   OLU R                  X5      U	S'   O7Ub4  U R                  X5      U	S'   US:X  a  SU	S'   OU R                  X5      U	S'   XS'   U R                  USS/5      nU R                  X5      $ )Nr_  netr.   r-  r.  )rd  r  r_  r-  r  r   rZ  isolatedzX createTpslOrder() requires a marginMode parameter that must be either cross or isolatedr   r   rf  rb  rg  rh  ri  rj  )	rb  r  r,  rk  r"   r.   rm  r  r  )rT  rq  rx  r  r}  r   r^  rb  r_  r  r   r   r   s                rV  r   blofin.create_tpsl_order_requestm  s   V$''FTl(((zCUV	
 "66v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{{7++rX  r.   c                 b   Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nU R	                  US/S5      nU R                  USSS5      nU R                  US5      nUb  XS'   OHU(       d  U(       d  [        U5      US	'   O+U(       a  [        U5      US
'   OU(       a  [        U5      US'   U R                  U/ SQ5      n	U(       a'  U R                  U/X#5      n
U R                  U
S5      nU$ U(       aC  U R                  U R                  XY5      5      nU R                  US5      nU R                  X5      $ U R                  U R                  XY5      5      nU R                  US/ 5      nU R                  US5      nU R                  UU5      $ )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 argumentrd  r.   r   Fr  TPSLr  r  r  r  )r  r  stopr   r  r   rZ  )r!   r.   r  rb  safe_bool_nsafe_bool_2r  strr  cancel_ordersr  privatePostTradeCancelAlgor  r  privatePostTradeCancelOrderr\  )rT  r.   rq  r^  rb  r  	isTriggerisTpslr  querytpslResponser  triggerResponsetriggerDatar_  rZ  r  s                    rV  cancel_orderblofin.cancel_order  s    >#DGG.Y$YZZV$fTl
 $$Vi[%@	!!&&&%@((A$'4O$V%(W	"$'G!$'G!		&"YZ--rdFCLNN<3EL"==dkk'>YZO..&AK##K8833DKK4OP~~h3tQ'v..rX  ordersc           	         U R                  5         / n[        S[        U5      5       H  nX   nU R                  US5      nU R                  US5      nU R                  US5      nU R	                  US5      n	U R	                  US5      n
U R                  US0 5      nU R                  X5      nU R                  XgXX5      nUR                  U5        M     U R                  U5      nU R                  US/ 5      nU R                  U5      $ )	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^  rZ  )r  r  r  r  
safe_valuer  r  rw  r  privatePostTradeBatchOrdersr\  parse_orders)rT  r  r^  ordersRequestsr  rawOrderr  rx  r  r}  r   orderParamsextendedParamsorderRequestr_  rZ  s                   rV  create_ordersblofin.create_orders  s     	q#f+&AyH''(;H##Hf5D##Hf5D__Xx8FOOHg6E..8R@K![[=N44XTSXiL!!,/ ' 33NC~~h3  &&rX  c                    U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX45      $ 0 nSnUb  U R                  U5      nUS   US'   Ub  X6S'   U R	                  USS	/S5      nU R                  US
SS5      n	Sn
U R                  USSS5      u  pU R                  U/ SQ5      nSnU	(       d  U
S:X  a!  U R                  U R                  Xk5      5      nOSU(       d  U
S:X  a&  S	US'   U R                  U R                  Xk5      5      nO U R                  U R                  Xk5      5      nU R                  US/ 5      nU R                  XX#5      $ )aT  
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  rC  rI  rC  r  r   r  r   privateGetTradeOrdersTpslPending privateGetTradeOrdersAlgoPendingrY  rZ  )r  r  fetch_paginated_call_dynamicrb  r  r  r  r  r  r  rI  r\  r  )rT  rq  r  r   r^  r  r  rb  r  isTpSlrC  r  r_  rZ  s                 rV  fetch_open_ordersblofin.fetch_open_orders  sy     	88ART^_445FW\ee
[[(F &tGH$G$$Vfi-@%H	!!&&&%@66v?PRZ\z{		&"OPf BB<<T[[=XYH6%GG#,GK <<T[[=XYH88W9TUH~~h3  u<<rX  c                    U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX45      $ 0 nSnUb  U R                  U5      nUS   US'   U R	                  SXd5      u  pdUb  X6S'   U R                  U R                  Xd5      5      nU R                  US	/ 5      n	U R                  XX#5      $ )
a  
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   rZ  )	r  r  r  rb  handle_until_optionprivateGetTradeFillsHistoryr  r\  r  )
rT  rq  r  r   r^  r  r  rb  r_  rZ  s
             rV  fetch_my_tradesblofin.fetch_my_trades  s     	88R\]44_fUZcc
[[(F &tGH225'J$G33DKK4PQ~~h3  u<<rX  rC  c                    U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX45      $ 0 nSnUb  U R                  U5      nUS   US'   Ub  [	        US-
  S5      US	'   Ub  X6S
'   U R                  SXd5      u  pdU R                  U R                  Xd5      5      nU R                  US/ 5      n	U R                  XX#U5      $ )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  rZ  )
r  r  r  r  r   r  privateGetAssetDepositHistoryr  r\  parse_transactions
rT  rC  r  r   r^  r  r  r  r_  rZ  s
             rV  fetch_depositsblofin.fetch_deposits$  s     	88R\]44_dSXaa
}}T*H"*4.GJ #EAIq 1GH$G227GL55dkk'6RS~~h3&&tuVLLrX  c                    U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX45      $ 0 nSnUb  U R                  U5      nUS   US'   Ub  [	        US-
  S5      US	'   Ub  X6S
'   U R                  SXd5      u  pdU R                  U R                  Xd5      5      nU R                  US/ 5      n	U R                  XX#U5      $ )a  
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  rZ  )
r  r  r  r  r   r   privateGetAssetWithdrawalHistoryr  r\  r  r  s
             rV  fetch_withdrawalsblofin.fetch_withdrawalsF  s     	88ASU_`445GV[dd
}}T*H"*4.GJ #EAIq 1GH$G227GL88W9UV~~h3&&tuVLLrX  c                    U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX45      $ 0 nUb  X6S'   SnUb  U R                  U5      nUS   US'   U R	                  SXd5      u  pdSnU R                  U R                  Xd5      5      nU R                  US	/ 5      n	U R                  XX#5      $ )
au  
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>`
Frs   r  Nr   r.   r  r  rZ  )	r  r  r  r  r  rH  r  r\  parse_ledgerr  s
             rV  fetch_ledgerblofin.fetch_ledgerh  s     	88PZ[44]DQV__
$G}}T*H"*4.GJ225'J,,T[[-IJ~~h3  >>rX  transactionr  c                    S nS nU R                  US5      nU R                  US5      nU R                  US5      nUnU R                  US5      n	Ub  SnUnOUnSnU R                  US5      n
U R                  U
5      nU R                  US5      nU R                  U R                  US	5      5      nU R                  US
5      nU R	                  US5      nU R                  US5      nU R                  U5      nU R                  US5      n0 SU_SU_SU_SU_SS _SS _SU_SU_SS _SU	_SU	_SU_SU_SS _SU_SU_SU R                  U5      _S S UUS.S.E$ )N
withdrawId	depositIdaddresstag
withdrawaldepositr  r}  ro  txIdr  feeCurrencyr  r  r.   networkaddressFrom	addressTotagFromtagTory  rx  updatedtxidr  r  )r  r  )internalcommentr  )r  r  r  parse_transaction_statusr  r  )rT  r  r  rx  r.   withdrawalIdr  r  r  r  rB  rC  r}  ry  r  r  r  feeCoder  s                      rV  parse_transaction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/#
$ #)
 	
rX  c                 4    SSSSS.nU R                  X!U5      $ )Npendingokfailed)r  rn  23r  r  s      rV  r	  blofin.parse_transaction_status  s*    	
 &99rX  c                 B    SSSSSSSSSSSS.nU R                  X!U5      $ )Nr   r  rebater  )rn  r  r  4567891011r  )rT  rx  typess      rV  parse_ledger_entry_typeblofin.parse_ledger_entry_type  s?    
 T22rX  itemc                    U R                  US5      nU R                  X25      nU R                  X25      nU R                  US5      nU R	                  UU R                  US5      S S U R                  US5      S U R                  U R                  US5      5      UU R                  US5      UU R                  U5      S S SS S.U5      $ )	Nr  r  
transferIdclientIdrx  r}  r  )r  r.   	directionr>  referenceIdreferenceAccountrx  r  r}  r  r  r
  r  ry  r  )r  r  safe_currencyr  safe_ledger_entryr   r  r  )rT  r"  r  rB  rC  r  s         rV  parse_ledger_entryblofin.parse_ledger_entry  s    %%dJ7
&&z<%%j;%%dD1	%%""46++D*= $001A1A$1OP&&tX6"Y/'
  ! 	rX  c                 R    [        U[        5      (       a  UR                  S5      $ U$ )zc
@ignore
       :param string[]|str ids: order ids
       :returns str[]: list of order ids
       ,)r/  r  split)rT  idss     rV  	parse_idsblofin.parse_ids  s$     c399S>!JrX  r0  c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      n/ nU R	                  U R
                  S0 5      nU R                  USS5      nU R                  USU5      nU R                  U R                  US5      5      n	U R                  U R                  US5      5      n
U R                  U/ SQ5      nU(       a  S	nU	c  U R                  U5      nU
b5  [        S
[        U
5      5       H  nUR                  X   US   S.5        M     [        S
[        U5      5       H>  nU(       a  UR                  X   US   S.5        M%  UR                  X   US   S.5        M@     O5[        S
[        U	5      5       H  nUR                  US   X   S.5        M     SnUS	:X  a  U R                  U5      nOU R                  U5      nU R                  US/ 5      nU R!                  XSSU5      $ )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   rC  rJ  r  r  )r  r   r  privatePostTradeCancelTpslr   r.   )r  rd  )r  rd  )rd  r  rZ  )r!   r.   r  rb  r  r,  r  r1  r  r  r  r  r  r4  rJ  r\  r  )rT  r0  rq  r^  rb  r  r,  defaultMethodrC  clientOrderIdstpslIdsr   r  r_  
ordersDatas                  rV  r  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")*"(,$  0
 1c#h'NN"%&"(,$ 
 NN#&6"(,$  ( 1c.12$Tl%3%6   3
 1166w?H==gFH^^Hfb9
  T4HHrX  fromAccount	toAccountc                    U R                  5         U R                  U5      nU R                  U R                  S0 5      nU R	                  XsU5      nU R	                  XtU5      n	US   U R                  X5      UU	S.n
U R                  U R                  X5      5      nU R                  US0 5      nU R                  X5      $ )a  
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  r}  r:  r;  rZ  )	r  r  r  r,  r  currency_to_precisionprivatePostAssetTransferr  parse_transfer)rT  rC  r}  r:  r;  r^  r  r/  fromIdtoIdr  r_  rZ  s                rV  r   blofin.transferT  s     	==&6FK!!.{K9E 00>!	
 00W1MN~~h3""422rX  r   c           
      >    U R                  US5      nUUS S S S S S S S.	$ )Nr$  )	r  r.   r  r  r  r}  r:  r;  ry  r  )rT  r   r  r.   s       rV  r?  blofin.parse_transferp  s9    h5

 
	
rX  c                    U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US/ 5      nU R                  US5      nUc  gU R                  Xs5      $ )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.   rZ  r   N)r  rb  rD  r  r\  r  parse_position)rT  rq  r^  rb  r  r_  rZ  positions           rV  fetch_positionblofin.fetch_position~  s     	V$fTl
 224;;w3OP~~h3>>$*""844rX  c                     U R                  5         U R                  U5      nU R                  U5      nU R                  US/ 5      nU R	                  U5      nU R                  USUS5      $ )at  
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>`
rZ  rq  F)r  r  rD  r\  parse_positionsfilter_by_array_positions)rT  r  r^  r_  rZ  r@  s         rV  fetch_positionsblofin.fetch_positions  si     	%%g.226:~~h3%%d+--fhOOrX  rG  c                 
   U R                  US5      nU R                  X25      nUS   nU R                  US5      n[        R                  " U5      nU R                  US5      nUS:g  nU R	                  U5      n	UbF  US:X  a@  [        R
                  " US5      (       a  SnO![        R                  " US5      (       a  SnOS nU R                  US	5      n
U R                  U
5      nU R                  US
5      nU R                  US5      nUS   (       a+  [        R                  " [        R                  " Xk5      U5      nU R	                  U5      nU R                  US5      nS nU R                  US5      nU R                  US5      nU R                  US5      nS nS nUS:X  a*  U R                  US5      n[        R                  " UU5      nO/US:X  a)  [        R                  " SU5      nU R                  US5      nU R                  US5      nU R	                  U5      n[        R                  " UU5      nUc(  U R	                  [        R                  " UUS5      5      nOUc  [        R                  " UU5      nSnU R	                  [        R                  " [        R                  " UU5      SS5      5      nU R                  US5      nU R                  US5      nU R	                  [        R                  " US5      5      nU R                  US5      nU R	                  [        R                  " UUS5      5      nU R                  0 SU_SS _SU_SU_SU_SU_S U R	                  U5      _SU R	                  U5      _S!U_S"U	_S	U
_S
U R	                  U5      _S#S _S$U_S%U_S&U_S'U R                  U5      _S UUU R	                  U5      U R	                  U5      U R	                  U5      U R	                  U5      US S S(.
E5      $ ))Nrd  rq  	positionsr_  r  r  r]  r^  r  r  notionalUsdr   r   r  unrealizedPnlr   rZ  initialMarginr  rn  r;   maintenanceMarginr  z0.00005liquidationPriceunrealizedPnlRatiorm  r  r  r.   notional
entryPricer  	contracts	lastPricer  r   r  r  )
r  rT  maintenanceMarginPercentage
collateralrS  initialMarginPercentager   marginRatior   r   )r  r  r(   r  rS  r  	string_ltr  number_to_stringr  r  
string_addr  safe_positionr  ) rT  rG  rb  r  rq  poscontractsAbsr  r   rY  r  contractSizeStringmarkPriceStringnotionalStringrW  r   initialMarginStringentryPriceStringunrealizedPnlStringleverageStringr]  collateralStringmaintenanceMarginStringrT  !maintenanceMarginPercentageStringrounderr[  rU  percentageStringr  r  r^  s                                    rV  rF  blofin.parse_position  s   6 ##Hh7!!(3!x5))#..9%%l3	?u}$$S#..!D&&sC00"DD''?!22<@**8[A))(MB)$//0B0B<0dfu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#
  	rX  c                 H   U R                  5         Uc  [        U R                  S-   5      eSnU R                  SU5      u  p2Uc  U R	                  USS5      nUS:w  a  US:w  a  [        U R                  S-   5      eU R                  U5      nSn[        S	[        U5      5       H2  nX   nU R                  U5      nUS	:  a  US
-   US   -   nM+  XGS   -   nM4     UUS.nU R                  U R                  X5      5      n	U R                  U	S/ 5      n
U R                  XS5      $ )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   rZ  r  zW fetchLeverages() requires a marginMode parameter that must be either cross or isolated r   r.  r.   rd  r   rZ  rd  )r  r!   r.   rl  r  r"   r  r  r  rb  "privateGetAccountBatchLeverageInfor  r\  parse_leverages)rT  r  r^  r   instIdsr  r+  entryMarketr  r_  	leveragess              rV  fetch_leveragesblofin.fetch_leverages  sG    	?#DGG.]$]^^
!??@PRXY
))&,HJ'!
j(@TWW  (A  A  B  B%%g.q#g,'AJE++e,K1u!C-+d*;;!$55 ( $
 ::4;;w;WX NN8VR8	##IAArX  c                 |   U R                  5         SnU R                  SU5      u  p2Uc  U R                  USS5      nUS:w  a  US:w  a  [        U R                  S-   5      eU R                  U5      nUS   US.nU R                  U R                  XR5      5      nU R                  US	0 5      nU R                  Xt5      $ )
aZ  
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   rZ  r  zV fetchLeverage() requires a marginMode parameter that must be either cross or isolatedr.   rt  rZ  )
r  rl  r  r"   r.   rb  privateGetAccountLeverageInfor  r  parse_leverage)rT  rq  r^  r   rb  r  r_  rZ  s           rV  fetch_leverageblofin.fetch_leverageD  s     	
!??QWX
))&,HJ'!
j(@TWW'  A  AV$Tl$
 55dkk'6RS ~~h3""400rX  r   c                     U R                  US5      nU R                  US5      nUU R                  X25      U R                  US5      UUS.$ )Nrd  r   r   )r  rq  r   longLeverageshortLeverage)r  r  r&  r  )rT  r   rb  r  leverageValues        rV  r~  blofin.parse_leveragej  sW    ##Hh7))(J?&&x800<H)*
 	
rX  c                    Uc  [        U R                  S-   5      eUS:  d  US:  a  [        U R                  S-   5      eU R                  5         U R	                  U5      nSnU R                  SUS5      u  pSUS:w  a  US:w  a  [        U R                  S	-   5      eUUUS
   S.nU R                  U R                  Xc5      5      nU$ )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   rZ  r  zT setLeverage() requires a marginMode parameter that must be either cross or isolatedr.   )r   r   rd  )r!   r.   r"   r  rb  rl  privatePostAccountSetLeverager  )rT  r   rq  r^  rb  r   r  r_  s           rV  set_leverageblofin.set_leverageu  s     >#DGG.Y$YZZ qLhnTWW'\\]]V$
!??vW^_
'!
j(@TWW'}}~~ $Tl

 55dkk'6RSrX  c                    U R                  5         U R                  U5      nU R                  US5      nSnU R                  SUS5      u  pcUS   US.nUb  XWS'   U R	                  U R                  Xs5      5      nU R                  US5      $ )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   rZ  r.   rt  rZ  )r  rb  r  rl  privatePostTradeClosePositionr  r  )	rT  rq  r  r^  rb  r  r   r  r_  s	            rV  close_positionblofin.close_position  s    $ 	V$((A
!??QWY`a
Tl$
 $'4O$55dkk'6RS~~h//rX  c                 L   U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX45      $ 0 nSnUb  U R                  U5      nUS   US'   Ub  X6S'   Ub  X&S'   U R	                  U/ S	QS5      nSn	U R                  US
SS5      u  pU R                  U/ SQ5      n
SnU(       d  U	S:X  a!  U R                  U R                  Xj5      5      nO U R                  U R                  Xj5      5      nU R                  US/ 5      nU R                  XX#5      $ )aN  
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   rC  rK  r   privateGetTradeOrdersTpslHistoryrZ  )r  r  r  rb  r  r  r  r  rK  r\  r  )rT  rq  r  r   r^  r  r  rb  r  rC  r  r_  rZ  s                rV  fetch_closed_ordersblofin.fetch_closed_orders  s@    	88ATV`a445H&Y^gg
[[(F &tGH$G$G$$V-PRWX	66v?PRZ\z{		&"OP6%GG<<T[[=XYH88W9TUH~~h3  u<<rX  c                     U R                  5         U R                  U5      nU R                  U5      nU R                  US0 5      nU R	                  XS5      $ )aW  
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>`
rZ  )r  rb  privateGetAccountMarginModer  parse_margin_mode)rT  rq  r^  rb  r_  rZ  s         rV  fetch_margin_modeblofin.fetch_margin_mode  sS     	V$33F; ~~h3%%d33rX  r   c                 N    UU R                  US5      U R                  US5      S.$ )Nrq  r   )r  rq  r   r  )rT  r   rb  s      rV  r  blofin.parse_margin_mode  s/    &&vx8**:|D
 	
rX  c                 
   U R                  SUSSS/5        U R                  5         SnUb  U R                  U5      nSU0nU R                  U R	                  XS5      5      nU R                  US0 5      nU R                  Xt5      $ )aP  
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   rZ  r  NrZ  )check_required_argumentr  rb  privatePostAccountSetMarginModer  r  r  )rT  r   rq  r^  rb  r  r_  rZ  s           rV  set_margin_modeblofin.set_margin_mode 	  s     	$$_j,QXZdPef[[(F*
 77G8TU ~~h3%%d33rX  c                 ~    U R                  U5      nU R                  US0 5      nU R                  US5      nUUS:H  S.$ )a{  
fetchs the position mode, hedged or one way

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
rZ  positionModelong_short_mode)r  r   )privateGetAccountPositionModer  r  )rT  rq  r^  r_  rZ  r  s         rV  fetch_position_modeblofin.fetch_position_mode 	  sP     55f=~~h3''n= "&77
 	
rX  r   c                 \    SU(       a  SOS0nU R                  U R                  XC5      5      $ )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
r  r  net_mode)!privatePostAccountSetPositionModer  )rT  r   rq  r^  r  s        rV  set_position_modeblofin.set_position_mode;	  s1     -Z
 55dkk'6RSSrX  httpCodereasonr   rC  headersbodyc
                    Uc  g U R                  US5      n
U R                  US5      nU R                  S-   U-   nU
bn  U
S:w  ah  U R                  U R                  S   X5        U R                  U R                  S   X5        U R	                  U R                  S   X5        [        U5      eU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nUbd  US:w  a^  U R                  U R                  S   UU5        U R                  U R                  S   X5        U R	                  U R                  S   X5        g )	NrC  msg r  r(  r)  rZ  r   )r  r.   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   r\  r  )rT  r  r  r   rC  r  r  r_  requestHeadersrequestBodyrC  messagefeedbackrZ  r  	insideMsg
insideCodes                    rV  handle_errorsblofin.handle_errorsT	  sI    &1""8U377S=4'001I7]001I4Z001I7])) ~~h/tQ'$$UE2	%%eV4
!jC&7001I:W_`001I9_001I9_rX  r   GETc                    SU R                   -   S-   U R                  X5      -   nU R                  X@R                  U5      5      nU R	                  U R
                  S   S   5      U-   n	US:X  a/  U R                  U5      (       d  U	SU R                  U5      -   -  n	GOUS:X  Ga  U R                  5         [        U R                  5       5      n
U R                  U R                  U
U
S.nS	nUS
:X  a3  U R                  U5      (       d  SU R                  U5      -   nX-  n	X|-  nO.U R                  U5      (       d  U R                  U5      nUnSUS'   Xs-   U
-   U
-   U-   nU R                  U R                  U R!                  U5      U R!                  U R"                  5      [$        R&                  5      5      nXS'   XXeS.$ )Nz/api/rh  r   r   r   ?r   )z
ACCESS-KEYzACCESS-PASSPHRASEzACCESS-TIMESTAMPzACCESS-NONCErs  r  zapplication/jsonzContent-TypezACCESS-SIGN)r   rC  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)rT  pathr   rC  r^  r  r  r  r  r   r  	sign_bodyurlencodedQueryauth	signatures                  rV  signblofin.signt	  s   DLL(3.1D1DT1R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*<'#i/);iGD--diiD8I4;;W[WbWbKceleses.tuI%.M"dOOrX   )N)^__name__
__module____qualname____firstlineno__r   rR  r   r   r`  dictr  r  r   r   r  r   r  r  r  r   r   r  r   r  r  r0  r  r  r   r  r   r'  r,  r3  r2  r1  r   rN  r   rV  r   r   floatr   rw  r  r   r  r  r  r  r   r  r  r  r   r  r  r	   r  r   r  r	  r   r+  r1  r  r   r   r?  r   rH  rM  rF  r   rz  r
   r  r~  intr  r  r  r   r  r  r  r  boolr  r  r  __static_attributes____classcell__)rU  s   @rV  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 
. 9=4^bkm #H# #H# #HS #HX[ #Hrvw{r| #HJ 8<$]ajl /Y /YC /YWZ /Yb
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	: 	:u uv 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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 ; .	 ;?r 9Ic 9IC 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 PrX  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*   r  rX  rV  <module>r     sm    ( ,  X  X  X  X  X  X  X  * 0 . ' . ) . 1 4 %|%PX{ |%PrX  