
    E#i'                       S SK Jr  S SKJr  S SKrS SKJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJr  S SKJ r   S SKJ!r!  S SK"J#r#  S SK$J%r%   " S S\\5      r&g)    )Exchange)ImplicitAPIN)AnyBalancesCurrencyDepositAddressIntLedgerEntryMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTradeTradingFeesTransaction)List)ExchangeError)AuthenticationError)ArgumentsRequired)
BadRequest)OrderNotFound)NotSupported)InvalidNonce)	TICK_SIZE)Precisec                     ^  \ rS rSrS\4U 4S jjrSSS0 4S\S\S\S\\	   4S jjr
S	 rSJS
\S\S\	4S jjr0 4S\\   4S jjrS\4S jr0 4S\4S jjrS0 4S\S\S\4S jjrSJS\S\S\4S jjr0 4S\S\4S jjrSSS0 4S\S\S\S\S\\   4
S jjrSJS\S\4S jjrSJS\S\S\4S jjrSS0 4S\S\S\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"S0 4S\S \#S!\$S"\%S#\&4
S$ jjr'S0 4S%\S\4S& jjr(S0 4S'\\   S\S\\)   4S( jjr*S0 4S\S\\)   4S) jjr+S*\4S+ jr,SJS,\S\S\)4S- jjr-SSS0 4S\S\S\S\\)   4S. jjr.S0 4S%\S\4S/ jjr/SSS0 4S%\S\S\S\4S0 jjr0S0 4S%\S\4S1 jjr1SSS0 4S\S\S\S\\2   4S2 jjr30 4S\S\44S3 jjr5S0 4S4\64S5 jjr7S0 4S4\64S6 jjr8SKS7 jr9S0 4S\S"\%S8\S9\S\24
S: jjr:SJS;\S\S\24S< jjr;S*\4S= jr<S> r=S?S@0 SS4SA jr>SB\?SC\SD\SE\SF\SG\4SH jr@SIrAU =rB$ )Lbitso   returnc                   > U R                  [        [        U ]  5       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 S*S
_S+S_S,S
_S-S._S/S_S0S
_S1S
_S2S
_S3S
_S4S
_S5S
_S6S
_S7S
_S8S
_S9S
_S:S
_S;S_E0 S<S
_S=S
_S>S
_S?S
_S@S
_SAS
_SBS
_SCS
_SDS
_SES
_SFS_SGS
_SHS
_SIS
_SJS
_SKS_SLS_E0 SMS
_SNS
_SOS
_SPS_SQS
_SRS
_SSS_STS_SUS_SVS
_SWS
_SXS
_SYS
_SZS
_S[S
_S\S
_S]S
_E0 S^S
_S_S_S`S
_SaS
_SbS_ScS
_SdS_SeS
_SfS_SgS
_ShS
_SiS
_SjS
_SkS
_SlS
_SmS
_SnS
_ES
S
S
S
SSo.ESpSqSr0SqSs0StSuSvSwSx.[        SySzSzS{.S|S}S~SSS.S.SSSSSSSSSS.	S/ SQ0/ SQ/ SQ/ SQ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
SS S SS.S
S
S
SS.S
SS
S
SS.S S SS0S.	S S S.S S S.S.[
        [        [        S.S.5      $ )Nr"   BitsoMXi  v3CORSspotTmarginFswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMarginborrowMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateDepositAddresscreateOrder$createOrderWithTakeProfitAndStopLoss&createOrderWithTakeProfitAndStopLossWscreateReduceOnlyOrderfetchAccountsfetchBalancefetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchIsolatedPositionsfetchLedgerfetchLeveragefetchLeveragesfetchLeverageTiersfetchLiquidationsfetchLongShortRatiofetchLongShortRatioHistoryfetchMarginAdjustmentHistoryfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricesfetchMyLiquidationsfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransferfetchTransfersfetchVolatilityHistoryreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeverage)	setMarginsetMarginModesetPositionModetransferwithdrawzOhttps://github.com/user-attachments/assets/178c8e56-9054-4107-b192-5e5053d4f975restzhttps://bitso.com/apizhttps://stage.bitso.com/apizhttps://bitso.comzhttps://bitso.com/api_infozhttps://bitso.com/feeszhttps://bitso.com/?ref=itej)logoapitestwwwdocfeesreferralgư>g{Gz?)XRPMXNTUSDg:0yE>trxerc20bscbep2)TRC20ERC20BEP20BEP2)	precisiondefaultPrecisionnetworks6030090018003600144004320086400604800)	1m5m15m30m1h4h12h1d1wget)available_booksticker
order_booktradesohlc)account_statusbalancer   fundingszfundings/{fid}funding_destinationkyc_documentsledgerzledger/tradeszledger/feeszledger/fundingszledger/withdrawalsmx_bank_codesopen_orderszorder_trades/{oid}orders/{oid}user_tradeszuser_trades/{tid}zwithdrawals/zwithdrawals/{wid})bitcoin_withdrawaldebit_card_withdrawalether_withdrawalordersphone_numberphone_verificationphone_withdrawalspei_withdrawalripple_withdrawalbcash_withdrawallitecoin_withdrawal)r   r   z
orders/all)r   postdelete)publicprivate)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyRequiresPricemarketBuyByCostselfTradePreventionicebergd   )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   i  )r   r   r   r   r   r   i,  )	sandboxr9   createOrdersrl   rt   rq   fetchOrdersfetchClosedOrdersrm   )linearinverse)r*   r,   r-   )02011040304)idname	countries	rateLimitversionhasurlsprecisionModeoptions
timeframesr   features
exceptions)deep_extendsuperr"   describer   r   r   r   )self	__class__s    D/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/bitso.pyr  bitso.describe   s   eT ; =lll %l 	l
 %l %l Ul $Ul 'l l "4l tl l $Ul  l  '!l" t#l$ 7%l& 9%'l( ()l*  +l, -l. &u/l0 "51l2 +E3l4 )%5l6 #E7l8 ,U9l: ';l< (=l> "5?l@ AlB &tClD (ElF 1%GlH  IlJ +EKlL *:MlN +DOlP &uQlR 'SlT (UlV #EWlX *5YlZ $U[l\ u]l^ "5_l` *5alb +Ecld )%elf tglh  ilj !%kll %emln $Uolp &uqlr -eslt /ulv "5wlx #Eylz +E{l| }l~ !%l@ "5AlB &uClD +EElF  GlH dIlJ $UKlL +EMlN %eOlP "4QlR uSlT #EUlV dWlX !$YlZ #D[l\  ]l^ '_l` $Ualb !%cld *5elf (glh %eilj )%kll )%mln tolp qlr Uslt tulv "5wlx #Dylz &u{l| '}l~ $Ul@  AlB !%ClD )%ElF GlH #EIlJ &uKlL uMlN #!&#(! Wl\ j3 9 +309 ' $ 
 %/"$""	 
  ,I)4n  %&+(,,0,0).+06: $(#'"&#(	( #($)$)27+0/4#(+$. %)&+!$$(%)*.& ',#($)*.	# ',!$#($)*.( $()-#a3j ##
 ##s=~ ,#"[R@
 R R	    Ncodesincer   c                     0 nUb  X5S'   U R                  U R                  XT5      5      nU R                  US/ 5      nU R                  U5      nU R	                  XxX#5      $ )a  
fetch the history of changes, actions done by the user or operations that altered the balance of the user
:param str [code]: unified currency code, default is None
:param int [since]: timestamp in ms of the earliest ledger entry, default is None
:param int [limit]: max number of ledger entries to return, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
r   payload)privateGetLedgerextend
safe_valuesafe_currencyparse_ledger)	r  r  r  r   paramsrequestresponser  currencys	            r  fetch_ledgerbitso.fetch_ledger-  sg     $G((W)EF0 //(Ir:%%d+  EAAr  c                 4    SSSSS.nU R                  X!U5      $ )Ntransactiontradefee)funding
withdrawalr#  r$  safe_string)r  typetypess      r  parse_ledger_entry_typebitso.parse_ledger_entry_typeU  s*    $'	
 T22r  itemr  c                    U R                  US5      nU R                  U5      nU R                  US/ 5      nU R                  US0 5      nS nS nU R                  US5      n	U R                  US5      n
U R                  X5      nU R	                  X5      nU R                  US0 5      nU R                  USS5      nUc  U R                  US	5      nUS
:X  a  SnO5US:X  a  SnO,US:X  a  S nO#US:X  a  Sn[        R                  " U	5      nUUS.nU R                  U R                  US5      5      nU R                  UU R                  US5      US US UUU	UU R                  U5      S S SUS.U5      $ )N	operationbalance_updatesr   amountr  detailsfidwidtidr%  inr&  outr#  r$  costr  
created_ateidok)infor   	directionaccountreferenceIdreferenceAccountr)  r  r1  	timestampdatetimebeforeafterstatusr$  )r(  r+  r  safe_currency_coder  safe_string_2r    
string_abs	parse8601safe_ledger_entryiso8601)r  r-  r  r/  r)  balanceUpdatesfirstBalancer>  r$  r1  
currencyIdr  r2  r@  r9  rB  s                   r  parse_ledger_entrybitso.parse_ledger_entry^  s   n $$T;7	++I6/@"E~q"=	!!,9%%lJ?
&&z<%%j;//$	26((%?**7E:K	!I,&I'!I%I%%f-D$C NN4#3#3D,#GH	%%""4/"& $"Y/'
  ! 	r  c                    U R                  U5      nU R                  US/ 5      n/ n[        S[        U5      5       GH   nX5   nU R	                  US5      nUR                  S5      u  pUR                  5       n
U	R                  5       nU R                  U
5      n
U R                  U5      nU R                  US0 5      nU R                  US0 5      nU R	                  US5      nU R	                  US5      nU R                  [        R                  " US	5      5      nU R                  [        R                  " US	5      5      nU R                  US
/ 5      nUUSSS.n/ n/ n[        S[        U5      5       Hv  nUU   nU R                  US5      nU R                  US5      nU R                  US5      nUR                  UU/5        UR                  UU/5        US:X  d  Ml  UUS'   UUS'   Mx     UUS.nUUS'   U R                  U R                  S   XR                  S   5      nUR                  U R                  0 SU_SU
S-   U-   _SU
_SU_SS_SU_SU	_SS_SS_SS_SS_S S_S!S_S"S_S#S_S$S_S%S_SUUSSSSSU R                  U R                  S   XR                  S   5      U R                  US&U5      S'.SSS(.U R                  US)5      U R                  US*5      S(.U R                  US+5      U R                  US,5      S(.U R                  US-5      U R                  US.5      S(.S/.SUS0.EU5      5        GM     U$ )1z
retrieves data on all markets for bitso

https://docs.bitso.com/bitso-api/docs/list-available-books

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
r  r   book_r   	flat_ratetakermaker100	structureT)rV  rW  
percentage	tierBasedvolume)rV  rW  tiersr   r   r   symbol/basequotesettleNbaseIdquoteIdsettleIdr)  r*   r+   Fr,   r-   r.   activecontractr   	tick_size)r1  price)minmaxminimum_amountmaximum_amountminimum_pricemaximum_priceminimum_valuemaximum_value)r   r1  ri  r9  )r   rV  rW  contractSizeexpiryexpiryDatetimestrike
optionTyper   limitscreatedr=  )publicGetAvailableBooksr  rangelenr(  splitupperrG  parse_numberr    
string_divsafe_numberappendr  r  )r  r  r  marketsresultimarketr   rc  rd  r`  ra  r   flatRatetakerStringmakerStringrV  rW  feeTiersr$  	takerFees	makerFeesjtierr\  takerFeemakerFeer]  defaultPricePrecisions                                r  fetch_marketsbitso.fetch_markets  s    //7B //(Ir:q#g,'AZF!!&&1B hhsmOF<<>DMMOE**40D++E2E??6626Dt["=H**8W=K**8W=K%%g&8&8e&LME%%g&8&8e&LMEt["=H"!	C II1c(m,{))$9++D':++D':  &(!34  &(!346#+CL#+CL - #"E !CL$($4$4T\\+5NPUWcWcdvWw$x!MM$++ 2'b2'$*u,2' 2' 	2'
 $2' &2' 72' D2' 2' 2' %2' 2' %2' %2' $2'  E!2'" $#2'$   $"&""..t||K/H$P\P\]oPpq!--fkCXY  $#!
  $//8HI#//8HI
  $//H#//H
  $//H#//H$  c2'd e2 2Q (v r  c                    U R                  US0 5      nU R                  US/ 5      nUS S S.n[        S[        U5      5       H}  nX5   nU R                  US5      nU R	                  U5      nU R                  5       n	U R                  US5      U	S'   U R                  US5      U	S	'   U R                  US
5      U	S
'   XU'   M     U R                  U5      $ )Nr  balances)r=  rB  rC  r   r  	availablefreelockedusedtotal)r  rz  r{  r(  rG  r?  safe_balance)
r  r  r  r  r  r  r   rO  r  r?  s
             r  parse_balancebitso.parse_balanceL  s    //(Ir:??7J;

 q#h-(AkG))':>J**:6DllnG"..wDGFO"..wAGFO#//AGG"4L )   ((r  c                 f    U R                  5         U R                  U5      nU R                  U5      $ )a=  
query for balance and get the amount of funds available for trading or funds locked in orders

https://docs.bitso.com/bitso-api/docs/get-account-balance

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
)load_marketsprivateGetBalancer  )r  r  r  s      r  fetch_balancebitso.fetch_balance_  s3     	))&14 !!(++r  r^  c           	      *   U R                  5         U R                  U5      nSUS   0nU R                  U R                  XS5      5      nU R	                  US5      nU R                  U R                  US5      5      nU R                  XtS   USSSS	5      $ )
a  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://docs.bitso.com/bitso-api/docs/list-order-book

:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: the maximum amount of order book entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
rS  r   r  
updated_atr^  bidsasksri  r1  )r  r  publicGetOrderBookr  r  rJ  r(  parse_order_book)	r  r^  r   r  r  r  r  	orderbookrB  s	            r  fetch_order_bookbitso.fetch_order_book  s     	V$F4L
 **4;;w+GHOOHi8	NN4#3#3I|#LM	$$Yx0@)VU[]dfnoor  r   r  c                 4   U R                  S U5      nU R                  U R                  US5      5      nU R                  US5      nU R                  US5      n[        R                  " Xe5      nU R                  US5      nU R                  0 SU_SU_SU R                  U5      _SU R                  US5      _S	U R                  US	5      _S
U R                  US
5      _SS _SU R                  US5      _SS _SU_SS _SU_SU_SS _SS _SS _SS _UUUS.EU5      $ )Nr:  vwapr\  lastr^  rB  rC  highlowbid	bidVolumeask	askVolumeopenclosepreviousClosechangerZ  average)
baseVolumequoteVolumer=  )safe_symbolrJ  r(  r    
string_mulsafe_tickerrL  )	r  r   r  r^  rB  r  r  r  r  s	            r  parse_tickerbitso.parse_ticker  s    !!$/NN4#3#3FL#IJ	/%%fh7
((:/ !
f!
!
 Y/!
 D$$VV4	!

 4##FE2!
 4##FE2!
 !
 4##FE2!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&)!
* + 	r  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US5      nU R                  Xc5      $ )a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://docs.bitso.com/bitso-api/docs/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>`
rS  r   r  )r  r  publicGetTickerr  r  r  )r  r^  r  r  r  r  r   s          r  fetch_tickerbitso.fetch_ticker  sl     	V$F4L
 ''G(DE95$   00r  r   	timeframec                    U R                  5         U R                  U5      nUS   U R                  U R                  X"5      S.nUb3  X7S'   Ub+  U R	                  U5      nU R                  X8U-  S-  5      US'   O3Ub0  U R                  5       n	XS'   XR	                  U5      S-  U-  -
  US'   U R                  U R                  Xu5      5      n
U R                  U
S/ 5      nU R                  XX#U5      $ )a  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
:param str symbol: unified symbol of the market to fetch OHLCV data for
:param str timeframe: the length of time each candle represents
:param int [since]: timestamp in ms of the earliest candle to fetch
:param int [limit]: the maximum amount of candles to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int[][]: A list of candles ordered, open, high, low, close, volume
r   )rS  time_bucketstarti  endr  )r  r  r(  r  parse_timeframesummillisecondspublicGetOhlcr  	safe_listparse_ohlcvs)r  r^  r  r  r   r  r  r  durationnowr  r  s               r  fetch_ohlcvbitso.fetch_ohlcv  s    	V$4L++DOOYR
 $G //	:!%%E1AD1H!I##%C EN"%9%9)%Dt%Ke%SSGG%%dkk'&BC( ..9b9  )EJJr  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      /$ )Nbucket_start_time
