
    E#i                       S SK Jr  S SKJr  S SKrS SKrS SKJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r   S SK!J"r"  S SK#J$r$  S SK#J%r%  S SK#J&r&  S S	K#J'r'  S S
K#J(r(  S SK#J)r)  S SK#J*r*  S SK#J+r+  S SK#J,r,  S SK#J-r-  S SK#J.r.  S SK#J/r/  S SK#J0r0  S SK#J1r1  S SK2J3r3  S SK2J4r4  S SK2J5r5  S SK2J6r6  S SK7J8r8   " S S\\5      r9g)    )Exchange)ImplicitAPIN)AnyBalances
CurrenciesCurrencyDepositAddressIntLedgerEntryMarginModificationMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTradingFeesTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)RateLimitExceeded)ExchangeNotAvailable)OnMaintenance)InvalidNonce)ROUND)TRUNCATE)DECIMAL_PLACES)SIGNIFICANT_DIGITS)Precisec                   t  ^  \ rS rSrS\4U 4S jjrS rS rS rS r	S r
0 4S	 jr0 4S\\   4S
 jjr0 4S\4S jjr0 4S\4S jjr0 4S\S\S\S\S\4
S jjrSgS\S\S\4S jjrS\S\4S jrS rS0 4S\S\S\4S jjrSgS\S\S\ 4S jjr!S0 4S\"S\#4S  jjr$0 4S\S\ 4S! jjr%SgS"\S\S\&4S# jjr'SS0 4S\S$\S\S\\&   4S% jjr(S&SS'0 4S\S(\S$\S\S\\)   4
S) jjr*SgS\S\)4S* jjr+S\4S+ jr,S, r-S- r.SgS.\S\S\/4S/ jjr0S0 4S\S0\1S1\2S\S2\34
S3 jjr4S0 4S\S0\1S1\2S\S2\34
S4 jjr50 4S5\\6   4S6 jjr7S0 4S\4S7 jjr8S0 4S8\S\4S9 jjr9S0 4S:\\   S\4S; jjr:S0 4S8\S\4S< jjr;S0 4S8\S\4S= jjr<SSS0 4S\S$\S\S\\/   4S> jjr=SSS0 4S\S$\S\S\\/   4S? jjr>SSS0 4S8\S\S$\S\4S@ jjr?SSS0 4S\S$\S\4SA jjr@0 4S\S\A4SB jjrB0 4S\S\A4SC jjrCS\4SD jrDSgSE\S\S\E4SF jjrF0 4S\G4SG jjrHSSS0 4S\S$\S\S\\E   4SH jjrIS0 4S\S\SI\SJ\S\E4
SK jjrJS0 4S\"S\\K   4SL jjrLSgSM\S\4SN jjrMSO rNSPSQ0 SS4SR jrOSS rPS0\4ST jrQSgSU\S\S\R4SV jjrSSSS0 4S\S$\S\S\\R   4SW jjrTS0 4S\"S\U4SX jjrVSSS0 4S\S$\S\4SY jjrWSgS\S\X4SZ jjrYSgS\4S[ jjrZS0 4S\"4S\ jjr[0 4S\4S] jjr\S&SS0 4S\S$\S\4S^ jjr]SgS\4S_ jjr^SS0 4S\S$\S\4S` jjr_SgS\4Sa jjr`0 4S\S\S\a4Sb jjrbSgS\a4Sc jjrcS0 4S8\S\4Sd jjrdSS0 4S8\S\S0\1S1\2S\3S2\34Se jjreSfrfU =rg$ )hbitfinex!   returnc                   > 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_S/S_E0 S0S
_S1S
_S2S_S3S_S4S
_S5S
_S6S_S7S
_S8S9_S:S_S;S_S<S
_S=S
_S>S
_S?S_S@S
_SAS
_E0 SBS_SCS
_SDS
_SES
_SFS_SGS_SHS_SIS_SJS_SKS_SLS_SMS_SNS_SOS
_SPS_SQS
_SRS
_E0 SSS_STS
_SUS_SVS_SWS
_SXS
_SYS_SZS _S[S9_S\S
_S]S
_S^S
_S_S
_S`S_SaS
_SbS
_ScS
_ESSSd.E_SeSfSgShSiSjSkSlSmSnSoSpSqSrSs._StSu_SvSwSxSySxSz.S{S|S}/S~S._S0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_ESSSSSSSSSSSS.ESSS.S.S0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_GS S_GSS_GSS_ESSGSSGS.E0GS._GSGSSSU R	                  GS5      U R	                  GS	5      U R	                  GS
5      U R	                  GS	5      /U R	                  GS5      U R	                  GS	5      /U R	                  GS5      U R	                  GS	5      /U R	                  GS5      U R	                  GS	5      /U R	                  GS5      U R	                  GS	5      /U R	                  GS5      U R	                  GS	5      /U R	                  GS5      U R	                  GS5      /U R	                  GS5      U R	                  GS5      /U R	                  GS5      U R	                  GS5      /U R	                  GS5      U R	                  GS5      /U R	                  GS5      U R	                  GS5      //U R	                  GS
5      U R	                  GS5      /U R	                  GS5      U R	                  GS5      /U R	                  GS5      U R	                  GS5      /U R	                  GS5      U R	                  GS5      /U R	                  GS5      U R	                  GS5      /U R	                  GS5      U R	                  GS
5      /U R	                  GS5      U R	                  GS
5      /U R	                  GS5      U R	                  GS
5      /U R	                  GS5      U R	                  GS
5      /U R	                  GS5      U R	                  GS
5      /U R	                  GS5      U R	                  GS
5      //GS.GS.GS0 0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'GS(GS).GS*GS+GS,GS-GS.GS/.GS0GS0GS1SSSSGS2.GS3S
0GS4GS5GS6GS7GS8GS9GS:GS;GS<GS=GS>GS?GS@GSAGSB.GSCGSD0GSE._GSFS
SSS S
SSS SSSS
GSG.S
SSS
SS
S
GSH.GSIGSJ0S
GSKS GSLS
GSM.S
S
S
S
GSN.S
S S
S
S
GSO.S S
S S S GSLS
S
S
GSP.GS%GSQ0GSR.	GSSGST0GSSGST0S GSU.S S GSU.GSV._GSW[        [        [        [        [        [        [        GSX.[        [        [        [        GSY.GSZ._GS[0 GS\GS]_GS^GS__GS`GS]_GSaGSb_GScGSd_GSeGSf_GSgGSh_GSiGSj_GSkGSl_GSmGSn_GSoGSp_GSqGSr_GSsGSt_GSuGS__GSvGSw_GSxGSy_GSzGS{_0 GS|GS}_GS~GS_GSGS~_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_EGSGSGSGS.E_5      $ (  Nidr4   nameBitfinex	countriesVGversionv2	certifiedFproThasCORSspotmarginswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelOrdercancelOrderscreateDepositAddresscreateLimitOrdercreateMarketOrdercreateOrdercreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrdercreateTrailingAmountOrdercreateTrailingPercentOrdercreateTriggerOrder	editOrderfetchBalancefetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchClosedOrderfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsWithdrawalsfetchFundingHistoryfetchFundingRateemulatedfetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchLeverageTiersfetchLiquidationsfetchMarginModefetchMarketLeverageTiersfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrderTradesfetchPositionfetchPositionModefetchPositionsfetchPremiumIndexOHLCVfetchStatusfetchTickers	fetchTimefetchTradingFeefetchTradingFeesfetchTransactionFeesfetchTransactionsreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeverage	setMarginsetMarginModesetPositionModesignIn)transferwithdraw
timeframes1m5m15m30m1h3h4h6h12h1D7D14D1M)r   r   r   r   r   r   r   r   r   1d1w2wr   	rateLimit   urlszOhttps://github.com/user-attachments/assets/4a8e947f-ab46-481a-a8ae-8b20e9b03178zhttps://api.bitfinex.comzhttps://api-pub.bitfinex.com)v1publicprivatezhttps://www.bitfinex.comz"https://docs.bitfinex.com/v2/docs/z0https://github.com/bitfinexcom/bitfinex-api-nodezhttps://www.bitfinex.com/fees)logoapiwwwdocfeesr   zconf/{config}g@zconf/pub:{action}:{object}z#conf/pub:{action}:{object}:{detail}zconf/pub:map:{object}zconf/pub:map:{object}:{detail}zconf/pub:map:currency:{detail}zconf/pub:map:currency:symzconf/pub:map:currency:labelzconf/pub:map:currency:unitzconf/pub:map:currency:undlzconf/pub:map:currency:poolzconf/pub:map:currency:explorerzconf/pub:map:currency:tx:feezconf/pub:map:tx:methodzconf/pub:list:{object}zconf/pub:list:{object}:{detail}zconf/pub:list:currencyzconf/pub:list:pair:exchangezconf/pub:list:pair:marginzconf/pub:list:pair:futureszconf/pub:list:competitionszconf/pub:info:{object}zconf/pub:info:{object}:{detail}zconf/pub:info:pairzconf/pub:info:pair:futureszconf/pub:info:tx:statuszconf/pub:feeszplatform/status   tickerszticker/{symbol}ztickers/histztrades/{symbol}/histzbook/{symbol}/{precision}   zbook/{symbol}/P0zbook/{symbol}/P1zbook/{symbol}/P2zbook/{symbol}/P3zbook/{symbol}/R0z-stats1/{key}:{size}:{symbol}:{side}/{section}z(stats1/{key}:{size}:{symbol}:{side}/lastz(stats1/{key}:{size}:{symbol}:{side}/histz&stats1/{key}:{size}:{symbol}/{section}z!stats1/{key}:{size}:{symbol}/lastz!stats1/{key}:{size}:{symbol}/histz&stats1/{key}:{size}:{symbol}:long/lastz&stats1/{key}:{size}:{symbol}:long/histz'stats1/{key}:{size}:{symbol}:short/lastz'stats1/{key}:{size}:{symbol}:short/histz5candles/trade:{timeframe}:{symbol}:{period}/{section}z,candles/trade:{timeframe}:{symbol}/{section}z'candles/trade:{timeframe}:{symbol}/lastP   
   )z'candles/trade:{timeframe}:{symbol}/histzstatus/{type}zstatus/derivzstatus/deriv/{symbol}/histzliquidations/histz-rankings/{key}:{timeframe}:{symbol}/{section}z(rankings/{key}:{timeframe}:{symbol}/histz
