
    eiX                       d dl mZ d dlmZ d dl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!m0Z0 d dl!m1Z1 d dl!m2Z2 d dl!m3Z3 d dl4m5Z5 d dl4m6Z6 d dl7m8Z8  G d dee          Z9d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    W/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/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_precisionL  s2    ((hV8L[8YZb8ceiewxxxr  c                 V  K   g }|                     |                     |                     | j        d         r'|                     |                                            t	          j        |  d{V }|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  Nr   resultcachedCurrenciesbasequote
fees_makerr   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asynciogather	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  rD  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_marketsO  s5      0088999<12 	9OOD5577888!.(3333333	"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                    K   |                      |           d{V }|                     |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>`
        Nr  r"  r#  okmaintenance)r"  updatedetaurlr<  )publicGetSystemStatusrB  rG  )r  rN  responser  	statusRaws        r  fetch_statuszkraken.fetch_status  s       33F;;;;;;;; (33$$VX66	(H44dd=
 
 	
r  c                   K   |                      |           d{V }|                     |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
        Nr  r   .r+  XZz.HOLDr"  enabledfiatcryptodecimalsr0  )r  r   )r7   coder<  r8   r-  r,  depositr   r  r  r:  r  )publicGetAssets
safe_valuerC  rD  rE  rF  rH  findrG  
startswithr   safe_currency_structurer  rK  )r  rN  rk  
currenciesidsr  rR  r7   r`  rv  altNameisFiats               r  fetch_currencieszkraken.fetch_currencies  s!      --f55555555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 )Nro  r   r   )rz  splitrG  r	  r4   rH  )r  r  r`  parts	firstPart
secondPartr  s         r  rH  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                 2  K   |                                   d{V  |                     |          }|d         dd}|                     |                     ||                     d{V }|                     |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>`
        Nr7   T)pairzfee-infor  )load_marketsrS  privatePostTradeVolumeextendry  parse_trading_fee)r  r  rN  rS  requestrk  r  s          r  fetch_trading_feezkraken.fetch_trading_fee  s       !!!!!!!!!V$$4L
 
 44T[[&5Q5QRRRRRRRR< 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   )ry  r  r2   rJ  rG  )r  rk  rS  rV  rY  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  )rL  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                   K   |                                   d{V  |                     |          }d|d         i}|||d<   |                     |                     ||                     d{V }|                     |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
        Nr  r7   countr  r<  r%  )r  rS  publicGetDepthr  ry  parse_order_book)r  r  r  rN  rS  r  rk  r  	orderbook
marketInfowsNames              r  fetch_order_bookzkraken.fetch_order_book  s      !!!!!!!!!V$$F4L
 $GG,,T[[&-I-IJJJJJJJJ( 8R88OOFF4L99	 __VVR88
X66	BBI$$Y777r  tickerrS  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_symbolry  rG  r2   
string_mulsafe_ticker)r  r  rS  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                   K   |                                   d{V  i }||                     |          }g }t          dt          |                    D ]:}||         }| j        |         }|d         r|                    |d                    ;d                    |          |d<   |                     |                     ||                     d{V }|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_symbolsrE  rF  r  r=  joinpublicGetTickerr  rC  rD  safe_marketr  filter_by_array_tickers)r  r  rN  r  	marketIdsrR  r  rS  rk  tickersr~  r  r7   r  s                 r  fetch_tickerszkraken.fetch_tickers0  s      !!!!!!!!!))'22GI1c'll++ 3 3 f-(# 3$$VD\222!hhy11GFO--dkk'6.J.JKKKKKKKK8$7<<>>""q#c((## 	? 	?AQB%%b))FH%FR[F!..vv>>F6NN++FHgFFFr  c                 *  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|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>`
        Nr  r7   r  )r  rS  r  r  r  )r  r  rN  rS  r  rk  r  s          r  fetch_tickerzkraken.fetch_tickerQ  s       !!!!!!!!!V$$F4L
 --dkk'6.J.JKKKKKKKK(#F4L1  000r  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r   r  r      r   )safe_timestamprL  )r  ohlcvrS  s      r  parse_ohlcvzkraken.parse_ohlcvd  s     q))UA&&UA&&UA&&UA&&UA&&
 	