first_ratemax_ratemin_rate	last_rater\  )safe_integerr  )r  ohlcvr  s      r  parse_ohlcvbitso.parse_ohlcv  so      e%89UL1UJ/UJ/UK0UH-
 	
r  r#  c                     U R                  U R                  US5      5      nU R                  US5      nU R                  XBS5      nU R                  US5      nU R                  US5      nS nUb  Xg:X  a  SnOSnOUS:X  a  S	nOSnU R                  US
S5      n	U	b  [        R
                  " U	5      n	S n
U R                  US5      nUb(  U R                  US5      nU R                  U5      nU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U R                  US5      nU R                  UUUU R                  U5      UUS UUUU	UU
S.U5      $ )Nr:  rS  rT  side
maker_siderW  rV  buysellr1  majorfees_amountfees_currencyr8  minorri  oidr5  )r   r=  rB  rC  r^  orderr)  r  takerOrMakerri  r1  r9  r$  )	rJ  r(  r  rH  r    rI  rG  
safe_traderL  )r  r#  r  rB  marketIdr^  r  	makerSider  r1  r$  feeCostfeeCurrencyIdfeeCurrencyr9  ri  orderIdr   s                     r  parse_tradebitso.parse_trade2  s   b NN4#3#3E<#HI	##E62!!(C8v.$$UL9	 &&E!##E8W=''/F""5-8 ,,UODM11-@K'C w/%%d+D  0""5%0eU+"Y/( 
  	r  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  Xd5      5      nU R	                  US   XRU5      $ )a  
