
    !:h&                        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mZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lm Z  d dlm!Z! d dl"m#Z# d dl$m%Z%  G d dee      Z&y)    )Exchange)ImplicitAPIN)AnyBalances
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                       e Zd Zdef fdZi fdefdZi fdee   fdZ	de
defdZdDde
d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dDde
dedefdZddi fd
edededee   fdZi fdefdZdDd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e"fdZ#dDd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& Z,di fd
e"dee$   fd'Z-di f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e$   fd*Z0dddi fd
e"dedefd+Z1dddi fd
e"dededee$   fd,Z2dddi fd
e"dedefd-Z3de"fd.Z4dDd/e
d0e5de6fd1Z7dddi fd2e"dededee6   fd3Z8dddi fd2e"dededee6   fd4Z9di fd$ed2e"fd5Z:di fd2ed!e(d6ede6fd7Z;dDd0e5fd8Z<di fd9efd:Z=d;d<i ddfd=Z>d2e?d>ed?ed@edAe
dBefdCZ@ xZAS )Ebitoproreturnc                    | j                  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d/dd0di d1dd2dd3d4d5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBdi dCddDddEddFddGddHddIddJddKddLddMddNddOddPddQddRddSdi dTddUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcddddi deddfddgddhddiddjddkddlddmddnddoddpddqddrddsddtddudddddddvdwdxdydzd{d|d}d~dddddddddiddgdddddddddddddddddd	iddddddddddd
ddddddidddddddddd| j	                  d      | j	                  d      | j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      gg| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      ggddidddddddddgdddddd dddd dddddddddddddd dddddddddddÜdd ddddĜddddddddŜdddddddddǜddidɜ	d d dʜd d dʜd˜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	addMarginborrowCrossMarginborrowIsolatedMarginborrowMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateOrder$createOrderWithTakeProfitAndStopLoss&createOrderWithTakeProfitAndStopLossWscreateReduceOnlyOrdercreateStopOrdercreateTriggerOrder	editOrderfetchBalancefetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchIsolatedPositionsfetchLeveragefetchLeveragesfetchLeverageTiersfetchLiquidationsfetchLongShortRatiofetchLongShortRatioHistoryfetchMarginAdjustmentHistoryfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricesfetchMyLiquidationsfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeesfetchTransactionsfetchTransferfetchTransfersfetchVolatilityHistoryfetchWithdrawalfetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeverage)	setMarginsetMarginModesetPositionModetransferwithdraw
timeframes1m5m15m30m1h3h6h12h1d1w1M)r   r   r   r   r   r   r   r   r   r   r   urlszOhttps://github.com/user-attachments/assets/affc6337-b95a-44bf-aacd-04f9722364f6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}zorders/openg      ?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ERC20TRXBSC)r   ETHr   TRC20BEP20r   TWD)networksfiatCurrenciesfeatures)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyRequiresPricemarketBuyByCostselfTradePreventioniceberg  i )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   )r   r   r   r   r   r   r   i'  )r   r   r   daysBackCanceledr   r   r   r   r   )	sandboxr>   createOrdersrp   rx   ru   rz   rL   rq   )linearinverse)r0   r2   r3   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    F/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/bitopro.pyr   zbitopro.describe   s
   gt = ? BB
)BB
IBB
 $BB
 t	BB

 BB
 4BB
  lll %l 	l
 %l %l Ul $Ul 'l l "4l tl l $Ul  l  t!l" 7#l$ 9%%l& ('l( "4)l* %d+l, U-l. /l0 &u1l2 "53l4 +E5l6 )%7l8 #E9l: ,U;l< $T=l> '?l@ (AlB "4ClD &uElF  GlH +EIlJ *:KlL +DMlN &uOlP 'QlR (SlT #EUlV *5WlX $UYlZ u[l\ "5]l^ *5_l` +Ealb )%cld  elf !%glh %eilj $Ukll &umln -eolp /qlr "5slt #Eulv +Ewlx ylz !%{l| "5}l~ &ul@ +EAlB  ClD dElF $UGlH +EIlJ %eKlL "4MlN uOlP #EQlR dSlT !$UlV uWlX #EYlZ  [l\ ']l^ $U_l` !%alb *5cld (elf %eglh )%ilj )%kll tmln olp Uqlr tslt "5ulv #Dwlx 'ylz $U{l|  }l~ !%l@ )%AlB "4ClD #DElF GlH #EIlJ &uKlL uMlN #!&#(! WlBB