r  r   	timeframesincec           	        K   |                                   d{V  d}|                     |dd          \  }}|r!|                     d|||||d           d{V S |                     |          }|                     | j        |          }d|d         i}	|||	d<   n||	d<   |8|                     |d	z            }
|d
z  }|                     |
|z
            |	d<   |                     | 	                    |	|                     d{V }| 
                    |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
        NFrs   paginater  r  r7   intervalr?   r   r  r  )r  handle_option_and_params"fetch_paginated_call_deterministicrS  r  r   parse_to_intnumber_to_stringpublicGetOHLCr  ry  rI  parse_ohlcvs)r  r  r  r  r  rN  r  rS  parsedTimeframer  scaledSincetimeFrameInSecondsrk  r  ohlcvss                  r  fetch_ohlcvzkraken.fetch_ohlcvz  s      !!!!!!!!!88zZZ& 	}@@vW\^cenpvx{|||||||||V$$++DOYGGF4L
 &"1GJ"+GJ++EDL99K!02!5#44[CU5UVVGG++DKK,H,HIIIIIIII 8R88tb99  E5IIIr  c                 @    dddddd}|                      |||          S )Ntradetransactionr   rE   )r  
withdrawalrw  r   rE   rG  )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?   balancere  r  r3  r`  )r<  r7   	directionaccountreferenceIdreferenceAccountr,  r`  r  beforeafterr"  r  r  r  )rG  r  rH  safe_currencyr2   	string_lt
string_abssafe_integer_productsafe_ledger_entryr  rL  iso8601)r  r  r`  r7   r  r  r  r  r,  r  rv  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  rv  c                 h  K   |                                   d{V  i }d}| |                     |          }|d         |d<   ||                     |dz            |d<   |                     |ddg          }|X|                     |ddg          }t          j        |d          }|                     t          j        |d	                    |d
<   |                     | 	                    ||                     d{V }	| 
                    |	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   rJ  
string_addprivatePostLedgersr  ry  rC  rD  rE  rF  r=  parse_ledger)r  rv  r  r  rN  r  r`  r  untilDividedrk  r  r  rD  itemsrR  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00Wf1M1MNNNNNNNN 8R88266FKKMM""q#d))$$ 	  	 Aq'C3KEE$KLL  %???r  c                   K   |                                   d {V  d                    |          }|                     d|i|          }|                     |           d {V }|d         }t	          |                                          }g }t          dt          |                    D ],}	||	         }
||
         }|
|d<   |                    |           -| 	                    |          S )Nr  r7   r  r   )
r  r  r  privatePostQueryLedgersrC  rD  rE  rF  r=  r  )r  r~  rv  rN  r  rk  r  rD  r  rR  r  r  s               r  fetch_ledger_entries_by_idsz"kraken.fetch_ledger_entries_by_ids  s	     !!!!!!!!!hhsmm++#
  55g>>>>>>>> (#FKKMM""q#d))$$ 	  	 Aq'C3KEE$KLL  '''r  r7   c                 R   K   |                      |g||           d {V }|d         S )Nr   )r  )r  r7   rv  rN  r  s        r  fetch_ledger_entryzkraken.fetch_ledger_entry7  s:      66tT6JJJJJJJJ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  rS  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  )
isinstancerC  r  rG  rF  strfind_market_by_altname_or_idget_delisted_market_by_idsafe_string_2	safe_boolr  	parse8601
safe_trade)r  r  rS  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                 B  K   |                                   d{V  |                     |          }|d         }d|i}|.|                     |                     |dz                      |d<   |||d<   |                     |                     ||                     d{V }|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>`
        Nr7   r  r?   r  r  r  r   r   r  )
r  rS  r  r  publicGetTradesr  rF  rG  r=  parse_trades)r  r  r  r  rN  rS  r7   r  rk  r  tradeslength	lastTradelastTradeIds                 r  fetch_tradeszkraken.fetch_trades  sT      !!!!!!!!!V$$D\B

 #44T5F5Fut|5T5TUUGG$GG--dkk'6.J.JKKKKKKKK (#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)	ry  rC  rD  rE  rF  rH  r  rG  safe_balance)
r  rk  balancesr  currencyIdsrR  r  rv  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                    K   |                                   d{V  |                     |           d{V }|                     |          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>`
        N)r  privatePostBalanceExr@  )r  rN  rk  s      r  fetch_balancezkraken.fetch_balance  sg       !!!!!!!!!226::::::::  !!(+++r  r  r3  c                    K   |                                   d{V  d|i}|                     |d||d|                     ||                     d{V 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>`
        Nr3  rS  )r  create_orderr  )r  r  r  r3  rN  reqs         r  create_market_order_with_costz$kraken.create_market_order_with_cost'  s|       !!!!!!!!! D
 &&vxtT4;;WZ\bKcKcdddddddddr  c                 v   K   |                                   d{V  |                     |d||           d{V 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>`
        Nr  )r  rG  )r  r  r3  rN  s       r  !create_market_buy_order_with_costz(kraken.create_market_buy_order_with_cost:  sX       !!!!!!!!!77tVTTTTTTTTTr  r,  r  r.  c           	        K   |                                   d{V  |                     |          }|d         |||                     ||          d}|                     d||||||          }	|                     |	d         dd          }