get the list of most recent trades for a particular symbol

https://docs.bitso.com/bitso-api/docs/list-trades

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
rS  r   r  )r  r  publicGetTradesr  parse_trades)r  r^  r  r   r  r  r  r  s           r  fetch_tradesbitso.fetch_trades  sc     	V$F4L
 ''G(DE  )!4fUKKr  c                 x   U R                  5         U R                  U5      nU R                  US0 5      nU R                  US/ 5      n0 n[        S[	        U5      5       HW  nXF   nU R                  US5      nU R                  USS5      n	UU	U R                  US5      U R                  US5      S	S	S
.XY'   MY     U$ )a"  
fetch the trading fees for multiple markets

https://docs.bitso.com/bitso-api/docs/list-fees

: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
r  r   r   rS  NrT  maker_fee_decimaltaker_fee_decimalT)r=  r^  rW  rV  rZ  r[  )r  privateGetFeesr  rz  r{  r(  r  r  )
r  r  r  r  r   r  r  r$  r  r^  s
             r  fetch_trading_feesbitso.fetch_trading_fees  s     	&&v.X //(Ir:w3q#d)$A'C''V4H%%hc:F ))#/BC))#/BC"!FN	 % r     c                 \   U R                  5         U R                  U5      nSU;   nUb  U(       d  [        U R                  S-   5      eU(       a   U R	                  US[        US   5      05      nUS   US.nU R                  U R	                  Xt5      5      nU R                  US   XRU5      $ )a  
fetch all trades made by the user

https://docs.bitso.com/bitso-api/docs/user-trades

: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>`
markerz fetchMyTrades() does not support fetching trades starting from a timestamp with the `since` argument, use the `marker` extra param to filter starting from an integer trade idr   rS  r   r  )r  r  r   r   r  intprivateGetUserTradesr  )	r  r^  r  r   r  r  markerInParamsr  r  s	            r  fetch_my_tradesbitso.fetch_my_trades  s     	V$ #f, ~  +\  !\  ]  ][[#fX./* F 4L
 ,,T[[-IJ  )!4fUKKr  r)  r  r1  ri  c                 N   U R                  5         U R                  U5      nUS   UUU R                  US   U5      S.nUS:X  a  U R                  US   U5      US'   U R	                  U R                  X5      5      n	U R                  U	S   S5      n
U R                  U	U
S.U5      $ )	aN  
create a trade order

https://docs.bitso.com/bitso-api/docs/place-an-order

:param str symbol: unified symbol of the market to create an order in
:param str type: 'market' or 'limit'
:param str side: 'buy' or 'sell'
:param float amount: how much of currency you want to trade in units of base currency
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r   r^  )rS  r  r)  r  r   ri  r  r  r=  r   )r  r  amount_to_precisionprice_to_precisionprivatePostOrdersr  r(  
safe_order)r  r^  r)  r  r1  ri  r  r  r  r  r   s              r  create_orderbitso.create_order  s     	V$4L--fX.>G	
 7?#66vh7GOGG))$++g*FGhy159 
  	r  r   c                     U R                  5         SU0nU R                  U R                  XC5      5      nU R                  US/ 5      nU R	                  US5      nU R                  UUS.5      $ )a9  
cancels an open order

https://docs.bitso.com/bitso-api/docs/cancel-an-order

:param str id: order id
:param str symbol: not used by bitso cancelOrder()
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r  r  r   r  )r  privateDeleteOrdersOidr  r  r(  r  )r  r   r^  r  r  r  r  r  s           r  cancel_orderbitso.cancel_order3  sy     	2
 ..t{{7/KL ..9b9""7A. 
  	r  idsc                    [        U[        5      (       d  [        U R                  S-   5      eSnUb  U R	                  U5      nSR                  U5      nSU0nU R                  U R                  Xc5      5      nU R                  US/ 5      n/ n	[        S[        U5      5       H'  n
X   nU	R                  U R                  X5      5        M)     U	$ )a=  
cancel multiple orders

https://docs.bitso.com/bitso-api/docs/cancel-an-order

:param str[] ids: order ids
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
z/ cancelOrders() ids argument should be an arrayN,oidsr  r   )
isinstancelistr   r   r  joinprivateDeleteOrdersr  r  rz  r{  r  parse_order)r  r  r^  r  r  r  r  r  r  r   r  r   s               r  cancel_ordersbitso.cancel_ordersP  s     #t$$#DGG._$_``[[(Fxx}D
 ++DKK,HI //(Ir:q#g,'ABMM$**267 ( r  c                    Ub  [        U R                  S-   5      eU R                  U5      nU R                  US/ 5      n/ n[	        S[        U5      5       H'  nU R                  XF   5      nUR                  U5        M)     U$ )aP  
cancel all open orders

https://docs.bitso.com/bitso-api/docs/cancel-an-order

:param None symbol: bitso does not support canceling orders for only a specific market
: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>`
zX cancelAllOrders() deletes all orders for user, it does not support filtering by symbol.r  r   )r   r   privateDeleteOrdersAllr  rz  r{  r  r  )r  r^  r  r  r  canceledOrdersr  r  s           r  cancel_all_ordersbitso.cancel_all_ordersr  s     tww  *D   D  E  E..v6 //(Ir:q#g,'A$$WZ0E!!%( ( r  rF  c                 4    SSSSS.nU R                  X!U5      $ )Nr  closed)zpartial-fillzpartially filledqueued	completedr'  r  rF  statusess      r  parse_order_statusbitso.parse_order_status  s*    " &!	
 &99r  r  c                    S n[        U[        5      (       a  UnO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U R	                  XbS5      nU R                  US5      nU R                  U R                  US5      5      n	U R                  US5      n
U R                  US	5      nU R                  US
5      nU R                  U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S _SS _SU_SU
_SS _SU_SS _SU_SS _US S S S.EU5      $ )Nr  r  rF  rS  rT  r)  r:  ri  original_amountunfilled_amount	client_idr=  r   clientOrderIdrB  rC  lastTradeTimestampr^  r   postOnlyr   r1  r9  	remainingfilled)rF  r$  r  r   )r  strr(  r(  r  rJ  r  rL  )r  r  r  r   r  rF  r  r^  	orderTyperB  ri  r1  r1  r.  s                 r  r  bitso.parse_order  s    eS!!B!!%/Bv.(()9)9%)JK##E62!!(C8$$UF3	NN4#3#3E<#HI	  0!!%):;$$U,=>	((<  
E 
" 
 ] 
 	 

 Y/ 
 !$ 
 f 
 I 
 4 
  
 D 
 U 
 D 
 f 
 D 
  ! 