h iBB
B i8 1h 7
CBB
X "$YBB
` -.#$*+)*3467=>2301
 -.*+-.0134?@>?<==>'( */(.68 !! /4&')*+)aBB
t !%"&!..w7!..w7 "..s3T5F5Fw5OP!..y94;L;LY;WX!..y94;L;LX;VW!..z:D<M<Mh<WX!..{;T=N=Nx=XY!..{;T=N=Nx=XY!..|<d>O>OPX>YZ" "..s3T5F5Fw5OP!..y94;L;LY;WX!..y94;L;LX;VW!..z:D<M<Mh<WX!..{;T=N=Nx=XY!..{;T=N=Nx=XY!..|<d>O>OPX>YZ"uBB
l $" ""  $)'
mBB
B $&+(,,0,0).+06:#(#("&#(	( #($)$)27+0/4#()$, %)&+!%$*%+*.& ',#($)*.	# ',!%#($)*/( ',!%$*%+#($)*.$ ',!%$*,-%*#($)*.	*  #CDL ##
 ##UNCBB
`	 Ya	BB
b	 -7.8$.)<1; '3$5 *'1	c	BB
@
  !A
BB
 B B	    c                 2   | j                  |      }| j                  |dg       }i }| j                  | j                  dg       }t        dt	        |            D ]  }||   }| j                  |d      }| j                  |      }	| j                  |d      }
| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d	      }||d
ddd
d}| j                  |	|      }||	||rdndd|
xr ||
||d|dd||	<    |S )aA  
        fetches all available currencies on an exchange

        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   r   currencydepositr   withdrawFeeminWithdrawmaxWithdrawminmaxN)r   amountfiatcrypto)r$   codeinfotyper%   activer  r   fee	precisionlimitsr   )
publicGetProvisioningCurrencies	safe_listr   rangelensafe_stringsafe_currency_code	safe_boolsafe_numberin_array)r   paramsresponse
currenciesresultr   ir  
currencyIdr  r  r   r  withdrawMinwithdrawMaxr  isFiats                    r   fetch_currencieszbitopro.fetch_currencies]  sR    77?^^Hfb9
" 6FKq#j/* !	A!!}H))(J?J**:6DnnXy9G~~h
;H""8];C**8]CK**8]CK '&
  	F ]]48F  "(h!.h"$!  F4L)!	D r   c                 j    | j                         }| j                  |dg       }| j                  |      S )aF  
        retrieves data on all markets for bitopro

        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  s7     99;..626* !!'**r   marketc                    | j                  |d       }| j                  |d      }|j                         }| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }|dz   |z   }	| j	                  |d      | j	                  |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 |
| j                  | j                  | j                  |d                  | j                  | j                  | j                  |d                  d|d |dS )Nmaintainpairbasequote/minLimitBaseAmountmaxLimitBaseAmountr  )r
  pricecostr   r$   uppercaseIdsymbolbaseIdquoteIdsettlesettleIdr  r0   Tr1   Fr2   r3   r4   contractr   quotePrecisionbasePrecision)r5  r
  )r   contractSizeexpiryexpiryDatetimestrike
optionTyper  r  r  createdr  )r  r  upperr  r  r   parse_precision)r   r,  r  r$   r7  r9  r:  r0  r1  r8  r  s              r   parse_marketzbitopro.parse_market  s)   ^^FJ77ff-hhj!!&&1""673&&v.''0e# ''0DE''0DE
 
 
 
