
    ei!V                       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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& 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- d dl m.Z. d dl m/Z/ d dl m0Z0 d dl m1Z1 d dl m2Z2 d dl3m4Z4 d dl3m5Z5 d dl6m7Z7  G d dee          Z8dS )    )Exchange)ImplicitAPIN)AnyBalances
CurrenciesCurrencyDepositAddress	IndexTypeIntLedgerEntryMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersTradeTradingFeeInterfaceTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)NotSupported)DDoSProtection)RateLimitExceeded)ExchangeNotAvailable)OnMaintenance)InvalidNonce)CancelPending)TRUNCATE)	TICK_SIZE)Precisec                       e Zd Zdef fdZd Zi fdee         fdZi fdZ	i fde
fdZdsded	edef fd
Zi fdedefdZd ZdtdededefdZdi fdededefdZdsdededefdZdi fdedefdZi fdedefdZdsdedefdZ dddi fdeded ededee         f
d!Z!d" Z"dsd#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i fd%efd'Z&di fd(ed%ede#fd)Z'dsd*edede(fd+Z)ddi fded ededee(         fd,Z*de+fd-Z,i fde+fd.Z-i fded/e.d0e/fd1Z0i fded0e/fd2Z1di fded3e2d/e.d4e/d5e3f
d6Z4i fd7ee5         fd8Z6d9 Z7d: Z8d;efd<Z9d= Z:dsd>edede;fd?Z<di fd@eded3edAed4e3d5e3fdBZ=ddi fd(eded3e2d/e.d4e3d5e3fdCZ>di fd(edefdDZ?dddi fd(eded edefdEZ@di fdefdFZAdddi fded edefdGZBdi fd(edefdHZCdi fdIee         defdJZDdi fdefdKZEi fdLefdMZFdddi fded ededee;         fdNZGdddi fded ededee;         fdOZHd;efdPZIdQ ZJdsdRed	edeKfdSZLdud%ed edefdTZMdddi fd%ed ededeeK         fdUZNi fdefdVZOdddi fd%ed ededeeK         fdWZPdX ZQi fd%edeRfdYZSi fd%efdZZTi fd%edeRfd[ZUdsd	edeRfd\ZVdi fd%ed4e/d]ed^edeKf
d_ZWdi fdedeeX         fd`ZYdsdaedefdbZZdc Z[i fd%efddZ\i fd%ed4e/deedfede]f
dgZ^dsdhed	ede]fdiZ_djdki ddfdlZ`dm Zad%ebdnedoed@edpedqefdrZc xZdS )vkrakenreturnc                 `   |                      t          t          |                                           i ddddddgddd	d
dddddi dd ddddddddddddddddddddddddddddddd di d!dd"dd#dd$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1di d2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBdi dCddDddEdFdGddHddIddJddKddLddMddNddOddPddQddRddSddTddUdVdWdXdYdZd[d\d]d^d_	d`dadbdbdcdddedfdgdhdidjdd|                     dk          |                     dl          |                     d          |                     dk          g|                     dm          |                     dn          g|                     do          |                     dp          g|                     dq          |                     dr          g|                     ds          |                     dt          g|                     du          |                     dl          g|                     dv          |                     dw          g|                     dx          |                     dy          g|                     dz          |                     d{          gg	|                     d          |                     dl          g|                     dm          |                     dw          g|                     do          |                     dy          g|                     dq          |                     d|          g|                     ds          |                     d}          g|                     du          |                     d~          g|                     dv          |                     d          g|                     dx          |                     d          g|                     dz          |                     d          gg	ddiddddddgiddVdVdddVdVdVdVdd	idi ddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddddddddddddd
iddi ddddddddddddddddddÓddœddǓddɓddddddddΓddГdddddddddٜdddi i g dۢdddޜi ddddddddddddddddddddddddddddddddddi dd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/d0d1d2d3d4dǐd5d6d6d7d8i d9d:d;d<d=d>ddɓd?d@dAdAdBdBdCdDdEdEdFdGdHdIdJdKdLdMdNdOdPdPdQdRdSdTi dUdVddWdddXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldldmdmdndodpdqdrdsdtdudvdwdxdydzd{	i d|d|ddd}dѓd5dǓd
dd~dΓddܓdddd7ddddddddÓddғdudГdkdݓd_d^i ddddddddPddwddddAd[dZd4d3drddddddd7ddddd&d%ddi d,d+ddddd:d9dddd#dd?dd\ddNdddddd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Ȑdɐdddːd̐d͐dΐdϐdАdѐdҐdӐdԐdՐd֜dאdgdٜ	ddddd dddd dddddۜddddddddܜddXddޜdd d d ddߜddddddd ddddd dd d d dddddddid	d d dd d dddt
          di dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          t          t          t          t          t          t          t           t          t"          d	t          t          t          t          t          t$          t&          ddd          S (   Nidr4   nameKraken	countriesUSversion0	rateLimit  	certifiedFproThasCORSspotmarginswapfutureoption	addMargincancelAllOrderscancelAllOrdersAftercancelOrdercancelOrderscreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreateStopLimitOrdercreateStopMarketOrdercreateStopOrdercreateTrailingAmountOrdercreateTrailingPercentOrder	editOrderfetchBalancefetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLedgerEntryfetchLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderTradesemulatedfetchPositionsfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchWithdrawalssetLeveragesetMarginModetransferwithdraw
timeframes            <      i  i`'  i`T  )	1m5m15m30m1h4h1d1w2wurlszdhttps://user-images.githubusercontent.com/51840849/76173629-fc67fb00-61b1-11ea-84fe-f2de582f58a3.jpgzhttps://api.kraken.comz<https://kraken.zendesk.com/api/v2/help_center/en-us/articles)publicprivatezendeskzhttps://www.kraken.comzhttps://docs.kraken.com/rest/z2https://www.kraken.com/en-us/features/fee-schedule)logoapiwwwdocfeesr   tradingz0.0026z0.001650000z0.0024100000z0.0022250000z0.0020500000z0.001810000002500000z0.00145000000z0.001210000000z0.0001z0.0010z0.0008z0.0006z0.0004z0.0002z0.0)takermaker)	tierBased
percentager   r   tiershandleContentTypeApplicationZipr   get360000292886	201893608g333333?)	Assets
AssetPairsDepthOHLCSpreadSystemStatusr   TimeTradespostAddOrderr   AddOrderBatch	AddExport   
AmendOrderBalance	CancelAllCancelAllOrdersAfterCancelOrderCancelOrderBatchClosedOrdersDepositAddressesDepositMethodsDepositStatus	EditOrderExportStatusGetWebSocketsTokenLedgers   
OpenOrdersOpenPositionsQueryLedgersQueryOrdersQueryTradesRetrieveExportRemoveExport	BalanceExTradeBalanceTradesHistoryTradeVolumeWithdrawWithdrawCancelWithdrawInfoWithdrawMethodsWithdrawAddressesWithdrawStatus)
WalletTransferGetApiKeyInfoCreateSubaccountAccountTransferzEarn/AllocatezEarn/DeallocatezEarn/AllocateStatuszEarn/DeallocateStatuszEarn/StrategieszEarn/Allocations)r   r   r   commonCurrenciesLUNALUNCLUNA2REPV2REPREPV1USTUSTCXBTBTCXDGDOGEFEEKFEEXETCETCXETHETHXLTCLTCXMLNMLNXREPXXBTXXDGXXLMXLMXXMRXMRXRPZECAUDCADEURGBPJPYUSD)XXRPXZECZAUDZCADZEURZGBPZJPYZUSDoptions)r  r	  r  r  ERC20TRC20)r   TRX1INCHz1inch (1INCH)AAVEAaveADAALGOAlgorandANKRzANKR (ANKR)ANTzAragon (ANT)ATOMCosmosAXSzAxie Infinity Shards (AXS)BADGERzBager DAO (BADGER)BALzBalancer (BAL)BANDzBand Protocol (BAND)BATBCHzBitcoin CashBNCzBifrost (BNC)BNTzBancor (BNT)BitcoinCHZzChiliz (CHZ)COMPzCompound (COMP)CQTz	Covalent Query Token (CQT)CRVzCurve DAO Token (CRV)CTSIzCartesi (CTSI)DAIDaiDASHDashDogecoinDOTPolkadotDYDXzdYdX (DYDX)ENJzEnjin Coin (ENJ)EOSzEther Classic (Hex)zEther (Hex)EWTzEnergy Web TokenzKraken Fee CreditFILFilecoinFLOWFlowGHSTzAavegotchi (GHST)GNOGRTICXIconINJzInjective Protocol (INJ)KARzKarura (KAR)KAVAKavaKEEPzKeep Token (KEEP)KNCzKyber Network (KNC)KSMKusamaLINKLinkLPTzLivepeer Token (LPT)LRCzLoopring (LRC)LSKLiskLitecoinMANAMATICzPolygon (MATIC)MINAMinaMIRzMirror Protocol (MIR)MKRzMaker (MKR)MOVRzMoonriver (MOVR)NANOOCEANOGNzOrigin Protocol (OGN)OMGOXTzOrchid (OXT)OXYzOxygen (OXY)PAXGz
PAX (Gold)PERPzPerpetual Protocol (PERP)PHAzPhala (PHA)QTUMRARIzRarible (RARI)RAYzRaydium (RAY)RENzRen Protocol (REN)REPv2SANDzThe Sandbox (SAND)SCSiacoinSDNzShiden (SDN)SOLSolanaSNXzSynthetix  Network (SNX)SRMSerumSTORJzStorj (STORJ)SUSHIzSushiswap (SUSHI)TBTCtBTCr  TronUNIUSDCUSDTzTether USD (ERC20)z
USDT-TRC20zTether USD (TRC20)WaveszWrapped Bitcoin (WBTC)zStellar XLMMoneroz
Ripple XRPXTZYFIzZcash (Transparent)z0x (ZRX))	WAVESWBTCr   r  r  ry  rz  r  ZRX	LightningRippleStellarEthereumzArbitrum OneArbitrumPolygonzArbitrum NovaOptimismz
zkSync ErazkSynczEthereum ClassicZcashCardanoQtumTezosNanor{  ICONzPolygon - USDC.ezArbitrum One - USDC.ez
Energy WebEW
CentrifugeCFGKarura	MoonriverShidenKhalazBifrost KusamaSongbirdSGBzTerra classicKILTBasiliskBSXFlareFLRzAvalanche C-ChainAVAXKintsugiKINTAltairAIRMoonbeamGLMRAcalaACAAstarASTRAkashAKT
RobonomicsXRTFantomFTMElrondEGLD	THORchainRUNESecretSCRTNearNEARzInternet Computer ProtocolICPPicassoPICAzCrust ShadowCSM
IntegriteeTEERzParallel FinancePARAHydraDXHDXINTRFETNYMJUNONODLSTXETHWAPTSUIGENSAVTSEIOTPTIA)InterlayzFetch.air  z	Terra 2.0JunoNodleStackszEthereum PoWAptosSuiGenshiroAventusSeiOriginTrailCelestiamarketsByAltnamedelistedMarketsById)	timeDifferenceadjustForTimeDifferencer  r  inactiveCurrenciesnetworksdepositMethodswithdrawMethodsmarketHelperPropsfeatures)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventioniceberg   )minmaxsameSymbolOnly)r  limitdaysBack	untilDayssymbolRequired)r  triggerr  r  )r  r  r  r  r  i )r  r  r  daysBackCanceledr  r  r  r  r    )	sandboxrR   rS   rr   rv   ru   fetchOrdersr^   rs   )linearinverserD   rF   rG   precisionModeg     @zEQuery:Invalid asset pairzEAPI:Invalid keyzEFunding:Unknown withdraw keyzEFunding:Invalid amountzEService:UnavailablezEDatabase:Internal errorzEService:BusyzEQuery:Unknown assetzEAPI:Rate limit exceededzEOrder:Rate limit exceededzEGeneral:Internal errorzEGeneral:Temporary lockoutzEGeneral:Permission deniedz EGeneral:Invalid arguments:priceEOrder:Unknown orderz+EOrder:Invalid price:Invalid price argumentzEOrder:Order minimum not met)	zEOrder:Insufficient fundszEGeneral:Invalid argumentszESession:Invalid sessionzEAPI:Invalid noncezEFunding:No funding methodzEFunding:Unknown assetz!EService:Market in post_only modezEGeneral:Too many requestszETrade:User Locked)z:Invalid orderz:Invalid arguments:volumez:Invalid arguments:viqcz:Invalid noncez:IInsufficient fundsz:Cancel pendingz:Rate limit exceeded)exactbroad)rollingWindowSize
exceptions)deep_extendsuperr4   describeparse_numberr1   r$   r   r&   r%   r,   r*   r    r'   r#   r.   r-   r!   r/   r+   )self	__class__s    I/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/kraken.pyr
  zkraken.describe$   s   fd 3 3 < < > > dA
