
    iI                        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 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)BalancesCurrencyInt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 fdZdddi fdededefdZd Zd9d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d9d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d9ded
efdZd9d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fd"Z%di fdefd#Z&d$ Z'd9d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)Z-dddi fdededed
e
e.         fd*Z/i fdefd+Z0di fd,e
e         fd-Z1di fd,e2fd.Z3d:d/Z4di fdede!fd0Z5d1 Z6d9ded
e.fd2Z7d3 Z8d4 Z9d5d6i ddfd7Z:d8 Z; xZ<S );bitsoc                    |                      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
dMdidNdOdPidQdRdSdTdUt          dVdWdWdXdYdZd[d\d]d^d_d`dadbdcdd	deg dfig dgg dhg didjdkt
          t          t          dldm          S )nNr   BitsoMXi  v3CORSspotTmarginFswapfutureoption	addMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateDepositAddresscreateOrdercreateReduceOnlyOrderfetchAccountsfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderTradesfetchPositionfetchPositionModefetchPositionsfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransferfetchTransfersreduceMarginsetLeveragesetMarginModesetPositionModetransferwithdrawzdhttps://user-images.githubusercontent.com/51840849/87295554-11f98280-c50e-11ea-80d6-15b3bafa8cbf.jpgrestzhttps://api.bitso.comzhttps://bitso.comzhttps://bitso.com/api_infozhttps://bitso.com/feeszhttps://bitso.com/?ref=itej)logoapiwwwdocfeesreferralgư>g{Gz?)XRPMXNTUSDg:0yE>)	precisiondefaultPrecision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balancero   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)02011040304)idname	countries	rateLimitversionhasurlsprecisionModeoptions
timeframesrl   
exceptions)deep_extendsuperr   describer   r   r   r   )self	__class__s    P/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/bitso.pyr   zbitso.describe   s:   eT 2 2 ; ; = =FFF %F 	F
 %F %F UF "4F tF F $UF  F 'F tF (F   !F" #F F$ +E%F& )%'F( ')F* (+F, -F. &t/F0 (1F2  3F4 +E5F6 *:7F8 +D9F: &u;F< #E=F> *5?F@ $UAFB "5CFD *5EF F FF +EGFH tIFJ  KFL "5MFN OFP !%QFR  SFT dUFV +EWFX "4YFZ d[F\ !$]F^ #D_F`  aFb $UcFd !%eFf %egF F Fh )%iFj tkFl mFn UoFp tqFr "5sFt #DuFv &uwFx 'yFz $U{F|  }F~ !%F@ AFB uCFD  EFF "5GFH EIF FJ DKF FP 3 +309	 	 ' $  
 %/  
 
      ,    I) )4 4l ,#" Ae@
 e@
 e e e	    Ncodesincelimitc                     i }|||d<   |                      |                     ||                    }|                     |dg           }|                     |          }|                     ||||          S )a  
        fetch the history of changes, actions done by the user or operations that altered 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 entrys 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-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((Wf)E)EFF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_type   s4    $'	
 
 tT222r   r   c                 0   |                      |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)r   	directionaccountreferenceIdreferenceAccountr   r   r   	timestampdatetimebeforeafterstatusr   info)
r   r   r   safe_currency_codesafe_string_2r   
string_abs	parse8601safe_ledger_entryiso8601)r   itemr   r   r   balanceUpdatesfirstBalancer   r   r   
currencyIdr   r   r   r   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<<//$	266((%??**7E::K	!!II,&&II'!!II%I%f--D$ C NN4#3#3D,#G#GHH	%%""4//"& $"Y//'
 '
  !  	r   returnc                    |                      |          }|                     |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
        :see: 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_ro   	flat_ratetakermaker100	structureT)r   r   
percentage	tierBasedvolume)r   r   tiersrt   ru   r   symbol/basequotesettleNbaseIdquoteIdsettleIdr   r%   r&   Fr'   r(   r)   activecontractlinear	tick_size)r   price)minmaxminimum_amountmaximum_amountminimum_pricemaximum_priceminimum_valuemaximum_value)leverager   r  r   )inverser   r   contractSizeexpiryexpiryDatetimestrike
optionTypert   limitscreatedr   )publicGetAvailableBooksr   rangelenr   splitupperr   parse_numberr   
string_divsafe_numberappendr   r   )r   r   r   marketsresultimarketr   r  r  r	  r
  ro   flatRatetakerStringmakerStringr   r   feeTiersr   	takerFees	makerFeesjtierr  takerFeemakerFeer  defaultPricePrecisions                                r   fetch_marketszbitso.fetch_marketsU  s    //77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)r   r   r   r   r   	availablefreelockedusedtotal)r   r&  r'  r   r   r   safe_balance)