$ 
" 
; 
 f 
 D	 

 U 
 d 
 u 
 d 
  
 F 
 D 
 e 
 E 
 e 
 e 
  ! 
" d# 
$  "**4+?+?@P@PQWYi@j+kl++D,@,@AQAQRXZiAj,kl ? 
  	
r   Ntickerc                    | j                  |d      }| j                  ||      }| j                  |d      }| j                  i d|dd dd d| j                  |d      d| j                  |d      d	d d
d dd dd dd dd d| j                  |d      d| j                  |d      dd dd d| j                  |d      dd | j                  |d      d |d|      S )Nr/  r8  	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   rI  r,  marketIdr8  s        r   parse_tickerzbitopro.parse_ticker  s~    ##FF3!!(F3!!&(3 !
f!
!
 !
 D$$VZ8	!

 4##FI6!
 4!
 !
 4!
 !
 D!
 D!
 T%%fk:!
 D$$V[9!
 T!
 d!
  $**63DE!!
" t#!
$ **6<@)!
* + 	r   r8  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  ||      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        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extend	safe_dictrd  )r   r8  r  r,  requestr  rI  s          r   fetch_tickerzbitopro.fetch_ticker"  sr     	V$F4L
 ,,T[[&-IJ&"5   00r   symbolsc                     | j                          | j                         }| j                  |dg       }| j                  ||      S )a;  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        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  )rf  publicGetTickersr  parse_tickers)r   rl  r  r  r   s        r   fetch_tickerszbitopro.fetch_tickersB  sE     	((*..626  !!'733r   r   c           	          | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  ||d   ddddd	      S )
a`  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        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   r8  bidsasksr5  r
  )rf  r,  publicGetOrderBookPairrh  parse_order_book)r   r8  r   r  r,  rj  r  s          r   fetch_order_bookzbitopro.fetch_order_book`  s     	V$F4L
 $GG..t{{7F/KL* $$Xvh/?vvW^`hiir   tradec                    | j                  |d      }| j                  |d      }d }|| j                  |d      }n| j                  |d      }| j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j	                  |d      }	| j	                  |d      }
|
| j                  |d	      }|rd
}
nd}
| j                  |d      }|| j                  |d      }d }| j                  |d      }| j                  | j                  |d            }|||d d}| j                  |d      }d }||rd}nd}| j                  ||||| j                  |      |||	|
||d |d|      S )NtradeIdorderIdrK  r/  r8  r5  r  actionisBuyerbuysellr
  
baseAmountr  	feeSymbol)r6  r  rateisTakerr   r   )r$   r  orderrK  rL  r8  takerOrMakerr  sider5  r
  r6  r  )	r  safe_timestampsafe_integerra  safe_string_lowerr  r  
safe_tradeiso8601)r   rw  r,  r$   rz  rK  rc  r8  r5  r  r  r|  r
  r  	feeAmountr  r  r  s                     r   parse_tradezbitopro.parse_trade  s   2 eY/""5)4	:++E;?I))%=I##E62!!(F3!!&(3  0%%eV4%%eX6<nnUI6G!!%2>%%e\:F$$UE2	++D,<,<UK,PQ	 !%C
 ..	2&&"Y/( 
  	r   sincec                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )aG  
        get the list of most recent trades for a particular symbol

        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  )rf  r,  publicGetTradesPairrh  r  parse_trades	r   r8  r  r   r  r,  rj  r  tradess	            r   fetch_tradeszbitopro.fetch_trades  sv     	V$F4L
 ++DKK,HI&"5   >>r   c                 \   | j                          | j                  |      }| j                  |di       }| j                  |d      }i }| j	                  |d      }| j	                  |d      }t        dt        | j                              D ]  }| j                  |   }	||	||ddd||	<    |S )a  
        fetch the trading fees for multiple markets

        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  r8  r   r   r   r   )rf  'publicGetProvisioningLimitationsAndFeesri  
safe_valuer  r  r  rl  )
r   r  r  r  firstr   r   r   r!  r8  s
             r   fetch_trading_feeszbitopro.fetch_trading_fees  s     	??G2BBG2|   
3  
3q#dll+, 		A\\!_F "!F6N		 r   c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )NrK  rV  rM  rO  rW  volume)r  r  )r   ohlcvr,  s      r   parse_ohlcvzbitopro.parse_ohlcvR  sl    e[1UF+UF+UE*UG,UH-
 	
r   r   c                    | j                          | j                  |      }| j                  | j                  ||      }|d   |d}|d}nt	        |d      }| j                  |      }	d}
|"| j                         |d<   |d   ||	z  z
  |d<   nh|	dz  }t        t        j                  ||z              |z  }
t        t        j                  |dz              |d<   | j                  |d   ||	z        |d<   | j                  | j                  ||            }| j                  |d	g       }| j                  |||||      }| j                  ||	|
|      S )
a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        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fromr   r  )rf  r,  r  r   r  parse_timeframesecondsintmathfloorsumpublicGetTradingHistoryPairrh  r  parse_ohlcvsinsert_missing_candles)r   r8  	timeframer  r   r  r,  r  rj  timeframeInSecondsalignedSincetimeframeInMillisecondsr  r  sparses                  r   fetch_ohlcvzbitopro.fetch_ohlcv\  sd    	V$%%dooy)L
4L$

 =Eu%E!11)<= LLNGDM%dmu7I/IJGFO&84&?#tzz%2I*IJKNeeL!$**UT\":;GFO HHWV_e>P6PQGDM33DKK4PQ~~h3 ""4E5I**63E|UZ[[r   c                    t        |      }|dk(  r|S g }|d   }d }||d   }n|}d}	t        |      }
d}||k  r|	|
k  r||	   }|d   |k(  r$|j                  |       | j                  |	d      }	nT| j                  g |      }||d<   |d   |d<   |d   |d<   |d   |d<   | j	                  d      |d<   |j                  |       | j                  ||dz        }t        |      }||dz
     }||k  r|	|
k  r|S )	Nr   r            r   r   r   )r  appendr  array_concatr   )r   candlesdistancer  r   lengthr   copyFromrK  r!  candleLengthresultLengthcandlecopys                 r   r  zbitopro.insert_missing_candles  s7    WQ;N1:	= II7|e#!l*:QZFayI%f%HHQN((X6#Qq'Qq'Qq'Q++C0Qd#HtO<Iv;LlQ./H! e#!l*:" r   c                    d|i}t        dt        |            D ]X  }||   }| j                  |d      }| j                  |      }| j                  |d      }| j                  |d      }||d}	|	||<   Z | j	                  |      S )Nr  r   r  r
  	available)freetotal)r  r  r  r  safe_balance)
r   r  r   r!  balancer"  r  r
  r  accounts
             r   parse_balancezbitopro.parse_balance  s     H
 q#h-( 
	#AqkG))':>J**:6D%%gx8F((+>I!G #F4L
	#   ((r   c                     | j                          | j                  |      }| j                  |dg       }| j                  |      S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        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  )rf  privateGetAccountsBalancer  r  )r   r  r  balancess       r   fetch_balancezbitopro.fetch_balance  sE     	11&9>>(FB7 !!(++r   statusc                 <    dddddddd}| j                  ||d       S )NrV  closedcanceled)z-1r   12346r  )r   r  statusess      r   parse_order_statuszbitopro.parse_order_status  s5    
 &$77r   r  c                    | j                  |dd      }| j                  |dd      }| j                  |d      }|j                         }| j                  |dd      }| j                  |d      }| j                  |d	      }| j	                  ||d
      }| j                  |d      }	| j                  |d      }
| j                  |
      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }d }|dk(  rd}d }| j                  |d      }| j                  | j                  |d            }t        j                  |d      r||d}| j                  i 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#|      S )$Nr$   rz  rK  createdTimestampr{  r
  originalAmountr5  r/  _r8  r  r  avgExecutionPriceexecutedAmountremainingAmountr   	POST_ONLYTr  r  r   )r  r6  clientOrderIdrL  lastTradeTimestampupdatedTimestamppostOnlyr  r   r6  r]  filled	remaining)r  r  r  r  )safe_string_2safe_integer_2r  lowerra  r  r  r  r   	string_gt
safe_orderr  r  )r   r  r,  r$   rK  r  r
  r5  rc  r8  orderStatusr  r  r]  r  r  r   r  r  r  r  s                        r   parse_orderzbitopro.parse_order  s   F tY7''{<NO	x0zz|##E85EF  0##E62!!(FC8!!&(3&&uh7((5%%eV4""5*=>!!%)9:$$U,=>	&&um<+%H$$UE2	++D,<,<UK,PQ	Y,%!C   
" 
T 
  
 Y/	 

 !$"3"3E;M"N 
 f 
 D 
 ; 
  
 D 
 U 
 D 
 f 
 D 
 w 
  f! 
" # 
$ + 
, - 	r   r  r  r
  r5  c                    | j                          | j                  |      }||d   || j                  ||      | j                         d}|j	                         }	|	dk(  r| j                  ||      |d<   |	dk(  r| j                  ||      |d<   | j                  |dd      }
| j                  |ddg      }|
t        | j                  d	z   |	z   d
z         | j                  ||
      |d<   | j                  |d      }|t        | j                  dz   |	z   d
z         ||d<   | j                  |	dk(  d|      }|rd|d<   | j                  | j                  ||            }| j                  ||      S )a(  
        create a trade order

        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 fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param dict [params.triggerPrice]: the price at which a trigger order is triggered at
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r$   )r  r/  r{  r
  rK  LIMITr5  
STOP_LIMITr   	stopPriceNz5 createOrder() requires a triggerPrice parameter for z orders	conditionz2 createOrder() requires a condition parameter for MARKETr  r   )rf  r,  amount_to_precisionmillisecondsrF  price_to_precisionsafe_value_2omitr   r$   r  is_post_onlyprivatePostOrdersPairrh  r  )r   r8  r  r  r
  r5  r  r,  rj  	orderTyper   r  r  r  s                 r   create_orderzbitopro.create_orderL  s    	V$4L..vv>**,
 JJL	#66vuEGG$#66vuEGG,,V^[QLYYv'DEF#"477-d#dgp#ps|#|}}'+'>'>v|'T$((=I "477-a#adm#mpy#yzz'0$$$Y(%:D&I%0GM"--dkk'6.JK &11r   r$   c                     |t        | j                  dz         | j                          | j                  |      }||d   d}| j	                  | j                  ||            }| j                  ||      S )a  
        cancels an open order

        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>`
        z) cancelOrder() requires a symbol argumentr$   )r$   r/  )r   r$   rf  r,  privateDeleteOrdersPairIdrh  r  r   r$   r8  r  r,  rj  r  s          r   cancel_orderzbitopro.cancel_order  s{     >#DGG.Y$YZZV$4L
 11$++gv2NO &11r   c                 *   t        |j                               }g }t        dt        |            D ]_  }||   }||   }t        dt        |            D ];  }|j	                  | j                  ||   ||   | j                  |      d             = a |S )Nr   )r  r$   r8  )listkeysr  r  r  r  safe_symbol)r   r  dataKeysr   r!  rc  orderIdsjs           r   parse_cancel_orderszbitopro.parse_cancel_orders  s    		$q#h-( 	A{HH~H1c(m, doo$QK"1+"..x8/  	 r   c                    |t        | j                  dz         | j                          | j                  |      }|d   }i }|||<   | j	                  | j                  ||            }| j                  |d      }| j                  |      S )a  
        cancel multiple orders

        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>`
        z* cancelOrders() requires a symbol argumentr7  r  )r   r$   rf  r,  privatePutOrdersrh  ri  r  )	r   idsr8  r  r,  r$   rj  r  r  s	            r   cancel_orderszbitopro.cancel_orders  s     >#DGG.Z$Z[[V$M"((Wf)EF ~~h/''--r   c                 .   | j                          i }d}|;| j                  |      }|d   |d<   | j                  | j                  ||            }n!| j	                  | j                  ||            }| j                  |di       }| j                  |      S )a  
        cancel all open orders

        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  )rf  r,  privateDeleteOrdersPairrh  privateDeleteOrdersAllri  r  )r   r8  r  rj  r  r,  r  s          r   cancel_all_orderszbitopro.cancel_all_orders  s     	
 [[(F$TlGFO33DKK4PQH224;;w3OPH~~h3 ''--r   c                     |t        | j                  dz         | j                          | j                  |      }||d   d}| j	                  | j                  ||            }| j                  ||      S )a  
        fetches information on an order made by the user

        https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_an_order_data.md

        :param str id: the 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>`
        z( fetchOrder() requires a symbol argumentr$   )rz  r/  )r   r$   rf  r,  privateGetOrdersPairOrderIdrh  r  r  s          r   fetch_orderzbitopro.fetch_order  s{     >#DGG.X$XYYV$4L
 33DKK4PQ0 &11r   c                 :   |t        | j                  dz         | j                          | j                  |      }d|d   i}|||d<   |||d<   | j	                  | j                  ||            }| j                  |dg       }|g }| j                  ||||      S )aX  
        fetches information on multiple orders made by the user

        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>`
        z) fetchOrders() requires a symbol argumentr/  r$   startTimestampr   r  )r   r$   rf  r,  privateGetOrdersAllPairrh  r  parse_orders)	r   r8  r  r   r  r,  rj  r  r   s	            r   fetch_orderszbitopro.fetch_orders   s     >#DGG.Y$YZZV$F4L
 (-G$%$GG//GV0LM&"5>F6   >>r   c                     | j                          i }d}|| j                  |      }|d   |d<   | j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )a7  
        fetch all unfilled currently open orders

        https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_open_orders_data.md

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr$   r/  r  )rf  r,  privateGetOrdersOpenrh  r  r  )	r   r8  r  r   r  rj  r,  r  r   s	            r   fetch_open_orderszbitopro.fetch_open_orders[  s     	[[(F$TlGFO,,T[[&-IJ&"5  >>r   c           	      R    ddi}| j                  |||| j                  ||            S )a_  
        fetches information on multiple closed orders made by the user

        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>`
        
