
    !:h'                       d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlm Z  d dlm!Z! d dl"m#Z# d dl$m%Z%  G d dee      Z&y)    )Exchange)ImplicitAPIN)AnyBalancesCurrency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                   j    e Zd Zdef fdZdddi fdedededee   fdZ	d Z
dEd	ed
edefdZi fdee   fdZdefdZi fdefdZdi fdededefdZdEdededefdZi fdedefdZdddi fdedededee   fdZdEdedefdZdEdededefdZddi fdedededee   fdZi fdefdZ dddi fdededefdZ!di fdede"de#d e$d!e%f
d"Z&di fd#edefd$Z'di fdedee(   fd%Z)di fdedee(   fd&Z*d'efd(Z+dEd)edede(fd*Z,dddi fdedededee(   fd+Z-di fd#edefd,Z.dddi fd#edededefd-Z/di fd#edefd.Z0dddi fdedededee1   fd/Z2i fdede3fd0Z4di fd1e5fd2Z6di fd1e5fd3Z7dFd4Z8di fded e$d5ede1fd6Z9dEd7ed
ede1fd8Z:d'efd9Z;d: Z<d;d<i ddfd=Z=d>e>d?ed@edAedBedCefdDZ? xZ@S )Gbitsoreturnc                    | j                  t        t        |          dddgddi dd ddd	d
dd
dd
dd
dd
dd
dd
dd
dddddddd
dd
dd
ddi dd
dd
dd
dd
dddd
dd
d d
d!d
d"d
d#d
d$d
d%d
d&dd'dd(d
d)d
i d*dd+d
d,d-d.dd/d
d0d
d1d
d2d
d3d
d4d
d5d
d6d
d7d
d8d
d9d
d:dd;d
i d<d
d=d
d>d
d?d
d@d
dAd
dBd
dCd
dDd
dEddFd
dGd
dHd
dId
dJddKddLd
i dMd
dNd
dOddPd
dQd
dRddSddTddUd
dVd
dWd
dXd
dYd
dZd
d[d
d\d
d]d
i d^dd_d
d`d
daddbd
dcdddd
deddfd
dgd
dhd
did
djd
dkd
dld
dmd
dnd
d
d
d
ddodpdqdridqdsidtdudvdwdxt        dydzdzd{d|d}d~dddddddddddddd	dg dig dg dg dddd
d
dd d d
d
d dddd
dd
d
d
d
d
d
d
dd d
dd d ddd
d
d
ddd
dd
d
ddd d ddid	d d dd d ddt
        t        t        dd      S )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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,  )	sandboxr8   createOrdersrj   rr   ro   fetchOrdersfetchClosedOrdersrk   )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/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/bitso.pyr
  zbitso.describe   s   eT ; =kkk %k 	k
 %k %k Uk $Uk 'k k "4k tk k $Uk  k  '!k" t#k$ 7%k& 9%'k( ()k*  +k, -k. &u/k0 "51k2 +E3k4 )%5k6 #E7k8 ,U9k: ';k< (=k> ?k@ &tAkB (CkD 1%EkF  GkH +EIkJ *:KkL +DMkN &uOkP 'QkR (SkT #EUkV *5WkX $UYkZ u[k\ "5]k^ *5_k` +Eakb )%ckd tekf  gkh !%ikj %ekkl $Umkn &uokp -eqkr /skt "5ukv #Ewkx +Eykz {k| !%}k~ "5k@ &uAkB +ECkD  EkF dGkH $UIkJ +EKkL %eMkN "4OkP uQkR #ESkT dUkV !$WkX #DYkZ  [k\ ']k^ $U_k` !%akb *5ckd (ekf %egkh )%ikj )%kkl tmkn okp Uqkr tskt "5ukv #Dwkx &uykz '{k| $U}k~  k@ !%AkB )%CkD EkF #EGkH &uIkJ uKkL UMkN "'#(! UkZ j3 9 +309 ' $ 
 %/"$""	 
  ,I)4n  %&+(,,0,0).+06: $(#'"&#(	( #($)$)27+0/4#(+$. %)&+!$$(%)*.& ',#($)*.	# ',!$#($)*.( $()-#a3j ##
 ##s=~ ,#"YQ@
 Q Q	    Ncodesincer   c                     i }|||d<   | j                  | j                  ||            }| j                  |dg       }| j                  |      }| j	                  ||||      S )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_ledgerzbitso.fetch_ledger,  so     $GG((Wf)EF0 //(Ir:%%d+  (E5AAr  c                 6    ddddd}| j                  |||      S )Ntransactiontradefee)funding
withdrawalr  r   safe_string)r  typetypess      r  parse_ledger_entry_typezbitso.parse_ledger_entry_typeT  s,    $'	
 tT22r  itemr  c                    | j                  |d      }| j                  |      }| j                  |dg       }| j                  |di       }d }d }| j                  |d      }	| j                  |d      }
