
    ei                         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$dS )    )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                   P    e Zd Zdef fdZd ZdAd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dBdededefdZi fdedefdZdBd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"dBd!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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d0Z0d1 Z1d2 Z2dBd3ed4e3de-fd5Z4i fdede5fd6Z6dBdede5fd7Z7d8d9i ddfd:Z8d+e9d;ed<ed=ed>ed?efd@Z: xZ;S )Cbitflyerreturnc                    |                      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d0d	d1d	d2dd3d	d4d	d5d	d6d	d7dd8dd9dd:dd;d	d<dddd	d=d>d?d@idAdBdCdDg dEig dFg dGdHdIdJ|                     dK          |                     dK          dLit
          dddd dddd d	d	d	d	dMddddddddNd ddOd d d	dPdddd	dQddOddd	dRddOd d ddd	dSddOd d d ddd	dTd dU	d d dVd d dVdWdXdYt          iidZ          S )[Nr    bitFlyerJPv1i  zbitflyer.comCORSspotTmarginFswapfutureoptionborrowCrossMarginborrowIsolatedMarginborrowMargincancelAllOrderscancelOrdercreateOrderfetchAllGreeksfetchBalancefetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchClosedOrdersemulatedfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchMarginModefetchMarketsfetchMyTradesfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchPositionModefetchPositionsfetchTickerfetchTradesfetchTradingFeefetchTradingFeesfetchTransferfetchTransfersfetchVolatilityHistoryfetchWithdrawalsrepayCrossMargin)repayIsolatedMargin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getparentorderrf   getpositionsgettradingcommission)sendcoinr\   sendchildordercancelchildordersendparentordercancelparentordercancelallchildorders)rb   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   )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   daysBackCanceledr   r   r   r   )	sandboxr1   createOrdersrH   rL   rI   rN   r:   
fetchOHLCV)linearinverse)r'   r)   r*   exactz-2)idname	countriesversion	rateLimithostnamehasurlsr_   feesprecisionModefeatures
exceptions)deep_extendsuperr    describeparse_numberr   r   )self	__class__s    K/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/bitflyer.pyr   zbitflyer.describe   s   h 5 5 > > @ @&777 %7 	7
 $7 %7 $U7 '7 7 "47 t7 t7 !%7 7 &u7  "5!7" +E#7 7$ )%%7& #E'7( ,U)7* $Z+7, '-7. (/70 "5172  374 #D576 *5778 $U97: u;7< *5=7> +E?7@ "5A7B C7D  E7 7 7F ":G7H uI7J #EK7L jM7N !$O7P tQ7R $US7T !$U7V tW7X tY7Z "4[7\ #E]7^  _7` !%a7b )%c7d #De7f #Eg7 7h (-! m7 7 7r j4 .D       (  + . .` !..w77!..w77  '  %&+(-,0,1).+06:#'#'"&#'	( ( #($)$)27+0/4#()$ $, %)&+!$$(%)*.& & ',#($)*.	# # ',!$#($)*.( ( ',!$$(%)#($)*.$ $ ',!$$(,0%)#($)*.	* 	* #'AA AF ## 
 ## OK KZ -SNC
 NC
 N N N	    c                     |dd         }|dd         }|dd         }ddddd	d
ddddddd}|                      ||          }|                     |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    QqSk1Q3K	ac{
 
   33~~dSj5036<|KLLLr   NmarketIdmarket	delimiter
marketTypec                 Z    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069fUUUr   c                 l   |                      |          }|                     |          }|                     |          }|                     ||          }|                     ||          }g }t	          dt          |                    D ]}||         }|                     |d          }	|	                    d          }
|                     |d          }|dk    }|dk    }| o| }d}d}d}d}d}|r.|                     |
d          }|                     |
d	          }n |r/d
}|                     |
d	          }|                     |
d          }n|r|                     |d          }|4|	dd         }|	dd         }|	dd         }|                     |          }n|                    d          }|                     |d          }|dd         }|dd         }|	                    |          }|                     |d	          }|                     |          }d}| 	                    |          }| 	                    |          }|dz   |z   }| j
        d         d         }| j
        d         d         }|p|}|r+d}d}d}|dz   |z   }|r|dz   |                     |          z   }|                    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||                     |          ddddd*ddd+ddd+ddd+ddd+d,d|d-           |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*   /r   r   r   g        JPY:r   r   symbolbasequotesettlebaseIdquoteIdsettleIdtyper(   Fr+   activeTcontractr   )amountprice)minmax)r   r   r  cost)r   r   r   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   r   r   r   s                                  r   fetch_marketszbitflyer.fetch_markets  s    --f55
" 0088
 //77
 ##J
