
    E#iz                         S SK Jr  S SKJr  S SKrS SKJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr   " S
 S\\5      rg)    )Exchange)ImplicitAPIN)AnyBalancesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrTickerTradeTransaction)List)ExchangeError)
BadRequest)	TICK_SIZE)Precisec                   @  ^  \ rS rSrS\4U 4S jjr0 4S\\   4S jjrS\	S\4S jr
S\4S jr0 4S\4S jjrS	0 4S
\S\S\4S jjrS2S\	S\S\4S jjr0 4S
\S\4S jjrS2S\	S\S\4S jjrS	S	0 4S
\S\S\S\\   4S jjrS	0 4S
\S\S\S\S\4
S jjrS	0 4S\S
\4S jjrS2S\	S\S\4S jjr S	S	S	0 4S
\S\S\S\\   4S jjr!S	S	S	0 4S
\S\S\S\\   4S jjr"S	0 4S\S\S \S!\S\#4
S" jjr$S2S#\	S$\%S\#4S% jjr&S& r'S'S(0 S	S	4S) jr(S*\)S+\S,\S-\S.\	S/\4S0 jr*S1r+U =r,$ )3zaif   returnc                 <  > U R                  [        [        U ]  5       SSS/SS0 SS _SS_S	S _S
S_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSSSSSSSS.ESSS0S/ SQSS .S!SU R	                  S"5      U R	                  S#5      S$.0S%S&S&S&S&S&S&S&S&S'.0S(S)S)S)S)S*S)S)S)S+S)S)S,.0S(S&S&S&S&S-.0S(S.S.S)S/S/S/S0.0S%S&S&S&S&S&S1.0S2.0 SSSSS SSS SSSSS3.SSSSSSSS4.S S S SS SSSS5.S SS6S7S&S7SSSS8.S S9.	S S S:.S S S:.S;.[
        S<[        00 S=.S>.5      $ )?Nr   ZaifJPd   1CORSspotTmarginswapFfutureoptioncancelOrdercreateMarketOrdercreateOrderfetchBalancefetchClosedOrdersfetchCurrenciesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCV)fetchMarketsfetchMarkOHLCVfetchOpenInterestHistoryfetchOpenOrdersfetchOrderBookfetchPremiumIndexOHLCVfetchTickerfetchTradesfetchTradingFeefetchTradingFeeswithdrawzchttps://user-images.githubusercontent.com/1294454/27766927-39ca2ada-5eeb-11e7-972f-1b4199518ca6.jpgrestzhttps://api.zaif.jpzhttps://zaif.jp)zChttps://techbureau-api-document.readthedocs.io/ja/latest/index.htmlzhttps://corp.zaif.jp/api-docsz'https://corp.zaif.jp/api-docs/api_linksz%https://www.npmjs.com/package/zaif.jpz%https://github.com/you21979/node-zaifzhttps://zaif.jp/fee?lang=en)logoapiwwwdocfeestradingz0.0010)
percentagetakermakerget   )zdepth/{pair}zcurrencies/{pair}zcurrencies/allzcurrency_pairs/{pair}zcurrency_pairs/allzlast_price/{pair}zticker/{pair}ztrades/{pair}post   
   2   )active_orderscancel_orderdeposit_historyget_id_infoget_info	get_info2get_personal_infotradetrade_historyr<   withdraw_history)createInvoice