pulse/histzpulse/profile/{nickname}zfunding/stats/{symbol}/histz	ext/vasps)zcalc/trade/avgzcalc/fx)getpostr   zauth/r/walletszauth/r/wallets/histzauth/r/orderszauth/r/orders/{symbol}zauth/w/order/submitzauth/w/order/updatezauth/w/order/cancelzauth/w/order/multizauth/w/order/cancel/multizauth/r/orders/{symbol}/histzauth/r/orders/histz!auth/r/order/{symbol}:{id}/tradeszauth/r/trades/{symbol}/histzauth/r/trades/histzauth/r/ledgers/{currency}/histzauth/r/ledgers/histzauth/r/info/margin/{key}zauth/r/info/margin/basezauth/r/info/margin/sym_allzauth/r/positionszauth/w/position/claimzauth/w/position/increase:zauth/r/position/increase/infozauth/r/positions/histzauth/r/positions/auditzauth/r/positions/snapzauth/w/deriv/collateral/setzauth/w/deriv/collateral/limitszauth/r/funding/offerszauth/r/funding/offers/{symbol}zauth/w/funding/offer/submitzauth/w/funding/offer/cancelzauth/w/funding/offer/cancel/allzauth/w/funding/closezauth/w/funding/autozauth/w/funding/keepz#auth/r/funding/offers/{symbol}/histzauth/r/funding/offers/histzauth/r/funding/loanszauth/r/funding/loans/histzauth/r/funding/loans/{symbol}z"auth/r/funding/loans/{symbol}/histzauth/r/funding/creditszauth/r/funding/credits/histzauth/r/funding/credits/{symbol}z$auth/r/funding/credits/{symbol}/histz#auth/r/funding/trades/{symbol}/histzauth/r/funding/trades/histzauth/r/info/funding/{key}zauth/r/info/userzauth/r/summaryzauth/r/logins/histzauth/r/permissionszauth/w/tokenzauth/r/audit/histzauth/w/transferzauth/w/deposit/address   zauth/w/deposit/invoicezauth/w/withdrawz auth/r/movements/{currency}/histzauth/r/movements/histzauth/r/alertsg\(\@zauth/w/alert/setz'auth/w/alert/price:{symbol}:{price}/delz(auth/w/alert/{type}:{symbol}:{price}/delzauth/calc/order/availzauth/w/settings/setzauth/r/settings   )zauth/w/settings/delzauth/r/pulse/histzauth/w/pulse/addzauth/w/pulse/del)r   r   r   r   z0.001z0.0020500000100000025000005000000750000010000000z0.001815000000z0.001620000000z0.001425000000z0.001230000000z0.0008z0.0006z0.0004z0.0002)takermaker)feeSide
percentage	tierBasedr   r   tiersr   )tradingfundingprecisionModeoptionsR0marketlimit)MARKETEXCHANGE MARKETLIMITEXCHANGE LIMITEXCHANGE STOPEXCHANGE FOKEXCHANGE STOP LIMITEXCHANGE IOCr   r   )r   r   USDEURJPYGBPCHN)r   r   r   r   r   exchanger   )rC   r   r   rD   derivativesrF   rE   
includeFeeBITCOINLITECOINETHEREUM	TETHERUSO	TETHERUSL	TETHERUSX	TETHERUSSTETHERUSDTAVAXTETHERUSDTSOLTETHERUSDTALGTETHERUSDTBCHTETHERUSDTKSMTETHERUSDTDVFTETHERUSDTOMG)BTCLTCERC20OMNILIQUIDTRC20EOSAVAXSOLALGOBCHKSMDVFOMG	TETHERUSEr   )	precisionexchangeTypes
orderTypesfiatv2AccountsByTyper   networksnetworksByIdfeatures)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyRequiresPricemarketBuyByCostselfTradePreventionicebergmaxK   	  i )r  r   daysBack	untilDayssymbolRequired)r  triggerr  r$  )r  r   r%  r  r$  )r  r   r"  daysBackCanceledr#  r%  r  r$  '  )	sandboxrQ   createOrdersrz   r   r   fetchOrdersrc   r{   extendsdefault)linearinverse)r,  rC   rE   rF   
exceptions)110101000110020101001011420060temporarily_unavailable)zavailable balance is onlyznot enough exchange balancezOrder not foundzsymbol: invalid)exactbroadcommonCurrenciesUSTUSDTEUTF0EURTUSTF0ALGr   AMPAMPLATOATOMBCHABCXECBCHNr   DATDATADOGMDOGEDSHDASHEDOPNTEUSEURSEUTHTXHTIDXIDIOTIOTAIQXIQLUNALUNCLUNA2MNAMANAORSz	ORS GroupPASPASSQSHQASHQTMQTUMRBTRBTCSNGSNGLSSTJSTORJTERRAUSTUSTCTSDTUSDYGGYEEDYYWYOYOWUDCUSDCVSYVSYSWAXPXCHFZB)WAXXCHZBT)deep_extendsuperr4   describeparse_numberr1   r*   r"   r$   r!   r-   r,   r+   r&   r(   r%   )self	__class__s    U/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/async_support/bitfinex.pyr  bitfinex.describe#   s   h > @ JC
*JC
JJC
 $JC
 t	JC

 JC
 4JC
  XXX $X 	X
 %X %X UX $UX 'X "4X tX X 'X #DX $TX  t!X" &t#X$ (%X& ''X( ()X* "4+X, ,T-X. -e/X0 %d1X2 T3X4 5X6 &u7X8 "59X: +E;X< )%=X> #E?X@ ,UAXB #DCXD $TEXF 'GXH (IXJ "4KXL &tMXN (OXP 1%QXR +DSXT &uUXV #JWXX *4YXZ $T[X\ "5]X^ *5_X` +EaXb tcXd  eXf %egXh $TiXj "5kXl +EmXn !%oXp  qXr dsXt $TuXv +DwXx %dyXz !${X| "4}X~ dX@ !$AXB "5CXD #DEXF  GXH $UIXJ !$KXL )%MXN tOXP QXR USXT "5UXV #DWXX 'YXZ $Z[X\ ]X^ #E_X` &uaXb ucXd TeXf  gXh "5iXj %kXl ! oXJC
B CJC
b cJC
d i4<9
 28F 8eJC
@ ?'?4c? >s? 0	?
 9#? 9#? 4S? 6s? 5c? 5c? 5c? 9#? 7? 1#? 1#?  :3!?" 1##?$ 6s%?& 4S'?( 5c)?* 5c+?, 1#-?. :3/?0 -c1?2 5c3?4 235?6 (7?8 *19?: "3;?< *3=?> '??@ /A?B 4QC?D +AE?F +AG?H +AI?J +AK?L +AM?N HO?P CCQ?R CCS?T A#U?V <SW?X <SY?Z A#[?\ A#]?^ B3_?` B3a?b PQTc?d Ge?f B3g?h DG),(+69-/ILDG&)4779%&}?B +.#&CEN  K )#K .s	K
 (K 1#K .sK .sK .sK -cK 4SK 6sK -cK <SK 6sK  -c!K" 9##K$ .s%K& 3C'K( 23)K* 5c+K, +C-K. 0/K0 4S1K2 83K4 05K6 1#7K8 09K: 6s;K< 9#=K> 0?K@ 9#AKB 6sCKD 6sEKF :3GKH /IKJ .sKKL .sMKN >sOKP 5cQKR /SKT 4SUKV 8WKX =cYKZ 1#[K\ 6s]K^ :3_K` ?aKb >scKd 5ceKf 4SgKh +CiKj )#kKl -cmKn -coKp 'qKr ,SsKt *3uKv 1"wKx 1"yKz *2{K| ;C}K~ 0K@ (AKB +CCKD B3EKF CCGKH 0IKJ .sKKL *3MKN 03-0,.,/UKMOUAJC
l $"&!%!..w7!..w7 "..s3T5F5Fw5OP!..x8$:K:KG:TU!..y94;L;LW;UV!..y94;L;LW;UV!..y94;L;LW;UV!..y94;L;LW;UV!..z:D<M<Mh<WX!..z:D<M<Mh<WX!..z:D<M<Mh<WX!..z:D<M<Mh<WX!..z:D<M<Mg<VW" "..s3T5F5Fw5OP!..x8$:K:KH:UV!..y94;L;LX;VW!..y94;L;LX;VW!..y94;L;LX;VW!..y94;L;LS;QR!..z:D<M<Mc<RS!..z:D<M<Mc<RS!..z:D<M<Mc<RS!..z:D<M<Mc<RS!..z:D<M<Mc<RS""H I'mJC
|	 /}	JC
~	 !
 ''/$&-%- %,+2$+"( 0-
 !     ' *(&#+&$% !% %%'')(&,*+****"  !CD	JC
H $&*(,,0,1)-+/6:#'#'"&#(	( #($($(27+//4#()$. r% ',!%$(%+*/& ',#($)*/	# ',!%#($)*/( $(&+!%$(,0%+#($)*/	*  #u=~ y
 "9  $	 ##QLIJC
b .-'0)*/C	 2C3D'4'0	cJC
F  &!v&!&! &! v	&!
 v&! v&! %&! &! v&! w&! v&! u&! v&! v&! t&!  t!&!" v#&!$ t%&!& '&!( )&!* v+&!, {-&!. v/&!0 v1&!2 v3&!4 v5&!6 w7&!8 w9&!: F;&!< v=&!> v?&!@ wA&!B vC&!D vE&!F K&!GJC
 J J	    c                 $    XR                   S   ;   $ )Nr  )r   r  codes     r  is_fiatbitfinex.is_fiat0  s    ||F++,r  c                     SU-   $ )Nf r  s     r  get_currency_idbitfinex.get_currency_id3  s    Tzr  c                     XR                   S   ;   a  U R                   S   U   $ [        U R                  S-   U-   S-   5      e)NcurrencyNames z not supported for withdrawal)r   r)   r8   r  s     r  get_currency_namebitfinex.get_currency_name6  sC    <<00<<066477S=4/2QQRRr  c                     U R                  U5      nU R                  U[        U R                  U   S   S   [        5      $ )Nr  amount)safe_symboldecimal_to_precisionr/   marketsr0   )r  symbolr  s      r  amount_to_precisionbitfinex.amount_to_precision<  sA     !!&)((4<<;OP[;\]e;fhvwwr  c                     U R                  U5      nU R                  U[        U R                  U   S   S   U R                  5      nU R                  U[
        S[        5      $ )Nr  pricer   )r  r  r.   r  r   r/   r0   )r  r  r  s      r  price_to_precisionbitfinex.price_to_precisionC  s\    !!&)))%V8L[8YZa8bdhdvdvw
 ((!^LLr  c                    #    U R                  U5      I Sh  vN nU R                  US5      nU R                  SSS.X35      SSSUS.$  N17f)a1  
the latest known information on the availability of the exchange API

https://docs.bitfinex.com/reference/rest-public-platform-status

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
Nr   maintenanceok)r   1)statusupdatedetaurlinfo)publicGetPlatformStatussafe_string)r  paramsresponse	statusRaws       r  fetch_statusbitfinex.fetch_statusL  s\      55f==$$Xq1	&&]'F	]
 	
 >s   AA	2Ac                 .  #    U R                  U5      nU R                  U5      nU R                  U5      n[        R                  " X#U/6 I Sh  vN u  pVnU R                  US/ 5      nU R                  US/ 5      nU R                  XV5      nU R                  US/ 5      n/ n	[        S[        U5      5       GHT  n
