
    ei[)                       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&dS )    )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                       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
dHd	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dHd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dee         f
dZdHdedefdZdHd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e         dedee(         fd'Z)di fdedee(         fd(Z*d)efd*Z+dHd+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d0Z0dddi fdedededee1         fd1Z2i fdede3fd2Z4di fd3e5fd4Z6di fd3e5fd5Z7dId6Z8di fded!e$d7ed8ede1f
d9Z9dHd:ed
ede1fd;Z:d)efd<Z;d= Z<d>d?i ddfd@Z=dAe>dBedCedDedEedFefdGZ? xZ@S )Jbitsoreturnc                 0   |                      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
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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,  )	sandboxr8   createOrdersrk   rs   rp   fetchOrdersfetchClosedOrdersrl   )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    V/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/bitso.pyr  zbitso.describe   su   eT 2 2 ; ; = =lll %l 	l
 %l %l Ul $Ul 'l l "4l tl l $Ul  l  '!l" t#l 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 l 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 l 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 l 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 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 lN #!&#(! Wl l l\ j3 9 +309  ' $  
 %/"$""	   
 
      ,    I) )4 4n  %&+(,,0,0).+06: $(#'"&#(	( ( #($)$)27+0/4#(+$ $. %)&+!$$(%)*.& & ',#($)*.	# # ',!$#($)*.( ( $()-#a3 3j ## 
 ## s= =~ ,#" [R@
 R@
 R R R	    Ncodesincer   c                    K   i }|||d<   |                      |                     ||                     d{V }|                     |dg           }|                     |          }|                     ||||          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-entry-structure>`
        Nr   payload)privateGetLedgerextend
safe_valuesafe_currencyparse_ledger)	r  r  r  r   paramsrequestresponser  currencys	            r  fetch_ledgerzbitso.fetch_ledger-  s       $GG..t{{7F/K/KLLLLLLLL0 //(Ir::%%d++  (E5AAAr  c                 >    ddddd}|                      |||          S )Ntransactiontradefee)funding
withdrawalr   r!  safe_string)r  typetypess      r  parse_ledger_entry_typezbitso.parse_ledger_entry_typeU  s4    $'	
 
 tT222r  itemr  c                 \   |                      |d          }|                     |          }|                     |dg           }|                     |di           }d }d }|                      |d          }	|                      |d          }
|                     |
|          }|                     |
|          }|                     |di           }|                     |dd          }||                      |d	          }|d
k    rd}n3|dk    rd}n*|dk    rd }n!|dk    rd}t          j        |	          }||d}|                     |                      |d                    }| 	                    ||                      |d          |d |d |||	|| 
                    |          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firstBalancer:  r!  r-  
currencyIdr  r.  r<  r5  r>  s                   r  parse_ledger_entryzbitso.parse_ledger_entry^  s   n $$T;77	++I66/@"EE~q"==	!!,99%%lJ??
&&z8<<%%j(;;//$	266((%??**7E::K	!!II,&&II'!!II%I%f--D$ C NN4#3#3D,#G#GHH	%%""4//"& $"Y//'
 '
  !  	r  c                   K   |                      |           d{V }|                     |dg           }g }t          dt          |                    D ]s}||         }|                     |d          }|                    d          \  }}	|                                }
|	                                }|                     |
          }
|                     |          }|                     |di           }|                     |di           }|                     |d          }|                     |d	          }|                     t          j
        |d
                    }|                     t          j
        |d
                    }|                     |dg           }||ddd}g }g }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d	          }|                    ||g           |                    ||g           |dk    r
||d<   ||d	<   ||d}||d<   |                     | j        d         || j        d                   }|                    |                     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        d         |
| j        d                   |                     |d&|          d'ddd(|                     |d)          |                     |d*          d(|                     |d+          |                     |d,          d(|                     |d-          |                     |d.          d(d/d|d0|                     u|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
        Nr  r   book_r   	flat_ratetakermaker100	structureT)rQ  rR  
percentage	tierBasedvolume)rQ  rR  tiersr   r   r   symbol/basequotesettle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-  rd  r5  )r   rQ  rR  contractSizeexpiryexpiryDatetimestrike
optionTyper   limitscreatedr9  )publicGetAvailableBooksr  rangelenr%  splitupperrC  parse_numberr    
string_divsafe_numberappendr  r  )r  r  r  marketsresultimarketr   r^  r_  r[  r\  r   flatRatetakerStringmakerStringrQ  rR  feeTiersr!  	takerFees	makerFeesjtierrW  takerFeemakerFeerX  defaultPricePrecisions                                r  fetch_marketszbitso.fetch_markets  s      55f========B //(Ir::q#g,,'' Z	 Z	AQZF!!&&11B hhsmmOFG<<>>DMMOOE**400D++E22E??66266Dt["==H**8W==K**8W==K%%g&8e&L&LMME%%g&8e&L&LMMEt["==H"!	 C II1c(mm,, 	, 	,{))$99++D'::++D'::  &(!3444  &(!344466#+CL#+CL"" E !CL$($4$4T\+5NPUW[WcdvWw$x$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\]oPpqq!--fkCXYY   $#! !
  $//8HII#//8HII 
  $//HH#//HH 
  $//HH#//HH  $  c2' 2' 2'd e2 2 2 2 2 2f r  c                    |                      |di           }|                      |dg           }|d d d}t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }	|                     |d          |	d<   |                     |d          |	d	<   |                     |d
          |	d
<   |	||<   |                     |          S )Nr  balances)r9  r>  r?  r   r  	availablefreelockedusedtotal)r  ru  rv  r%  rC  r;  safe_balance)
r  r  r  r  r~  r  r   rK  r  r;  s
             r  parse_balancezbitso.parse_balanceL  s   //(Ir::??7J;;
 

 q#h--(( 	# 	#AqkG))':>>J**:66DllnnG"..wDDGFO"..wAAGFO#//AAGG"F4LL  (((r  c                    K   |                                   d{V  |                     |           d{V }|                     |          S )ac  
        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>`
        N)load_marketsprivateGetBalancer  )r  r  r  s      r  fetch_balancezbitso.fetch_balance_  sg       !!!!!!!!!//777777774 !!(+++r  rY  c           	        K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |d          }|                     |                     |d                    }|                     ||d         |ddd	d
          S )a1  
        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
        NrN  r   r  