getInvoicegetInvoiceIdsByOrderNumbercancelInvoiceB   !   )get_positionsposition_historyactive_positionscreate_positionchange_positioncancel_position)zgroups/{group_id}zlast_price/{group_id}/{pair}zticker/{group_id}/{pair}ztrades/{group_id}/{pair}zdepth/{group_id}/{pair})publicprivateecapitlapifapi)IOCFOKPOGTD)
marginModetriggerPricetriggerDirectiontriggerPriceTypestopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventioniceberg)rm   limittriggerrv   symbolRequired  i )rm   r|   daysBackdaysBackCanceled	untilDaysr}   rv   r~   )	sandboxr)   createOrdersfetchMyTrades
fetchOrderr5   fetchOrdersr+   
fetchOHLCV)linearinverse)r"   r$   r%   zunsupported currency_pair)exactbroad)idname	countries	rateLimitversionhasurlsrB   r?   optionsfeaturesprecisionMode
exceptions)deep_extendsuperr   describeparse_numberr   r   )self	__class__s    Q/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/async_support/zaif.pyr   zaif.describe   s   dD : < $ 	
 % % t $U t  $T "5 &u #E *5  $U!" "5#$ !%"',1#'"&*/###($) 9> ~1 ) 6  "&!..w7!..s3 ()-.*+12./-.)*)*	 )*()+,'($&%&-.!")+$%,-  )*&'67)*	 )+,.,-+-+-+-	 -.89454534]7p  %&*(,,1,0).+06:#(#("'#(	( #($)$(+027/4#()$, %)%)"&&*!%#($)*/( $(&*!%$*,-%+#($)*/	* #'[.` ##
 ##i8r ' 0	_v?
 v v	    c                 b   #    U R                  U5      I Sh  vN nU R                  U5      $  N7f)z

https://zaif-api-document.readthedocs.io/ja/latest/PublicAPI.html#id12