|
                    d          d	k    }|                     |                     |	d         |	d
                              d{V }|                     |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>`
        Nr7   )r  r,  r  volumerR   r   oflags viqcr   r  	usingCost)
r  rS  amount_to_precisionorder_requestrG  rz  privatePostAddOrderr  rB  parse_order)r  r  r,  r  r  r.  rN  rS  r  orderRequestflagsisUsingCostrk  r  s                 r  rE  zkraken.create_orderH  s/     0 !!!!!!!!!V$$4L..vv>>	
 
 ))-wPVX]_eff  a(B??jj((2-11$++l1o|\]2_2_```````` (33){ '''r  ordersc           
        K   |                                   d{V  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{V }| 	                    |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.  rN  )r,  r  rK  rS   FTr7   )rX  r  r  rX  )r  rE  rF  rG  r#   r7   rS  r=  ry  rB  rQ  rR  r  r  privatePostAddOrderBatchparse_ordersrI  )r  rX  rN  ordersRequestsorderSymbolsr  rS  rR  rawOrderr.  r,  r  r  r.  orderParamsrF  rU  rk  r  r  s                       r  create_orderszkraken.create_orders|  sF      !!!!!!!!!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..66w????????, (B77  !A!ABBBr  c                 |    |                      | j        di           }||v r||         S |                     |          S )Nr  )ry  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)  )ry  r  rF  rH  )r  r7   rS  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filledrj  rk  rl  r  r  r"  statusess      r  parse_order_statuszkraken.parse_order_status  sC    ! &" 

 

 &&999r  c                 @    dddddd}|                      |||          S )NrS  r  )take-profit	stop-lossstop-loss-limittake-profit-limittrailing-stop-limitr  rr  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 )DNrP  Fdescrr"   r   r   r  r  r   r  rS  z	stop lossztake profitr   	   r,  r  r  opentmr  vol_execr.  %z0.00000r=   price2
limitpricerL  rM  r   rO  r  r  )r3  ratefciqr  r`  fcibr  r"  )r7   txidorder_idamend_id[r  userref	cl_ord_idr4  )r7   r,  r  r<  rv  rw  r  r7   clientOrderIdr<  r  r  lastTradeTimestampr  postOnlyr  r  r  r  r3  
reduceOnlyreduce_only)r  rq  r  	remainingr  r  r4  )r)  r  rB  rG  r  r&  r'  r  endswithr2   string_equalsr(  rz  rL  rt  r  r{  rI  ry  rE  rF  r$  r%  r=  r+  	omit_zeror{  in_array
safe_orderr  safe_bool_2)'r  r"  rS  rW  descriptionorderDescriptionObjorderDescriptionr  rawTyper.  r.  r  r3  r  r  part4part5r/  r  r  rq  r  rV  
isPostOnlyr  feeCostr"  r7   r  r  r  	rawTradesr4  rR  rawTrader  r  	finalTypeamendIds'                                          r  rT  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  rS  r3  rL  rN  rO  rK  z,viqcr.  r  r  rx  r  rw  ry  rv  r  r  +offset-r  r  rz  ztrailing-stopcreateOrderWsTtruer  r  timeinforceFz,postr   )	r  r  r  r  r  r  r  r  r  )rG  r  r  rz  cost_to_precisionr  price_to_precisionr  rB  r  ry  r(  handle_post_only)(r  r  r  r,  r  r  r.  rN  r  stopLossTriggerPricetakeProfitTriggerPriceisStopLossTriggerOrderisTakeProfitTriggerOrderisStopLossOrTakeProfitTriggerr  r  r  r  isTrailingAmountOrderisTrailingPercentOrderisLimitOrderisMarketOrderr3  rV  isViqcOrderextendedOflagsr  trailingPercentStringtrailingAmountStringr  trailingLimitAmountStringtrailingActivationPriceTypetrailingLimitPercentStringr  
closePriceclosePrice2r  isMarketr  extendedPostFlagss(                                           r  rR  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                   K   |                                   d{V  |                     |          }|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{V }|                     |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>`
        NrD   z editOrder() does not support r,  z& orders, only spot orders are acceptedr  r  r  rS  Fr  	post_only	order_qtylimit_price)r  r  r  r  r  r  r  )r  r  r  r  r  r  r  trigger_pricer  )r  rS  r)   r7   r(  r  r  rQ  r  r  rG  privatePostAmendOrderr  rB  rT  )r  r7   r  r,  r  r  r.  rN  rS  r  r  r  r  allTriggerPricesr  rk  r  s                    r  
edit_orderzkraken.edit_orderV  sg     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[+\+\(33DKK4P4PQQQQQQQQ (B77///r  c                   K   |                                   d{V  |                     |dd          }d|d}|}|||d<   |                     |ddg          }|                     |                     ||                     d{V }|                     |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>`
        Nr  r  Tr4  r  r  z& fetchOrder() could not find order id r7   )	r  safe_value_2r  privatePostQueryOrdersr  ry  r(   r7   rT  )	r  r7   r  rN  r  r  queryrk  r  s	            r  fetch_orderzkraken.fetch_order  s      !!!!!!!!!))&)_MM
 

 $!.GIIIfy/&BCCE44T[[%5P5PQQQQQQQQL 8R88f*R RUW WXXXT2Jr
 C CDDDr  c                   K   |                      |d          }g }|t          | j        dz             t          dt	          |                    D ]P}||         }	t          |	t                    r|                    |	           5|                    |	d                    Q|                                  d{V  || 	                    |          }|                      | j
        di           }
