
    E#i&                        S SK Jr  S SKJr  S SKrS SKrS SKJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJ r   S SKJ!r!  S SK"J#r#  S SK$J%r%   " S S\\5      r&g)    )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                   ,  ^  \ rS rSrS\4U 4S jjr0 4S\4S jjr0 4S\\	   4S jjr
S\S\	4S jrSIS	\S\	S\4S
 jjr0 4S\S\4S jjrS0 4S\S\4S jjrS0 4S\S\S\4S jjrSIS\S\	S\4S jjrSS0 4S\S\S\S\\   4S jjr0 4S\4S jjrSIS\	S\4S jjrSSS0 4S\S\S\S\S\\   4
S jjrS rS\ 4S jr!0 4S\ 4S jjr"S\#4S jr$SIS\S\	S\%4S  jjr&S0 4S\S!\'S"\(S#\)S$\*4
S% jjr+S0 4S&\S\#4S' jjr,S( r-S0 4S)\\   S\#S\\%   4S* jjr.S0 4S\#S\\%   4S+ jjr/S0 4S&\S\#4S, jjr0SSS0 4S\#S\S\S\\%   4S- jjr1SSS0 4S\#S\S\4S. jjr2SSS0 4S\#S\S\S\\%   4S/ jjr3SSS0 4S\#S\S\4S0 jjr4S\#4S1 jr5SIS2\S3\6S\74S4 jjr8SSS0 4S5\#S\S\S\\7   4S6 jjr9SSS0 4S5\#S\S\S\\7   4S7 jjr:S0 4S&\S5\#4S8 jjr;S0 4S5\S#\)S9\S:\#S\74
S; jjr<SIS3\64S< jjr=S0 4S=\4S> jjr>S?S@0 SS4SA jr?S5\@SB\SC\SD\SE\SF\4SG jrASHrBU =rC$ )Jbitopro   returnc                   > U R                  [        [        U ]  5       0 SS_SS_SS/_SS_S	S
_SS_S0 SS _SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_0 S S_S!S_S"S_S#S_S$S_S%S_S&S_S'S_S(S_S)S_S*S_S+S_S,S_S-S_S.S_S/S_S0S_E0 S1S_S2S_S3S4_S5S_S6S_S7S_S8S_S9S_S:S_S;S_S<S_S=S_S>S_S?S_S@S_SAS_SBS_E0 SCS_SDS_SES_SFS_SGS_SHS_SIS_SJS_SKS_SLS_SMS_SNS_SOS_SPS_SQS_SRS_SSS_E0 STS_SUS_SVS_SWS_SXS_SYS_SZS_S[S_S\S_S]S_S^S_S_S_S`S_SaS_SbS_ScS_SdS_E0 SeS_SfS_SgS_ShS_SiS_SjS_SkS_SlS_SmS_SnS_SoS_SpS_SqS_SrS_SsS_StS_SuS_ESSSSSSv.E_SwSxSySzS{S|S}S~SSSSS._SSSS0SS/SS._SSSS._SSSSSSSSSSSS.	0SSSSSSSSSSS.
SSSS.SS0SSSS.S.S._SSSSU R	                  S5      U R	                  S5      U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      //U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      /U R	                  S5      U R	                  S5      //S.S.0_SSSSSSSS.S/S._SSSSS SSSS SSSSS.SSSSSSSS.S SSSSSS.SSSSS.SS SSSS.SSSSSSSS.SSSSSSSSS.SS0S.	S S S.S S S.S._S[
        _S[        [        [        [        [        S.[        [        [        [        S.S._S0 _5      $ )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?   createOrdersrq   ry   rv   r{   rM   rr   )linearinverse)r1   r3   r4   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/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/bitopro.pyr   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                 D   U R                  U5      nU R                  US/ 5      n0 nU R                  U R                  S/ 5      n[        S[	        U5      5       H  nX6   nU R                  US5      nU R                  U5      n	U R                  US5      n
U R                  US5      nU R                  US5      nU R                  US5      nU R                  US	5      nUUS
.SSS
.S.nU R                  X5      nUU	UU(       a  SOSSU
=(       a    UU
UUSUSS.XI'   M     U$ )a  
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_currenciesbitopro.fetch_currencies]  sG    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"$!  FL) +D r  c                 j    U R                  5       nU R                  US/ 5      nU R                  U5      $ )a  
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_marketsbitopro.fetch_markets  s7     99;..626* !!'**r  marketc                    U R                  US5      (       + nU R                  US5      nUR                  5       nU R                  US5      nU R                  US5      nU R                  U5      nU R                  U5      nUS-   U-   n	U R	                  US5      U R	                  US5      S.S S S.S S S.S S S.S	.n
0 S
U_SU_SU	_SU_SU_SU_SU_SS _SS _SS_SS_SS_SS_SS_SS_SS_SS _S S S S S S U
U R                  U R                  U R                  US5      5      5      U R                  U R                  U R                  US5      5      5      S.US US.E$ )Nmaintainpairbasequote/minLimitBaseAmountmaxLimitBaseAmountr	  )r  pricecostr   r%   uppercaseIdsymbolbaseIdquoteIdsettlesettleIdr  r1   Tr2   Fr3   r4   r5   contractr   quotePrecisionbasePrecision)r9  r  )r   contractSizeexpiryexpiryDatetimestrike
optionTyper  r  r  createdr  )r  r  upperr  r  r   parse_precision)r   r0  r  r%   r;  r=  r>  r4  r5  r<  r  s              r   parse_market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                    U R                  US5      nU R                  X25      nU R                  US5      nU R                  0 SU_SS _SS _SU R                  US5      _SU R                  US5      _S	S _S
S _SS _SS _SS _SS _SU R                  US5      _SU R                  US5      _SS _SS _SU R                  US5      _SS _U R                  US5      S US.EU5      $ )Nr3  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   rN  r0  marketIdr<  s        r   parse_tickerbitopro.parse_ticker  s|    ##FF3!!(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  r<  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US0 5      nU R                  Xc5      $ )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>`
r3  r%   r  )load_marketsr0  publicGetTickersPairextend	safe_dictri  )r   r<  r  r0  requestr   rN  s          r   fetch_tickerbitopro.fetch_ticker"  sn     	V$F4L
 ,,T[[-IJ&"5   00r  symbolsc                     U R                  5         U R                  5       nU R                  US/ 5      nU R                  XA5      $ )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  )rl  publicGetTickersr  parse_tickers)r   rs  r  r   r   s        r   fetch_tickersbitopro.fetch_tickersB  sC     	((*..626  !!'33r  r   c           	          U R                  5         U R                  U5      nSUS   0nUb  X%S'   U R                  U R                  XS5      5      nU R	                  XdS   SSSSS	5      $ )
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
r3  r%   Nr   r<  bidsasksr9  r  )rl  r0  publicGetOrderBookPairrn  parse_order_book)r   r<  r   r  r0  rp  r   s          r   fetch_order_bookbitopro.fetch_order_book`  s{     	V$F4L
 $G..t{{7/KL* $$Xh/?vvW^`hiir  tradec                 $   U R                  US5      nU R                  US5      nS nUc  U R                  US5      nOU R                  US5      nU R                  US5      nU R                  Xb5      nU R                  US5      nU R                  US5      nU R	                  US5      n	U R	                  US5      n
U
c  U R                  US	5      nU(       a  S
n
OSn
U R                  US5      nUc  U R                  US5      nS nU R                  US5      nU R                  U R                  US5      5      nUb  UUS S.nU R                  US5      nS nUb  U(       a  SnOSnU R                  UUUUU R                  U5      UUU	U
UUS US.U5      $ )NtradeIdorderIdrP  r3  r<  r9  r  actionisBuyerbuysellr  
baseAmountr  	feeSymbol)r:  r  rateisTakerr   r   )r%   r  orderrP  rQ  r<  takerOrMakerr  sider9  r  r:  r  )	r  safe_timestampsafe_integerrf  safe_string_lowerr  r  
safe_tradeiso8601)r   r  r0  r%   r  rP  rh  r<  r9  r  r  r  r  r  	feeAmountr  r  r  s                     r   parse_tradebitopro.parse_trade  s   2 eY/""5)4	:++E;?I))%=I##E62!!(3!!&(3  0%%eV4%%eX6<nnUI6G!!%2>%%e\:F$$UE2	++D,<,<UK,PQ	 !%C
 ..	2&&"Y/( 
  	r  sincec                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  Xd5      5      nU R	                  US/ 5      nU R                  XX#5      $ )a  
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>`
r3  r%   r  )rl  r0  publicGetTradesPairrn  r  parse_trades	r   r<  r  r   r  r0  rp  r   tradess	            r   fetch_tradesbitopro.fetch_trades  sp     	V$F4L
 ++DKK,HI&"5   >>r  c                 ^   U R                  5         U R                  U5      nU R                  US0 5      nU R                  US5      n0 nU R	                  US5      nU R	                  US5      n[        S[        U R                  5      5       H  nU R                  U   n	UU	UUSSS.XY'   M     U$ )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  r<  r   r   r   r   )rl  'publicGetProvisioningLimitationsAndFeesro  
safe_valuer  r  r  rs  )
r   r  r   r  firstr"  r   r   r#  r<  s
             r   fetch_trading_feesbitopro.fetch_trading_fees  s     	??G2BBG2|   
3  
3q#dll+,A\\!_F "!FN - r  c           	          U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )NrP  r[  rR  rT  r\  volume)r  r  )r   ohlcvr0  s      r   parse_ohlcvbitopro.parse_ohlcvR  sl    e[1UF+UF+UE*UG,UH-
 	
r  r   	timeframec                    U R                  5         U R                  U5      nU R                  U R                  X"5      nUS   US.nUc  SnO[	        US5      nU R                  U5      n	Sn
Uc!  U R                  5       US'   US   XI-  -
  US'   OhU	S-  n[        [        R                  " X;-  5      5      U-  n
[        [        R                  " US-  5      5      US'   U R                  US   XI-  5      US'   U R                  U R                  X5      5      nU R                  US	/ 5      nU R                  XX#U5      nU R                  XX5      $ )
aq  
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%   )r3  
resolutionNi  i$ tofromr   r  )rl  r0  r  r   r
  parse_timeframesecondsintmathfloorsumpublicGetTradingHistoryPairrn  r  parse_ohlcvsinsert_missing_candles)r   r<  r  r  r   r  r0  r  rp  timeframeInSecondsalignedSincetimeframeInMillisecondsr   r  sparses                  r   fetch_ohlcvbitopro.fetch_ohlcv\  sM    	V$%%dooyL
4L$

 =Eu%E!11)<= LLNGDM%dmu/IJGFO&84&?#tzz%*IJKNeeL!$**UT\":;GFO HHWV_e6PQGDM33DKK4PQ~~h3 ""45I**6|[[r  c                    [        U5      nUS:X  a  U$ / nUS   nS nUc  US   nOUnSn	[        U5      n
SnX:  a  X:  a  X   nUS   U:X  a$  UR                  U5        U R                  U	S5      n	OSU R                  / U5      nXS'   US   US'   US   US'   US   US'   U R	                  S5      US'   UR                  U5        U R                  XS-  5      n[        U5      nXkS-
     nX:  a  X:  a  M  U$ )	Nr   r            r   r   r   )r  appendr  array_concatr   )r   candlesdistancer  r   lengthr"  copyFromrP  r#  candleLengthresultLengthcandlecopys                 r   r  bitopro.insert_missing_candles  s'    WQ;N1:	= II7|#!*:ZFayI%f%HHQN((X6#Qq'Qq'Qq'Q++C0Qd#tO<Iv;LQ./H! #!*:" r  c                    SU0n[        S[        U5      5       HW  nX   nU R                  US5      nU R                  U5      nU R                  US5      nU R                  US5      nUUS.n	XU'   MY     U R	                  U5      $ )Nr  r   r  r  	available)freetotal)r  r  r  r  safe_balance)
r   r   r"  r#  balancer$  r  r  r  accounts
             r   parse_balancebitopro.parse_balance  s     H
 q#h-(AkG))':>J**:6D%%gx8F((+>I!G #4L )   ((r  c                     U R                  5         U R                  U5      nU R                  US/ 5      nU R                  U5      $ )ah  
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  )rl  privateGetAccountsBalancer  r  )r   r  r   balancess       r   fetch_balancebitopro.fetch_balance  sE     	11&9>>(FB7 !!(++r  statusc                 :    SSSSSSSS.nU R                  X!S 5      $ )Nr[  closedcanceled)z-1r   12346r  )r   r  statusess      r   parse_order_statusbitopro.parse_order_status  s3    
 $77r  r  c                    U R                  USS5      nU R                  USS5      nU R                  US5      nUR                  5       nU R                  USS5      nU R                  US5      nU R                  US	5      nU R	                  XS
5      nU R                  US5      n	U R                  US5      n
U R                  U
5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nS nUS:X  a  SnS nU R                  US5      nU R                  U R                  US5      5      n[        R                  " US5      (       a  UUS.nU R                  0 SU_SS _SU_SU R                  U5      _SU R                  US5      _SU	_SU_SU_SU_SU_SU_SS _SU_SS _S U_S!U_S"U_UUS US#.EU5      $ )$Nr%   r  rP  createdTimestampr  r  originalAmountr9  r3  _r<  r  r  avgExecutionPriceexecutedAmountremainingAmountr   	POST_ONLYTr  r  r   )r  r:  clientOrderIdrQ  lastTradeTimestampupdatedTimestamppostOnlyr  r   r:  rb  filled	remaining)r  r  r  r  )safe_string_2safe_integer_2r  lowerrf  r  r  r  r   	string_gt
safe_orderr  r  )r   r  r0  r%   rP  r  r  r9  rh  r<  orderStatusr  r  rb  r  r  r   r  r  r  r  s                        r   parse_orderbitopro.parse_order  s   F tY7''{<NO	x0zz|##E85EF  0##E62!!(C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  r9  c                    U R                  5         U R                  U5      nUUS   UU R                  X5      U R                  5       S.nUR	                  5       n	U	S:X  a  U R                  X5      US'   U	S:X  a  U R                  X5      US'   U R                  USS5      n
U R                  USS/5      nU
c  [        U R                  S	-   U	-   S
-   5      eU R                  X5      US'   U R                  US5      nUc  [        U R                  S-   U	-   S
-   5      eXS'   U R                  U	S:H  SU5      nU(       a  SUS'   U R                  U R                  X5      5      nU R                  X5      $ )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  r3  r  r  rP  LIMITr9  
STOP_LIMITr   	stopPriceNz5 createOrder() requires a triggerPrice parameter for z orders	conditionz2 createOrder() requires a condition parameter for MARKETr  r   )rl  r0  amount_to_precisionmillisecondsrJ  price_to_precisionsafe_value_2omitr   r%   r  is_post_onlyprivatePostOrdersPairrn  r  )r   r<  r  r  r  r9  r  r0  rp  	orderTyper   r  r  r   s                 r   create_orderbitopro.create_orderL  s    	V$4L..v>**,
 JJL	#66vEGG$#66v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'.JK 11r  r%   c                     Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUUS   S.nU R	                  U R                  XS5      5      nU R                  Xd5      $ )aw  
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%   r3  )r   r%   rl  r0  privateDeleteOrdersPairIdrn  r  r   r%   r<  r  r0  rp  r   s          r   cancel_orderbitopro.cancel_order  sw     >#DGG.Y$YZZV$4L
 11$++g2NO 11r  c                 *   [        UR                  5       5      n/ n[        S[        U5      5       H^  nX$   nX   n[        S[        U5      5       H:  nUR	                  U R                  Xg   Xg   U R                  U5      S.5      5        M<     M`     U$ )Nr   )r  r%   r<  )listkeysr  r  r  r  safe_symbol)r   r  dataKeysr   r#  rh  orderIdsjs           r   parse_cancel_ordersbitopro.parse_cancel_orders  s    		$q#h-(A{H~H1c(m,doo$K"+"..x8/   - ) r  idsc                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUS   n0 nXU'   U R	                  U R                  Xc5      5      nU R                  US5      nU R                  U5      $ )al  
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 argumentr;  r  )r   r%   rl  r0  privatePutOrdersrn  ro  r  )	r   r  r<  r  r0  r%   rp  r   r  s	            r   cancel_ordersbitopro.cancel_orders  s     >#DGG.Z$Z[[V$M"((W)EF ~~h/''--r  c                 ,   U R                  5         0 nSnUb:  U R                  U5      nUS   US'   U R                  U R                  X25      5      nO U R	                  U R                  X25      5      nU R                  US0 5      nU R                  U5      $ )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%   r3  r  )rl  r0  privateDeleteOrdersPairrn  privateDeleteOrdersAllro  r  )r   r<  r  rp  r   r0  r  s          r   cancel_all_ordersbitopro.cancel_all_orders  s     	
 [[(F$TlGFO33DKK4PQH224;;w3OPH~~h3 ''--r  c                     Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUUS   S.nU R	                  U R                  XS5      5      nU R                  Xd5      $ )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%   )r  r3  )r   r%   rl  r0  privateGetOrdersPairOrderIdrn  r  r  s          r   fetch_orderbitopro.fetch_order  sw     >#DGG.X$XYYV$4L
 33DKK4PQ0 11r  c                 8   Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nUb  X&S'   Ub  X6S'   U R	                  U R                  Xd5      5      nU R                  US/ 5      nUc  / nU R                  XX#5      $ )a  
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 argumentr3  r%   startTimestampr   r  )r   r%   rl  r0  privateGetOrdersAllPairrn  r  parse_orders)	r   r<  r  r   r  r0  rp  r   r   s	            r   fetch_ordersbitopro.fetch_orders   s     >#DGG.Y$YZZV$F4L
 (-$%$G//G0LM&"5>F6   >>r  c                     U R                  5         0 nSnUb  U R                  U5      nUS   US'   U R                  U R                  XT5      5      nU R	                  US/ 5      nU R                  XX#5      $ )a  
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%   r3  r  )rl  r0  privateGetOrdersOpenrn  r  r0  )	r   r<  r  r   r  rp  r0  r   r   s	            r   fetch_open_ordersbitopro.fetch_open_orders[  sy     	[[(F$TlGFO,,T[[-IJ&"5  >>r  c           	      L    SS0nU R                  XX0R                  XT5      5      $ )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)r1  rn  )r   r<  r  r   r  rp  s         r   fetch_closed_ordersbitopro.fetch_closed_ordersq  s.     &
   {{77STTr  c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nU R	                  U R                  Xd5      5      nU R                  US/ 5      nU R                  XX#5      $ )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 argumentr3  r%   r  )r   r%   rl  r0  privateGetOrdersTradesPairrn  r  r  r  s	            r   fetch_my_tradesbitopro.fetch_my_trades  s     >#DGG.[$[\\V$F4L
 224;;w3OP&"5(   >>r  c           
      >    SSSSSSSSSS.	nU R                  X!U5      $ )Nokfailedpending)	COMPLETEINVALID
PROCESSINGWAIT_PROCESSFAILEDEXPIRED	CANCELLEDEMAIL_VERIFICATIONWAIT_CONFIRMATIONr  )r   r  statess      r   parse_transaction_status bitopro.parse_transaction_status  s9    #%!"+!*

 77r  transactionr  c                 d   U R                  US5      nU R                  X25      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n	U	S:X  a  Un	0 SU_S	U R                  US
5      _SU R                  US5      _SS _SU_SU R                  U	5      _SU R	                  US5      _SU R                  U5      _SU_SU R                  U5      _SU_SS _SU_SU_SS _SU_SS _S S UU R	                  US5      S S.S.E$ )NcoinrP  addressmessager  protocolMAINr  r%   serialtxidr  r  networkr  r  rQ  addressFrom	addressTotagtagFromtagToupdatedr  )r  r:  r  )commentinternalr  )r  r  r  network_id_to_coder  rN  r  )
r   rP  r  r$  r  rP  rS  r\  r  	networkIds
             r   parse_transactionbitopro.parse_transaction  s   Z %%k6:
&&z<%%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                 4   Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nUb  X&S'   Ub  X6S'   U R	                  U R                  Xd5      5      nU R                  US/ 5      nU R                  XX#SS05      $ )	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%   rl  safe_currency&privateGetWalletDepositHistoryCurrencyrn  r  parse_transactions	r   r  r  r   r  r  rp  r   r"  s	            r   fetch_depositsbitopro.fetch_deposits  s     <#DGG.[$[\\%%d+
 (-$%$G>>t{{7?[\&"5( &&vPYGZ[[r  c                 4   Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nUb  X&S'   Ub  X6S'   U R	                  U R                  Xd5      5      nU R                  US/ 5      nU R                  XX#SS05      $ )	a  
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%   rl  rg  'privateGetWalletWithdrawHistoryCurrencyrn  r  ri  rj  s	            r   fetch_withdrawalsbitopro.fetch_withdrawals<  s     <#DGG.^$^__%%d+
 (-$%$G??G@\]&"5& &&vP\G]^^r  c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUUS   S.nU R	                  U R                  XS5      5      nU R                  US0 5      nU R                  Xt5      $ )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%   )rW  r  r  )r   r%   rl  rg  &privateGetWalletWithdrawCurrencySerialrn  ro  rd  )r   r%   r  r  r  rp  r   r"  s           r   fetch_withdrawalbitopro.fetch_withdrawall  s     <#DGG.]$]^^%%d+ 
 >>t{{7?[\&"5" %%f77r  rS  r\  c                 H   U R                  XE5      u  pEU R                  5         U R                  U5        U R                  U5      nUS   U R	                  U5      US.nSU;   au  U R                  U R                  S0 5      nU R                  US5      n	U R                  US/5      nU R                  X5      n
U
c  [        U R                  S-   U	-   5      eXS'   Ub  XGS'   U R                  U R                  Xu5      5      nU R                  US0 5      nU R                  X5      $ )	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  rS  rY  r   z invalid network rU  rT  r  )handle_withdraw_tag_and_paramsrl  check_addressr  number_to_stringro  r   safe_string_upperr  r  r   r%   !privatePostWalletWithdrawCurrencyrn  rd  )r   r  r  rS  r\  r  r  rp  r   requestedNetworkrc  r   r"  s                r   r   bitopro.withdraw  s&    99#F7#==& ++F3

 ~~dllJCH#55fiHYYv	{3F((DI #DGG.A$ADT$TUU"+J?!$I99$++g:VW&"5 %%f77r  c                 <    UU R                  US5      SS.S S S.0 S.$ )Nr  F)r  r   )r  r   r  r   )r  )r   r  r  s      r   parse_deposit_withdraw_fee"bitopro.parse_deposit_withdraw_fee  s;     ''];#
 " 
 	
r  codesc                     U R                  5         U R                  U5      nU R                  US/ 5      nU R                  XAS5      $ )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  )rl  r  r  parse_deposit_withdraw_fees)r   r  r  r   r  s        r   fetch_deposit_withdraw_fees#bitopro.fetch_deposit_withdraw_fees  sG     	77?" ~~h3//ZHHr  r   GETc                    SU R                  X5      -   nU R                  X@R                  U5      5      nUc  0 nSUS'   US:X  Ga`  U R                  5         US:X  d  US:X  a  U R	                  U5      nU R                  U5      n	U R                  U R                  U	5      U R                  U R                  5      [        R                  5      n
U R                  US'   XS'   XS	'   OUS
:X  d  US:X  a  U(       a  USU R                  U5      -   -  nU R                  5       nSU0nU R	                  U5      nU R                  U5      n	U R                  U R                  U	5      U R                  U R                  5      [        R                  5      n
U R                  US'   XS'   XS	'   O*US:X  a$  US
:X  a  U(       a  USU R                  U5      -   -  nU R                  S   S   U-   nXsXeS.$ )Nr6  ccxtzX-BITOPRO-APIr   POSTPUTzX-BITOPRO-APIKEYzX-BITOPRO-PAYLOADzX-BITOPRO-SIGNATUREr  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   r  r  r  r  r  querypayload	signaturer  rawDatar  s                 r   signbitopro.sign  s   D''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&,dOOr  reasonr  r  r  r  c
                     Uc  g US:  a  US:  a  g U R                   S-   U-   n
U R                  US5      nU R                  U R                  S   X5        U R	                  U R                  S   X5        [        U
5      e)N   i,   errorr   r   )r%   r  throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r   r  r  r  r  r  r  r   requestHeadersrequestBodyfeedbackr  s               r   handle_errorsbitopro.handle_errors  s|    3;4#:77S=4'  73,,T__W-EuW,,T__W-EuWH%%r   )N)D__name__
__module____qualname____firstlineno__r   r   r   r(  r   r
   r.  dictrL  r   ri  strrq  r   r   rw  r	   r   r~  r   r  r  r   r  r  r  r  r  r   r  r  r   r  r   r  r   r   floatr   r  r  r  r"  r'  r+  r1  r5  r:  r>  rN  r   r   rd  rk  rp  rt  r   r  r  r  r  r  __static_attributes____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 
 9=4^bkm 4\# 4\# 4\S 4\X[ 4\rvw{r| 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> ;?r .c .C .dSXk .@ /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 KOWY /8S /8% /8# /8C /8^i /8b
 
0 <@ I I> &eBSW  PD	&# 	&s 	& 	&c 	&TX 	&`c 	& 	&r  r!   )'ccxt.base.exchanger   ccxt.abstract.bitopror   r  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  r   <module>r     s\    ( -   z  z  z  z  z  * 0 . ' . ) 4 %P&h P&r  