
    !:h{                         d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZ 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CurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrTickerTradeTradingFeesTransaction)List)ExchangeError)AuthenticationError)	BadSymbol)	TICK_SIZEc                       e Zd Zdef fdZdefdZi fdefdZdddi fdede	de	de
e   fd	Zd0d
ede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d0dededefdZdddi fdede	de	fdZddi fdede	de	de
e   fdZi fdefdZ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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 efd!Z%d0d"ed#e&d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+ xZ,S )1	coincheckreturnc                    | j                  t        t        |          ddddg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	d/dd0dd1d	d2dd3dd4d	d5d	d6d	d7d	d8dd9d:d;id<d=d>d?gd@dAg dBig dCg dDg dEdFdG| j	                  dHdIdJdKdLdMdddN      | j	                  dOdPdQdKdRdMdddN      | j	                  dSdTdUdKdVdMdddN      | j	                  dWdXdYdKdZdMdddN      | j	                  d[d\dQdJdRdLdddN      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	dad d d db	d d dcd d dcddded	d| j                  df      | j                  df      dgit        t        t        dhi didj      S )kNr   JPIDi  CORSspotTmarginFswapfutureoption	addMargincancelOrdercloseAllPositionsclosePositioncreateOrdercreateReduceOnlyOrderfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchDepositsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchMarginModefetchMarkOHLCVfetchMyTradesfetchOpenInterestHistoryfetchOpenOrdersfetchOrderBookfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTradesfetchTradingFeefetchTradingFeesfetchWithdrawalsreduceMarginsetLeveragesetMarginModesetPositionModewszdhttps://user-images.githubusercontent.com/51840849/87182088-1d6d6380-c2ec-11ea-9c64-8ab9f9b289f5.jpgrestzhttps://coincheck.com/apizhttps://coincheck.comz,https://coincheck.com/documents/exchange/apiz"https://coincheck.com/exchange/feezhttps://coincheck.com/info/fee)logoapiwwwdocfeesget)zexchange/orders/rateorder_bookszrate/{pair}tickertrades)accountszaccounts/balancezaccounts/leverage_balancebank_accountsdeposit_moneyzexchange/orders/openszexchange/orders/transactionsz'exchange/orders/transactions_paginationzexchange/leverage/positionszlending/borrows/matches
send_money	withdraws)	r\   zdeposit_money/{id}/fastzexchange/orderszexchange/transfers/to_leveragez exchange/transfers/from_leveragezlending/borrowszlending/borrows/{id}/repayr^   r_   )zbank_accounts/{id}zexchange/orders/{id}zwithdraws/{id})rW   postdelete)publicprivatebtc_jpyBTC/JPYBTCJPYbtcjpy)idsymbolbasequotebaseIdquoteIdtyper    etc_jpyETC/JPYETCetcfct_jpyFCT/JPYFCTfctmona_jpyMONA/JPYMONAmonaetc_btcETC/BTC)re   rr   rv   rz   r~   )IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventioniceberg)r   limitdaysBack	untilDayssymbolRequired)r   r   triggerr   r   )	sandboxr)   createOrdersr;   
fetchOrderr=   fetchOrdersfetchClosedOrders
fetchOHLCV)linearinverse)r    r"   r#   trading0)	tierBased
percentagemakertaker)zdisabled API Keyzinvalid authentication)exactbroad)rj   name	countries	rateLimithasurlsrS   marketsfeaturesrV   precisionMode
exceptions)deep_extendsuperr   describesafe_market_structureparse_numberr   r   )self	__class__s    H/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/coincheck.pyr   zcoincheck.describe   s>   i ? A333 %3 	3
 %3 %3 U3 t3 $U3  3 t3 (3 3 +E3 )%3  '!3" (#3$  %3& &u'3( #E)3* *5+3, $U-3. "5/30 *5132 +E334  536 "5738 !%93:  ;3< +E=3> "4?3@ !$A3B  C3D 'E3F $UG3H !%I3J *5K3L (M3N %eO3P )%Q3R tS3T tU3V "5W3X #DY3Z #D[3\ ]3^ u_3`  a3b "5c3d de3j 7 /E84  
5*X  55YR[ejuz  GL  Y^  hn  x|  7}  ~55YR[ejuz  GL  Y^  hn  x|  7}  ~  55YR[ejuz  GL  Y^  hn  x|  7}  ~ 66jT^hny~  KQ  ^c  ms  }A  8B  C  55YR[ejuz  GL  Y^  hn  x|  7}  ~!:  %&+(-,0,1).+06:#(#("&#(	( #($)$)+027/4#()$, %)&+!%$(%)*.& #'&+!%#($)*/( $()-"&U+Z ##
 ##c5n !&"&!..s3!..s3	 ' )<.A UQD
 Q Q	    c                 n   d|i}t        | j                  j                               }t        dt	        |            D ]f  }||   }| j                  |      }|d   }||v s#| j                         }|dz   }	| j                  ||      |d<   | j                  ||	      |d<   |||<   h | j                  |      S )Ninfor   rj   	_reservedfreeused)	list