statusKindDONE)r  rh  )r   r8  r  r   r  rj  s         r   fetch_closed_orderszbitopro.fetch_closed_ordersq  s4     &
   t{{7F7STTr   c                    |t        | j                  dz         | j                          | j                  |      }d|d   i}| j	                  | j                  ||            }| j                  |dg       }| j                  ||||      S )a!  
        fetch all trades made by the user

        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>`
        z+ fetchMyTrades() requires a symbol argumentr/  r$   r  )r   r$   rf  r,  privateGetOrdersTradesPairrh  r  r  r  s	            r   fetch_my_tradeszbitopro.fetch_my_trades  s     >#DGG.[$[\\V$F4L
 224;;w3OP&"5(   >>r   c           
      @    dddddddddd	}| j                  |||      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  s;    #%!"+!*

 77r   transactionr  c                 d   | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	|	dk(  r|}	i d|d	| j                  |d
      d| j                  |d      dd d|d| j                  |	      d| j	                  |d      d| j                  |      d|d| j                  |      d|dd d|d|dd d|dd d d || j	                  |d      d ddS )NcoinrK  addressmessager  protocolMAINr  r$   serialtxidr  r  networkr
  r  rL  addressFrom	addressTotagtagFromtagToupdatedr  )r  r6  r  )commentinternalr  )r  r  r  network_id_to_coder  r1  r  )
r   r2  r  r"  r  rK  r5  r>  r  	networkIds
             r   parse_transactionzbitopro.parse_transaction  s   Z %%k6:
&&z8<%%k;?	"";	:{I6!!+x8$$[*=	I
K
$"";9
 D$$[&9
 D	

 
 t..y9
 d&&{G<
 d33F;
 
 Y/
 w
 4
 
 3
 t
  S!
" t#
$  ((e<)
 	
r   r  c                 8   |t        | j                  dz         | j                          | j                  |      }d|d   i}|||d<   |||d<   | j	                  | j                  ||            }| j                  |dg       }| j                  ||||ddi      S )	a<  
        fetch all deposits made to an account

        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>`
        z+ fetchDeposits() requires the code argumentr  r$   r  r   r  r  r  )r   r$   rf  safe_currency&privateGetWalletDepositHistoryCurrencyrh  r  parse_transactions	r   r  r  r   r  r  rj  r  r   s	            r   fetch_depositszbitopro.fetch_deposits  s     <#DGG.[$[\\%%d+
 (-G$%$GG>>t{{7TZ?[\&"5( &&vxPYGZ[[r   c                 8   |t        | j                  dz         | j                          | j                  |      }d|d   i}|||d<   |||d<   | j	                  | j                  ||            }| j                  |dg       }| j                  ||||ddi      S )	aH  
        fetch all withdrawals made from an account

        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>`
        z. fetchWithdrawals() requires the code argumentr  r$   r  r   r  r  
withdrawal)r   r$   rf  rH  'privateGetWalletWithdrawHistoryCurrencyrh  r  rJ  rK  s	            r   fetch_withdrawalszbitopro.fetch_withdrawals<  s     <#DGG.^$^__%%d+
 (-G$%$GG??GU[@\]&"5& &&vxP\G]^^r   c                    |t        | j                  dz         | j                          | j                  |      }||d   d}| j	                  | j                  ||            }| j                  |di       }| j                  ||      S )a  
        fetch data on a currency withdrawal via the withdrawal id

        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>`
        z- fetchWithdrawal() requires the code argumentr$   )r9  r  r  )r   r$   rf  rH  &privateGetWalletWithdrawCurrencySerialrh  ri  rF  )r   r$   r  r  r  rj  r  r   s           r   fetch_withdrawalzbitopro.fetch_withdrawall  s     <#DGG.]$]^^%%d+ 
 >>t{{7TZ?[\&"5" %%fh77r   r5  c                 N   | j                  ||      \  }}| j                          | j                  |       | j                  |      }|d   | j	                  |      |d}d|v rv| j                  | j                  di       }| j                  |d      }	| j                  |dg      }| j                  ||	      }
