
    !:hR                    0   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 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)y)    )Exchange)ImplicitAPIN)AnyBalancesCurrencyDepositAddressIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTransaction)List)ExchangeError)AuthenticationError)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)DuplicateOrderId)ExchangeNotAvailable)	TICK_SIZE)Precisec                       e Zd Zdef fdZ fdZi fdefdZdi fdefdZd Z	i fde
e   fd	Zd
i fdededefdZdRdefdZd Zddi d
d
fdZi fdZdSded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d
d
i fdededede
e   fdZd ZdSdedefdZi fdedefdZ d  Z!d! Z"d" Z#dSded#e$fd$Z%ded%efd&Z&ded'e$fd(Z'ded)efd*Z(ded#e$fd+Z)ded%efd,Z*d- Z+d. Z,d
i fded/e-d0e.d#e$d'e/f
d1Z0d
i fd2ede1fd3Z2d
i fd2ede1fd4Z3d
d
d
i fde1dedede
e4   fd5Z5d
d
d
i fde1dedede
e4   fd6Z6d
d
d
i fde1dedede
e4   fd7Z7d8e1fd9Z8d: Z9dSd;edede4fd<Z:d= Z;i fde<fd>Z=dTd?Z>d
d
d
i fde1dedefd@Z?d
d
i fdededede
e@   fdAZAdSdBedede@fdCZBdRdDedefdEZCd
i fdDefdFZDdeEdGedHedIedJedKefdLZFd
i fded#e$dMedeGfdNZHdSdOedPeIdeGfdQZJ xZKS )Uwavesexchangereturnc                 P   | j                  t        t        |          i ddddddg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 d0dd1dd2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@di dAddBddCddDddEddFddGddHddIddJddKddLddMddNddOddPddQddRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodig dpdqdrdsg dtg dudvdwgdwgdxg dyg dzd{d|gd}d~g dig ddgdddgdgdd~dgididd| j	                  dd d| j                  d      d      idt        ddd dd d dd dddddddddddddd ddd dddddddddddddd dddddddddddddddddddd d ddddddddddddddd id	d d dd d dddddidd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        d      S )Nidr%   namezWaves.Exchange	countriesCH	certifiedFprodexThasCORSspotmarginswapfutureoption	addMargincancelOrdercloseAllPositionsclosePositioncreateMarketOrdercreateOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchLeverageTiersfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTransferfetchTransfersreduceMarginsandboxsetLeveragesetMarginModesetPositionModesignIntransferwithdrawws
timeframes1m5m15m30m1h2h3h4h6h12h1d1w1M)rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   urlszchttps://user-images.githubusercontent.com/1294454/84547058-5fb27d80-ad0b-11ea-8711-78ac8b3c7f31.jpgz"https://matcher-testnet.wx.networkz$https://nodes-testnet.wavesnodes.comz(https://api-testnet.wavesplatform.com/v0z!https://api-testnet.wx.network/v1z1https://testnet.wx.network/api/v1/forward/matcherz;https://testnet.wx.network/api/v1/forward/marketdata/api/v1)matchernodepublicprivateforwardmarketzhttps://matcher.wx.networkzhttps://nodes.wx.networkz https://api.wavesplatform.com/v0zhttps://api.wx.network/v1z)https://wx.network/api/v1/forward/matcherz3https://wx.network/api/v1/forward/marketdata/api/v1)zhttps://docs.wx.networkzhttps://docs.waves.techz&https://api.wavesplatform.com/v0/docs/z0https://nodes.wavesnodes.com/api-docs/index.htmlz2https://matcher.waves.exchange/api-docs/index.htmlzhttps://wx.network)logotestapidocwwwr   )r   zmatcher/settingszmatcher/settings/ratesz$matcher/balance/reserved/{publicKey}zmatcher/debug/allSnashotOffsetszmatcher/debug/currentOffsetzmatcher/debug/lastOffsetz"matcher/debug/oldestSnapshotOffsetzmatcher/debug/configzmatcher/debug/address/{address}zmatcher/debug/statusz%matcher/debug/address/{address}/checkmatcher/orderbook$matcher/orderbook/{baseId}/{quoteId}z:matcher/orderbook/{baseId}/{quoteId}/publicKey/{publicKey}z.matcher/orderbook/{baseId}/{quoteId}/{orderId}z)matcher/orderbook/{baseId}/{quoteId}/infoz+matcher/orderbook/{baseId}/{quoteId}/statusz>matcher/orderbook/{baseId}/{quoteId}/tradableBalance/{address}zmatcher/orderbook/{publicKey}z'matcher/orderbook/{publicKey}/{orderId}matcher/orders/{address}"matcher/orders/{address}/{orderId}zmatcher/transactions/{orderId}z#api/v1/orderbook/{baseId}/{quoteId})r   zmatcher/orderbook/marketzmatcher/orderbook/cancelz+matcher/orderbook/{baseId}/{quoteId}/cancelz1matcher/orderbook/{baseId}/{quoteId}/calculateFeez+matcher/orderbook/{baseId}/{quoteId}/deletez.matcher/orderbook/{baseId}/{quoteId}/cancelAllzmatcher/debug/saveSnapshotszmatcher/orders/{address}/cancelzmatcher/orders/cancel/{orderId}zmatcher/orders/serializer   z matcher/settings/rates/{assetId})getpostdeleteput)D	addresseszaddresses/balance/{address}z+addresses/balance/{address}/{confirmations}z#addresses/balance/details/{address}addresses/data/{address}zaddresses/data/{address}/{key}z$addresses/effectiveBalance/{address}z4addresses/effectiveBalance/{address}/{confirmations}zaddresses/publicKey/{publicKey}zaddresses/scriptInfo/{address}z#addresses/scriptInfo/{address}/metazaddresses/seed/{address}zaddresses/seq/{from}/{to}zaddresses/validate/{address}zalias/by-address/{address}zalias/by-alias/{alias}z.assets/{assetId}/distribution/{height}/{limit}zassets/balance/{address}z"assets/balance/{address}/{assetId}zassets/details/{assetId}z"assets/nft/{address}/limit/{limit}zblockchain/rewardszblockchain/rewards/heightz%blocks/address/{address}/{from}/{to}/zblocks/at/{height}z#blocks/delay/{signature}/{blockNum}zblocks/firstzblocks/headers/lastzblocks/headers/seq/{from}/{to}zblocks/heightzblocks/height/{signature}zblocks/lastzblocks/seq/{from}/{to}zblocks/signature/{signature}zconsensus/algozconsensus/basetargetzconsensus/basetarget/{blockId}z%consensus/{generatingbalance}/addresszconsensus/generationsignaturez'consensus/generationsignature/{blockId}z debug/balances/history/{address}zdebug/blocks/{howMany}zdebug/configInfozdebug/historyInfoz
debug/infozdebug/minerInfozdebug/portfolios/{address}zdebug/statez$debug/stateChanges/address/{address}zdebug/stateChanges/info/{id}zdebug/stateWaves/{height}zleasing/active/{address}z
node/stateznode/versionz	peers/allzpeers/blacklistedzpeers/connectedzpeers/suspendedz,transactions/address/{address}/limit/{limit}ztransactions/info/{id}ztransactions/statusztransactions/unconfirmedz"transactions/unconfirmed/info/{id}ztransactions/unconfirmed/sizez
utils/seedzutils/seed/{length}z
utils/timezwallet/seed)r   r   zaddresses/sign/{address}zaddresses/signText/{address}zaddresses/verify/{address}zaddresses/verifyText/{address}zdebug/blacklistzdebug/printzdebug/rollbackzdebug/validatez	node/stopzpeers/clearblacklistzpeers/connectztransactions/broadcastztransactions/calculateFeeztranasctions/signz!transactions/sign/{signerAddress}ztranasctions/statuszutils/hash/fastzutils/hash/securezutils/script/compileCodezutils/script/compileWithImportszutils/script/decompilezutils/script/estimatezutils/sign/{privateKey}zutils/transactionsSerializezaddresses/{address}zdebug/rollback-to/{signature})r   r   r   r   )assetspairszcandles/{baseId}/{quoteId}ztransactions/exchange)zdeposit/addresses/{currency}z'deposit/addresses/{currency}/{platform}	platformszdeposit/currencieszwithdraw/currenciesz'withdraw/addresses/{currency}/{address}zoauth2/token)r   r   r   r   $matcher/orders/{wavesAddress}/canceltickers
currenciesWX,EMAMLxDnv3xiz8RXg8Btj33jcEw3wLczL3JKYYmuubpc1e-8)r(   	numericIdcode	precisionprecisionModeoptions      d  i  順 g:0yE>WETHBSC)ERC20BEP20)allowedCandlesaccessToken!createMarketBuyOrderRequiresPricematcherPublicKeyquotescreateOrderDefaultExpirywavesAddresswithdrawFeeUSDNwithdrawFeeWAVESwavesPrecisionmessagePrefixnetworksfeatures)IOCFOKPOGTD)
marginModetriggerPricetriggerDirectiontriggerPriceTypestopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergd   )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   )r   r   r   r   r   r   r      )r   r   r   daysBackCanceledr   r   r   r   r   )	rm   r;   createOrdersrX   r\   r[   r^   rC   rY   )linearinverse)r1   r3   r4   commonCurrenciesEGGzWaves DucksrequiresEddsa
exceptions31472701124131431457333148040314880194405129440771944102694412829441286944129594415409441542	106954752)	106954769	106957828	106960131	1069811379437184943719310485771051904)deep_extendsuperr%   describesafe_currency_structureparse_numberr"   r   r   r!   r   r    r   r   r   r   r   )self	__class__s    L/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/wavesexchange.pyr   zwavesexchange.describe   s\   mT C E wH
/wH
$wH
 $wH
 	wH

 5wH
 4wH
  EEE %E 	E
 %E %E UE tE $UE  E $TE tE (E 'E (E  "5!E" #E$ +E%E& )%'E( $T)E* '+E, (-E. &t/E0 (1E2 1$3E4 *:5E6 +D7E8 &u9E: #E;E< *5=E> $U?E@ "5AEB *5CED +EEEF  GEH %eIEJ "5KEL MEN !%OEP  QER dSET +EUEV "4WEX dYEZ !$[E\ t]E^  _E` 'aEb $UcEd !%eEf *5gEh (iEj %ekEl )%mEn toEp qEr tsEt  uEv !%wEx yEz 4{E| u}E~  E@ "5AEB $CED EEEF DGEH eIEwH
Z [wH
x }CBHBR[  <6@:JS ,3ywH
n 6 ?:
 ;[0dEL: .7GgR   ' 3<
 ? !q}owH
j	 d22:hw{  FJ  Y]  Yj  Yj  kq  Yr  4s  tk	wH
p	 Yq	wH
r	 "&#59$(,6 $#'$*"&!$""s	wH
T
 #&+(,,1,0).+06:#(#("'#'	( #($)$)+026/4#()$, %)&+!$$*%+*/& ',#($)*/	# ',!$#($)*/( ',!$$(%)#($)*.$ ',!$$*,-%+#($)*/	*  #ACJ ##
 ##SMU
wH
p }!qwH
v TwwH
x  ,( ] *	
 * + + . . 9 < < < < <  <!" 0#$ 1000%(%.3ywH
 w w	    c                 p    |rdnd| j                   d<   || j                   d<   t        t        |   |       y )NTr   r   sandboxMode)r   r   r%   set_sandbox_mode)r   enabledr   s     r   r  zwavesexchange.set_sandbox_mode  s2    /6C_%&-]#mT3G<r   symbolc                     | j                          | j                  |      }| j                  ||      }| j                  ||      }| j	                  |d   |d   |||d|      }| j                  |      S )NbaseIdquoteId)r  r  	orderTypeamountprice)load_marketsr   to_real_symbol_amountto_real_symbol_priceextend4matcherPostMatcherOrderbookBaseIdQuoteIdCalculateFee)r   r  sider
  r  paramsr   requests           r   get_fees_for_assetz wavesexchange.get_fees_for_asset  s    V$++FF;))&%8++X&i(
  HHQQr   takerc                 T   | j                  ||||      }| j                  |dd      }	d }