updated_atrY  bidsasksrd  r-  )r  r  publicGetOrderBookr  r  rF  r%  parse_order_book)	r  rY  r   r  r  r  r  	orderbookr>  s	            r  fetch_order_bookzbitso.fetch_order_book  s       !!!!!!!!!V$$F4L
 00Wf1M1MNNNNNNNNOOHi88	NN4#3#3I|#L#LMM	$$Yx0@)VU[]dfnooor  r   r  c                    |                      d |          }|                     |                     |d                    }|                     |d          }|                     |d          }t          j        ||          }|                     |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|          S )Nr6  vwaprW  lastrY  r>  r?  highlowbid	bidVolumeask	askVolumeopenclosepreviousClosechangerU  average)
baseVolumequoteVolumer9  )safe_symbolrF  r%  r    
string_mulsafe_tickerrH  )	r  r   r  rY  r>  r  r  r  r  s	            r  parse_tickerzbitso.parse_ticker  s    !!$//NN4#3#3FL#I#IJJ	//%%fh77
(T::// !
f!
!
 Y//!
 D$$VV44	!

 4##FE22!
 4##FE22!
 !
 4##FE22!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&)!
 !
 !
* +  	r  c                 .  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |d          }|                     ||          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>`
        NrN  r   r  )r  r  publicGetTickerr  r  r  )r  rY  r  r  r  r  r   s          r  fetch_tickerzbitso.fetch_ticker  s       !!!!!!!!!V$$F4L
 --dkk'6.J.JKKKKKKKK955$   000r  r   	timeframec                 `  K   |                                   d{V  |                     |          }|d         |                     | j        ||          d}|<||d<   |4|                     |          }|                     |||z  dz            |d<   n<|:|                                 }	|	|d<   |	|                     |          dz  |z  z
  |d<   |                     |                     ||                     d{V }
