
    i
                       d dl mZ d dlmZ d dl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 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
CurrenciesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeesTransaction)List)ExchangeError)AuthenticationError)ArgumentsRequired)
BadRequest)InsufficientFunds)InvalidOrder)	TICK_SIZE)Precisec                   V    e Zd Z fdZi fdefdZi fdee         fdZdefdZ	d8dede
fdZi fd	ede
fd
Zdi fdedefdZdi fd	ededefdZd8d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d8dedefdZdddi fd	edededee         fdZd ZdefdZi fdefdZd Z d8d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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-dddi fd	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ddi fd	e(dedefd(Z0d) Z1d8d*e2de3fd+Z4dddi fd,e(dededee3         fd-Z5dddi fd,e(dededee3         fd.Z6di fd ed,e(fd/Z7di fd,ede%fd0Z8d8d*e2fd1Z9di fd2efd3Z:d4d5i ddfd6Z;d7 Z< xZ=S )9bitoproc                 "   |                      t          t          |                                           i ddddddg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d%dd&d'd(dd)dd*dd+dd,dd-dd.dd/dd0dd1di d2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBdddddddddddddCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTidUdVgdWdXdYdddZd[d\d]d]d]d]d]d]d]d]d]d^	id]d]d]d]d]d]d]d]d]d_	d`dadbdcdddeidfdededgdhdidjdkdd|                     dl          |                     dm          |                     dn          |                     dm          g|                     do          |                     dp          g|                     dq          |                     dr          g|                     ds          |                     dt          g|                     du          |                     dv          g|                     dw          |                     dx          g|                     dy          |                     dz          gg|                     dn          |                     dl          g|                     do          |                     d{          g|                     dq          |                     d|          g|                     ds          |                     d}          g|                     du          |                     d~          g|                     dw          |                     d          g|                     dy          |                     d          ggddidddddddddidt
          dt          t          t          t          t          dt          t          t          t          dddi           S )Nidr    nameBitoPro	countriesTWversionv3	rateLimitd   proThasCORSspotmarginFswapfutureoptioncancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateOrder	editOrderfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionModefetchPositionsfetchPremiumIndexOHLCVfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFee)fetchTradingFeesfetchTransactionFeesfetchTransactionsfetchTransferfetchTransfersfetchWithdrawalfetchWithdrawalssetLeveragesetMarginModetransferwithdraw
timeframes1m5m15m30m1h3h6h12h1d1w1M)rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   urlszdhttps://user-images.githubusercontent.com/1294454/158227251-3a92a220-9222-453c-9277-977c6677fe71.jpgrestzhttps://api.bitopro.com/v3zhttps://www.bitopro.comzRhttps://github.com/bitoex/bitopro-offical-api-docs/blob/master/v3-1/rest-1/rest.mdzhttps://www.bitopro.com/fees)logoapiwwwdocfeesrequiredCredentials)apiKeysecretr{   get   )	zorder-book/{pair}tickersztickers/{pair}ztrades/{pair}zprovisioning/currencieszprovisioning/trading-pairsz!provisioning/limitations-and-feesztrading-history/{pair}zprice/otc/{currency})	zaccounts/balancezorders/historyzorders/all/{pair}zorders/trades/{pair}zorders/{pair}/{orderId}z#wallet/withdraw/{currency}/{serial}z"wallet/withdraw/{currency}/id/{id}z wallet/depositHistory/{currency}z!wallet/withdrawHistory/{currency}g      ?g@
   )orders/{pair}zorders/batchzwallet/withdraw/{currency}orders   gUUUUUU?)zorders/{pair}/{id}z