|	r| j                  |d      }
n| j                  |d      }
| j                  |
d      }| j                  |
d      }| j	                  |      }| j                  ||      }| j                  |      }| j                  |      }| j                  || j                  |            }t        j                  |t        j                  ||            }||| j                  |      | j                  |      dS )NisDiscountFeeFdiscountbase
matcherFee
feeAssetId)typecurrencyratecost)r  	safe_bool
safe_valuesafe_stringsafe_currency_codefrom_real_currency_amountnumber_to_stringfee_to_precisionr   r#   
string_div
string_mul)r   r  r  r  r
  r  takerOrMakerr  responser  moder  r  feeAssetadjustedMatcherFeeamountAsStringpriceAsStringfeeCostfeeRates                      r   custom_calculate_feez"wavesexchange.custom_calculate_fee  s&   **64G vF??8Z8D??8V4D%%dL9
%%dL9
**:6!;;HjQ..v6--e4''0A0ABT0UV$$%79K9KN\i9jk  %%g.%%g.	
 	
r   c                     | j                  | j                  d      }|r|S | j                         }i }| j                  |d      }t        dt	        |            D ]
  }d|||   <    || j                  d<   |S )Nr   priceAssetsr   T)r!  r   matcherGetMatcherSettingsrangelen)r   r   r*  r4  is        r   
get_quoteszwavesexchange.get_quotes
  s    x8M 557Hb F//(MBK1c+./ .)-{1~&.%+DLL"Mr   c                    | j                         }g }t        dt        |            D ]E  }||   }| j                  |d      }| j                  |d      }|dz   |z   }| j                  |d      }	|	j	                  d      \  }
}| j                  |
      }
| j                  |      }|
dz   |z   }|j                  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
| j                  | j                  | j                  |d                  | j                  | j                  | j                  |d                  dd
d
dd
d
dd
d
dd
d
ddd
|d
       H |S )z
        retrieves data on all markets for wavesexchange
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r   amountAssetIDpriceAssetID/r  r(   r  quotesettleNr  r  settleIdr  r1   Tr2   Fr3   r4   r5   activecontractr   amountAssetDecimalspriceAssetDecimals)r
  r  )minmax)r   r
  r  r  )
