
    !:hN                         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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#  G d dee      Z$y)    )Exchange)ImplicitAPIN)AnyBalancesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerFundingRateTradeTradingFeeInterfaceTransactionMarketInterface)List)ExchangeError)ArgumentsRequired)OrderNotFound)OnMaintenance)	TICK_SIZE)Precisec                       e Zd Zdef fdZd Zd@dededededef
 fd	Z	i fde
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dAdededefdZi fdedefdZdAd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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efd Z"dAd!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dd#i fdededede
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i fd)e*de
e+   fd*Z,di fd+e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/Z0d0 Z1d1 Z2dAd2ed3e3de-fd4Z4i fdede5fd5Z6dAdede5fd6Z7d7d8i ddfd9Z8d+e9d:ed;ed<ed=ed>efd?Z: xZ;S )Bbitflyerreturnc                 N   | 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,d-id.d/d0d1g d2ig d3g d4d5d6d7| j	                  d8      | j	                  d8      d9it
        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@dd<d d d ddd	dAd dB	d d dCd d dCdDdEdFt        iidG      S )HNr    bitFlyerJPv1i  zbitflyer.comCORSspotTmarginFswapfutureoptioncancelAllOrderscancelOrdercreateOrderfetchBalancefetchClosedOrdersemulatedfetchDepositsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchMarginModefetchMarketsfetchMyTradesfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionModefetchPositionsfetchTickerfetchTradesfetchTradingFeefetchTradingFeesfetchTransferfetchTransfersfetchWithdrawalstransferwithdrawzOhttps://github.com/user-attachments/assets/d0217747-e54d-4533-8416-0d553dca74bbrestzhttps://api.{hostname}zhttps://bitflyer.comz+https://lightning.bitflyer.com/docs?lang=en)logoapiwwwdocget)