orders/allr   )r   postputdelete)publicprivater~   tradingz0.001z0.00203000000z0.001945000000z0.001530000000z0.0014	300000000z0.0013	550000000z0.0012
1300000000z0.0011z0.00097z0.0007z0.0006z0.0005z0.0004z0.0003)takermaker)	tierBased
percentager   r   tiersoptionsnetworksERC20TRXBSC)r   ETHr   TRC20BEP20r   precisionMode
exceptions)zUnsupported currency.zUnsupported order typezInvalid bodyzInvalid SignaturezAddress not in whitelist.)zInvalid amountzBalance for zInvalid zWrong parameter)exactbroadcommonCurrencies)
deep_extendsuperr    describeparse_numberr   r   r   r   r   )self	__class__s    R/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/bitopro.pyr   zbitopro.describe   s   gt 4 4 = = ? ? DB
)DB
IDB
 $DB
 t	DB

 DB
 4DB
  ??? %? 	?
 %? %? "4? t? ? $U?  ? t? U? ? +E?  )%!?" $T#? ?$ '%?& ('?( "4)?* &u+?,  -?. +E/?0 *:1?2 +D3?4 &u5?6 #E7?8 *59?: $U;?< "5=?> *5??@ +EA?B "5C?D E? ? ?F !%G?H  I?J dK?L +EM?N "4O?P dQ?R !$S?T uU?V #EW?X $UY?Z !%[?\ )%]?^ t_?` a?b Uc?d te?f "5g? ?h %)(-%*!&"'#'$($!&! }? ? ?DB
N  ODB
h ~8 1h 7
 
iDB
~ "$ $DB
F -.#$*+)*3467=>2301
 
 -.*+-.0134?@>?<==>
 
 */(.68  !! /4&')* ) ( (GDB
X !%"&!..w77!..w77 "..s33T5F5Fw5O5OP!..y994;L;LY;W;WX!..y994;L;LX;V;VW!..z::D<M<Mh<W<WX!..{;;T=N=Nx=X=XY!..{;;T=N=Nx=X=XY!..|<<d>O>OPX>Y>YZ" "..s33T5F5Fw5O5OP!..y994;L;LY;W;WX!..y994;L;LX;V;VW!..z::D<M<Mh<W<WX!..{;;T=N=Nx=X=XY!..{;;T=N=Nx=X=XY!..|<<d>O>OPX>Y>YZ"  YDB
P $" ""  	QDB
d YeDB
f -7.8$.)<1;  '3$5 *'1	  gDB
D  !EDB
 D D D	    returnc                     |                      |          }|                     |dg           }i }t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                     |d          }	|                     |d          }
|                     |d          }|                     |d          }|                     |d          }||d	d
d
d	d}|||d
d
|	o|
|	|
|d
|d||<   |S )aE  
        fetches all available currencies on an exchange
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_currency_info.md
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        datar   currencydepositrk   withdrawFeeminWithdrawmaxWithdrawminmaxN)rk   amount)r"   codeinfotyper#   activer   rk   fee	precisionlimits)publicGetProvisioningCurrencies
safe_valuerangelensafe_stringsafe_currency_codesafe_number)r   paramsresponse
currenciesresultir   
currencyIdr   r   rk   r   withdrawMinwithdrawMaxr   s                  r   fetch_currencieszbitopro.fetch_currencies   sY    77??__Xvr::
" q#j//** 	 	A!!}H))(J??J**:66Dooh	::Gx<<H""8];;C**8]CCK**8]CCK '& 
   	 	F ! !.h"$!  F4LL r   c                     |                                  }|                     |dg           }|                     |          S )aJ  
        retrieves data on all markets for bitopro
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_trading_pair_info.md
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r   )!publicGetProvisioningTradingPairsr   parse_markets)r   r   r   marketss       r   fetch_marketszbitopro.fetch_markets  s@     99;;//(FB77* !!'***r   c                 *   |                      |d           }|                     |d          }|                                }|                     |d          }|                     |d          }|                     |          }|                     |          }|dz   |z   }	|                     |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                              |                     |                     |                     |d                              d|d |dS )Nmaintainpairbasequote/minLimitBaseAmountmaxLimitBaseAmountr   )r   pricecostleverager"   uppercaseIdsymbolbaseIdquoteIdsettlesettleIdr   r.   Tr/   Fr0   r1   r2   contractlinearquotePrecisionbasePrecision)r   r   )inversecontractSizeexpiryexpiryDatetimestrike
optionTyper   r   r   createdr   )r   r   upperr   r   r   parse_precision)r   marketr   r"   r   r   r   r   r   r   r   s              r   parse_marketzbitopro.parse_market:  s}   __VZ888ff--hhjj!!&&11""6733&&v..''00e# ''0DEE''0DEE 
  
  
  
 
$ 
" 
; 
 f 
 D	 

 U 
 d 
 u 
 d 
  
 F 
 D 
 e 
 E 
 e 
 e 
  ! 