r   contractSizeexpiryexpiryDatetimestrike
optionTyper   limitscreatedinfo)	marketGetTickersr6  r7  r"  splitr#  appendr   parse_precision)r   r  r*  resultr8  entryr  r  r(   marketIdr  r>  r  s                r   fetch_marketszwavesexchange.fetch_marketsK  sQ    ((*: q#h-( :	AQKE%%e_=F&&un=G#'B''x8H"..-KD%**40D++E2ECZ%'FMM 0b0&0 0 	0
 $0 &0 70 D0 0 0 %0 0 %0 %0 $0  E!0" $#0$   $"&""//0D0DTEUEUV[]rEs0tu!..t/C/CDDTDTUZ\pDq/rs  $#!
  $#
  $#
  $#$  _0 0:	v r   Nr   c                 |   | j                          | j                  |      }| j                  |d   |d   d|      }| j                  |      }| j	                  |d      }| j                  | j                  |d      ||      }| j                  | j                  |d      ||      }	|||	|| j                  |      ddS )	aF  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://matcher.waves.exchange/api-docs/index.html#/markets/getOrderBook

        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        r  r  )r  r  	timestampbidsasksN)r  rY  rZ  rX  datetimenonce)r  r   r  'matcherGetMatcherOrderbookBaseIdQuoteIdsafe_integerparse_order_book_sider!  iso8601)
r   r  r   r  r   r  r*  rX  rY  rZ  s
             r   fetch_order_bookzwavesexchange.fetch_order_book  s     	V$++X&i(
  ??H%%h<	))$//(F*KVUZ[))$//(F*KVUZ["Y/
 	
r   c                 ^   |d   }| j                  | j                  dd      }| j                  |d      }| j                  |d      }t        j                  ||      }t        j                  ||      }	g }
t	        dt        |            D ]  }||   }| j                  |dd      }| j                  |dd      }d }d }|	|t        j                  ||	      }||t        j                  ||      }|||kD  r |
S |
j                  | j                  |      | j                  |      g        |
S )Nr   r   r   r
  r  r   0)	r"  r   r#   r'  r6  r7  r(  rQ  r   )r   bookSider   r   r   r   amountPrecisionStringpricePrecisionString
differencepricePrecisionrS  r8  rT  
entryPriceentryAmountr  r
  s                    r   r_  z#wavesexchange.parse_order_book_side  sR   ;'	))$,,8H&Q $ 0 0H E#//	7C''(=?ST
 ++NJGq#h-( 	AQKE))%#>J**5(C@KEF*1G**:~F%18O ++K9NO!E	
 	 MM!!%(!!&) 	  r   c                    | j                   t        | j                  dz         | j                  t        | j                  dz         d }d }	 | j	                  | j                         }	 | j	                  | j                        }| j                  |      }| j                  |      }t        |      dk7  rt        | j                  dz         t        |      dk7  rt        | j                  dz         y# t
        $ r}t        | j                  dz         d }~ww xY w# t
        $ r}t        | j                  dz         d }~ww xY w)Nz requires apiKey credentialz requires secret credentialz+ apiKey must be a base58 encoded public keyz, secret must be a base58 encoded private key@   T)apiKeyr   r(   secretbase58_to_binary	Exceptionbinary_to_base16r7  )r   apiKeyBytessecretKeyBytesehexApiKeyByteshexSecretKeyBytess         r   check_required_keysz!wavesexchange.check_required_keys  s:   ;;%dgg0M&MNN;;%dgg0M&MNN	_//<K	`!224;;?N ..{; 11.A~"$%dgg0]&]^^ !R'%dgg0^&^__  	_%dgg0]&]^^	_  	`%dgg0^&^__	`s0   C4 *D 4	D=DD	E&D>>Er   GETc                 l   | j                  || j                  |            }|dk(  }| j                  ||      }| j                  d   |   dz   |z   }	| j	                  |      }
|dk(  s|dk(  rjddi}| j                  | j                  d      }|rd	|z   |d
<   |dk(  rd|d<   nd|d<   |r| j                  |d   g      }d}
t        |
      dkD  rb|	d|
z   z  }	nY|dk(  r|dk(  rddd}| j                  |      }n8|}n5|dk(  rddi}| j                  |      }nddi}t        |
      dkD  r|	d|
z   z  }	|	|||dS )Nr   r   r=  r   r   Acceptapplication/jsonr   zBearer AuthorizationPOSTzcontent-typez!application/x-www-form-urlencodedorderId r   ?r   )rz  zContent-Type)urlmethodbodyheaders)	omitextract_paramsimplode_paramsr   urlencode_with_array_repeatr"  r   jsonr7  )r   pathr   r  r  r  r  queryisCancelOrderr  queryStringr   s               r   signzwavesexchange.sign  s   		&$"5"5d";< FF""40iis#c)D066u=9#"2,G **4<<GK+4{+B(*<'*M'yy%	"2!34 ;!#s[((I0$6 yy'"$6 yy' #$G {#a'3,,CfdwOOr   c                 h   | j                  | j                  d      sd}d}| j                  | j                         |      }t	        |      }d}| j                  | j                  dd      }|dz   |z   dz   |z   }| j                  | j                  |            }||z   }	| j                  | j                  | j                              }
| j                  |	|
d      }d	d
| j                  |dz   |z   |d}| j                  |      }| j                  |d      | j                  d<   | j                  d   S y)a  
        sign in, must be called prior to using other authenticated methods

        https://docs.wx.network/en/api/auth/oauth2-token

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns: response from exchange
        r   ffffff01i:	 z