|                     |
dd          }t	          |          }|                     ||z            }|                     |d	          }g }t          d|          D ]6}g }t          d|          D ]<}|                     ||z  |          }||k     r|                    ||                    =d
d                    |          i}|                     |           d{V }|                      |d          }t!          |                                          }t          dt	          |                    D ]}||         |||                  d<   |                     |d||          }|                     ||          }|                     ||          }8|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>`
        r4  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  )ry  r"   r7   rE  rF  r$  r%  r=  r  r  r  r  r  sumr  privatePostQueryTradesrC  rD  r3  filter_by_symbolarray_concat)r  r7   r  r  r  rN  orderTradestradeIdsrR  
orderTrader  r  numTradeIds
numBatchesr  j
requestIdskindexr  rk  r  r~  r4  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 "88AAAAAAAAH, (;;Iy~~''((C1c#hh'' 1 1*-a&	#a&!$''&&y$uEEF%)%:%:66%J%J"&&v/EFFFFr  c                   K   |                                   d{V  |                     |                     dd                    |          d|                     d{V }|                     |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>`
        NTr  r  r  r   r7   )r  r  r  r  ry  rC  rD  rE  rF  rT  r=  )r  r~  r  rN  rk  r  rX  orderIdsrR  r7   r  r"  s               r  fetch_orders_by_idszkraken.fetch_orders_by_ids"	  s1      !!!!!!!!!44T[[HHSMMB
 B
 6 6         8R88&&q#h--(( 	! 	!A!B":D$$T[[$T%B%BCCEMM%    r  c                   K   |                                   d{V  i }||                     |dz            |d<   |                     |ddg          }|X|                     |ddg          }t	          j        |d          }|                     t	          j        |d                    |d<   |                     |                     ||                     d{V }|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  r4  r   r7   )r  r  r  r  r2   rJ  r	  privatePostTradesHistoryr  rC  rD  rE  rF  rS  r3  )r  r  r  r  rN  r  r  r  rk  r4  r~  rR  rS  s                r  fetch_my_tradeszkraken.fetch_my_trades<	  s      !!!!!!!!!
 #00>>GG""6GV+<==YYv'899F"-eV<<L!..w/A,PS/T/TUUGEN66t{{7F7S7STTTTTTTT: (#H-6;;==!!q#c((## 	* 	*A#&q6F3q6N4  [[((F  >>>r  c                 x  K   |                                   d{V  d}|                     |d|          }|                     |d          }d|i}|                     |dd          }|3||d<   |                     |ddg          }|                     |d          }	 |                     |                     ||                     d{V }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  ry  r  r(  privatePostCancelOrderr  	Exceptionlast_http_responserz  r(   r7   r  )	r  r7   r  rN  rk  	requestIdr  r  es	            r  cancel_orderzkraken.cancel_order	  s      !!!!!!!!!OOFIr::	69--I
 **6?KPP$#0GK YYv'EFFFii00G	!88Wf9U9UVVVVVVVVHH  	 	 	& e*//0FGG1LL'2I(IDLc(cdddG		
 H 
   	s   /C 
D"ADD"r~  c                    K   d|i}|                      |                     ||                     d{V }|                     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>`
        rX  Nr<  )privatePostCancelOrderBatchr  r  )r  r~  r  rN  r  rk  s         r  cancel_orderszkraken.cancel_orders	  sp       c
 99$++gv:V:VWWWWWWWW OO  
 	
r  c                    K   |                                   d{V  |                     |           d{V }|                     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>`
        Nr<  )r  privatePostCancelAllr  )r  r  rN  rk  s       r  cancel_all_orderszkraken.cancel_all_orders	  sx       !!!!!!!!!226:::::::: OO  
 	
