
    ii                    L   d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lm Z  d dlm!Z! 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+  G d dee          Z,dS )    )Exchange)ImplicitAPIN)Balances
CurrenciesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeeInterfaceTradingFeesTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)
BadRequest)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)NotSupported)ExchangeNotAvailable)OnMaintenance)InvalidNonce)	TICK_SIZE)Precisec                       e Zd Z fdZi fdee         fdZd Zi fdZi fde	fdZ
di fded	edefd
ZdHdedefdZi fdedefdZdi fdedefdZd Zd ZdHdedefdZddi fdeded	edee         fdZdHdedefdZd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 fdZ!dHdede fdZ"d Z#i fde$fdZ%di fdee         fdZ&dHd Z'di fd!Z(dHd"Z)di fded#e*d$e+d%e,d&e-f
d'Z.di fd(ede/fd)Z0di fde/fd*Z1d+ Z2di fd(ede/fd,Z3di fd(ede/fd-Z4dddi fde/ded	efd.Z5dddi fd/e/ded	edee6         fd0Z7dddi fd/e/ded	edee6         fd1Z8dHd2e9de6fd3Z:d4 Z;dHdede<fd5Z=d6 Z>dHd2e9fd7Z?dddi fd/e/ded	efd8Z@dddi fde/ded	edee<         fd9ZAd: ZBd; ZCi fd/efd<ZDdi fd/ed%e,fd=ZEi fd/ed%e,d>ed?edeFf
d@ZGdHdAZHdB ZIdC ZJdDdEi ddfdFZKdG ZL xZMS )Ibitstampc                 x   |                      t          t          |                                           i ddddddgddd	d
d| j        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d0dd1dd2dd3di d4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBddCddDdddddd*ddddddddEdFdGdHdHdIdJdHdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZddd[d\d]d^d^d^d^d^d^d^d^d^d^d_
id^d^d^d^d`i dad^dbd^dcd^ddd^ded^dfd^dgd^dhd^did^djd^dkd^dld^dmd^dnd^dod^dpd^dqd^i drd^dsd^dtd^dud^dvd^dwd^dxd^dyd^dzd^d{d^d|d^d}d^d~d^dd^dd^dd^dd^i 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^i 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^i 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^i dd^dd^dd^dd^dd^dd^dd^dd^dd^dd^dd^dd^dd^dd^dd^dd^dd^i dd^dd^dd^dd^dd^dd^d d^dd^dd^dd^dd^dd^dd^dd^dd^d	d^d
d^i dd^dd^dd^dd^dd^dd^dd^dd^dd^dd^dd^dd^dd^dd^dd^dd^dd^i dd^dd^dd^dd^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^d0d^d1d^d2d^d3d^d4d^d5d^d6d^d7d^d8d^d9d^d:d^d;d^d<d^d=d^d^d^d^d>d?dId@dd|                     dA          |                     dA          |                     dB          |                     dA          g|                     dC          |                     dD          g|                     dE          |                     dF          g|                     dG          |                     dH          g|                     dI          |                     dJ          g|                     dK          |                     dL          g|                     dM          |                     dN          g|                     dO          |                     dP          g|                     dQ          |                     dR          g|                     dS          |                     dT          g|                     dU          |                     dV          g|                     dW          |                     dX          g|                     dY          |                     dZ          g|                     d[          |                     d\          g|                     d]          |                     d^          g|                     d_          |                     d`          g|                     da          |                     dB          gg|                     dB          |                     dA          g|                     dC          |                     dD          g|                     dE          |                     dF          g|                     dG          |                     dH          g|                     dI          |                     dJ          g|                     dK          |                     dL          g|                     dM          |                     dN          g|                     dO          |                     dP          g|                     dQ          |                     dR          g|                     dS          |                     dT          g|                     dU          |                     dV          g|                     dW          |                     dX          g|                     dY          |                     dZ          g|                     d[          |                     d\          g|                     d]          |                     d^          g|                     d_          |                     d`          g|                     da          |                     dB          ggdbdcddi dddddddddddddddedddf	dgdhdit          djdkdlidmdni dodpdqdrdsdtdudvdwdxdydz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dt          t          t          t          t          t          t          t          t          t          t          t          t          t          t          dt          t          t           t          dd          S (  Nidr(   nameBitstamp	countriesGB	rateLimitK   versionv2	userAgentchromeproThasCORSspotmarginFswapfutureoption	addMargincancelAllOrderscancelOrdercloseAllPositionsclosePositioncreateOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchPositionfetchPositionModefetchPositionsfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickers)fetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeesfetchTransactionsfetchWithdrawalsreduceMarginsetLeveragesetMarginModesetPositionModetransferwithdrawurlszchttps://user-images.githubusercontent.com/1294454/27786377-8c8ab57e-5fe9-11e7-8ea4-2b05b6bcceec.jpgzhttps://www.bitstamp.net/api)publicprivatezhttps://www.bitstamp.net)logoapiwwwdoc
timeframes6018030090018003600720014400216004320086400259200)1m3m5m15m30m1h2h4h6h12h1d1wrequiredCredentials)apiKeysecretr{   get   )
zohlc/{pair}/zorder_book/{pair}/zticker/zticker_hour/{pair}/zticker/{pair}/ztransactions/{pair}/ztrading-pairs-info/zcurrencies/zeur_usd/ztravel_rule/vasps/)travel_rule/contacts/zcontacts/{contact_uuid}/zearn/subscriptions/zearn/transactions/zaccount_balances/zaccount_balances/{currency}/zbalance/zbalance/{pair}/zbch_withdrawal/zbch_address/zuser_transactions/zuser_transactions/{pair}/zcrypto-transactions/zopen_orders/all/zopen_orders/{pair}/zorder_status/zcancel_order/zcancel_all_orders/zcancel_all_orders/{pair}/zbuy/{pair}/zbuy/market/{pair}/zbuy/instant/{pair}/zsell/{pair}/zsell/market/{pair}/zsell/instant/{pair}/ztransfer-to-main/ztransfer-from-main/zmy_trading_pairs/zfees/trading/zfees/trading/{market_symbol}zfees/withdrawal/zfees/withdrawal/{currency}/zwithdrawal-requests/zwithdrawal/open/zwithdrawal/status/zwithdrawal/cancel/zliquidation_address/new/zliquidation_address/info/zbtc_unconfirmed/zwebsockets_token/zbtc_withdrawal/zbtc_address/zripple_withdrawal/zripple_address/zltc_withdrawal/zltc_address/zeth_withdrawal/zeth_address/zxrp_withdrawal/zxrp_address/zxlm_withdrawal/zxlm_address/zpax_withdrawal/zpax_address/zlink_withdrawal/zlink_address/zusdc_withdrawal/zusdc_address/zomg_withdrawal/zomg_address/zdai_withdrawal/zdai_address/zknc_withdrawal/zknc_address/zmkr_withdrawal/zmkr_address/zzrx_withdrawal/zzrx_address/zgusd_withdrawal/zgusd_address/zaave_withdrawal/zaave_address/zbat_withdrawal/zbat_address/zuma_withdrawal/zuma_address/zsnx_withdrawal/zsnx_address/zuni_withdrawal/zuni_address/zyfi_withdrawal/yfi_addresszaudio_withdrawal/zaudio_address/zcrv_withdrawal/zcrv_address/zalgo_withdrawal/zalgo_address/zcomp_withdrawal/zcomp_address/grt_withdrawalzgrt_address/zusdt_withdrawal/zusdt_address/zeurt_withdrawal/zeurt_address/zmatic_withdrawal/zmatic_address/zsushi_withdrawal/zsushi_address/zchz_withdrawal/zchz_address/zenj_withdrawal/zenj_address/zalpha_withdrawal/zalpha_address/zftt_withdrawal/zftt_address/zstorj_withdrawal/zstorj_address/zaxs_withdrawal/zaxs_address/zsand_withdrawal/zsand_address/zhbar_withdrawal/zhbar_address/zrgt_withdrawal/zrgt_address/zfet_withdrawal/zfet_address/zskl_withdrawal/zskl_address/zcel_withdrawal/zcel_address/zsxp_withdrawal/zsxp_address/zada_withdrawal/zada_address/zslp_withdrawal/zslp_address/zftm_withdrawal/zftm_address/zperp_withdrawal/zperp_address/zdydx_withdrawal/zdydx_address/zgala_withdrawal/zgala_address/zshib_withdrawal/zshib_address/zamp_withdrawal/zamp_address/zsgb_withdrawal/zsgb_address/zavax_withdrawal/zavax_address/zwbtc_withdrawal/zwbtc_address/zctsi_withdrawal/zctsi_address/zcvx_withdrawal/zcvx_address/zimx_withdrawal/zimx_address/znexo_withdrawal/znexo_address/zust_withdrawal/zust_address/zant_withdrawal/zant_address/zgods_withdrawal/zgods_address/zrad_withdrawal/zrad_address/zband_withdrawal/zband_address/zinj_withdrawal/zinj_address/zrly_withdrawal/zrly_address/zrndr_withdrawal/zrndr_address/zvega_withdrawal/zvega_address/z1inch_withdrawal/z1inch_address/zens_withdrawal/zens_address/zmana_withdrawal/zmana_address/zlrc_withdrawal/zlrc_address/zape_withdrawal/zape_address/zmpl_withdrawal/zmpl_address/zeuroc_withdrawal/zeuroc_address/zsol_withdrawal/zsol_address/zdot_withdrawal/zdot_address/znear_withdrawal/znear_address/zdoge_withdrawal/zdoge_address/zflr_withdrawal/zflr_address/zdgld_withdrawal/zdgld_address/zldo_withdrawal/zldo_address/r   zearn/subscribe/zearn/subscriptions/setting/zearn/unsubscribezwecan_withdrawal/zwecan_address/ztrac_withdrawal/ztrac_address/zeurcv_withdrawal/zeurcv_address/zpyusd_withdrawal/zpyusd_address/zlmwr_withdrawal/zlmwr_address/zpepe_withdrawal/zpepe_address/zblur_withdrawal/zblur_address/zvext_withdrawal/zvext_address/zcspr_withdrawal/zcspr_address/zvchf_withdrawal/)zvchf_address/zveur_withdrawal/zveur_address/)r   postfeesz0.005020000z0.0025100000z0.0024200000z0.0022400000z0.0020600000z0.00151000000z0.00142000000z0.00134000000z0.001220000000z0.001150000000z0.0010	100000000z0.0007	500000000z0.0005
2000000000z0.0003
6000000000z0.000120000000000z0.0000520000000001)takermaker)	tierBased
percentager   r   tiersr   g      @)	BTCBCHLTCETHXRPXLMPAXUSDEUR)r   r   rv   deposit)tradingfundingprecisionModecommonCurrenciesUSTUSTCoptionsnetworksByIdzbitcoin-cashr   bitcoinr   ethereumERC20litecoinr   stellarr   xrplr   tronTRC20algorandALGOflareFLRhederaHBARcardanaADAsongbirdzavalanche-c-chainAVAXsolanaSOLpolkadotDOTnearNEARdogeDOGESUICSRP)suicasper
exceptions)zNo permission foundzAPI key not foundzIP address not allowedzInvalid noncezInvalid signaturezAuthentication failedz+Missing key, signature and nonce parameterszWrong API key formatzYour account is frozenzIPlease update your profile with your FATCA information, before using API.zOrder not found.z*Price is more than 20% below market price.z@Bitstamp.net is under scheduled maintenance. We'll be back soon.zOrder could not be placed.zInvalid offset.)zMinimum order size isz'Check your account balance for details.zEnsure self value has at leastz"Ensure that there are no more than)exactbroad)deep_extendsuperr(   describe
userAgentsparse_numberr%   r   r   r$   r    r   r#   r"   r   r   r   )self	__class__s    a/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/async_support/bitstamp.pyr   zbitstamp.describe   s   h 5 5 > > @ @ UC
*UC
JUC
 $UC

 UC
 tUC
 2UC
 4UC
  @@@ %@ 	@
 %@ %@ U@ "4@ t@ $U@  @ t@ (@ '@ (@  "5!@" #@ @$ +E%@& )%'@( ')@* (+@, "4-@. &t/@0 +D1@2 *:3@4 +D5@6 &u7@8 #E9@: *5;@< $U=@> "5?@@ *5A@B +EC@D tE@ @ @F  G@H "5I@J K@L !%M@N  O@P dQ@R +ES@T "4U@V dW@X !$Y@Z  [@\ $U]@^ !%_@` %ea@b )%c@d te@f g@ @h  $#'$((,%/$( %$!&#(  @ @ @UC