| 	                    |
dg           }| 
                    |||||          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
        Nr   )rN  time_bucketstarti  endr  )r  r  r%  r  parse_timeframesummillisecondspublicGetOhlcr  	safe_listparse_ohlcvs)r  rY  r  r  r   r  r  r  durationnowr  r  s               r  fetch_ohlcvzbitso.fetch_ohlcv  sa      !!!!!!!!!V$$4L++DOY	RR
 
 $GG //	::!%%E1AD1H!I!I##%%C GEN"T%9%9)%D%Dt%Ke%SSGG++DKK,H,HIIIIIIII( ..9b99  &)UEJJJr  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nbucket_start_time
first_ratemax_ratemin_rate	last_raterW  )safe_integerr{  )r  ohlcvr  s      r  parse_ohlcvzbitso.parse_ohlcv  s      e%899UL11UJ//UJ//UK00UH--
 	
r  r   c                 t   |                      |                     |d                    }|                     |d          }|                     ||d          }|                     |d          }|                     |d          }d }|||k    rd}nd}n|dk    rd	}nd}|                     |d
d          }	|	t	          j        |	          }	d }
|                     |d          }|0|                     |d          }|                     |          }||d}
|                     |d          }|t	          j        |          }|                     |d          }|                     |d          }|                     |d          }|                     ||||                     |          ||d ||||	||
d|          S )Nr6  rN  rO  side
maker_siderR  rQ  buysellr-  majorfees_amountfees_currencyr4  minorrd  oidr1  )r   r9  r>  r?  rY  orderr&  r  takerOrMakerrd  r-  r5  r!  )	rF  r%  r  rD  r    rE  rC  
safe_traderH  )r  r   r  r>  marketIdrY  r  	makerSider  r-  r!  feeCostfeeCurrencyIdfeeCurrencyr5  rd  orderIdr   s                     r  parse_tradezbitso.parse_trade2  s   b NN4#3#3E<#H#HII	##E622!!(FC88v..$$UL99	y  &&E!!##E8W=='//F""5-88 ,,UODDM11-@@K' C w//%d++D  00""5%00eU++"Y//( 
  
   	r  c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |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>`
        NrN  r   r  )r  r  publicGetTradesr  parse_trades)r  rY  r  r   r  r  r  r  s           r  fetch_tradeszbitso.fetch_trades  s       !!!!!!!!!V$$F4L
 --dkk'6.J.JKKKKKKKK  )!4feUKKKr  c                   K   |                                   d{V  |                     |           d{V }|                     |di           }|                     |dg           }i }t          dt	          |                    D ]k}||         }|                     |d          }|                     |dd          }	||	|                     |d          |                     |d          d	d	d
||	<   l|S )aH  
        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
        Nr  r   r   rN  rO  maker_fee_decimaltaker_fee_decimalT)r9  rY  rR  rQ  rU  rV  )r  privateGetFeesr  ru  rv  r%  r  r{  )
r  r  r  r  r   r~  r  r!  r  rY  s
             r  fetch_trading_feeszbitso.fetch_trading_fees  s$      !!!!!!!!!,,V44444444X //(Ir::w33q#d))$$ 	 	Aq'C''V44H%%hc::F ))#/BCC))#/BCC"! F6NN r     c                   K   |                                   d{V  |                     |          }d|v }||st          | j        dz             |r+|                     |dt          |d                   i          }|d         |d}|                     |                     ||                     d{V }|                     |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>`
        N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   rN  r   r  )r  r  r   r   r  intprivateGetUserTradesr  )	r  rY  r  r   r  r  markerInParamsr  r  s	            r  fetch_my_tradeszbitso.fetch_my_trades  s      !!!!!!!!!V$$ #f, ~  +\  !\  ]  ]  ] 	[[#fX.//*  F 4L
 
 224;;w3O3OPPPPPPPP  )!4feUKKKr  r&  r  r-  rd  c                   K   |                                   d{V  |                     |          }|d         |||                     |d         |          d}|dk    r|                     |d         |          |d<   |                     |                     ||                     d{V }	|                     |	d         d          }