r  timeoutc                   K   |dk    rt          | j        dz             |                                  d{V  d|dk    r|                     |dz            ndi}|                     |                     ||                     d{V }|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 millisecondsNr  r   r?   )r#   r7   r  r  privatePostCancelAllOrdersAfterr  )r  r  rN  r  rk  s        r  cancel_all_orders_afterzkraken.cancel_all_orders_after	  s       XTW'ppqqq!!!!!!!!!w{{))'D.999QR
 ==dkk'SY>Z>Z[[[[[[[[ r  c                 \  K   |                                   d{V  i }||                     |dz            |d<   |                     |d          }|||d<   |                     |d          }|                     |d          }|||d<   |                     |d          }|                     |                     ||                     d{V }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  rG  privatePostOpenOrdersr  rS  rB  rC  rD  rE  rF  r=  r[  )r  r  r  r  rN  r  r  r  rk  rS  r  r  rX  r  rR  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33DKK4P4PQQQQQQQQL [[((F(B77~~ffb11		$$q#h--(( 	9 	9A!B8DMM$++tRj$778888  >>>r  c                   K   |                                   d{V  i }||                     |dz            |d<   |                     |d          }|||d<   |                     |d          }|                     |d          }|||d<   |                     |d          }|                     d||          \  }}|                     |                     ||                     d{V }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  rj  r   r7   )r  r  r  r  rG  handle_until_optionprivatePostClosedOrdersr  rS  rB  rC  rD  rE  rF  r=  r[  )r  r  r  r  rN  r  r  r  rk  rS  r  rj  rX  r  rR  r7   r  s                    r  fetch_closed_orderszkraken.fetch_closed_ordersK
  s      !!!!!!!!!#00>>GG##FI66!(GIYYvy11F((AA$#0GK YYv77F225'6JJ55dkk'66R6RSSSSSSSS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 )Nrm  re  failed)InitialPendingSuccessSettledFailurePartialr  rr  s      r  parse_transaction_statuszkraken.parse_transaction_status
  s<     !  
 
 &&999r  c                 h    |                      | j        di           }|                     |||          S )Nr  )ry  r  rG  )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onholdrm  r,  r  rw  r   r7   r`  r  address	addressToaddressFromtagtagTotagFromrg  r  r  )r`  r3  )commentinternalr  )rG  r  rH  rL  r  r  r  )r  r  r`  r7   r  r  r  rv  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,  )rE  rF  r!  r  r=  filter_by_currency_since_limit)	r  r,  transactionsrv  r  r  r  rR  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                 :  K   |                                   d{V  i }| |                     |          }|d         |d<   |-|                     |          }t          j        |d          |d<   |                     |ddg          }|E|                     |ddg          }t          j        |d          }	t          j        |	d          |d	<   |                     | 	                    ||                     d{V }
| 
                    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  rw  r  )r  r`  r  r2   rJ  r  r  r	  privatePostDepositStatusr  r%  )r  rv  r  r  rN  r  r`  sinceStringr  r  rk  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66t{{7F7S7STTTTTTTT ..y(8:LdTY[`aaar  c                    K   |                      |           d{V }|                     |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
        Nr  unixtime)publicGetTimery  r  )r  rN  rk  r  s       r  