" d# 
$  "**4+?+?@P@PQWYi@j@j+k+kll++D,@,@AQAQRXZiAjAj,k,kll  ? 
  
  
  	
r   Nr   c                    |                      |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          d |d|          S )Nr   r   	timestampdatetimehighhigh24hrlowlow24hrbid	bidVolumeask	askVolumevwapopenclose	lastPricelastpreviousClosechanger   priceChange24hraverage
volume24hr)
baseVolumequoteVolumer   )r   safe_marketsafe_ticker)r   tickerr   marketIdr   s        r   parse_tickerzbitopro.parse_tickerw  s    ##FF33!!(F33!!&(33 !
f!
!
 !
 D$$VZ88	!

 4##FI66!
 4!
 !
 4!
 !
 D!
 D!
 T%%fk::!
 D$$V[99!
 T!
 d!
  $**63DEE!!
" t#!
$ **6<@@)!
 !
 !
* +  	r   r   c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_ticker_data.md
        :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   )load_marketsr   publicGetTickersPairextendr   r  )r   r   r   r   requestr   r  s          r   fetch_tickerzbitopro.fetch_ticker  s     	V$$F4L
 ,,T[[&-I-IJJ6266   000r   symbolsc                     |                                   |                                 }|                     |dg           }|                     ||          S )a?  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_ticker_data.md
        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        r   )r  publicGetTickersr   parse_tickers)r   r  r   r   r   s        r   fetch_tickerszbitopro.fetch_tickers  sT     	((**//(FB77  !!'7333r   limitc           	      
   |                                   |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     ||d         ddddd	          S )
ad  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_orderbook_data.md
        :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"   Nr  r   bidsasksr   r   )r  r   publicGetOrderBookPairr  parse_order_book)r   r   r  r   r   r  r   s          r   fetch_order_bookzbitopro.fetch_order_book  s     	V$$F4L
 $GG..t{{7F/K/KLL* $$Xvh/?vvW^`hiiir   c                    |                      |d          }|                      |d          }d }||                     |d          }n|                     |d          }|                      |d          }|                     ||          }|                      |d          }|                      |d          }|                     |d          }	|                     |d          }
|
|                     |d	          }|rd
}
nd}
|                      |d          }||                      |d          }d }|                      |d          }|                     |                      |d                    }|||d d}|                     |d          }d }||rd}nd}|                     |||||                     |          |||	|
||d |d|          S )NtradeIdorderIdr   r   r   r   r   actionisBuyerbuysellr   
baseAmountr   	feeSymbol)r   r   rateisTakerr   r   )r"   r   orderr   r   r   takerOrMakerr   sider   r   r   r   )	r   safe_timestampsafe_integerr  safe_string_lowerr   r   
safe_tradeiso8601)r   trader   r"   r(  r   r  r   r   r   r3  r*  r   r   	feeAmountr.  r0  r2  s                     r   parse_tradezbitopro.parse_trade  s!   2 eY//""5)44	:++E;??II))%==I##E622!!(F33!!&(33  00%%eV44%%eX66<ooeY77G !!%22>%%e\::F$$UE22	++D,<,<UK,P,PQQ	 !% C
 //%33 '&&"Y//( 
  
   	r   sincec                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     ||||          S )aK  
        get the list of most recent trades for a particular symbol
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_trades_data.md
        :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   )r  r   publicGetTradesPairr  r   parse_trades	r   r   r<  r  r   r   r  r   tradess	            r   fetch_tradeszbitopro.fetch_tradesM  s     	V$$F4L
 ++DKK,H,HII6266   >>>r   c                    |                                   |                     |          }|                     |di           }|                     |d          }i }|                     |d          }|                     |d          }t	          dt          | j                            D ]}| j        |         }	||	||ddd||	<   |S )a  
        fetch the trading fees for multiple markets
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_limitations_and_fees.md
        :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
        tradingFeeRater   makerFeetakerFeeT)r   r   r   r   r   r   )r  'publicGetProvisioningLimitationsAndFeesr   r   r   r   r  )
r   r   r   rD  firstr   r   r   r   r   s
             r   fetch_trading_feeszbitopro.fetch_trading_feesl  s     	??GG3CRHH22|   
33  
33q#dl++,, 		 		A\!_F "! F6NN r   c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r  r   r   r  volume)r5  r   )r   ohlcvr   s      r   parse_ohlcvzbitopro.parse_ohlcv  s~    e[11UF++UF++UE**UG,,UH--
 	
r   rm   c                    |                                   |                     |          }|                     | j        ||          }|d         |d}|d}nt	          |d          }|                     |          }	d}
|)|                                 |d<   |d         ||	z  z
  |d<   nu|	dz  }t          t          j	        ||z                      |z  }
t          t          j	        |dz                      |d<   | 
                    |d         ||	z            |d<   |                     |                     ||                    }|                     |d	g           }|                     |||||          }|                     ||	|
|          S )
a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_ohlc_data.md
        :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   
resolutionNi  i$ tofrom  r   )r  r   r   rl   r   parse_timeframesecondsintmathfloorsumpublicGetTradingHistoryPairr  r   parse_ohlcvsinsert_missing_candles)r   r   	timeframer<  r  r   r   rO  r  timeframeInSecondsalignedSincetimeframeInMillisecondsr   r   sparses                  r   fetch_ohlcvzbitopro.fetch_ohlcv  s    	V$$%%doy)LL
4L$
 

 =EEu%%E!11)<<= LLNNGDM%dmu7I/IJGFOO&84&?#tz%2I*IJJKKNeeL!$*UT\":":;;GFO HHWV_e>P6PQQGDM33DKK4P4PQQx44 ""4E5II**63E|UZ[[[r   c                 t   t          |          }|dk    r|S g }|d         }d }|	|d         }n|}d}	t          |          }
d}||k     r|	|
k     r||	         }|d         |k    r,|                    |           |                     |	d          }	ni|                     g |          }||d<   |d         |d<   |d         |d<   |d         |d<   |                     d          |d<   |                    |           |                     ||dz            }t          |          }||dz
           }||k     r|	|
k     |S )	Nr   r            r   r   rR  )r   appendrX  array_concatr   )r   candlesdistancer<  r  lengthr   copyFromr   r   candleLengthresultLengthcandlecopys                 r   r[  zbitopro.insert_missing_candles  si    WQ;;N1:	= III7||e##!l*:*:QZFayI%%f%%%HHQNN((X66#Qq'Qq'Qq'Q++C00Qd###HtO<<Iv;;LlQ./H! e##!l*:*:" r   c                 F   d|i}t          dt          |                    D ]k}||         }|                     |d          }|                     |          }|                     |d          }|                     |d          }||d}	|	||<   l|                     |          S )Nr   r   r   r   	available)freetotal)r   r   r   r   safe_balance)
r   r   r   r   balancer   r   r   rq  accounts
             r   parse_balancezbitopro.parse_balance$  s     H
 q#h--(( 
	# 
	#AqkG))':>>J**:66D%%gx88F((+>>I! G #F4LL  (((r   c                     |                                   |                     |          }|                     |dg           }|                     |          S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_account_balance.md
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        r   )r  privateGetAccountsBalancer   rw  )r   r   r   balancess       r   fetch_balancezbitopro.fetch_balance>  sT     	11&99??8VR88 !!(+++r   c                 D    dddddddd}|                      ||d           S )Nr  closedcanceled)z-1r   12346r   )r   statusstatusess      r   parse_order_statuszbitopro.parse_order_statusW  s=    
 
 &$777r   c           	      ~   |                      |dd          }|                     |dd          }|                     |d          }|                                }|                      |dd          }|                     |d          }|                     |d	          }|                     ||d
          }|                     |d          }	|                     |d          }
|                     |
          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }d }|dk    rd}d }|                     |d          }|                     |                     |d                    }t          j	        |d          r||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#|          S )$Nr"   r(  r   createdTimestampr)  r   originalAmountr   r   _r   r  r   avgExecutionPriceexecutedAmountremainingAmounttimeInForce	POST_ONLYTr   r.  r   )r   r   clientOrderIdr   lastTradeTimestampupdatedTimestamppostOnlyr3  	stopPricetriggerPricer   r  filled)	remainingr  r   rA  r   )safe_string_2safe_integer_2r   lowerr  r  r6  r   r   	string_gt
safe_orderr8  r5  )r   r1  r   r"   r   r3  r   r   r  r   orderStatusr  r   r  r  r  r  r  r   r:  r.  s                        r   parse_orderzbitopro.parse_orderc  s   F tY77''{<NOO	x00zz||##E85EFF  00##E622!!(FC88!!&(33&&uh77((55%%eV44""5*=>>!!%)9::$$U,=>>	&&um<<+%%H$$UE22	++D,<,<UK,P,PQQ	Y,, 	%! C   
" 
T 
  
 Y//	 

 !$"3"3E;M"N"N 
 f 
 D 
 ; 
  
 D 
 U 
  
 D 
 f 
 D 
  w! 
" f# 
$ #- 
  
  
. /  	r   r   r3  r   r   c                 d   |                                   |                     |          }||d         ||                     ||          |                                 d}|                                }	|	dk    r|                     ||          |d<   |	dk    r|                     ||          |d<   |                     |dd          }
|                     |ddg          }|
t          | j	        d	z   |	z   d
z             |                     ||
          |d<   | 
                    |d          }|t          | j	        dz   |	z   d
z             ||d<   |                     |	dk    d|          }|rd|d<   |                     |                     ||                    }|                     ||          S )a  
        create a trade order
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/create_an_order.md
        :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   LIMITr   
STOP_LIMITr  r  Nz2 createOrder() requires a stopPrice parameter for z orders	conditionz2 createOrder() requires a condition parameter for MARKETr  r  )r  r   amount_to_precisionmillisecondsr   price_to_precisionsafe_value_2omitr   r"   r   is_post_onlyprivatePostOrdersPairr  r  )r   r   r   r3  r   r   r   r   r  	orderTyper  r  r  r   s                 r   create_orderzbitopro.create_order  s    	V$$4L..vv>>**,,
 
 JJLL	#66vuEEGG$$#66vuEEGG))&.+NNIYYv'DEEF "47-a#adm#mpy#yzzz'+'>'>vy'Q'Q$((==I "47-a#adm#mpy#yzzz'0$$$Y(%:D&II 	1%0GM"--dkk'6.J.JKK &111r   r"   c                    |t          | j        dz             |                                  |                     |          }||d         d}|                     |                     ||                    }|                     ||          S )a  
        cancels an open order
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/cancel_an_order.md
        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz) cancelOrder() requires a symbol argumentr"   )r"   r   )r   r"   r  r   privateDeleteOrdersPairIdr  r  r   r"   r   r   r   r  r   s          r   cancel_orderzbitopro.cancel_order  s     >#DG.Y$YZZZV$$4L
 
 11$++gv2N2NOO &111r   c                     |t          | j        dz             |                                  |                     |          }|d         }i }|||<   |                     |                     ||                    }|S )a  
        cancel multiple orders
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/cancel_batch_orders.md
        :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>`
        Nz* cancelOrders() requires a symbol argumentr   )r   r"   r  r   privatePutOrdersr  )r   idsr   r   r   r"   r  r   s           r   cancel_orderszbitopro.cancel_orders  s     >#DG.Z$Z[[[V$$M"((Wf)E)EFF r   c                 N   |                                   i }d}|J|                     |          }|d         |d<   |                     |                     ||                    }n)|                     |                     ||                    }|                     |di           }|S )a  
        cancel all open orders
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/cancel_all_orders.md
        :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr"   r   r   )r  r   privateDeleteOrdersPairr  privateDeleteOrdersAllr   )r   r   r   r  r   r   r   s          r   cancel_all_orderszbitopro.cancel_all_orders)  s     	
 [[((F$TlGFO33DKK4P4PQQHH224;;w3O3OPPH6266 r   c                    |t          | j        dz             |                                  |                     |          }||d         d}|                     |                     ||                    }|                     ||          S )a  
        fetches information on an order made by the user
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_an_order_data.md
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz( fetchOrder() requires a symbol argumentr"   )r(  r   )r   r"   r  r   privateGetOrdersPairOrderIdr  r  r  s          r   fetch_orderzbitopro.fetch_orderI  s     >#DG.X$XYYYV$$4L
 
 33DKK4P4PQQ0 &111r   c                 l   |t          | j        dz             |                                  |                     |          }d|d         i}|||d<   |||d<   |                     |                     ||                    }|                     |d          }|g }|                     ||||          S )a\  
        fetches information on multiple orders made by the user
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_orders_data.md
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz) fetchOrders() requires a symbol argumentr   r"   startTimestampr  r   )r   r"   r  r   privateGetOrdersAllPairr  r   parse_orders)	r   r   r<  r  r   r   r  r   r   s	            r   fetch_orderszbitopro.fetch_orderss  s     >#DG.Y$YZZZV$$F4L
 (-G$%$GG//GV0L0LMM622>F6   >>>r   c           	      b    ddi}|                      ||||                     ||                    S )N
statusKindOPENr  r  r   r   r<  r  r   r  s         r   fetch_open_orderszbitopro.fetch_open_orders  s8    &
   t{{7F7S7STTTr   c           	      b    ddi}|                      ||||                     ||                    S )ac  
        fetches information on multiple closed orders made by the user
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_orders_data.md
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  DONEr  r  s         r   fetch_closed_orderszbitopro.fetch_closed_orders  s:     &
   t{{7F7S7STTTr   c                 J   |t          | j        dz             |                                  |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     ||||          S )a%  
        fetch all trades made by the user
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_trades_data.md
        :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>`
        Nz+ fetchMyTrades() requires a symbol argumentr   r"   r   )r   r"   r  r   privateGetOrdersTradesPairr  r   r?  r@  s	            r   fetch_my_tradeszbitopro.fetch_my_trades  s     >#DG.[$[\\\V$$F4L
 224;;w3O3OPP6266(   >>>r   c           
      H    dddddddddd	}|                      |||          S )Nokfailedpending)	COMPLETEINVALID
PROCESSINGWAIT_PROCESSFAILEDEXPIRED	CANCELLEDEMAIL_VERIFICATIONWAIT_CONFIRMATIONr  )r   r  statess      r   parse_transaction_statusz bitopro.parse_transaction_status  sC    #%!"+!*

 

 777r   r   c                    |                      |d          }|                     ||          }|                     |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }	|	dk    r|}	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S )Ncoinr   addressmessager  protocolMAINr   r"   serialtxidr   r   networkr   rs  r   addressFrom	addressTotagtagFromtagToupdatedr   )r   r   r/  )commentinternalr   )r   r   r5  network_id_to_coder   r  r8  )
r   transactionr   r   r   r   r  r  r  	networkIds
             r   parse_transactionzbitopro.parse_transaction  s   Z %%k6::
&&z8<<%%k;??	"";	::{I66!!+x88$$[*==	I
K
$"";99
 D$$[&99
 D	

 
 t..y99
 d&&{G<<
 d33F;;
 
 Y//
 w
 4
 
 3
 t
  S!
" t#
$  ((e<< )
 
 
 	
r   r   c                 l   |t          | j        dz             |                                  |                     |          }d|d         i}|||d<   |||d<   |                     |                     ||                    }|                     |dg           }|                     ||||dd	i          S )
a@  
        fetch all deposits made to an account
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_deposit_invoices_data.md
        :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>`
        Nz+ fetchDeposits() requires the code argumentr   r"   r  r  r   r   r   )r   r"   r  safe_currency&privateGetWalletDepositHistoryCurrencyr  r   parse_transactions	r   r   r<  r  r   r   r  r   r   s	            r   fetch_depositszbitopro.fetch_depositsH  s     <#DG.[$[\\\%%d++
 (-G$%$GG>>t{{7TZ?[?[\\6266( &&vxPYGZ[[[r   c                 l   |t          | j        dz             |                                  |                     |          }d|d         i}|||d<   |||d<   |                     |                     ||                    }|                     |dg           }|                     ||||dd	i          S )
aL  
        fetch all withdrawals made from an account
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_withdraw_invoices_data.md
        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals 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>`
        Nz. fetchWithdrawals() requires the code argumentr   r"   r  r  r   r   
withdrawal)r   r"   r  r  'privateGetWalletWithdrawHistoryCurrencyr  r   r  r  s	            r   fetch_withdrawalszbitopro.fetch_withdrawalsw  s     <#DG.^$^___%%d++
 (-G$%$GG??GU[@\@\]]6266& &&vxP\G]^^^r   c                 H   |t          | j        dz             |                                  |                     |          }||d         d}|                     |                     ||                    }|                     |di           }|                     ||          S )a   
        fetch data on a currency withdrawal via the withdrawal id
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_an_withdraw_invoice_data.md
        :param str id: withdrawal id
        :param str code: unified currency code of the currency withdrawn, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nz- fetchWithdrawal() requires the code argumentr"   )r  r   r   )r   r"   r  r  &privateGetWalletWithdrawCurrencySerialr  r   r  )r   r"   r   r   r   r  r   r   s           r   fetch_withdrawalzbitopro.fetch_withdrawal  s     <#DG.]$]^^^%%d++ 
 
 >>t{{7TZ?[?[\\6266" %%fh777r   c                    |                      ||          \  }}|                                  |                     |           |                     |          }|d         |                     |          |d}d|v r|                     | j        di           }|                     |d          }	|                     |dg          }| 	                    ||	          }
|
t          | j        dz   |	z             |
|d<   |||d<   |                     |                     ||                    }|                     |d	i           }|                     ||          S )
a	  
        make a withdrawal
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/create_an_withdraw_invoice.md
        :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>`
        r"   )r   r   r  r  r   Nz invalid network r  r  r   )handle_withdraw_tag_and_paramsr  check_addressr   number_to_stringr   r   safe_string_upperr  r   r   r"   !privatePostWalletWithdrawCurrencyr  r  )r   r   r   r  r  r   r   r  r   requestedNetworkr  r   r   s                r   rk   zbitopro.withdraw  si    99#vFFV7###==&& ++F33
 

 t|ZDDH#55fiHHYYv	{33F((3CDDI #DG.A$ADT$TUUU"+GJ?!$GI99$++gv:V:VWW6266 %%fh777r   c                 D    ||                      |d          ddd d di dS )Nr   F)r   r   )r   rk   r   r   )r   )r   r   r   s      r   parse_deposit_withdraw_feez"bitopro.parse_deposit_withdraw_fee  sM     ''];;# 
 "  
 
 	
r   codesc                     |                                   |                     |          }|                     |dg           }|                     ||d          S )a  
        fetch deposit and withdraw fees
        :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_currency_info.md
        :param str[]|None codes: list of unified currency codes
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
        r   r   )r  r   	safe_listparse_deposit_withdraw_fees)r   r  r   r   r   s        r   fetch_deposit_withdraw_feesz#bitopro.fetch_deposit_withdraw_fees  sX     	77??" ~~h33//eZHHHr   r   GETc                     d|                      ||          z   }|                     ||                     |                    }|i }d|d<   |dk    rw|                                  |dk    s|dk    r|                     |          }|                     |          }	|                     |                     |	          |                     | j                  t          j
                  }
