
    E#iŸ                         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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
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PositionStrStringsTickerFundingRateTradeTradingFeeInterfaceTransactionMarketInterface)List)ExchangeError)ArgumentsRequired)OrderNotFound)OnMaintenance)	TICK_SIZE)Precisec                     ^  \ rS rSrS\4U 4S jjrS rSCS\S\S\S	\S\	4
U 4S
 jjjr
0 4S\\   4S j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SDS\S\S\4S jjr0 4S\S\4S jjrSDS\S\S\4S jjrSS0 4S\S\S\S\\   4S jjr0 4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"S \4S! jr#SDS"\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SS$0 4S\S\S\S\\$   4S' jjr(S0 4S\S\4S( jjr)SSS0 4S\S\S\4S) jjr*S0 4S*\+S\\,   4S+ jjr-S0 4S,\S\S-\S.\S\.4
S/ jjr/SSS0 4S,\S\S\S\\.   4S0 jjr0SSS0 4S,\S\S\S\\.   4S1 jjr1S2 r2S3 r3SDS4\S5\4S\.4S6 jjr50 4S\S\64S7 jjr7SDS\S\64S8 jjr8S9S:0 SS4S; jr9S,\:S<\S=\S>\S?\S@\4SA jr;SBr<U =r=$ )Ebitflyer   returnc                 T  > U R                  [        [        U ]  5       S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_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	_ES,S-S.0S/S0S1.S2/ S3Q0/ S4Q/ S5QS6.S7.S8U R	                  S95      U R	                  S95      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	SA.SS=S S S SSS	SB.S SC.	S S SD.S S SD.SE.SFSG[        00SH.5      $ )INr    bitFlyerJPv1i  zbitflyer.comCORSspotTmarginFswapfutureoptioncancelAllOrderscancelOrdercreateOrderfetchBalancefetchClosedOrdersemulatedfetchCurrencies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getparentorderrS   getpositionsgettradingcommission)sendcoinrI   sendchildordercancelchildordersendparentordercancelparentordercancelallchildorders)rO   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   )ry   limitdaysBack	untilDayssymbolRequired)ry   triggerr   r   )ry   r   r   r   r   )ry   r   r   r   r   r   r   )ry   r   r   daysBackCanceledr   r   r   r   )	sandboxr/   createOrdersr:   r<   r;   r>   r1   
fetchOHLCV)linearinverse)r(   r*   r+   exactz-2)idname	countriesversion	rateLimithostnamehasurlsrL   feesprecisionModefeatures
exceptions)deep_extendsuperr    describeparse_numberr   r   )self	__class__s    U/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/async_support/bitflyer.pyr   bitflyer.describe   sY   h > @&### %# 	#
 $# %# "4# t# t# # $Z# "5#  # #D# *5#  $U!#" "5##$ %#&  '#( ":)#* j+#, !$-#. t/#0 $U1#2 !$3#4 t5#6 t7#8 "49#: #E;#<  =#> !%?#@ #DA#B EC#D DE#J j4 .D  (+.` !..w7!..w7 '  %&+(-,0,1).+06:#'#'"&#'	( #($)$)27+0/4#()$, %)&+!$$(%)*.& ',#($)*.	# ',!$#($)*.( ',!$$(%)#($)*.$ ',!$$(,0%)#($)*.	* #'AAF ##
 ##OKZ -kzC
 z z	    c                     USS nUSS nUSS nSSSSS	S