|                     |	|
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>`
        Nr   rY  )rN  r  r&  r  r   rd  r  r  r9  r   )r  r  amount_to_precisionprice_to_precisionprivatePostOrdersr  r%  
safe_order)r  rY  r&  r  r-  rd  r  r  r  r  r   s              r  create_orderzbitso.create_order  s      !!!!!!!!!V$$4L--fX.>GG	
 
 7??#66vh7GOOGG//GV0L0LMMMMMMMMhy1599 
  
   	r  r   c                 *  K   |                                   d{V  d|i}|                     |                     ||                     d{V }|                     |dg           }|                     |d          }|                     ||d          S )ao  
        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>`
        Nr  r  r   r  )r  privateDeleteOrdersOidr  r  r%  r  )r  r   rY  r  r  r  r  r  s           r  cancel_orderzbitso.cancel_order3  s       !!!!!!!!!2
 44T[[&5Q5QRRRRRRRR ..9b99""7A.. 
  
   	r  idsc                   K   t          |t                    st          | j        dz             d}||                     |          }d                    |          }d|i}|                     |                     ||                     d{V }|                     |dg           }g }	t          dt          |                    D ]3}
||
         }|	                    |                     ||                     4|	S )as  
        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  ru  rv  r|  parse_order)r  r  rY  r  r  r  r  r  r  r   r  r   s               r  cancel_orderszbitso.cancel_ordersP  s      #t$$ 	a#DG._$_```[[((Fxx}}D
 11$++gv2N2NOOOOOOOO //(Ir::q#g,,'' 	8 	8ABMM$**2v667777r  c                 D  K   |t          | j        dz             |                     |           d{V }|                     |dg           }g }t	          dt          |                    D ]2}|                     ||                   }|                    |           3|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>`
        NzX cancelAllOrders() deletes all orders for user, it does not support filtering by symbol.r  r   )r   r   privateDeleteOrdersAllr  ru  rv  r  r|  )r  rY  r  r  r  canceledOrdersr  r  s           r  cancel_all_orderszbitso.cancel_all_ordersr  s       tw  *D   D  E  E  E44V<<<<<<<< //(Ir::q#g,,'' 	) 	)A$$WQZ00E!!%((((r  rB  c                 >    ddddd}|                      |||          S )Nr  closed)zpartial-fillzpartially filledqueued	completedr$  r  rB  statusess      r  parse_order_statuszbitso.parse_order_status  s4    " &!	
 
 &&999r  r  c                 .   d }t          |t                    r|}n|                     |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|          S )Nr  r  rB  rN  rO  r&  r6  rd  original_amountunfilled_amount	client_idr9  r   clientOrderIdr>  r?  lastTradeTimestamprY  r   postOnlyr   r-  r5  	remainingfilled)rB  r!  r  r   )r  strr%  r  r  rF  r  rH  )r  r  r  r   r  rB  r  rY  	orderTyper>  rd  r-  r  r  s                 r  r  zbitso.parse_order  s8    eS!! 	0BB!!%//Bv..(()9)9%)J)JKK##E622!!(FC88$$UF33	NN4#3#3E<#H#HII	  00!!%):;;$$U,=>>	((<<  
E 
" 
 ] 
 	 

 Y// 
 !$ 
 f 
 I 
 4 
  
 D 
 U 
 D 
 f 
 D 
  ! 