wx.networkr   r   :ed25519passwordgeneral)
grant_typescopeusernamer  	client_idaccess_tokenN)r"  r   sumsecondsstrrq  encodero  rn  axolotlrm  privatePostOauth2Token)r   r  prefixexpiresDeltar  clientIddefaultMessagePrefixmessage
messageHexpayloadhexKey	signaturer  r*  s                 r   sign_inzwavesexchange.sign_in(  s1    m<F+Lhht||~|<G'lG#H#'#3#3DLL/SV#W *S08;cAGKG..t{{7/CDJz)G**4+@+@+MNFWfi@I(" KK#cMI5%G 227;H +/*:*:8^*TDLL'<<..r   tickerr   c                 8   | j                  |d      }| j                  |d      }| j                  ||d      }|d   }| j                  |dd      }| j                  |dd      }| j                  |dd	      }| j                  |d
d      }	| j                  |dd      }
| j                  |dd      }| j                  |dd      }| j	                  i d|d|d| j                  |      d	|d|dd dd dd dd d|	d|d|d|dd dd dd dd |
||d|      S ) NrX  r  r=  	24h_close	lastPrice24h_lowlow24h_highhigh24h_vwapweightedAveragePrice
24h_volumevolume24h_priceVolumequoteVolume24h_open
firstPricer[  bid	bidVolumeask	askVolumevwapopencloselastpreviousClosechange
percentageaverage)
baseVolumer  rN  )r^  r"  safe_marketsafe_string_2safe_tickerr`  )r   r  r   rX  rU  r  r  r  r  r  r  r  r  s                r   parse_tickerzwavesexchange.parse_tickerO  s   P %%fk:	##FH5!!(FC8!!!&+{C  E:!!&*f=!!&*6LM''hG
((1BMR!!&*lC !
f!
!
 Y/!
 D	!

 3!
 4!
 !
 4!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&)!
* + 	r   c                 *   | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j	                  |di       }| j                  |di       }| j                  ||      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://api.wavesplatform.com/v0/docs/#/pairs/getPairsListAll

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r   r(   datar   )r  r   publicGetPairsr  r!  	safe_dictr  )	r   r  r  r   r  r*  r  r  
dataTickers	            r   fetch_tickerzwavesexchange.fetch_ticker  s     	V$VD\
 &&t{{7F'CD0 x4q"-^^FFB7
  V44r   symbolsc                 h    | j                          | j                  |      }| j                  ||      S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :param str[] [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>`
        )r  rO  parse_tickers)r   r  r  r*  s       r   fetch_tickerszwavesexchange.fetch_tickers  s5     	((0: !!(G44r   rv   sincec                    | j                          | j                  |      }|d   |d   | j                  | j                  ||      d}| j	                  | j
                  dd      }| j	                  |d      }	|	du}
||}t        ||      }| j                  |      dz  }|Y| j                         }|
r|	n|}| j                  ||z        |z  }|d	z
  |z  }||z
  }t        |      |d
<   |
rQt        |	      |d<   nBt        |      |d
<   |
rt        |	      |d<   n#| j                  |||z        }t        |      |d<   | j                  |d      }| j                  | j                  ||            }| j                  |dg       }| j!                  |||||      }| j#                  |      }d}t%        |      }t'        dt%        |            D ]4  }||z
  d	z
  }||   }|d	   }|||d	<   ||d<   ||d<   ||d<   |||<   |d   }6 |S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://api.wavesplatform.com/v0/docs/#/candles/getCandles

        :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 int [params.until]: timestamp in ms of the latest candle to fetch
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        r  r  )r  r  intervalr   r   untilNi  r   	timeStarttimeEndr  r            )r  r   r"  ru   r^  r   rE  parse_timeframemillisecondsparse_to_intr  r  r  publicGetCandlesBaseIdQuoteIdr  r!  parse_ohlcvsfilter_future_candlesr7  r6  )r   r  	timeframer  r   r  r   r  r   r  untilIsDefineddurationnowr  durationRoundedTimestampdeltar  r*  r  rS  	lastCloselengthr8  jrT  r  s                             r   fetch_ohlcvzwavesexchange.fetch_ohlcv  sM    	V$X&i((()YO

 **4<<9I4P!!&'2d*="ENE*''	2T9=##%C-e3G'+'8'889K'Lx'W$QY(*E058I#&y>GK %(Z	"#&u:GK %(Z	"((5(U*:;%(\	"67+55dkk'66RS0 x4""4E5I++F3	Vq#f+& 
	!A
QA1IE8D|$a$a$a$a!q	aI
	! r   c                     g }| j                         }t        dt        |            D ]$  }||   d   |kD  r |S |j                  ||          & |S )Nr   )r  r6  r7  rQ  )r   ohlcvsrS  rX  r8  s        r   r  z#wavesexchange.filter_future_candlesC  s`    %%'	q#f+& 	%Aay|i' MM&)$		%
 r   c           
         | j                  |di       }| j                  | j                  |d            | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |dd      gS )	Nr  timer  r  r  r  r  r   )r!  	parse8601r"  safe_number)r   ohlcvr   r  s       r   parse_ohlcvzwavesexchange.parse_ohlcvM  s    & ufb1NN4++D&9:T6*T6*T5)T7+T8Q/
 	
r   r   c                    | j                          | j                  | j                  di       }| j                  |d      }| j	                  |||      }| j                  |dg      }| j                         }i }i }| j                  |dg       }	t        dt        |	            D ]n  }
|	|
   }| j	                  |d      }| j                  |dg       }t        dt        |            D ]*  }| j	                  ||      }d||<   ||vri ||<   d||   |<   , p ||vrIt        |j                               }t        | j                  dz   |z   d	z   d
j                  |      z         d}|&d|i}| j                  | j                  ||            }n||   }||vrOt        |j                               }t        | j                  dz   |z   dz   |z   dz   d
j                  |      z         |dk(  rId| j                   i}| j#                  | j                  ||            }| j	                  |d      }||||ddS ||d}| j%                  | j                  ||            }| j                  |d      }| j	                  |d      }| j                  | j                  di       }| j	                  |||      }| j                  |d      }| j	                  |d      }||||ddS )a9  
        fetch the deposit address for a currency associated with self account
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r   networkitemsr   r(   r   Tz fetchDepositAddress() - not supported. Currency code must be one of z, Nr   z	 network z7 deposit address not supported. Network must be one of WAVES	publicKeyaddress)rN  r  r  r  tag)r  platformplatform_idnetworkByIdsdeposit_addresses)r  r!  r   safe_string_upperr"  r  privateGetPlatformsr6  r7  listkeysr   r(   join"privateGetDepositAddressesCurrencyr  rm  "nodeGetAddressesPublicKeyPublicKey*privateGetDepositAddressesCurrencyPlatform)r   r   r  r   
rawNetworkr  supportedCurrenciesr   networksByCurrencyr  r8  rT  
currencyIdinnerCurrenciesr  currencyCodecodesr*  r  supportedNetworkssupportedNetworkKeysresponseInneraddressInnerr  	networkIdr  unifiedNetworkr   r  s                                r   fetch_deposit_addressz#wavesexchange.fetch_deposit_addressj  sp    	??4<<R@++FI>
""8ZD6I;/"668B 
#% 3WbAq#e*% 		DA!HE))%6J"ooe\2FO1c/23 D#//C+/
<($(::79&|4?C"<0<D			D 
"*+E*C Cd JM| |  @D  @I  @I  JO  @P  !P  Q  Q?DG >>t{{7TZ?[\H 24 800'+,=,B,B,D'E$#DGGcMG$;k$ID$P  TM  %M  PT  PY  PY  Zn  Po  %o  p  p'!! !% G GT[]dHe f#//)D) $&+  !% '!  JJ4;;W^`fKgh0 ??8Z8$$X}=	t||^RH)),	9MOOH.AB	""9a0%
 	
r   c                     | j                  | j                  d      }|r|S | j                         }|dt        |      dz
   | j                  d<   | j                  d   S )Nr   r   )r"  r   matcherGetMatcherr7  )r   r   r*  s      r   get_matcher_public_keyz$wavesexchange.get_matcher_public_key  s`    ++DLL:LM##--/H/7#h-!:K/LDLL+,<< 233r   c                     |dk(  r| j                  dd      S | j                  | j                  dd      | j                  |            S )Nr  r   r   )number_to_bebinary_concatro  r   r  s     r   get_asset_byteszwavesexchange.get_asset_bytes  sI     $$Q**%%d&7&71&=t?T?TU_?`aar   c                     |dk(  ry|S )Nr  r   r  s     r   get_asset_idzwavesexchange.get_asset_id  s     r   r
  c                     | j                  |      }t        j                  | j                  |      | j	                  |d            }t        |      S Nr   )r  r#   r'  r%  r"  int)r   r   r
  networkCoder  stringValues         r   to_real_currency_amountz%wavesexchange.to_real_currency_amount   sG    ==&(()>)>v)FHXHXYacnHop;r   amountStringc                     || j                   vr|S | j                  |      }| j                  |d      }t        j                  ||      S r%  )r   r  r"  r#   r(  )r   r   r*  r  precisionAmounts        r   r$  z'wavesexchange.from_real_currency_amount  sG    '==&**8[A!!,@@r   r  c                     | j                  |      }t        j                  | j                  |      | j	                  |d   d            }t        |      S Nr   r  r   r#   r'  r%  r"  r&  )r   r  r  r   r(  s        r   r  z"wavesexchange.to_real_symbol_price  sM    V$(()>)>u)EtGWGWX^_jXkmtGuv;r   priceStringc                 r    | j                   |   }t        j                  || j                  |d   d            S r.  )marketsr#   r(  r"  )r   r  r0  r   s       r   from_real_symbol_pricez$wavesexchange.from_real_symbol_price  s6    f%!!+t/?/?{@SU\/]^^r   c                     | j                  |      }t        j                  | j                  |      | j	                  |d   d            }t        |      S Nr   r
  r/  )r   r  r
  r   r(  s        r   r  z#wavesexchange.to_real_symbol_amount  sM    V$(()>)>v)FHXHXY_`kYlnvHwx;r   c                 X    | j                   |   }t        j                  ||d   d         S r5  )r2  r#   r(  )r   r  r*  r   s       r   from_real_symbol_amountz%wavesexchange.from_real_symbol_amount  s-    f%!!,{0CH0MNNr   c                     | j                  |d      }d|v r| j                  |d      S | j                  |d   d   d      S )NorderFeedynamic	compositedefaultr!  )r   settingsr9  s      r   safe_get_dynamiczwavesexchange.safe_get_dynamic  sF    ??8Z8 ??8Y77??8K#8#CYOOr   c                 6    | j                  |d      }|ddiS |S )Nratesr  r   r=  )r   r:  rA  s      r   safe_get_rateszwavesexchange.safe_get_rates%  s&    1=Q<r   r  r  c                 
   | j                          | j                          | j                          | j                  |      }| j	                         }| j                  |d         }	| j                  |d         }