fetch_timezkraken.fetch_timeK  sZ       ++F33333333 8R88""6:666r  c           	      @  K   |                                   d{V  d}|                     |dd          \  }}|r&d|d<   |                     d||||dd           d{V S i }| |                     |          }|d         |d	<   |-|                     |          }t          j        |d
          |d<   |                     |ddg          }	|	E|                     |ddg          }t          j        |	d
          }
t          j	        |
d          |d<   | 
                    |                     ||                     d{V }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>`
        NFr   r  Tcursornext_cursorr7   r  r  r  r  r  r/  r  r  r  )r  r  fetch_paginated_call_cursorr`  r  r2   rJ  r  r  r	  privatePostWithdrawStatusr  ry  r$  rC  add_pagination_cursor_to_resultr%  )r  rv  r  r  rN  r  r  r`  r(  r  r  rk  rawWithdrawalsr  s                 r  fetch_withdrawalszkraken.fetch_withdrawalsb  s      !!!!!!!!!88ASU_``& 	C#F899:LdTY[`bhjw  zB  C  C  C  C  C  C  C  C  C}}T**H'~GG//66K&1+vFFGG""6GV+<==YYv'899F"-eV<<L$/cBBGEN77GV8T8TUUUUUUUUN 844&$'' 	$!AA&IINN#N..|^TSXZ_```r  c                     |                      |d          }|                     |d          }t          |          }||dk    r||dz
           }||d<   |||dz
  <   |S )Nr0  withdrawalsr   r   )rG  ry  rF  )r  r  r/  data