r   r   r   r?  r/  r0  r   r   r   r   s
             r   parse_balancezbitso.parse_balance  s   //(Ir::??7J;;
 

 q#h--(( 	# 	#AqkG))':>>J**:66DllnnG"..wDDGFO"..wAAGFO#//AAGG"F4LL  (((r   c                 ~    |                                   |                     |          }|                     |          S )ai  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: 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privateGetBalancerF  )r   r   r   s      r   fetch_balancezbitso.fetch_balance  s?     	))&114 !!(+++r   r  c           	      z   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d          }|                     |                     |d                    }|                     ||d         |dddd	          S )
a7  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: 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
        r   r   r   
updated_atr  bidsasksr  r   )rH  r1  publicGetOrderBookr   r   r   r   parse_order_book)	r   r  r   r   r1  r   r   	orderbookr   s	            r   fetch_order_bookzbitso.fetch_order_book  s     	V$$F4L
 **4;;w+G+GHHOOHi88	NN4#3#3I|#L#LMM	$$Yx0@)VU[]dfnooor   r1  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 )Nr   vwapr  lastr  r   r   highlowbid	bidVolumeask	askVolumeopenclosepreviousClosechanger  average)
baseVolumequoteVolumer   )safe_symbolr   r   r   
string_mulsafe_tickerr   )	r   r   r1  r  r   rT  ra  rb  rU  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                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d          }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: 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>`
        r   r   r   )rH  r1  publicGetTickerr   r   rf  )r   r  r   r1  r   r   r   s          r   fetch_tickerzbitso.fetch_tickerR  s     	V$$F4L
 ''GV(D(DEE955$   000r   r   c                 D   |                                   |                     |          }|d         |                     | j        ||          d}|<||d<   |4|                     |          }|                     |||z  dz            |d<   n<|:|                                 }	|	|d<   |	|                     |          dz  |z  z
  |d<   |                     |                     ||                    }
| 	                    |
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
        r   )r   time_bucketNstarti  endr   )rH  r1  r   r   parse_timeframesummillisecondspublicGetOhlcr   	safe_listparse_ohlcvs)r   r  	timeframer   r   r   r1  r   durationnowr   r   s               r   fetch_ohlcvzbitso.fetch_ohlcvt  s9    	V$$4L++DOY	RR
 
 $GG //	::!%%E1AD1H!I!I##%%C GEN"T%9%9)%D%Dt%Ke%SSGG%%dkk'6&B&BCC( ..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_rater  )safe_integerr,  )r   ohlcvr1  s      r   parse_ohlcvzbitso.parse_ohlcv  s      e%899UL11UJ//UJ//UK00UH--
 	
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 )Nr   r   r   side
maker_sider   r   buysellr   majorfees_amountfees_currencyr   minorr  oidr   )r   r   r   r   r  orderr   r  takerOrMakerr  r   r   r   )	r   r   rc  r   r   r   r   
safe_trader   )r   r   r1  r   marketIdr  r  	makerSider  r   r   feeCostfeeCurrencyIdfeeCurrencyr   r  orderIdr   s                     r   parse_tradezbitso.parse_trade  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                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d         |||          S )a  
        get the list of most recent trades for a particular symbol
        :see: 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>`
        r   r   r   )rH  r1  publicGetTradesr   parse_trades)r   r  r   r   r   r1  r   r   s           r   fetch_tradeszbitso.fetch_trades  sy     	V$$F4L
 ''GV(D(DEE  )!4feUKKKr   c                    |                                   |                     |          }|                     |di           }|                     |dg           }i }t          dt	          |                    D ]k}||         }|                     |d          }|                     |dd          }	||	|                     |d          |                     |d          d	d	d
||	<   l|S )aN  
        fetch the trading fees for multiple markets
        :see: 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   ro   r   r   Nr   maker_fee_decimaltaker_fee_decimalT)r   r  r   r   r  r  )rH  privateGetFeesr   r&  r'  r   rc  r,  )