retrieves data on all markets for zaif
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
N)publicGetCurrencyPairsAllparse_markets)r   paramsmarketss      r   fetch_marketszaif.fetch_markets   s2      66v>>, !!'**- ?s   /-/marketc                 ,   U R                  US5      nU R                  US5      nUR                  S5      u  pEU R                  U5      nU R                  U5      nUS-   U-   n0 SU_SU_SU_SU_SS _S	U_S
U_SS _SS_SS_SS _SS_SS_SS_SS _SS_SS _S S S S S S U R                  US5      U R	                  U R                  U R                  US5      5      5      S.S S S.U R                  US5      S S.U R                  US5      S S.S S S.S.S US.
E$ )Ncurrency_pairr   /r   symbolbasequotesettlebaseIdquoteIdsettleIdtyper"   Tr#   r$   Fr%   r&   activecontractr   item_unit_stepaux_unit_point)amountprice)minmaxitem_unit_minaux_unit_min)rw   r   r   cost)
r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedinfo)safe_stringsplitsafe_currency_codesafe_numberr   parse_precision)	r   r   r   r   r   r   r   r   r   s	            r   parse_marketzaif.parse_market   s   fo6/**S/&&v.''0e#0
"0
f0
 D0
 U	0

 d0
 f0
 w0
 0
 F0
 D0
 d0
 E0
 e0
 e0
 d0
  !0
" d#0
$  "**63CD**4+?+?@P@PQWYi@j+kl  
  ++FOD
  ++FNC
  $ _0
 0	
r   c                    U R                  US0 5      nU R                  US5      nUS S S.nU R                  US0 5      n[        UR                  5       5      n[        S[	        U5      5       Ha  nXg   nU R                  U5      n	U R                  XX5      n
U R                  5       nXS'   XS'   Ub  X;   a  U R                  X85      US'   XU	'   Mc     U R                  U5      $ )Nr   deposit)r   	timestampdatetimefundsr   freetotal)	
safe_valuelistkeysrangelenr   r   accountsafe_balance)r   responsebalancesr   resultr   currencyIdsi
currencyIdcodebalancer   s               r   parse_balancezaif.parse_balance&  s    ??8Xr://(I6

 '265::<(q#k*+A$J**:6D&&u9GllnG%FO&G"('+'7'7'LGG$"4L ,   ((r   c                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  U5      $  N. N7f)aK  

https://zaif-api-document.readthedocs.io/ja/latest/TradingAPI.html#id10

query for balance and get the amount of funds available for trading or funds locked in orders
: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privatePostGetInfor   )r   r   r   s      r   fetch_balancezaif.fetch_balance=  sE      !!!0088!!(++ 	"8s   A	AA	AA	A	Nr   r|   c                    #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XS5      5      I Sh  vN nU R	                  XdS   5      $  NX N7f)a  

https://zaif-api-document.readthedocs.io/ja/latest/PublicAPI.html#id34

fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
: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pairr   r   )r   r   publicGetDepthPairextendparse_order_book)r   r   r|   r   r   requestr   s          r   fetch_order_bookzaif.fetch_order_bookJ  sv      !!!V$F4L
 00W1MNN$$Xh/?@@ 	"
 Os!   A3A/?A3A1A31A3tickerc                    U R                  S U5      nU R                  US5      nU R                  US5      n[        R                  " XT5      nU R                  US5      nU R	                  0 SU_SS _SS _SU R                  US5      _SU R                  US5      _S	U R                  US	5      _S
S _SU R                  US5      _SS _SU_SS _SU_SU_SS _SS _SS _SS _UUUS.EU5      $ )Nvwapvolumelastr   r   r   highlowbid	bidVolumeask	askVolumeopenclosepreviousClosechangerE   average)
baseVolumequoteVolumer   )safe_symbolr   r   
string_mulsafe_ticker)r   r   r   r   r   r  r  r   s           r   parse_tickerzaif.parse_ticker]  s    !!$//%%fh7
((:/ !
f!
!
 !
 D$$VV4	!

 4##FE2!
 4##FE2!
 !
 4##FE2!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&)!
* + 	r   c                    #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  XS5      $  NU N7f)a  

https://zaif-api-document.readthedocs.io/ja/latest/PublicAPI.html#id22

fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
: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   publicGetTickerPairr   r	  )r   r   r   r   r   r   s         r   fetch_tickerzaif.fetch_ticker  ss      !!!V$F4L
 //G0LMM   00# 	"
 Ns!   A0A,?A0A.A0.A0rU   c                 r   U R                  US5      nUS:X  a  SOSnU R                  US5      nU R                  USS5      nU R                  US5      nU R                  US	5      nU R                  US
5      nU R                  XS5      n	U R	                  UUUU R                  U5      U	S US S UUS S S.U5      $ )N
trade_typer   buyselldater   tidr   r   r   _)r   r   r   r   r   r   sideordertakerOrMakerr   r   r   fee)r   safe_timestampsafe_string_2r  
safe_tradeiso8601)
r   rU   r   r  r   r   priceStringamountStringmarketIdr   s
             r   parse_tradezaif.parse_trade  s     |4uV''v6	tU3&&ug6''x8##E?;!!(C8"Y/  " 
  	r   sincec                 $  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  Xd5      5      I Sh  vN n[	        U5      nUS:X  a  US   n	U	(       d  / nU R                  XuX#5      $  Nu N77f)a  

https://zaif-api-document.readthedocs.io/ja/latest/PublicAPI.html#id28

get the list of most recent trades for a particular symbol
: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   rI   r   )r   r   publicGetTradesPairr   r   parse_trades)
r   r   r#  r|   r   r   r   r   	numTrades
firstTrades
             r   fetch_tradeszaif.fetch_trades  s      !!!V$F4L
 11$++g2NOO M	>!!J  5@@/ 	"
 Ps!   BB?BB6BBr   r  r   r   c                 \  #    U R                  5       I Sh  vN   US:w  a  [        U R                  S-   5      eU R                  U5      nUS   US:X  a  SOSUUS.nU R	                  U R                  X5      5      I Sh  vN n	U R                  U	[        U	S	   S
   5      S.U5      $  N N*7f)ac  

https://zaif-api-document.readthedocs.io/ja/latest/MarginTradingAPI.html#id23

create a trade order
:param str symbol: unified symbol of the market to create an order in
:param str type: must be '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|   z' createOrder() allows limit orders onlyr   r  r   r   )r   actionr   r   r   order_id)r   r   )r   r   r   r   privatePostTrader   
safe_orderstr)
r   r   r   r  r   r   r   r   r   r   s
             r   create_orderzaif.create_order  s      !!!7?*S STTV$#D\ $eE	
 ..t{{7/KLLhx(45 
  	 	" Ms"   B,B(A(B,?B* )B,*B,r   c                    #    SU0nU R                  U R                  XC5      5      I Sh  vN nU R                  US5      nU R                  U5      $  N'7f)aJ  

https://zaif-api-document.readthedocs.io/ja/latest/TradingAPI.html#id37

cancels an open order
:param str id: order id
:param str symbol: not used by zaif cancelOrder()
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r-  Nr   )privatePostCancelOrderr   	safe_dictparse_order)r   r   r   r   r   r   datas          r   rO   zaif.cancel_order
  sZ      
 44T[[5QRR ~~h1%%! Ss   (AA(Ar  c                    U R                  US5      nUS:X  a  SOSnU R                  US5      nU R                  US5      nU R                  XRS5      nU R                  US5      nU R                  US	5      nU R                  US
S5      n	U R	                  0 S
U	_SS _SU_SU R                  U5      _SS _SS_SU_SS_SS _SS _SU_SU_SS _SS _S	U_SS _SS _S S US S.EU5      $ )Nr,  r   r  r  r   r   r  r   r   r   r-  clientOrderIdr   lastTradeTimestampstatusr   r   r   r|   rt   postOnlyr  rn   r   filled	remaining)tradesr  r   r  )r   r  r  r  r/  r  )
r   r  r   r  r   r   r   r   r   r   s
             r   r6  zaif.parse_order*  s   . x0uV''{;	##E?;!!(C8  0!!%2tZ8  
" 
T 
  
 Y/	 

 !$ 
 f 
 f 
 G 
 4 
  
 D 
 U 
 D 
 D 
 f 
  d! 
" # 
$ + 
, - 	r   c                    #    U R                  5       I Sh  vN   Sn0 nUb  U R                  U5      nUS   US'   U R                  U R                  Xd5      5      I Sh  vN nU R	                  US   XRU5      $  Nb N7f)a  

https://zaif-api-document.readthedocs.io/ja/latest/MarginTradingAPI.html#id28

fetch all unfilled currently open orders
:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch open orders for
:param int [limit]: the maximum number of  open orders structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr   r   r   )r   r   privatePostActiveOrdersr   parse_ordersr   r   r#  r|   r   r   r   r   s           r   fetch_open_orderszaif.fetch_open_ordersa  s      !!!
 [[(F'-d|GO$55dkk'6RSS  (!3VEJJ 	" T"   A=A9AA=A;A=;A=c                    #    U R                  5       I Sh  vN   Sn0 nUb  U R                  U5      nUS   US'   U R                  U R                  Xd5      5      I Sh  vN nU R	                  US   XRU5      $  Nb N7f)a  

https://zaif-api-document.readthedocs.io/ja/latest/TradingAPI.html#id24

fetches information on multiple closed orders made by the user
: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>`
Nr   r   r   )r   r   privatePostTradeHistoryr   rD  rE  s           r   fetch_closed_orderszaif.fetch_closed_ordersy  s      !!!	
 [[(F'-d|GO$55dkk'6RSS  (!3VEJJ! 	" TrH  r   addresstagc                   #    U R                  XE5      u  pEU R                  U5        U R                  5       I Sh  vN   U R                  U5      nUS:X  a  [	        U R
                  S-   U-   S-   5      eUS   UUS.nUb  XGS'   U R                  U R                  Xu5      5      I Sh  vN nU R                  US5      n	U R                  X5      $  N N)7f)	a  

https://zaif-api-document.readthedocs.io/ja/latest/TradingAPI.html#id41

make a withdrawal
:param str code: unified currency code
:param float amount: the amount to withdraw
:param str address: the address to withdraw to
:param str tag:
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
NJPYz withdraw() does not allow z withdrawalsr   )currencyr   rM  messager   )
handle_withdraw_tag_and_paramscheck_addressr   rQ  r   r   privatePostWithdrawr   r5  parse_transaction)
r   r   r   rM  rN  r   rQ  r   r   
returnDatas
             r   r<   zaif.withdraw  s      99#F7#!!!==&5=*G G$ NQ_ _`` 
 ?!$I//G0LMM" ^^FH5
%%j;;? 	" Ns"   8CCA,C'C((CCtransactionrQ  c                     U R                  S U5      nS nU R                  US5      nUb  UUS   S.n0 SU R                  US5      _SU R                  US5      _SS _SS _SS _S	S _S
S _SS _SS _SS _SUS   _SS _SS _SS _SS _SS _SS _S UUS.E$ )Nr  r   )r   rQ  r   txidr   r   networkaddressFromrM  	addressTor   r   rQ  r<  updatedtagFromrN  tagTocomment)internalr  r   )safe_currencyr   r   )r   rY  rQ  r  feeCosts        r   rV  zaif.parse_transaction  sD    %%dH5//+u5$V,C
$"";5
D$$[&9
 
 	

 t
 4
 t
 
 d
 D
 (
 d
 t
 t
 4
  T!
" t#
$ )
 	
r   c                 t    U R                  U R                  5       S-  5      n[        U5      n[        US5      $ )Nr   z.8f)number_to_stringmillisecondsfloatformat)r   numnonces      r   custom_noncezaif.custom_nonce  s6    ##D$5$5$7$$>?c
eU##r   rd   GETc                 ^   U R                   S   S   S-   nUS:X  a(  USU R                  -   S-   U R                  X5      -   -  nOUS:X  a(  USU R                  -   S-   U R                  X5      -   -  nOU R                  5         US:X  a  US-  nOUS	:X  a  US	-  nOUS
-  nU R	                  5       nU R                  U R                  UUS.U5      5      nSU R                  U R                  U R                  U5      U R                  U R                  5      [        R                  5      S.nXsXeS.$ )Nr?   r=   r   rd   zapi/rh   zfapi/rf   rg   tapi)methodrm  z!application/x-www-form-urlencoded)zContent-TypeKeySign)urlrs  bodyheaders)r   r   implode_paramscheck_required_credentialsrn  	urlencoder   apiKeyhmacencodesecrethashlibsha512)	r   pathr?   rs  r   rx  rw  rv  rm  s	            r   sign	zaif.sign  s/   iiv&,(?6DLL(3.1D1DT1RRRCF]7T\\)C/$2E2Ed2SSSC++-g~wwv%%'E>>$++/ # D
 !D{{		$++d"3T[[5Mw~~^G
 dOOr   httpCodereasonrv  rs  rx  rw  c
                 6   Uc  g U R                   S-   U-   n
U R                  US5      nUbI  U R                  U R                  S   X5        U R	                  U R                  S   X5        [        U
5      eU R                  USS5      nU(       d  [        U
5      eg )N errorr   r   successT)r   r   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   	safe_bool)r   r  r  rv  rs  rx  rw  r   requestHeadersrequestBodyfeedbackr  r  s                r   handle_errorszaif.handle_errors  s     77S=4'  73001I5[001I5[))..9d;))r    )N)-__name__
__module____qualname____firstlineno__r   r   r   r	   r   dictr   r   r   r   r0  r   r   r   r   r	  r  r   r!  r)  r   r   rj  r
   r1  r   rO   r   r6  rF  rK  r   r<   r   rV  rn  r  intr  __static_attributes____classcell__)r   s   @r   r   r      s   w# wr *, +V +B7
4 7
F 7
r) ). *, , , @DB AS A AS\ A&&4 & &6 &P 68 1 1F 1:# #v # #J <@d[] #A #AS #A #Abfglbm #AJ mqy{  I Y X] fi < 9=R &S &# &@5 5v 5 5n 59tZ^gi Kc K KTW Knrsxny K0 7;\`ik K K3 KVY Kptuzp{ K< QU]_ .<3 .< .< .<# .<do .<`+
T +
X +
Q\ +
Z$
 &eBSW P4c 3 S # X\ dg  r   r   ) ccxt.async_support.base.exchanger   ccxt.abstract.zaifr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r   r  r   r   <module>r     sG    6 *  O  O  O  O  * ' 4 %Q8[ Qr   