X   nU R                  US5      nU R                  US0 5      nSnUR                  S5      S:  a  SnU(       + nSnSnUR                  S5      S:  a  UR                  S5      nUS   nUS   nO
USS nUSS	 nU R                  U5      nU R                  U5      nUR                  S5      nUR                  S5      nU R                  US5      nU R                  US5      nUS
-   U-   nU R                  U5      nU R                  U5      nSnSnU(       a  UnUnUS-   U-   nU R                  US5      nU R                  US5      nSnU(       a  U R!                  X5      (       a  SnU	R#                  0 SSU-   _SU_SU_SU_SU_SU_SU_SU_SU(       a  SOS_SU_SU_SU_SS_SS_SS_SU_SU(       a  SOS_U(       a  SOSU(       a  U R%                  S5      OSSSSS['        S5      ['        S 5      S!.SSS".U R%                  U5      U R%                  U5      S".U R%                  S#5      SS".SSS".S$.SUS%.
E5        GMW     U	$  GN7f)&z
retrieves data on all markets for bitfinex

https://docs.bitfinex.com/reference/rest-public-conf

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
Nr   r   TF0F:      /   r8   tr  basequotesettlebaseIdquoteIdsettleIdtyperC   rE   rD   rF   rG   activecontractr-  r  85)r  r  minr  z1e-8)r  r  r  cost)
r.  contractSizeexpiryexpiryDatetimestrike
optionTyper  limitscreatedr  )publicGetConfPubInfoPairpublicGetConfPubInfoPairFuturespublicGetConfPubListPairMarginasynciogather	safe_listarray_concat
safe_valuerangelensafe_string_upperfindsplitsafe_currency_coder  r  in_arrayappendr  int)r  r  spotMarketsInfoPromisefuturesMarketsInfoPromisemarginIdsPromisespotMarketsInfofuturesMarketsInfo	marginIdsr  resultipairr8   r   rC   rE   r  r  partsr  r  	splitBase
splitQuoter  r  r  minOrderSizeStringmaxOrderSizeStringrD   s                                r  fetch_marketsbitfinex.fetch_marketsc  s     "&!>!>v!F$($H$H$P!>>vF?F~~Pf  DT  PU  @V  :V6Y..!R@!^^,>2F##OHOOIq"5	( q#g,'A:D''a0B__T1b1FDwwt}!8DFGwws|q q(AaQq'**62D++G4E

4(IT*J##Iq1D$$Z3ECZ%'F))&1F**73GFH #.!%!1!1&!!<!%!1!1&!!<Fb44MM 0cBh0&0 0 	0
 &0 &0 70 H0 $F0 0 &0 0 %0 %0 $0  D!0" $$D#0$ %)5d:> 1 1# 6D"&"!#h X  $#!
  $001CD#001CD
  $008#
  $#$  _0 0K (l _ :Vs   ALLKLc                 8  #    / SQnSR                  U5      nSU0nU R                  U R                  XA5      5      I Sh  vN nU R                  U R	                  US/ 5      S5      U R                  U R	                  US/ 5      S5      U R                  U R	                  US/ 5      S5      U R                  U R	                  US	/ 5      S5      U R                  U R	                  US
/ 5      S5      U R                  U R	                  US/ 5      S5      U R                  U R	                  US/ 5      S5      U R	                  US/ 5      U R                  U R	                  US/ 5      S5      S.	n0 n[        S[        US   5      5       Hh  nUS   U   n	U R                  U	S5      n
U R	                  U	S5      nU R                  US5      nU R	                  X|/ 5      nUR                  U
5        XU'   Mj     U R	                  US/ 5      n0 n[        S[        U5      5       GH  nX   nUR                  S5      (       a  M   U R                  U5      nU R	                  US   U/ 5      nU R                  US5      nU R	                  US   U/ 5      nU R                  US5      nUSL=(       d    UUS   ;   nSnU(       a  SnU R	                  US   U/ 5      nU R	                  US/ 5      nU R                  US5      nU R	                  US   U/ 5      nSnSU-   nU R	                  US   U/ 5      nU R                  US5      S:H  nU R                  US5      S:H  n 0 n!U R	                  UU/ 5      n"[        S[        U"5      5       H;  n#U"U#   n
U R                  U
5      n$U
U
R                  5       U
SSSSSSSSS.0S.	U!U$'   M=     U R                  UUUUUUUU/UUSUU U[!        U5      U R#                  U R%                  U5      5      SS.USS.S.U!S .5      UU'   GM     U$  GN7f)!z
fetches all available currencies on an exchange

https://docs.bitfinex.com/reference/rest-public-conf

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
)
zpub:list:currencyzpub:map:currency:symzpub:map:currency:labelzpub:map:currency:unitzpub:map:currency:undlzpub:map:currency:poolzpub:map:currency:explorerzpub:map:currency:tx:feezpub:map:tx:methodzpub:info:tx:status,configNr   r      r  r     r     r   	   )	symlabelunitundlpoolexplorerr   r	  statusesr	  r  r  r  r  cryptor   r  r  r  r  r   r  )	r  r8   networkr  depositr   feer  r  T)r  r   )r8   uppercaseIdr  r  r  r9   r  r   r   r  r  r  r	  )joinpublicGetConfConfigextendindex_byr  r  r  r  r  endswithr  safe_numbersafe_integernetwork_id_to_codelowersafe_currency_structurer  r  parse_precision)%r  r  labelsr  requestr  indexedindexedNetworksr  
networkObj	networkId
valuesListnetworkNamenetworksListidsr  r8   r  r  r9   r  rawTypeisCryptoCoinr  	feeValuesr   r  r  r  fid
dwStatusesdepositEnabledwithdrawEnabledr	  	netwokIdsjr  s%                                        r  fetch_currenciesbitfinex.fetch_currencies  sL    
 &!f
 11$++g2NOOj ==!R!@!D]]4>>(Ar#BAFMM$..1b"A1EMM$..1b"A1EMM$..1b"A1EdnnXq"&EqIMM$..1b"A1ExB7dnnXq"&EqI

 !#q#gj123A ,Q/J((Q7I
A6J**:q9K>>/KL	*+7K( 4 nnXq"-q#c(#AB{{4  **2.DNN77#3R<E##E1-D>>'&/2r:D&&tQ/G#4/OR7:;N5NLDwvB?I>>)Q3D""4+C>>'&/2r:DI(C
(;RDJ!..z1=BN"//
A>!COHB?I1c)n-%aL	11)<%#//+("# $!%"#'#'%%! .&  77!UD)T:)+ ^  $001E1Ei1PQ#
  ##!	 %-9 F4LY $H _ Ps   =PP OPc                   #    U R                  5       I Sh  vN   U R                  U R                  S0 5      nU R                  USS5      nU R                  X#U5      nUcC  [	        UR                  5       5      n[        U R                  S-   SR                  U5      -   5      eUS:H  nU R                  US5      nU R                  U5      I Sh  vN nSU0n	[        S	[        U5      5       H  n
X   nU R                  5       nU R                  US
5      nUS:w  a  XS'   U R                  US	5      nU R                  USS5      n[        U5      S-
  nUUS S:H  nU(       + =(       d    UnXN:X  d  M  U(       d  M  U R                  U5      nU R                  US5      US'   U R                  US5      US'   XU'   M     U R!                  U	5      $  GN GN7f)a9  
query for balance and get the amount of funds available for trading or funds locked in orders

https://docs.bitfinex.com/reference/rest-auth-wallets

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nr  r  r   z. fetchBalance() type parameter must be one of , r   r  r   r  r   debtr    r  f0totalr  free)load_marketsr  r   r  listkeysr    r8   r  omitprivatePostAuthRWalletsr  r  accountsafe_string_lowerr  safe_balance)r  r  accountsByTyperequestedTypeaccountTyper,  isDerivativequeryr  r  r  balancer/  interestr  
currencyIdstartisDerivativeCodederivativeConditionr  s                       r  fetch_balancebitfinex.fetch_balance  s     !!!7I2N((D&&~mT++-.D*Z Z]a]f]fgk]l lmm$5		&&)55e<<)q#h-(AkGllnG''3H3"*##GQ/D//B?J
Oa'E)%&1T9'3#3#G7G#)<)<..z:#'#3#3GQ#? "&"2"27A">&t! )"   ((9 	" =s0   GGB7GGBG1G:AGGr  r  fromAccount	toAccountc                   #    U R                  5       I Sh  vN   U R                  U R                  S0 5      nU R                  Xc5      nUcC  [	        UR                  5       5      n[        U R                  S-   SR                  U5      -   5      eU R                  Xd5      n	U	cC  [	        UR                  5       5      n[        U R                  S-   SR                  U5      -   5      eU R                  U5      n
U R                  X5      nU R                  X5      nU R                  X5      nUUUUU	S.nU R                  U R                  X5      5      I Sh  vN nU R                  US5      nUS:X  a^  U R                  US	S
5      nU R                  U R                  S   UU R                  S-   U-   5        [!        U R                  S-   U-   5      eU R#                  SU0U
5      $  GN N7f)a  
transfer currency internally between wallets on the same account

https://docs.bitfinex.com/reference/rest-auth-transfer

:param str code: unified currency code
:param float amount: amount to transfer
:param str fromAccount: account to transfer from
:param str toAccount: account to transfer to
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
Nr  z' transfer() fromAccount must be one of r$  z% transfer() toAccount must be one of )r  currencycurrency_tofromtor   errorr  r&  r7  r  r  )r*  r  r   r  r+  r,  r#   r8   r  rB  convert_derivatives_idcurrency_to_precisionprivatePostAuthWTransferr  throw_exactly_matched_exceptionr/  r    parse_transfer)r  r  r  r?  r@  r  r2  fromIdr,  toIdrB  fromCurrencyIdtoCurrencyIdrequestedAmountr  r  rF  messages                     r  r   bitfinex.transfer  s     !!!7I2N!!.>>++-.D#DGG.W$WZ^ZcZcdhZi$ijj:<++-.D#DGG.U$UX\XaXabfXg$ghh==&44XK228G44TB &&'
 66t{{77STT,   1-G&&xB7G001I7TXT[T[^aTadkTkl# 788""Hh#7BBe 	", Us#   G)G$D>G)G'BG)'G)Nr   rB  c           
         U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n	S UU R	                  U5      U R                  U	5      U R                  US5      U R                  X5      UUUS	.	$ )
Nr  r   r  r   r  r  r  r  )	r8   	timestampdatetimer  r  rB  r?  r@  r  )r  r	  r  r  iso8601parse_transfer_statusr  r  )
r  r   rB  r  rT  r  r?  r@  r9  r  s
             r  rK  bitfinex.parse_transfer  s    0 (3%%fa0	vq)&&tQ/$$T1-	%%dA.
!!&!,"Y/008&&tQ///
E&"

 
	
r  r  c                 2    SSSS.nU R                  X!U5      $ )Nr  failed)SUCCESSERRORFAILUREr  r  r  r  s      r  rW  bitfinex.parse_transfer_statusA  s'    

 &99r  c                 *   U R                  US5      nU R                  US5      nU R                  US/ 5      nS nUS:X  a6  U R                  USU5      n[        U5      S-
  nXgS  S:H  nU(       d  US-   nU$ US:w  a  U R                  USU5      nU$ UnU$ )	Nr  r   r  r   r  r  rD   r   )r  r  r  )	r  rB  r  r  
transferId
underlyingr9  r:  r;  s	            r  rG  bitfinex.convert_derivatives_idI  s     x0%%dA.
__T1b1

= ))*aDJ
Oa'E)&1T9#'$.

 	 X))*aDJ  $Jr  r  r   c                 (  #    U R                  5       I Sh  vN   U R                  U R                  SS5      nU R                  U5      nUS   US.nUb  X&S'   U R	                  Xc5      nU R                  U5      I Sh  vN nU R                  5       n	US   / / U	U R                  U	5      SS.n
US   S:X  a  S	OS
n[        S
[        U5      5       H  nX   nU R                  X5      nU R                  US5      n[        R                  " U5      n[        R                  " US5      (       a  SOSnU
U   nUR                  XR!                  U5      /5        M     U R#                  U
S   S
S5      U
S'   U R#                  U
S   S
5      U
S'   U
$  GNv GN7f)a  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://docs.bitfinex.com/reference/rest-public-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, bitfinex only allows 1, 25, or 100
: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
Nr  r   r8   )r  r  r  r  )r  bidsasksrT  rU  noncer   r   r  r   rf  rg  T)r*  r  r   r   r  publicGetBookSymbolPrecisionmillisecondsrV  r  r  r  r  r2   
string_abs	string_gtr  r  sort_by)r  r  r   r  r  r   r  fullRequest	orderbookrT  r  
priceIndexr  orderr  signedAmountr  side
resultSides                      r  fetch_order_bookbitfinex.fetch_order_book_  s     !!!OODLL+tD	V$Tl"
 "ENkk'2;;KHH	%%'	X&"Y/
 '{3t;Q!