;;##GZ88q#g,,'' g	 g	AQZF!!&.99B#J))&-@@J$&D I-F8*F
DDFFGF  ))*a88**:q99  ))*a88**:q99  ((99=  !WF 1gG!#BCCJ!33J??FF!&S!1!1J"&"2"2:q"A"AK(2.F)"##.G hh{33G!%!1!1'1!=!=J!33J??F**622D++G44ECZ%'FIi(1EIi(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" $0$$D#2$ $(244U $ "&,,v"6"6""!   $#! !
  $# 
  $# 
  $#  $  c2 2 2 2 2 2 2f r   c                 p   d|i}t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |||<   |                     |          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))'?CCJ**:66DllnnG#//BBGG"..wDDGFO"F4LL  (((r   c                 ~    |                                   |                     |          }|                     |          S )ao  
        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privateGetGetbalancer0  )r   r  r,  s      r   fetch_balancezbitflyer.fetch_balance  s?     	,,V44( !!(+++r   r   r   c           	          |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     ||d         ddddd          S )	a2  
        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)r2  r   publicGetGetboardextendparse_order_book)r   r   r   r  r   request	orderbooks          r   fetch_order_bookzbitflyer.fetch_order_book  s     	V$$F4L
 **4;;w+G+GHH	$$Yx0@$PVX_aghhhr   tickerc                    |                      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|          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   rA  rO  s         r   parse_tickerzbitflyer.parse_ticker  s   !!$//NN4#3#3FK#H#HII	.. !
f!
!
 Y//!
 D	!

 4!
 4##FJ77!
 !
 4##FJ77!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **63FGG)!
 !
 !
* +  	r   c                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     ||          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   )r2  r   publicGetGettickerr:  rY  r   r   r  r   r<  r,  s         r   fetch_tickerzbitflyer.fetch_ticker  sp     	V$$F4L
 **4;;w+G+GHH  6222r   tradec                 2   |                      |d          }|t          |          dk     rd }d }||dz   }||v r||         }||                     |d          }|                     |                     |d                    }|                     |d          }|                     |d          }|                     |d          }	|                     d |          }|                     |	|||                     |          |d	         |d |d ||d d d
|          S )Nsider   _child_order_acceptance_idchild_order_acceptance_id	exec_dater  r8  r   r   )r   r  rA  rC  r   orderr   r`  takerOrMakerr  r   r  fee)safe_string_lowerr  r   r   r   
safe_trader  )
r   r^  r   r`  rd  idInnerrA  priceStringamountStringr   s
             r   parse_tradezbitflyer.parse_trade  sJ   6 %%eV444yy1}}99G%g=$$U,GHHENN4#3#3E;#G#GHH	&&ug66''v66eT**!!$//"Y//X&  " 
  
   	r   sincec                     |                                   |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     ||||          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   Ncount)r2  r   publicGetGetexecutionsr:  parse_tradesr   r   rm  r   r  r   r<  r,  s           r   fetch_tradeszbitflyer.fetch_trades=  s     	V$$F4L
 $GG..t{{7F/K/KLL   65%@@@r   c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |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   r   r   rR  	tierBased)r2  r   privateGetGettradingcommissionr:  safe_number)r   r   r  r   r<  r,  rf  s          r   fetch_trading_feezbitflyer.fetch_trading_fee`  s     	V$$F4L
 66t{{7F7S7STT x):;;X&
 
 	
r   r   r`  r   r  c                 V   |                                   |                     |          |                                |                                ||d}|                     |                     ||                    }|                     |d          }	|                     |	|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_typer`  r  r8  rb  )r   r  )r2  	market_idupperprivatePostSendchildorderr:  r   
safe_order)
r   r   r   r`  r   r  r  r<  r  r   s
             r   create_orderzbitflyer.create_order  s     	 NN622 $