| j                  |
|      }| j	                  |
|      }| j                  |di       }| j                  |dd      }|| j                  |d	      }|d
k(  rd}n1|dk(  rd}n)|dk(  rd }n!|dk(  rd}t        j                  |	      }||d}| j                  | j                  |d            }| j                  || j                  |d      |d |d |||	|| j                  |      d d d|d|      S )N	operationbalance_updatesr   amountr  detailsfidwidtidr!  inr"  outr  r   costr  
created_ateidok)infor   	directionaccountreferenceIdreferenceAccountr%  r  r,  	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firstBalancer9  r   r,  
currencyIdr  r-  r;  r4  r=  s                   r  parse_ledger_entryzbitso.parse_ledger_entry]  s   n $$T;7	++I6/@"E~q"=	!!,9%%lJ?
&&z8<%%j(;//$	26((%?**7E:K	!I,&I'!I%I%%f-D$C NN4#3#3D,#GH	%%""4/"& $"Y/'
  ! 	r  c                 ~   | j                  |      }| j                  |dg       }g }t        dt        |            D ]  }||   }| j	                  |d      }|j                  d      \  }}	|j                         }
|	j                         }| j                  |
      }
| j                  |      }| j                  |di       }| j                  |di       }| j	                  |d      }| j	                  |d      }| j                  t        j                  |d	            }| j                  t        j                  |d	            }| j                  |d
g       }||ddd}g }g }t        dt        |            D ]s  }||   }| j                  |d      }| j                  |d      }| j                  |d      }|j                  ||g       |j                  ||g       |dk(  sj||d<   ||d<   u ||d}||d<   | j                  | j                  d   || j                  d         }|j                  | j                  i d|d|
dz   |z   d|
d|ddd|d|	ddddddddd dd!dd"dd#dd$dd%dd||ddddd| j                  | j                  d   |
| j                  d         | j                  |d&|      d'ddd(| j                  |d)      | j                  |d*      d(| j                  |d+      | j                  |d,      d(| j                  |d-      | j                  |d.      d(d/d|d0|               |S )1a  
        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)rP  rQ  