q#i.)ALE$$U7E++E15L''5F$..|SAA6vDJu&7&7&?@A * fVna>vfVna8v? 	" Is#   FFA&F=F>DFFtickerr   c                 l   [        U5      nUS:H  =(       d    US:H  nS nSnSnU(       a  SnUS:H  nO(U R                  US5      nU R                  X5      nUS:H  nU R                  S U5      nS n	S n
S nS nS nS nS nS nU(       a  U R                  USU-
  5      n	U R                  USU-
  5      n
U R                  USU-
  5      nU R                  US	U-
  5      nU R                  US
U-
  5      nU R                  USU-
  5      nU R                  USU-
  5      nU R                  USU-
  5      nOU R                  USU-
  5      n	U R                  USU-
  5      n
U R                  USU-
  5      nU R                  USU-
  5      nU R                  USU-
  5      n[        R
                  " US5      nU R                  US	U-
  5      nU R                  US
U-
  5      nU R                  USU-
  5      nU R                  0 SU_SS _SS _SU_SU_SU
_SS _SU_SS _SS _SS _SU	_SU	_SS _S U_S!U_S"S _US US#.EU5      $ )$Nr   r   r   Fr      r  r  r   r           r  r  r  100r  rT  rU  highlowbid	bidVolumeask	askVolumevwapopencloselastpreviousClosechanger   average)
baseVolumequoteVolumer  )r  r  safe_marketr  r2   
string_mulsafe_ticker)r  rw  r   lengthisFetchTickerr  
minusIndexisFundingCurrencymarketIdr  r  r  r  r   volumer~  r  s                    r  parse_tickerbitfinex.parse_ticker  s   R V286R<
!J!'2''2H%%h7F!'2!!$/
##FBO<D""61z>:C""61z>:C%%fa*n=F))&!j.AJ%%fb:o>F##FBO<D""62
?;C ##FA
N;D""61z>:C""61z>:C%%fa*n=F))&!j.AJ ++J>J%%fa*n=F##FA
N;D""62
?;C !
f!
!
 !
 D	!

 3!
 3!
 !
 3!
 !
 D!
 D!
 T!
 D!
 T!
 f!
  *!!
" t#!
$ !)!
* + 	r  symbolsc                 6  #    U R                  5       I Sh  vN   U R                  U5      n0 nUb&  U R                  U5      nSR                  U5      US'   OSUS'   U R	                  U R                  X25      5      I Sh  vN nU R                  XQ5      $  N~ N7f)a  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://docs.bitfinex.com/reference/rest-public-tickers

:param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr  r  ALL)r*  market_symbols
market_idsr  publicGetTickersr  parse_tickers)r  r  r  r  r  r   s         r  fetch_tickersbitfinex.fetch_tickers  s      !!!%%g.//'*C!$#GI!&GI--dkk'.JKKP !!'33a 	" Ls"   BBA(B?B BBc                    #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  XS5      $  NU N7f)a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://docs.bitfinex.com/reference/rest-public-ticker

: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>`
Nr  r8   )r*  r   publicGetTickerSymbolr  r  )r  r  r  r   r  rw  s         r  fetch_tickerbitfinex.fetch_ticker1  sq      !!!V$fTl
 11$++g2NOO  00 	"
 Ps!   A0A,?A0A.A0.A0tradec                 r   U R                  US/ 5      n[        U5      nUS:  nU R                  US5      nU(       a  SOSnS nU R                  X75      n	U(       a  SOSn
U R                  X:5      nU	S   S:X  a  Sn[        R                  " U	5      n	OS	nS nS nS nS nU R                  S U5      nU(       a  SOS
nU R                  UU5      nU(       a  US
   nU R                  U5      nU R                  US5      nU R                  US5      nUS
:X  a  SOSnU R                  US5      n[        R                  " U5      nU R                  US5      nU R                  U5      nUUS.nUS   nU R                  U R                  S   U5      nU R                  UUU R                  U5      UUUUUUU	S UUS.U5      $ )Nr  r  r   r  r  r  -sellbuyr   r   r   r   r  r   )r  rB  r  r  )r8   rT  rU  r  rq  rs  r  takerOrMakerr  r  r  r  r  )r  r  r  r2   rk  r  r	  
string_negr  r   
safe_traderV  )r  r  r   	tradeListtradeLength	isPrivater8   amountIndexrs  amountStringrp  priceStringorderIdr  r  r  r  timestampIndexrT  r  r   feeCostStringfeeCurrencyIdfeeCurrency	orderTypes                            r  parse_tradebitfinex.parse_tradeC  s   8 NN5(B7	)n 1_	i+$a!''	?#Q
&&y=?c!D"--l;LD!!$/'Q%%i@	 |H%%h/F&&y!4G%%i3E',z7L ,,Y:M#..}=M ,,Y;M11-@K%'C "!I##DLL$A9MD"Y/( " 
  	r  sincec                 V  #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX4S5      I Sh  vN $ U R                  U5      nSnSUS   0nUb  X(S	'   S
nUb  [	        US5      US'   XxS'   U R                  SX5      u  pU R                  U R                  X5      5      I Sh  vN n	U R                  U	S5      n
/ n[        S[        U
5      5       H  nUR                  SX   05        M     U R                  XSU5      $  GN N Na7f)a'  
get the list of most recent trades for a particular symbol

https://docs.bitfinex.com/reference/rest-public-trades

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch, default 120, max 10000
: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 [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:param int [params.until]: the latest time in ms to fetch entries for
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
NFfetchTradespaginater'  z-1r  r8   r:  r  r   sortendr   r   r  )r*  handle_option_and_paramsfetch_paginated_call_dynamicr   r  handle_until_optionpublicGetTradesSymbolHistr  rm  r  r  r  parse_trades)r  r  r  r   r  r  r   r  r  r  trades
tradesListr  s                r  fetch_tradesbitfinex.fetch_trades  sC     !!!88PZ[::=&Y^hmnnnV$fTl
 $GD"5%0GG225'J77G8TUU h*
q#f+&Ax34 '  T5AAA 	" o Vs5   D)D"9D)D%A4D)D'AD)%D)'D)r   d   	timeframec           	        #    U R                  5       I Sh  vN   SnU R                  USS5      u  peU(       a  U R                  SXXBUS5      I Sh  vN $ U R                  U5      nUc  SnO[	        US5      nUS   U R                  U R                  X"5      SUS.nUb  X8S	'   U R                  S
X5      u  pU R                  U R                  X5      5      I Sh  vN n	U R                  XX#U5      $  N N N7f)a  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://docs.bitfinex.com/reference/rest-public-candles

: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, default 100 max 10000
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int[][]: A list of candles ordered, open, high, low, close, volume
:param int [params.until]: timestamp in ms of the latest candle to fetch
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
NFr{   r  r'  r8   r   )r  r  r  r   r:  r  )r*  r  "fetch_paginated_call_deterministicr   r  r  r   r  (publicGetCandlesTradeTimeframeSymbolHistr  parse_ohlcvs
r  r  r  r  r   r  r  r   r  r  s
             r  fetch_ohlcvbitfinex.fetch_ohlcv  s     !!!88zZ@@v^cpvx}~~~V$=Eu%ETl))$//9P	
 $G225'JFFt{{SZGcdd   9UKK7 	"  es4   C9C3:C9C5B	C9C7C95C97C9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  r  r  )r	  r  )r  ohlcvr   s      r  parse_ohlcvbitfinex.parse_ohlcv  sn     eQ'UA&UA&UA&UA&UA&
 	
r  c                     Uc  U$ UR                  S5      nU R                  US5      nSSSSSSSSSSS.
nU R                  XCU5      $ )Nr  r   r  closedcanceledrejected)
ACTIVE	PARTIALLYEXECUTEDCANCELEDINSUFFICIENTzPOSTONLY CANCELEDRSN_DUST	RSN_PAUSEzIOC CANCELEDzFILLORKILL CANCELED)r  r  )r  r  r  stater  s        r  parse_order_statusbitfinex.parse_order_status  sf    >MS!  * "&!+"#&#-
 88r  c                 :    S/S/SS/S.nU R                  X!S 5      $ )N
reduceOnlypostOnly)102440965120)r  )r  flags
flagValuess      r  parse_order_flagsbitfinex.parse_order_flags  s0     "NL!:.

 z$77r  c                 4    SSSSS.nU R                  X!S5      $ )Nr  r  )r   r   r  r  GTCr^  )r  r  r  s      r  parse_time_in_forcebitfinex.parse_time_in_force$  s*    !!	

 
u==r  rq  c                    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[        R
                  " U R                  US5      5      nU R                  US5      n	[        R
                  " U	5      n
[        R                  " U	S5      (       a  SOS	nU R                  US
5      nU R                  U R                  U R                  S5      U5      nU R                  U5      nU R                  US5      nU R                  U5      nSnUb)  [        S[        U5      5       H  nUU   S:X  d  M  SnM     U R                  US5      nS nUS:X  d  US:X  a,  S nU R                  US5      nUS:X  a  U R                  US5      nS nU R                  US5      nUb2  UR                  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                  0 SU_SU_SU_SU_SU R!                  U5      _SS _SU_SU_S U_SU_S!U_S"U_S#U_S$U
_S%S _S&U_S'S _UUS S S(.EU5      $ ))Nr  r   r  r  r  r  r   r  r  r   r  r{  Fr  Tr   r   r      r|   @ ry  r  r  r8   clientOrderIdrT  rU  lastTradeTimestampr  r  r  rs  r  r  r  r  r  filled)	remainingr  r  r  )r  r  r  r	  r2   rk  	string_ltr  r   r  r  r  r  r  r  
safe_orderrV  )r  rq  r   	orderListr8   r  r  rT  r  rr  r  rs  r  r  r  rawFlagsr  r  r  r  r  r  statusStringr  r  r  s                             r  parse_orderbitfinex.parse_order-  s   NN5(3	i+##Iq1!!(+ %%i3	&&t'7'7	1'EF	''	15##L1 **<==v5$$Y2	o NPYZ..y9##Ir2&&x01c%j)8z)#H *   B/(i;P.PE++Ir:L11((B7''	26# &&u-E,,T-=-=eQ-GHF""9b1((A6  
I 
" 
 ] 
 	 

 Y/ 
 !$ 
 f 
 D 
 ; 
  
 D 
 U 
 L 
 f 
 D 
  w! 
" d# 
$ #+ 
, - 	r  r  rs  r  c                 ~   U R                  U5      nU R                  X5      nUS:X  a  UO[        R                  " U5      nUS   US.n	U R	                  USS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
S	5      nU R                  USS5      nUR                  5       nUb  SnXS'   O6U
b3  U R                  X5      U	S'   US:X  a  SnU R                  X5      U	S'   OSnUS:H  nUS:H  nU=(       d    US:H  nU(       d  U(       a  Uc  [        U R                  S-   5      eU(       d  U(       a  US:X  a  [        U R                  S-   5      eUS:w  a  U
c  U R                  X5      U	S'   U(       a  SnO	U(       a  SnSnU R                  SU5      u  nnUS   (       a  Uc  SU-   nUU	S'   SnU(       a  U R                  US 5      nU(       a  U R                  US!5      nUS:w  a  UU	S"'   Ub  XS'   U R                  U/ S#Q5      nU R                  X5      $ )$a  
@ignore
       helper function to build an order request
       :param str symbol: unified symbol of the market to create an order in
       :param str type: 'market' or 'limit'
       :param str side: 'buy' or 'sell'
       :param float amount: how much you want to trade in units of the base currency
       :param float [price]: the price of the order, in units of the quote currency, ignored in market orders
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :param float [params.triggerPrice]: The price at which a trigger order is triggered at
       :param str [params.timeInForce]: "GTC", "IOC", "FOK", or "PO"
       :param bool [params.postOnly]:
       :param bool [params.reduceOnly]: Ensures that the executed order does not flip the opened position.
       :param int [params.flags]: additional order parameters: 4096(Post Only), 1024(Reduce Only), 16384(OCO), 64(Hidden), 512(Close), 524288(No Var Rates)
       :param int [params.lev]: leverage for a derivative order, supported by derivative symbol orders only. The value should be between 1 and 100 inclusive.
       :param str [params.price_traling]: The trailing price for a trailing stop order
       :param str [params.price_aux_limit]: Order price for stop limit orders
       :param str [params.price_oco_stop]: OCO stop price
       :returns dict: an `order structure <https://github.com/ccxt/ccxt/wiki/Manual#order-structure>`
       r  r8   )r  r  	stopPricer  trailingAmountr  r  Fr  cidr  NzTRAILING STOPprice_trailingr  r   z