(dA
HdA
 $dA
 s	dA
 dA
 dA
 4dA
  EEE $E 	E
 %E %E UE "4E 'E tE E 'E /E ,UE 0E  t!E" #E E$ '%E& ('E( "4)E* ,T+E, -d-E. T/E0 1E2 &u3E4 +E5E6 )%7E8 $T9E: ';E< (=E> "4?E@ &tAEB (CED 1%EE E EF  GEH &uIEJ #EKEL *5MEN $UOEP "5QER *5SET +EUEV tWEX #DYEZ %e[E\ ]E^ !%_E`  aEb dcEd +EeEf "4gE E Eh diEj !$kEl #JmEn !$oEp )%qEr tsEt tuEv wEx TyEz t{E| "4}E~ #EE@ #DAEB uCED  EEF DGEH DIE EdA
b 
 
cdA
x ~67] 
 06L
 
ydA
N !%"&!..x88!..x88 "..s33T5F5Fx5P5PQ!..w779J9J89T9TU!..x88$:K:KH:U:UV!..x88$:K:KH:U:UV!..x88$:K:KH:U:UV!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..z::D<M<Mh<W<WX
" "..s33T5F5Fx5P5PQ!..w779J9J89T9TU!..x88$:K:KH:U:UV!..x88$:K:KH:U:UV!..x88$:K:KH:U:UV!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..z::D<M<Me<T<TU
"  OdA
N .tOdA
P  '#	 "#&'!$ #"#()"# !"%   0"A0'0 $Q0 %a	0
 "10 $Q0 /0 &q0 +A0 '0 +A0 )!0 (0 $Q0 '0  -a!0" "1#0 0$ %a%0& ('0( ')0* &q+0, &q-0. )!/00 '102 $Q304 '506 (708 &q90: #A;0< )!=0> '?0@ *1A0B ,QC0D )!E0 0F +,)*,-+,)*+,/012+,,-_0 0 02/J JQdA
f  !! ! 	!
 w! v! u! v! v! ! ! ! ! ! !  !!" #!$ %!& 5! ! !gdA
^ "#+0$&')&B&B&B"" _#6_#F_# 5_# J	_#
 3_# 3_# H_# A_# <_# 5_# <_# 5_# >_# 4_# 3_#  9!_#" 3#_# _#$ 7%_#& C'_#( <)_#* 6+_#, 5-_#. F/_#0 J1_#2 :3_#4 35_#6 77_#8 59_#: :;_#< 2=_#> -?_#@ .A_#B :C_#D FE_# _# _#F 9G_#H 5I_#J 5K_#L 6M_#N ?O_#P 3Q_#R FS_#T 9U_#V :W_#X 8Y_#Z F[_#\ ;]_#^ 5__#` 6a_#b :c_#d Fe_#f 8g_# _# _#h Fi_#j <k_#l 2m_#n 5o_#p 8q_#r Fs_#t Wu_#v <w_#x 5y_#z 3{_#| 3}_#~ 2_#@ AA_#B 2C_#D FE_#F 6G_#H 4I_# _# _#J 9K_#L 7M_#N UO_#P :Q_#R )S_#T 3U_#V 8W_#X ?Y_#Z 7[_#\ 6]_#^ :__#` Fa_#b 6c_#d 5e_#f Fg_#h :i_#j !"@k_# _#l %>(#'  :/}_# _# _#@T$T$uT$ eT$ 	T$
 T$ uT$ T$ #JT$ wT$ $ZT$ 
T$ !(T$ 'T$ UT$ eT$  G!T$" e#T$ T$$ 5%T$& #E'T$( u)T$* F+T$, U-T$. f/T$0 F1T$2 t3T$4 E5T$6 W7T$8 E9T$: ;T$< '=T$> ,Z?T$@ AT$B FCT$D ET$ T$ T$F eGT$H FIT$J !$KT$L FMT$N !%OT$P eQT$R  ST$T eUT$V UWT$X %eYT$Z [T$\ $V]T$^ F_T$` aT$b UcT$d (eT$f gT$ T$ T$h eiT$j kT$l UmT$n VoT$p UqT$r !%sT$t euT$v fwT$x  yT$z f{T$| F}T$~ 1%T$@ vAT$B #ECT$D !&ET$F 'GT$H uIT$ T$J !' % !("##$*"  &$ #( %gT$ T$ T$j '9:O%PAA A_dA
b $&+(-,0,1)-+/6:#'#'"&#(	( ( #($($)+/27/3#')$ $.  !!*.% % ',!%$(%)*/& & ',#($)*/	# # ',!%#($)*/( ( $(&+!%$(,0%+#($)*/	* 	*  #y? ?B ## 
 ## KI IcdA
v YwdA
x ")/&(; 4^ ./@	
 +,@ /0D $%9 +I / 1. ./C 1. 12B 7 +L  B<!" 3L#$ 2C2<0C*62<.79F2@*:5  : '31=/;&2,='4,= ;& &{dA
 dA
 dA
 d d d	    c                 t    |                      |t          | j        |         d         d         | j                  S )N	precisionamount)decimal_to_precisionr0   marketsr  )r  symbolfees      r  fee_to_precisionzkraken.fee_to_precisionK  s2    ((hV8L[8YZb8ceiewxxxr  c                 .   g }|                     |                     |                     | j        d         r'|                     |                                            |}|d         }|                     |di           }|                     | j        di           }t          |                                          }g }t          dt          |                    D ]}	||	         }
||
         }| 	                    |d          }| 	                    |d          }| 
                    |          }| 
                    |          }|}|}|                     |dg           }|                     |dg           }| 	                    |d          }d	}|(|                     t          j        |d
                    }|                     |dg           }|                     |dg           }| 	                    |d          }d	}|(|                     t          j        |d
                    }|                     |dg           }t          |          }|                     |                     | 	                    |d                              }|                     |                     | 	                    |d                              }d}|r*||v r&||         }|                     |d          } | |k    r| }| 	                    |d          }!|!dk    }"|                     i d|
d| 	                    |d          d|dz   |z   d|d|dd	d|d|dd	d|d         ddd|d|dk    d d!d"d!d#d!d$|"d!d	d	||d	d	d	d	d	||d%|                     d&          |                     ||dz
  d          d'|                     |d(          d	d'd	d	d'|                     |d)          d	d'd*d	|d+           |                     |d          | j        d,<   |S )-a2  
        retrieves data on all markets for kraken

        https://docs.kraken.com/rest/#tag/Spot-Market-Data/operation/getTradableAssetPairs

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r  r   resultcachedCurrenciesbasequote
fees_makerr   N100r   leverage_buypair_decimalslot_decimalsTr  statusonliner7   wsIdwsnamer  /settlebaseIdquoteIdsettleIdaltnametyperD   rE   rF   FrG   rH   active)r  price1r  r  ordermincostmin)r  r  r.  cost)contractr  r   r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper  limitscreatedinfor  )appendpublicGetAssetPairsr  load_time_difference	safe_dictlistkeysrangelensafe_stringsafe_currency_code	safe_listr  r2   
string_divparse_precisionsafe_numberindex_by)#r  paramspromises	responsesassetsResponser  r  rB  r  ir7   market	baseIdRaw
quoteIdRawr(  r)  r  r  	makerFeesfirstMakerFeefirstMakerFeeRater   	takerFeesfirstTakerFeefirstTakerFeeRater   leverageBuyleverageBuyLengthprecisionPriceprecisionAmountrD   currencycurrencyPrecisionr"  isActives#                                      r  fetch_marketszkraken.fetch_marketsN  s    0088999<12 	9OOD5577888	"1` ..2>>>>$,8JBOOGLLNN##q#d))$$ W	 W	AaBR[F((88I))&'::J,,Y77F--j99GDEv|R@@I NN9a<<M $ 0 0 B BE ,))'*<=NPU*V*VWWvvr::I NN9a<<M $ 0 0 B BE ,))'*<=NPU*V*VWW..DDK #K 0 0!..t/C/CDDTDTU[]lDmDm/n/nooN"//0D0DTEUEUV\^lEmEm0n0nooOD 8!111+D1$($4$4X{$K$K!$66&7O%%fh77F)HMM 4b4((::4 $*u,4 	4
 4 $4 &4 74 D4 6),4 4 4 ,q04 4 %4  %!4" (#4$ " $"&"-+   $0055#//=NQR=RTUVV! !
  $//
CC# 
  $# 
  $//	BB#  $  g4 4 4 4 4 4 4j ,0==+K+K'(r  c                     |                      |          }|                     |d          }|                     |d          }|dk    rdndddd|dS )aT  
        the latest known information on the availability of the exchange API

        https://docs.kraken.com/api/docs/rest-api/get-system-status/

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `status structure <https://docs.ccxt.com/?id=exchange-status-structure>`
        r  r"  r#  okmaintenanceN)r"  updatedetaurlr<  )publicGetSystemStatusr@  rE  )r  rL  responser  	statusRaws        r  fetch_statuszkraken.fetch_status  sm     --f55 (33$$VX66	(H44dd=
 
 	
r  c                    |                      |          }|                     |di           }t          |                                          }i }t	          dt          |                    D ]m}||         }||         }|                     |          }	|                    d          dk     r{|                     |d          }
||
k    rJ|	                    d          s|	                    d          r |                     |
          }	|	| j
        |<   n|                     |          }	|	                    d          dk    }|                     ||	||                     |d          |                     |d          d	k    |rd