SSSSSSS.nU R                  XS5      nU R                  US-   U-   S-   U-   S-   5      $ )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_datebitflyer.parse_expiry_date   s    Qqk1QK	a{
   3~~dSj5036<|KLLr   NmarketIdmarket	delimiter
marketTypec                 .   > [         [        U ]  XUS5      $ )Nr(   )r   r    safe_market)r   r   r   r   r   r   s        r   r   bitflyer.safe_market   s     Xt09fUUr   c                   #    U R                  U5      I Sh  vN nU R                  U5      I Sh  vN nU R                  U5      I Sh  vN nU R                  X#5      nU R                  XT5      n/ n[	        S[        U5      5       GHt  nXW   nU R                  US5      n	U	R                  S5      n
U R                  US5      nUS:H  nUS:H  nU(       + =(       a    U(       + nSnSnSnSnSnU(       a%  U R                  U
S5      nU R                  U
S	5      nOU(       a'  S
nU R                  U
S	5      nU R                  U
S5      nOU(       a  U R                  US5      nUc!  U	SS nU	SS nU	SS nU R                  U5      nOaUR                  S5      nU R                  US5      nUSS nUSS nU	R                  U5      nU R                  US	5      nU R                  U5      nSnU R                  U5      nU R                  U5      nUS-   U-   nU R                  S   S   nU R                  S   S   nU=(       d    UnU(       a,  SnSnSnUS-   U-   nU(       a  US-   U R                  U5      -   nUR                  0 SU	_SU_SU_SU_SU_SU_S U_S!S_S"U_SU_S#S$_S
U_SU_S%S$_S&S'_S(U_S)U(       a  SOS'_U(       a  SOS$UUSUU R                  U5      SSSSS*.SSS+.SSS+.SSS+.SSS+.S,.SUS-.E5        GMw     U$  GN GN GN7f).z
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
Nr   product_code_market_typeFXFuturesr(      r*   r   alias      ir+   /rr   rt   rs   g        JPY:r   r   symbolbasequotesettlebaseIdquoteIdsettleIdtyper)   Fr,   activeTcontractr   )amountprice)minmax)r   r   r   cost)r   rt   rs   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   rt   rs   r   s                                  r   fetch_marketsbitflyer.fetch_markets   s      33F;;
"  66v>>
  55f==
 ##J;##G8q#g,'AZF!!&.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 (P U <" ? >s2   LLLLL	L
J9LLLc                 .   SU0n[        S[        U5      5       Hh  nX   nU R                  US5      nU R                  U5      nU R	                  5       nU R                  US5      US'   U R                  US5      US'   XrU'   Mj     U R                  U5      $ )Nr   r   currency_coder   total	availablefree)r  r  r   r  accountsafe_balance)r   responser  r  balance
currencyIdcoder  s           r   parse_balancebitflyer.parse_balance  s    )q#h-(AkG))'?CJ**:6DllnG#//BGG"..wDGFO"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)aI  
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>`
N)load_marketsprivateGetGetbalancer!  )r   r  r  s      r   fetch_balancebitflyer.fetch_balance  sG      !!!226::( !!(+++ 	":s   A	AA	AA	A	r   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   SSSSS5      $  N] N7f)	a  
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
Nr   r   r   bidsasksr   size)r$  r   publicGetGetboardextendparse_order_book)r   r   r   r  r   request	orderbooks          r   fetch_order_bookbitflyer.fetch_order_book  s      !!!V$F4L
 00W1MNN	$$Yx0@$PVX_aghh 	"
 Os!   A8A4?A8A6A86A8tickerc                    U R                  S U5      nU R                  U R                  US5      5      nU R                  US5      nU R                  0 SU_SU_SU R	                  U5      _SS _SS _SU R                  US5      _S	S _S
U R                  US5      _SS _SS _SS _SU_SU_SS _SS _SS _SS _U R                  US5      S US.EU5      $ )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   r3  r   r   r5  rC  s         r   parse_ticker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                    #    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  
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>`
Nr   r   )r$  r   publicGetGettickerr-  rM  r   r   r  r   r/  r  s         r   fetch_tickerbitflyer.fetch_ticker  sq      !!!V$F4L
 00W1MNN  22 	"
 O!   A0A,?A0A.A0.A0tradec                    U R                  US5      nUb  [        U5      S:  a  S nS nUb  US-   nXQ;   a  X   nUc  U R                  US5      nU R                  U R                  US5      5      nU R                  US5      nU R                  US5      nU R                  US5      n	U R	                  S U5      nU R                  U	UUU R                  U5      US	   US US UUS S S
.U5      $ )Nsider   _child_order_acceptance_idchild_order_acceptance_id	exec_dater   r+  r   r   )r   r   r5  r7  r   orderr   rW  takerOrMakerr   r   r   fee)safe_string_lowerr  r   r   r   
safe_trader  )
r   rU  r   rW  r[  idInnerr5  priceStringamountStringr   s
             r   parse_tradebitflyer.parse_trade  s   6 %%eV44y1}99G=$$U,GHENN4#3#3E;#GH	&&ug6''v6eT*!!$/"Y/X&  " 
  	r   sincec                    #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nUb  X6S'   U R                  U R                  Xd5      5      I Sh  vN nU R	                  XuX#5      $  N] N7f)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>`
Nr   r   count)r$  r   publicGetGetexecutionsr-  parse_tradesr   r   re  r   r  r   r/  r  s           r   fetch_tradesbitflyer.fetch_trades)  s      !!!V$F4L
 $G44T[[5QRR   5@@+ 	" S"   A8A4AA8A6A86A8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	                  US5      nUUS   UUSSS.$  Nb N$7f)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>`
Nr   r   commission_rater   )r   r   rs   rt   rF  	tierBased)r$  r   privateGetGettradingcommissionr-  safe_number)r   r   r  r   r/  r  r]  s          r   fetch_trading_feebitflyer.fetch_trading_feeL  s      !!!V$F4L
 <<T[[=YZZ x):;X&
 	
 	"
 [s!   A=A9?A=A;#A=;A=r   rW  r   r   c                 D  #    U R                  5       I Sh  vN   U R                  U5      UR                  5       UR                  5       UUS.nU R                  U R	                  Xv5      5      I Sh  vN nU R                  US5      n	U R                  U	US.5      $  N N,7f)aV  
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>`
N)r   child_order_typerW  r   r+  rY  )r   r   )r$  	market_idupperprivatePostSendchildorderr-  r   
safe_order)
r   r   r   rW  r   r   r  r/  r  r   s
             r   create_orderbitflyer.create_orderk  s      !!! NN62 $