T }<=  25 UUC
f  gUC
B "$ $CUC
J ()./#$/0*+01/0'($%./   2345/0./	 b+Qb6b #Ab *1	b
 *1b 'b -ab 4Qb /b +Ab .qb (b (b -ab 4Qb  &q!b" -a#b b$ .q%b& ''b( .q)b* /+b, ,Q-b. .q/b0 ,Q1b2 (3b4 75b6 +A7b8 6q9b: /;b< +A=b> -a?b@ -aAbB 3ACbD 4QEb b bF +AGbH ,QIbL *1MbN 'ObP -aQbR *1SbT *1UbV 'WbX *1YbZ '[b\ *1]b^ '_b` *1abb 'cbd *1ebf 'gbh +Aib b bj (kbl +Ambn (obp *1qbr 'sbt *1ubv 'wbx *1ybz '{b| *1}b~ 'b@ *1AbB 'CbD +AEbF (GbH +AIbJ (Kb b bL *1MbN 'ObP *1QbR 'SbT *1UbV 'WbX *1YbZ '[b\ *1]b^ &q_b` ,Qabb )!cbd *1ebf 'gbh +Aibj (kbl +Amb b bn (obp )!qbr 'sbt +Aubv (wbx +Aybz ({b| ,Q}b~ )!b@ ,QAbB )!CbD *1EbF 'GbH *1IbJ 'KbL ,QMbN )!Ob b bP *1QbR 'SbT ,QUbV )!WbX *1YbZ '[b\ +A]b^ (_b` +Aabb (cbd *1ebf 'gbh *1ibj 'kbl *1mbn 'obp *1qb b br 'sbt *1ubv 'wbx *1ybz '{b| *1}b~ 'b@ *1AbB 'CbD +AEbF (GbH +AIbJ (KbL +AMbN (ObP +AQbR (Sb b bT *1UbV 'WbX *1YbZ '[b\ +A]b^ (_b` +Aabb (cbd +Aebf (gbh *1ibj 'kbl *1mbn 'obp +Aqbr (sbt *1ub b bv 'wbx *1ybz '{b| +A}b~ (b@ *1AbB 'CbD +AEbF (GbH *1IbJ 'KbL *1MbN 'ObP +AQbR (SbT +AUbV (Wb b bX ,QYbZ )![b\ *1]b^ '_b` +Aabb (cbd *1ebf 'gbh *1ibj 'kbl *1mbn 'obp ,Qqbr )!sbt *1ubv 'wbx *1yb b bz '{b| +A}b~ (b@ +AAbB (CbD *1EbF 'GbH +AIbJ (KbL *1MbN 'ObP 0QbR *1SbT 6qUbV +AWbX ,QYbZ )![b b b\ +A]b^ (_b` ,Qabb )!cbd ,Qebf )!gbh +Aibj (kbl +Ambn (obp +Aqbr (sbt +Aubv (wbx +Aybz ({b| +A}b b~ *+,-)*Cb b bj jz zKUC
@ !%"&!..w77!..w77 "..s33T5F5Fw5O5OP!..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!..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!..z::D<M<Mh<W<WX!..{;;T=N=Nx=X=XY!..{;;T=N=Nx=X=XY!..|<<d>O>OPX>Y>YZ!..|<<d>O>OPX>Y>YZ!..}==t?P?PQZ?[?[\!..}==t?P?PQT?U?UV#"( "..s33T5F5Fw5O5OP!..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!..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!..z::D<M<Mh<W<WX!..{;;T=N=Nx=X=XY!..{;;T=N=Nx=X=XY!..|<<d>O>OPX>Y>YZ!..|<<d>O>OPX>Y>YZ!..}==t?P?PQZ?[?[\!..}==t?P?PQT?U?UV#")' '- -^ "'"' "       " 
  
 	 _? ?AUC
@ YAUC
B v!CUC
J  !"E!u! ! 	!
 u! E! G! ! U! f! u! ! (! e! !  F!!" F#!$ !$'! ! !KUC
x +;)<.>%1)<-@CV,?.>aq(5BNXe2F'1 $ .:?P6D:F	 % yUC
 U U U	    returnc                 F  K   |                      |           d{V }g }t          dt          |                    D ]}||         }|                     |d          }|                    d          \  }}|                                }	|                                }
|                     |          }|                     |          }|                     |d          }|                    d          }|                     |d          }|                    i d|                     |d	          d
|	dz   |
z   d|dz   |z   d|d|ddd|	d|
d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!ddd!| 
                    |d          dd!d"d|d#           |S )$a1  
        retrieves data on all markets for bitstamp
        :see: https://www.bitstamp.net/api/#tag/Market-info/operation/GetTradingPairsInfo
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Nr   r+   /minimum_order r   r*   
url_symbolmarketId_symbolbasequotesettlebaseIdquoteIdsettleIdtyper8   Tr9   Fr;   r:   r<   activeEnabledcontractbase_decimalscounter_decimals)amountpriceminmax)leverager  r	  cost)linearinversecontractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedinfo)fetch_markets_from_cacherangelensafe_stringsplitlowersafe_currency_codeappendr   parse_precisionsafe_number)r   paramsresponseresultimarketr+   r   r   r   r   minimumOrderpartsstatuss                 r   fetch_marketszbitstamp.fetch_markets  s      66v>>>>>>>> q#h--(( <	 <	Aa[F##FF33D**S//KD%ZZ\\FkkmmG**400D++E22E++FODDL &&s++E%%fi88FMM 1d&&v|<<1FSL721 $*u,1 	1
 1 $1 &1 71 D1 1 1 %1 %1 1 %1  6Y.!1" E#1$  $"&""//0D0DTEUEUV\^mEnEn0o0opp!..t/C/CDDTDTU[]oDpDp/q/qrr   $#! !
  $# 
  $# 
  $//q99#  $  a1 1 1 1 1 1 1d r   c                 ^   d}|                                  }|                     |          rd}|                     |                     |                     |                              }	|||||dd d |                     |d         d         d         |          |	|	d d|	d d|d dd d ddi d	S )