r   r   r   r   ro   r/  r0  r   r  r  s
             r   fetch_trading_feeszbitso.fetch_trading_fees1  s     	&&v..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                    |                                   |                     |          }d|v }||st          | j        dz             |r+|                     |dt          |d                   i          }|d         |d}|                     |                     ||                    }|                     |d         |||          S )a  
        fetch all trades made by the user
        :see: 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>`
        markerNz 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   r   r   r   )rH  r1  r   r   r   intprivateGetUserTradesr  )	r   r  r   r   r   r1  markerInParamsr   r   s	            r   fetch_my_tradeszbitso.fetch_my_tradesv  s     	V$$ #f, ~  +\  !\  ]  ]  ] 	[[#fX.//*  F 4L
 
 ,,T[[&-I-IJJ  )!4feUKKKr   r   r  r   r  c                    |                                   |                     |          }|d         |||                     |d         |          d}|dk    r|                     |d         |          |d<   |                     |                     ||                    }	|                     |	d         d          }
|                     |	|
d|          S )	a  
        create a trade order
        :see: 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 fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   r  )r   r  r   r  r   r  r   r  )r   r   )rH  r1  amount_to_precisionprice_to_precisionprivatePostOrdersr   r   
safe_order)r   r  r   r  r   r  r   r1  r   r   r   s              r   create_orderzbitso.create_order  s     	V$$4L--fX.>GG	
 
 7??#66vh7GOOGG))$++gv*F*FGGhy1599 
  
   	r   r   c                     |                                   d|i}|                     |                     ||                    S )au  
        cancels an open order
        :see: 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  )rH  privateDeleteOrdersOidr   )r   r   r  r   r   s        r   cancel_orderzbitso.cancel_order  sF     	2
 **4;;w+G+GHHHr   c                    t          |t                    st          | j        dz             d}||                     |          }d                    |          }d|i}|                     |                     ||                    }|                     |dg           }g }	t          dt          |                    D ]3}
||
         }|	                    |                     ||                     4|	S )ay  
        cancel multiple orders
        :see: 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   r1  joinprivateDeleteOrdersr   r   r&  r'  r-  parse_order)r   idsr  r   r1  r  r   r   r   r   r0  r   s               r   cancel_orderszbitso.cancel_orders  s     #t$$ 	a#DG._$_```[[((Fxx}}D
 ++DKK,H,HII //(Ir::q#g,,'' 	8 	8ABMM$**2v667777r   c                 4   |t          | j        dz             |                     |          }|                     |dg           }g }t	          dt          |                    D ]2}|                     ||                   }|                    |           3|S )a  
        cancel all open orders
        :see: 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   r&  r'  r  r-  )r   r  r   r   r   canceledOrdersr0  r  s           r   cancel_all_orderszbitso.cancel_all_orders  s     tw  *D   D  E  E  E..v66 //(Ir::q#g,,'' 	) 	)A$$WQZ00E!!%((((r   c                 >    ddddd}|                      |||          S )Nr\  closed)zpartial-fillzpartially filledqueued	completedr   r   r   statusess      r   parse_order_statuszbitso.parse_order_status  s4    " &!	
 
 &&999r   c           	      0   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 d|          S )Nr  r  r   r   r   r   r   r  original_amountunfilled_amount	client_idr   r   clientOrderIdr   r   lastTradeTimestampr  timeInForcepostOnly	stopPricetriggerPricer   r   	remaining)filledr   r   r`  r   )r  strr   r  rc  r   r  r   )r   r  r1  r   r  r   r  r  	orderTyper   r  r   r  r  s                 r   r  zbitso.parse_order  s;    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! 
" # 
$ - 
  
  
. /  	r   c                    |                                   |                     |          }d|v }||st          | j        dz             |r+|                     |dt          |d                   i          }|d         |d}|                     |                     ||                    }|                     |d         |||          }	|	S )a  
        fetch all unfilled currently open orders
        :see: 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  Nz 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   )rH  r1  r   r   r   r  privateGetOpenOrdersparse_orders)
r   r  r   r   r   r1  r  r   r   r   s
             r   fetch_open_orderszbitso.fetch_open_orders3  s     	V$$ #f, ~  +^  !^  _  _  _ 	[[#fX.//*  F 4L
 
 ,,T[[&-I-IJJ""8I#6uMMr   c                 T   |                                   |                     d|i          }|                     |d          }t          |t                    r6t          |d                   }|dk    r|                     |d                   S t          | j        dz   |z   dz             )al  
        fetches information on an order made by the user
        :see: https://docs.bitso.com/bitso-api/docs/look-up-orders
        :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.)	rH  privateGetOrdersOidr   r  r  r'  r  r   r   )r   r   r  r   r   r   	numOrderss          r   fetch_orderzbitso.fetch_orderV  s     	++2-
   //(I66gt$$ 	4HY/00IA~~''
333DGn4r9MIJJJr   c                     |                                   |                     |          }d|i}|                     |                     ||                    }|                     |d         |          S )a  
        fetch all the trades made from a single order
        :see: 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   )rH  r1  privateGetOrderTradesOidr   r  )	r   r   r  r   r   r   r1  r   r   s	            r   fetch_order_tradeszbitso.fetch_order_tradesi  sq     	V$$2
 00Wf1M1MNN  )!4f===r   c                 
   |                                   d|i}|                     |                     ||                    }|                     |dg           }|                     |di           }|                     |          S )a  
        fetch information on a deposit
        :see: 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   )rH  privateGetFundingsFidr   r   	safe_dictparse_transaction)r   r   r   r   r   r   transactionsfirsts           r   fetch_depositzbitso.fetch_deposit|  s     	2
 --dkk'6.J.JKK0 xB??|Q33%%e,,,r   c                     |                                   d}||                     |          }|                     |          }|                     |dg           }|                     |||||          S )a  
        fetch all deposits made to an account
        :see: 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   )rH  r   privateGetFundingsrr  parse_transactions)r   r   r   r   r   r   r   r  s           r   fetch_depositszbitso.fetch_deposits  sx     	}}T**H**6220 ~~h	2>>&&|XueVTTTr   c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d         d          }d}|                    d          dk    rA|                    d          }|                     |d          }|                     |d          }|                     |           |||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  )r   addresstagnetworkr   )rH  r   privateGetFundingDestinationr   r   findr(  check_address)	r   r   r   r   r   r   r  r  partss	            r   fetch_deposit_addresszbitso.fetch_deposit_address  s     	==&&Xd^
 44T[[&5Q5QRR""8I#68LMM<<1$$MM&))E&&ua00G""5!,,C7###
 
 	
r   codesc                    |                                   |                     |          }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 )a  
         * @deprecated
        please use fetchDepositWithdrawFees instead
        :see: 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   )depositri   )r  ri   r   withdrawal_feesr  r   )rH  r  r   r&  r'  r   r   in_arrayr,  r  keys)r   r  r   r   r/  r   depositFeesr0  
depositFeer   r   withdrawalFeescurrencyIdss                r   fetch_transaction_feeszbitso.fetch_transaction_fees  s    	&&v..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                     |                                   |                     |          }|                     |dg           }|                     ||          S )ad  
        fetch deposit and withdraw fees
        :see: 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   )rH  r  rr  parse_deposit_withdraw_fees)r   r  r   r   r   s        r   fetch_deposit_withdraw_feesz!bitso.fetch_deposit_withdraw_feesB  sW     	&&v..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 )Nr  r  r   r   r   is_fixed)r   r  )r  ri   networksr   ri   r   )
r   r&  r'  r   r   r,  r  r  r*  deposit_withdraw_fee)r   r   r  currencyIdKeyr/  depositResponsewithdrawalResponser0  entryr   r   withdrawalKeyswithdrawFeeresultValues                 r   r  z!bitso.parse_deposit_withdraw_feesz  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   c                    |                      ||          \  }}|                     |           |                                  dddddd}|                     |          }||v r||         nd}|t	          | j        dz   |z             |||d	}	d
|z   dz   }
 t          | |
          |                     |	|                    }|                     |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>`
        BitcoinEtherRippleBcashLitecoin)BTCETHrq   BCHLTCNz not valid withdraw coin: )r   r  destination_tagprivatePost