" d# 
$ + 
  
  
, -  	r  c                   K   |                                   d{V  |                     |          }d|v }||st          | j        dz             |r+|                     |dt          |d                   i          }|d         |d}|                     |                     ||                     d{V }|                     |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>`
        Nr  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  rY  r  r   r  r  r  r  r  r   s
             r  fetch_open_orderszbitso.fetch_open_orders  s      !!!!!!!!!V$$ #f, ~  +^  !^  _  _  _ 	[[#fX.//*  F 4L
 
 224;;w3O3OPPPPPPPP""8I#6uMMr  c                 p  K   |                                   d{V  |                     d|i           d{V }|                     |d          }t          |t                    r6t          |d                   }|dk    r|                     |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>`
        Nr  r     r   z: The order z not found.)	r  privateGetOrdersOidr  r  r  rv  r  r   r   )r  r   rY  r  r  r  	numOrderss          r  fetch_orderzbitso.fetch_order  s       !!!!!!!!!1123
         //(I66gt$$ 	4HY/00IA~~''
333DGn4r9MIJJJr  c                   K   |                                   d{V  |                     |          }d|i}|                     |                     ||                     d{V }|                     |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>`
        Nr  r  )r  r  privateGetOrderTradesOidr  r  )	r  r   rY  r  r   r  r  r  r  s	            r  fetch_order_tradeszbitso.fetch_order_trades  s       !!!!!!!!!V$$2
 66t{{7F7S7STTTTTTTT  )!4f===r  c                 &  K   |                                   d{V  d|i}|                     |                     ||                     d{V }|                     |dg           }|                     |di           }|                     |          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>`
        Nr/  r  r   )r  privateGetFundingsFidr  r  	safe_dictparse_transaction)r  r   r  r  r  r  transactionsfirsts           r  fetch_depositzbitso.fetch_deposit  s       !!!!!!!!!2
 33DKK4P4PQQQQQQQQ0 xB??|Q33%%e,,,r  c                   K   |                                   d{V  d}||                     |          }|                     |           d{V }|                     |dg           }|                     |||||          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=  s       !!!!!!!!!}}T**H00888888880 ~~h	2>>&&|XueVTTTr  c                    K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |d         d          }d}|                    d          dk    rA|                    d          }|                     |d          }|                     |d          }|                     |           ||d||d	S )
a7  
        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>`
        Nfund_currencyr   r  account_identifierz?dt=r   r$  )r9  r  networkaddresstag)r  r  privateGetFundingDestinationr  r%  findrw  check_address)	r  r  r  r  r  r  r:  r;  partss	            r  fetch_deposit_addresszbitso.fetch_deposit_addressh  s'      !!!!!!!!!==&&Xd^
 ::4;;wPV;W;WXXXXXXXX""8I#68LMM<<1$$MM&))E&&ua00G""5!,,C7###
 
 	
r  codesc                   K   |                                   d{V  |                     |           d{V }i }|                     |di           }|                     |dg           }t          dt	          |                    D ]n}||         }|                     |d          }	|                     |	          }
||                     |
|          sN|                     |d          d|ddd||
<   o|                     |d	g           }t          |
                                          }t          dt	          |                    D ]}||         }	|                     |	          }
||                     |
|          s8|                     ||
         d
          |                     ||	          |                     ||
         d         d
          |                     ||	          dd||
<   |S )aw  
 @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>`
        Nr  deposit_feesr   r  r!  )depositr   )rD  r   r9  withdrawal_feesrD  r9  )r  r  r  ru  rv  r%  rC  in_arrayr{  r  keys)r  rA  r  r  r~  r  depositFeesr  
depositFeerK  r  withdrawalFeescurrencyIdss                r  fetch_transaction_feeszbitso.fetch_transaction_fees  s+      !!!!!!!!!,,V44444444X //(Ir::oog~rBBq#k**++ 	 	A$QJ))*jAAJ**:66D!4==u+E+E!++J>> ) $  F4LL 2CRHH>..0011q#k**++ 	 	A$QJ**:66D!4==u+E+E!??6$<CC ,,^ZHH#vd|F/CYOO $ 0 0 L L  F4LL r  c                    K   |                                   d{V  |                     |           d{V }|                     |dg           }|                     ||          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>`
        Nr  )r  r  r  parse_deposit_withdraw_fees)r  rA  r  r  r  s        r  fetch_deposit_withdraw_feesz!bitso.fetch_deposit_withdraw_fees  s       !!!!!!!!!,,V44444444X ..9b99//???r  c                 ,   i }|                      |dg           }|                      |dg           }t          dt          |                    D ]t}||         }|                     |d          }	|                     |	          }