|dk(  }| j                  |dd      }|du}|r |t        | j                  dz   |z   dz         | j                         }d}| j                  |d	d
| j                  | j                  dd            \  }}| j                  ||      }| j                  ||||      }| j                  |dd      }| j!                  |d      }| j#                  |      }| j!                  |d      }| j%                  |d      }| j!                  |d      }| j#                  |      }| j!                  |d      }d}d}d|v sd| j                  v rP| j!                  |d| j!                  | j                  d            }| j'                  |      }| j!                  |d      }| j)                         }|||k7  r&||k7  r!t        | j                  dz   |z   dz   |z         | j#                  |      }||k(  r|n|} t+        | j-                  ||             }!||v r||   d   |!k\  rt/        |       }nt1        | j                  dz         | j-                  ||      }"| j-                  ||      }#|K||v r"||   d   t+        |"      k\  r|}t/        |      }n%||v r!||   d   t+        |#      k\  r|}t/        |      }|-t1        | j                  dz   |z   dz   |"z   dz   |z   dz   |#z         | j3                  ||      }| j5                  ||      }|	|
d}$| j7                  | j                  dd      }%|%rdnd}&| j8                  ||$|||||t/        |      dd|&d }'|rPd!d"d#| j5                  ||      id$d%}(| j;                  | j=                  t?        j@                  |(                  |'d&<   |d'k7  r||'d(<   | jC                  |'      })|)d)   d*k(  r%|)tE        |)      d!z
     d*k(  r|)d!tE        |)      d!z
   })| jG                  | jI                  | jK                  |)            | jI                  | jK                  | jL                              d+      }*|*|'d,<   |rE| jO                  | jQ                  |'|            }+| jS                  |+d-      },| jU                  |,|      S | jW                  | jQ                  |'|            }+| jS                  |+d-      },| jU                  |,|      S ).a  
        create a trade order

        https://matcher.waves.exchange/api-docs/index.html#/serialize/serializeOrder

        :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 float [params.triggerPrice]: The price at which a stop order is triggered at
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  r   r   	stopPriceNz- createOrder() requires a price argument for zE orders to determine the max price for buy and the min price for sellr;   defaultExpiryr   r   r  r  r  r  r,  r(   z asset fee must be z or freez+ not enough funds of the selected asset feez6 not enough funds on none of the eligible asset fees: r  amountAsset
priceAssetr  FT   W   assetDecimalsr  )senderPublicKeyr   	assetPairr	  r  r
  rX  