STOP LIMITprice_aux_limitSTOPr  r  r  z@ createOrder() requires a price argument with IOC and FOK ordersr   z7 createOrder() does not allow market IOC and FOK ordersrQ   rC   z	EXCHANGE r  r         r  )r  r  r  r  r  r  r  )r   r  r2   r  safe_string_2r  	safe_boolsafe_value_2upperr  r'   r8   handle_margin_mode_and_paramssumr-  r  )r  r  r  rs  r  r  r  r   r  r  r  r  r  postOnlyParamr  r  r  iocfokr  r  r  s                         r  create_order_requestbitfinex.create_order_requesti  s]   * V$//?(,|G<N<N|<\Tl"
 ))&+~N))&2BC&&v}=vz5A^^FL%@
))&%IJJL	%'I(6$%%#66vLGGw(	-1-D-DV-S)*"	e#e#!:kT&93U]tww)kkll3TX-tww)bbccH<#7#66vEGGII
!??vV
F&>z1#i/I#HHUD)EHHUD)EA:$GG$*EN6  $M  N{{7++r  c                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  XX4XV5      nU R                  U5      I Sh  vN n	U R	                  U	S5      n
U
S:w  a7  U	S   nU	S   n[        U R                  S-   U	S   -   S-   U-   S-   U-   S	-   5      eU R                  U	S
/ 5      nU R                  US5      nSU0nU R                  X5      $  N N7f)a!  
create an order on the exchange

https://docs.bitfinex.com/reference/rest-auth-submit-order

:param str symbol: unified CCXT market symbol
:param str type: 'limit' or 'market'
:param str side: 'buy' or 'sell'
:param float amount: the amount of currency to trade
:param float [price]: price of the order
:param dict [params]: extra parameters specific to the exchange API endpoint
:param float [params.triggerPrice]: the price that triggers a trigger order
:param str [params.timeInForce]: "GTC", "IOC", "FOK", or "PO"
:param boolean [params.postOnly]: set to True if you want to make a post only order
:param boolean [params.reduceOnly]: indicates that the order is to reduce the size of a position
:param int [params.flags]: additional order parameters: 4096(Post Only), 1024(Reduce Only), 16384(OCO), 64(Hidden), 512(Close), 524288(No Var Rates)
:param int [params.lev]: leverage for a derivative order, supported by derivative symbol orders only. The value should be between 1 and 100 inclusive.
:param str [params.price_aux_limit]: order price for stop limit orders
:param str [params.price_oco_stop]: OCO stop price
:param str [params.trailingAmount]: *swap only* the quote amount to trail away from the current market price
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr  r[  r  r  r  : (#)r  r   r  )	r*  r   r  privatePostAuthWOrderSubmitr  r    r8   r  r  )r  r  r  rs  r  r  r  r   r  r  r  	errorCode	errorTextordersrq  newOrders                   r  create_orderbitfinex.create_order  s     . !!!V$++F$V99'BB` !!(A.Y I I# ;d BY NQU UXa adg ghh!R0vq)e$11w 	" Cs"   C%C!<C%C#BC%#C%r  c           	        #    U R                  5       I Sh  vN   / n[        S[        U5      5       H  nX   nU R                  US5      nU R                  US5      nU R                  US5      nU R	                  US5      n	U R	                  US5      n
U R                  US0 5      nU R                  XgXX5      nUR                  S	U/5        M     S
U0nU R                  U5      I Sh  vN n/ nU R                  US/ 5      n[        S[        U5      5       H#  nUU   nUS   nUR                  SUS   05        M%     U R                  U5      $  GN9 Ni7f)a  
create a list of trade orders

https://docs.bitfinex.com/reference/rest-auth-order-multi

: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>`
Nr   r  r  rs  r  r  r  onopsr  r  )r*  r  r  r  r  	safe_dictr  r  privatePostAuthWOrderMultir  parse_orders)r  r  r  ordersRequestsr  rawOrderr  r  rs  r  r  orderParamsorderRequestr  r  resultsdataentryindividualOrders                      r  create_ordersbitfinex.create_orders  sf     !!!q#f+&AyH%%h9F##Hf5D##Hf5D%%h9F$$Xw7E..8R@K44V4QVdL!!4"67 ' >
 88AA4 ~~h2.q#d)$AGE#AhONNHoa&89: %   ))_ 	" Bs#   EECE(E)A'EEc                 H  #    U R                  5       I Sh  vN   SS0nU R                  U R                  X25      5      I Sh  vN nU R                  US/ 5      n/ n[	        S[        U5      5       H  nUR                  SXW   05        M     U R                  U5      $  N N]7f)a  
cancel all open orders

https://docs.bitfinex.com/reference/rest-auth-cancel-orders-multiple

:param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nallr   r  r   r  )r*   privatePostAuthWOrderCancelMultir  r  r  r  r  r%  )r  r  r  r  r  r  
ordersListr  s           r  cancel_all_ordersbitfinex.cancel_all_ordersF  s      !!!1
 >>t{{7?[\\!R0
q#f+&Ax34 '  ,, 	" ]s"   B"B+B"B AB" B"r8   c                   #    U R                  5       I Sh  vN   U R                  USS5      nSnSnUb  U R                  U5      nUbG  U R                  US5      nUc  [	        U R
                  S-   5      eUUS.nU R                  USS/5      nOS[        U5      0nU R                  U R                  XS5      5      I Sh  vN nU R                  US5      n	S	U	0n
U R                  X5      $  N N-7f)
aA  
cancels an open order

https://docs.bitfinex.com/reference/rest-auth-cancel-order

:param str id: order id
:param str symbol: Not used by bitfinex cancelOrder()
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr  r  cidDatez\ canceling an order by clientOrderId('cid') requires both 'cid' and 'cid_date'('YYYY-MM-DD'))r  cid_dater8   r  r  )r*  r  r   r  r'   r8   r-  r  privatePostAuthWOrderCancelr  r  )r  r8   r  r  r  r  r   r7  r  rq  r  s              r  cancel_orderbitfinex.cancel_order[  s     !!!?[[(F?oofi8G"477  .L  $L  M  M#G YYv'?@F c"gG 99$++g:VWW!,e$11- 	"& Xs"   C0C,B)C0 C.,C0.C0r  c                   #    U R                  5       I Sh  vN   / n[        S[        U5      5       H%  nUR                  U R	                  X   5      5        M'     SU0nSnUb  U R                  U5      nU R                  U R                  Xc5      5      I Sh  vN nU R                  US/ 5      n	/ n
[        S[        U	5      5       H  nU
R                  SX   05        M     U R                  X5      $  N N]7f)ao  
cancel multiple orders at the same time

https://docs.bitfinex.com/reference/rest-auth-cancel-orders-multiple

:param str[] ids: order ids
:param str symbol: unified market symbol, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an array of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr   r8   r  r  )
r*  r  r  r  parse_to_numericr   r2  r  r  r%  )r  r  r  r  
numericIdsr  r  r   r  r  r3  s              r  cancel_ordersbitfinex.cancel_orders~  s      !!!
q#c(#Ad33CF;< $ *
 [[(F>>t{{7?[\\f !R0
q#f+&Ax34 '  44E 	" ]s#   C8C4BC8C6AC86C8c           	         #    S[        U5      /0nU R                  USSU R                  XC5      5      I Sh  vN nU R                  US5      nUc  [	        U R
                  S-   U-   S-   5      eU$  N97fa  
fetch an open order by it's id

https://docs.bitfinex.com/reference/rest-auth-retrieve-orders
https://docs.bitfinex.com/reference/rest-auth-retrieve-orders-by-symbol

:param str id: order id
:param str symbol: unified market symbol, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r8   Nr   z order z
 not found)r  fetch_open_ordersr  r  r(   r8   r  r8   r  r  r  r  rq  s          r  fetch_open_orderbitfinex.fetch_open_order  s{      3r7)
 --fdD$++gB^__*=) 3b 8< GHH	 `   5A3A1:A3c           	         #    S[        U5      /0nU R                  USSU R                  XC5      5      I Sh  vN nU R                  US5      nUc  [	        U R
                  S-   U-   S-   5      eU$  N97frB  )r  fetch_closed_ordersr  r  r(   r8   rD  s          r  fetch_closed_orderbitfinex.fetch_closed_order  s|      3r7)
 //dDKKPWD`aa*=) 3b 8< GHH	 brG  c                   #    U R                  5       I Sh  vN   0 nSnSnUc)  U R                  U R                  XT5      5      I Sh  vN nOAU R                  U5      nUS   US'   U R	                  U R                  XT5      5      I Sh  vN n/ n[        S[        U5      5       H  n	UR                  SXy   05        M     U R                  XX#5      $  N N NM7f)a  
fetch all unfilled currently open orders

https://docs.bitfinex.com/reference/rest-auth-retrieve-orders
https://docs.bitfinex.com/reference/rest-auth-retrieve-orders-by-symbol

: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
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr8   r  r   r  )	r*  privatePostAuthROrdersr  r   privatePostAuthROrdersSymbolr  r  r  r%  )
r  r  r  r   r  r  r   r  r3  r  s
             r  rC  bitfinex.fetch_open_orders  s      !!!>!88W9UVVH[[(F &tGH!>>t{{7?[\\HN 
q#h-(Ax56 )  UBBg 	"
 W ]s5   CC0CCAC	C
A
CCCc                 r  #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX45      I Sh  vN $ 0 nUb  X&S'   Ub  X6S'   U R                  SXd5      u  pdSnSnUc)  U R	                  U R                  Xd5      5      I Sh  vN nOAU R                  U5      nUS   US	'   U R                  U R                  Xd5      5      I Sh  vN n/ n	[        S
[        U5      5       H  n
U	R                  SX   05        M     U R                  XX#5      $  GN N N NP7f)at  
fetches information on multiple closed orders made by the user

https://docs.bitfinex.com/reference/rest-auth-retrieve-orders
https://docs.bitfinex.com/reference/rest-auth-retrieve-orders-by-symbol

:param str symbol: unified market symbol of the market orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch entries for
:param 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>`
NFrc   r  r:  r   r  r8   r  r   r  )r*  r  r  r  privatePostAuthROrdersHistr  r    privatePostAuthROrdersSymbolHistr  r  r  r%  )r  r  r  r   r  r  r  r   r  r3  r  s              r  rI  bitfinex.fetch_closed_orders9  sJ      !!!88ATV`a::;NPV_dmmm$G$G225'J>!<<T[[=YZZH[[(F &tGH!BB4;;wC_``HN 
q#h-(Ax56 )  UBBy 	" n [ asH   D7D.8D7D1AD7"D3#AD7$D5%A
D71D73D75D7c                   #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      n[	        U5      nUUS   S.nU R                  U R                  X5      5      I Sh  vN n	/ n
[        S[        U	5      5       H  nU
R                  SX   05        M     U R                  XX45      $  N NK7f)a  
fetch all the trades made from a single order

https://docs.bitfinex.com/reference/rest-auth-order-trades

:param str id: order id
: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 to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
Nz. fetchOrderTrades() requires a symbol argumentr8   )r8   r  r   r  )r#   r8   r*  r   r  #privatePostAuthROrderSymbolIdTradesr  r  r  r  r  )r  r8   r  r  r   r  r   r  r  r  r  r  s               r  fetch_order_tradesbitfinex.fetch_order_trades  s      >#DGG.^$^__!!!V$b'Tl

 AA$++gB^__
q#h-(Ax56 )  UBB 	" `s#   /CCAC=C	>A
C	Cc                   #    U R                  5       I Sh  vN   SnSU R                  5       0nUb  X&S'   Ub  X6S'   SnUbB  U R                  U5      nUS   US'   U R                  U R	                  Xd5      5      I Sh  vN nO(U R                  U R	                  Xd5      5      I Sh  vN n/ n[        S[        U5      5       H  n	UR                  SXy   05        M     U R                  XX#5      $  N Nt NM7f)	a  
fetch all trades made by the user

https://docs.bitfinex.com/reference/rest-auth-trades
https://docs.bitfinex.com/reference/rest-auth-trades-by-symbol

: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
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
Nr  r:  r   r8   r  r   r  )
r*  rj  r    privatePostAuthRTradesSymbolHistr  privatePostAuthRTradesHistr  r  r  r  )
r  r  r  r   r  r   r  r  r  r  s
             r  fetch_my_tradesbitfinex.fetch_my_trades  s      !!!4$$&
 $G$G[[(F &tGH!BB4;;wC_``H!<<T[[=YZZH
q#h-(Ax56 )  UBB' 	" aZs5   C7C1A'C7>C3?(C7'C5(A
C73C75C7c                    #    U R                  5       I Sh  vN   SS0nU R                  XR                  X25      5      I Sh  vN $  N0 N7f)aU  
create a currency deposit address

https://docs.bitfinex.com/reference/rest-auth-deposit-address

:param str code: unified currency code of the currency for the deposit address
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
Nop_renewr   )r*  fetch_deposit_addressr  )r  r  r  r  s       r  create_deposit_addressbitfinex.create_deposit_address  sO      !!!
 //kk'6RSSS	 	" Ts!   AA+AA	A	Ac                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  USU5      nU R                  US0 5      nU R                  XT5      nU R                  US5      nUc  [	        U R
                  S-   U-   S-   5      eU R                  USS5      nU R                  USS5      nUUS	S
.n	U R                  U R                  X5      5      I Sh  vN n
U R                  U
S/ 5      nU R                  US5      nUc  U R                  US5      OUnUc  SOU R                  US5      nU R                  U5        UUUSU
S.$  GN@ Ns7f)aQ  
fetch the deposit address for a currency associated with self account

https://docs.bitfinex.com/reference/rest-auth-deposit-address

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
Nr  r	  r8   z5 fetchDepositAddress() could not find a network for 'D'. You can specify it by providing the 'network' value inside paramswalletr   r   )methodrd  r^  r  r  )rB  addresstagr  r  )
r*  rB  r  r  r#   r8   r-  privatePostAuthWDepositAddressr  check_address)r  r  r  rB  r  currencyNetworkscurrencyNetworkr  rd  r  r  r  poolAddressrf  rg  s                  r  r_  bitfinex.fetch_deposit_address  s     !!!==&""69d;??8ZD//*:D$$_d;	#DGG.e$ehl$l  pv  %v  w  w!!&(J?69h7

 <<T[[=YZZ( 1b1&&vq12=2E$""61-K"*d1A1A&!1L7#
 	
S 	"  [s#   EECE%E&A1EEc                 B    SSSSSSSSSSSS.nU R                  X!U5      $ )Nr  rZ  r  pending)r[  	COMPLETEDr\  r]  r  zPENDING APPROVALPENDINGzPENDING REVIEWzPENDING CANCELLATIONSENDINGzUSER APPROVEDr^  r_  s      r  parse_transaction_status!bitfinex.parse_transaction_status	  s?    " ) '$- &
 &99r  transactionc                 r   [        U5      nS nS nS nS nS nS n	S n
S nS nS nS nS nS nUS:X  a  U R                  US/ 5      nU R                  US5      nUb  US   nU R                  US5      nUb  [        R
                  " U5      nU R                  US5      nU R                  US5      nSn	US:X  a  S nSn	U R                  US5      n
S	nU R                  US
5      nU R                  UR                  5       5      nGORUS:X  GaK  U R                  US5      nU R                  US5      nU R                  UU5      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 R                  U R                  US5      5      n	U R                  US5      n[        R
                  " U5      nUb!  [        R                  " US5      (       a  S	nOSnU R                  US5      nUb  [        R
                  " U5      nU R                  US5      nU R                  US5      nU R                  US5      n0 SU_SU_SU_SU_SU_SU_SU R                  U5      _SU	_SU_SU R                  U5      _S U_S!S _S"U_S#U
_S$S _S%U
_S&U_US UU R                  U5      S S'.S(.E$ ))Nr   r  r   r  r  r  rZ  r  
withdrawalr     r   r  r  r{  r   r   r|  r         r  r8   txidr  rB  r  r  r  rT  rU  rf  addressFrom	addressTorg  tagFromtagTor  )rB  r  rate)commentinternalr  )r  r  r	  r  r2   rk  r  r
  r  r  rs  r  r  rV  )r  ru  rB  transactionLengthrT  r  r  r  r8   r  rg  r  feeCostr{  r}  r  r  r+  r  r9  rr  s                        r  parse_transactionbitfinex.parse_transaction!	  s   h  ,		!??;26D))+q9I#'&&tQ/G"!,,W5%%dA.F""4+BFQw!""4+CD((q1I--ioo.?@G"$!!+q1B))+q9J**:x@D((a8I--i8G))+q9I''Q7G2243C3CKQR3STF++K<L''5F'$$\377'D$D&&{B7G"!,,W5((b9I##K4D&&{B7G
K
"
 D
 D	

 
 w
 d''/
 f
 
 Y/
 y
 4
 
 3
 t
  S!
" w#
$  ))'2)
 	
r  c                   #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN n0 nU R                  U R                  S0 5      nU R                  US/ 5      nU R                  US/ 5      nU R                  US/ 5      nU R	                  US5      nU R	                  US5      n	U R	                  US5      n
U R	                  US5      nU R	                  US5      nU R	                  US5      n[        S[        U R                  5      5       Ha  nU R                  U   nU R                  U5      nUUSSS	.nUS
   U;   a  U	US'   UUS'   OUS   (       a  U
US'   UUS'   O
UUS'   UUS'   UX?'   Mc     U$  GNh GNR7f)a(  
fetch the trading fees for multiple markets

https://docs.bitfinex.com/reference/rest-auth-summary

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
Nr  r  r   r   r  r  T)r  r  r   r   r  r   r   r  )	r*  privatePostAuthRSummaryr  r   r  r  r  r  r   )r  r  r  r  r  feeData	makerData	takerDatamakerFeemakerFeeFiatmakerFeeDerivtakerFeetakerFeeFiattakerFeeDerivr  r  r   r  s                     r  fetch_trading_feesbitfinex.fetch_trading_fees	  s     !!!55f==H t||VR8//(Ar2OOGQ3	OOGQ3	##Iq1''	15((A6##Iq1''	15((A6q#dll+,A\\!_F[[(F  "!	C g$&+G+G
#,G,G'G'G FN% -& G 	"=s    FE>FFEFFc                 l  #    U R                  5       I Sh  vN   Sn0 nUb  X&S'   Ub  X6S'   SnUbB  U R                  U5      nUS   US'   U R                  U R                  Xd5      5      I Sh  vN nO(U R	                  U R                  Xd5      5      I Sh  vN nU R                  XuX#5      $  N NA N7f)aX  
fetch history of deposits and withdrawals

https://docs.bitfinex.com/reference/movement-info
https://docs.bitfinex.com/reference/rest-auth-movements

:param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
:param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
:param int [limit]: max number of deposit/withdrawals to return, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr:  r   r  rB  )r*  rB  %privatePostAuthRMovementsCurrencyHistr  privatePostAuthRMovementsHistparse_transactions)r  r  r  r   r  rB  r  r  s           r  fetch_deposits_withdrawals#bitfinex.fetch_deposits_withdrawals
  s      !!!$G$G}}T*H"*="9GJ!GGT[HdeeH!??G@\]]H: &&x5HHU 	" f]s4   B4B.AB4.B0/(B4B2B40B42B4rf  rg  c                 p  #    U R                  U5        U R                  5       I Sh  vN   U R                  U5      nU R                  USU5      nU R	                  US5      nU R                  US0 5      nU R                  X5      n	U R                  U	S5      n