zgetmarkets/usazgetmarkets/eu
getmarketsgetboard	gettickergetexecutions	gethealthgetboardstategetchatsgetfundingrate)getpermissions
getbalancegetbalancehistorygetcollateralgetcollateralhistorygetcollateralaccountsgetaddresses
getcoininsgetcoinoutsgetbankaccountsgetdepositsgetwithdrawalsgetchildordersgetparentordersgetparentorderrQ   getpositionsgettradingcommission)sendcoinrG   sendchildordercancelchildordersendparentordercancelparentordercancelallchildorders)rM   post)publicprivatetradingz0.002)makertaker)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyRequiresPricemarketBuyByCostselfTradePreventionicebergd   )rw   limitdaysBack	untilDayssymbolRequired)rw   triggerr   r   )rw   r   r   r   r   )rw   r   r   r   r   r   r   )rw   r   r   daysBackCanceledr   r   r   r   )	sandboxr.   createOrdersr8   r:   r9   r<   r0   
fetchOHLCV)linearinverse)r'   r)   r*   exactz-2)idname	countriesversion	rateLimithostnamehasurlsrJ   feesprecisionModefeatures
exceptions)deep_extendsuperr    describeparse_numberr   r   )self	__class__s    G/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/bitflyer.pyr   zbitflyer.describe   sK   h > @&""" %" 	"
 $" %" "4" t" t" " $Z"  " #D" *5" $U"  "5!"" #"$  %"& ":'"( j)"* !$+", t-". $U/"0 !$1"2 t3"4 t5"6 "47"8 #E9":  ;"< !%="> #D?"@ EA"B DC"H j4 .D  (+.` !..w7!..w7 '  %&+(-,0,1).+06:#'#'"&#'	( #($)$)27+0/4#()$, %)&+!$$(%)*.& ',#($)*.	# ',!$#($)*.( ',!$$(%)#($)*.$ ',!$$(,0%)#($)*.	* #'AAF ##
 ##OKZ -iyC
 y y	    c                     |dd }|dd }|dd }ddddd	d
ddddddd}| j                  ||      }| j                  |dz   |z   dz   |z   dz         S )Nr         	   010203040506070809101112)JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC-z
T00:00:00Z)safe_string	parse8601)r   expiryday	monthNameyearmonthsmonths          r   parse_expiry_datezbitflyer.parse_expiry_date   s    Qqk1QK	a{
   3~~dSj5036<|KLLr   NmarketIdmarket	delimiter
marketTypec                 0    t         t        |   |||d      S )Nr'   )r   r    safe_market)r   r   r   r   r   r   s        r   r   zbitflyer.safe_market   s     Xt069fUUr   c                 f   | j                  |      }| j                  |      }| j                  |      }| j                  ||      }| j                  ||      }g }t	        dt        |            D ]>  }||   }| j                  |d      }	|	j                  d      }
| j                  |d      }|dk(  }|dk(  }| xr | }d}d}d}d}d}|r%| j                  |
d      }| j                  |
d	      }n|r'd
}| j                  |
d	      }| j                  |
d      }n|r| j                  |d      }|!|	dd }|	dd }|	dd }| j                  |      }na|j                  d      }| j                  |d      }|dd }|dd }|	j                  |      }| j                  |d	      }| j                  |      }d}| j                  |      }| j                  |      }|dz   |z   }| j                  d   d   }| j                  d   d   }|xs |}|r'd}d}d}|dz   |z   }|r|dz   | j                  |      z   }|j                  i d|	d|d|d|d|d|d |d!dd"|d|d#d$d
|d|d%d$d&d'd(|d)|rdnd'|rdnd$||d|| j                  |      ddddd*ddd+ddd+ddd+ddd+d,d|d-       A |S ).a  
        retrieves data on all markets for bitflyer

        https://lightning.bitflyer.com/docs?lang=en#market-list

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r   product_code_market_typeFXFuturesr'   N   r)   r   alias      ir*   /rp   rr   rq   g        JPY:r   r   symbolbasequotesettlebaseIdquoteIdsettleIdtyper(   Fr+   activeTcontractr   )amountprice)minmax)r   r   r   cost)r   rr   rq   contractSizer   expiryDatetimestrike
optionType	precisionlimitscreatedinfo)publicGetGetmarketspublicGetGetmarketsUsapublicGetGetmarketsEuarray_concatrangelenr   splitr   safe_currency_coder   yymmddappendiso8601)r   params
jp_markets
us_markets
eu_marketsmarketsresultir   r   
currenciesr   r)   r*   r'   r   r   r   r   r   r   
expiryDate
splitAliascurrencyIdssplitIdr   r   r   rr   rq   r   s                                  r   fetch_marketszbitflyer.fetch_markets   s    --f5
" 008
 //7
 ##J
;##GZ8q#g,' g	AQZF!!&.9B#J))&-@J$&D I-F8*F
DDFFGF))*a8**:q9))*a8**:q9((9=  !WF 1gG!#BCJ!33J?F!&S!1J"&"2"2:q"AK(2.F)"#.G hh{3G!%!1!1'1!=J!33J?F**62D++G4ECZ%'FIIi(1EIIi(1E~vH#.#c\DKK,??FMM 2b2&2 2 	2
 &2 &2 72 D2 2 2 %2 2 &2 %2 $2  H!2" $$D#2$ $(4U $ "&,,v"6""!  $#!
  $#
  $#
  $#$  c2 2kg	P r   c                 .   d|i}t        dt        |            D ]i  }||   }| j                  |d      }| j                  |      }| j	                         }| j                  |d      |d<   | j                  |d      |d<   |||<   k | j                  |      S )Nr   r   currency_coder   total	availablefree)r   r   r   r   accountsafe_balance)r   responser  r	  balance
currencyIdcoder  s           r   parse_balancezbitflyer.parse_balance  s    )q#h-( 	#AqkG))'?CJ**:6DllnG#//BGG"..wDGFO"F4L	#   ((r   c                 f    | j                          | j                  |      }| j                  |      S )aq  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://lightning.bitflyer.com/docs?lang=en#get-account-asset-balance

        :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privateGetGetbalancer  )r   r  r  s      r   fetch_balancezbitflyer.fetch_balance  s3     	,,V4( !!(++r   r   r   c           	          | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  ||d   ddddd      S )	a4  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://lightning.bitflyer.com/docs?lang=en#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   r   r   Nbidsasksr   size)r  r   publicGetGetboardextendparse_order_book)r   r   r   r  r   request	orderbooks          r   fetch_order_bookzbitflyer.fetch_order_book  sp     	V$F4L
 **4;;w+GH	$$Yx0@$PVX_aghhr   tickerc                    | j                  d |      }| j                  | j                  |d            }| j                  |d      }| j                  i d|d|d| j	                  |      dd d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 )N	timestampltpr   datetimehighlowbidbest_bid	bidVolumeaskbest_ask	askVolumevwapopencloselastpreviousClosechange
percentageaveragevolume_by_product)
baseVolumequoteVolumer   )safe_symbolr   r   safe_tickerr  )r   r*  r   r   r,  r:  s         r   parse_tickerzbitflyer.parse_ticker  sg   !!$/NN4#3#3FK#HI	. !
f!
!
 Y/!
 D	!

 4!
 4##FJ7!
 !
 4##FJ7!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **63FG)!
* + 	r   c                     | 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://lightning.bitflyer.com/docs?lang=en#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>`
        r   r   )r  r   publicGetGettickerr%  rD  r   r   r  r   r'  r  s         r   fetch_tickerzbitflyer.fetch_ticker  s^     	V$F4L
 **4;;w+GH  622r   tradec                    | j                  |d      }|t        |      dk  rd }d }||dz   }||v r||   }|| j                  |d      }| j                  | j                  |d            }| j                  |d      }| j                  |d      }| j                  |d      }	| j	                  d |      }| j                  |	||| j                  |      |d	   |d |d ||d d d
|      S )Nsider   _child_order_acceptance_idchild_order_acceptance_id	exec_dater   r#  r   r   )r   r   r,  r.  r   orderr   rK  takerOrMakerr   r   r   fee)safe_string_lowerr   r   r   r   
safe_trader  )
r   rI  r   rK  rO  idInnerr,  priceStringamountStringr   s
             r   parse_tradezbitflyer.parse_trade  s   6 %%eV44y1}99G%g=$$U,GHENN4#3#3E;#GH	&&ug6''v6eT*!!$/"Y/X&  " 
  	r   sincec                     | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  ||||      S )a#  
        get the list of most recent trades for a particular symbol

        https://lightning.bitflyer.com/docs?lang=en#list-executions

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r   r   count)r  r   publicGetGetexecutionsr%  parse_tradesr   r   rX  r   r  r   r'  r  s           r   fetch_tradeszbitflyer.fetch_trades(  st     	V$F4L
 $GG..t{{7F/KL   65%@@r   c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |d      }||d   ||dddS )a]  
        fetch the trading fees for a market

        https://lightning.bitflyer.com/docs?lang=en#get-trading-commission

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        r   r   commission_rater   N)r   r   rq   rr   r=  	tierBased)r  r   privateGetGettradingcommissionr%  safe_number)r   r   r  r   r'  r  rQ  s          r   fetch_trading_feezbitflyer.fetch_trading_feeK  s     	V$F4L
 66t{{7F7ST x):;X&
 	
r   r   rK  r   r   c                    | j                          | j                  |      |j                         |j                         ||d}| j                  | j	                  ||            }| j                  |d      }	| j                  |	|d      S )a  
        create a trade order

        https://lightning.bitflyer.com/docs?lang=en#send-a-new-order

        :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   child_order_typerK  r   r#  rM  )r   r   )r  	market_idupperprivatePostSendchildorderr%  r   
safe_order)
r   r   r   rK  r   r   r  r'  r  r   s
             r   create_orderzbitflyer.create_orderj  s     	 NN62 $

JJL
 //GV0LMf&AB 
  	r   r   c                     |t        | j                  dz         | j                          | j                  |      |d}| j	                  | j                  ||            }| j                  d|i      S )a  
        cancels an open order

        https://lightning.bitflyer.com/docs?lang=en#cancel-order

        :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>`
        z) cancelOrder() requires a symbol argument)r   rM  r   )r   r   r  rg  privatePostCancelchildorderr%  rj  )r   r   r   r  r'  r  s         r   cancel_orderzbitflyer.cancel_order  sz     >#DGG.Y$YZZ NN62)+
 33DKK4PQ H 
  	r   statusc                 8    dddddd}| j                  |||      S )Nr8  closedcanceled)ACTIVE	COMPLETEDCANCELEDEXPIREDREJECTEDr   r   ro  statusess      r   parse_order_statuszbitflyer.parse_order_status  s/    !"!"
 &&99r   rO  c                    | j                  | j                  |d            }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  | j                  |d            }| j                  |d      }	| j                  |d      }
| j                  |d	      }| j	                  ||      }d }| j                  |d
      }||d d d}| j                  |d      }| j                  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|      S )Nchild_order_dater   r#  executed_sizeoutstanding_sizechild_order_staterf  rK  r   total_commission)r   currencyraterM  r   clientOrderIdr   r,  r.  lastTradeTimestampro  r   r   r~   postOnlyrx   r   r   filled)	remainingrQ  r>  trades)r   r   r{  rR  rB  rc  rj  r  )r   rO  r   r,  r   r   r  r  ro  r   rK  r   r   rQ  feeCostr   s                   r   parse_orderzbitflyer.parse_order  s   NN4#3#3E;M#NO	  0!!%0!!%9$$U,>?	(()9)9%AT)UV%%e-?@%%eV4##E>:!!(F3""5*<= C
 e%@A  
" 
T 
 E 
 	 

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

        https://lightning.bitflyer.com/docs?lang=en#list-orders

        :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>`
        z) fetchOrders() requires a symbol argumentr   )r   rZ  r   )r   r   r  r   privateGetGetchildordersr%  parse_orders	filter_by)	r   r   rX  r   r  r   r'  r  orderss	            r   fetch_orderszbitflyer.fetch_orders  s     >#DGG.Y$YZZV$"4L
 00Wf1MN""8VUEB^^FHf=Fr   c           	      R    ddi}| j                  |||| j                  ||            S )a
  
        fetch all unfilled currently open orders

        https://lightning.bitflyer.com/docs?lang=en#list-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>`
        r  rs  r  r%  r   r   rX  r   r  r'  s         r   fetch_open_orderszbitflyer.fetch_open_orders  s4      
   t{{7F7STTr   c           	      R    ddi}| j                  |||| j                  ||            S )a6  
        fetches information on multiple closed orders made by the user

        https://lightning.bitflyer.com/docs?lang=en#list-orders

        :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  rt  r  r  s         r   fetch_closed_orderszbitflyer.fetch_closed_orders  s4      
   t{{7F7STTr   c                     |t        | j                  dz         | j                  |      }| j                  |d      }||v r||   S t	        | j                  dz   |z         )a  
        fetches information on an order made by the user

        https://lightning.bitflyer.com/docs?lang=en#list-orders

        :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>`
        z( fetchOrder() requires a symbol argumentr   z No order found with id )r   r   r  index_byr   )r   r   r   r  r  
ordersByIds         r   fetch_orderzbitflyer.fetch_order  sj     >#DGG.X$XYY""6*]]640
b>!DGG&@@2EFFr   c                     |t        | j                  dz         | j                          | j                  |      }d|d   i}|||d<   | j	                  | j                  ||            }| j                  ||||      S )a  
        fetch all trades made by the user

        https://lightning.bitflyer.com/docs?lang=en#list-executions

        :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>`
        z+ fetchMyTrades() requires a symbol argumentr   r   rZ  )r   r   r  r   privateGetGetexecutionsr%  r\  r]  s           r   fetch_my_tradeszbitflyer.fetch_my_trades'  s     >#DGG.[$[\\V$F4L
 $GG//GV0LM   65%@@r   symbolsc                     |t        | j                  dz         | j                          d| j                  |      i}| j	                  | j                  ||            }|S )au  
        fetch all open positions

        https://lightning.bitflyer.com/docs?lang=en#get-open-interest-summary

        :param str[] symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        zO fetchPositions() requires a `symbols` argument, exactly one symbol in an arrayr   )r   r   r  
market_idsprivateGetGetpositionsr%  )r   r  r  r'  r  s        r   fetch_positionszbitflyer.fetch_positionsM  si     ?#DGG.$  A  ADOOG4
 ..t{{7F/KL& r   r  addressc                 6   | j                  |       | j                          |dk7  r(|dk7  r#|dk7  rt        | j                  dz   |z   dz         | j	                  |      }|d   |d}| j                  | j                  ||            }| j                  ||      S )a  
        make a withdrawal

        https://lightning.bitflyer.com/docs?lang=en#withdrawing-funds

        :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>`
        r   USDEURz( allows withdrawing JPY, USD, EUR only, z is not supportedr   )r  r   )check_addressr  r   r   r  privatePostWithdrawr%  parse_transaction)	r   r  r   r  tagr  r  r'  r  s	            r   rG   zbitflyer.withdrawr  s     	7#5=TU]tu}*T TW[ [^q qrr==&%d^

 ++DKK,HI %%h99r   c                     | j                          d}i }|| j                  |      }|||d<   | j                  | j                  ||            }| j	                  ||||      S )a  
        fetch all deposits made to an account

        https://lightning.bitflyer.com/docs?lang=en#get-crypto-assets-deposit-history

        :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>`
        NrZ  )r  r  privateGetGetcoininsr%  parse_transactionsr   r  rX  r   r  r  r'  r  s           r   fetch_depositszbitflyer.fetch_deposits  sr     	}}T*H$GG,,T[[&-IJ &&x5%HHr   c                     | j                          d}i }|| j                  |      }|||d<   | j                  | j                  ||            }| j	                  ||||      S )a.  
        fetch all withdrawals made from an account

        https://lightning.bitflyer.com/docs?lang=en#get-crypto-assets-transaction-history

        :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>`
        NrZ  )r  r  privateGetGetcoinoutsr%  r  r  s           r   fetch_withdrawalszbitflyer.fetch_withdrawals  sr     	}}T*H$GG--dkk'6.JK" &&x5%HHr   c                 2    ddd}| j                  |||      S Npendingok)PENDINGrt  rx  ry  s      r   parse_deposit_statuszbitflyer.parse_deposit_status  &     
 &&99r   c                 2    ddd}| j                  |||      S r  rx  ry  s      r   parse_withdrawal_statusz bitflyer.parse_withdrawal_status  r  r   transactionr  c                    | j                  |dd      }| j                  |d      }| j                  |d      }| j                  ||      }| j                  | j                  |d            }| j	                  |d      }| j                  |d      }	| j                  |d      }
d }d }d }d	|v r`d
}| j                  |
      }| j                  |d	      }| j                  |d      }|| j                  t        j                  ||            d}n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S )Nr   
message_idr  r  
event_dater   tx_hashro  rQ  
withdrawaladditional_fee)r  r   depositr   txidr,  r.  network	addressToaddressFromr  tagTotagFromr   r  updated)commentinternalrQ  )safe_string_2r   r   r   rc  r  r   r   
string_addr  r  )r   r  r  r   r  r  r  r,  r   txId	rawStatusr   ro  rQ  r  additionalFees                   r   r  zbitflyer.parse_transaction  s   H T<@"";	:%%k?C
&&z8<NN4#3#3K#NO	!!+x8Y7$$[(;	KD11)<F&&{E:G ,,[:JKM#T->->w?Q?QRY[h?i-jkCD..y9F
K
"
 D
 	

 Y/
 t
 w
 
 4
 4
 T
 t
 D
 f
 
  f!
" t#
$ )
 	
r   c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  ||      S )aX  
        fetch the current funding rate

        https://lightning.bitflyer.com/docs#funding-rate

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        r   r   )r  r   publicGetGetfundingrater%  parse_funding_raterG  s         r   fetch_funding_ratezbitflyer.fetch_funding_rate8  s`     	V$F4L
 //GV0LM &&x88r   c                    | j                  |d      }| j                  |      }i d|d| j                  |d      dd dd dd dd dd d	d d
d dd dd d| j                  |d      d|d| j                  |      dd dd dd dd iS )Nnext_funding_rate_settledater   r   	markPrice
indexPriceinterestRateestimatedSettlePricer,  r.  fundingRatefundingTimestampfundingDatetimenextFundingRatecurrent_funding_ratenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r   r   rc  r  )r   r   r   r  r  s        r   r  zbitflyer.parse_funding_rateP  s,    #..x9WX#~~.AB
H
d&&vx8
 
 $	

 D
 #D
 
 
 4
 
 t
 t//:PQ
 #$8
 "4<<0D#E
 "4
  '!
" &t#
$ %
 	
r   rn   GETc                 H   d| j                   z   dz   }|dk(  r|dz  }||z  }|dk(  r|r|d| j                  |      z   z  }| j                  | j                  d   d         }||z   }	|dk(  r| j	                          t        | j                               }
dj                  |
||g      }|r|dk7  r| j                  |      }||z  }| j                  |
| j                  | j                  |      | j                  | j                        t        j                        d	d
}|	|||dS )Nr   ro   zme/r  ?rJ   rH    zapplication/json)z
ACCESS-KEYzACCESS-TIMESTAMPzACCESS-SIGNzContent-Type)urlmethodbodyheaders)r   	urlencodeimplode_hostnamer   check_required_credentialsstrnoncejoinjsonapiKeyhmacencodesecrethashlibsha256)r   pathrJ   r  r  r  r  r'  baseUrlr  r  auths               r   signzbitflyer.signn  s&   $s*)uG4U?3!777''		%(8(@A)++-

%E77E6734DU?99V,DDLD"kk$)#yyT):DKK<TV]VdVde 2	G fdwOOr   reasonr  r  r  r  c
                     |y | j                   dz   |z   }
| j                  |d      }| j                  |d      }|+| j                  | j                  d   ||
       t        |
      y )N error_messagero  r   )r   r   safe_integerthrow_exactly_matched_exceptionr   r   )r   r  r  r  r  r  r  r  requestHeadersrequestBodyfeedbackerrorMessage
statusCodes                r   handle_errorszbitflyer.handle_errors  sq    77S=4'''/B&&x:
#001I:W_`))r   )NNNN)N)<__name__
__module____qualname__r   r   r   r   r	   r   r   r   r  r   r  r  r  r   r   r)  dictr   rD  rH  r   rW  r^  r   rd  r   r   floatr
   rk  rn  r{  r   r  r  r  r  r  r  r   r   r  r   rG   r  r  r  r  r   r  r   r  r  r   intr  __classcell__)r   s   @r   r    r       s   z# zxM*VC V VRU Vjm V  zI V $& S$v, Sj
) 
) $& ,( ,@ :>b is i3 iY i&4  6 6 02 33 3f 3$9 9v 9 9v 6:UW !A3 !As !A# !A\`af\g !AF 57 
 
;N 
> gksu 3 i y RW `c < 37r s C 4: :* *v * *X *.Ds[] 3 c  bfglbm 4 /3TW`b U U3 Uc Ugklqgr U" 154VYbd U# US UPS Uimnsit U" 26b Gc G3 G& -1tRV_a $Ac $A $AC $AL 26b #w #T(^ #J DHPR :S :% :# :Wb :> *.Dt\^ "I3 "Ic "I "Icghsct "IH -1tRV_a $Ic $I $IC $Ifjkvfw $IL::M
T M
X M
Q\ M
^ 68 9 9K 90
6 
[ 
< &eBSW P4
# 
s 
 
c 
TX 
`c 
r   r    )%ccxt.base.exchanger   ccxt.abstract.bitflyerr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r     r   r   <module>r     sY    ( .  U  U  U  U  U  U  * . * * 4 %x r   