expirationr  	priceModeversionchainIdr   spp)tv)rV  c
attachmentr  matcherFeeAssetIdr   "r  r  r  ),check_required_dependenciesrw  r  r   r  r#  safe_float_2r   r(   r  handle_option_and_paramsr^  r   r  r  safe_value_2r"  r#  r!  r  fetch_balancefloatr$  r&  r   r  r  r   rm  binary_to_base58r  r  dumps!matcherPostMatcherOrdersSerializer7  r  rq  ro  rn  !matcherPostMatcherOrderbookMarketr  r  parse_ordermatcherPostMatcherOrderbook)-r   r  r  r  r
  r  r  r   r   rH  rI  isMarketOrderr   isStopOrderrX  defaultExpiryDeltarO  matcherFeesr  baseFeeAssetIdbaseFeeAssetbaseMatcherFeer  discountFeeAssetIddiscountFeeAssetdiscountMatcherFeerY  r  r,  feeCurrencybalancesmatcherFeeAssetrawMatcherFeefloatMatcherFeefloatBaseMatcherFeefloatDiscountMatcherFeerN  r  rR  r  rX  serializedOrderr  r*  values-                                                r   create_orderzwavesexchange.create_order+  s?    	((*  "V$668''x(89&&vi'89
)((M#4/tww)XX[__  cj   j  k  k%%'	!%)%B%B6=Zikok|k|  ~B  ~J  ~J  Lf  hr  ls  &t"FXXi);<
--fdFEJ   fjA))$=..~>))$=??;
;!--hE223EF!--hE 
& jDLL&@''
D<L<LT\\[e<fgH--1K $ 0 0d C%%'(!227IM^7^"477-B#B\#QTZ#Z]m#mnn"556GHO/@N/RNYkM#D$B$B?Ta$bcO8+(?2KF2SWf2f /
'2_(_``"<<\>Z"&"@"@AQSe"f$(x/Ef/MQVWjQk/k$2! 0
$0x@P7QRX7Y]bcz]{7{(:%!$%7!8J$#DGG.f$fiu$ux{${  R  %R  U[  %[  ^n  %n  qt  %t  wN  %N  O  O++FF;))&%8&$
	 nnT\\=%H$"2#{{ 0""$j/(
  T66v|L J "&!6!6t{{4::jCY7Z![D'(9D$%@@FA#%OS=QTU=U,W[^,^-aO0Dq0HIOLL!6!6t7L7L_7]!^`d`u`uvz  wL  wL  MQ  MX  MX  wY  aZ  \e  f	%[@ ==dkk$PV>WXHNN8Y7E##E62277D&8QRHNN8Y7E##E622r   r(   c                    | j                          | j                          | j                          | j                         }| j	                  ||d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	| j                  i d|d|	ddd	dd
dddd|ddddddddddddddddddddddi      S )a  
        cancels an open order

        https://matcher.waves.exchange/api-docs/index.html#/cancel/cancelOrdersByIdsWithKeyOrSignature

        :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>`
        )r   r~  r  r   r~  rN  r(   clientOrderIdNrX  r[  lastTradeTimestampr  r  r  r  r
  r  r  filled	remainingstatusfeetrades)r[  rw  r  get_waves_address*forwardPostMatcherOrdersWavesAddressCancelr!  r"  
safe_order)
r   r(   r  r  r   r*  r  firstMessage
firstOrder
returnedIds
             r   cancel_orderzwavesexchange.cancel_order  s}    	((*  "--/BB(D
  //(I6w2__\15
%%j)<
  
H 
* 
 T 
 	 

  
 !$ 
 f 
 D 
 D 
 T 
 d 
 D 
 t 
 d 
  
  d! 
" 4# 
$ d% 
  	r   c                 Z   | j                          | j                          | j                          d}|| j                  |      }| j	                         }| j                  | j                        | j                  |d      g}| j                  |      }| j                  | j                  | j                              }| j                  | j                  |      |d      }	t        |      |	| j                  |d}
| j                  | j                  |
|            }| j                  ||      S )a  
        fetches information on an order made by the user

        https://matcher.waves.exchange/api-docs/index.html#/status/getOrderStatusByPKAndIdWithSig

        :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>`
        N   r  )	Timestamp	Signaturer  r~  )r[  rw  r  r   r  ro  rm  r  binary_concat_arrayrq  rn  r  r  *matcherGetMatcherOrderbookPublicKeyOrderIdr  re  )r   r(   r  r  r   rX  	byteArraybinary	hexSecretr  r  r*  s               r   fetch_orderzwavesexchange.fetch_order  s    	((*  "[[(F%%'	!!$++.i+
	 )))4))$*?*?*LM	LL!6!6v!>	9U	Y"	
 BB4;;wX^C_`&11r   c                    | j                          | j                          |t        | j                  dz         | j	                          | j                  |      }| j                         }| j                  | j                        | j                  |d      g}| j                  |      }| j                  | j                  | j                              }	| j                  | j                  |      |	d      }
dt        |      |
| j                  |d   |d   d}| j                  | j!                  ||            }| j#                  ||||      S )a  
        fetches information on multiple orders made by the user
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        z) fetchOrders() requires a symbol argumentr  r  r{  r  r  )rz  r  r  r  r  r  )r[  rw  r   r(   r  r   r  ro  rm  r  r  rq  rn  r  r  9matcherGetMatcherOrderbookBaseIdQuoteIdPublicKeyPublicKeyr  parse_orders)r   r  r  r   r  r   rX  r  r  r  r  r  r*  s                r   fetch_orderszwavesexchange.fetch_orders*  s;    	((*  ">#DGG.Y$YZZV$%%'	!!$++.i+
	 )))4))$*?*?*LM	LL!6!6v!>	9U	(Y"X&i(
 QQRVR]R]^egmRno    65%@@r   c                     | j                          | j                          d}|| j                  |      }| j                         }|dd}| j	                  |      }| j                  ||||      S )a  
        fetch all unfilled currently 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
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        NT)r  
activeOnlyr  r  r   r  forwardGetMatcherOrdersAddressr  	r   r  r  r   r  r   r  r  r*  s	            r   fetch_open_orderszwavesexchange.fetch_open_orders[  sv     	[[(F((*
 66w?  65%@@r   c                     | j                          | j                          d}|| j                  |      }| j                         }|dd}| j	                  |      }| j                  ||||      S )a  
        fetches information on multiple closed orders made by the user
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        NT)r  
closedOnlyr  r  s	            r   fetch_closed_ordersz!wavesexchange.fetch_closed_ordersq  sx     	[[(F((*
 66w?*   65%@@r   r  c                 6    ddddd}| j                  |||      S )Ncanceledr  closed)	CancelledAcceptedFilledPartiallyFilled)r"  )r   r  statusess      r   parse_order_statusz wavesexchange.parse_order_status  s,    #%	
 &&99r   c                     | j                  |dd      }| j                  |dd      }| j                  |      dz   | j                  |      z   S )NrH  r  rI  r=  )r"  r#  )r   rN  r  r  s       r   get_symbol_from_asset_pairz(wavesexchange.get_symbol_from_asset_pair  sP    !!)]GD""9lGD&&v.4t7N7Nw7WWWr   orderc           
         | j                  |d      }| j                  |dd      }d}d|v r| j                  |d|      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	| j                  |d	      }
d }|
| j	                  |
      }n||d
   }| j                  | j                  |
dd            }| j                  ||      }| j                  ||	      }| j                  ||      }| j                  || j                  |d            }| j                  | j                  |d            }d }d|v rV| j                  | j                  |d            }|| j                  | j                  || j                  |d                  d}nV| j                  | j                  |dd            }|| j                  | j                  || j                  |d                  d}d }| j                  |d      }|k| j                  | j                  | j                  |                  }|:| j                  |d      }|&| j                  |d      }|| j                  |d      }| j                  i d|d|dd d|d| j                  |      dd d
|d|dd dd d|d|d|d|d d d!|d|d ||d d"|      S )#NrX  r  r	  r   r(   r~  r  r
  rN  r  rH  r  avgWeighedPricer  r,  	filledFee)r  r  rY  r  rX  rW  rV  rT  rN  r|  r[  r}  r   postOnlyr  r   r  r  )r  r  r  r  )r^  r  r"  r!  r  r#  r3  r$  r  r   
parse_jsondecodero  r  r`  )r   r  r   rX  r  r  r(   filledStringr0  r*  rN  r  amountCurrencyr  r
  r~  r  r  r  r   r   rX  decodedAttachmentrW  rV  s                            r   re  zwavesexchange.parse_order  s   j %%e[9	!!%=U?##E;=DeT*''x8&&ug6''x8OOE;7	 44Y?FH%F001A1A)]\c1de++FK@//M//M--fd6F6FuN_6`a(()9)9%)JKU?**4+;+;E:+NOD (()G)GdN^N^_dfqNr)stC
 **4+;+;ECVX_+`aD (()G)GdN^N^_dfrNs)tuC %%e\:
! $D<Q<QR\<]0^ _ ,OO$5s;=3/A}'+'7'73'?  
E 
" 
 T 
 	 

 Y/ 
 !$ 
 f 
 D 
 4 
  
 D 
 U 
 L 
 f 
 D 
  w! 
" f# 
$ + 
, - 	r   c                     | j                  | j                  d      }|Md| j                  i}| j                  |      }| j                  |d      | j                  d<   | j                  d   S |S )Nr   r  r  )r"  r   rm  r	  )r   cachedAddreessr  r*  s       r   r  zwavesexchange.get_waves_address$  sp    ))$,,G!T[[G >>wGH+/+;+;Hi+PDLL(<<//!!r   c                 D   | j                          | j                          | j                          | j                         }d|i}| j	                  |      }| j                  |dg       }i }d}g }g }	t        dt        |            D ]  }
||
   }| j                  |d      }||nt        ||      }| j                  |d      }| j                  |d      }| j                  |d      }|| j                  v }|r=| j                  |      }| j                         ||<   | j                  ||      ||   d	<   ||j                  |       |	j                  |        t        |      }|rd
|i}| j!                  |      }| j                  |dg       }t        dt        |            D ]  }
||
   }|	|
   }| j                  |d      }| j#                  | j                  |d            }| j                  |d      }| j                  |      }| j                         ||<   t%        j&                  ||      ||   d	<    | j)                         }| j+                  | j,                        | j/                  |d      g}| j1                  |      }| j3                  | j+                  | j4                              }| j7                  | j3                  |      |d      }| j,                  |t9        |      d}| j;                  |      }t=        |j?                               } t        dt        |             D ]Y  }
| |
   }| j                  |      }||vr| j                         ||<   | j                  ||      }!| j                  ||!      ||   d<   [ d|i}"| jA                  |"      }#| j                  |d| j                               |d<   | j                  d| j                  |#d            |d   d	<   | jC                  |      }||d<   | jE                  |      |d<   | jG                  |      S )a!  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        r  rr  Nr   rX  issueTransactionassetIdbalancetotalidsr  r   r  r  r  )r  r  rX  usedr  r[  )$r[  rw  r  r  nodeGetAssetsBalanceAddressr!  r6  r7  r^  rF  r"  currencies_by_idr#  accountr$  rQ  publicGetAssetsrR  r#   r(  r  ro  rm  r  r  rq  rn  r  r  )matcherGetMatcherBalanceReservedPublicKeyr  r  nodeGetAddressesBalanceAddressset_undefined_balances_to_zeror`  safe_balance)$r   r  r   r  totalBalancerr  rS  rX  assetIdsnonStandardBalancesr8  rT  entryTimestampr  r  r  currencyExistsr   nonStandardAssetsrequestInnerr*  r  innerr   r  currentTimestampr  r  r  r  matcherRequestreservedBalancereservedKeysr
  wavesRequest
wavesTotals$                                       r   r_  zwavesexchange.fetch_balance0  s8    	((*  "--/|
 77@F ??<R@	 q#h-( 	4AQKE!..ukBN+4+<3yR`CaI#u6HI))%;J&&ui8G(D,A,AAN..z:#||~t(,(F(FtW(UtW%!)
+#**73	4  Mx"L ++L9H??8VR8D1c$i( OQ-a0v6 001A1A%1UV	))%:..v6#||~t(/(:(:7I(NtW%O  ,,.!!$++..2
	 )))4))$*?*?*LM	LL!6!6v!>	9U	"-. 

 HHXO0023q#l+, 	PA%aJ**:6DFN#||~t%%ozBF#'#A#A$#OF4L 	P |
 88F
 //&'4<<>Jw#'#A#A'4K[K[\fhqKr#sw 44V<'{!\\)4z  ((r   c                     t        |j                               }t        dt        |            D ]%  }||   }| j	                  ||   d      d||   |<   ' |S )Nr   r  rc  )r  r  r6  r7  r!  )r   rr  keyr  r8  r   s         r   r  z,wavesexchange.set_undefined_balances_to_zero  s_    X]]_%q#e*% 	*A8Dx~v6>&)s#	* r   c                    | j                          | j                         }d|i}d}|!| j                  |      }|d   |d<   |d   |d<   | j                  |      }| j	                  |d      }	| j                  |	|||      S )a  
        fetch all trades made by the user

        https://api.wavesplatform.com/v0/docs/#/transactions/searchTxsExchange

        :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>`
        senderNr  rH  r  rI  r  )r  r  r   publicGetTransactionsExchanger!  parse_trades)
r   r  r  r   r  r  r  r   r*  r  s
             r   fetch_my_tradeszwavesexchange.fetch_my_trades  s     	((*g
 [[(F%+H%5GM"$*9$5GL!55g>x0F   vue<<r   c                     | j                          | j                  |      }|d   |d   d}|t        |d      |d<   |||d<   | j                  |      }| j	                  |d      }| j                  ||||      S )a.  
        get the list of most recent trades for a particular symbol

        https://api.wavesplatform.com/v0/docs/#/transactions/searchTxsExchange

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r  r  rG  r   r   r  r  )r  r   rE  r  r!  r  )	r   r  r  r   r  r   r  r*  r  s	            r   fetch_tradeszwavesexchange.fetch_trades  s     	V$!(+ +
 "5#GG#(GK 55g>x0F   vue<<r   tradec                    | j                  |d      }| j                  |d      }| j                  |      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	| j                  |d      }
d }| j                  |	d      | j                  k(  r|	}n|
}d }| j                  |d	      }|| j	                  |      }n||d
   }| j                  |d      }| j                  |d      }| j                  |d      | j                  | j                  |dd            d}| j                  ||||||d |d ||d |d|      S )Nr  rX  r(   r  r
  order1order2rM  rN  r  r	  r  rY  r  )r  r  )rN  rX  r[  r  r(   r  r  r  r)  r  r
  r  r  )r!  r"  r  rm  r  r#  
safe_trade)r   r  r   r  r[  rX  r(   r0  r*  r  r  r  r  rN  r  r~  r  s                    r   parse_tradezwavesexchange.parse_tradeq  s   ^ uf-##D+6NN8,	dD)&&tW5''h7x0x0F$56$++EEEOOE;7	 44Y?FH%F{3""5$/$$UL9//0@0@H[]d0ef
 "   " 
  	r   r  c                 p   i }| j                  |      }t        dt        |            D ]K  }||   }|}| j                  ||      }| j	                  | j
                  |      }	| j                  |	d|      }
|| j                  |
|      sa| j	                  ||
      }||gd d dd d di d}n||
   }| j                  |d   |g      |d<   | j                  |d      }| j                  |	d      }| j                  ||      }| j	                  |d   |      }|d d dd d dd}| j                  |d	      }| j	                  |d
      }d}|dk(  rd}| j                  |d      dd||<   ||d   |<   |||
<   N t        |j                               }t        dt        |            D ]  }||   }
||
   }| j	                  |d      }t        |j                               }t        |      }|dk(  sI| j	                  ||d         }| j	                  |d      ||
   d<   | j	                  |d      ||
   d<    |S )Nr   r   )r  r  )rN  rs   depositr   rN  r   r   )rs   r  r  feesr  withdrawal_currencyrs   flatFr   )market_codesr6  r7  r"  r!  r  in_arrayarray_concatnetwork_id_to_coder  r  r  )r   r*  r  currencyIdKeydepositWithdrawFeesr8  rT  
dictionaryr  r  r   depositWithdrawFeer  r  r'  r  feeTyper  
networkKeydepositWithdrawFeesKeysr   networkKeysnetworkKeysLengths                          r   parse_deposit_withdraw_feesz)wavesexchange.parse_deposit_withdraw_fees  s   $&!!%(q#h-( .	?AQKEJ))*mDJt'<'<jIH##HfjAD4==u#=%)__5H$%O"%-!+#'*.%
 $(*.$ %'*& *=T)B&151B1BCUV\C]`j_k1l&v. ,,ZG	#//&A"55iN//*<Z*H+V? $(*.%
 $(*.$	G **:v>z6:&
33!+J.2.>.>tV.L\a&b
#>E":.{;,>#D)].	?^ #'':'?'?'A"Bq#567 		[A*1-D'-Euj9Hx}}/K #K 0 A%//(KNC8<Q[8\#D)*57;wPY7Z#D))4		[ #"r   c                 V   | j                          g }g }|j                  | j                  |             |j                  | j                  |             |}t	        dt        |            D ])  }| j                  ||   d      }| j                  ||      }+ | j                  ||d      S )a  
        fetch deposit and withdraw fees

        https://docs.wx.network/en/api/gateways/deposit/currencies
        https://docs.wx.network/en/api/gateways/withdraw/currencies

        :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>`
        r   r  r(   )	r  rQ  privateGetDepositCurrenciesprivateGetWithdrawCurrenciesr6  r7  r!  r  r  )r   r  r  r  promisesr8  r  s          r   fetch_deposit_withdraw_feesz)wavesexchange.fetch_deposit_withdraw_fees		  s     	88@A99&ABr q#h-( 	2AOOHQK9E$$T51D	2 //eTBBr   reasonr  r  r  r  c
                 |   | j                  |d      }
| j                  |dd      }| j                  | j                  |
      }|*| j                  |d      } || j                  dz   |z         | j                  |d      }|dk(  rt        | j                  dz   |z         |st        | j                  dz   |z         y )NerrorsuccessTr  r  zValidation Error)r"  r   r!  r   r(   r   r   )r   r   r  r  r  r  r  r*  requestHeadersrequestBody	errorCoder  rp  messageInnerr  s                  r   handle_errorszwavesexchange.handle_errorsW	  s    $$Xw7	..9d;OODOOY?	 ++Hi@LDGGcML899""8Y7((TWWs]T122# 455r   r  c                    | j                  ||      \  }}|dk7  r| j                         }i }| j                  |dg       }t        dt	        |            D ]  }	||	   }
| j                  |
d      }d||<     ||vrCt        |j                               }t        | j                  dz   |z   dz   t        |      z         | j                          g d}i }t        dt	        |            D ]  }	||	   }d||<    d}| j                  |      }|j                         }t	        |      d	z  }t        d|      D ]  }	||	   }||vsd
} n | j                          d}|dk(  r|s|}n||d}| j                  |      }| j                  |d      }| j                  |d      }| j!                  |d      }||k  r9t#        | j                  dz   |z   dz   t        |      z   dz   t        |      z         | j                  |dg       }| j                  |d      }| j%                  | j&                  dd      }d}d}d}| j)                  ||      } | j+                  |      }!| j-                         }"| j/                  dd	      | j/                  dd	      | j1                  | j2                        | j5                  |!d         | j5                  |      | j/                  |"d      | j/                  | d      | j/                  |d      | j1                  |      | j/                  dd      g
}#| j7                  |#      }$| j9                  | j1                  | j:                              }%| j=                  | j9                  |$      |%d      }&| j2                  | |||d| j?                  |      |&g| j?                  |!d         ||"|&d}'| jA                  |'      }(| jC                  |(|!      S )a  
        make a withdrawal
        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r  r  r   r(   Tz withdraw() r  )rc  123r   56789abrW  drt  fr   FN)r  r  r  allowed_amountrE  r  z withdraw failed, amount z4 must be greater than the minimum allowed amount of proxy_addressesr   r   r  r  r  r  r  )rM  r
  r  r  rQ  rX  r  proofsr  	recipientrX  r  )"handle_withdraw_tag_and_paramsr  r!  r6  r7  r"  r  r  r   r(   r  r  remove0x_prefixlowerr  *privateGetWithdrawAddressesCurrencyAddressr  r   r^  r   r)  r  r  r  ro  rm  r   r  rq  rn  r  r#  nodePostTransactionsBroadcastparse_transaction))r   r   r
  r  r  r  r  r   r  r8  rT  r  r  hexCharssetr  isErc20noPrefixr  stringLength	characterproxyAddresswithdrawAddressRequestwithdrawAddresscurrencyInnerallowedAmountminimumproxyAddressesr  r  r  rQ  amountIntegerr  rX  r  r  r  r  r  rS  s)                                            r   rs   zwavesexchange.withdrawe	  s=    99#vFV7?"&"C"C"E!JOO$7"EE1c%j) 0a#//t<+/
<(0 J&Z__./#DGGn$<t$CFu$ux{  }B  yC  %C  D  Dcq#h-( 	A1+CCH	 ''0 5zA~q,' 	AaI$		
 	7?7"L # ," #MMNdeO OOOZHM OOM;KLM&&}e<G  3!58S!SVYZ`Va!a  e[  "[  ^a  bi  ^j  "j  k  k, "___>OQSTN++NA>L.@&I
44T6B==&%%'	a#a#!!$++.  $0  ,i+mQ/c1%!!,/a#
	 )))4))$*?*?*LM	LL!6!6v!>	9U	#{{#++J7 (($8%""
  33G< %%fh77r   transactionr  c           	         | j                  d |      }|d   }| j                  |d      }|dk(  rdnd}| j                  | j                  || j                  |d                  }| j                  |d      }| j                  |dd	      }| j	                  |      }	| j                  | j                  |	|            }