ndddd|                     |                     |                     |d                              dddddddi d          ||	<   o|S )a)  
        fetches all available currencies on an exchange

        https://docs.kraken.com/rest/#tag/Spot-Market-Data/operation/getAssetInfo

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r  r   .r+  XZz.HOLDr"  enabledfiatcryptoNdecimalsr0  )r  r   )r7   coder<  r8   r-  r,  depositr   r  r  r:  r  )publicGetAssets
safe_valuerA  rB  rC  rD  rF  findrE  
startswithr   safe_currency_structurer  rI  )r  rL  ri  
currenciesidsr  rP  r7   r^  rt  altNameisFiats               r  fetch_currencieszkraken.fetch_currencies  s    ''//n __Xx<<
:??$$%%q#c((## 3	 3	AQB!"~H **2..Dwws||a**8Y?? ==bmmC&8&8=BMM#<N<N=227;;D04D)"--22266DYYw''1,F77 ((9==**8X>>)K"(6h !..t/C/CDDTDTU]_iDjDj/k/kll  $# 
  $#! !	 	 +9 9  F4LL. r  N
currencyIdr^  c                 p   ||S |                     d          dk    rp|                    d          }|                     |d          }|                     |d          }t          t          |                               ||          dz   |z   S t          t          |                               ||          S )Nrm  r   r   )rx  splitrE  r	  r4   rF  )r  r  r^  parts	firstPart
secondPartr  s         r  rF  zkraken.safe_currency_code~  s    ??3!##$$S))E((22I))%33J&&99)XNNQTTWaaaVT""55j(KKKr  r  c                    |                                   |                     |          }|d         dd}|                     |                     ||                    }|                     |di           }|                     ||          S )a`  
        fetch the trading fees for a market

        https://docs.kraken.com/rest/#tag/Account-Data/operation/getTradeVolume

        :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>`
        r7   T)pairzfee-infor  )load_marketsrQ  privatePostTradeVolumeextendrw  parse_trading_fee)r  r  rL  rQ  requestri  r  s          r  fetch_trading_feezkraken.fetch_trading_fee  s     	V$$4L
 
 ..t{{7F/K/KLL< 8R88%%ff555r  c                    |                      |di           }|                      |di           }|                      ||d         i           }|                      ||d         i           }||d         |                     t          j        |                     |d          d                    |                     t          j        |                     |d          d                    dddS )	Nr  r   r7   r  r  r  T)r<  r  r   r   r   r   )rw  r  r2   rH  rE  )r  ri  rQ  rT  rW  symbolMakerFeesymbolTakerFees          r  r  zkraken.parse_trading_fee  s    OOHlB??	OOHfb99	F4L"EEF4L"EEX&&&w'9$:J:J>[`:a:ach'i'ijj&&w'9$:J:J>[`:a:ach'i'ijj
 
 	
r  r   r   r  priceKey	amountKeycountOrIdKeyc                     |                      ||          }|                      ||          }|                     |d          }|||gS )Nr  )rJ  safe_integer)r  bidaskr  r  r  r.  r  	timestamps           r  parse_bid_askzkraken.parse_bid_ask  sN      22!!&)44%%fa00	vy))r  r  c                    |                                   |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |di           }|                     ||d                   }|                     |di           }	|                     |	d          }
|
|                     ||
|          }|                     ||          S )aE  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://docs.kraken.com/rest/#tag/Spot-Market-Data/operation/getOrderBook

        :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  r7   Ncountr  r<  r%  )r  rQ  publicGetDepthr  rw  parse_order_book)r  r  r  rL  rQ  r  ri  r  	orderbook
marketInfowsNames              r  fetch_order_bookzkraken.fetch_order_book  s     	V$$F4L
 $GG&&t{{7F'C'CDD( 8R88OOFF4L99	 __VVR88
X66	BBI$$Y777r  tickerrQ  c                    |                      d |          }|                     |dg           }|                     |d          }|                     |dg           }|                     |d          }t          j        ||          }|                     |dg           }	|                     |	d          }
|                     |dg           }|                     |dg           }|                     |dg           }|                     |d	g           }|                     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|          S )Nvr   pcr   hlbar  r  datetimehighlowbid	bidVolumer  ask	askVolumevwapopenocloselastpreviousClosechanger   average)
baseVolumequoteVolumer<  )safe_symbolrw  rE  r2   
string_mulsafe_ticker)r  r  rQ  r  r  r  r  r  r  r  r  r  r  r  r  s                  r  parse_tickerzkraken.parse_ticker  sq    !!$//OOFC,,%%a++
OOFC,,1%%(T::OOFC,,1%%vsB//oofc2..oofc2..oofc2.. !
f!
!
 !
 D$$T1--	!

 4##C++!
 4##C++!
 ))#q11!
 4##C++!
 ))#q11!
 D!
 D$$VS11!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&)!
 !
 !
* +  	r  symbolsc                    |                                   i }||                     |          }g }t          dt          |                    D ]:}||         }| j        |         }|d         r|                    |d                    ;d                    |          |d<   |                     |                     ||                    }|d         }	t          |	
                                          }
i }t          dt          |
                    D ]H}|
|         }|                     |          }|d         }|	|         }|                     ||          ||<   I|                     |d|          S )	a+  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://docs.kraken.com/rest/#tag/Spot-Market-Data/operation/getTickerInformation

        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/?id=ticker-structure>`
        Nr   r-  r7   ,r  r  r  )r  market_symbolsrC  rD  r  r=  joinpublicGetTickerr  rA  rB  safe_marketr  filter_by_array_tickers)r  r  rL  r  	marketIdsrP  r  rQ  ri  tickersr|  r  r7   r  s                 r  fetch_tickerszkraken.fetch_tickers/  sn    	))'22GI1c'll++ 3 3 f-(# 3$$VD\222!hhy11GFO''GV(D(DEE8$7<<>>""q#c((## 	? 	?AQB%%b))FH%FR[F!..vv>>F6NN++FHgFFFr  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|d         |d                  }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://docs.kraken.com/rest/#tag/Spot-Market-Data/operation/getTickerInformation

        :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  r7   r  )r  rQ  r  r  r  )r  r  rL  rQ  r  ri  r  s          r  fetch_tickerzkraken.fetch_tickerP  s     	V$$F4L
 ''GV(D(DEE(#F4L1  000r  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r   r  r      r   )safe_timestamprJ  )r  ohlcvrQ  s      r  parse_ohlcvzkraken.parse_ohlcvc  s     q))UA&&UA&&UA&&UA&&UA&&
 	
r  r   	timeframesincec           	         |                                   d}|                     |dd          \  }}|r|                     d|||||d          S |                     |          }|                     | j        |          }d|d         i}	|||	d<   n||	d<   |8|                     |d	z            }
|d
z  }|                     |
|z
            |	d<   |                     | 	                    |	|                    }| 
                    |di           }|                     ||d         g           }|                     |||||          S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://docs.kraken.com/api/docs/rest-api/get-ohlc-data

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Frs   paginater  r  r7   Nintervalr?   r   r  r  )r  handle_option_and_params"fetch_paginated_call_deterministicrQ  r  r   parse_to_intnumber_to_stringpublicGetOHLCr  rw  rG  parse_ohlcvs)r  r  r  r  r  rL  r  rQ  parsedTimeframer  scaledSincetimeFrameInSecondsri  r  ohlcvss                  r  fetch_ohlcvzkraken.fetch_ohlcvy  so    	88zZZ& 	w::<QVX]_hjpruvvvV$$++DOYGGF4L
 &"1GJ"+GJ++EDL99K!02!5#44[CU5UVVGG%%dkk'6&B&BCC 8R88tb99  E5IIIr  c                 @    dddddd}|                      |||          S )Ntradetransactionr   rE   )r  
withdrawalru  r   rE   rE  )r  r,  typess      r  parse_ledger_entry_typezkraken.parse_ledger_entry_type  s7    '$"
 
 tT222r  itemc                    |                      |d          }d }d }|                      |d          }d }|                     |                      |d                    }|                      |d          }	|                     |	|          }
|                     |	|          }|                      |d          }t	          j        |d          rd}t	          j        |          }nd}|                     |d	d
          }|                     ||||||||
| 	                    |          d | 
                    |d          d||                     |          | 
                    |d          |
dd|          S )Nr7   refidr,  assetr  r=   outintimer?   balancerc  r  r3  r^  )r<  r7   	directionaccountreferenceIdreferenceAccountr,  r^  r  beforeafterr"  r  r  r  )rE  r  rF  safe_currencyr2   	string_lt
string_abssafe_integer_productsafe_ledger_entryr  rJ  iso8601)r  r  r^  r7   r  r  r  r  r,  r  rt  r  r  s                r  parse_ledger_entryzkraken.parse_ledger_entry  s     dD))	&&tW55++D,<,<T6,J,JKK%%dG44
&&z8<<%%j(;;!!$11VS)) 	I'//FFI--dFDAA	%%"& 0''//%%dI66"Y//((u55  '
 '
& '  	r  rt  c                 L   |                                   i }d}| |                     |          }|d         |d<   ||                     |dz            |d<   |                     |ddg          }|X|                     |ddg          }t          j        |d          }|                     t          j        |d	                    |d
<   |                     | 	                    ||                    }	| 
                    |	di           }
| 
                    |
di           }t          |                                          }g }t          dt          |                    D ],}||         }||         }||d<   |                    |           -|                     ||||          S )a  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

        https://docs.kraken.com/rest/#tag/Account-Data/operation/getLedgers

        :param str [code]: unified currency code, default is None
        :param int [since]: timestamp in ms of the earliest ledger entry, default is None
        :param int [limit]: max number of ledger entries to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest ledger entry
        :param int [params.end]: timestamp in seconds of the latest ledger entry
        :returns dict: a `ledger structure <https://docs.ccxt.com/?id=ledger-entry-structure>`
        Nr7   r  r?   startuntiltill1000r/  endr  ledgerr   )r  r^  r  safe_string_nomitr2   rH  