| j        |d<   |	|d<   |
|d	<   n|d
k    s|dk    r|r|d|                     |          z   z  }|                                 }d|i}|                     |          }|                     |          }	|                     |                     |	          |                     | j                  t          j
                  }
| j        |d<   |	|d<   |
|d	<   n)|dk    r#|d
k    r|r|d|                     |          z   z  }| j        d         d         |z   }||||dS )Nr   ccxtzX-BITOPRO-APIr   POSTPUTzX-BITOPRO-APIKEYzX-BITOPRO-PAYLOADzX-BITOPRO-SIGNATUREr  DELETE?noncer   r{   ry   )urlmethodbodyheaders)implode_paramsr  extract_paramscheck_required_credentialsjsonstring_to_base64hmacencoder   hashlibsha384r   	urlencoder  rx   )r   pathr{   r  r   r  r  r  querypayload	signaturer  rawDatar   s                 r   signzbitopro.sign.  s*   D''f555		&$"5"5d";";<<?G#) )++---6U??yy((//55 IIdkk'&:&:DKK<T<TV]Vdee	.2k*+/6+,1:-..5Fh$6$6 73!6!666C))++U yy))//55 IIdkk'&:&:DKK<T<TV]Vdee	.2k*+/6+,1:-.H__5 3sT^^E2222iv&,fdwOOOr   c
                    |d S |dk    r|dk     rd S | j         dz   |z   }