|
t        | j                  dz   |	z         |
|d<   |||d<   | j                  | j                  ||            }| j                  |di       }| j                  ||      S )	a  
        make a withdrawal

        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
  r5  r;  r   z invalid network r7  r6  r  )handle_withdraw_tag_and_paramsrf  check_addressr  number_to_stringri  r   safe_string_upperr  r  r   r$   !privatePostWalletWithdrawCurrencyrh  rF  )r   r  r
  r5  r>  r  r  rj  r   requestedNetworkrE  r  r   s                r   r   zbitopro.withdraw  s5    99#vFV7#==& ++F3

 ~~dllJCH#55fiHYYv	{3F((3CDI #DGG.A$ADT$TUU"+GJ?!$GI99$++gv:VW&"5 %%fh77r   c                 <    || j                  |d      ddd d di dS )Nr  F)r  r   )r  r   r  r   )r  )r   r  r  s      r   parse_deposit_withdraw_feez"bitopro.parse_deposit_withdraw_fee  s;     ''];#
 " 
 	
r   codesc                     | j                          | j                  |      }| j                  |dg       }| j                  ||d      S )a  
        fetch deposit and withdraw fees

        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  )rf  r  r  parse_deposit_withdraw_fees)r   r]  r  r  r  s        r   fetch_deposit_withdraw_feesz#bitopro.fetch_deposit_withdraw_fees  sI     	77?" ~~h3//eZHHr   r   GETc                    d| j                  ||      z   }| j                  || j                  |            }|i }d|d<   |dk(  r[| j                          |dk(  s|dk(  r| j	                  |      }| j                  |      }	| j                  | j                  |	      | j                  | j                        t        j                        }