dataLengthr  s         r  r3  z&kraken.add_pagination_cursor_to_result  sn    !!&-88v}55YY
*q..
Q'D"(D#'Da r  c                 n   K   ddi}|                      ||                     ||                     d{V 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>`
        ro  r  N)fetch_deposit_addressr  )r  rv  rN  r  s       r  create_deposit_addresszkraken.create_deposit_address  sL       6
 //dkk'66R6RSSSSSSSSSr  c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |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
        Nr  r7   r  )r  r`  privatePostDepositMethodsr  ry  )r  rv  rN  r`  r  rk  s         r  fetch_deposit_methodszkraken.fetch_deposit_methods  s       !!!!!!!!!==&&Xd^
 77GV8T8TUUUUUUUU0 x222r  c                 ^  K   |                                   d{V  |                     |          }|                     |d          }|                     | j        di           }|                     |||          }|                     |d          }|dk    r|dk    r|dz   |z   }|                     | j        di           }|                     ||          }|                     |d|          }||                     |           d{V }	|Yt          d	t          |	                    D ];}
|                     |	|
         d          }|
                    |          d	k    r|} n<|-|                     |	d	i           }|                     |d          }|d
         |d}|                     |                     ||                     d{V }|                     |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>`
        Nr  r  rv  r  r  r  r  r   r7   )r  r  r  z9 privatePostDepositAddresses() returned no addresses for )r  r`  safe_string_upperry  r  rG  r  r?  rE  rF  rz  privatePostDepositAddressesr  r&   r7   parse_deposit_address)r  rv  rN  r`  r  r  defaultDepositMethodsdefaultDepositMethoddepositMethodr  rR  entryfirstDepositMethodr  rk  r  firstResults                    r  r;  zkraken.fetch_deposit_address  st      !!!!!!!!!==&&((;;??4<R@@""8Wg>>69--FNNG!3!3#:'D $>NPR S S#//0EtLL((;OPP  #'#=#=d#C#CCCCCCCN"q#n"5"566  A ,,^A->IIEzz'**a//(- 0 $%)__^Q%K%K" $ 0 01CX N Nd^#
 
 99$++gv:V:VWWWWWWWW 8R88oofa44 +f!fim!mnnn))+x@@@r  c                     |                      |d          }|                      |d          }|                     d |          }|d         }|                     |           ||d ||dS )Nr  r  rv  )r<  r`  r  r  r  )rG  r  check_address)r  depositAddressr`  r  r  rv  s         r  rC  zkraken.parse_deposit_address+  s     "">9==~u55%%dH557###"
 
 	