| j                  |d
      }i d| j                  |d      dd d
|d| j                  |      dd d| j                  |d      dd d| j                  |d      d|d|d|d   dd dd dd dd dd dd d |	|
d|dS )Nr   r  r   rs   r  r
  r  r  r  rX  r(   txidr[  r  addressFromr  r  	addressTor  r  r  updatedtagFromr  tagTocomment)r  r  )internalr  rN  )safe_currencyr"  r   r$  r#  r^  r`  )r   r*  r  r   typeRawr  r
  	feeStringr  feeCode	feeAmountrX  s               r   r  zwavesexchange.parse_transaction	  s   > %%dH5"";7%nz9""4#A#A$HXHXYdfnHo#pq$$[%8	%%k<I
))*5%%d&D&DWi&XY	%%k;?	
$"";5
D
 
 Y/	

 t
 4++KB
 t
 ))+{C
 f
 D
 (
 d
 t
 t
 4
  T!
" t#
$ #!  /
 	
r   )NN)N)r  )L__name__
__module____qualname__r   r   r  r  r  r2  r9  r   r
   rV  r	   r   ra  r_  rw  r  r  dictr   r  r  r   r   r  r  r  r  r  r   r  r  r   r#  r`  r)  r$  r  r3  r  r7  r?  rB  r   r   r   rz  r   r  r  r   r  r  r  r  r  re  r  r   r_  r  r  r   r  r  r  r  r&  r  r   rs   r   r  __classcell__)r   s   @r   r%   r%      s   x# xt=
 KM R R Y`hj 
3 
B?B $& _$v, _B :>b 
s 
3 
Y 
<# 4. &eBSW +PZ   %NH4 H H6 HT 02 *53 *5f *5X 04B %5W %57 %5N 26DW[df U# Uc UQT Ukoptku Un
 
4 
: 79 ~
# ~
^ ~
@	4b
 C    
Ac A A 3  u  
_S _s _ C    
Oc O OP gksu j33 j3i j3y j3RW j3`c j3X 37r /s /C /b 26b  2c  23  2D *.Dt\^ /A3 /Ac /A /Acghmcn /Ab /3TXac A A3 Ac Ahlmrhs A, 154VZce (A# (AS (APS (Ajnotju (AT: :Xx xv x xt
" $& )( )B -1tRV_a Z=c Z= Z=C Z=x 6:UW Z=3 Z=s Z=# Z=\`af\g Z=xW Wv W Wr=#7 =#be =#~ <@ LC LC\# s  c TX `c  DHPR }8S }8% }8# }8Wb }8~A
T A
X A
Q\ A
r   r%   )*ccxt.base.exchanger   ccxt.abstract.wavesexchanger   r  ccxt.base.typesr   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!   ccxt.base.decimal_to_precisionr"   ccxt.base.preciser#   r%   r"  r   r   <module>rE     sh    ( 3  q  q  q  q  q  * 0 - . ' & . ) * - 1 4 %K(
Hk K(
r   