|                     |d          }|                     | j        d         ||
           |                     | j        d         ||
           t          |
          )N   i,   errorr   r   )r"   r   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r   r   reasonr  r  r  r  r   requestHeadersrequestBodyfeedbackr,  s               r   handle_errorszbitopro.handle_errorsP  s    43;;4#::47S=4'  733,,T_W-EuhWWW,,T_W-EuhWWWH%%%r   )N)>__name__
__module____qualname__r   r   r   r   r	   r   r   r   r  strr  r   r   r  r   r   r%  r   r;  rB  r   rI  listrM  ra  r[  r   rw  r{  r  r   r  r   r   floatr
   r  r   r  r  r  r  r  r  r  r  r  r   r   r  r  r  r  rk   r  r  r(  r3  __classcell__)r   s   @r   r    r       s       E E E E EN ') : :Z : : : :x $& + +$v, + + + +>;
f ;
 ;
 ;
 ;
z$ $6 $V $ $ $ $L 02 1 13 1f 1 1 1 1< 04B 4 4W 47 4 4 4 48 :>b %j %js %j3 %jY %j %j %j %jNM M M5 M M M M^ 6:UW ? ?3 ?s ?# ?\`af\g ? ? ? ?> )+ U U{ U U U Un
 
 
4 
 
 
 
 26DW[df 2\ 2\# 2\c 2\QT 2\koptku 2\ 2\ 2\ 2\h! ! !F) ) ) ) )4 $& , ,( , , , ,2
8 
8 
8U U U5 U U U Un gksu 32 323 32i 32y 32RW 32`c 32 32 32 32j 37r 2 2s 2C 2 2 2 2: 04B      : /32      @ 26b (2 (2c (23 (2 (2 (2 (2T *.Dt\^ 7? 7?3 7?c 7? 7?cghmcn 7? 7? 7? 7?r /3TXac U U U3 Uc U U U U 154VZce U U# US UPS Ujnotju U U U U -1tRV_a &? &?c &? &?C &? &? &? &?P8 8 8O
 O
x O
; O
 O
 O
 O
b *.Dt\^ -\ -\3 -\c -\ -\cghsct -\ -\ -\ -\^ -1tRV_a ,_ ,_c ,_ ,_C ,_fjkvfw ,_ ,_ ,_ ,_\ 59 #8 #83 #8c #8 #8 #8 #8J ?C2 -8 -8S -8% -8 -8 -8 -8^
 
 
 
 
 
0 <@ I I I I I I: &eBSW  P  P  P  PD	& 	& 	& 	& 	& 	& 	&r   r    )&ccxt.base.exchanger   ccxt.abstract.bitopror   r   rV  ccxt.base.typesr   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   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r     r   r   <module>rC     s   ( ' ' ' ' ' - - - - - -   u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u       * * * * * * 0 0 0 0 0 0 . . . . . . ' ' ' ' ' ' . . . . . . ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %C& C& C& C& C&h C& C& C& C& C&r   