
    i[                        d dl mZ d dlmZ d dlZd dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZ 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!dS )    )Exchange)ImplicitAPIN)BalancesIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrTickerTrade)List)ExchangeError)AuthenticationError)PermissionDenied)InsufficientFunds)InvalidOrder)OrderNotFound)DDoSProtection)InvalidNonce)	TICK_SIZE)Precisec                       e Zd Z 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
d"d	edefd
Zi fdedefdZd"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 Zd"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  Z#ddi ddi fd!Z$ xZ%S )#btcboxc                    |                      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=id>d?d@dAdBg dCidDg dEidF|                     dGdHdIdJdGdK|                     dL          |                     dL          dd	dM
          |                     dNdOdPdJdNdK|                     dQ          |                     dQ          dd	dM
          |                     dRdSdTdJdRdK|                     dQ          |                     dQ          dd	dM
          |                     dUdVdWdJdUdK|                     dQ          |                     dQ          dd	dM
          dXt          t          t          t          t          t          t          t          t          t          t          dY
dZ          S )[Nr   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fetchPositionModefetchPositionsfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTransferfetchTransfersfetchWithdrawalfetchWithdrawalsreduceMarginsetLeveragesetMarginModesetPositionModetransferwithdrawwszdhttps://user-images.githubusercontent.com/51840849/87327317-98c55400-c53c-11ea-9a11-81f7d951cc74.jpg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post)balance	trade_addtrade_cancel
trade_list
trade_viewwallet)publicprivatebtcBTC/JPYBTCJPYjpyz0.0005)
idsymbolbasequotebaseIdquoteIdtakermakertyper"   ethETH/JPYETHz0.0010ltcLTC/JPYLTCbchBCH/JPYBCH)rh   rv   ry   r|   )
104105106107200201202203401402)rl   name	countries	rateLimitversionprohasurlsrV   marketsprecisionMode
exceptions)deep_extendsuperr   describesafe_market_structureparse_numberr   r   r   r   r   r   r   r   )self	__class__s    _/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/async_support/btcbox.pyr   zbtcbox.describe   s   fd 3 3 < < > >444 %4 	4
 %4 %4 U4 t4 $U4  4 t4 (4 4 +E4 )%4  '!4" (#4 4$ &u%4& #E'4( *5)4* $U+4, "5-4. *5/40 +E142  344 "5546 !%748 +E94: "4;4< d=4> !$?4@ tA4B  C4D $UE4 4 4F !%G4H %eI4J )%K4L tM4N O4P tQ4R  S4T !%U4V "5W4X #EY4Z [4\ u]4^  _4` "5a4b Ec4d Ee4f eg4 4l : 3@g         	 (  55Uiafqv  CH  UZ  ei  ev  ev  w  e@  e@  KO  K\  K\  ]e  Kf  Kf  pv  @D  7E  7E  F  F55Uiafqv  CH  UZ  ei  ev  ev  w  e@  e@  KO  K\  K\  ]e  Kf  Kf  pv  @D  7E  7E  F  F55Uiafqv  CH  UZ  ei  ev  ev  w  e@  e@  KO  K\  K\  ]e  Kf  Kf  pv  @D  7E  7E  F  F55Uiafqv  CH  UZ  ei  ev  ev  w  e@  e@  KO  K\  K\  ]e  Kf  Kf  pv  @D  7E  7E  F  F	  '*'##(##$$% kA
 kA
 k k k	    returnc                    d|i}t          | j                                                  }t          dt	          |                    D ]}||         }|                     |          }|d         }|dz   }||v rP|                                 }	|dz   }
|                     ||          |	d<   |                     ||
          |	d<   |	||<   |                     |          S )Ninfor   rl   _balance_lockfreeused)	list
currencieskeysrangelencurrencyaccountsafe_stringsafe_balance)r   responseresultcodesicoder   
currencyIdr   r   r   s              r   parse_balancezbtcbox.parse_balance   s    (#T_))++,,q#e**%% 
	' 
	'A8D}}T**H!$J
*Dx,,..!G+"&"2"28T"B"B"&"2"28T"B"B&t  (((r   c                    K   |                                   d{V  |                     |           d{V }|                     |          S )a]  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: 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   paramsr   s      r   fetch_balancezbtcbox.fetch_balance   se       !!!!!!!!!0088888888!!(+++r   Nrm   limitc                 H  K   |                                   d{V  |                     |          }i }t          | j                  }|dk    r|d         |d<   |                     |                     ||                     d{V }|                     ||d                   S )a.  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: 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
        N   rp   coinrm   )r   marketr   symbolspublicGetDepthextendparse_order_book)r   rm   r   r   r   request