Withdrawalr   r   )handle_withdraw_tag_and_paramsr  rH  r   r   r   getattrr   r   r  r  )r   r   r   r  r  r   methodsr   methodr   classMethodr   r   r  s                 r   ri   zbitso.withdraw  s3    99#vFFV7###
 
 ==&&#'7??>*F F MNNN"
 

 $f,|;-74--dkk'6.J.JKK( //(Ir::w**%%eX666r   c                 n    |d S |                                 }ddddd}|                     |||          S )NTRC20ERC20BEP20BEP2)trxerc20bscbep2)r)  r   )r   	networkIdnetworksByIds      r   safe_networkzbitso.safe_network  sN    4OO%%		
 
 iCCCr   c                 .   |                      |dd          }|                     ||          }|                     |di           }|                     |d          }|                     |d          }|                     |d          }|                      |dd          }|                     |d	          }	|                     |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   r   withdrawal_addressreceiving_addressr  r  r   r   r   r   txidtx_hashr   r   addressFromr  	addressTor   r   r  r   updatedtagFromr  tagTocomment)internalr   r   )	r   r   r   r   r   r+  r,  r   parse_transaction_status)r   r   r   r   r   r   withdrawalAddressreceivingAddressr)  r   
withdrawIds              r   r  zbitso.parse_transaction  s8   J ''ZII
%%j(;;//+y"==##K>> ,,W6JKK++G5HII&&{IxHH	!!+x88%%k599

$$$[%??
D$$Wi88
 11
 	

 t((33
 +
 ->-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pendingr   failed)r>  in_progresscompleter?  r   r  s      r   r9  zbitso.parse_transaction_statusK  s4     $	
 
 &&999r   c                 *    |                                  S N)rp  )r   s    r   noncezbitso.nonceT  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	                    |
||g          }|dk    r"|dk    r|r| 
                    |          }||z  }|                     |                     |          |                     | j                  t          j                  }| j        d	z   |