percentage	tierBasedvolume)rP  rQ  tiersr   r   r   symbol/basequotesettleNbaseIdquoteIdsettleIdr%  r)   r*   Fr+   r,   r-   activecontractr   	tick_size)r,  price)minmaxminimum_amountmaximum_amountminimum_pricemaximum_priceminimum_valuemaximum_value)r   r,  rc  r4  )r   rP  rQ  contractSizeexpiryexpiryDatetimestrike
optionTyper   limitscreatedr8  )publicGetAvailableBooksr  rangelenr$  splitupperrB  parse_numberr    
string_divsafe_numberappendr  r  )r  r  r  marketsresultimarketr   r]  r^  rZ  r[  r   flatRatetakerStringmakerStringrP  rQ  feeTiersr   	takerFees	makerFeesjtierrV  takerFeemakerFeerW  defaultPricePrecisions                                r  fetch_marketszbitso.fetch_markets  s+    //7B //(Ir:q#g,' Z	AQZF!!&&1B hhsmOFG<<>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\\+5NPUW[WcWcdvWw$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$PTP\P\]oPpq!--fkCXY  $#!
  $//8HI#//8HI
  $//H#//H
  $//H#//H$  c2'd e2 2QZ	v r  c                    | j                  |di       }| j                  |dg       }|d d d}t        dt        |            D ]~  }||   }| j                  |d      }| j	                  |      }| j                         }	| j                  |d      |	d<   | j                  |d      |	d	<   | j                  |d
      |	d
<   |	||<    | j                  |      S )Nr  balances)r8  r=  r>  r   r  	availablefreelockedusedtotal)r  rt  ru  r$  rB  r:  safe_balance)
r  r  r  r  r}  r~  r   rJ  r  r:  s
             r  parse_balancezbitso.parse_balanceK  s    //(Ir:??7J;

 q#h-( 	#AqkG))':>J**:6DllnG"..wDGFO"..wAGFO#//AGG"F4L	#   ((r  c                 f    | j                          | j                  |      }| j                  |      S )ae  
        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_balancezbitso.fetch_balance^  s3     	))&14 !!(++r  rX  c           	      .   | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |d      }| j                  | j                  |d            }| j                  ||d   |dddd	      S )
a3  
        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
        rM  r   r  
updated_atrX  bidsasksrc  r,  )r  r  publicGetOrderBookr  r  rE  r$  parse_order_book)	r  rX  r   r  r  r  r  	orderbookr=  s	            r  fetch_order_bookzbitso.fetch_order_book  s     	V$F4L
 **4;;w+GHOOHi8	NN4#3#3I|#LM	$$Yx0@)VU[]dfnoor  r   r  c                 4   | j                  d |      }| j                  | j                  |d            }| j                  |d      }| j                  |d      }t        j                  ||      }| j                  |d      }| j                  i d|d|d| j                  |      d| j                  |d      d	| j                  |d	      d
| j                  |d
      dd d| j                  |d      dd d|dd d|d|dd dd dd dd |||d|      S )Nr5  vwaprV  lastrX  r=  r>  highlowbid	bidVolumeask	askVolumeopenclosepreviousClosechangerT  average)
baseVolumequoteVolumer8  )safe_symbolrE  r$  r    
string_mulsafe_tickerrG  )	r  r   r  rX  r=  r  r  r  r  s	            r  parse_tickerzbitso.parse_ticker  s    !!$/NN4#3#3FL#IJ	/%%fh7
((T:/ !
f!
!
 Y/!
 D$$VV4	!

 4##FE2!
 4##FE2!
 !
 4##FE2!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&)!
* + 	r  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |d      }| j                  ||      S )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>`
        rM  r   r  )r  r  publicGetTickerr  r  r  )r  rX  r  r  r  r  r   s          r  fetch_tickerzbitso.fetch_ticker  sp     	V$F4L
 ''GV(DE95$   00r  r   c                    | j                          | j                  |      }|d   | j                  | j                  ||      d}|4||d<   |a| j	                  |      }| j                  |||z  dz        |d<   n4|2| j                         }	|	|d<   |	| j	                  |      dz  |z  z
  |d<   | j                  | j                  ||            }
| j                  |
dg       }| j                  |||||      S )aQ  
        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   )rM  time_bucketstarti  endr  )r  r  r$  r  parse_timeframesummillisecondspublicGetOhlcr  	safe_listparse_ohlcvs)r  rX  	timeframer  r   r  r  r  durationnowr  r  s               r  fetch_ohlcvzbitso.fetch_ohlcv  s    	V$4L++DOOY	R
 $GG //	:!%%E1AD1H!I##%C GEN"T%9%9)%Dt%Ke%SSGG%%dkk'6&BC( ..9b9  &)UEJJr  c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nbucket_start_time
first_ratemax_ratemin_rate	last_raterV  )safe_integerrz  )r  ohlcvr  s      r  parse_ohlcvzbitso.parse_ohlcv  so      e%89UL1UJ/UJ/UK0UH-
 	
r  r  c                    | j                  | j                  |d            }| j                  |d      }| j                  ||d      }| j                  |d      }| j                  |d      }d }|||k(  rd}nd}n
|dk(  rd	}nd}| j                  |d
d      }	|	t	        j
                  |	      }	d }
| j                  |d      }|(| j                  |d      }| j                  |      }||d}
| j                  |d      }|t	        j
                  |      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |||| j                  |      ||d ||||	||
d|      S )Nr5  rM  rN  side
maker_siderQ  rP  buysellr,  majorfees_amountfees_currencyr3  minorrc  oidr0  )r   r8  r=  r>  rX  orderr%  r  takerOrMakerrc  r,  r4  r   )	rE  r$  r  rC  r    rD  rB  
safe_traderG  )r  r  r  r=  marketIdrX  r  	makerSider  r,  r   feeCostfeeCurrencyIdfeeCurrencyr4  rc  orderIdr   s                     r  parse_tradezbitso.parse_trade1  s   b NN4#3#3E<#HI	##E62!!(FC8v.$$UL9	y &&E!##E8W=''/F""5-8 ,,UODM11-@K'C w/%%d+D  0""5%0eU+"Y/( 
  	r  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |d   |||      S )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>`
        rM  r   r  )r  r  publicGetTradesr  parse_trades)r  rX  r  r   r  r  r  r  s           r  fetch_tradeszbitso.fetch_trades  sg     	V$F4L
 ''GV(DE  )!4feUKKr  c                 x   | j                          | j                  |      }| j                  |di       }| j                  |dg       }i }t        dt	        |            D ]X  }||   }| j                  |d      }| j                  |dd      }	||	| j                  |d      | j                  |d      d	d	d