||
|v r9|                     |d          |                      |d           dd d di |d||
<   ut          |                                          }t          dt          |                    D ]}||         }	|                     |	          }
||
|v rm|                     ||	                   }|                      ||
          }|| 	                    i           ||
<   |||
         d	         d<   |||
         d
         |
<   |S )NrC  rE  r   r  r!  is_fixed)r!  rU  )rD  r   r   r9  r   r9  )
r  ru  rv  r%  rC  r{  r  rG  ry  deposit_withdraw_fee)r  r  rA  currencyIdKeyr~  depositResponsewithdrawalResponser  entryrK  r  withdrawalKeyswithdrawFeeresultValues                 r  rN  z!bitso.parse_deposit_withdraw_fees  s   R //(NBGG!__X7H"MMq#o..// 	 	A#A&E))%<<J**:66D45==  $//u==*.//%*L*L&L   
  $&*! ! !#!   t 0557788q#n--.. 		9 		9A'*J**:66D45=="//0B:0NOO"oofd;;&#'#<#<R#@#@F4L2=tZ(/-8tV$T*r  r:  r;  c                 ,  K   |                      ||          \  }}|                     |           |                                  d{V  dddddd}|                     |          }||v r||         nd}|t	          | j        dz   |z             |||d	}	d
|z   dz   }
 t          | |
          |                     |	|                     d{V }|                     |dg           }| 	                    |d          }| 
                    ||          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>`
        NBitcoinEtherRippleBcashLitecoin)BTCETHr   BCHLTCz not valid withdraw coin: )r-  r:  destination_tagprivatePost
Withdrawalr  r   )handle_withdraw_tag_and_paramsr>  r  r  r   r   getattrr  r  r-  r.  )r  r  r-  r:  r;  r  methodsr  methodr  classMethodr  r  r0  s                 r  r   zbitso.withdrawb  s[      99#vFFV7###!!!!!!!!!
 
 ==&&#'7??>*F F MNNN"
 

 $f,|;3{33DKK4P4PQQQQQQQQ( //(Ir::w**%%eX666r  r  c                 b   |                      |dd          }|                     ||          }|                     |di           }|                     |d          }|                     |d          }|                     |d          }|                      |dd          }|                     |d	          }	|                     |d
          }
|                     |          }||                                nd }i d|                      |d
d          d|                     |d          d|                     |          d|d|d|d||n|d|d|                     |d          d|
dndd|                     ||          d	| 	                    |	          dd dd dd dd dd d d |dS )Nr  assetr.  r6  withdrawal_addressreceiving_addressr9  rj  rB  r0  r   r/  txidtx_hashr>  r?  addressFromr:  	addressTor-  r&  rD  r#  updatedtagFromr;  tagTocomment)internalr!  r9  )
rD  r  r  r%  network_id_to_coderx  rF  r{  rC  parse_transaction_status)r  r  r  rK  r.  r?  withdrawalAddressreceivingAddress	networkIdrB  
withdrawIdnetworkCodenetworkCodeUppers                r  r.  zbitso.parse_transaction  s[   J ''ZII
%%j(;;//+y"==##K>> ,,W6JKK++G5HII&&{IxHH	!!+x88%%k599
--i883>3J;,,...QU
$$$[%??
D$$Wi88
 11
 	

 '
 +
 ->-J((Qa
 *
 d&&{H==
 *"4II<
 //
HEE
 d33F;;
 t
 t
 4
  T!
" t#
$ )
 
 
 	
r  c                 >    ddddd}|                      |||          S )Npendingr8  failed)r  in_progresscompleter  r$  r  s      r  rz  zbitso.parse_transaction_status  s4     $	
 
 &&999r  c                 *    |                                  S N)r  )r  s    r  noncezbitso.nonce  s      """r  r   GETc                    d| j         z   dz   |                     ||          z   }|                     ||                     |                    }|dk    s|dk    r|r|d|                     |          z   z  }| j        d         d         |z   }	|dk    r|                                  t          |                                           }
d|z   }d		                    |
||g          }|dk    r"|dk    r|r| 
                    |          }||z  }|                     |                     |          |                     | j                  t          j                  }| j        d
z   |
z   d
z   |z   }dd|z   i}|	|||dS )NrZ  r  DELETE?r   r   r   z/api :AuthorizationzBitso )urlrj  bodyheaders)r  implode_paramsomitextract_params	urlencoder  check_required_credentialsr  r  r  jsonhmacencodesecrethashlibsha256apiKey)r  pathr   rj  r  r  r  endpointqueryr  r  r  	signatureauths                 r  signz
bitso.sign  s   %+d.A.A$.O.OO		&$"5"5d";";<<U??f00 8C$.."7"777iv&1)++---

%%E(Hggufh788G6X#5#5 $99U++DtOG		$++g"6"6DK8P8PRYR`aaI;$u,s2Y>DDG fdwOOOr  httpCodereasonr  rj  r  r  c
                    |d S d|v r|                      |dd          }