numSymbolsr   s           r   fetch_order_bookzbtcbox.fetch_order_book   s       !!!!!!!!!V$$&&
>>$X.GFO,,T[[&-I-IJJJJJJJJ$$Xvh/?@@@r   r   c                    |                      d |          }|                     |d          }|                     i d|dd dd d|                     |d          d|                     |d          d|                     |d          d	d d
|                     |d          dd dd dd d|d|dd dd dd dd |                     |d          |                     |d          |d|          S )Nlastrm   	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   r]   r   rm   r   s        r   parse_tickerzbtcbox.parse_ticker   s   !!$//// !
f!
!
 !
 D$$VV44	!

 4##FE22!
 4##FE22!
 !
 4##FF33!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **6599++FH==)!
 !
 !
* +  	r   c                 <  K   |                                   d{V  |                     |          }i }t          | j                  }|dk    r|d         |d<   |                     |                     ||                     d{V }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: 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   rp   r   )r   r   r   r   publicGetTickerr   r   )r   rm   r   r   r   r   r   s          r   fetch_tickerzbtcbox.fetch_ticker   s       !!!!!!!!!V$$&&
>>$X.GFO--dkk'6.J.JKKKKKKKK  6222r   c                    |                      |d          }|                     d |          }|                     |d          }|                     |d          }|                     |d          }d }|                     |d          }|                     ||d ||                     |          |d         ||d ||d d d|          S )Ndatetidpriceamountrt   rm   )r   rl   orderr   r   rm   rt   sidetakerOrMakerr   r   costfee)safe_timestampsafe_marketr   
safe_tradeiso8601)	r   trader   r   rl   priceStringamountStringrt   r   s	            r   parse_tradezbtcbox.parse_trade   s     ''v66	!!$//eU++&&ug66''x88v.."Y//X&  " 
  
   	r   sincec                 @  K   |                                   d{V  |                     |          }i }t          | j                  }|dk    r|d         |d<   |                     |                     ||                     d{V }|                     ||||          S )a  
        get the list of most recent trades for a particular symbol
        :see: 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   rp   r   )r   r   r   r   publicGetOrdersr   parse_trades)	r   rm   r   r   r   r   r   r   r   s	            r   fetch_tradeszbtcbox.fetch_trades  s       !!!!!!!!!V$$&&
>>$X.GFO--dkk'6.J.JKKKKKKKK   65%@@@r   rt   r   r   r   c                   K   |                                   d{V  |                     |          }||||d         d}|                     |                     ||                     d{V }	|                     |	|          S )a  
        create a trade order
        :see: 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 fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nrp   )r   r   rt   r   )r   r   privatePostTradeAddr   parse_order)
r   rm   rt   r   r   r   r   r   r   r   s
             r   create_orderzbtcbox.create_order!  s       !!!!!!!!!V$$8$	
 
 11$++gv2N2NOOOOOOOO &111r   rl   c                   K   |                                   d{V  |d}|                     |          }||d         d}|                     |                     ||                     d{V }|                     ||          S )a  
        cancels an open order
        :see: 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>`
        Nrh   rp   rl   r   )r   r   privatePostTradeCancelr   r   r   rl   rm   r   r   r   r   s          r   cancel_orderzbtcbox.cancel_order>  s       !!!!!!!!!>FV$$8$
 
 44T[[&5Q5QRRRRRRRR &111r   c                 @    dddddd}|                      |||          S )Nr   closedcanceled)partall	cancelledr  no)r   )r   statusstatusess      r   parse_order_statuszbtcbox.parse_order_statusV  s9     #
 
 &&999r   c           	         |                      |d          }|                      |d          }d }||                     |d         dz             }|                      |d          }|                      |d          }|                      |d          }|                     |                      |d                    }	|	t          j        |d          r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|          S )Nrl   r   z+09:00amount_originalamount_outstandingr   r  0r  rt   clientOrderIdr   lastTradeTimestampr   	remainingfilledr   timeInForcepostOnlyrm   	stopPricetriggerPrice)r   tradesr   r   r   )r   	parse8601r	  r   string_equalsr   
safe_orderr   )r   r   r   rl   datetimeStringr   r   r  r   r  r  r   s               r   r   zbtcbox.parse_ordera  s    eT**))%<<	%uZ'88'CDDI!!%):;;$$U,@AA	  00(()9)9%)J)JKK>$Y44 "!!!$//v..  
" 
T 
  
 Y//	 

 !$ 
 f 
  
 d 
 D 
 D 
 4 
  
 f 
 fX& 
 U 
  ! 
" D# 
$ - 
  
  
. /  	r   c                 4  K   |                                   d{V  |d}|                     |          }|                     ||d         d|          }|                     |                     ||                     d{V }|                     ||          S )a{  
        fetches information on an order made by the user
        :see: https://blog.btcbox.jp/en/archives/8762#toc16
        :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>`
        Nrh   rp   r   )r   r   r   privatePostTradeViewr   r   s          r   fetch_orderzbtcbox.fetch_order  s       !!!!!!!!!>FV$$++8$
 
   224;;w3O3OPPPPPPPP &111r   c                 v  K   |                                   d {V  |d}|                     |          }||d         d}|                     |                     ||                     d {V }|                     ||||          }	|dk    r+t          dt          |	                    D ]}