NcryptofiatTr   r   rv   r
  )r  r	  r  rv   )r*   coder  r  r+   r  r   rv   feer  r  networks)r   is_fiatr   r"  number_to_stringr#  )
r   r*   r0  r+   r  minCostoriginalPayloadcurrencyTypedescriptiontickSizes
             r   construct_currency_objectz"bitstamp.construct_currency_objectK  s   mmoo<< 	"!L$$T%9%9$:O:OPY:Z:Z%[%[\\# ##K$7	$B:$NPTUU! $ 
 $ 
 # 
    $ ;
 
 	
r   c                   K   |                      | j        di           }|                     |d          }|                     |dd          }|                                 }|	||z
  |k    r<|                     |           d {V }|                     |||d          | j        d<   |                      | j        d         d          S )Nr\   	timestampexpires  )r%  r<  r%  )
safe_valuer   safe_integermillisecondspublicGetTradingPairsInfoextend)r   r$  r   r<  r=  nowr%  s          r   r  z!bitstamp.fetch_markets_from_cacheq  s       //$,CC%%g{;;	##GY==!!C)Ow#>#>!;;FCCCCCCCCH+/;;w$ A A , ,DL( t|N;ZHHHr   c           
      \  K   |                      |           d{V }i }t          dt          |                    D ]m}||         }|                     |d          }|                    d          \  }}|                                }	|                                }
|                     |          }|                     |          }|                     |d          }|                    d          \  }}|                     |d          }|                    d          }|d         }||vr3|                     |d	          }|                     |	|||d|          ||<   ||vrF|                     |d
          }|                     |
|||| 	                    |          |          ||<   o|S )a/  
        fetches all available currencies on an exchange
        :see: https://www.bitstamp.net/api/#tag/Market-info/operation/GetTradingPairsInfo
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        Nr   r+   r   r8  z / r   r   r  r  )
r  r  r  r  r  r  r   r@  r:  r   )r   r$  r%  r&  r'  r(  r+   r   r   r   r   r8  baseDescriptionquoteDescriptionr)  r*  r  baseDecimalscounterDecimalss                      r   fetch_currencieszbitstamp.fetch_currencies  s      66v>>>>>>>> q#h--(( 	S 	SAa[F##FF33D**S//KD%ZZ\\FkkmmG**400D++E22E**6=AAK0;0A0A%0H0H-O-++FODDL &&s++E8DFNN#00II#==fdO]ikoqwxxtVOO"&"3"3F<N"O"O $ > >wO_aprv  sD  sD  EI  sJ  sJ  LR  !S  !Sur   Nr   limitc                 z  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |d          }|                     |dz            }|                     ||d         |          }	||	d<   |	S )aE  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://www.bitstamp.net/api/#tag/Order-book/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
        Npairr*   microtimestampr>  r   nonce)load_marketsr(  publicGetOrderBookPairrC  r@  parse_to_intparse_order_book)