currencieskeysrangelencurrencyaccountsafe_stringsafe_balance)
r   responseresultcodesicoder   
currencyIdr   reserveds
             r   parse_balancezcoincheck.parse_balance   s    )T__))+,q#e*% 		'A8D}}T*H!$JX%,,.%3"&"2"28Z"H"&"2"28X"F&t		'   ((r   c                 f    | j                          | j                  |      }| j                  |      S )av  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://coincheck.com/documents/exchange/api#order-transactions-pagination

        :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privateGetAccountsBalancer   )r   paramsr   s      r   fetch_balancezcoincheck.fetch_balance   s1     	11&9!!(++r   Nrk   sincer   c                 D   | j                          d}|| j                  |      }| j                  |      }| j                  |dg       }| j	                  ||||      }g }	t        dt        |            D ](  }
|	j                  | j                  ||
   ddi             * |	S )a  
        fetch all unfilled currently open orders

        https://coincheck.com/documents/exchange/api#order-opens

        :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>`
        Nordersr   statusopen)	r   marketprivateGetExchangeOrdersOpens
safe_valueparse_ordersr   r   appendextend)r   rk   r   r   r   r   r   	rawOrdersparsedOrdersr   r   s              r   fetch_open_orderszcoincheck.fetch_open_orders  s     	[[(F55f=OOHh;	((FE5Iq#l+, 	LAMM$++l1o&7IJK	Lr   orderr   c                    | j                  |d      }| j                  |d      }| j                  | j                  |d            }| j                  |d      }| j                  |d      }| j                  |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 )Nrj   
order_type
created_atpending_amountratepair_clientOrderId	timestampdatetimelastTradeTimestampamount	remainingfilledsiderp   r   postOnlyr   rk   pricer   cost)feer   averagerZ   )r   	parse8601safe_symbol
safe_orderiso8601)r   r   r   rj   r   r   r   r   r   r   marketIdrk   s               r   parse_orderzcoincheck.parse_order  s    eT*|4NN4#3#3E<#HI	!!%)9:$$U,<=	  /##E62!!(FC8  
" 
T 
  
 Y/	 

 !$ 
 f 
  
 d 
 D 
 D 
 4 
  
 f 
 f 
 U 
  D! 
" D# 
$ + 
, - 	r   c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  ||d         S )a5  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://coincheck.com/documents/exchange/api#order-book

        :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   rj   rk   )r   r   publicGetOrderBooksr   parse_order_book)r   rk   r   r   r   requestr   s          r   fetch_order_bookzcoincheck.fetch_order_bookL  sc     	V$F4L
 ++DKK,HI$$Xvh/?@@r   rY   c                    | j                  d |      }| j                  |d      }| j                  |d      }| j                  i d|d|d| j	                  |      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      d |d|      S )Nr   lastrk   r   highlowbid	bidVolumeask	askVolumevwapr   closepreviousClosechanger   r   volume)
baseVolumequoteVolumer   )r   safe_timestampr   safe_tickerr   )r   rY   r   rk   r   r  s         r   parse_tickerzcoincheck.parse_ticker_  sy    !!$/''<	/ !
f!
!
 Y/!
 D$$VV4	!

 4##FE2!
 4##FE2!
 !
 4##FE2!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **68<)!
* + 	r   c                     |dk7  rt        | j                  dz         | j                          | j                  |      }d|d   i}| 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://coincheck.com/documents/exchange/api#ticker

        :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>`
        re   z$ fetchTicker() supports BTC/JPY onlyr   rj   )r   rj   r   r   publicGetTickerr   r  )r   rk   r   r   r   rY   s         r   fetch_tickerzcoincheck.fetch_ticker  s}     YDGG&LLMMV$F4L
 %%dkk'6&BC   00r   tradec                    | j                  | j                  |d            }| j                  |d      }| j                  |d      }| j                  |d      }| j                  ||d      }|d   }|d   }|d   }	d }
