
    !:hy                        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 d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dl m!Z! d dl"m#Z#  G d dee      Z$y)    )Exchange)ImplicitAPIN)AnyBalancesIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTrade)List)ExchangeError)AuthenticationError)PermissionDenied)InsufficientFunds)InvalidOrder)OrderNotFound)DDoSProtection)InvalidNonce)	TICK_SIZE)Precisec                   &    e Zd Zdef fdZi fdee   fdZdedefdZ	de
fdZi fde
fdZdi fd	ed
edefdZd0d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d0dededefdZddi fd	eded
ede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efdZ!d0dedede"fdZ#di fded	efd Z$dddi fd	eded
efd!Z%dddi fd	eded
edee"   fd"Z&dddi fd	eded
edee"   fd#Z'd$ Z(d%d&i ddfd'Z)d(e*d)ed*ed+ed,ed-efd.Z+d%d&i ddi fd/Z, xZ-S )1btcboxreturnc                    | j                  t        t        |          dddg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d)di d*dd+dd,dd-dd.dd/dd0d	d1d	d2d	d3dd4dd5dd6dd7dd8dd9dd:ddddd;d<d=d>id?d@dAdBdCg dDidEg dFidCdGgidHd	dIdJdKdLdddd dddd dddddMddddddddNd d dddd	dOddPddd	dQddPd d ddd	dRd d dS	d d dTd d dTdUt        t
        t        t        t        t        t        t        t        t        t        dV
dW      S )XNr   BtcBoxJPi  v1FCORSspotTmarginswapfutureoption	addMargincancelOrdercloseAllPositionsclosePositioncreateOrdercreateReduceOnlyOrderfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchMarginModefetchMarkOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTransferfetchTransfersfetchWithdrawalfetchWithdrawalsreduceMarginsetLeveragesetMarginModesetPositionMode)transferwithdrawwszOhttps://github.com/user-attachments/assets/1e2cb499-8d0f-4f8f-9464-3c015cfbc76brestzhttps://www.btcbox.co.jp/apizhttps://www.btcbox.co.jp/z'https://blog.btcbox.jp/en/archives/8762zMhttps://support.btcbox.co.jp/hc/en-us/articles/360001235694-Fees-introduction)logoapiwwwdocfeesget)depthorderstickertickerspost)balance	trade_addtrade_cancel
trade_list
trade_viewwalletzajax/coin/coinInfo)publicprivatewebApi   )webApiEnablewebApiRetriesz0.0001)fetchMarketsamountPrecision)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedleveragemarketBuyRequiresPricemarketBuyByCostselfTradePreventiontrailingiceberg)ry   triggerr   symbolRequiredd   )ry   limitr   r   r   )ry   r   daysBack	untilDaysr   r   r   )	sandboxr/   createOrdersfetchMyTradesrB   rA   rD   fetchClosedOrders
fetchOHLCV)linearinverse)r&   r(   r)   )
104105106107200201202203401402)idname	countries	rateLimitversionprohasurlsr]   optionsfeaturesprecisionMode
exceptions)deep_extendsuperr   describer   r   r   r   r   r   r   r   )self	__class__s    E/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/btcbox.pyr   zbtcbox.describe   s7   fd < >777 %7 	7
 %7 %7 U7 t7 $U7  7 t7 (7 7 +E7 )%7  '!7" (#7$ &u%7& #E'7( *5)7* $U+7, "5-7. *5/70 +E172  374 "5576 !%778 +E97: "4;7< d=7> !$?7@ tA7B  C7D 'E7F $UG7H !%I7J *5K7L (M7N %eO7P )%Q7R tS7T U7V tW7X  Y7Z !%[7\ "5]7^ #E_7` a7b uc7d  e7f "5g7h "!m7r j: 3@g    	 ,'6 %)%&! $,  %&+(-,0,1).+06:#(#("'#(	( #($)27+0/4$)#()$, %)%)&+#($)*.	# ',!$#($)*.( ',!$$(%)#($)*.$ *."&c2h ##
 ##q<z '*'##(##$$%MrA
 r r	    c                    | j                         }| j                  ddd      }||g\  }}| j                  |di       }t        |j	                               }g }t        dt        |            D ]o  }	||	   }