r   r   rK  r$  r(  requestr%  rN  r<  	orderbooks
             r   fetch_order_bookzbitstamp.fetch_order_book  s       !!!!!!!!!V$$F4L
 44T[[&5Q5QRRRRRRRR" **85EFF%%nt&;<<	))(F84DiPP	+	'r   r(  c                    |                      |d          }|                     ||d           }|                     |d          }|                      |d          }|                      |d          }t          j        ||          }|                      |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|          S )NrM  r<  vwapvolumelastr   datetimehighlowbid	bidVolumeask	askVolumeopenclosepreviousClosechanger   average)
baseVolumequoteVolumer  )r  safe_symbolsafe_timestampr&   
string_mulsafe_tickeriso8601)
r   tickerr(  r   r   r<  rX  rg  rh  rZ  s
             r   parse_tickerzbitstamp.parse_ticker  s   " ##FF33!!(FD99''<<	//%%fh77
(T::// !
f!
!
 Y//!
 D$$VV44	!

 4##FE22!
 4##FE22!
 !
 4##FE22!
 !
 D!
 D$$VV44!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&)!
 !
 !
* +  	r   c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: https://www.bitstamp.net/api/#tag/Tickers/operation/GetMarketTicker
        :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>`
        NrM  r*   )rP  r(  publicGetTickerPairrC  ro  )r   r   r$  r(  rT  rn  s         r   fetch_tickerzbitstamp.fetch_ticker   s       !!!!!!!!!V$$F4L
 //GV0L0LMMMMMMMM    000r   symbolsc                    K   |                                   d{V  |                     |           d{V }|                     ||          S )a*  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: https://www.bitstamp.net/api/#tag/Tickers/operation/GetCurrencyPairTickers
        :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>`
        N)rP  publicGetTickerparse_tickers)r   rs  r$  r%  s       r   fetch_tickerszbitstamp.fetch_tickers  si       !!!!!!!!!--f55555555" !!(G444r   c                 r   |                      |d          }||S |                     |g d          }t          |                                          }t	          dt          |                    D ]E}||         }|                    d          dk     r"|                     ||          }|
|dk    r|c S Fd S )Ncurrency)r1  r	  r[  r  r+  r*   r   r   )safe_string_loweromitlistkeysr  r  findr@  )r   transaction
currencyIdidsr'  r*   values          r    get_currency_id_from_transactionz)bitstamp.get_currency_id_from_transaction;  s     ++KDD
!ii .
 .
 .
   ;##%%&&q#c((## 	 	AQBwws||a))+r::%EQJJIIItr   c                    |                      |g d          }t          |                                          }t          |          }|dk    rFt	          | j        dz   |                     |          z   dz   |                     |          z             |dk    r^|d         |d         z   }|| j        v r|                     |          S |d         |d         z   }|| j        v r|                     |          S d S )N)r1  r	  r[  tidr  order_idside   z% getMarketFromTrade() too many keys: z in the trade: r   r   )	r{  r|  r}  r  r   r*   jsonmarkets_by_idsafe_market)r   tradecurrencyIdsnumCurrencyIdsr   s        r   get_market_from_tradezbitstamp.get_market_from_trade]  s7   		% "
 "
 "
   5::<<(([))A*Q QTXT]T]^iTjTj jm~ ~  BF  BK  BK  LQ  BR  BR  !R  S  S  SQ"1~A6H4---''111"1~A6H4---''111tr   c                 T   |                      |dd          }d }d }|                     |d          }|                     |d          }|                     |d          }d }	|                     |d          }
d }|t          |                                          }t	          dt          |                    D ]B}||         }|dk    r2|                    d          dk    r|}|                     ||d          }C||                     |          }|                     |d	          }|d
         }||n|d         }|                     |||          }|                     ||d         |          }|                     ||d         |
          }
|d         }|                      |dd          }d }|C|                    d          dk    r| 	                    |          }nt          |          }|dz  }d|v r3|0t          j        |d          }|rd}t          j        |          }n-d}n*|                     |d          }|dk    rd}n|dk    rd}nd }|
t          j        |
          }
d }|||d}|                     ||||                     |          |||	|d |||
|d|          S )Nr*   r  r	  r  r  r  r   r   r1  r   r   r   r   r   dater[  r   r>  r   sellbuyr  1)r  ry  )r*   r  r<  r[  r   orderr  r  takerOrMakerr	  r  r  r1  )safe_string_2r  r|  r}  r  r  r~  r  r  	parse8601intr&   	string_lt
string_neg
string_abs
safe_traderm  )r   r  r(  r*   r   r  priceStringamountStringorderIdr  
costStringrawMarketIdr}  r'  
currentKeyfeeCostStringfeeCurrencypriceIddatetimeStringr<  isAmountNegr1  s                         r   parse_tradezbitstamp.parse_tradet  s   P tU33&&ug66''x88""5*55%%eV44
>

%%D1c$ii(( H H!!W
++
0D0D0I0I",K!--k63GGF >//66F((66Wo"-"9++z@R&&ug{CC''vh/?NN%%eVI->
KK
!++E6:FF	%""3''1,, NN>::		  //	%,	5=='%/cBB !!D#*#5l#C#CLL D##E622Ds{{! +J77J$%' C "Y//  " 
  
   	r   sincec                   K   |                                   d{V  |                     |          }|d         dd}|                     |                     ||                     d{V }|                     ||||          S )a;  
        get the list of most recent trades for a particular symbol
        :see: https://www.bitstamp.net/api/#tag/Transactions-public/operation/GetTransactions
        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        Nr*   hour)rM  time)rP  r(  publicGetTransactionsPairrC  parse_trades)r   r   r  rK  r$  r(  rT  r%  s           r   fetch_tradeszbitstamp.fetch_trades  s       !!!!!!!!!V$$4L
 
 77GV8T8TUUUUUUUU&   65%@@@r   c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr<  rb  r\  r]  rc  rY  )rj  r#  )r   ohlcvr(  s      r   parse_ohlcvzbitstamp.parse_ohlcv  s     {33UF++UF++UE**UG,,UH--
 	
r   r   c                   K   |                                   d{V  |                     |          }|d         |                     | j        ||          d}|                     |          }|L|d|d<   nd}|                     |dz            }	|	|d<   |                     |	||dz
  z            |d<   ||d<   nQ|<|                     |dz            }	|	|d<   |                     |	||dz
  z            |d<   t          |d          |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
        :see: https://www.bitstamp.net/api/#tag/Market-info/operation/GetOHLCData
        :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
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nr*   )rM  stepr>  rK  startr   enddataohlc)rP  r(  r  r~   parse_timeframerR  sumr  publicGetOhlcPairrC  r?  	safe_listparse_ohlcvs)r   r   	timeframer  rK  r$  r(  rT  durationr  r%  r  r  s                r   fetch_ohlcvzbitstamp.fetch_ohlcv#  s      !!!!!!!!!V$$4L$$T_iKK
 
 ''	22=}#'  ))%$,77#( !%%UQY1G!H!H#(   ))%$,77#( !%%UQY1G!H!H"5$//GG//GV0L0LMMMMMMMM x44~~dFB//  vy%GGGr   c                    |d d d}|g }t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |                     |d          |d<   |||<   |                     |          S )	N)r  r<  r[  r   ry  	availablefreereservedusedtotal)r  r  r  r   accountsafe_balance)r   r%  r&  r'  currencyBalancer  currencyCoder  s           r   parse_balancezbitstamp.parse_balanceU  s    
 

 Hq#h--(( 	+ 	+A&qkO))/:FFJ22:>>LllnnG"..LLGFO"..