t          |
t                    r|
dk    s|
dk    rd}
nd}
|
s| j        dz   |                     |          z   }|                     |d          }|t          |          |                     |d          }|                     | j	        ||           t          |          d S )	NsuccessFtrue1T errorr  )
	safe_boolr  r  r   r  r  r   r%  throw_exactly_matched_exceptionr  )r  r  r  r  rj  r  r  r  requestHeadersrequestBodyr  feedbackr  r  s                 r  handle_errorszbitso.handle_errors  s    4   nnXy%@@G'3'' $v%%7c>>"GG#G .7S=499X+>+>>'::='111''v6644T_dHUUU#H---tr  r  )NN)A__name__
__module____qualname__r   r  r   r	   r   r
   r  r(  dictr   rL  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*  r1  r   r5  r   r@  r   rL  rO  rN  r   r.  rz  r  r  r  r  __classcell__)r  s   @r  r"   r"      s       S# S S S S S Sj .2SW`b &B &Bs &B# &BS &Bgklwgx &B &B &B &BP3 3 3c ct cx c; c c c cJ *, G GV G G G GR) ) ) ) )& *, $, $, $, $, $, $,L @DB p pS p pS\ p p p p** *4 * *6 * * * *X 68 "1 "1 "1F "1 "1 "1 "1H ?CQUdhqs .K .K .K .K3 .K^a .Kx|  ~B  yC .K .K .K .K`
 
 
4 
 
 
 
0a a av a a a a aF <@d[] L L LS L Lbfglbm L L L L( /1 E E[ E E E EN 37TXZce "L "LC "Ls "LRU "L "L "L "LH mqy{   I Y X] fi    > 9=R  S #    : AER    tCy  #  TXY^T_        D 59  c U    4: : : : :+ + +v + + + + +Z 59tZ\eg # #c # #TW #lpqvlw # # # #J 8<B K KC K K K K K, ?CQUdhqs > >3 > >3 >^a > > > >* 8<B )- )-c )- )- )- )- )-V 04$UYbd )U )U )UC )Us )Uimnyiz )U )U )U )UV =? 
 
 
> 
 
 
 
8 =A X X' X X X Xt BFb 8@ 8@w 8@ 8@ 8@ 8@tH H H HT QU]_ 47 473 47 47 47# 47do 47 47 47 47lE
 E
T E
X E
Q\ E
 E
 E
 E
N:s : : : :# # # &eBSW P P P P0c 3 S # X\ dg        r  r"   )' ccxt.async_support.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   6 5 5 5 5 5 + + + + + +  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B       * * * * * * 0 0 0 0 0 0 . . . . . . ' ' ' ' ' ' * * * * * * ) ) ) ) ) ) ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %B B B B BHk B B B B Br  