||	<   Z |S )aJ  
        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   rM  NrN  maker_fee_decimaltaker_fee_decimalT)r8  rX  rQ  rP  rT  rU  )r  privateGetFeesr  rt  ru  r$  r  rz  )
r  r  r  r  r   r}  r~  r   r  rX  s
             r  fetch_trading_feeszbitso.fetch_trading_fees  s     	&&v.X //(Ir:w3q#d)$ 	Aq'C''V4H%%hc:F ))#/BC))#/BC"!F6N		 r     c                 H   | j                          | j                  |      }d|v }||st        | j                  dz         |r | j	                  |dt        |d         i      }|d   |d}| j                  | j	                  ||            }| j                  |d   |||      S )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   rM  r   r  )r  r  r   r   r  intprivateGetUserTradesr  )	r  rX  r  r   r  r  markerInParamsr  r  s	            r  fetch_my_tradeszbitso.fetch_my_trades  s     	V$ #f, ~  +\  !\  ]  ][[#fX./* F 4L
 ,,T[[&-IJ  )!4feUKKr  r%  r  r,  rc  c                 N   | j                          | j                  |      }|d   ||| j                  |d   |      d}|dk(  r| j                  |d   |      |d<   | j	                  | j                  ||            }	| j                  |	d   d      }
| j                  |	|
d|      S )	a  
        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   rX  )rM  r  r%  r  r   rc  r  r  r8  r   )r  r  amount_to_precisionprice_to_precisionprivatePostOrdersr  r$  
safe_order)r  rX  r%  r  r,  rc  r  r  r  r  r   s              r  create_orderzbitso.create_order  s     	V$4L--fX.>G	
 7?#66vh7GOGG))$++gv*FGhy159 
  	r  r   c                     | j                          d|i}| j                  | j                  ||            }| j                  |dg       }| j	                  |d      }| j                  ||d      S )aq  
        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   rX  r  r  r  r  r  s           r  cancel_orderzbitso.cancel_order2  s{     	2
 ..t{{7F/KL ..9b9""7A. 
  	r  c                    t        |t              st        | j                  dz         d}|| j	                  |      }dj                  |      }d|i}| j                  | j                  ||            }| j                  |dg       }g }	t        dt        |            D ](  }