| j                  |d<   |	|d<   |
|d	<   n|d
k(  s|dk(  r|r|d| j                  |      z   z  }| j                         }d|i}| j	                  |      }| j                  |      }	| j                  | j                  |	      | j                  | j                        t        j                        }
| j                  |d<   |	|d<   |
|d	<   n#|dk(  r|d
k(  r|r|d| j                  |      z   z  }| j                  d   d   |z   }||||dS )Nr2  ccxtzX-BITOPRO-APIr   POSTPUTzX-BITOPRO-APIKEYzX-BITOPRO-PAYLOADzX-BITOPRO-SIGNATUREra  DELETE?noncer   r   r   )urlmethodbodyheaders)implode_paramsr  extract_paramscheck_required_credentialsjsonstring_to_base64hmacencoder   hashlibsha384r   	urlencoder  r   )r   pathr   rj  r  rl  rk  ri  querypayload	signaturerh  rawDatar  s                 r   signzbitopro.sign  s   D''f55		&$"5"5d";<?G#) )++-6U?yy(//5 IIdkk'&:DKK<TV]VdVde	.2kk*+/6+,1:-.5Fh$63!666C))+U! yy)//5 IIdkk'&:DKK<TV]VdVde	.2kk*+/6+,1:-.H_5sT^^E222iiv&,fdwOOr   reasonri  rj  rl  rk  c
                     |y |dk\  r|dk  ry | j                   dz   |z   }