d }d }d }d }d }d	|v r| j                  |d	      d
k(  rd}
n| j                  |d	      dk(  rd}
| j                  |di       }| j                  ||      }| j                  ||      }| j                  |d      | j                  |d      d}| j                  |d      }| j                  |d      }n$| j                  |d      }| j                  |d      }| j	                  ||| j                  |      ||	d |||
||||d|      S )Nr   rj   r   r   r   rn   ro   rk   	liquidityTr   Mr   fundsfee_currencyr   )r   r   r   order_idr   r   )rj   r   r   r   rk   rp   r   r   takerOrMakerr   r   r   r   )r   r   safe_marketr   
safe_trader   )r   r  r   r   rj   priceStringr   rn   ro   rk   r  amountString
costStringr   r   orderIdr  s                    r   parse_tradezcoincheck.parse_trade  s   > NN4#3#3E<#HI	eT*&&uf5##E62!!(FC8!#!
%{3s:&!!%5<&OOE7B7E++E6:L))%9J ,,UNC((6C ##E62D&&uj9G++E8<L##E<8DY/"( " 
  	r   c                     | j                          | j                  |      }i }|||d<   | j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )a  
        fetch all trades made by the user

        https://coincheck.com/documents/exchange/api#order-transactions-pagination

        :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>`
        r   data)r   r   .privateGetExchangeOrdersTransactionsPaginationr   	safe_listparse_trades)	r   rk   r   r   r   r   r   r   transactionss	            r   fetch_my_tradeszcoincheck.fetch_my_trades  s{     	V$$GGFFt{{SZ\bGcd. ~~h;  vueDDr   c                     | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )a"  
        get the list of most recent trades for a particular symbol

        https://coincheck.com/documents/exchange/api#public-trades

        :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   rj   r   r(  )r   r   publicGetTradesr   r*  r+  )	r   rk   r   r   r   r   r   r   r(  s	            r   fetch_tradeszcoincheck.fetch_trades  s     	V$F4L
 $GG''GV(DE ~~h3  vue<<r   c                 ~   | j                          | j                  |      }| j                  |di       }i }t        dt	        | j
                              D ]d  }| j
                  |   }| j                  |      }| j                  ||d   i       }||| j                  |d      | j                  |d      ddd||<   f |S )	aT  
        fetch the trading fees for multiple markets

        https://coincheck.com/documents/exchange/api#account-info

        :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
        exchange_feesr   rj   	maker_fee	taker_feeTF)r   rk   r   r   r   r   )r   privateGetAccountsr   r   r   symbolsr   safe_number)	r   r   r   rV   r   r   rk   r   r   s	            r   fetch_trading_feeszcoincheck.fetch_trading_fees>  s     	**62( x"=q#dll+, 	A\\!_F[[(F//$tb9C ))#{;))#{;""F6N		 r   rp   r   r   r   c                 N   | j                          | j                  |      }d|d   i}|dk(  r"|dz   |z   }	|	|d<   |dk(  r|	dz   nd}
|||
dz   <   n||d<   ||d	<   ||d<   | j                  | j                  ||            }| j	                  |d      }| j                  ||d
|      S )a  
        create a trade order

        https://coincheck.com/documents/exchange/api#order-new

        :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   rj   r   r   r   buy r   r   )rj   r   )r   r   privatePostExchangeOrdersr   r   r   )r   rk   rp   r   r   r   r   r   r   r   prefixr   rj   s                r   create_orderzcoincheck.create_orderl  s     	V$F4L
 8d*J$.GL!,0EMj3&F)/GFX%&$(GL!#GFO &GH11$++gv2NOh- 
  	r   rj   c                 n    d|i}| j                  | j                  ||            }| j                  |      S )ay  
        cancels an open order

        https://coincheck.com/documents/exchange/api#order-cancel

        :param str id: order id
        :param str symbol: not used by coincheck cancelOrder()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rj   )privateDeleteExchangeOrdersIdr   r   )r   rj   rk   r   r   r   s         r   cancel_orderzcoincheck.cancel_order  s@     "
 55dkk'66RS ))r   r   c                    | j                          d}i }|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||            }| j	                  |dg       }| j                  ||||ddi      S )a  
        fetch all deposits made to an account

        https://coincheck.com/documents/exchange/api#account-deposits

        :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>`
        Nrj   r   r   depositsrp   deposit)r   r   privateGetDepositMoneyr   r*  parse_transactions	r   r   r   r   r   r   r   r   r(  s	            r   fetch_depositszcoincheck.fetch_deposits  s     	}}T*H"*4.GJ$GG..t{{7F/KL0 ~~h