string_addprivatePostLedgersr  rw  rA  rB  rC  rD  r=  parse_ledger)r  rt  r  r  rL  r  r^  r   untilDividedri  r  r  rB  itemsrP  keyvalues                    r  fetch_ledgerzkraken.fetch_ledger  s    	}}T**H'~GG#00>>GG""6GV+<==YYv'899F"-eV<<L!..w/A,PS/T/TUUGEN**4;;w+G+GHH 8R88266FKKMM""q#d))$$ 	  	 Aq'C3KEE$KLL  %???r  c                    |                                   d                    |          }|                     d|i|          }|                     |          }|d         }t	          |                                          }g }t          dt          |                    D ],}	||	         }
||
         }|
|d<   |                    |           -| 	                    |          S )Nr  r7   r  r   )
r  r  r  privatePostQueryLedgersrA  rB  rC  rD  r=  r	  )r  r|  rt  rL  r  ri  r  rB  r  rP  r  r  s               r  fetch_ledger_entries_by_idsz"kraken.fetch_ledger_entries_by_ids  s    hhsmm++#
  //88 (#FKKMM""q#d))$$ 	  	 Aq'C3KEE$KLL  '''r  r7   c                 B    |                      |g||          }|d         S )Nr   )r  )r  r7   rt  rL  r  s        r  fetch_ledger_entryzkraken.fetch_ledger_entry6  s$    00"tVDDQxr  r  c                    d }d }d }d }d }d }d }	d }
d }d }t          |t                    r|                     |d          }|d         dk    rdnd}|d         dk    rdnd	}|                     |d
          }|                     |d          }t	          |          }|dk    r|                     |d          }	nt          |t
                    r|}	nd|v r|                     |d          }|                     |          }||}n||                     |          }|                     |d          }
|                     |dd          }	|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }d|v r%d }||d         }|                     |d          |d}n|                     |d          }|                     |d          }|                     |d          }	|                     |d          }|                     |d          }|                     |d          }|                     |d          }||d         }|                     |d          }| 	                    |d           }d }||rd nd!}|| 
                    |          }n|                     |          }|                     |	|
|||||||||||d"|          S )#Nr  r   ssellbuyr  r  r  rQ  r   r   r   	ordertxidr  r7   postxidr  r,  	ordertyper.  volr  r  r  r  r  trade_idsideord_typeqtyr3  r   r   )r7   orderr<  r  r  r  r,  r  takerOrMakerr.  r  r3  r  )
isinstancerA  r  rE  rD  strfind_market_by_altname_or_idget_delisted_market_by_idsafe_string_2	safe_boolr  	parse8601
safe_trade)r  r  rQ  r  r  r  r,  r.  r  r7   orderIdr  r  tradeLengthmarketIdfoundMarketr^  r3  r   r!  s                       r  parse_tradezkraken.parse_trade:  s   ~ 	eT"" )	4++E155I#Ah#oo66ED$Qx377XD$$UA..E%%eQ//Fe**KQ%%eQ//s##  	4BBE!!''v66H;;HEEK&$%77AA&&uk::G##E4;;B++E6::I##E622D##E;77D$$UG44E%%eU33F~~%%gH ,,UE:: ( 
 %%eX66F''{;;H!!%44B##E622D##E:66D$$UG44E%%eU33FH%Fv..ug..&+877L||I..HHx00I" ( 
  
   	r  c                 &   |                                   |                     |          }|d         }d|i}|.|                     |                     |dz                      |d<   |||d<   |                     |                     ||                    }|d         }	|	|         }
t          |
          }|dk    rg S |
|d	z
           }|                     |	d
          }|                    |           ||
|d	z
  <   | 	                    |
|||          S )a2  
        get the list of most recent trades for a particular symbol

        https://docs.kraken.com/rest/#tag/Spot-Market-Data/operation/getRecentTrades

        :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>`
        r7   r  Nr?   r  r  r  r   r   r  )
r  rQ  r  r  publicGetTradesr  rD  rE  r=  parse_trades)r  r  r  r  rL  rQ  r7   r  ri  r  tradeslength	lastTradelastTradeIds                 r  fetch_tradeszkraken.fetch_trades  s,    	V$$D\B

 #44T5F5Fut|5T5TUUGG$GG''GV(D(DEE (#VQ;;I6A:&	&&vv66%%%&vz  >>>r  c                    |                      |di           }|d d d}t          |                                          }t          dt	          |                    D ]}||         }|                     |          }|                      ||i           }|                                 }	|                     |d          |	d<   |                     |d          |	d<   |	||<   |                     |          S )Nr  )r<  r  r  r   
hold_tradeusedr  total)	rw  rA  rB  rC  rD  rF  r  rE  safe_balance)
r  ri  balancesr  currencyIdsrP  r  rt  r  r  s
             r  parse_balancezkraken.parse_balance  s    ??8Xr::
 

 8==??++q#k**++ 	# 	#A$QJ**:66Dooh
B??GllnnG"..wEEGFO#//CCGG"F4LL  (((r  c                 ~    |                                   |                     |          }|                     |          S )au  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://docs.kraken.com/rest/#tag/Account-Data/operation/getExtendedBalance

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
        )r  privatePostBalanceExr>  )r  rL  ri  s      r  fetch_balancezkraken.fetch_balance
  s?     	,,V44  !!(+++r  r  r3  c                     |                                   d|i}|                     |d||d|                     ||                    S )a3  
        create a market order by providing the symbol, side and cost

        https://docs.kraken.com/rest/#tag/Spot-Trading/operation/addOrder

        :param str symbol: unified symbol of the market to create an order in(only USD markets are supported)
        :param str side: 'buy' or 'sell'
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r3  rQ  N)r  create_orderr  )r  r  r  r3  rL  reqs         r  create_market_order_with_costz$kraken.create_market_order_with_cost&  sT     	 D
   4tT[[QTV\E]E]^^^r  c                 Z    |                                   |                     |d||          S )a  
        create a market buy order by providing the symbol, side and cost

        https://docs.kraken.com/rest/#tag/Spot-Trading/operation/addOrder

        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r  )r  rE  )r  r  r3  rL  s       r  !create_market_buy_order_with_costz(kraken.create_market_buy_order_with_cost9  s0     	11&%vNNNr  r,  r  r.  c           	         |                                   |                     |          }|d         |||                     ||          d}|                     d||||||          }	|                     |	d         dd          }
|
                    d          dk    }|                     |                     |	d         |	d	                             }|                     |d
          }||d<   | 	                    |          S )a:  
        create a trade order

        https://docs.kraken.com/api/docs/rest-api/add-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
        :param bool [params.postOnly]: if True, the order will only be posted to the order book and not executed immediately
        :param bool [params.reduceOnly]: *margin only* indicates if self order is to reduce the size of a position
        :param float [params.stopLossPrice]: *margin only* the price that a stop loss order is triggered at
        :param float [params.takeProfitPrice]: *margin only* the price that a take profit order is triggered at
        :param str [params.trailingAmount]: *margin only* the quote amount to trail away from the current market price
        :param str [params.trailingPercent]: *margin only* the percent to trail away from the current market price
        :param str [params.trailingLimitAmount]: *margin only* the quote amount away from the trailingAmount
        :param str [params.trailingLimitPercent]: *margin only* the percent away from the trailingAmount
        :param str [params.offset]: *margin only* '+' or '-' whether you want the trailingLimitAmount value to be positive or negative, default is negative '-'
        :param str [params.trigger]: *margin only* the activation price type, 'last' or 'index', default is 'last'
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r7   )r  r,  r  volumerR   r   oflags viqcr   r  	usingCost)
r  rQ  amount_to_precisionorder_requestrE  rx  privatePostAddOrderr  r@  parse_order)r  r  r,  r  r  r.  rL  rQ  r  orderRequestflagsisUsingCostri  r  s                 r  rC  zkraken.create_orderG  s   0 	V$$4L..vv>>	
 
 ))-wPVX]_eff  a(B??jj((2-++DKKQVW,Y,YZZ (33){ '''r  ordersc           
         |                                   g }g }d}d}t          dt          |                    D ]2}||         }|                     |d          }	||	}n||	k    rt	          | j        dz             |                     |	          }|                    |	           |                     |d          }
|                     |d          }|                     |d          }|                     |d          }| 	                    |d	i           }||
| 
                    |d         |          d
}|                     d|	|
||||          }|                    |d                    4|                     |dddd          }d}||d         d}|                     ||          }|                     |          }| 	                    |di           }|                     |                     |d                    S )a  
        create a list of trade orders

        https://docs.kraken.com/api/docs/rest-api/add-order-batch/

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr   r  z; createOrders() requires all orders to have the same symbolr,  r  r  r.  rL  )r,  r  rI  rS   FTr7   )rV  r  r  rV  )r  rC  rD  rE  r#   r7   rQ  r=  rw  r@  rO  rP  r  r  privatePostAddOrderBatchparse_ordersrG  )r  rV  rL  ordersRequestsorderSymbolsr  rQ  rP  rawOrderr,  r,  r  r  r.  orderParamsrD  rS  ri  r  r  s                       r  create_orderszkraken.create_orders{  s    	q#f++&& 	3 	3AayH''(;;H~!X%%$TW/l%lmmm[[**F)))##Hf55D##Hf55D__Xx88FOOHg66E..8R@@K!226(3CVLL C
  --nhcSY[`bmnnL!!,q/2222**<udDQQ$4L
 
 ++gv..0099, (B77  !A!ABBBr  c                 |    |                      | j        di           }||v r||         S |                     |          S )Nr  )rw  r  r  )r  r7   r  s      r  r$  z#kraken.find_market_by_altname_or_id  sF    ??4<9KRPP!!!#B''##B'''r  c                    ||S |                      | j        d         |          }||S d}d}d}d}t          |          dk    rd}d}d}nt          |          dk    rd}d}d}|||         }|||         }|                     |          }	|                     |          }