KKGFO#//IIGG#*F<    (((r   c                    K   |                                   d{V  |                     |           d{V }|                     |          S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://www.bitstamp.net/api/#tag/Account-balances/operation/GetAccountBalances
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        N)rP  privatePostAccountBalancesr  r   r$  r%  s      r   fetch_balancezbitstamp.fetch_balanceh  sg       !!!!!!!!!88@@@@@@@@ !!(+++r   c                 f  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |d          }|                     ||d                   }|                     ||          S )ai  
        fetch the trading fees for a market
        :see: https://www.bitstamp.net/api/#tag/Fees/operation/GetTradingFeesForCurrency
        :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>`
        Nmarket_symbolr*   currency_pair)rP  r(  privatePostFeesTradingrC  index_by	safe_dictparse_trading_fee)r   r   r$  r(  rT  r%  tradingFeesByMarketId
tradingFees           r   fetch_trading_feezbitstamp.fetch_trading_fee~  s       !!!!!!!!!V$$VD\
 44T[[&5Q5QRRRRRRRR !%h H H^^$96$<HH
%%j&999r   c                     |                      |d          }|                     |di           }||                     ||          |                     |d          |                     |d          d d dS )Nr(  r   r   r   )r  r   r   r   r   r   )r  r  ri  r#  )r   r1  r(  r   r   s        r   r  zbitstamp.parse_trading_fee  s}    ##C22~~c62..&&x88%%dG44%%dG44
 
 	
r   c                     d|i}| j         }t          dt          |                    D ]*}||         }|                     ||                   }|||<   +|S )Nr  r   )rs  r  r  r  )r   r   r&  rs  r'  r   r1  s          r   parse_trading_feeszbitstamp.parse_trading_fees  sa    $,q#g,,'' 	! 	!AQZF((a11C F6NNr   c                    K   |                                   d{V  |                     |           d{V }|                     |          S )aa  
        fetch the trading fees for multiple markets
        :see: https://www.bitstamp.net/api/#tag/Fees/operation/GetAllTradingFees
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        N)rP  r  r  r  s      r   fetch_trading_feeszbitstamp.fetch_trading_fees  sg       !!!!!!!!!44V<<<<<<<< &&x000r   codesc                    K   |                                   d{V  |                     |           d{V }|                     |          S )a~  
         * @deprecated
        please use fetchDepositWithdrawFees instead
        :see: https://www.bitstamp.net/api/#tag/Fees
        :param str[]|None codes: list of unified currency codes
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
        N)rP  privatePostFeesWithdrawalparse_transaction_fees)r   r  r$  r%  s       r   fetch_transaction_feeszbitstamp.fetch_transaction_fees  sg       !!!!!!!!!77???????? **8444r   c                    i }|                      |d          }t          |                                          }t          dt	          |                    D ]}||         }|                     ||i           }|                     |          }	||                     |	|          sO|                     |d          i | 	                    ||          d||	<   |S )Nry  r   r1  )withdraw_feer   r  )
r  r|  r}  r  r  r?  r   in_arrayr#  r  )
r   r%  r  r&  
currenciesr  r'  r*   r   r0  s
             r   r  zbitstamp.parse_transaction_fees  s    ]]8Z88
:??$$%%q#c((## 
	 
	AQB??8Q33D**2..D!4==u+E+E! $ 0 0u = =z266 F4LL
 r   c                    K   |                                   d{V  |                     |           d{V }|                     |d          }|                     ||          S )az  
        fetch deposit and withdraw fees
        :see: https://www.bitstamp.net/api/#tag/Fees/operation/GetAllWithdrawalFees
        :param str[]|None codes: list of unified currency codes
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
        Nry  )rP  r  group_byparse_deposit_withdraw_fees)r   r  r$  r%  responseByCurrencyIds        r   fetch_deposit_withdraw_feesz$bitstamp.fetch_deposit_withdraw_fees  s~       !!!!!!!!!77????????  $}}XzBB//0DeLLLr   c                 :   |                      |          }t          dt          |                    D ]g}||         }|                     |d          }|                     |          }|                     |d          }|d d|d<   |d dd d dd|d         |<   h|S )Nr   networkr1  )r1  r   rv   )rv   r   r2  )deposit_withdraw_feer  r  r  network_id_to_coder#  )	r   r1  ry  r&  jnetworkEntry	networkIdnetworkCodewithdrawFees	            r   parse_deposit_withdraw_feez#bitstamp.parse_deposit_withdraw_fee  s    **3//q#c((## 	 	Aq6L((yAAI11)<<K**<??K""" "F: '"& 
  "& 	/ 	/F:{++ r   r  r  r  r	  c                 "  K   |                                   d{V  |                     |          }|d         |                     ||          d}|                     |dd          }	|	|	|d<   |                     |dg          }d}
|                     |          }|dk    rg|dk    r1|                     |                     ||                     d{V }
n|                     |                     ||                     d{V }
n|dk    rf|dk    r0| 	                    |                     ||                     d{V }
n| 
                    |                     ||                     d{V }
n~|                     ||          |d	<   |dk    r0|                     |                     ||                     d{V }
n/|                     |                     ||                     d{V }
|                     |
|          }||d
<   |S )a[  
        create a trade order
        :see: https://www.bitstamp.net/api/#tag/Orders/operation/OpenInstantBuyOrder
        :see: https://www.bitstamp.net/api/#tag/Orders/operation/OpenMarketBuyOrder
        :see: https://www.bitstamp.net/api/#tag/Orders/operation/OpenLimitBuyOrder
        :see: https://www.bitstamp.net/api/#tag/Orders/operation/OpenInstantSellOrder
        :see: https://www.bitstamp.net/api/#tag/Orders/operation/OpenMarketSellOrder
        :see: https://www.bitstamp.net/api/#tag/Orders/operation/OpenLimitSellOrder
        :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 fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr*   )rM  r  client_order_idclientOrderIdr(  Buyinstantr	  r  )rP  r(  amount_to_precisionr  r{  
capitalizeprivatePostBuyMarketPairrC  privatePostSellMarketPairprivatePostBuyInstantPairprivatePostSellInstantPairprice_to_precisionprivatePostBuyPairprivatePostSellPairparse_order)r   r   r  r  r  r	  r$  r(  rT  r  r%  capitalizedSider  s                r   create_orderzbitstamp.create_order"  sn     " !!!!!!!!!V$$4L..vv>>
 
 **63DoVV$)6G%&YYv'899F//$//8%''!%!>!>t{{7TZ?[?[!\!\\\\\\\!%!?!?GU[@\@\!]!]]]]]]]Y%''!%!?!?GU[@\@\!]!]]]]]]]!%!@!@WV\A]A]!^!^^^^^^^#66vuEEGG%''!%!8!8Wf9U9U!V!VVVVVVV!%!9!9$++gv:V:V!W!WWWWWWW  622fr   r*   c                    K   |                                   d{V  d|i}|                     |                     ||                     d{V S )a  
        cancels an open order
        :see: https://www.bitstamp.net/api/#tag/Orders/operation/CancelOrder
        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr*   )rP  privatePostCancelOrderrC  )r   r*   r   r$  rT  s        r   cancel_orderzbitstamp.cancel_orderS  sn       !!!!!!!!!"
 00Wf1M1MNNNNNNNNNr   c                 L  K   |                                   d{V  d}i }d}|P|                     |          }|d         |d<   |                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|S )a
  
        cancel all open orders
        :see: https://www.bitstamp.net/api/#tag/Orders/operation/CancelAllOrders
        :see: https://www.bitstamp.net/api/#tag/Orders/operation/CancelOrdersForMarket
        :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
        :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*   rM  )rP  r(  privatePostCancelAllOrdersPairrC  privatePostCancelAllOrders)r   r   r$  r(  rT  r%  s         r   cancel_all_orderszbitstamp.cancel_all_ordersb  s       !!!!!!!!![[((F$TlGFO!@@WV\A]A]^^^^^^^^HH!<<T[[RX=Y=YZZZZZZZZHr   c                 >    ddddd}|                      |||          S )Nrb  closedcanceled)zIn QueueOpenFinishedCanceledr  r   r+  statusess      r   parse_order_statuszbitstamp.parse_order_statusw  s4     "	
 
 &&999r   c                 f  K   |                                   d {V  |                     |dd          }i }|||d<   |                     |ddg          }n||d<   |                     |                     ||                     d {V }|                     |                     |d                    S )Nr  r  r*   r+  )rP  safe_value_2r{  privatePostOrderStatusrC  r  r  )r   r*   r   r$  r  rT  r%  s          r   fetch_order_statuszbitstamp.fetch_order_status  s      !!!!!!!!!))&2C_UU$)6G%&YYv(9?'KLLFFGDM44T[[&5Q5QRRRRRRRR&&t'7'7('K'KLLLr   c                 r  K   |                                   d{V  d}||                     |          }|                     |dd          }i }|||d<   |                     |ddg          }n||d<   |                     |                     ||                     d{V }|                     ||          S )a  
        fetches information on an order made by the user
        :see: https://www.bitstamp.net/api/#tag/Orders/operation/GetOrderStatus
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr  r  r*   )rP  r(  r  r{  r  rC  r  )r   r*   r   r$  r(  r  rT  r%  s           r   fetch_orderzbitstamp.fetch_order  s       !!!!!!!!![[((F))&2C_UU$)6G%&YYv(9?'KLLFFGDM44T[[&5Q5QRRRRRRRR& &111r   c                 f  K   |                                   d{V  i }d}d}|%|                     |          }|d         |d<   |dz  }|||d<    t          | |          |                     ||                     d{V }|                     |dd          }	|                     |	|||          S )	a  
        fetch all trades made by the user
        :see: https://www.bitstamp.net/api/#tag/Transactions-private/operation/GetUserTransactions
        :see: https://www.bitstamp.net/api/#tag/Transactions-private/operation/GetUserTransactionsForMarket
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        NprivatePostUserTransactionsr*   rM  PairrK  r  2)rP  r(  getattrrC  	filter_byr  )
r   r   r  rK  r$  rT  methodr(  r%  r&  s
             r   fetch_my_tradeszbitstamp.fetch_my_trades  s       !!!!!!!!!.[[((F$TlGFOfF$GG.v..t{{7F/K/KLLLLLLLL&#66  >>>r   r0  c                 @  K   |                                   d{V  i }|||d<   |                     |                     ||                     d{V }d}||                     |          }|                     |dddgd          }|                     ||||          S )a  
        fetch history of deposits and withdrawals
        :see: https://www.bitstamp.net/api/#tag/Transactions-private/operation/GetUserTransactions
        :param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
        :param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
        :param int [limit]: max number of deposit/withdrawals to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        NrK  r  r   r  F)rP  r!  rC  ry  filter_by_arrayparse_transactions)	r   r0  r  rK  r$  rT  r%  ry  transactionss	            r   fetch_deposits_withdrawalsz#bitstamp.fetch_deposits_withdrawals  s       !!!!!!!!!$GG99$++gv:V:VWWWWWWWW6 }}T**H++HfsCj%PP&&|XueLLLr   c                   K   |                                   d{V  i }||                                 |z
  |d<   nd|d<   |                     |                     ||                     d{V }|                     |d||          S )a.  
        fetch all withdrawals made from an account
        :see: https://www.bitstamp.net/api/#tag/Withdrawals/operation/GetWithdrawalRequests
        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        N	timedeltai)rP  rA  privatePostWithdrawalRequestsrC  r*  )r   r0  r  rK  r$  rT  r%  s          r   fetch_withdrawalszbitstamp.fetch_withdrawals  s       !!!!!!!!!#'#4#4#6#6#>GK  #+GK ;;DKKQW<X<XYYYYYYYY2 &&xueDDDr   ry  c                 ^   |                      |                     |d                    }|                     |          }|                     ||          }|                     |d          }d }d }d|v r|                     |d          }nE|&|                     ||d         |          }|d         }n|||                     |||          }|}|t	          j        |          }d}	d|v r)|                     |                     |d                    }	d }
d|v r(|                     |d          }|d	k    rd
}
n|dk    rd}
nd}
d }|                     |d          }|:|                    d          }t          |          }|dk    r|d         }|d         }d d d d}|||d d}i d|d|                     |d          d|                     |d          d|
d|dd d| 	                    |          d|	d|d| 
                    |          d|dd d|d|dd d|dd d d |dS )Nr[  r1  r  r*   r0  okr+  r  r   r   r  
withdrawaladdressz?dt=r   r   )ry  r  rater  txidtransaction_idry  r  r<  addressFrom	addressTotagtagFromtagToupdated)commentinternalr1  )r  r  r  r   r&   r  parse_transaction_statusr  r  r   rm  )r   r  ry  r<  r  r0  feeCostr  r  r+  r  rawTyper:  r4  addressPartsnumPartsr1  s                    r   parse_transactionzbitstamp.parse_transaction'  s*   P NN4#3#3K#L#LMM	::;GG
&&z8<<"";66{""%%k8<<FF!%%k8D>6JJF"6*KKZ%;%%k:vFFFK'//F{""2243C3CKQY3Z3Z[[F[  &&{F;;G#~~ C#  D"";	::"==00L<((H!||&q/"1o
 

 ' C

K
$"";55
 D$$[2BCC
 D	

 
 t
 d''//
 f
 
 Y//
 w
 4
 
 3
 t
  S!
" t#
$ )
 
 
 	
r   c                 @    dddddd}|                      |||          S )Npendingr2  r  failed)r   r  r#  34r  r  s      r   r@  z!bitstamp.parse_transaction_status  s9     
 
 &&999r   c           	         |                      |d          }|                      |d          }|                      |d          }|
|dk    rdnd}|                     |                      |d                    }|                     |d          }|                     ||d	          }|                     |                      |d
                    }	|                      |d          }
|                     |dg           }|                      |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|          S )Nr*   r  r  r  r  r  r[  r  r   r+  r  r+  r	  r  r<  lastTradeTimestampr   timeInForcepostOnlyr  	stopPricetriggerPricer  filled)	remainingtradesr1  r  rf  )r  r  rz  ri  r  r?  
safe_orderrm  )r   r  r(  r*   r  r  r<  r   r   r+  r  r+  r	  s                r   r  zbitstamp.parse_order  s   P eT**((0ABBv.."ckk66DNN4#3#3E:#F#FGG	))%AA!!(FC88(()9)9%)J)JKK!!%22unbAA  00  
" 
] 
 Y// 
 	 

 !$ 
 f 
 f 
 D 
 4 
  
 D 
 U 
  
 D 
 D 
  f! 
" d# 
$ "- 
  
  
. /  	r   c                 >    ddddd}|                      |||          S )Nr  r  ru   )r   r  r#  14r  )r   r  typess      r   parse_ledger_entry_typez bitstamp.parse_ledger_entry_type  s4    	
 
 tT222r   c                 n   |                      |                     |d                    }|dk    r|                     |          }d }t          |                                          }t          dt          |                    D ]S}||                             d          dk    r2||                             dd          }| 	                    ||          }T|| 
                    |          }|d         dk    rdnd	}	|d
         ||d         |d         |	d |d         d ||d         |d         d d d|d         dS |                     ||          }
d }	d|v r0|                     |d          }t          j        |d          rdnd	}	nld|
v rh|
d         `|                     |
d          }|                     |          }|                     ||d
                   }t          j        |d          rdnd	}	|