" d# 
$ + 
, - 	r  c                 `   U R                  5         U R                  U5      nSU;   nUb  U(       d  [        U R                  S-   5      eU(       a   U R	                  US[        US   5      05      nUS   US.nU R                  U R	                  Xt5      5      nU R                  US   XRU5      n	U	$ )a  
fetch all unfilled currently open orders

https://docs.bitso.com/bitso-api/docs/list-open-orders

:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch open orders for
:param int [limit]: the maximum number of  open orders structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
r  z fetchOpenOrders() does not support fetching orders starting from a timestamp with the `since` argument, use the `marker` extra param to filter starting from an integer trade idr   r   r  )r  r  r   r   r  r  privateGetOpenOrdersparse_orders)
r  r^  r  r   r  r  r  r  r  r   s
             r  fetch_open_ordersbitso.fetch_open_orders  s     	V$ #f, ~  +^  !^  _  _[[#fX./* F 4L
 ,,T[[-IJ""8I#6uMr  c                 "   U R                  5         U R                  SU05      nU R                  US5      n[        U[        5      (       a(  [        US   5      nUS:X  a  U R                  US   5      $ [        U R                  S-   U-   S-   5      e)aT  
fetches information on an order made by the user

https://docs.bitso.com/bitso-api/docs/look-up-orders

:param str id: the order id
:param str symbol: not used by bitso fetchOrder
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r  r     r   z: The order z not found.)	r  privateGetOrdersOidr  r  r  r{  r  r   r   )r  r   r^  r  r  r  	numOrderss          r  fetch_orderbitso.fetch_order  s     	++2-
  //(I6gt$$HY/0IA~''
33DGGn4r9MIJJr  c                     U R                  5         U R                  U5      nSU0nU R                  U R                  Xu5      5      nU R	                  US   U5      $ )a  
fetch all the trades made from a single order

https://docs.bitso.com/bitso-api/docs/list-user-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>`
r  r  )r  r  privateGetOrderTradesOidr  r  )	r  r   r^  r  r   r  r  r  r  s	            r  fetch_order_tradesbitso.fetch_order_trades  s]     	V$2
 00W1MN  )!4f==r  c                     U R                  5         SU0nU R                  U R                  XC5      5      nU R                  US/ 5      nU R	                  US0 5      nU R                  U5      $ )a  