U
c  [        U R                  S-   U-   S-   5      eU R                  USS5      nU R	                  USS5      nU
UU R                  U5      US	.nUb  XLS
'   U R                  U R                  S0 5      nU R                  USS5      nU(       a  SUS'   U R                  U R                  X5      5      I Sh  vN nU R                  US5      nUS:X  ap  U R                  S-   U-   nU R                  USS5      nU R                  U R                  S   UU5        U R                  U R                  S   UU5        [!        U5      eU R                  US5      nUS:w  a   U R                  U R                  S   UU5        U R#                  X5      $  GN
 N7f)a  
make a withdrawal

https://docs.bitfinex.com/reference/rest-auth-withdraw

:param str code: unified currency code
:param float amount: the amount to withdraw
:param str address: the address to withdraw to
:param str tag:
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr  r	  r8   z* withdraw() could not find a network for 'rc  rd  r   )re  rd  r  rf  
payment_idr   r   Fr   
fee_deductr   rF  r  r  r&  r7  r8  r  success)ri  r*  rB  r  r-  r  r#   r8   number_to_stringr   r  privatePostAuthWWithdrawr  rJ  r/  throw_broadly_matched_exceptionr    r  )r  r  r  rf  rg  r  rB  r  rj  rk  r  rd  r  withdrawOptionsr   r  statusMessagefeedbackrQ  texts                       r  r   bitfinex.withdrawM
  s=     	7#!!!==&""69d;69-??8ZD//*:D$$_d;	#DGG.Z$Z]a$a  ek  %k  l  l!!&(J?69h7++F3	
 ?$'L!//$,,
BG^^O\5I
$%GL!66t{{77STT> ((15G#ww}x/H&&xB7G001I7T\]001I7T\]))!,9001I4QUV%%h99E 	"0 Us#   %H6H1D3H6H4CH64H6c                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  U5      I Sh  vN n/ n[        S[	        U5      5       H  nUR                  SX5   05        M     U R                  XA5      $  Nr NJ7f)a<  
fetch all open positions

https://docs.bitfinex.com/reference/rest-auth-positions

:param str[]|None symbols: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
Nr   r  )r*  r  privatePostAuthRPositionsr  r  r  parse_positions)r  r  r  r  positionsListr  s         r  fetch_positionsbitfinex.fetch_positions
  s      !!!%%g.77??F q#h-(A  (HK!89 )##M;;Q 	"?s"   BB	)B BA	BBpositionc                    U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n	U R                  0 SU_S	U R                  US
5      _SU R	                  XB5      _SU R                  U5      _SS_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S _SS _SS _S[        R                  " US5      (       a  SOS_SS _S U_S!U R                  U5      _U R                  US"5      U R                  US#5      S U R                  US$5      U R                  [        R                  " X5      5      S U R                  US%5      S S S S&.
E5      $ )'Nr  r   r  r{  r  trade_pricetrade_amountr  r8   rz  r  notionalr  isolatedliquidationPricer   
entryPricer  unrealizedPnlr  r   r  	contractsr  	markPrice	lastPricers  r   longshortr  rT  rU  r|     ry  r  )
lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager  marginRatior  r  )r  r  r	  safe_positionr  r  r  r2   rl  rV  r  )
r  r  r   positionListr  r  rT  meta
tradePricetradeAmounts
             r  parse_positionbitfinex.parse_position
  sD   B ~~h9##L!4!!,2%%lB7	b1%%dM:
&&t^<!! #
L#
$""<4#
 d&&x8#
 ))&1	#

 *#
  0 0q A#
 $**<;#
 T--lA>#
 $**<;#
 #
 D#
 #
 #
 g//<<F'#
 d#
  !#
" Y/##
$ $(#4#4\2#F!%!1!1,!C+/**<<!..w/A/A+/Z['+((q9!#7#
  	r  c                 "    U R                  5       $ N)rj  )r  s    r  rh  bitfinex.nonce  s      ""r  r   GETc                 j   SU R                  X5      -   nU R                  X@R                  U5      5      nUS:X  a  X'-   nOU R                  U-   nU R                  S   U   S-   U-   n	US:X  a  U(       a  U	SU R                  U5      -   -  n	US:X  a  U R                  5         [        U R                  5       5      n
U R                  U5      nSU-   U
-   U-   nU R                  U R                  U5      U R                  U R                  5      [        R                  5      nU
U R                  USS	.nXXeS
.$ )Nr  r   r   r   ?r   z/api/zapplication/json)z	bfx-noncez
bfx-apikeyzbfx-signaturezContent-Type)r  re  bodyheaders)implode_paramsr-  extract_paramsr=   r   	urlencodecheck_required_credentialsstrrh  jsonhmacencodesecrethashlibsha384apiKey)r  pathr   re  r  r  r  r  r6  r  rh  auth	signatures                r  signbitfinex.sign  s!   ++D99		&"5"5d";<$;mGllW,Giis#c)G3(?sT^^E222)++-

%E99U#DW$u,t3D		$++d"3T[[5Mw~~^I""kk!* 2	G dOOr  c
                 0   Ub  [        U[        5      (       d~  U R                  USS5      n
U R                  S-   U-   nU R	                  U R
                  S   X5        U R                  U R
                  S   X5        [        U R                  S-   U-   5      eOUS:X  a  [        U R                  S-   5      eUS:X  a  [        U R                  S-   U-   5      eUS	:X  a  U R                  US
S5      nU R                  USS5      nU R                  S-   U-   nU R                  U R
                  S   X5        U R	                  U R
                  S   X5        U R	                  U R
                  S   X5        [        U R                  S-   U-   S-   U-   S-   5      eU$ )NrQ  rF  r  r7  r8  r&  z returned empty responsei    r   r  r  r  )

isinstancer+  r
  r8   rJ  r/  r  r    r*   r  )r  
statusCode
statusTextr  re  r  r  r  requestHeadersrequestBodyrQ  r  r  r  s                 r  handle_errorsbitfinex.handle_errors5  s   h--,,Xy'J77S=4/44T__W5Mwa44T__W5Mwa#DGGcMD$899 . ^*D DEE#DGGcMD$899((1b9I((1b9Iww}y0H001I9_001I9_001I9_#	 9D @9 Ls RSSr  c                    Uc  g UR                  S5      S:  d  UR                  S5      S:  a  gUR                  S5      S:  a  gUR                  S5      S:  d  UR                  S5      S:  a  gUR                  S5      S:  a  gUR                  S	5      S:  a  g
UR                  S5      S:  d  UR                  S5      S:  a  gU$ )Nr  r   chargedrebater   rw  ru  r   paymentpayoutr   r  r  )r  )r  r  s     r  parse_ledger_entry_type bitfinex.parse_ledger_entry_typeM  s    <YYu"dii	&:a&?YYx A%YYy!Q&$))L*AQ*F YYz"a'YYy!Q&YYz"a'499Z+@A+EKr  itemc                    U R                  US/ 5      nS nU R                  US5      nU R                  US5      nU R                  Xb5      nU R                  Xb5      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b4  UR                  S5      nU R                  US5      nU R                  U5      nU R                  UUS S US UUU	UU R                  U5      S U
S S S	.U5      $ )
Nr  r   r   r  r  r  r   r  )r  r8   	directionr/  referenceIdreferenceAccountr  rB  r  rT  rU  beforeafterr  r  )r  r  r  safe_currencyr	  r  r  r0  r  safe_ledger_entryrV  )r  r  rB  itemListr  r8   r9  r  rT  r  r  descriptionr  firsts                 r  parse_ledger_entrybitfinex.parse_ledger_entry_  s2     >>$"5h*%%h2
&&z<%%j;%%h2	!!(A.  1-&&x3"%%e,E**5!4E//6D%% $"Y/'
  ! 	r  c                 x  #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX4S5      I Sh  vN $ Sn0 nUb  X'S'   Ub  X7S'   U R                  SXt5      u  ptSnUbB  U R	                  U5      nUS	   US
'   U R                  U R                  Xt5      5      I Sh  vN nO(U R                  U R                  Xt5      5      I Sh  vN n/ n	[        S[        U5      5       H  n
X   nU	R                  SU05        M     U R                  XX#5      $  GN N Ny NR7f)aO  
fetch the history of changes, actions done by the user or operations that altered the balance of the user

https://docs.bitfinex.com/reference/rest-auth-ledgers

: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, max is 2500
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest ledger entry
: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>`
NFrs   r  r!  r:  r   r  r  rB  r   r  )r*  r  r  r  rB  #privatePostAuthRLedgersCurrencyHistr  privatePostAuthRLedgersHistr  r  r  parse_ledger)r  r  r  r   r  r  rB  r  r  ledgerObjectsr  r  s               r  fetch_ledgerbitfinex.fetch_ledger  sP     !!!88PZ[::=$W\fjkkk$G$G225'J}}T*H"*="9GJ!EEdkkRYFbccH!==dkk'>Z[[H  q#h-(A;D  (D!12 )   %GGM 	" l d[sG   D:D19D:D4A+D:<D6=(D:%D8&AD:4D:6D:8D:c                 2  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nSSR	                  U5      0nU R                  U R                  XB5      5      I Sh  vN nU R                  XQ5      $  Na N7f)af  
fetch the current funding rate for multiple symbols

https://docs.bitfinex.com/reference/rest-public-derivatives-status

:param str[] symbols: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
Nz0 fetchFundingRates() requires a symbols argumentr,  r  )r#   r8   r*  r  r  publicGetStatusDerivr  parse_funding_ratesr  r  r  	marketIdsr  r  s         r  fetch_funding_ratesbitfinex.fetch_funding_rates  s      ?#DGG.`$`aa!!!OOG,	CHHY'
 224;;w3OPP> ''::I 	"
 Qs"   /BBAB=B>BBc           	        #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R	                  SXUSUS5      I Sh  vN $ U R                  U5      nSUS	   0nUb  X'S
'   U R                  SXt5      u  ptU R                  U R                  Xt5      5      I Sh  vN n/ n	[        S[        U5      5       H)  n
X   nU R                  X5      nU	R                  U5        M+     / nU R                  XX#5      n[        U5      n[        SU5       H   n
X-
  S-
  nUU   nUR                  U5        M"     U$  GN1 N N7f)a  
fetches historical funding rate prices

https://docs.bitfinex.com/reference/rest-public-derivatives-status-history

:param str symbol: unified market symbol
:param int [since]: timestamp in ms of the earliest funding rate entry
:param int [limit]: max number of funding rate entrys to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest funding rate
: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 `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
Nz5 fetchFundingRateHistory() requires a symbol argumentFrn   r  8h  r  r8   r:  r  r   r   )r#   r8   r*  r  r  r   r  publicGetStatusDerivSymbolHistr  r  r  parse_funding_rate_historyr  filter_by_symbol_since_limit)r  r  r  r   r  r  r   r  r  ratesr  frr  reversedArrayrawRatesratesLengthindexvalueAtIndexs                     r  fetch_funding_rate_history#bitfinex.fetch_funding_rate_history  s     >#DGG.e$eff!!!88AZ\fg@@AZ\bkprvx~  AE  F  F  FV$fTl
 $G225'J<<T[[=YZZ> q#h-(AB222>DLL ) 44UEQ(mq+&AOa'E#E?L  . ' o 	" F [s5   /E)E";E)-E%.AE)E'	BE)%E)'E)c                    U R                  US5      nU R                  US5      nU R                  US5      n0 SU_SU R                  X25      _SU R                  US5      _SU R                  US	5      _S
S _SS _SU_SU R	                  U5      _SU R                  US5      _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 0E$ )Nr   r   r   r  r  r     
indexPricer  interestRateestimatedSettlePricerT  rU  fundingRater{  fundingTimestampfundingDatetimenextFundingRater  nextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r  r	  r  r  rV  )r  r  r   r  rT  r&  s         r  parse_funding_ratebitfinex.parse_funding_rate@  sl   : ##Ha0%%h2	#001=
H
d&&x8
 ))(B7
 $**8Q7	

 D
 #D
 
 Y/
 4++Hb9
 
 t
 t//!<
 #$8
 "4<<0D#E
 "4
  '!
" &t#
$ %
 	
r  c                    U R                  US5      nU R                  US5      n0 SU_SU R                  S U5      _SU R                  US5      _SU R                  US5      _S	S _S
S _SU_SU R                  U5      _SU R                  US5      _SS _SS _SU R                  US5      _SU_SU R                  U5      _SS _SS _SS _$ )Nr   r  r  r  r     r  r  r   r!  rT  rU  r"  rz  r#  r$  r%  r   r&  r'  r(  r)  r*  )r	  r  r  rV  )r  r  r   rT  r&  s        r  r  #bitfinex.parse_funding_rate_historyu  sP   8 %%h2	#001=
H
d&&tV4
 ))(B7
 $**8Q7	

 D
 #D
 
 Y/
 4++Hb9
 
 t
 t//!<
 #$8
 "4<<0D#E
 "4
  '!
" &t#
 	
r  c                 *  #    U R                  5       I Sh  vN   U R                  U5      nS/nUb  U R                  U5      nSSR                  U5      0nU R	                  U R                  XB5      5      I Sh  vN nU R                  XQ5      $  Nx N7f)aU  
Retrieves the open interest for a list of symbols

https://docs.bitfinex.com/reference/rest-public-derivatives-status

:param str[] [symbols]: a list of unified CCXT market symbols
:param dict [params]: exchange specific parameters
:returns dict[]: a list of `open interest structures <https://docs.ccxt.com/#/?id=open-interest-structure>`
Nr  r,  r  )r*  r  r  r  r  r  parse_open_interestsr
  s         r  fetch_open_interestsbitfinex.fetch_open_interests  s      !!!%%g.G	0ICHHY'
 224;;w3OPP> ((;;O 	" Qs"   BBA"B9B:BBc                   #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  US5      nU R                  Xc5      $  Ng N)7f)a@  
retrieves the open interest of a contract trading pair

https://docs.bitfinex.com/reference/rest-public-derivatives-status

:param str symbol: unified CCXT market symbol
:param dict [params]: exchange specific parameters
:returns dict: an `open interest structure <https://docs.ccxt.com/#/?id=open-interest-structure>`
Nr,  r8   r   )r*  r   r  r  r  parse_open_interest)r  r  r  r   r  r  ois          r  fetch_open_interestbitfinex.fetch_open_interest  s      !!!V$F4L
 224;;w3OPP> ^^Ha(''33K 	"
 Qs!   BA>?BB (B Bc           	        #    U R                  5       I Sh  vN   SnU R                  USS5      u  peU(       a  U R                  SXUSUS5      I Sh  vN $ U R                  U5      nSUS   0nUb  X8S	'   Ub  XHS
'   U R	                  SX5      u  pU R                  U R                  X5      5      I Sh  vN n	U R                  XX45      $  N Nz N7f)al  
retrieves the open interest history of a currency

https://docs.bitfinex.com/reference/rest-public-derivatives-status-history

:param str symbol: unified CCXT market symbol
:param str timeframe: the time period of each row of data, not used by bitfinex
:param int [since]: the time in ms of the earliest record to retrieve unix timestamp
:param int [limit]: the number of records in the response
:param dict [params]: exchange specific parameters
:param int [params.until]: the time in ms of the latest record to retrieve unix timestamp
: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: An array of `open interest structures <https://docs.ccxt.com/#/?id=open-interest-structure>`
NFr}   r  r  r  r  r8   r:  r   r  )r*  r  r  r   r  r  r  parse_open_interests_historyr  s
             r  fetch_open_interest_history$bitfinex.fetch_open_interest_history  s      !!!88A[]gh@@A[]clqswy  BF  G  G  GV$fTl
 $G$G225'J<<T[[=YZZ< 005PPY 	" G [s4   CC;CCA!C4C5CCCc           	         [        U5      nUS:X  a  SOSnU R                  US5      nU R                  US5      nU R                  U R	                  XbS S5      U R                  X5      S UU R                  U5      US.U5      $ )N   ry  r  r   r   rE   )r  openInterestAmountopenInterestValuerT  rU  r  )r  r	  r  safe_open_interestr  r  rV  )r  r8  r   interestLengthopenInterestIndexrT  r  s          r  r6  bitfinex.parse_open_interestH  s    v X#1R#7Bb%%h2	##Ha0&&&&xvF"&"2"28"O!%"Y/(
  	r  c           	        #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXUSUS5      I Sh  vN $ U R                  U5      n0 nUb  X'S'   Ub  X7S'   U R	                  S	Xt5      u  ptU R                  U R                  Xt5      5      I Sh  vN nU R                  XX#5      $  N Nu N7f)