d
         ||
d         |
d         |	d |
d         d ||
d         |
d         d d |
d         |
d         dS )Nr  r  r   r    r  r  inoutr*   r<  r[  r  r   r  r2  r1  )r*   r  r<  r[  	directionr  referenceIdreferenceAccountr  ry  r  beforeafterr+  r1  r   ry  r6  r+  )rX  r  r  r|  r}  r  r  r~  replacer  r  rE  r&   	string_gtry  )r   itemry  r  parsedTrader(  r}  r'  r   r]  parsedTransactionr  r  s                r   parse_ledger_entryzbitstamp.parse_ledger_entry  s   6 ++D,<,<T6,J,JKK7??**400KF		$$D1c$ii(( @ @7<<$$))#AwsB77H!--h??F ~33D99!,V!4!=!=EI!$'(5'
3&*73$("6N%h/"5)  $ !% 6 6tX F FI4))$99$+$5fc$B$BMDD		 1117H7T7`#//0A:NN==66))$??$+$5fc$B$BMDD	'-.{;-j9&08$(-j9+H5+H5(/  r   c                   K   |                                   d{V  i }|||d<   |                     |                     ||                     d{V }d}||                     |          }|                     ||||          S )aw  
        fetch the history of changes, actions done by the user or operations that altered balance of the user
        :see: https://www.bitstamp.net/api/#tag/Transactions-private/operation/GetUserTransactions
        :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 entrys to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger-structure>`
        NrK  )rP  r!  rC  ry  parse_ledger)r   r0  r  rK  r$  rT  r%  ry  s           r   fetch_ledgerzbitstamp.fetch_ledgerU  s       !!!!!!!!!$GG99$++gv:V:VWWWWWWWW}}T**H  8UEBBBr   c           	         K   d}|                                   d{V  ||                     |          }|                     |           d{V }|                     ||||ddd          S )ar  
        fetch all unfilled currently open orders
        :see: https://www.bitstamp.net/api/#tag/Orders/operation/GetAllOpenOrders
        :see: https://www.bitstamp.net/api/#tag/Orders/operation/GetOpenOrdersForMarket
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of  open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nrb  rK  )r+  r  )rP  r(  privatePostOpenOrdersAllparse_orders)r   r   r  rK  r$  r(  r%  s          r   fetch_open_orderszbitstamp.fetch_open_ordersi  s       !!!!!!!!![[((F66v>>>>>>>>   65%B
 B
   	r   c                 *    |                                 S )z{
         * @ignore
        :param str code: Unified currency code
        :returns str: lowercase version of code
        )r  r   r0  s     r   get_currency_namezbitstamp.get_currency_name  s     zz||r   c                 &    |dk    p|dk    p|dk    S )Nr   r   GBP rp  s     r   r3  zbitstamp.is_fiat  s    u}>>>r   c                   K   |                      |          rt          | j        dz   |z   dz             |                     |          }d|                     |          z   dz   } t          | |          |           d{V }|                     |d          }|                     |dd          }|                     |           |||d|d	S )