fetch information on a deposit

https://docs.bitso.com/bitso-payouts-funding/docs/fundings

:param str id: deposit id
:param str code: bitso does not support filtering by currency code and will ignore self argument
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
r3  r  r   )r  privateGetFundingsFidr  r  	safe_dictparse_transaction)r  r   r  r  r  r  transactionsfirsts           r  fetch_depositbitso.fetch_deposit  sn     	2
 --dkk'.JK0 xB?|Q3%%e,,r  c                     U R                  5         SnUb  U R                  U5      nU R                  U5      nU R                  US/ 5      nU R	                  XuX#U5      $ )a  
fetch all deposits made to an account

https://docs.bitso.com/bitso-payouts-funding/docs/fundings

:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch deposits for
:param int [limit]: the maximum number of deposits structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr  )r  r  privateGetFundingsr  parse_transactions)r  r  r  r   r  r  r  rI  s           r  fetch_depositsbitso.fetch_deposits=  sb     	}}T*H**620 ~~h	2>&&|uVTTr  c                    U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US   S5      nSnUR                  S5      S:  a5  UR                  S5      nU R	                  US5      nU R	                  US5      nU R                  U5        UUSUUS	.$ )
a  
fetch the deposit address for a currency associated with self account
: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>`
fund_currencyr   r  account_identifierNz?dt=r   r<  )r=  r  networkaddresstag)r  r  privateGetFundingDestinationr  r(  findr|  check_address)	r  r  r  r  r  r  rV  rW  partss	            r  fetch_deposit_addressbitso.fetch_deposit_addressh  s     	==&Xd^
 44T[[5QR""8I#68LM<<1$MM&)E&&ua0G""5!,C7#
 	
r  codesc                    U R                  5         U R                  U5      n0 nU R                  US0 5      nU R                  US/ 5      n[        S[	        U5      5       H`  nXg   nU R                  US5      n	U R                  U	5      n
Ub  U R                  X5      (       d  ME  U R                  US5      SUSS.S.XJ'   Mb     U R                  US	/ 5      n[        UR                  5       5      n[        S[	        U5      5       H  nX   n	U R                  U	5      n
Ub  U R                  X5      (       d  M3  U R                  XJ   S
5      U R                  X5      U R                  XJ   S   S
5      U R                  X5      S.S.XJ'   M     U$ )ar  
@deprecated
       please use fetchDepositWithdrawFees instead

       https://docs.bitso.com/bitso-api/docs/list-fees

       :param str[]|None codes: list of unified currency codes
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :returns dict[]: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
       r  deposit_feesr   r  Nr$  )depositr   )ra  r   r=  withdrawal_feesra  r=  )r  r  r  rz  r{  r(  rG  in_arrayr  r  keys)r  r^  r  r  r  r  depositFeesr  
depositFeerO  r  withdrawalFeescurrencyIdss                r  fetch_transaction_feesbitso.fetch_transaction_fees  s    	&&v.X //(Ir:oog~rBq#k*+A$J))*jAJ**:6D!4==+E+E++J> ) $FL , 2CRH>..01q#k*+A$J**:6D!4==+E+E??6<C ,,^H#v|F/CYO $ 0 0 LFL , r  c                     U R                  5         U R                  U5      nU R                  US/ 5      nU R                  XA5      $ )a0  
fetch deposit and withdraw fees

https://docs.bitso.com/bitso-api/docs/list-fees

:param str[]|None codes: list of unified currency codes
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
r  )r  r  r  parse_deposit_withdraw_fees)r  r^  r  r  r  s        r  fetch_deposit_withdraw_fees!bitso.fetch_deposit_withdraw_fees  sF     	&&v.X ..9b9//??r  c                    0 nU R                  US/ 5      nU R                  US/ 5      n[        S[        U5      5       Hh  nXW   nU R                  US5      n	U R	                  U	5      n
Ub  X;   d  M4  U R                  US5      U R                  US5      (       + S.S S S.0 US.XJ'   Mj     [        UR                  5       5      n[        S[        U5      5       Hp  nX   n	U R	                  U	5      n
Ub  X;   d  M"  U R                  Xi   5      nU R                  XJ5      nUc  U R                  0 5      XJ'   XU
   S	   S'   XU
   S
   U
'   Mr     U$ )Nr`  rb  r   r  r$  is_fixed)r$  rZ  )ra  r   r   r=  r   r=  )
r  rz  r{  r(  rG  r  r  rd  r~  deposit_withdraw_fee)r  r  r^  currencyIdKeyr  depositResponsewithdrawalResponser  entryrO  r  withdrawalKeyswithdrawFeeresultValues                 r  rl  !bitso.parse_deposit_withdraw_fees  so   R //(NBG!__X7H"Mq#o./A#&E))%<J**:6D4=  $//u=*.//%*L&L 
  $&*! !#!  0" 05578q#n-.A'*J**:6D4="//0B0NO"oof;&#'#<#<R#@FL2=tZ(/-8tV$T* / r  rV  rW  c                    U R                  XE5      u  pEU R                  U5        U R                  5         SSSSSS.nU R                  U5      nX;   a  Xa   OSnUc  [	        U R
                  S-   U-   5      eUUUS	.n	S
U-   S-   n
[        X
5      " U R                  X5      5      nU R                  US/ 5      nU R                  US5      nU R                  X5      $ )aO  
make a withdrawal
: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>`
BitcoinEtherRippleBcashLitecoin)BTCETHr   BCHLTCNz not valid withdraw coin: )r1  rV  destination_tagprivatePost
Withdrawalr  r   )handle_withdraw_tag_and_paramsrZ  r  r  r   r   getattrr  r  rG  rH  )r  r  r1  rV  rW  r  methodsr  methodr  classMethodr  r  rJ  s                 r  r   bitso.withdrawb  s     99#F7#
 ==&#'?>*F F MNN"

 $f,|;4-dkk'.JK( //(Ir:w*%%e66r  r"  c                    U R                  USS5      nU R                  X25      nU R                  U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S5      nU R                  US	5      n	U R                  US
5      n
U R	                  U5      nUb  UR                  5       OS n0 SU R                  US
S5      _SU R                  US5      _SU R                  U5      _SU_SU_SU_SUb  UOU_SU_SU R                  US5      _SU
c  SOS_SU R                  X25      _S	U R                  U	5      _SS _SS _SS _SS _SS _S S US.E$ )Nr  assetr2  r:  withdrawal_addressreceiving_addressrU  r  rF  r4  r   r3  txidtx_hashrB  rC  addressFromrV  	addressTor1  r)  ra  r&  updatedtagFromrW  tagTocomment)internalr$  r=  )
rH  r  r  r(  network_id_to_coder}  rJ  r  rG  parse_transaction_status)r  r"  r  rO  r2  rC  withdrawalAddressreceivingAddress	networkIdrF  
withdrawIdnetworkCodenetworkCodeUppers                r  rH  bitso.parse_transaction  s   J ''ZI
%%j;//+y"=##K> ,,W6JK++G5HI&&{IxH	!!+x8%%k59
--i83>3J;,,.QU
$$$[%?
D$$Wi8
 1
 	

 '
 +
 ->-J(Qa
 *
 d&&{H=
 *"4I<
 //
E
 d33F;
 t
 t
 4
  T!
" t#
$ )
 	
r  c                 4    SSSSS.nU R                  X!U5      $ )Npendingr<  failed)r  in_progresscompleter  r'  r&  s      r  r  bitso.parse_transaction_status  s*     $	
 &99r  c                 "    U R                  5       $ N)r  )r  s    r  noncebitso.nonce  s      ""r  r   GETc                    SU R                   -   S-   U R                  X5      -   nU R                  X@R                  U5      5      nUS:X  d  US:X  a  U(       a  USU R	                  U5      -   -  nU R
                  S   S   U-   n	US:X  a  U R                  5         [        U R                  5       5      n
SU-   nS	R                  XU/5      nUS:w  a"  US:w  a  U(       a  U R                  U5      nX-  nU R                  U R                  U5      U R                  U R                  5      [        R                  5      nU R                   S
-   U
-   S
-   U-   nSSU-   0nXXeS.$ )Nr_  r  DELETE?r   r   r   z/api :AuthorizationzBitso )urlr  bodyheaders)r  implode_paramsomitextract_params	urlencoder  check_required_credentialsr3  r  r  jsonhmacencodesecrethashlibsha256apiKey)r  pathr   r  r  r  r  endpointqueryr  r  r  	signatureauths                 r  sign
bitso.sign  sO   %+d.A.A$.OO		&"5"5d";<U?f0C$.."777iiv&1)++-

%E(Hgguh78G6X#599U+DOG		$++g"6DKK8PRYR`R`aI;;$u,s2Y>DDG dOOr  httpCodereasonr  r  r  r  c
                    Uc  g SU;   a  U R                  USS5      n
[        U
[        5      (       a  U
S:X  d  U
S:X  a  Sn
OSn
U
(       dz  U R                  S-   U R	                  U5      -   nU R                  US5      nUc  [        U5      eU R                  US5      nU R                  U R                  X5        [        U5      eg )	NsuccessFtrue1T errorr  )
	safe_boolr  r3  r   r  r  r   r(  throw_exactly_matched_exceptionr	  )r  r  r  r  r  r  r  r  requestHeadersrequestBodyr  feedbackr  r  s                 r  handle_errorsbitso.handle_errors  s      nnXy%@G'3''v%7c>"G#G77S=499X+>>':='11''v644T__dU#H--r   r  )NN)C__name__
__module____qualname____firstlineno__r   r  r   r	   r   r
   r  r+  dictr   rP  r   r  r   r  r  r3  r   r  r   r  r  r  r  r  r   r  r  r   r  r  r   r   floatr   r  r  r   r  r   r(  r  r9  r?  rC  rK  r   rP  r   r\  r   ri  rm  rl  r   rH  r  r  r  r  r  __static_attributes____classcell__)r  s   @r  r"   r"      s|   S# Sj (,$TZ\ &B &BC &Bs &Baefqar &BP3ct cx c; cJ $& G$v, GR) )& $& $,( $,L :>b ps p3 pY p**4 * *6 *X 02 "13 "1f "1H 9=4^bkm .K# .K# .KS .KX[ .Krvw{r| .K`
 
4 
0a av a aF 6:UW L3 Ls L# L\`af\g L( )+ E{ EN -1tRT]_ "Lc "L "LC "LH gksu 3 i y RW `c > 37r s C : ;?r  c  C  dSXk  D /32  $u+ 4: :+ +v + +Z /3TV_a # #3 #c #fjkpfq #J 26b Kc K3 K, 9=4^bkm >S ># >S >X[ >* 26b )- )-3 )-V *.Dt\^ )U3 )Uc )U )Ucghsct )UV 79 
# 
^ 
8 7;2 XG Xt <@ 8@ 8@tHT KOWY 47S 47% 47# 47C 47^i 47lE
T E
X E
Q\ E
N:s :# &eBSW P0c 3 S # X\ dg  r  r"   )'ccxt.base.exchanger   ccxt.abstract.bitsor   r  ccxt.base.typesr   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   ccxt.base.decimal_to_precisionr   ccxt.base.preciser    r"   r  r  r  <module>r     s\    ( +  B  B  B  B  B  * 0 . ' * ) ) 4 %BHk Br  