
    !:hz                        d dl mZ d dlmZ d dl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    S/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/async_support/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                   K   | j                         }| j                  ddd      }t        j                  ||g  d{   \  }}| 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 7 w)'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   webApiGetAjaxCoinCoinInfoTNdatar   _   /BTCz0.0005z0.0010trader   uppercaseId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asynciogather	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\]%,^^h5I%JJ	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?	@ K  Ks   ;H G=G H 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_balanceX  s    )T__))+,q#e*% 
	'A8D}}T*H!$J
*Dx,,.!G+"&"2"28T"B"&"2"28T"B&t
	'   ((r   c                    K   | j                          d{    | j                  |       d{   }| j                  |      S 7 .7 w)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>`
        N)load_marketsprivatePostBalancer  )r   r   r  s      r   fetch_balancezbtcbox.fetch_balanceh  sG      !!!0088!!(++ 	"8s   A	AA	AA	A	Nr   r   c                 (  K   | j                          d{    | j                  |      }i }t        | j                        }|dkD  r|d   |d<   | j	                  | j                  ||             d{   }| j                  ||d         S 7 w7 w)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
        Nr   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_booku  s      !!!V$&
>$X.GFO,,T[[&-IJJ$$Xvh/?@@ 	" Ks"   BBAB4B5BB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                 "  K   | j                          d{    | j                  |      }i }t        | j                        }|dkD  r|d   |d<   | j	                  | j                  ||             d{   }| j                  ||      S 7 t7 w)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>`
        Nr   r   r  )r  r   r   r  publicGetTickerr  r:  )r   r   r   r   r  r  r  s          r   fetch_tickerzbtcbox.fetch_ticker  s      !!!V$&
>$X.GFO--dkk'6.JKK  622 	" Ls"   BBAB4B5BBr  c                    K   | j                          d{    | j                  |       d{   }| j                  ||      S 7 /7 w)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>`
        N)r  r   parse_tickers)r   r  r   r  s       r   fetch_tickerszbtcbox.fetch_tickers  sI      !!!..v66!!(G44 	"6s   A
AA
AA
A
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   rE  s	            r   parse_tradezbtcbox.parse_trade  s     ''v6	!!$/eU+&&ug6''x8v."Y/X&  " 
  	r   sincec                 &  K   | j                          d{    | j                  |      }i }t        | j                        }|dkD  r|d   |d<   | j	                  | j                  ||             d{   }| j                  ||||      S 7 v7 w)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>`
        Nr   r   r  )r  r   r   r  publicGetOrdersr  parse_trades)	r   r   rN  r   r   r   r  r  r  s	            r   fetch_tradeszbtcbox.fetch_trades  s      !!!V$&
>$X.GFO--dkk'6.JKK   65%@@% 	" Ls"   BBAB4B5BBr   rE  r   r   c                    K   | j                          d{    | j                  |      }||||d   d}| j                  | j                  ||             d{   }	| j	                  |	|      S 7 Z7 w)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>`
        Nr   )r   r   r   r  )r  r   privatePostTradeAddr  parse_order)
r   r   r   rE  r   r   r   r   r  r  s
             r   create_orderzbtcbox.create_order  s      !!!V$8$	
 11$++gv2NOO &11 	" Ps"   A5A1AA5A3A53A5r   c                    K   | j                          d{    |d}| j                  |      }||d   d}| j                  | j                  ||             d{   }| j	                  ||      S 7 \7 w)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>`
        NBTC/JPYr   r   r  )r  r   privatePostTradeCancelr  rU  r   r   r   r   r   r  r  s          r   cancel_orderzbtcbox.cancel_order#  s      !!!>FV$8$
 44T[[&5QRR &11 	" Ss"   A7A3AA7A5A75A7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   rD  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filledrE  r   postOnlyr   rz   r   )tradesr   r   r3  )r   	parse8601rf  r   string_equalsrH  
safe_orderrJ  )r   rD  r   r   datetimeStringr#  r   rm  r   r]  rp  rE  s               r   rU  zbtcbox.parse_orderH  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                   K   | j                          d{    |d}| j                  |      }| j                  ||d   d|      }| j                  | j                  ||             d{   }| j	                  ||      S 7 l7 w)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>`
        NrX  r   rY  )r  r   r  privatePostTradeViewrU  r[  s          r   fetch_orderzbtcbox.fetch_order~  s      !!!>FV$++8$
  224;;w3OPP &11- 	" Qs"   BBAB,B-BBc                 @  K   | j                          d {    | j                  |      }||d   d}| j                  | j                  ||             d {   }| j	                  ||||      }	|dk(  r"t        dt        |	            D ]
  }
d|	|
   d<    |	S 7 7 Cw)Nr   )r   r  r.  r   r]  )r  r   privatePostTradeListr  parse_ordersr   r   )r   r   r   rN  r   r   r   r  r  rc   r   s              r   fetch_orders_by_typezbtcbox.fetch_orders_by_type  s     !!!V$8$
 224;;w3OPP ""8VUEB 6>1c&k* -&,q	(#-5 	" Qs#   BBABBABBc                 H   K   | j                  d||||       d{   S 7 w)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>`
        rb  Nr{  r   r   rN  r   r   s        r   fetch_orderszbtcbox.fetch_orders  s'      ..ufeUFSSSS   " "c                 H   K   | j                  d||||       d{   S 7 w)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.  Nr}  r~  s        r   fetch_open_orderszbtcbox.fetch_open_orders  s'      ..vvueVTTTTr  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           	        K   | j                  |||||||       d {   }t        |t              rR| j                  |      }| j	                  |      st        | j                  dz   |z         t        j                  |      }|S 7 hw)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  sz     T3vVVh$zz(+H..x8#DGGcMH$<==zz(+H Ws   BBA)Br  ).__name__
__module____qualname__r   r   r   r   r   dictr  r   r  r  r  r   r   r   r   r:  r=  r   r   r@  r   rM  rR  r   r   floatr	   rV  r   r\  rf  r
   rU  rw  r{  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) )  *, , , @DB AS A AS\ A(4  6 4 68 3 3F 3& 6:" 	57 	5 	5! !v ! !F <@d[] A AS A Abfglbm A@ mqy{ 2 2I 2Y 2X] 2fi 2> 9=R 2S 2# 24	: 	:4 4v 4 4l 8<B !2C !2 !2F >BPTcgpr s # ]` : 04$UYbd T TC Ts Timnsit T 59tZ^gi Uc U UTW Unrsxny U# &eBSW P.&c &3 &S &# &X\ &dg & '/uRQU\`ik r   r   )& ccxt.async_support.base.exchanger   ccxt.abstract.btcboxr   r   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_    6 ,    J  J  J  J  * 0 - . ) * + ) 4 %qX{ qr   