a  
        fetch the deposit address for a currency associated with self account
        :see: https://www.bitstamp.net/api/#tag/Deposits/operation/GetCryptoDepositAddress
        :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>`
        z  fiat fetchDepositAddress() for z is not supported!privatePostAddressNr4  memo_iddestination_tag)ry  r4  r:  r  r  )	r3  r!   r*   rq  r  r$  r  r  check_address)r   r0  r$  r+   r&  r%  r4  r:  s           r   fetch_deposit_addresszbitstamp.fetch_deposit_address  s       << 	ktw)KKdRUiijjj%%d++!6!66B.v..v66666666""8Y77  96GHH7###
 
 	
r   c                 ^  K   |                      ||          \  }}|                                  d{V  |                     |           d|i}d}d}|                     |          sW|                     |          }	d|                     |	          z   dz   }|dk    r|||d<   n|dk    s|dk    r|||d	<   ||d
<   n'd}|                     |          }||d<   |d         |d<    t          | |          |                     ||                     d{V }
| 	                    |
|          S )aI  
        make a withdrawal
        :see: https://www.bitstamp.net/api/#tag/Withdrawals/operation/RequestFiatWithdrawal
        :see: https://www.bitstamp.net/api/#tag/Withdrawals/operation/RequestCryptoWithdrawal
        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr  rv  
Withdrawalr   ry  r   r   rx  r4  privatePostWithdrawalOpenibanr*   account_currency)
handle_withdraw_tag_and_paramsrP  rz  r3  rq  r  ry  r$  rC  rE  )r   r0  r  r4  r:  r$  rT  ry  r&  r+   r%  s              r   rv   zbitstamp.withdraw  sw      99#vFFV!!!!!!!!!7###f
 ||D!! 	9))$//D"T__T%:%::\IFu}}?14G-.$&..?),GI&!(GI0F}}T**H%GFO*24.G&'.v..t{{7F/K/KLLLLLLLL%%h999r   fromAccount	toAccountc                 `  K   |                                   d{V  |                     |          }|                     ||          }|                     |          }||d                                         d}d}|dk    r5||d<   |                     |                     ||                     d{V }nR|dk    r5||d<   |                     |                     ||                     d{V }nt          | j	        dz             | 
                    ||          }	||	d<   ||	d<   ||	d	<   |	S )
a  
        transfer currency internally between wallets on the same account
        :see: https://www.bitstamp.net/api/#tag/Sub-account/operation/TransferFromMainToSub
        :see: https://www.bitstamp.net/api/#tag/Sub-account/operation/TransferFromSubToMain
        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        Nr*   )r  ry  main