|	dz   |
z   }||	|
||d	}|| j        d         |<   |S )
Nr  r   r   r      r     r&  )r  r  r  r(  r)  )rw  r  rD  rF  )r  r7   rQ  baseIdStart	baseIdEndquoteIdStart
quoteIdEndr(  r)  r  r  r  s               r  r%  z kraken.get_delisted_market_by_id  s
   :I.C!DbIIM	
r77a<<ILJJWW\\ILJK	)*\*,-&&v..''00e#
 
 39*+B/r  r"  c           
      H    dddddddddd	}|                      |||          S )Nr  closedcanceledexpired)	pendingr  pending_newnewpartially_filledfilledrh  ri  rj  r  r  r"  statusess      r  parse_order_statuszkraken.parse_order_status  sC    ! &" 

 

 &&999r  c                 @    dddddd}|                      |||          S )NrQ  r  )take-profit	stop-lossstop-loss-limittake-profit-limittrailing-stop-limitr  rp  s      r  parse_order_typezkraken.parse_order_type  s9     $!&!(#*
 
 &&999r  r   c                    |                      |dd          }|                     |d          }|                     |di           }|                     |d          }d }||                     |d          }n|                     |d          }d }d }d }	d }
d }d }d }||                    d          }|                     |d          }|s|                     |d          }n|                     |d          }|                     |d          }	|                     |d	          }|                     |d
          }|dk    s|dk    r|}n|dz   |z   }|dk    s|dk    r-|                     |d          }|                     |d          }
n|dk    r|                     |d
          }
|                     |d|          }|                     |d|          }|                     |d|	          }	|                     |	          }d }||}n|	|                     |	          }|                     |d          }|                     |d|          }|                     |d          }d }|                     |d|
          }
|
A|
                    d          s*t          j
        |
d          st          j
        |
d          rd }
|
.|                     |d          }
|                     |dd|
          }