|
j                  d      }| j                  |d      }| j                  |d      }|j                         }|j                         }||
   }|dz   |z   }|d	k(  r| j                  d
      n| j                  d      }| j                  ||i       }| j                  |di       }|j                  | j                  i d|ddd|d|d|d|d|ddddddddddddddddd|d|ddddddddddd ddd ddd ddd d!| j                  | j                  | j                  |d"                  dd#| j                  |d$      d%k(  d|d&             r |S )'z
        retrieves data on all markets for ace
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        rs   webApiGetAjaxCoinCoinInfoTdatar   _   /BTCz0.0005z0.0010trader   uppercaseIdNsymbolbasebaseIdquotequoteIdsettlesettleIdtyper&   r'   Fr(   r)   r*   takermakerminmaxamountpricecostr   pricedecimalr   r   enable1)contractr   r   contractSizeexpiryexpiryDatetimestrike
optionTypelimits	precisionactivecreatedinfo)publicGetTickersfetch_web_endpoint	safe_dictlistkeysrangelensplitsafe_stringlowerparse_numberappendsafe_market_structureparse_precision)r   paramspromise1promise2	response1	response2result2Data	marketIdsmarketsimarketIdsymbolPartsbaseCurrr   r   r   resr   feedetailstradeDetailss                        r   fetch_marketszbtcbox.fetch_markets   s    ((***>;VX\] ((3	9nnY;)*	q#i.) ?	A |H"..-K''Q7H$$[!4EkkmG!BH%C^e+F24+$##H-DDUDUV^D_Cnn["b9G>>'7B?LNN455 37b37t37 &37 	37
 "37 37 737 $37 D37 37 37 %37 37 %37 %37  !37" #37$ " $"&"  $#
  $#
  $#
  $#!& "..t/C/CDDTDTUacqDr/st" **<BcIe37 3 3?	@ r   marketc                 d   | j                  |d      }| j                  |      }| j                  |d      }| j                  |      }|dz   |z   }i d| j                  |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 | j                  |d      | j                  |d      dd d dd d dd d dd| j                  | j	                  | j                  |d                  | j                  | j	                  | j                  |d                  dd d |dS )Nr   r   r   r   r   r   r   r   r   r   r   r&   Tr'   Fr(   r)   r*   r   r   minLimitBaseAmountmaxLimitBaseAmountr   r   quotePrecisionbasePrecisionr   )r   r   r   r   r   r   r   r   r   r   r   )r   safe_currency_codesafe_numberr   r   )r   r   r   r   r   r   r   s          r   parse_marketzbtcbox.parse_market  s   !!&&1&&v.""673''0e#1
$""6841
41
 f1
 D	1

 f1
 U1
 w1
 d1
 1
 F1
 D1
 e1
 E1
 e1
 e1
  !1
" d#1
$  "  ++F4HI++F4HI
  
  
  & **4+?+?@P@PQWYi@j+kl++D,@,@AQAQRXZiAj,kl a1
 1	
r   c                 x   d|i}t        | j                  j                               }t        dt	        |            D ]k  }||   }| j                  |      }|d   }|dz   }||v s(| j                         }	|dz   }
| j                  ||      |	d<   | j                  ||
      |	d<   |	||<   m | j                  |      S )Nr   r   r   _balance_lockfreeused)	r   
currenciesr   r   r   currencyaccountr   safe_balance)r   responseresultcodesr   coder	  
currencyIdr  r
  r  s              r   parse_balancezbtcbox.parse_balanceW  s    )T__))+,q#e*% 
	'A8D}}T*H!$J
*Dx,,.!G+"&"2"28T"B"&"2"28T"B&t
	'   ((r   c                 f    | j                          | j                  |      }| j                  |      S )aY  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://blog.btcbox.jp/en/archives/8762#toc13

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        )load_marketsprivatePostBalancer  )r   r   r  s      r   fetch_balancezbtcbox.fetch_balanceg  s1     	**62!!(++r   Nr   r   c                     | j                          | j                  |      }i }t        | j                        }|dkD  r|d   |d<   | j	                  | j                  ||            }| j                  ||d         S )a*  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://blog.btcbox.jp/en/archives/8762#toc6

        :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   coinr   )r  r   r   symbolspublicGetDepthextendparse_order_book)r   r   r   r   r   request
numSymbolsr  s           r   fetch_order_bookzbtcbox.fetch_order_bookt  sy     	V$&
>$X.GFO&&t{{7F'CD$$Xvh/?@@r   rd   c                    | j                  d |      }| j                  |d      }| j                  i d|dd dd d| j                  |d      d| j                  |d      d| j                  |d      d	d d
| j                  |d      dd dd dd d|d|dd dd dd dd | j                  |d      | j                  |d      |d|      S )Nlastr   	timestampdatetimehighlowbidbuy	bidVolumeasksell	askVolumevwapopenclosepreviousClosechange
percentageaveragevolvolume)
baseVolumequoteVolumer   )safe_symbolr   safe_ticker)r   rd   r   r   r   s        r   parse_tickerzbtcbox.parse_ticker  si   !!$// !
f!
!
 !
 D$$VV4	!

 4##FE2!
 4##FE2!
 !
 4##FF3!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **659++FH=)!