| j                  |d      }| j                  | j                  d   ||
       | j	                  | j                  d   ||
       t        |
      )N   i,   errorr   r   )r$   r  throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r   r  r}  ri  rj  rl  rk  r  requestHeadersrequestBodyfeedbackr  s               r   handle_errorszbitopro.handle_errors  s    3;4#:77S=4'  73,,T__W-EuhW,,T__W-EuhWH%%r   )N)B__name__
__module____qualname__r   r   r   r&  r   r
   r+  dictrH  r   rd  strrk  r   r   rp  r	   r   rv  r   r  r  r   r  r  r  r  r  r   r  r  r   r  r   r  r   r   floatr   r  r   r  r  r  r  r  r  r  r"  r1  r   r   rF  rL  rP  rS  r   r\  r`  r|  r  r  __classcell__)r   s   @r   r!   r!      s   C# CJ
 ') ?Z ?B $& +$v, +B;
4 ;
F ;
z$4 $ $6 $L 02 13 1f 1@ 04B 4W 47 4< :>b 'js 'j3 'jY 'jRM Mv M M^ 6:UW ?3 ?s ?# ?\`af\g ?B )+ W{ Wr
 
4 
 26DW[df 4\# 4\c 4\QT 4\koptku 4\l!F) )4 $& ,( ,6
8 
8T Tv T Tl gksu 623 62i 62y 62RW 62`c 62p 37r 2s 2C 2> 04B . .4; .@ /32  .  .$u+  .D 26b +2c +23 +2Z *.Dt\^ 9?3 9?c 9? 9?cghmcn 9?v /3TXac ? ?3 ?c ?, 154VZce U# US UPS Ujnotju U" -1tRV_a (?c (? (?C (?T8s 8O
T O
X O
Q\ O
b *.Dt\^ /\3 /\c /\ /\cghsct /\b -1tRV_a ._c ._ ._C ._fjkvfw ._` 59 %83 %8c %8N DHPR /8S /8% /8# /8Wb /8b
 
0 <@ I I> &eBSW  PD	&# 	&s 	& 	&c 	&TX 	&`c 	&r   r!   )'ccxt.base.exchanger   ccxt.abstract.bitopror   rt  r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r!    r   r   <module>r     s\    ( -   z  z  z  z  z  * 0 . ' . ) 4 %P&h P&r   