||
   }|	j                  | j                  ||             * |	S )au  
        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  rt  ru  r{  parse_order)r  idsrX  r  r  r   r  r  r  r   r~  r   s               r  cancel_orderszbitso.cancel_ordersO  s     #t$#DGG._$_``[[(Fxx}D
 ++DKK,HI //(Ir:q#g,' 	8ABMM$**2v67	8 r  c                    |t        | j                  dz         | j                  |      }| j                  |dg       }g }t	        dt        |            D ]'  }| j                  ||         }|j                  |       ) |S )a  
        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  rt  ru  r  r{  )r  rX  r  r  r  canceledOrdersr~  r  s           r  cancel_all_orderszbitso.cancel_all_ordersq  s     tww  *D   D  E  E..v6 //(Ir:q#g,' 	)A$$WQZ0E!!%(	) r  rA  c                 6    ddddd}| j                  |||      S )Nr  closed)zpartial-fillzpartially filledqueued	completedr#  r  rA  statusess      r  parse_order_statuszbitso.parse_order_status  s,    " &!	
 &&99r  r  c                    d }t        |t              r|}n| j                  |d      }| j                  |d      }| j                  | j                  |d            }| j                  |d      }| j	                  ||d      }| j                  |d      }| j                  | j                  |d            }	| j                  |d      }
| j                  |d	      }| j                  |d
      }| j                  |d      }| j                  i d|d|d|d|	d| j                  |	      dd d|d|dd dd d|d|
dd d|dd d|dd |d d d d|      S )Nr  r  rA  rM  rN  r%  r5  rc  original_amountunfilled_amount	client_idr8  r   clientOrderIdr=  r>  lastTradeTimestamprX  r   postOnlyr   r,  r4  	remainingfilled)rA  r   r  r   )r  strr$  r  r  rE  r  rG  )r  r  r  r   r  rA  r  rX  	orderTyper=  rc  r,  r  r  s                 r  r  zbitso.parse_order  s    eS!B!!%/Bv.(()9)9%)JK##E62!!(FC8$$UF3	NN4#3#3E<#HI	  0!!%):;$$U,=>	((<  
E 
" 
 ] 
 	 

 Y/ 
 !$ 
 f 
 I 
 4 
  
 D 
 U 
 D 
 f 
 D 
  ! 