* + 	r   c                     | j                          | j                  |      }i }t        | j                        }|dkD  r|d   |d<   | j	                  | j                  ||            }| j                  ||      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://blog.btcbox.jp/en/archives/8762#toc5

        :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  )r  r   r   r  publicGetTickerr  r8  )r   r   r   r   r  r  r  s          r   fetch_tickerzbtcbox.fetch_ticker  st     	V$&
>$X.GFO''GV(DE  622r   r  c                 h    | j                          | j                  |      }| j                  ||      S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        )r  r   parse_tickers)r   r  r   r  s       r   fetch_tickerszbtcbox.fetch_tickers  s3     	((0!!(G44r   r   c                 B   | j                  |d      }| j                  d |      }| j                  |d      }| j                  |d      }| j                  |d      }d }| j                  |d      }| j                  ||d || j	                  |      |d   ||d ||d d d|      S )Ndatetidr   r   r   r   )r   r   orderr!  r"  r   r   sidetakerOrMakerr   r   r   r   )safe_timestampsafe_marketr   
safe_tradeiso8601)	r   r   r   r!  r   priceStringamountStringr   rC  s	            r   parse_tradezbtcbox.parse_trade  s     ''v6	!!$/eU+&&ug6''x8v."Y/X&  " 
  	r   sincec                     | j                          | j                  |      }i }t        | j                        }|dkD  r|d   |d<   | j	                  | j                  ||            }| j                  ||||      S )a  
        get the list of most recent trades for a particular symbol

        https://blog.btcbox.jp/en/archives/8762#toc7

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r   r   r  )r  r   r   r  publicGetOrdersr  parse_trades)	r   r   rL  r   r   r   r  r  r  s	            r   fetch_tradeszbtcbox.fetch_trades  sz     	V$&
>$X.GFO''GV(DE   65%@@r   r   rC  r   r   c                     | j                          | j                  |      }||||d   d}| j                  | j                  ||            }	| j	                  |	|      S )a  
        create a trade order

        https://blog.btcbox.jp/en/archives/8762#toc18

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   )r   r   r   r  )r  r   privatePostTradeAddr  parse_order)
r   r   r   rC  r   r   r   r   r  r  s
             r   create_orderzbtcbox.create_order  sh     	V$8$	
 ++DKK,HI &11r   r   c                     | j                          |d}| j                  |      }||d   d}| j                  | j                  ||            }| j	                  ||      S )a|  
        cancels an open order

        https://blog.btcbox.jp/en/archives/8762#toc17

        :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>`
        BTC/JPYr   r   r  )r  r   privatePostTradeCancelr  rS  r   r   r   r   r   r  r  s          r   cancel_orderzbtcbox.cancel_order"  sl     	>FV$8$
 ..t{{7F/KL &11r   statusc                 8    dddddd}| j                  |||      S )Nr,  closedcanceled)partall	cancelledr]  no)r   )r   r[  statusess      r   parse_order_statuszbtcbox.parse_order_status<  s1     #
 &&99r   rB  c                 j   | j                  |d      }| j                  |d      }d }|| j                  |d   dz         }| j                  |d      }| j                  |d      }| j                  |d      }| j                  | j                  |d            }	|	t        j                  |d      rd	}	d }
| j                  d |      }| j                  |d
      }| j                  i d|dd d|d| j                  |      dd d|d|dd d|d
d dd dd d|	d|d   d|dd dd |
d |d d|      S )Nr   r"  z+09:00amount_originalamount_outstandingr   r[  0r]  r   clientOrderIdr!  lastTradeTimestampr   	remainingfilledrC  r   postOnlyr   rz   r   )tradesr   r   r1  )r   	parse8601rd  r   string_equalsrF  
safe_orderrH  )r   rB  r   r   datetimeStringr!  r   rk  r   r[  rn  rC  s               r   rS  zbtcbox.parse_orderG  s    eT*))%<	%uZ'88'CDI!!%):;$$U,@A	  0(()9)9%)JK>$$Y4!!!$/v.  
" 
T 
  
 Y/	 

 !$ 
 f 
  
 d 
 D 
 D 
 4 
  
 f 
 fX& 
 U 
  D! 
" D# 
$ + 
, - 	r   c                     | j                          |d}| j                  |      }| j                  ||d   d|      }| j                  | j                  ||            }| j	                  ||      S )a  
        fetches information on an order made by the user

        https://blog.btcbox.jp/en/archives/8762#toc16

        :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>`
        rV  r   rW  )r  r   r  privatePostTradeViewrS  rY  s          r   fetch_orderzbtcbox.fetch_order}  s}     	>FV$++8$
  ,,T[[&-IJ &11r   c                    | j                          | j                  |      }||d   d}| j                  | j                  ||            }| j	                  ||||      }	|dk(  r"t        dt        |	            D ]
  }