B7&&tXuefiEXYYr   c                     | j                          d}|| j                  |      }i }|||d<   | j                  | j                  ||            }| j	                  |dg       }| j                  ||||ddi      S )a  
        fetch all withdrawals made from an account

        https://coincheck.com/documents/exchange/api#withdraws

        :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>`
        Nr   r(  rp   
withdrawal)r   r   privateGetWithdrawsr   r*  rF  rG  s	            r   fetch_withdrawalszcoincheck.fetch_withdrawals  s     	}}T*H$GG++DKK,HI, ~~h3&&tXueflE[\\r   r   c                 :    ddddddd}| j                  |||      S )Npendingokcanceled)rN  
processingfinishedrP  	confirmedreceived)r   )r   r   statusess      r   parse_transaction_statusz"coincheck.parse_transaction_status  s4     !#""	
 &&99r   transactionr   c                 F   | j                  |d      }| j                  | j                  |d            }| j                  |d      }| j                  |d      }| j                  |d      }| j                  ||      }| j	                  | j                  |d            }	| j                  | j                  |d            }
d }| j                  |d      }|||d	}i d
|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S )Nrj   r   addressr   r   r   confirmed_atr   )r   r   r   txidr   r   network	addressToaddressFromtagtagTotagFromrp   updated)commentinternalr   )r   r   r7  safe_currency_coderV  r   )r   rW  r   rj   r   rY  r   r   r   r   rb  r   feeCosts                r   parse_transactionzcoincheck.parse_transaction  s   6 k40NN4#3#3K#NO	"";	:!!+x8%%k:>
&&z8<..t/?/?X/VW..!1!1+~!NO"";6 C
K
"
 D
 	

 Y/
 t
 w
 
 4
 4
 T
 t
 D
 f
 
  f!
" w#
$ )
 	
r   c                 "    | j                         S N)milliseconds)r   s    r   noncezcoincheck.nonceO  s      ""r   rb   GETc           	         | j                   d   d   dz   | j                  ||      z   }| j                  || j                  |            }|dk(  r|r|d| j	                  |      z   z  }n| j                          t        | j                               }	d}
|dk(  r)|rK|d| j	                  | j                  |            z   z  }n$|r"| j	                  | j                  |            }|}
|	|z   |
z   }d| j                  |	| j                  | j                  |      | j                  | j                        t        j                        d	}||||d
S )NrS   rQ   /rb   ?r;  rl  z!application/x-www-form-urlencoded)zContent-Typez
ACCESS-KEYzACCESS-NONCEzACCESS-SIGNATURE)urlmethodbodyheaders)r   implode_paramsomitextract_params	urlencodecheck_required_credentialsstrrk  keysortapiKeyhmacencodesecrethashlibsha256)r   pathrS   rq  r   rs  rr  rp  queryrk  queryStringauths               r   signzcoincheck.signR  s4   iiv&,t/B/B4/PP		&$"5"5d";<(?sT^^E222++-

%EK3U0C!DDDC>>$,,u*=>D"&K3;,D C"kk %$(IIdkk$.?T[[AY[b[i[i$j	G fdwOOr   httpCodereasonrp  rq  rs  rr  c
                 n   |y | j                  |dd      }
|
s| j                  |d      }| j                  dz   | j                  |      z   }| j	                  | j
                  d   ||       | j                  | j
                  d   ||       t        | j                  dz   | j                  |      z         y )NsuccessTerror r   r   )	safe_boolr   rj   jsonthrow_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r   r  r  rp  rq  rs  rr  r   requestHeadersrequestBodyr  r  feedbacks                r   handle_errorszcoincheck.handle_errorsl  s    
 ..9d;$$Xw7Eww}tyy'::H001I5RZ[001I4QYZ#		(0C CDDr   ri  )-__name__
__module____qualname__r   r   r   r   r   r   r   r   r   r   dictr	   r   ry  r   r  r   r  r  r   r&  r-  r0  r   r8  r   r   floatr
   r>  rA  r   rH  rL  rV  r   rg  rk  r  intr  __classcell__)r   s   @r   r   r      s   R# Rh) ) $& ,( , /3TXac  3 c hlmrhs 2. .v . .` :>b As A3 AY A&$4 $ $6 $L 02 13 1f 1>L Lv L L\ -1tRV_a )Ec )E )EC )EV 6:UW =3 =s =# =\`af\g =B )+ ,{ ,\ gksu !3 !i !y !RW !`c !F 37r *s *C *. *.Dt\^ -Z3 -Zc -Z -Zcghsct -Z^ -1tRV_a *]c *] *]C *]fjkvfw *]X:s :?
T ?
X ?
Q\ ?
B# &eBSW P4c 3 S # X\ dg r   r   )ccxt.base.exchanger   ccxt.abstract.coincheckr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   ccxt.base.decimal_to_precisionr   r    r   r   <module>r     sM    ( /  \  \  \  \  \  * 0 & 4i+ ir   