" d# 
$ + 
, - 	r  c                 L   | j                          | j                  |      }d|v }||st        | j                  dz         |r | j	                  |dt        |d         i      }|d   |d}| j                  | j	                  ||            }| j                  |d   |||      }	|	S )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  rX  r  r   r  r  r  r  r  r   s
             r  fetch_open_orderszbitso.fetch_open_orders  s     	V$ #f, ~  +^  !^  _  _[[#fX./* F 4L
 ,,T[[&-IJ""8I#6uMr  c                    | j                          | j                  d|i      }| j                  |d      }t        |t              r't        |d         }|dk(  r| j                  |d         S t        | j                  dz   |z   dz         )a  
        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  ru  r  r   r   )r  r   rX  r  r  r  	numOrderss          r  fetch_orderzbitso.fetch_order  s     	++2-
  //(I6gt$HY/0IA~''
33DGGn4r9MIJJr  c                     | j                          | j                  |      }d|i}| j                  | j                  ||            }| j	                  |d   |      S )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   rX  r  r   r  r  r  r  s	            r  fetch_order_tradeszbitso.fetch_order_trades  s_     	V$2
 00Wf1MN  )!4f==r  c                     | j                          d|i}| j                  | j                  ||            }| j                  |dg       }| j	                  |di       }| j                  |      S )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>`
        r.  r  r   )r  privateGetFundingsFidr  r  	safe_dictparse_transaction)r  r   r  r  r  r  transactionsfirsts           r  fetch_depositzbitso.fetch_deposit  sp     	2
 --dkk'6.JK0 xB?|Q3%%e,,r  c                     | j                          d}|| j                  |      }| j                  |      }| j                  |dg       }| j	                  |||||      S )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  r.  s           r  fetch_depositszbitso.fetch_deposits<  sf     	}}T*H**620 ~~h	2>&&|XueVTTr  c                    | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |d   d      }d}|j                  d      dk\  r5|j                  d      }| j	                  |d      }| j	                  |d      }| j                  |       ||d||d	S )
a9  
        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#  )r8  r  networkaddresstag)r  r  privateGetFundingDestinationr  r$  findrv  check_address)	r  r  r  r  r  r  r9  r:  partss	            r  fetch_deposit_addresszbitso.fetch_deposit_addressg  s     	==&Xd^
 44T[[&5QR""8I#68LM<<1$MM&)E&&ua0G""5!,C7#
 	
r  codesc                 
   | j                          | j                  |      }i }| j                  |di       }| j                  |dg       }t        dt	        |            D ][  }||   }| j                  |d      }	| j                  |	      }
|| j                  |
|      s@| j                  |d      d|ddd||
<   ] | j                  |d	g       }t        |j                               }t        dt	        |            D ]  }||   }	| j                  |	      }
|| j                  |
|      s.| j                  ||
   d
      | j                  ||	      | j                  ||
   d   d
      | j                  ||	      dd||
<    |S )ay  
 @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   )rC  r   r8  withdrawal_feesrC  r8  )r  r  r  rt  ru  r$  rB  in_arrayrz  r  keys)r  r@  r  r  r}  r  depositFeesr~  
depositFeerJ  r  withdrawalFeescurrencyIdss                r  fetch_transaction_feeszbitso.fetch_transaction_fees  s    	&&v.X //(Ir:oog~rBq#k*+ 	A$QJ))*jAJ**:6D!4==u+E++J> ) $F4L	 2CRH>..01q#k*+ 	A$QJ**:6D!4==u+E??6$<C ,,^ZH#vd|F/CYO $ 0 0 LF4L	 r  c                     | j                          | j                  |      }| j                  |dg       }| j                  ||      S )a`  
        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_feesz!bitso.fetch_deposit_withdraw_fees  sH     	&&v.X ..9b9//??r  c                    i }| j                  |dg       }| j                  |dg       }t        dt        |            D ]b  }||   }| j                  |d      }	| j	                  |	      }
||
|v s2| j                  |d      | j                  |d       dd d di |d||
<   d t        |j                               }t        dt        |            D ]q  }||   }	| j	                  |	      }
||
|v s | j                  ||	         }| j                  ||
      }|| j                  i       ||
<   |||
   d	   d<   |||
   d
   |
<   s |S )NrB  rD  r   r  r   is_fixed)r   rT  )rC  r   r   r8  r   r8  )
r  rt  ru  r$  rB  rz  r  rF  rx  deposit_withdraw_fee)r  r  r@  currencyIdKeyr}  depositResponsewithdrawalResponser~  entryrJ  r  withdrawalKeyswithdrawFeeresultValues                 r  rM  z!bitso.parse_deposit_withdraw_fees  s   R //(NBG!__X7H"Mq#o./ 	A#A&E))%<J**:6D45=  $//u=*.//%*L&L 
  $&*! !#! t	" 05578q#n-. 		9A'*J**:6D45="//0B:0NO"oofd;&#'#<#<R#@F4L2=tZ(/-8tV$T*		9 r  r9  c                    | j                  ||      \  }}| j                  |       | j                          dddddd}| j                  |      }||v r||   nd}|t	        | j
                  dz   |z         |||d	}	d
|z   dz   }
 t        | |
      | j                  |	|            }| j                  |dg       }| j                  |d      }| j                  ||      S )a  
        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: )r,  r9  destination_tagprivatePost
Withdrawalr  r   )handle_withdraw_tag_and_paramsr=  r  r  r   r   getattrr  r  r,  r-  )r  r  r,  r9  r:  r  methodsr  methodr  classMethodr  r  r/  s                 r  r   zbitso.withdrawa  s     99#vFV7#
 ==&#'7?>*F F MNN"

 $f,|;-74-dkk'6.JK( //(Ir:w*%%eX66r  r  c                    | j                  |dd      }| j                  ||      }| j                  |di       }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |dd      }| j                  |d	      }	| j                  |d
      }