JJLL
 
 //GV0L0LMMf&ABB 
  
   	r   r   c                    |t          | j        dz             |                                  |                     |          |d}|                     |                     ||                    }|                     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>`
        Nz) cancelOrder() requires a symbol argument)r   rb  r  )r   r   r2  r|  privatePostCancelchildorderr:  r  )r   r   r   r  r<  r,  s         r   cancel_orderzbitflyer.cancel_order  s     >#DG.Y$YZZZ NN622)+
 
 33DKK4P4PQQ H 
   	r   statusc                 @    dddddd}|                      |||          S )NrM  closedcanceled)ACTIVE	COMPLETEDCANCELEDEXPIREDREJECTEDr   r   r  statusess      r   parse_order_statuszbitflyer.parse_order_status  s7    !"!"
 
 &&999r   rd  c                 8   |                      |                     |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|          S )Nchild_order_dater  r8  executed_sizeoutstanding_sizechild_order_stater{  r`  r   total_commission)r  currencyraterb  r   clientOrderIdr  rA  rC  lastTradeTimestampr  r   r   r   postOnlyr   r  r   filled)	remainingrf  rS  trades)r   r   r  rg  rW  rx  r  r  )r   rd  r   rA  r  r   r  r  r  r   r`  r   r   rf  feeCostr   s                   r   parse_orderzbitflyer.parse_order  sQ   NN4#3#3E;M#N#NOO	  00!!%00!!%99$$U,>??	(()9)9%AT)U)UVV%%e-?@@%%eV44##E>::!!(F33""5*<==  C
 e%@AA  
" 
T 
 E 
 	 

 Y// 
 !$ 
 f 
 f 
 D 
 4 
  
 D 
 U 
 D 
 D 
  f! 
" f# 
$ #+ 
  
  
, -  	r   r   c                 T   |t          | j        dz             |                                  |                     |          }|d         |d}|                     |                     ||                    }|                     ||||          }||                     |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>`
        Nz) fetchOrders() requires a symbol argumentr   )r   ro  r   )r   r   r2  r   privateGetGetchildordersr:  parse_orders	filter_by)	r   r   rm  r   r  r   r<  r,  orderss	            r   fetch_orderszbitflyer.fetch_orders  s     >#DG.Y$YZZZV$$"4L
 
 00Wf1M1MNN""8VUEBB^^FHf==Fr   c           	      b    ddi}|                      ||||                     ||                    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  r  r  r:  r   r   rm  r   r  r<  s         r   fetch_open_orderszbitflyer.fetch_open_orders  s:      
   t{{7F7S7STTTr   c           	      b    ddi}|                      ||||                     ||                    S )a4  
        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  r  r  r  s         r   fetch_closed_orderszbitflyer.fetch_closed_orders  s:      
   t{{7F7S7STTTr   c                     |t          | j        dz             |                     |          }|                     |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>`
        Nz( 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)  su     >#DG.X$XYYY""6**]]6400
b>!DG&@@2EFFFr   c                 *   |t          | j        dz             |                                  |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     ||||          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>`
        Nz+ fetchMyTrades() requires a symbol argumentr   r   ro  )r   r   r2  r   privateGetGetexecutionsr:  rq  rr  s           r   fetch_my_tradeszbitflyer.fetch_my_trades<  s     >#DG.[$[\\\V$$F4L
 $GG//GV0L0LMM   65%@@@r   symbolsc                     |t          | j        dz             |                                  d|                     |          i}|                     |                     ||                    }|S )as  
        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>`
        NzO fetchPositions() requires a `symbols` argument, exactly one symbol in an arrayr   )r   r   r2  
market_idsprivateGetGetpositionsr:  )r   r  r  r<  r,  s        r   fetch_positionszbitflyer.fetch_positionsb  s|     ?#DG.$  A  A  ADOOG44
 ..t{{7F/K/KLL& r   r/  addresstagc                 p   |                      |           |                                  |dk    r)|dk    r#|dk    rt          | j        dz   |z   dz             |                     |          }|d         |d}|                     |                     ||                    }|                     ||          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_addressr2  r   r   r  privatePostWithdrawr:  parse_transaction)	r   r/  r   r  r  r  r  r<  r,  s	            r   r\   zbitflyer.withdraw  s     	7###5==TU]]tu}}*T TW[ [^q qrrr==&&%d^
 

 ++DKK,H,HII %%h999r   c                     |                                   d}i }||                     |          }|||d<   |                     |                     ||                    }|                     ||||          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>`
        Nro  )r2  r  privateGetGetcoininsr:  parse_transactionsr   r/  rm  r   r  r  r<  r,  s           r   fetch_depositszbitflyer.fetch_deposits  s     	}}T**H$GG,,T[[&-I-IJJ &&x5%HHHr   c                     |                                   d}i }||                     |          }|||d<   |                     |                     ||                    }|                     ||||          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>`
        Nro  )r2  r  privateGetGetcoinoutsr:  r  r  s           r   fetch_withdrawalszbitflyer.fetch_withdrawals  s     	}}T**H$GG--dkk'6.J.JKK" &&x5%HHHr   c                 :    ddd}|                      |||          S Npendingok)PENDINGr  r  r  s      r   parse_deposit_statuszbitflyer.parse_deposit_status  .     
 
 &&999r   c                 :    ddd}|                      |||          S r  r  r  s      r   parse_withdrawal_statusz bitflyer.parse_withdrawal_status  r  r   transactionr  c                 F   |                      |dd          }|                     |d          }|                     |d          }|                     ||          }|                     |                     |d                    }|                     |d          }|                     |d          }	|                     |d          }
d }d }d }d	|v rod
}|                     |
          }|                     |d	          }|                     |d          }||                     t          j        ||                    d}n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S )Nr   
message_idr  r&  
event_dater   tx_hashr  rf  
withdrawaladditional_fee)r  r  depositr  txidrA  rC  network	addressToaddressFromr  tagTotagFromr   r  updated)commentinternalrf  )safe_string_2r   r  r   rx  r  r   r   
string_addr  r  )r   r  r  r   r  r.  r/  rA  r   txId	rawStatusr   r  rf  r  additionalFees                   r   r  zbitflyer.parse_transaction  sT   H T<@@"";	::%%k?CC
&&z8<<NN4#3#3K#N#NOO	!!+x88Y77$$[(;;	KD11)<<F&&{E::G ,,[:JKKM#T->->w?QRY[h?i?i-j-jkkCCD..y99F
K
"
 D
 	

 Y//
 t
 w
 
 4
 4
 T
 t
 D
 f
 
  f!
" t#
$ )
 
 
 	
r   c                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     ||          S )aV  
        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   )r2  r   publicGetGetfundingrater:  parse_funding_rater\  s         r   fetch_funding_ratezbitflyer.fetch_funding_rateM  sr     	V$$F4L
 //GV0L0LMM &&x888r   c                 @   |                      |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 iS )Nnext_funding_rate_settledater  r   	markPrice
indexPriceinterestRateestimatedSettlePricerA  rC  fundingRatefundingTimestampfundingDatetimenextFundingRatecurrent_funding_ratenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r   r   rx  r  )r   r   r   r  r  s        r   r  zbitflyer.parse_funding_ratee  s@    #..x9WXX#~~.ABB
H
d&&vx88
 
 $	

 D
 #D
 
 
 4
 
 t
 t//:PQQ
 #$8
 "4<<0D#E#E
 "4
  '!
" &t#
$ %
 
 	
r   r   GETc                 |   d| j         z   dz   }|dk    r|dz  }||z  }|dk    r|r|d|                     |          z   z  }|                     | j        d         d                   }||z   }	|dk    r|                                  t          |                                           }
d                    |
||g          }|r |dk    r|                     |          }||z  }| j	        |
| 
                    |                     |          |                     | j                  t          j                  d	d
}|	|||dS )Nr   r   zme/r  ?r_   r]    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   pathr_   r  r  r  r  r<  baseUrlr  r	  auths               r   signzbitflyer.sign  sW   $s*)uG4U?? 83!7!777''	%(8(@AA)++---

%%E77E67344D !U??99V,,DDLD"k$)#yyT):):DKK<T<TV]Vdee 2	 G fdwOOOr   reasonr  r  r  r  c
                     |d S | j         dz   |z   }
|                     |d          }|                     |d          }|1|                     | j        d         ||
           t          |
          d S )N error_messager  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  s    47S=4'''/BB&&x::
#001I:W_```)))tr   )NNNN)N)<__name__
__module____qualname__r   r   r   r   r	   r   r   r   r$  r   r0  r4  r  r   r   r>  dictr   rY  r]  r   rl  rs  r   ry  r   r   floatr
   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  intr!  __classcell__)r   s   @r   r    r       s       O# O O O O O ObM M M*V VC V VRU Vjm V  zI V V V V V V $& S S$v, S S S Sj
) 
) 
) 
) 
) $& , ,( , , , ,@ :>b i is i3 iY i i i i& 4  6    6 02 3 33 3f 3 3 3 3$9 9 9v 9 9 9 9 9v 6:UW !A !A3 !As !A# !A\`af\g !A !A !A !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 U3 Uc Ugklqgr U U U U" 154VYbd U U# US UPS Uimnsit U U U U" 26b G Gc G3 G G G G& -1tRV_a $A $Ac $A $AC $A $A $A $AL 26b # #w #T(^ # # # #J KOWY : :S :% :# :C :^i : : : :> *.Dt\^ "I "I3 "Ic "I "Icghsct "I "I "I "IH -1tRV_a $I $Ic $I $IC $Ifjkvfw $I $I $I $IL: : :: : :M
 M
T M
X M
Q\ M
 M
 M
 M
^ 68 9 9 9K 9 9 9 90
 
6 
[ 
 
 
 
< &eBSW P P P 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>r1     s   ( ' ' ' ' ' . . . . . .  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U       * * * * * * . . . . . . * * * * * * * * * * * * 4 4 4 4 4 4 % % % % % %T T T T Tx T T T T Tr   