z   d	z   |z   }d
|z   dd}|	|||dS )Nr  rE  DELETE?rl   rj   r    :zBitso zapplication/json)AuthorizationzContent-Type)urlr  bodyheaders)r   implode_paramsomitextract_params	urlencoder   check_required_credentialsr  rD  r  jsonhmacencodesecrethashlibsha256apiKey)r   pathrl   r  r   rN  rM  endpointqueryrL  rD  r   	signatureauths                 r   signz
bitso.signW  s   %+d.A.A$.O.OO		&$"5"5d";";<<U??f00 8C$.."7"777iv&1)++---

%%Eggufh788G6X#5#5 $99U++DtOG		$++g"6"6DK8P8PRYR`aaI;$u,s2Y>D!)D 2 G fdwOOOr   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   rT  r   r   r   throw_exactly_matched_exceptionr   )r   httpCodereasonrL  r  rN  rM  r   requestHeadersrequestBodyrb  feedbackrf  r   s                 r   handle_errorszbitso.handle_errorsn  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   rC  )NN)=__name__
__module____qualname__r   r   r   r   r   r   r   r   r   r=  r   rF  rJ  r  r   rR  r   rf  ri  r  rw  r  r   r  r  r   r  r  r   r   floatr	   r  r  r  r  r  r
   r  r  r  r  r  r   r  r  r  r   r  r  ri   r+  r  r9  rD  r`  rn  __classcell__)r   s   @r   r   r      s       f f f f fP (,$TZ\ &B &B &BC &Bs &B &B &B &BP3 3 3b b b b b bH $& E E$v, E E E EN) ) ) ) )& $& ", ",( ", ", ", ",H :>b p ps p3 pY p p p p&* *6 *V * * * *X 02  1  13  1f  1  1  1  1D 26DW[df .K .K# .Kc .KQT .Kkoptku .K .K .K .K`
 
 
4 
 
 
 
0a a a5 a a a aF 6:UW L L3 Ls L# L\`af\g L L L L$ )+ C C{ C C C CJ -1tRT]_  L  Lc  L  LC  L  L  L  LD gksu  3 i y RW `c    : 37r I Is IC I I I I 04B      @ /32      0: : :, , ,5 , , , ,\ /3TV_a ! ! !3 !c !fjkpfq ! ! ! !F 26b K Kc K3 K K K K& 9=4^bkm > >S ># >S >X[ > > > >& 26b '- '- '-3 '- '- '- '-R *.Dt\^ 'U 'U3 'Uc 'U 'Ucghsct 'U 'U 'U 'UR 79 
 
# 
 
 
 
8 9=R V VDI V V V Vp <@ 6@ 6@ 6@ 6@ 6@ 6@pH H H HT ?C2 47 47S 47% 47 47 47 47l
D 
D 
DC
 C
x C
; C
 C
 C
 C
J: : :# # # &eBSW P P P P.      r   r   )$ccxt.base.exchanger   ccxt.abstract.bitsor   rX  ccxt.base.typesr   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   ( ' ' ' ' ' + + + + + +  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `  `       * * * * * * 0 0 0 0 0 0 . . . . . . ' ' ' ' ' ' * * * * * * ) ) ) ) ) ) ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %m m m m mHk m m m m mr   