a   
retrieves the public liquidations of a trading pair

https://docs.bitfinex.com/reference/rest-public-liquidations

:param str symbol: unified CCXT market symbol
:param int [since]: the earliest time in ms to fetch liquidations for
:param int [limit]: the maximum number of liquidation structures to retrieve
:param dict [params]: exchange specific parameters
:param int [params.until]: timestamp in ms of the latest liquidation
: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: an array of `liquidation structures <https://docs.ccxt.com/#/?id=liquidation-structure>`
NFrv   r  r  r  r:  r   r  )r*  r  r  r   r  publicGetLiquidationsHistr  parse_liquidations)	r  r  r  r   r  r  r   r  r  s	            r  fetch_liquidationsbitfinex.fetch_liquidations  s      !!!88ATV`a@@ATV\ejlprxz}~~~V$$G$G225'J77G8TUU* &&xFFC 	"  Vs4   CC;CCAC/C
0CC
Cc                    US   nU R                  US5      nU R                  US5      n[        R                  " U R                  US5      5      nU R                  US5      n[        R                  " Xg5      nU R                  US5      n	U R                  US5      n
U
S:X  a  S	OS
nU R                  UU R                  XRS S5      U R                  U5      U R                  U5      U R                  U	5      UU R                  U5      U R                  [        R                  " X5      5      UU R                  U5      S.
5      $ )Nr   r  r  r  r  rz  r   r   r  r  r  )
r  r  r  r  r  rs  	baseValue
quoteValuerT  rU  )	r	  r  r2   rk  r  safe_liquidationr  r  rV  )r  liquidationr   r,  rT  r  r  r  rL  r  sideFlagrs  s               r  parse_liquidationbitfinex.parse_liquidation  s1   & A%%eQ/	##E1-&&t'7'7q'AB	''?&&y?	  +$$UA.!QuV$$&&xzJ**95 --l;&&u-**95++G,>,>y,PQ"Y/&
  	r  c                 l  #    U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      eUS   U R	                  U5      S.nU R                  U R                  XS5      5      I Sh  vN nU R                  US5      nU R                  Xt5      $  N N)7f)a  
either adds or reduces margin in a swap position in order to set the margin to a specific value

https://docs.bitfinex.com/reference/rest-auth-deriv-pos-collateral-set

:param str symbol: unified market symbol of the market to set margin in
:param float amount: the amount to set the margin to
:param dict [params]: parameters specific to the exchange API endpoint
:returns dict: A `margin structure <https://github.com/ccxt/ccxt/wiki/Manual#add-margin-structure>`
NrE   z& setMargin() only support swap marketsr8   )r  r  r   )	r*  r   r)   r8   r=  "privatePostAuthWDerivCollateralSetr  r  parse_margin_modification)r  r  r  r  r   r  r  r+  s           r  
set_marginbitfinex.set_margin  s      !!!V$f~tww)QQRRTl//7
 @@WA]^^ x+--d;;# 	" _s"   B4B0A1B4B2	(B42B4c                 @    US   nUS:X  a  SOSnUUS   S SS S S US S S.
$ )Nr   r   r  rZ  r  r  )
r  r  r  r  r  r(  r  r  rT  rU  r  )r  r+  r   marginStatusRawmarginStatuss        r  rU  "bitfinex.parse_margin_modification  sH     q' /1 4t8X&$"
 	
r  c                   #    U R                  5       I Sh  vN   SU R                  U5      /0nSnSnUc)  U R                  U R                  XC5      5      I Sh  vN nOAU R	                  U5      nUS   US'   U R                  U R                  XC5      5      I Sh  vN nU R                  US5      nSU0nU R                  X5      $  N No N/7f)a  
fetches information on an order made by the user

https://docs.bitfinex.com/reference/rest-auth-retrieve-orders
https://docs.bitfinex.com/reference/rest-auth-retrieve-orders-by-symbol

:param str id: the order id
:param str [symbol]: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr8   r  r   r  )r*  r=  rM  r  r   rN  r  r  )	r  r8   r  r  r  r   r  rq  r  s	            r  fetch_orderbitfinex.fetch_order!  s      !!!4((,-
 >!88W9UVVH[[(F &tGH!>>t{{7?[\\HN x+e$11i 	" W ]s5   CCACC	ACC,C	CCc                   #    U R                  5       I Sh  vN   U R                  U5      nSU R                  U5      0n	Ub3  U R                  X%5      n
US:X  a  U
O[        R
                  " U
5      n
XS'   U R                  USS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S
5      nU R                  USS5      nUb  XS'   O1Ub.  U R                  X+5      U	S'   US:X  a  U R                  X&5      U	S'   U=(       d    US:H  nUS:w  a  Uc  U R                  X&5      U	S'   SnU(       a  U R                  US5      nU(       a  U R                  US5      nUS:w  a  UU	S'   Ub  UU	S'   U R                  USS5      nUb  UU	S'   U R                  U/ SQ5      nU R                  U R                  X5      5      I Sh  vN nU R                  US5      nUS:w  a7  US   nUS   n[        U R                   S-   US   -   S -   U-   S!-   U-   S"-   5      eU R#                  US#/ 5      nS$U0nU R%                  UU5      $  GNI N7f)%aO  
edit a trade order

https://docs.bitfinex.com/reference/rest-auth-update-order

:param str id: edit order id
:param str symbol: unified symbol of the market to edit an order in
:param str type: 'market' or 'limit'
:param str side: 'buy' or 'sell'
:param float amount: how much you want to trade in units of the base currency
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
:param dict [params]: extra parameters specific to the exchange API endpoint
:param float [params.triggerPrice]: the price that triggers a trigger order
:param boolean [params.postOnly]: set to True if you want to make a post only order
:param boolean [params.reduceOnly]: indicates that the order is to reduce the size of a position
:param int [params.flags]: additional order parameters: 4096(Post Only), 1024(Reduce Only), 16384(OCO), 64(Hidden), 512(Close), 524288(No Var Rates)
:param int [params.leverage]: leverage for a derivative order, supported by derivative symbol orders only, the value should be between 1 and 100 inclusive
:param int [params.clientOrderId]: a unique client order id for the order
:param float [params.trailingAmount]: *swap only* the quote amount to trail away from the current market price
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr8   r  r  r  r  r  r  r  Fr  r  r  r  r  r   r  r  r   r   r  r	  r  r  lev)r  r  r  r  r  r  r  r  r  r[  r  r  r  r  r  r  r  r  )r*  r   r=  r  r2   r  r
  r  r  safe_integer_2r  r  r-  privatePostAuthWOrderUpdater  r    r8   r  r  )r  r8   r  r  rs  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rq  r  s                             r  
edit_orderbitfinex.edit_orderc  s    , !!!V$$''+
 33FCL,0EM<@R@RS_@`L ,H))&+~N))&2BC&&v}=vz5A^^FL%@
++FE?K%(6$%%#66vLGGw-1-D-DV-S)*!:kT&9H<#7#66vEGGHHUD)EHHUD)EA:$GG$*GEN&&vz5A%GEN6  $Y  Z99$++g:VWW\ !!(A.Y I I# ;d BY NQU UXa adg ghhxB/e$&11y 	"N Xs#   I$IGI$"I"#A=I$"I$r  r  )h__name__
__module____qualname____firstlineno__r   r  r  r  r  r  r  r  r   r   r  r   r!  r   r=  r  floatr   r   dictr   rK  r   rW  rG  r
   r   ru  r   r  r   r   r  r  r   r  r  r+  r  r  r  r  r  r   r  r   r   r   r  r  r   r.  r4  r:  r?  rE  rJ  rC  rI  rV  r[  r	   r`  r_  rs  r   r  r   r  r  r   r   r  r  rh  r  r  r  r   r  r  r   r  r  r   r,  r  r3  r8  r<  r6  rI  rQ  r   rV  rU  r]  rc  __static_attributes____classcell__)r  s   @r  r4   r4   !   s   K# KZ-SxM )+ 
. *, {V {z -/ H: HT *, ') ')R ac AC3 AC ACC ACTW ACgt ACF)
t )
x )
= )
V:C :C :, @DB *S * *S\ *Xh4 h h6 hT 6:" :47 :4 :4x 68 1 1F 1$O Ov O Ob <@d[] .B .BS .B .Bbfglbm .B` ?CQUdgpr *L *L *L3 *L^a *Lw{  }A  xB *LX
 
4 
(9 9&8>: :v : :x os{} L,3 L,i L,y L,Z_ L,hk L,\ mqy{ R2 R2I R2Y R2X] R2fi R2h FH 9*$|*< 9*v 59 -c -* 9=R !2S !2# !2F AER M5tCy M5# M5^ =A  c * ?C2 3  * 59tZ^gi @Cc @C @CTW @Cnrsxny @CD 7;\`ik LC LC3 LCVY LCptuzp{ LC\ ?CQUdhqs C3 C C3 C^a C: 37TX\eg  CC  Cs  CRU  CD >@ T TN T  =? 9
 9
> 9
v:s : C
T C
X C
Q\ C
J /1 l[ l\ <@daenp 7IS 7I 7I[^ 7Iuy  {F  vG 7Ir QU]_ P:3 P: P: P:# P:do P:d 8<B 2<W 2<4PX> 2<hDt DV DL# &eBSW P20C $.t .x .; .` .2SW`b 4Hs 4H# 4HS 4Hgklwgx 4Hl <@ 0; 0;| 0;d >BPTcgpr Gs G# G]` GR3
6 3
[ 3
j0
6 0
d =A 1<' 1<f =? /4 /4b HLZ^mqz| ;Q ;QTW ;Qgj ;QzFF FP BFTXac /Gs /G3 /Gc /Gb'V 'R CE <s <E <I[ <<
>P 
2 8<B @2C @2 @2D fjx|  FH r23 r2 r29 r2I r2_b r2ru r2 r2r  r4   ): ccxt.async_support.base.exchanger   ccxt.abstract.bitfinexr   r  r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   ccxt.base.decimal_to_precisionr.   r/   r0   r1   ccxt.base.preciser2   r4   r  r  r  <module>rt     s    6 .   m  m  m  m  m  m  m  * 0 - . ' & . ) * ) . 1 * ) 0 3 9 = %t:2x t:2r  