r  r  r  c                   K   |                      ||          \  }}d|v r|                                  d{V  |                     |          }|d         |d}| |dk    r||d<   |                     |           |                     |                     ||                     d{V }|                     |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  Nr7   )r  r  rM  r  r  zO withdraw() requires a 'key' parameter(withdrawal key name, up on your account))
handle_withdraw_tag_and_paramsr  r`  rK  privatePostWithdrawr  rB  r!  r   r7   )
r  rv  r  r  r  rN  r`  r  rk  r  s
             r  r   zkraken.withdraw?  s      99#vFFVF??##%%%%%%%%%}}T**H!$  G
 "w"}}%,	"""7+++!55dkk'66R6RSSSSSSSSH ^^Hh;;F))&(;;;DG&wwxxxr  c                 T  K   |                                   d{V  ddd}|                     |                     ||                     d{V }|                     |          }|                     |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>`
        Nr  rS  )docalcsconsolidationr  r  F)r  privatePostOpenPositionsr  r  rI  parse_positionsfilter_by_array_positions)r  r  rN  r  rk  r  resultss          r  fetch_positionszkraken.fetch_positionse  s       !!!!!!!!! %
 

 66t{{7F7S7STTTTTTTT\ %%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  )rG  safe_positionr  rL  )r  rX  rS  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                 D   K   |                      ||dd|           d{V 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   N)r   )r  rv  r  rN  s       r  transfer_outzkraken.transfer_out  s4       ]]4HHHHHHHHHr  fromAccount	toAccountc                 
  K   |                                   d{V  |                     |          }|                     |          }|                     |          }|                     ||          |||d         d}|dk    r#t	          | j        dz   |z   dz   |z   dz             |                     |                     ||                     d{V }|                     ||          }	|                     |	|||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>`
        Nr7   )r  fromtor  rp  z transfer cannot transfer from z to zA. Use krakenfutures instead to transfer from the futures account.)r  ru  rv  )	r  r`  rr  currency_to_precisionr#   r7   privatePostWalletTransferr  parse_transfer)
r  rv  r  ru  rv  rN  r`  r  rk  r   s
             r  r   zkraken.transfer  sN      !!!!!!!!!==&&--k::++I66	00v>>d^	
 
 -''TW'HH;VY__bkk  or  r  s  s  s77GV8T8TUUUUUUUU &&x::{{8&"&
 &
   	r  r   c           
          |                      |di           }|                     |d          }||d d |                     |d          d d d dd	S )Nr  r  rv  sucess)	r<  r7   r  r  r`  r  ru  rv  r"  )ry  rG  )r  r   r`  r  r  s        r  r|  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   )ri  r  bodyheaders)r<   urlencode_nestedrG  r  check_required_credentialsr%  r  jsonr  encodehashbinary_concatbase64_to_binarysecrethmachashlibsha512apiKeyr   )r  pathr   r  rN  r  r  ri  r.  isTriggerPercentisCancelOrderBatchisBatchOrderr  authr  r  binhashr  	signatures                      r  signzkraken.sign1  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.nonceX  s!      ""T\2B%CCCr  reasonri  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  rX  )r,   r7   r%  r$  rF  rE  throw_exactly_matched_exceptionr  throw_broadly_matched_exceptionr   rB  rI  rG  )r  rv  r  ri  r  r  r  rk  requestHeadersrequestBodymessage	numErrorsrR  r  r  rX  r"  s                    r  handle_errorszkraken.handle_errors[  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   rc  rm  r   r  r   r   rH  r%  r   r  r  r
   r  r   r   r  dictr   r  r   r   r  r  rC  r  r  r  r   r  r  r  r  r   r0  r8  r   r@  rC  r   floatrG  rI  r   r   rE  r   r`  r&  r'  rt  r{  r   rT  rR  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r!  r%  r)  r-  r5  r3  r	   r<  r?  r;  rC  r   r   rW  rn  rr  rt  r   r   r|  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: w w w wr	L 	LS 	LH 	LPS 	L 	L 	L 	L 	L 	L ;= /6 /6c /6AT /6 /6 /6 /6b
 
 
* *i *	 *en * * * * @DB .8 .8S .8 .8S\ .8 .8 .8 .8`/ /4 / /6 / / / /b 6:" G G7 G G G G GB 68 1 1 1F 1 1 1 1&
 
 
4 
 
 
 
, ?CQUdhqs 0J 0J 0J 0J3 0J^a 0Jx|  ~B  yC 0J 0J 0J 0Jd3 3 33 3t 3x 3; 3 3 3 3j .2SW`b /@ /@s /@# /@S /@gklwgx /@ /@ /@ /@b BFb ( (3 ( ( ( (6 =A  3 c P[    L L Lv L L L L L\ <@d[] .? .? .?S .? .?bfglbm .? .? .? .?`) ) ) ) )$ *, , , , , , ,8 eg e e# eY eV[ e e e e& XZ U Uc U U U U U mqy{ 2( 2( 2(I 2(Y 2(X] 2(fi 2( 2( 2( 2(h FH CC CC$|*< 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 fjx|  FH @0 @03 @0 @09 @0I @0_b @0ru @0 @0 @0 @0D 8<B ?E ?EC ?E ?E ?E ?E ?EB ?CQUdhqs G G3 G G3 G^a G G G GR <@  S    4 37TX\eg A? A?C A?s A?RU A? A? A? A?F 9=R * *S *# * * * *X AER 
 
tCy 
# 
 
 
 
: 59 
 
c 
 
 
 
4 BD  S    8 59tZ^gi K? K?c K? K?TW K?nrsxny K? K? K? K?Z 7;\`ik O? O? O?3 O?VY O?ptuzp{ 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 04$UYbd *b *b *bC *bs *bimnyiz *b *b *b *bX ') 7 7S 7 7 7 7. 37TX\eg Na NaC Nas NaRU Nalpq|l} Na Na Na Na`   >@ T T TN T T T T =? '3 '3 '3 '3 '3 '3R =? 5A 5A 5A> 5A 5A 5A 5An
 
h 
R` 
 
 
 
( QU]_ $y $y3 $y $y $y# $ydo $y $y $y $yL 8<B AQ AQW AQ4PX> AQ AQ AQ AQF. .t .V . . . .`A A A <> I Is I I I I ac ( (3 ( (C (TW (gt ( ( ( (T
 
t 
x 
= 
 
 
 
4 &eBSW %P %P %P %PND D D# s  c TX `c        r  r4   ): ccxt.async_support.base.exchanger   ccxt.abstract.krakenr   r@  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     sA   6 5 5 5 5 5 , , , , , ,   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  