subAccountz) transfer() only supports from or to mainr  r  r  )rP  ry  currency_to_precisionparse_to_numericupperprivatePostTransferFromMainrC  privatePostTransferToMainr   r*   parse_transfer)
r   r0  r  r  r  r$  ry  rT  r%  ru   s
             r   ru   zbitstamp.transfer  st      !!!!!!!!!==&&++D&99&&v.. ,,..
 
 &  $-GL!!==dkk'SY>Z>Z[[[[[[[[HH&  $/GL!!;;DKKQW<X<XYYYYYYYYHHTW'RRSSS &&x::#"- )r   c                 x    |                      |d          }|d d d |d         d d d |                     |          d	S )Nr+  r0  )	r  r*   r<  r[  ry  r  r  r  r+  )r  parse_transfer_status)r   ru   ry  r+  s       r   r  zbitstamp.parse_transfer  sV     !!(H55 (0088

 

 
	
r   c                 :    ddd}|                      |||          S )Nr2  rH  )r2  errorr  r  s      r   r  zbitstamp.parse_transfer_status  s.    
 
 &&999r   c                 *    |                                  S N)rA  )r   s    r   rO  zbitstamp.nonce  s      """r   rx   GETc                 j   | j         d         |         dz   }|| j        dz   z  }||                     ||          z  }|                     ||                     |                    }|dk    r|r|d|                     |          z   z  }n#|                                  d| j        z   }	|                                 }
t          | 
                                          }d}d}|	|
||d}|d	k    r=|r|                     |          }d
}||d<   n|                     ddi          }d
}||d<   |r|nd}|	|z   |                    dd          z   |z   |
z   |z   |z   |z   }|                     |                     |          |                     | j                  t          j                  }||d<   ||||dS )Nr{   r   rx   ?z	BITSTAMP r2   rZ  )zX-AuthzX-Auth-NoncezX-Auth-TimestampzX-Auth-VersionPOSTz!application/x-www-form-urlencodedzContent-Typefoobarzhttps://zX-Auth-Signature)urlr&  bodyheaders)rw   r1   implode_paramsr{  extract_params	urlencodecheck_required_credentialsr   uuidstrrA  rb  hmacencoder   hashlibsha256)r   pathr{   r&  r$  r  r  r  queryxAuth
xAuthNoncexAuthTimestampxAuthVersioncontentTypeauthBodyauth	signatures                    r   signzbitstamp.sign  s   is#c)t|c!!t""4000		&$"5"5d";";<<(?? 3sT^^E2222++---$+-EJ !2!2!4!455NLK *$2".	 G  :>>%00D"EK.9GN++  >>5%.99D"EK.9GN+#+ttH6>CKK
B$?$??+MPZZ]kknzz  ~F  FD		$++d"3"3T[[5M5Mw~^^I*3G&'fdwOOOr   c
                    |d S |                      |d          }
|                     |d          }|
dk    s|g }t          |t                    r|                    |           n|t          |                                          }t          dt          |                    D ]a}||         }|                     ||          }t          |t
                    r| 	                    ||          }L|                    |           b|                     |di           }t          |t                    r|                    |           nR|                     |dg           }t          dt          |                    D ]}|                    ||                    |                      |d          }|dk    rt          | j        dz             | j        d	z   |z   }t          dt          |                    D ]N}||         }|                     | j        d
         ||           |                     | j        d         ||           Ot          |          d S )Nr+  r  r   reason__all__r0  API0005zL invalid signature, use the uid for the main account if you have subaccountsr   r   r   )r  r?  
isinstancer  r!  r|  r}  r  r  array_concatr   r*   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r   httpCoder  r  r&  r  r  r%  requestHeadersrequestBodyr+  r  errorsr}  r'  keyr  reasonInnerallr0  feedbacks                        r   handle_errorszbitstamp.handle_errors?  se   4 !!(H55'22g5#4F%%% 
-e$$$$"EJJLL))q#d)),, - -Aq'C OOE377E!%.. -!%!2!265!A!Ae,,,,//(HbAAK+s++ *k****ook9bAAq#c((++ * *AMM#a&))))##Hf55Dy  )$'  5C  +C  D  D  Dw}t+H1c&kk** ` `q	44T_W5MuV^___44T_W5MuV^____)))tr   r  )N__name__
__module____qualname__r   r   r	   r,  r:  r  r   rJ  r  r   r   rV  r   ro  rr  r   r   rw  r  r  r   r  r  r|  r  r  r   r  r  r   r  r  r  r   r  r  r  r  r  r   r   floatr
   r  r   r  r  r  r  r  r'  r   r,  r0  r   rE  r@  r   r  rX  rg  rj  rn  rq  r3  r{  rv   r   ru   r  r  rO  r  r  __classcell__)r   s   @r   r(   r(      s-       V V V V Vp *, T TV T T T Tl$
 $
 $
L 57 I I I I -/ * *: * * * *X @DB # #S # #S\ # # # #J- -6 -V - - - -^ 68 1 1 1F 1 1 1 1> 6:" 5 57 5 5 5 5 58     D  .t t t5 t t t tl <@d[] #A #A #AS #A #Abfglbm #A #A #A #AJ
 
 
4 
 
 
 
( 8<$]ajl 0H 0H 0HC 0HWZ 0Hquvzq{ 0H 0H 0H 0Hd) ) ) ) )& *, , , , , , ,, ;= : :c :AT : : : :@

 

V 

?R 

 

 

 

   /1 1 1[ 1 1 1 12 ?C2 5 5$s) 5 5 5 5.   " 7;2 M M M M.   . mqy{ / / /I /Y /X] /fi / / / /b 9=R O OS O# O O O O 59  c    *: : : ?C2 
M 
M3 
M 
M 
M 
M 
M 8<B &2 &2C &2 &2 &2 &2 &2P 37TX\eg ? ?C ?s ?RU ? ? ? ?2 <@daenp -M -MS -M -M[^ -Muy  {F  vG -M -M -M -M^ 37TX\eg )E )EC )Es )ERU )Elpq|l} )E )E )E )EVp
 p
x p
; p
 p
 p
 p
d: : :L L L5 L L L L\3 3 3U U U U U Un .2SW`b C Cs C# CS C C C C( 59tZ^gi    c    TW  nrsxny        D  ? ? ? =? 
 
 
 
 
 
0 EIQS &: &:3 &: &: &: &: &:P ac $ $3 $ $C $TW $gt $ $ $ $L
 
 
 
": : :# # # &eBSW &P &P &P &PP' ' ' ' ' ' 'r   r(   )- ccxt.async_support.base.exchanger   ccxt.abstract.bitstampr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   r   r   r    r!   r"   r#   r$   ccxt.base.decimal_to_precisionr%   ccxt.base.preciser&   r(   rt  r   r   <module>r     s~   6 5 5 5 5 5 . . . . . .  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y  Y       * * * * * * 0 0 0 0 0 0 - - - - - - ' ' ' ' ' ' . . . . . . + + + + + + ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) 1 1 1 1 1 1 * * * * * * ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %K! K! K! K! K!x K! K! K! K! K!r   