d|	|
         d<   |	S )Nrh   rp   )rt   r   r   r   r  )r   r   privatePostTradeListr   parse_ordersr   r   )r   rt   rm   r   r   r   r   r   r   r\   r   s              r   fetch_orders_by_typezbtcbox.fetch_orders_by_type  s      !!!!!!!!!>FV$$8$
 
 224;;w3O3OPPPPPPPP ""8VUEBB 6>>1c&kk** - -&,q	(##r   c                 D   K   |                      d||||           d{V S )a)  
        fetches information on multiple orders made by the user
        :see: 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  Nr!  r   rm   r   r   r   s        r   fetch_orderszbtcbox.fetch_orders  s6       ..ufeUFSSSSSSSSSr   c                 D   K   |                      d||||           d{V S )a  
        fetch all unfilled currently open orders
        :see: 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  s6       ..vvueVTTTTTTTTTr   c                 *    |                                  S N)milliseconds)r   s    r   noncezbtcbox.nonce  s      """r   re   GETc                    | j         d         d         dz   | j        z   dz   |z   }|dk    r|r|d|                     |          z   z  }n|                                  t	          |                                           }|                     | j        |d|          }	|                     |	          }
|                     | 	                    | j
                  d          }|                     | 	                    |
          | 	                    |          t          j                  |	d<   |                     |	          }d	d
i}||||dS )NrV   rT   /re   ?)keyr+  sha256	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hashlibr1  )r   pathrV   r4  r   r6  r5  r3  r+  queryr   r=  s               r   signzbtcbox.sign  sC   iv&,t|;cADH(?? 4sT^^F3333++---

%%EKK{! !  E nnU++GYYt{{4;77BBF!%4;;w+?+?VATATV]Vd!e!eE+>>%((D CG fdwOOOr   c
                     |d S |dk    rd S |                      |d          }
|
|
du rd S |                      |d          }| j        dz   |z   }|                     | j        ||           t	          |          )Ni  r   Tr    )
safe_valuerl   throw_exactly_matched_exceptionr   r   )r   httpCodereasonr3  r4  r6  r5  r   requestHeadersrequestBodyr   r   feedbacks                r   handle_errorszbtcbox.handle_errors  s    4s??4844>Vt^^4x007S=4',,T_dHMMMH%%%r   c           	      &  K   |                      |||||||           d {V }t          |t                    rX|                     |          }|                     |          st          | j        dz   |z             t          j        |          }|S )NrD  )	fetch2
isinstancer9  stripis_json_encoded_objectr   rl   jsonloads)	r   r@  rV   r4  r   r6  r5  configr   s	            r   r   zbtcbox.request  s      T3vVVVVVVVVh$$ 	,zz(++H..x88 >#DGcMH$<===z(++Hr   r)  )&__name__
__module____qualname__r   r   r   r   r9  r   r
   r   r   r   r   r   r   r   r   r   r   r   floatr   r   r   r   r	  r	   r   r  r!  r%  r'  r+  rB  rL  r   __classcell__)r   s   @r   r   r      s       l l l l l\) ) ) ) )  *, 	, 	, 	, 	, 	, 	, @DB A AS A AS\ A A A A$ 6 V    4 68 3 3 3F 3 3 3 3"! ! !5 ! ! ! !F <@d[] A A AS A Abfglbm A A A A< mqy{ 2 2 2I 2Y 2X] 2fi 2 2 2 2: 9=R 2 2S 2# 2 2 2 20	: 	: 	:5 5 55 5 5 5 5n 8<B 2 2C 2 2 2 2 2@ >BPTcgpr  s # ]`    > 04$UYbd 
T 
T 
TC 
Ts 
Timnsit 
T 
T 
T 
T 59tZ^gi 
U 
Uc 
U 
UTW 
Unrsxny 
U 
U 
U 
U# # # &eBSW P P P P*& & & '/uRQU\`ik        r   r   )" ccxt.async_support.base.exchanger   ccxt.abstract.btcboxr   r?  rR  ccxt.base.typesr   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>rb     s   6 5 5 5 5 5 , , , , , ,   r r r r r r r r r r r r r r r r r r r r r r r r r r       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . ) ) ) ) ) ) * * * * * * + + + + + + ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %E E E E EX{ E E E E Er   