|                     |dd          }|                    d          d k    }|                     |d          }|p|d!         }d"|v rd|                     |d"          }|d d#}|                    d$          dk    r|d%         |d&<   n$|                    d'          dk    r|d(         |d&<   |                     |                     |d)                    }|                     |g d*          }||                    d+          r,|                     |d,          }|                     |d          }|                     |d-          }|                     |d.|          }|                     |d/g           }g } t'          dt)          |                    D ]b}!||!         }"t+          |"t,                    r.|                     |                     |"||i d0                     M|                     |"           cd }#d }$||                    d1          r@|                     |d          }$|                     |                     |d                    }
nf|                    d2          r@|                     |d          }#|                     |                     |d                    }
n|dk    r|}$n|dk    r|}#|                     |          }%|                     |%ddg          r|
dnd}%|                     |d3          }&|&d }|                     i d4|d5|d6|d7|d8|                     |          d9d d)|d!|d|%d:d d;|d<|d|
d=|d>|$d?|#d@||||d |                     |dAdB          || dC|          S )DNrN  Fdescrr    r   r   r  r  r   r  rQ  z	stop lossztake profitr   	   r,  r  r  opentmr  vol_execr.  %z0.00000r=   price2
limitpricerJ  rK  r   rM  r  r  )r3  ratefciqr  r^  fcibr  r"  )r7   txidorder_idamend_id[r  userref	cl_ord_idr2  )r7   r*  r  r<  rt  ru  r  r7   clientOrderIdr<  r  r  lastTradeTimestampr  postOnlyr  r  r  r  r3  
reduceOnlyreduce_only)r  ro  r  	remainingr  r  r2  )r'  r  r@  rE  r  r$  r%  r  endswithr2   string_equalsr&  rx  rJ  rr  r  ry  rG  rw  rC  rD  r"  r#  r=  r)  	omit_zerory  in_array
safe_orderr  safe_bool_2)'r  r   rQ  rU  descriptionorderDescriptionObjorderDescriptionr  rawTyper,  r.  r  r3  r  r  part4part5r-  r  r  ro  r  rT  
isPostOnlyr  feeCostr"  r7   r  r  r  	rawTradesr2  rP  rawTrader  r  	finalTypeamendIds'                                          r  rR  zkraken.parse_order  s   F nnUK??		%--nnUGR88"nnUG<<*#//0CWMM#//w??'$**3//E##E1--D 2))%33''q11''q11H$$UA..E$$UA..E5H#4#4#+-+%%M)A)A#//q99((22G##((22VT::"";WEE##KBB77AA" FF!33H==F''x88	!!%77!!%44   gu==ENN3$7$77;PQVXa;b;bfmf{  }B  DG  gH  gHE=$$[(;;E&&ulGUKKE  "55ZZ''",
""5'22H%F~~**5%88#   ::f%%**&,WoC
OOZZ''1,,&,VnC
O(()9)9%)J)JKK'M'M'MNNJBMM#..J>>%00D!!$**B""5)44((WEEOOE8R88	q#i..)) 	( 	(A |H(C(( (dooX"X^hj.k.kllmmmmh''''  !!-00 	-"&"2"2;"H"Ht'7'7X'N'NOO##K00 - $ 0 0g F Ft'7'7X'N'NOOM))".K'' ,))'22	 ==[-$@AA 	A%*]I""5*55J  
" 
] 
 E 
 	 

 Y// 
 !$ 
 f 
 f 
 I 
 4 
 
 
 D 
 U 
 L 
  
  ]! 
" D# 
$ **5,NN1 
  
  
2 3  	r  methodr  c                    |                      |d          }|                     |dg          }|||d<   |                      |d          }	|                      |d          }
|	d u}|
d u}|p|}|                      |d          }|                      |d          }|                      |d          }|                      |d          }|d u}|d u}|                    d	          }|d
k    }|                      |d          }|                      |d          }|                     |ddg          }|d uo|                    d          dk    }|r]||rY|/|-|                     ||                     |                    |d<   n|                     ||          |d<   ||dz   nd}||d<   n|r|s|s|                     ||          |d<   |                     |dd          }|rm|r'|                     ||	          |d<   |rd|d<   n.d|d<   n(|r&|                     ||
          |d<   |rd|d<   nd|d<   |r|                     ||          |d<   n|s|rd }|"|                    d          rd|z   nd|z   dz   }|d|z   nd }|                      |dd          }|||                     |          z   nd }|                      |dd          }||d<   |s||Ad |d<   |-|                    d          r||z   n||z   dz   } ||d<   | |d<   n|
||d<   ||d<   nd!|d<   |||d<   n||d<   |r|d"k    rd#|d<   nd$|d<   |                     |d%          }!|!}| 	                    i |!          }!| 
                    |!d          }"|"|                     ||"          |!d<   | 
                    |!d          }#|#|                     ||#          |!d<   |!|d%<   |                     |d&d'          }$|$|$|d'<   |d
k    }%d }&|                     |%d(|          \  }&}|&r||d)z   nd*}'|'|d<   |	d|vr||d<   |                     |g d+          }||gS ),Nr  r  r  r  trailingAmounttrailingPercenttrailingLimitAmounttrailingLimitPercentr  rQ  r3  rJ  rL  rM  rI  z,viqcr.  r  r  rv  r  ru  rw  rt  r  r  +offset-r  r  rx  ztrailing-stopcreateOrderWsTtruer  r  timeinforceFz,postr   )	r  r  r  r  r  r  r  r  r  )rE  r  r  rx  cost_to_precisionr  price_to_precisionr  r@  r  rw  r&  handle_post_only)(r  r  r  r,  r  r  r.  rL  r  stopLossTriggerPricetakeProfitTriggerPriceisStopLossTriggerOrderisTakeProfitTriggerOrderisStopLossOrTakeProfitTriggerr  r  r  r  isTrailingAmountOrderisTrailingPercentOrderisLimitOrderisMarketOrderr3  rT  isViqcOrderextendedOflagsr  trailingPercentStringtrailingAmountStringr  trailingLimitAmountStringtrailingActivationPriceTypetrailingLimitPercentStringr  
closePriceclosePrice2r  isMarketr  extendedPostFlagss(                                           r  rP  zkraken.order_request  s   ((AA6O#455$#0GK #//HH!%!1!1&:K!L!L!5T!A#9#E (>(ZBZ%))&2BCC**63DEE"..v7LMM#//8NOO .d :!0!<}}W--(//  226FH#566D(Guzz&/A/AB/F 	Fd.+.|!3$($:$:64CXCXY_C`C`$a$a!!$($:$:64$H$H!161BUW__N .GH 	F"7 	F@V 	F#66vuEEGG%%flMJJ
( &	<% 9#'#:#:6CW#X#X  7+<GK((+6GK(() 9#'#:#:6CY#Z#Z  9+>GK((+8GK( K$($;$;FE$J$J!" 	<&< 	<$(!*DSD\D\]`DaDa  )F)>)>ilo~i~  BE  jE%<J<V3#7#7]a %%fh<<F`s`1F1FGZ1[1[([([  GK%*.*:*:69f*U*U'!<GI < 3 ?EYEe'<$'3UiUrUrsvUwUw  2d&;O2O2O  @F  I]  @]  `c  @c.'<GG$(BGH%%(4';GG$(AGH%'6$".'<GG$$';GG$ 	0(()-&&)/&vw//KKE**E88J%!%!8!8!L!Lg//%::K&"&"9"9&+"N"Nh$GG((NN"%0GM"H$005&II& 	2494EF 1GHG(;(; %GH6  $C  $C  $C  D  D  r  c                    |                                   |                     |          }|d         s#t          | j        dz   |d         z   dz             d|i}	|                     |dd          }
|
3|
|	d<   |                     |ddg          }|                     |	d          }	|d	k    }d}|                     |d
|          \  }}|rd|	d<   ||                     ||          |	d<   ||                     ||          |	d<   | 	                    |g d          }|T| 
                    |d          }|                     |g d          }|||z   }||	d<   n|                     ||          |	d<   |                     |                     |	|                    }|                     |di           }|                     ||          S )aL  
        edit a trade order

        https://docs.kraken.com/api/docs/rest-api/amend-order

        :param str id: order id
        :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 the currency you want to trade in units of the 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
        :param float [params.stopLossPrice]: the price that a stop loss order is triggered at
        :param float [params.takeProfitPrice]: the price that a take profit order is triggered at
        :param str [params.trailingAmount]: the quote amount to trail away from the current market price
        :param str [params.trailingPercent]: the percent to trail away from the current market price
        :param str [params.trailingLimitAmount]: the quote amount away from the trailingAmount
        :param str [params.trailingLimitPercent]: the percent away from the trailingAmount
        :param str [params.offset]: '+' or '-' whether you want the trailingLimitAmount value to be positive or negative
        :param boolean [params.postOnly]: if True, the order will only be posted to the order book and not executed immediately
        :param str [params.clientOrderId]: the orders client order id
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        rD   z editOrder() does not support r,  z& orders, only spot orders are acceptedr  r  r  NrQ  Fr  	post_only	order_qtylimit_price)r  r  r  r  r  r  r  )r  r  r  r  r  r  r  trigger_pricer  )r  rQ  r)   r7   r&  r  r  rO  r  r  rE  privatePostAmendOrderr  r@  rR  )r  r7   r  r,  r  r  r.  rL  rQ  r  r  r  r  allTriggerPricesr  ri  r  s                    r  
edit_orderzkraken.edit_orderU  s?   0 	V$$f~ 	Gtw)IIFSYNZ  ^F   F  G  G  GB
 **6?KPP$#0GK YYv'EFFFii00GH$005&II& 	*#)GK #'#;#;FF#K#KGK %)%<%<VU%K%KGM"--f  7o  7o  7o  p  p'%%fh77FYYv  (j  (j  (j  k  kF!#),<#< +;((+/+B+B6K[+\+\(--dkk'6.J.JKK (B77///r  c                    |                                   |                     |dd          }d|d}|}|||d<   |                     |ddg          }|                     |                     ||                    }|                     |dg           }||vrt          | j        dz   |z             |                     |                     d|i||                             S )	a  
        fetches information on an order made by the user

        https://docs.kraken.com/rest/#tag/Account-Data/operation/getOrdersInfo

        :param str id: order id
        :param str symbol: not used by kraken fetchOrder
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        r  r  Tr2  r  Nr  z& fetchOrder() could not find order id r7   )	r  safe_value_2r  privatePostQueryOrdersr  rw  r(   r7   rR  )	r  r7   r  rL  r  r  queryri  r  s	            r  fetch_orderzkraken.fetch_order  s     	))&)_MM
 

 $!.GIIIfy/&BCCE..t{{7E/J/JKKL 8R88f*R RUW WXXXT2Jr
 C CDDDr  c                    |                      |d          }g }|t          | j        dz             t          dt	          |                    D ]P}||         }	t          |	t                    r|                    |	           5|                    |	d                    Q|                                  || 	                    |          }|                      | j
        di           }
|                     |
dd          }t	          |          }|                     ||z            }|                     |d	          }g }t          d|          D ]0}g }t          d|          D ]<}|                     ||z  |          }||k     r|                    ||                    =d
d                    |          i}|                     |          }|                      |d          }t!          |                                          }t          dt	          |                    D ]}||         |||                  d<   |                     |d||          }|                     ||          }|                     ||          }2|S )a%  
        fetch all the trades made from a single order

        https://docs.kraken.com/rest/#tag/Account-Data/operation/getTradesInfo

        :param str id: order id
        :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 to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        r2  Nz fetchOrderTrades() requires a unified order structure in the params argument or a 'trades' param(an array of trade id strings)r   r7   rx   	batchSize   r   r  r  r  )rw  r"   r7   rC  rD  r"  r#  r=  r  r  r  r  r  sumr  privatePostQueryTradesrA  rB  r1  filter_by_symbolarray_concat)r  r7   r  r  r  rL  orderTradestradeIdsrP  
orderTrader  r  numTradeIds
numBatchesr  j
requestIdskindexr  ri  r  r|  r2  tradesFilteredBySymbols                            r  fetch_order_tradeszkraken.fetch_order_trades  s    oofh77#DG  /p  %p  q  q  q1c+..// 6 6(^
j#.. 6OOJ////OOJt$45555[[((F//$,0BBGG%%g{B??	(mm&&{Y'>??
XXj!,,
q*%% %	G %	GAJ1i(( 7 7Y22;&&%%huo666,,G 227;;H, (;;Iy~~''((C1c#hh'' 1 1*-a&	#a&!$''&&y$uEEF%)%:%:66%J%J"&&v/EFFFFr  c                     |                                   |                     |                     dd                    |          d|                    }|                     |di           }g }t          |                                          }t          dt          |                    D ]R}||         }	||	         }
| 	                    |                     d|	i|
                    }|
                    |           S|S )a  
        fetch orders by the list of order id

        https://docs.kraken.com/rest/#tag/Account-Data/operation/getClosedOrders

        :param str[] [ids]: list of order id
        :param str [symbol]: unified ccxt market symbol
        :param dict [params]: extra parameters specific to the kraken api endpoint
        :returns dict[]: a list of `order structure <https://docs.ccxt.com/?id=order-structure>`
        Tr  r  r  r   r7   )r  r  r  r  rw  rA  rB  rC  rD  rR  r=  )r  r|  r  rL  ri  r  rV  orderIdsrP  r7   r  r   s               r  fetch_orders_by_idszkraken.fetch_orders_by_ids!	  s     	..t{{HHSMM<
 <
 0 0   8R88&&q#h--(( 	! 	!A!B":D$$T[[$T%B%BCCEMM%    r  c                    |                                   i }||                     |dz            |d<   |                     |ddg          }|X|                     |ddg          }t	          j        |d          }|                     t	          j        |d                    |d<   |                     |                     ||                    }|d	         d
         }	t          |	
                                          }
t          dt          |
                    D ]}|
|         |	|
|                  d<   d}||                     |          }|                     |	|||          S )a  
        fetch all trades made by the user

        https://docs.kraken.com/api/docs/rest-api/get-trade-history

        :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
        :param int [params.until]: timestamp in ms of the latest trade entry
        :param int [params.end]: timestamp in seconds of the latest trade entry
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Nr?   r  r   r  r  r/  r  r  r2  r   r7   )r  r  r  r  r2   rH  r  privatePostTradesHistoryr  rA  rB  rC  rD  rQ  r1  )r  r  r  r  rL  r  r   r
  ri  r2  r|  rP  rQ  s                r  fetch_my_tradeszkraken.fetch_my_trades;	  se    	
 #00>>GG""6GV+<==YYv'899F"-eV<<L!..w/A,PS/T/TUUGEN00Wf1M1MNN: (#H-6;;==!!q#c((## 	* 	*A#&q6F3q6N4  [[((F  >>>r  c                 \   |                                   d}|                     |d|          }|                     |d          }d|i}|                     |dd          }|3||d<   |                     |ddg          }|                     |d          }	 |                     |                     ||                    }nX# t          $ rK}| j        r=| j                            d          dk    rt          | j
        dz   | j        z             |d}~ww xY w|                     d	|i          S )
a  
        cancels an open order

        https://docs.kraken.com/api/docs/rest-api/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
        :param str [params.clientOrderId]: the orders client order id
        :param int [params.userref]: the orders user reference id
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr  r  r  r  r  r   z cancelOrder() error r<  )r  rw  r  r&  privatePostCancelOrderr  	Exceptionlast_http_responserx  r(   r7   r  )	r  r7   r  rL  ri  	requestIdr  r  es	            r  cancel_orderzkraken.cancel_order~	  sZ    	OOFIr::	69--I
 **6?KPP$#0GK YYv'EFFFii00G	224;;w3O3OPPHH  	 	 	& e*//0FGG1LL'2I(IDLc(cdddG		
 H 
   	s   )B? ?
D	ADDr|  c                     d|i}|                      |                     ||                    }|                     d|i          gS )a  
        cancel multiple orders

        https://docs.kraken.com/rest/#tag/Spot-Trading/operation/cancelOrderBatch

        :param str[] ids: open orders transaction ID(txid) or user reference(userref)
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        rV  r<  )privatePostCancelOrderBatchr  r  )r  r|  r  rL  r  ri  s         r  cancel_orderszkraken.cancel_orders	  sZ     c
 33DKK4P4PQQ OO  
 	
r  c                     |                                   |                     |          }|                     d|i          gS )a  
        cancel all open orders

        https://docs.kraken.com/rest/#tag/Spot-Trading/operation/cancelAllOrders

        :param str symbol: unified market symbol, not used by kraken cancelAllOrders(all open orders are cancelled)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        r<  )r  privatePostCancelAllr  )r  r  rL  ri  s       r  cancel_all_orderszkraken.cancel_all_orders	  sP     	,,V44 OO  
 	
r  timeoutc                     |dk    rt          | j        dz             |                                  d|dk    r|                     |dz            ndi}|                     |                     ||                    }|S )at  
        dead man's switch, cancel all orders after the given timeout

        https://docs.kraken.com/rest/#tag/Spot-Trading/operation/cancelAllOrdersAfter

        :param number timeout: time in milliseconds, 0 represents cancel the timer
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: the api result
        i \&zG cancelAllOrdersAfter timeout should be less than 86400000 millisecondsr  r   r?   )r#   r7   r  r  privatePostCancelAllOrdersAfterr  )r  r  rL  r  ri  s        r  cancel_all_orders_afterzkraken.cancel_all_orders_after	  s     XTW'ppqqqw{{))'D.999QR
 77GV8T8TUU r  c                 @   |                                   i }||                     |dz            |d<   |                     |d          }|||d<   |                     |d          }|                     |d          }|||d<   |                     |d          }|                     |                     ||                    }d}	||                     |          }	|                     |di           }
|                     |
di           }g }t          |
                                          }t          d	t          |                    D ]=}||         }||         }|                    |                     d
|i|                     >|                     ||	||          S )a  
        fetch all unfilled currently open orders

        https://docs.kraken.com/api/docs/rest-api/get-open-orders

        :param str [symbol]: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of  open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.clientOrderId]: the orders client order id
        :param int [params.userref]: the orders user reference id
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nr?   r  r  r  r  r  r  r   r7   )r  r  r  r  rE  privatePostOpenOrdersr  rQ  r@  rA  rB  rC  rD  r=  rY  )r  r  r  r  rL  r  r  r  ri  rQ  r  r  rV  r  rP  r7   r  s                    r  fetch_open_orderszkraken.fetch_open_orders	  s    	#00>>GG##FI66!(GIYYvy11F((AA$#0GK YYv77F--dkk'6.J.JKKL [[((F(B77~~ffb11		$$q#h--(( 	9 	9A!B8DMM$++tRj$778888  >>>r  c                 t   |                                   i }||                     |dz            |d<   |                     |d          }|||d<   |                     |d          }|                     |d          }|||d<   |                     |d          }|                     d||          \  }}|                     |                     ||                    }d}	||                     |          }	| 	                    |di           }
| 	                    |
d	i           }g }t          |                                          }t          d
t          |                    D ]=}||         }||         }|                    |                     d|i|                     >|                     ||	||          S )a	  
        fetches information on multiple closed orders made by the user

        https://docs.kraken.com/api/docs/rest-api/get-closed-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
        :param int [params.until]: timestamp in ms of the latest entry
        :param str [params.clientOrderId]: the orders client order id
        :param int [params.userref]: the orders user reference id
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nr?   r  r  r  r  r  r  rh  r   r7   )r  r  r  r  rE  handle_until_optionprivatePostClosedOrdersr  rQ  r@  rA  rB  rC  rD  r=  rY  )r  r  r  r  rL  r  r  r  ri  rQ  r  rh  rV  r  rP  r7   r  s                    r  fetch_closed_orderszkraken.fetch_closed_ordersJ
  s    	#00>>GG##FI66!(GIYYvy11F((AA$#0GK YYv77F225'6JJ//GV0L0LMMP [[((F(B77"55&&q#h--(( 	9 	9A!B":DMM$++tRj$778888  >>>r  c                 B    ddddddd}|                      |||          S )Nrk  rc  failed)InitialPendingSuccessSettledFailurePartialr  rp  s      r  parse_transaction_statuszkraken.parse_transaction_status
  s<     !  
 
 &&999r  c                 h    |                      | j        di           }|                     |||          S )Nr  )rw  r  rE  )r  networkr  s      r  parse_networkzkraken.parse_network
  s2    //$,8I2NN'BBBr  r  c                 D   |                      |d          }|                      |d          }|                     |d          }|                      |d          }|                     ||          }|                      |d          }|                     |d          }	|                     |                      |d                    }
|                      |d          }|d	k    }|d
k    }|dk    }|s|s|rd}
|                      |d          }|                     |d          }||dk    r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S )Nr  r  r  r  r<  r  r"  zstatus-propzon-holdzcancel-pendingonholdrk  r,  r  ru  r   r7   r^  r  address	addressToaddressFromtagtagTotagFromre  r  r  )r^  r3  )commentinternalr  )rE  r  rF  rJ  r  r  r  )r  r  r^  r7   r  r  r  rt  r  r  r"  
statusPropisOnHoldDepositisCancellationRequestisOnHoldWithdrawalr,  r  s                    r  parse_transactionzkraken.parse_transaction
  sp   z k733V44''V<<	%%k7;;
&&z8<<"";77!!+x88..t/?/?X/V/VWW%%k=AA
$	1 *.> >'83 	3 	7I 	FV44"";66?y  
K
"
 
 f	

 t))$*:*:;	*R*RSS
 w
 
 4
 4
 T
 t
 f
 D
 t
 D
  !
" Y//#
$   )
 
 
 	
r  c                    g }t          dt          |                    D ]H}|                     |                     d|i||                             }|                    |           I|                     ||||          S )Nr   r,  )rC  rD  r  r  r=  filter_by_currency_since_limit)	r  r,  transactionsrt  r  r  r  rP  r  s	            r  parse_transactions_by_typez!kraken.parse_transactions_by_type  s    q#l++,, 	' 	'A00>A2  2  ! !K MM+&&&&2264NNNr  c                    |                                   i }| |                     |          }|d         |d<   |-|                     |          }t          j        |d          |d<   |                     |ddg          }|E|                     |ddg          }t          j        |d          }	t          j        |	d          |d	<   |                     | 	                    ||                    }
| 
                    d
|
d         |||          S )a  
        fetch all deposits made to an account

        https://docs.kraken.com/rest/#tag/Funding/operation/getStatusRecentDeposits

        :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
        :param int [params.until]: timestamp in ms of the latest transaction entry
        :param int [params.end]: timestamp in seconds of the latest transaction entry
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        Nr7   r  r  r  r   r  r/  r  ru  r  )r  r^  r  r2   rH  r  r  r  privatePostDepositStatusr  r#  )r  rt  r  r  rL  r  r^  sinceStringr   r
  ri  s              r  fetch_depositszkraken.fetch_deposits  s    	}}T**H'~GG//66K&1+vFFGG""6GV+<==YYv'899F"-eV<<L$/cBBGEN00Wf1M1MNN ..y(8:LdTY[`aaar  c                     |                      |          }|                     |di           }|                     |d          S )ag  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://docs.kraken.com/rest/#tag/Spot-Market-Data/operation/getServerTime

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        r  unixtime)publicGetTimerw  r  )r  rL  ri  r  s       r  
fetch_timezkraken.fetch_timeJ  sD     %%f-- 8R88""6:666r  c           	         |                                   d}|                     |dd          \  }}|r d|d<   |                     d||||dd          S i }| |                     |          }|d         |d	<   |-|                     |          }t          j        |d
          |d<   |                     |ddg          }	|	E|                     |ddg          }t          j        |	d
          }
t          j	        |
d          |d<   | 
                    |                     ||                    }d}|                     |d          }t          |t                    s|                     |          }n|}|                     d||||          S )aY  
        fetch all withdrawals made from an account

        https://docs.kraken.com/rest/#tag/Funding/operation/getStatusRecentWithdrawals

        :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
        :param int [params.until]: timestamp in ms of the latest transaction entry
        :param int [params.end]: timestamp in seconds of the latest transaction entry
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        Fr   r  Tcursornext_cursorNr7   r  r  r  r   r  r/  r  r  r  )r  r  fetch_paginated_call_cursorr^  r  r2   rH  r  r  r  privatePostWithdrawStatusr  rw  r"  rA  add_pagination_cursor_to_resultr#  )r  rt  r  r  rL  r  r  r^  r&  r   r
  ri  rawWithdrawalsr  s                 r  fetch_withdrawalszkraken.fetch_withdrawalsa  s    	88ASU_``& 	}#F8334FeUZ\bdqs{|||}}T**H'~GG//66K&1+vFFGG""6GV+<==YYv'899F"-eV<<L$/cBBGEN11$++gv2N2NOON 844&$'' 	$!AA&IINN#N..|^TSXZ_```r  c                     |                      |d          }|                     |d          }t          |          }||dk    r||dz
           }||d<   |||dz
  <   |S )Nr.  withdrawalsr   r   )rE  rw  rD  )r  r  r-  data
dataLengthr  s         r  r1  z&kraken.add_pagination_cursor_to_result  sn    !!&-88v}55YY
*q..
Q'D"(D#'Da r  c                 ^    ddi}|                      ||                     ||                    S )a  
        create a currency deposit address

        https://docs.kraken.com/rest/#tag/Funding/operation/getDepositAddresses

        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/?id=address-structure>`
        rm  r  )fetch_deposit_addressr  )r  rt  rL  r  s       r  create_deposit_addresszkraken.create_deposit_address  s6     6
 ))$GV0L0LMMMr  c                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d          S )aO  
        fetch deposit methods for a currency associated with self account

        https://docs.kraken.com/rest/#tag/Funding/operation/getDepositMethods

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the kraken api endpoint
        :returns dict: of deposit methods
        r  r7   r  )r  r^  privatePostDepositMethodsr  rw  )r  rt  rL  r^  r  ri  s         r  fetch_deposit_methodszkraken.fetch_deposit_methods  sp     	==&&Xd^
 11$++gv2N2NOO0 x222r  c                 6   |                                   |                     |          }|                     |d          }|                     | j        di           }|                     |||          }|                     |d          }|dk    r|dk    r|dz   |z   }|                     | j        di           }|                     ||          }|                     |d|          }||                     |          }	|Yt          d	t          |	                    D ];}
|                     |	|
         d          }|
                    |          d	k    r|} n<|-|                     |	d	i           }|                     |d          }|d
         |d}|                     |                     ||                    }|                     |dg           }|                     |d	i           }|t          | j        dz   |z             |                     ||          S )a  
        fetch the deposit address for a currency associated with self account

        https://docs.kraken.com/rest/#tag/Funding/operation/getDepositAddresses

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/?id=address-structure>`
        r  r  rv  r  r  r  r  Nr   r7   )r  r  r  z9 privatePostDepositAddresses() returned no addresses for )r  r^  safe_string_upperrw  r  rE  r  r=  rC  rD  rx  privatePostDepositAddressesr  r&   r7   parse_deposit_address)r  rt  rL  r^  r  r  defaultDepositMethodsdefaultDepositMethoddepositMethodr  rP  entryfirstDepositMethodr  ri  r  firstResults                    r  r9  zkraken.fetch_deposit_address  s:    	==&&((;;??4<R@@""8Wg>>69--FNNG!3!3#:'D $>NPR S S#//0EtLL((;OPP  !77==N"q#n"5"566  A ,,^A->IIEzz'**a//(- 0 $%)__^Q%K%K" $ 0 01CX N Nd^#
 
 33DKK4P4PQQ 8R88oofa44 +f!fim!mnnn))+x@@@r  c                     |                      |d          }|                      |d          }|                     d |          }|d         }|                     |           ||d ||dS )Nr  r  rt  )r<  r^  r  r  r  )rE  r  check_address)r  depositAddressr^  r  r  rt  s         r  rA  zkraken.parse_deposit_address*  s     "">9==~u55%%dH557###"
 
 	
r  r  r  c                    |                      ||          \  }}d|v r|                                  |                     |          }|d         |d}| |dk    r||d<   |                     |           |                     |                     ||                    }|                     |di           }	|                     |	|          S t          | j	        dz             )	a  
        make a withdrawal

        https://docs.kraken.com/rest/#tag/Funding/operation/withdrawFunds

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to, not required can be '' or None/none/None
        :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  r7   )r  r  NrK  r  r  zO withdraw() requires a 'key' parameter(withdrawal key name, up on your account))
handle_withdraw_tag_and_paramsr  r^  rI  privatePostWithdrawr  r@  r  r   r7   )
r  rt  r  r  r  rL  r^  r  ri  r  s
             r  r   zkraken.withdraw>  s     99#vFFVF??}}T**H!$  G
 "w"}}%,	"""7+++//GV0L0LMMH ^^Hh;;F))&(;;;DG&wwxxxr  c                 8   |                                   ddd}|                     |                     ||                    }|                     |          }|                     |d          }|                     ||          }|                     |d|d          S )a~  
        fetch all open positions

        https://docs.kraken.com/rest/#tag/Account-Data/operation/getOpenPositions

        :param str[] [symbols]: not used by kraken fetchPositions()
        :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>`
        r  rQ  )docalcsconsolidationr  r  F)r  privatePostOpenPositionsr  r  rG  parse_positionsfilter_by_array_positions)r  r  rL  r  ri  r  resultss          r  fetch_positionszkraken.fetch_positionsd  s     	 %
 

 00Wf1M1MNN\ %%g..(33&&vw77--gx%PPPr  positionc                    |                      |d          }|                      |d          }|dk    r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 d|dd dd d d d d d |                     |d          d |                     |d          d d d d          S )Nr  r,  r  longshortr<  r7   r  notionalr  liquidationPrice
entryPriceunrealizedPnlnetrealizedPnlr   	contractsr  r5  	markPrice	lastPricer  r  r  rE   r  )r  lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager  marginRatior  r  )rE  safe_positionr  rJ  )r  rV  rQ  r,  rawSider  s         r  parse_positionzkraken.parse_position  s    ##Hf55""8V44!U**vv!! #
H#
$#
 d&&x88#
 	#

 $#
 #
 $#
 T--h>>#
 4#
 $#
 ))(E::#
 D#
 #
 #
 D#
  d!#
" ##
$ #'!%+/!--hAA'+((:>>!#9#
 #
 #
   	r  c                 <    dddd}|                      |||          S )NSpot WalletzFutures Walletr  r  )r  r  accountByTypes      r  parse_account_typezkraken.parse_account_type  s1    !$&
 

 w@@@r  c                 4    |                      ||dd|          S )a  
        transfer from spot wallet to futures wallet

        https://docs.kraken.com/rest/#tag/User-Funding/operation/walletTransfer

        :param str code: Unified currency code
        :param float amount: Size of the transfer
        :param dict [params]: Exchange specific parameters
        :returns: a `transfer structure <https://docs.ccxt.com/?id=transfer-structure>`
        rD   rF   )r   )r  rt  r  rL  s       r  transfer_outzkraken.transfer_out  s     }}T6666BBBr  fromAccount	toAccountc                    |                                   |                     |          }|                     |          }|                     |          }|                     ||          |||d         d}|dk    r#t	          | j        dz   |z   dz   |z   dz             |                     |                     ||                    }|                     ||          }	|                     |	|||d          S )a  

        https://docs.kraken.com/rest/#tag/User-Funding/operation/walletTransfer

        transfers currencies between sub-accounts(only spot->swap direction is supported)
        :param str code: Unified currency code
        :param float amount: Size of the transfer
        :param str fromAccount: 'spot' or 'Spot Wallet'
        :param str toAccount: 'swap' or 'Futures Wallet'
        :param dict [params]: Exchange specific parameters
        :returns: a `transfer structure <https://docs.ccxt.com/?id=transfer-structure>`
        r7   )r  fromtor  rn  z transfer cannot transfer from z to zA. Use krakenfutures instead to transfer from the futures account.)r  rs  rt  )	r  r^  rp  currency_to_precisionr#   r7   privatePostWalletTransferr  parse_transfer)
r  rt  r  rs  rt  rL  r^  r  ri  r   s
             r  r   zkraken.transfer  s&    	==&&--k::++I66	00v>>d^	
 
 -''TW'HH;VY__bkk  or  r  s  s  s11$++gv2N2NOO &&x::{{8&"&
 &
   	r  r   c           
          |                      |di           }|                     |d          }||d d |                     |d          d d d dd	S )Nr  r  rt  sucess)	r<  r7   r  r  r^  r  rs  rt  r"  )rw  rE  )r  r   r^  r  r  s        r  rz  zkraken.parse_transfer  sh     8R88  11((6::

 

 
	
r  r   GETc                    d| j         z   dz   |z   dz   |z   }|dk    r|r|d|                     |          z   z  }n|dk    r|                     |d          }d}	||                    d          rdnd}	|d	k    }
|d
k    }|                                  t          |                                           }|
s|	s|r,|                     |                     d|i|                    }n+|                     |                     d|i|                    }| 	                    ||z             }| 
                    |dd          }| 	                    |          }|                     ||          }|                     | j                  }|                     ||t          j        d          }| j        |d}|
s|	s|rd|d<   nd|d<   nd|z   }| j        d         |         |z   }||||dS )Nr&  r   ?r   r.  Fr  Tr   r   noncesha256binarybase64)zAPI-KeyzAPI-Signzapplication/jsonzContent-Typez!application/x-www-form-urlencodedr   )rg  r  bodyheaders)r<   urlencode_nestedrE  r  check_required_credentialsr#  r  jsonr  encodehashbinary_concatbase64_to_binarysecrethmachashlibsha512apiKeyr   )r  pathr   r  rL  r  r  rg  r.  isTriggerPercentisCancelOrderBatchisBatchOrderr  authr  r  binhashr  	signatures                      r  signzkraken.sign0  s6   DL 3&,s2T9(?? ;sT226::::I$$VW55E$ ,1NN3,?,?#K44e "&*<"< O3L++---

%%E! T%5 T Tyygu-=v!F!FGG ,,T[['59I6-R-RSS;;ut|,,D99T8X66D[[%%F((66G**4;77F		'67>8LLI;% G " N%5 N N*<''*M''*Cis#c)fdwOOOr  c                 F    |                                  | j        d         z
  S )Nr  )millisecondsr  )r  s    r  r  zkraken.nonceW  s!      ""T\2B%CCCr  reasonrg  r  r  c
                    |dk    r-t          | j        dz   t          |          z   dz   |z             |d S |d         dk    rt          |t                    sx| j        dz   |z   }
d|v rt	          |d                   }|rt          dt	          |d                             D ]T}|d         |         }|                     | j        d         ||
           |                     | j        d         ||
           Ut          |
          d|v r| 
                    |di           }d	|v r|                     |d	g           }t          dt	          |                    D ]u}||         }|                     |d          }|S|                     | j        d         ||
           |                     | j        d         ||
           t          |
          vd S )
Ni  r|  r   {errorr  r  r  rV  )r,   r7   r#  r"  rD  rC  throw_exactly_matched_exceptionr  throw_broadly_matched_exceptionr   r@  rG  rE  )r  rt  r  rg  r  r  r  ri  requestHeadersrequestBodymessage	numErrorsrP  r  r  rV  r   s                    r  handle_errorszkraken.handle_errorsZ  s    3;;&tw}s4yy'@3'F'OPPP47c>>h,, ='C-$.h&& #HW$5 6 6I  5!&q#hw.?*@*@!A!A k kA$,W$5a$8E @@QXAY[`bijjj @@QXAY[`bijjjj+G444x''!^^HhCCF6))!%"!E!E!&q#f++!6!6 = =A$*1IE$($4$4UG$D$DE$0 $ D DT_U\E]_dfm n n n $ D DT_U\E]_dfm n n n&3G&<&< <  1 tr  )N)r   r   r  )NNN)e__name__
__module____qualname__r   r
  r  r   r   ra  rk  r   r  r   r   rF  r#  r   r  r  r
   r  r   r   r  dictr   r  r   r   r  r  rA  r  r  r  r   r  r  r  r  r   r.  r6  r   r>  rA  r   floatrE  rG  r   r   rC  r   r^  r$  r%  rr  ry  r   rR  rP  r  r  r  r  r  r  r  r  r  r   r  r  r  r   r  r#  r'  r+  r3  r1  r	   r:  r=  r9  rA  r   r   rU  rl  rp  rr  r   r   rz  r  r  intr  __classcell__)r  s   @r  r4   r4   "   s       e# e e e e e eNy y y $& [ [$v, [ [ [ [z #% 
 
 
 
4 ') w wZ w w w wr	L 	LS 	LH 	LPS 	L 	L 	L 	L 	L 	L 57 /6 /6 /6;N /6 /6 /6 /6b
 
 
* *i *	 *en * * * * :>b .8 .8s .83 .8Y .8 .8 .8 .8`/ /4 / /6 / / / /b 04B G GW G7 G G G GB 02 1 13 1f 1 1 1 1&
 
 
4 
 
 
 
, 9=4^bkm 0J 0J# 0J# 0JS 0JX[ 0Jrvw{r| 0J 0J 0J 0Jd3 3 33 3t 3x 3; 3 3 3 3j (,$TZ\ /@ /@ /@C /@s /@aefqar /@ /@ /@ /@b <@ ( (S ( ( ( (6 7;2  S  +    L L Lv L L L L L\ 6:UW .? .?3 .?s .?# .?\`af\g .? .? .? .?`) ) ) ) )$ $& , ,( , , , ,8 _a _ _C _y _PU _ _ _ _& RT O O O5 O O O O gksu 2( 2(3 2(i 2(y 2(RW 2(`c 2( 2( 2( 2(h @B CC CCD$6 CC CC CC CCJ( ( (  B: : : : :	: 	: 	:n n nv n n n n n` kowy b! b!C b! b!C b!$ b!X[ b!dg b! b! b! b!H `drv  @B @0 @0S @0# @0Y @0i @0Y\ @0lo @0 @0 @0 @0D 26b ?E ?Ec ?E3 ?E ?E ?E ?EB 9=4^bkm G GS G# GS GX[ G G G GR 6:"  s    4 -1tRV_a A? A?c A? A?C A? A? A? A?F 37r * *s *C * * * *X ;?r 
 
c 
C 
 
 
 
: /32 
 
 
 
 
 
4 <>  s    8 /3TXac K? K? K?3 K?c K?hlmrhs K? K? K? K?Z 154VZce O? O?# O?S O?PS O?jnotju O? O? O? O?b
:s 
: 
: 
: 
:C C Ch
 h
T h
X h
Q\ h
 h
 h
 h
TO O3 OVY Oil O O O O *.Dt\^ *b *b3 *bc *b *bcghsct *b *b *b *bX !# 7 7s 7 7 7 7. -1tRV_a Na Nac Na NaC Nafjkvfw Na Na Na Na`   8: N N3 Nn N N N N 79 '3 '3# '3 '3 '3 '3R 79 5A 5A# 5A^ 5A 5A 5A 5An
 
h 
R` 
 
 
 
( KOWY $y $yS $y% $y# $yC $y^i $y $y $y $yL 26b AQ AQw AQT(^ AQ AQ AQ AQF. .t .V . . . .`A A A 68 C C C C C C [] ( (S (% (c (c (an ( ( ( (T
 
t 
x 
= 
 
 
 
4 &eBSW %P %P %P %PND D D# s  c TX `c        r  r4   )9ccxt.base.exchanger   ccxt.abstract.krakenr   r  ccxt.base.typesr   r   r   r   r	   r
   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!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   ccxt.base.decimal_to_precisionr0   r1   ccxt.base.preciser2   r4    r  r  <module>r     s8   ( ' ' ' ' ' , , , , , ,  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q  Q       * * * * * * 0 0 0 0 0 0 - - - - - - - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . + + + + + + ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) + + + + + + . . . . . . 1 1 1 1 1 1 * * * * * * ) ) ) ) ) ) * * * * * * 3 3 3 3 3 3 4 4 4 4 4 4 % % % % % %T5 T5 T5 T5 T5X{ T5 T5 T5 T5 T5r  