| j	                  |      }||j                         nd }i d| j                  |d
d      d| j                  |d      d| j                  |      d|d|d|d||n|d|d| j                  |d      d|
dndd| j                  ||      d	| j                  |	      dd dd dd dd dd d d |dS )Nr  assetr-  r5  withdrawal_addressreceiving_addressr8  ri  rA  r/  r   r.  txidtx_hashr=  r>  addressFromr9  	addressTor,  r%  rC  r"  updatedtagFromr:  tagTocomment)internalr   r8  )
rC  r  r  r$  network_id_to_coderw  rE  rz  rB  parse_transaction_status)r  r  r  rJ  r-  r>  withdrawalAddressreceivingAddress	networkIdrA  
withdrawIdnetworkCodenetworkCodeUppers                r  r-  z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<
 //
HE
 d33F;
 t
 t
 4
  T!
" t#
$ )
 	
r  c                 6    ddddd}| j                  |||      S )Npendingr7  failed)r  in_progresscompleter  r#  r  s      r  ry  zbitso.parse_transaction_status  s,     $	
 &&99r  c                 "    | j                         S N)r  )r  s    r  noncezbitso.nonce  s      ""r  r   GETc                    d| j                   z   dz   | j                  ||      z   }| j                  || j                  |            }|dk(  s|dk(  r|r|d| j	                  |      z   z  }| j
                  d   d   |z   }	|dk(  r| j                          t        | j                               }
d|z   }d	j                  |
||g      }|dk7  r|dk7  r|r| j                  |      }||z  }| j                  | j                  |      | j                  | j                        t        j                        }| j                   d
z   |
z   d
z   |z   }dd|z   i}|	|||dS )NrY  r  DELETE?r   r   r   z/api :AuthorizationzBitso )urlri  bodyheaders)r   implode_paramsomitextract_params	urlencoder  check_required_credentialsr  r  r  jsonhmacencodesecrethashlibsha256apiKey)r  pathr   ri  r  r  r  endpointqueryr  r  r  	signatureauths                 r  signz
bitso.sign  s[   %+d.A.A$.OO		&$"5"5d";<U?f0C$.."777iiv&1)++-

%E(Hggufh78G6X#599U+DtOG		$++g"6DKK8PRYR`R`aI;;$u,s2Y>DDG fdwOOr  httpCodereasonr  ri  r  r  c
                 n   |y d|v r| j                  |dd      }
t        |
t              r|
dk(  s|
dk(  rd}
nd}
|
sz| j                  dz   | j	                  |      z   }| j                  |d      }|t        |      | j                  |d      }| j                  | j                  ||       t        |      y )	NsuccessFtrue1T errorr  )
	safe_boolr  r  r   r  r  r   r$  throw_exactly_matched_exceptionr  )r  r  r  r  ri  r  r  r  requestHeadersrequestBodyr  feedbackr  r  s                 r  handle_errorszbitso.handle_errors  s      nnXy%@G'3'v%7c>"G#G77S=499X+>>':='11''v644T__dHU#H--r  r  )NN)A__name__
__module____qualname__r   r
  r   r	   r   r
   r  r'  dictr   rK  r   r  r   r  r  r  r   r  r   r  r  r  r  r  r   r  r  r   r  r  r   r   floatr   r  r  r   r  r  r  r  r!  r&  r)  r0  r   r4  r   r?  r   rK  rN  rM  r   r-  ry  r  r  r  r  __classcell__)r  s   @r  r"   r"      s\   R# Rh (,$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 26DW[df .K# .Kc .KQT .Kkoptku .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 : 04B    4;  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 DHPR 47S 47% 47# 47Wb 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  <module>r     s\    ( +  B  B  B  B  B  * 0 . ' * ) ) 4 %AHk Ar  