JJL
 55dkk'6RSSf&AB 
  	 	" Ts"   B BAB 1B2+B B r   c                   #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      US.nU R	                  U R                  XC5      5      I Sh  vN nU R                  SU05      $  NS N7f)aO  
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   rY  r   )r   r   r$  rw  privatePostCancelchildorderr-  rz  )r   r   r   r  r/  r  s         r   cancel_orderbitflyer.cancel_order  s      >#DGG.Y$YZZ!!! NN62)+
 99$++g:VWW H 
  	 	"
 Xs!   /B	B;B	-B.B	B	statusc                 6    SSSSSS.nU R                  X!U5      $ )NrA  closedcanceled)ACTIVE	COMPLETEDCANCELEDEXPIREDREJECTEDr   r   r  statusess      r   parse_order_statusbitflyer.parse_order_status  s-    !"!"
 &99r   r[  c                    U R                  U R                  US5      5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  U R                  US5      5      nU R                  US5      n	U R                  US5      n
U R                  US	5      nU R	                  X5      nS nU R                  US
5      nUb  US S S.nU R                  US5      nU R                  0 SU_SS _SU_SU_SU R                  U5      _SS _SU_SU_SU	_SS _SS _SU
_SU_SS _SS _SU_SU_UUS S S.EU5      $ )Nchild_order_dater   r+  executed_sizeoutstanding_sizechild_order_staterv  rW  r   total_commission)r   currencyraterY  r   clientOrderIdr   r5  r7  lastTradeTimestampr  r   r   r   postOnlyrz   r   r   filled)	remainingr]  rG  trades)r   r   r  r^  rK  rr  rz  r  )r   r[  r   r5  r   r   r  r  r  r   rW  r   r   r]  feeCostr   s                   r   parse_orderbitflyer.parse_order  s   NN4#3#3E;M#NO	  0!!%0!!%9$$U,>?	(()9)9%AT)UV%%e-?@%%eV4##E>:!!(3""5*<= C
 e%@A  
" 
T 
 E 
 	 

 Y/ 
 !$ 
 f 
 f 
 D 
 4 
  
 D 
 U 
 D 
 D 
  f! 