d|	|
   d<    |	S )Nr   )r   r  r,  r   r[  )r  r   privatePostTradeListr  parse_ordersr   r   )r   r   r   rL  r   r   r   r  r  rc   r   s              r   fetch_orders_by_typezbtcbox.fetch_orders_by_type  s    V$8$
 ,,T[[&-IJ ""8VUEB 6>1c&k* -&,q	(#-r   c                 ,    | j                  d||||      S )a%  
        fetches information on multiple orders made by the user

        https://blog.btcbox.jp/en/archives/8762#toc15

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r`  ry  r   r   rL  r   r   s        r   fetch_orderszbtcbox.fetch_orders  s     ((ufMMr   c                 ,    | j                  d||||      S )a   
        fetch all unfilled currently open orders

        https://blog.btcbox.jp/en/archives/8762#toc15

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of  open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r,  r{  r|  s        r   fetch_open_orderszbtcbox.fetch_open_orders  s     ((vNNr   c                 "    | j                         S N)milliseconds)r   s    r   noncezbtcbox.nonce  s      ""r   rm   GETc                    | j                   d   d   dz   | j                  z   dz   |z   }|dk(  r|r|d| j                  |      z   z  }n|dk(  r| j                   d   dz   |z   }n| j                          t	        | j                               }| j                  | j                  |d|      }	| j                  |	      }
| j                  | j                  | j                        d	      }| j                  | j                  |
      | j                  |      t        j                        |	d
<   | j                  |	      }ddi}||||dS )Nr]   r[   r   rm   ?ro   r^   )keyr  md5	signaturezContent-Typez!application/x-www-form-urlencoded)urlmethodbodyheaders)r   r   	urlencodecheck_required_credentialsstrr  r  apiKeyhashencodesecrethmachashlibsha256)r   pathr]   r  r   r  r  r  r  queryr  r  s               r   signzbtcbox.sign  s5   iiv&,t||;cADH(?sT^^F333H_))E"S(4/C++-

%EKK{{! E nnU+GYYt{{4;;7?F!%4;;w+?VATV]VdVd!eE+>>%(D CG fdwOOr   httpCodereasonr  r  r  r  c
                     |y |dk\  ry | j                  |d      }
|
|
du ry | j                  |d      }| j                  dz   |z   }| j                  | j                  ||       t	        |      )Ni  r  Tr   )
safe_valuer   throw_exactly_matched_exceptionr   r   )r   r  r  r  r  r  r  r  requestHeadersrequestBodyr  r  feedbacks                r   handle_errorszbtcbox.handle_errors  sv    s?84>Vt^x077S=4',,T__dHMH%%r   c           	          | j                  |||||||      }t        |t              rR| j                  |      }| j	                  |      st        | j                  dz   |z         t        j                  |      }|S )Nr  )	fetch2
isinstancer  stripis_json_encoded_objectr   r   jsonloads)	r   r  r]   r  r   r  r  configr  s	            r   r  zbtcbox.request  sm    ;;tS&&'4Ph$zz(+H..x8#DGGcMH$<==zz(+Hr   r  ).__name__
__module____qualname__r   r   r   r   r   dictr  r   r  r  r  r   r   r  r   r8  r;  r   r   r>  r   rK  rP  r   r   floatr	   rT  r   rZ  rd  r
   rS  ru  ry  r}  r  r  r  intr  r  __classcell__)r   s   @r   r   r      s   s# sj $& M$v, M^7
4 7
F 7
r) )  $& ,( , :>b As A3 AY A(4  6 4 02 33 3f 3& 04B 	5W 	57 	5! !v ! !F 6:UW A3 As A# A\`af\g A@ gksu 23 2i 2y 2RW 2`c 2> 37r 2s 2C 24	: 	:4 4v 4 4l 26b !2c !23 !2F 8<$]ajl  C WZ : *.Dt\^ N3 Nc N Ncghmcn N /3TXac O O3 Oc Ohlmrhs O# &eBSW P.&c &3 &S &# &X\ &dg & !)r4VZce r   r   )%ccxt.base.exchanger   ccxt.abstract.btcboxr   r  r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   r   r   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r    r   r   <module>r     s\    ( ,   J  J  J  J  * 0 - . ) * + ) 4 %qX{ qr   