" f# 
$ #+ 
, - 	r   r   c                 N  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nUS   US.nU R	                  U R                  Xd5      5      I Sh  vN nU R                  XuX#5      nUb  U R                  USU5      nU$  No N07f)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   rg  r   )r   r   r$  r   privateGetGetchildordersr-  parse_orders	filter_by)	r   r   re  r   r  r   r/  r  orderss	            r   fetch_ordersbitflyer.fetch_orders  s      >#DGG.Y$YZZ!!!V$"4L
 66t{{77STT""8UB^^FHf=F 	" Us"   /B%B!A B%2B#3/B%#B%c           	      h   #    SS0nU R                  XX0R                  XT5      5      I Sh  vN $  N7f)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  Nr  r-  r   r   re  r   r  r/  s         r   fetch_open_ordersbitflyer.fetch_open_orders  s7       
 &&ve[[=YZZZZ   )202c           	      h   #    SS0nU R                  XX0R                  XT5      5      I Sh  vN $  N7f)a  
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  Nr  r  s         r   fetch_closed_ordersbitflyer.fetch_closed_orders  s7       
 &&ve[[=YZZZZr  c                    #    Uc  [        U R                  S-   5      eU R                  U5      I Sh  vN nU R                  US5      nX;   a  XQ   $ [	        U R                  S-   U-   5      e N:7f)am  
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_orderbitflyer.fetch_order  sq      >#DGG.X$XYY((00]]640
>!DGG&@@2EFF	 1s   0A/A-;A/c                 *  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nSUS   0nUb  X6S'   U R	                  U R                  Xd5      5      I Sh  vN nU R                  XuX#5      $  N] N7f)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   rg  )r   r   r$  r   privateGetGetexecutionsr-  ri  rj  s           r   fetch_my_tradesbitflyer.fetch_my_trades(  s      >#DGG.[$[\\!!!V$F4L
 $G55dkk'6RSS   5@@- 	" Ts"   /BBAB8B9BBsymbolsc                    #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   SU R                  U5      0nU R	                  U R                  X25      5      I Sh  vN nU$  NA N7f)aE  
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   r$  
market_idsprivateGetGetpositionsr-  )r   r  r  r/  r  s        r   fetch_positionsbitflyer.fetch_positionsN  s~      ?#DGG.$  A  A!!!DOOG4
 44T[[5QRR& / 	" Ss!   /A7A3:A7,A5-A75A7r   addresstagc                 h  #    U R                  U5        U R                  5       I Sh  vN   US:w  a*  US:w  a$  US:w  a  [        U R                  S-   U-   S-   5      eU R	                  U5      nUS   US.nU R                  U R                  Xu5      5      I Sh  vN nU R                  X5      $  N N7f)	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>`
Nr   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  r  r  r  r/  r  s	            r   rI   bitflyer.withdraws  s      	7#!!!5=TU]tu}*T TW[ [^q qrr==&%d^

 11$++g2NOO %%h99 	" Ps"   %B2B.A0B2B0B20B2c                    #    U R                  5       I Sh  vN   Sn0 nUb  U R                  U5      nUb  X6S'   U R                  U R                  Xd5      5      I Sh  vN nU R	                  XuX#5      $  N] N7f)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>`
Nrg  )r$  r  privateGetGetcoininsr-  parse_transactionsr   r   re  r   r  r  r/  r  s           r   fetch_depositsbitflyer.fetch_deposits  s      !!!}}T*H$G224;;w3OPP &&x5HH- 	" Qrm  c                    #    U R                  5       I Sh  vN   Sn0 nUb  U R                  U5      nUb  X6S'   U R                  U R                  Xd5      5      I Sh  vN nU R	                  XuX#5      $  N] N7f)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>`
Nrg  )r$  r  privateGetGetcoinoutsr-  r  r  s           r   fetch_withdrawalsbitflyer.fetch_withdrawals  s      !!!}}T*H$G33DKK4PQQ" &&x5HH1 	" Rrm  c                 0    SSS.nU R                  X!U5      $ Npendingok)PENDINGr  r  r  s      r   parse_deposit_statusbitflyer.parse_deposit_status  $     
 &99r   c                 0    SSS.nU R                  X!U5      $ r  r  r  s      r   parse_withdrawal_status bitflyer.parse_withdrawal_status  r  r   transactionr  c                    U R                  USS5      nU R                  US5      nU R                  US5      nU R                  XR5      nU R                  U R                  US5      5      nU R	                  US5      nU R                  US5      n	U R                  US5      n
S nS nS nS	U;   a_  S
nU R                  U
5      nU R                  US	5      nU R                  US5      nX`R                  [        R                  " X5      5      S.nOSnU R                  U
5      n0 SU_SU_SU	_SU_SU R                  U5      _SS _SU_SU_SS _SS _SS _SS _SU_SU_SU_SU_SS _S S US.E$ )Nr   
message_idr  r  
event_dater   tx_hashr  r]  
withdrawaladditional_fee)r  r   depositr   txidr5  r7  network	addressToaddressFromr  tagTotagFromr   r  updated)commentinternalr]  )safe_string_2r   r  r   rr  r  r   r   
string_addr  r  )r   r  r  r   r  r  r   r5  r   txId	rawStatusr   r  r]  r  additionalFees                   r   r  bitflyer.parse_transaction  s   H T<@"";	:%%k?C
&&z<NN4#3#3K#NO	!!+x8Y7$$[(;	KD11)<F&&{E:G ,,[:JKM#->->w?Q?QRY?i-jkCD..y9F
K
"
 D
 	

 Y/
 t
 w
 
 4
 4
 T
 t
 D
 f
 
  f!
" 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(  
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>`
Nr   r   )r$  r   publicGetGetfundingrater-  parse_funding_raterQ  s         r   fetch_funding_ratebitflyer.fetch_funding_rate9  ss      !!!V$F4L
 55dkk'6RSS &&x88 	"
 TrT  c                    U R                  US5      nU R                  U5      n0 SU_SU R                  US5      _SS _SS _SS _SS _SS _S	S _S
S _SS _SS _SU R                  US5      _SU_SU R                  U5      _SS _SS _SS _SS 0E$ )Nnext_funding_rate_settledater   r   	markPrice
indexPriceinterestRateestimatedSettlePricer5  r7  fundingRatefundingTimestampfundingDatetimenextFundingRatecurrent_funding_ratenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r   r   rr  r  )r   r   r   r  r  s        r   r  bitflyer.parse_funding_rateQ  s,    #..x9WX#~~.AB
H
d&&vx8
 
 $	

 D
 #D
 
 
 4
 
 t
 t//:PQ
 #$8
 "4<<0D#E
 "4
  '!
" &t#
$ %
 	
r   rp   GETc                 X   SU R                   -   S-   nUS:X  a  US-  nXq-  nUS:X  a  U(       a  USU R                  U5      -   -  nU R                  U R                  S   S   5      nX-   n	US:X  a  U R	                  5         [        U R                  5       5      n
SR                  XU/5      nU(       a  US:w  a  U R                  U5      nX-  nU R                  U
U R                  U R                  U5      U R                  U R                  5      [        R                  5      S	S
.nXXeS.$ )Nr   rq   zme/r  ?rL   rJ    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   pathrL   r  r  r  r  r/  baseUrlr  r  auths               r   signbitflyer.signo  s   $s*)uGU?3!777''		%(8(@A)++-

%E77E734DU?99V,DLD"kk$)#yyT):DKK<TV]VdVde 2	G dOOr   reasonr  r  r  r  c
                     Uc  g U R                   S-   U-   n
U R                  US5      nU R                  US5      nUb*  U R                  U R                  S   X5        [        U
5      eg )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_errorsbitflyer.handle_errors  sn    77S=4'''/B&&x:
#001I:`))r    )NNNN)N)>__name__
__module____qualname____firstlineno__r   r   r   r   r	   r   r   r   r  r   r!  r&  r  r   r   r1  dictr   rM  rR  r   rc  rk  r   rs  r   r   floatr
   r{  r  r  r   r  r  r  r  r  r  r   r   r  r   rI   r  r  r  r  r   r  r   r  r  r#  intr0  __static_attributes____classcell__)r   s   @r   r    r       s#   {# {zM*VC V VRU Vjm V  zI V V *, SV Sj
) 
) *, , ,@ @DB iS i iS\ i&4  6 6 68 3 3F 3$9 9v 9 9v <@d[] !A !AS !A !Abfglbm !AF ;= 
c 
AT 
> mqy{  I Y X] fi < 9=R S # 4: :* *v * *X 04$UXac  C s hlmrhs 4 59tZ]fh [c [ [TW [mqrwmx [" 7;\_hj [ [3 [VY [ostyoz [" 8<B GC G G& 37TX\eg $AC $As $ARU $AL 8<B #W #4PX> #J QU]_ :3 : : :# :do :> 04$UYbd "I "IC "Is "Iimnyiz "IH 37TX\eg $IC $Is $IRU $Ilpq|l} $IL::M
T M
X M
Q\ M
^ <> 9s 9+ 90
6 
[ 
< &eBSW P4
# 
s 
 
c 
TX 
`c 
 
r   r    )% ccxt.async_support.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    r2  r   r   <module>rC     sY    6 .  U  U  U  U  U  U  * . * * 4 %@x @r   