
    ei                         d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ 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)ImplicitAPI)AccountAnyBalances
CurrenciesCurrencyIntMarginModificationMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTradeTradingFeeInterfaceTransactionTransferEntry)List)ExchangeError)ArgumentsRequired)NotSupported)	TICK_SIZEc                       e Zd Zdef fdZi fdefdZdedefdZ	i fde
e         fdZdedefdZi fd	edefd
ZdNdedefdZi fd	edefdZdNdededefdZdi fd	ededefdZddi fd	ededede
e         fdZdNdededefdZdddi fd	ededede
e         fdZi fdefdZdefdZi fde
e          fdZ!dede fdZ"dddi fd	e#dedede
e$         fdZ%i fd	efdZ&di fde'fd Z(dNd!edede)fd"Z*di fd#e#d	ed$e+d%e,d&e-d'e.fd(Z/di fd	ed$e+d%e,d&e-d'e.f
d)Z0i fd*e
e1         de
e$         fd+Z2di fd#ed	e#fd,Z3di fd-e
e         d	e#de
e$         fd.Z4i fd	ede
e$         fd/Z5i fd	ed&e-de6fd0Z7i fd	ed&e-de6fd1Z8i fd2ed&e-d3ed4ede9f
d5Z:dNd6ed7ede9fd8Z;di fd2ed&e-d9ed:e#de<f
d;Z=dNd<ed7ede<fd=Z>di fd>e?d	e#fd?Z@d@edefdAZAdNdBedede$fdCZBdDe?dEedFedGedHedIefdJZCdKdLi ddfdMZD xZES )O	aftermathreturnc                    |                      t          t          |                                           i dddddg 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d0dd1ddddddd2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFidEdGidHdIdJdKdKdLdKdKdKdKdMdNdOi dPdKdQdKdRdKdSdKdTdKdUdKdVdKdWdKdXdKdYdKdZdKd[dKd\dKd]dKd^dKd_dKd`dKdKdKdKdaidbdcdddddddet          dfdddgdhi i didjdkddddddldddddddmdni          S )oNidr!   nameAftermathFinance	countriesversionv1	rateLimit2   	certifiedFproTdexhasCORSspotmarginswapfutureoption	addMargincancelOrdercancelOrderscreateOrdercreateOrders	editOrderfetchAccountsfetchBalancefetchCurrenciesfetchDepositAddressfetchDepositsfetchLedgerfetchMarketsfetchMyTrades
fetchOHLCVfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionsfetchTickerfetchTickersfetchTradesfetchTradingFeefetchTradingFeesfetchTradingLimitsfetchTransactions)fetchWithdrawalsreduceMarginsetLeveragetransferwithdraw
timeframes1m3m5m15m30m1h2h4h8h12h1d3d1w1M)rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   urlszOhttps://github.com/user-attachments/assets/70e5ae86-2f3a-4755-976b-aedb9d3c2807restz"https://aftermath.finance/api/ccxtz*https://testnet.aftermath.finance/api/ccxtzhttps://docs.aftermath.finance)logoapitestdocsri      )markets
currencies)ticker	orderbooktradesOHLCV)getpostrt   accountsbalancemyPendingOrders	positionszbuild/allocatezbuild/cancelOrderszbuild/createAccountzbuild/createOrderszbuild/deallocatezbuild/depositzbuild/setLeveragezbuild/withdrawzsubmit/allocatezsubmit/cancelOrderszsubmit/createAccountzsubmit/createOrderszsubmit/deallocate)zsubmit/depositzsubmit/setLeveragezsubmit/withdraw)publicprivaterequiredCredentials)apiKeysecretwalletAddress
privateKeyprecisionModeoptions)defaultTypesandboxMode
exceptions)exactbroadfeaturesdefault)IOCFOKPOGTD)timeInForceleveragemarketBuyRequiresPricemarketBuyByCostselfTradePreventiontrailingiceberg)sandboxr9   )deep_extendsuperr!   describer   )self	__class__s    L/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/aftermath.pyr   zaftermath.describe   s   i 6 6 ? ? A A TD
+TD
&TD
 TD
 t	TD

 TD
 TD
 4TD
 4TD
  ((( %( 	(
 %( %( T( t( ( t( ( U(  ( ( "4(  &u!("  #( ($ u%(& '((  )(* d+(, "4-(. e/(0 !$1(2 u3(4  5(6 !$7(8 t9(: ;(< t=(> "4?(@ #EA(B %eC(D $UE( (F %* $#  O( ( (TD
d  eTD
D i@ H 9	 	ETD
X  $%&' 
 #$%&"#!"	    "A!1 *1 $Q	
 )! -a .q -a +A ( ,Q )! *1 .q /  .q!" ,Q#$ +,./+,)  % %YTD
d "!%"	$ $eTD
p YqTD
r %$ sTD
z  {TD
B # $(#'"&#(	( ( %*27+0/4$)#($ $ CTD
 T T T	    c                 Z    |                      |          }|                     |          }|S )a  

        https://testnet.aftermath.finance/docs/#/CCXT/currencies

        fetches all available currencies on an exchange
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        )publicGetCurrenciesparse_currencies)r   paramsresponsern   s       r   fetch_currencieszaftermath.fetch_currencies   s2     ++F33**844
& r   rawCurrencyc                 X   |                      |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          d|d		          S )
Nr$   coder%   activedepositrV   	precisioncrypto)	r$   r   r%   r   r   rV   r   typeinfo)safe_currency_structuresafe_string	safe_boolsafe_number)r   r   s     r   parse_currencyzaftermath.parse_currency   s    ++"";55$$[&99$$[&99nn[(;;~~k9=={J??))+{CC
-
 
-
 
 
 
	r   c                 V    |                      |          }|                     |          S )a  

        https://testnet.aftermath.finance/docs/#/CCXT/markets

        retrieves data on all markets for woo
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        )publicGetMarketsparse_markets)r   r   r   s      r   fetch_marketszaftermath.fetch_markets   s.     ((00^ !!(+++r   marketc                    |                      |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$d d d$|                     |d%         d&          d d$d'd(|                      |d(          d)d d*|          S )+Nr   limitsr$   symbolbasequotesettlebaseIdquoteIdsettleIdr   subTyper1   r2   r3   r4   r5   r   contractlinearinverse	tierBased
percentagecontractSizeexpiryexpiryDatetimestrike
optionTypetakermakeramountprice)r   r   r   max)minr   costr   )r   r   r   r   marginModescreatedr   )	safe_dictsafe_market_structurer   r   r   )r   r   r   r   s       r   parse_marketzaftermath.parse_market  s   Z NN6;77	11)) 6+
$""64006+
d&&vx886+
 D$$VV446+
 T%%fg66	6+

 d&&vx886+
 d&&vx886+
 t''	::6+
 ((<<6+
 D$$VV446+
 t''	::6+
 DNN66226+
 dnnVX666+
 DNN66226+
 dnnVX666+
 dnnVX666+
  dnnVX66!6+
" vz::#6+
 6+
$ dnnVX66%6+
& t~~fi88'6+
( <<)6+
* $..>>+6+
, D,,V^DD-6+
. d/6+
0 d16+
2 d36+
4 $56+
6 T%%fg6676+
8 T%%fg6696+
: **9h??)))W== ;6+
B ++F:,>FF 
   
   
  ++F6NEBB  C6+
f 4>>&-@@g6+
h ti6+
j Fk6+
 6+
 6 6 6	r   r   c                 ~    |                                   |                     |          }|                     |          S )aP  

        https://testnet.aftermath.finance/docs/#/CCXT/markets

        fetch the trading fees for a market
        :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>`
        )load_marketsr   parse_trading_fee)r   r   r   r   s       r   fetch_trading_feezaftermath.fetch_trading_feev  s;     	V$$%%f---r   Nc                     |                      |d          }|||                     |d          |                     |d          dd dS )Nr   r   r   T)r   r   r   r   r   r   )r   r   )r   r   r   s      r   r   zaftermath.parse_trading_fee  sX    !!&(33%%fg66%%fg66
 
 	
r   c                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     ||          S )a  

        https://testnet.aftermath.finance/docs/#/CCXT/ticker

        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :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>`
        chIdr$   )r   r   publicPostTickerextendparse_ticker)r   r   r   r   requestr   s         r   fetch_tickerzaftermath.fetch_ticker  sr     	V$$F4L
 ((Wf)E)EFF2   6222r   ro   c           
         |                      |d          }|                     i d|                     |d          d|d|                     |          d|                     |d          d|                     |d          d|                     |d          d|                     |d          d|                     |d          d	|                     |d	          d
|                     |d
          d|                     |d          dd dd dd d|                     |d          dd dd |                     |d          |                     |d          d |                     |d          |d|          S )N	timestampr   datetimehighlowbid	bidVolumeask	askVolumevwapopencloselastpreviousClosechanger   average
baseVolumequoteVolume
indexPrice)r   r   	markPricer   r   )safe_integersafe_tickerr   iso8601)r   ro   r   r   s       r   r   zaftermath.parse_ticker  s   %%fk::	 !
d&&vx88!
!
 Y//!
 D$$VV44	!

 4##FE22!
 4##FE22!
 ))&+>>!
 4##FE22!
 ))&+>>!
 D$$VV44!
 D$$VV44!
 T!
 D!
 T!
 d&&vx88!
  $!!
" t#!
$ **6<@@++FMBB**6<@@-!
 !
 !
. /  	r   limitc                 j   |                                   |                     |          }|                     |d          }d|i}|                     |                     ||                    }|                     |d          }|                     |||          }	|                     |d          |	d<   |	S )a5  

        https://testnet.aftermath.finance/docs/#/CCXT/orderbook

        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :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   nonce)r   r   r   publicPostOrderbookr   r   parse_order_book)
r   r   r   r   r   r   r   r   r   rp   s
             r   fetch_order_bookzaftermath.fetch_order_book  s     	V$$--D
 ++DKK,H,HII %%h<<	))(FIFF	!..xAA	'r   sincec                 b   |                                   |                     |          }|                     |d          }d|i}|t          |d          |d<   |                     |                     ||                    }|                     |dg           }	|                     |	|||          S )ai  

        https://testnet.aftermath.finance/docs/#/CCXT/trades

        get the list of most recent trades for a particular symbol
        :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
        :param int [params.until]: the latest time in ms to fetch trades for
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r$   r   Nr+   r   rq   )r   r   r   r   publicPostTradesr   	safe_listparse_trades)
r   r   r   r   r   r   r   r   r   datas
             r   fetch_tradeszaftermath.fetch_trades  s     	V$$--D
 "5"~~GG((Wf)E)EFF  ~~h"55  vue<<<r   rawTradec                     |                      |                     d|i|                    }d|d<   d |d<   d |d<   |                     |d          |d<   |S )Nr    r$   ordertakerOrMakerr   )
safe_trader   r   )r   r  r   trades       r   parse_tradezaftermath.parse_trade   sa    VX,> I IJJdg $n!..xEEkr   rX   c                 *   |                                   |                     |          }|                     |d          }||d}|||d<   |||d<   |                     |                     ||                    }	|                     |	||||          S )a  

        https://testnet.aftermath.finance/docs/#/CCXT/ohlcv

        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :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]: max=1000, max=100 when since is defined and is less than(now - (999 * (timeframe in ms)))
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        r$   )r   	timeframeNr   r   )r   r   r   publicPostOHLCVr   parse_ohlcvs)
r   r   r  r   r   r   r   r   r   r   s
             r   fetch_ohlcvzaftermath.fetch_ohlcv(  s     	V$$--"
 
 $GG$GG''GV(D(DEE   69eUKKKr   c                     d}|                      |dd          \  }}d|i}|t          | j        dz             |                     |                     ||                    }|                     |          S )a  

        https://testnet.aftermath.finance/docs/#/CCXT/balance

        query for balance and get the amount of funds available for trading or funds locked in positions
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.account]: account object ID, required
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        Nr=   accountz  fetchBalance() requires account)handle_option_and_paramsr   r$   privatePostBalancer   parse_balance)r   r   r  r   r   s        r   fetch_balancezaftermath.fetch_balanceO  s     77PYZZw
 ?#DG.P$PQQQ**4;;w+G+GHH !!(+++r   c                 2   d|i}|                      |dg           }t          |                                          }t          dt	          |                    D ]v}||         }||         }|                                 }|                     |d          |d<   |                     |d          |d<   |                     |d          |d<   |||<   w|                     |d          }	|	|d<   |                     |	          |d<   | 	                    |          S )	Nr   balancesr   freeusedtotalr   r   )
r   listkeysrangelenr  r   r   r   safe_balance)
r   r   resultr  rn   ir   rv   r  r   s
             r   r  zaftermath.parse_balanceo  s   H
 >>(J;;(--//**
q#j//** 	# 	#Aa=DtnGllnnG"..w??GFO"..w??GFO#//AAGG"F4LL%%h<<	'{!\\)44z  (((r   c                     |                                   d| j        i}|                     |                     ||                    }|                     |          S )ao  

        https://testnet.aftermath.finance/docs/#/CCXT/accounts

        query for accounts owned by the walletAddress. An Account is needed for all trading methods.
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Array: a list of `account structures <https://github.com/ccxt/ccxt/wiki/Manual#accounts>`
        address)r   r~   privatePostAccountsr   parse_accounts)r   r   r   r   s       r   fetch_accountszaftermath.fetch_accounts  s^     	t)
 ++DKK,H,HII ""8,,,r   r  c                     |                      |d          |                      |d          |                      |d          |dS )Nr$   r   r   )r$   r   r   r   r   )r   r  s     r   parse_accountzaftermath.parse_account  sM    ""7D11$$Wf55$$Wf55	
 
 	
r   c                 l   |                                   |                     |          }d}|                     |dd          \  }}|t          | j        dz             |                     |d          |d}|                     |                     ||                    }|                     |          S )aj  

        https://testnet.aftermath.finance/docs/#/CCXT/my_pending_orders

        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
        :param int [params.accountNumber]: account number to query orders for, required
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        NrE   accountNumberz@ fetchOpenOrders() requires an accountNumber parameter in paramsr$   )r   r-  )	r   r   r  r   r$   r   privatePostMyPendingOrdersr   parse_orders)	r   r   r   r   r   r   r-  r   r   s	            r   fetch_open_orderszaftermath.fetch_open_orders  s     	V$$ $ = =fFWYh i iv #DG.p$pqqq$$VT22*
 
 224;;w3O3OPP*   ***r   c                 ^    |                      |g|          }|                     |di           S )a  
        fetch data on an open position

        https://testnet.aftermath.finance/docs/#/CCXT/positions

        :param str symbol: unified market symbol of the market the position is held in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.accountNumber]: account number to query positions for, required
        :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        r   )fetch_positionsr   )r   r   r   rx   s       r   fetch_positionzaftermath.fetch_position  s1     ((&6::	~~iB///r   symbolsc                    |                                   d}|                     |dd          \  }}|t          | j        dz             d|i}|                     |                     ||                    }|                     ||          S )a  

        https://testnet.aftermath.finance/docs/#/CCXT/positions

        fetch all open positions
        :param str[] symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.accountNumber]: account number to query positions for, required
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        NrJ   r-  z? fetchPositions() requires an accountNumber parameter in params)r   r  r   r$   privatePostPositionsr   parse_positions)r   r4  r   r-  r   r   s         r   r2  zaftermath.fetch_positions  s     	 $ = =fFVXg h hv #DG.o$oppp]
 ,,T[[&-I-IJJ4 ##Hg666r   positionc                 ,    |                      |          S N)safe_position)r   r8  r   s      r   parse_positionzaftermath.parse_position  s    !!(+++r   r$   r   sider   r   c                 `    |                      |          }|d         }||||||d}	|||	d<   |	S )Nr   )r   r   r=  r   r   r   r$   )r   )
r   r$   r   r   r=  r   r   r   r   r  s
             r   parse_create_edit_order_argsz&aftermath.parse_create_edit_order_args  sP    V$$!
 
 >E$Kr   c           	          |                                   d}|                     |dd          \  }}|                     d||||||          }|                     |gd|i          }	|	d         S )a  
        create a trade order

        https://testnet.aftermath.finance/docs/#/CCXT/build_create_orders
        https://testnet.aftermath.finance/docs/#/CCXT/submit_create_orders

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.reduceOnly]: True or False whether the order is reduce-only
        :param Account [params.account]: account id to use, required
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr9   r  r   )r   r  r?  create_orders)
r   r   r   r=  r   r   r   r  r  orderss
             r   create_orderzaftermath.create_order!  s}    " 	77yYY11$dFTY[abb##UGi-ABBayr   rB  c                    |                                   g }t          dt          |                    D ])}|                     ||                   }|                     |d          }|                     |          }|                     |d          }|                     |d          }	|                     |di           }
|                     |
d          }|||d<   |d= |d= |d         |d	<   |,|                     | 	                    ||                    |d<   |                     | 
                    ||	                    |d<   |                    |           +d}|                     |d
d          \  }}|d| j        i|dd}|                     |                     ||                    }|                     |          }|                     |          }|                     |          S )ah  

        https://testnet.aftermath.finance/docs/#/CCXT/build_create_orders
        https://testnet.aftermath.finance/docs/#/CCXT/submit_create_orders

        create a list of trade orders
        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param Account [params.account]: account id to use, required
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   r   r   r   r   
reduceOnlyNr$   r   r:   r  senderF)	accountIdmetadatarB  deallocateFreeCollateral)r   r  r   cloner   r   r   r   parse_to_numericprice_to_precisionamount_to_precisionappendr  r~   privatePostBuildCreateOrdersr   sign_tx_ed25519privatePostSubmitCreateOrdersr/  )r   rB  r   ordersRequestr#  r  r   r   r   r   orderParamsrE  r  	txRequesttxr   r   s                    r   rA  zaftermath.create_orders9  s    	q#f++&& 	( 	(AJJvay))E%%eX66F[[((F$$UG44E%%eX66F.."==K\BBJ%&0l#hh"4LE&M !%!6!6t7N7NvW\7]7]!^!^g"33D4L4LVU[4\4\]]E(O  ''''77PYZZ $, $(-
 
	 ..t{{9f/M/MNN&&r**55g>>,   ***r   c                 ^    |                      |g||          }|                     |d          S )a  
        cancels an open order

        https://testnet.aftermath.finance/docs/#/CCXT/build_cancel_orders
        https://testnet.aftermath.finance/docs/#/CCXT/submit_cancel_orders

        :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   )cancel_ordersr   )r   r$   r   r   rB  s        r   cancel_orderzaftermath.cancel_order|  s1     ##RD&&99~~fa(((r   idsc                 \   |                                   |                     |          }d}|                     |dd          \  }}|d| j        i|d         |d}|                     |          }|                     |          }|                     |          }	|                     |	          S )a!  

        https://testnet.aftermath.finance/docs/#/CCXT/build_cancel_orders
        https://testnet.aftermath.finance/docs/#/CCXT/submit_cancel_orders

        cancel multiple orders
        :param str[] ids: order ids
        :param str [symbol]: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param Account [params.account]: account to cancel orders for, required
        :returns Order[]: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr8   r  rF  r$   )rG  rH  r   orderIds)r   r   r  r~   privatePostBuildCancelOrdersrP  privatePostSubmitCancelOrdersr/  )
r   rY  r   r   r   r  rT  rU  r   r   s
             r   rW  zaftermath.cancel_orders  s     	V$$77PYZZ $, 4L
 
	 ..y99&&r**55g>>*   ***r   c                     |                                   |                     |          }|d         }d| j        i|d}|                     |          }|                     |          }|                     |          }|S )Nr   rF  )rH  r   )r   r   r~   privatePostBuildCreateAccountrP  privatePostSubmitCreateAccount)	r   r   r   r   r   rT  rU  r   r   s	            r   create_accountzaftermath.create_account  s    V$$*% $, !	
 
	 //	::&&r**66w??" r   c                    |                                   |                     |          }d}|                     |ddd          \  }}||d         |                     |                     ||                    d| j        id}|                     |          }|                     |          }|                     |          }	|	S )a  

        https://testnet.aftermath.finance/docs/#/CCXT/build_allocate
        https://testnet.aftermath.finance/docs/#/CCXT/submit_allocate

        add margin
        :param str symbol: unified market symbol
        :param float amount: amount of margin to add
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param Account [params.account]: account id to use, required
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
        Nr6   r  rG  r$   rF  rG  r   r   rH  )	r   r   handle_option_and_params_2rK  rM  r~   privatePostBuildAllocaterP  privatePostSubmitAllocate
r   r   r   r   r   r  rT  rU  r   r   s
             r   
add_marginzaftermath.add_margin  s     	V$$99&+yZeff 4L++D,D,DVV,T,TUU$,	
 
	 **955&&r**11'::$ r   c                    |                                   |                     |          }d}|                     |ddd          \  }}||d         |                     |                     ||                    d| j        id}|                     |          }|                     |          }|                     |          }	|	S )a%  

        https://testnet.aftermath.finance/docs/#/CCXT/build_deallocate
        https://testnet.aftermath.finance/docs/#/CCXT/submit_deallocate

        remove margin from a position
        :param str symbol: unified market symbol
        :param float amount: amount of margin to remove
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param Account [params.account]: account id to use, required
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=reduce-margin-structure>`
        NrS   r  rG  r$   rF  rc  )	r   r   rd  rK  rM  r~   privatePostBuildDeallocaterP  privatePostSubmitDeallocaterg  s
             r   reduce_marginzaftermath.reduce_margin  s     	V$$99&.R[]hii 4L++D,D,DVV,T,TUU$,	
 
	 ,,Y77&&r**33G<<$ r   r   fromAccount	toAccountc                 R   |                                   |                     |          }d| j        i||d}|                     |          }|                     |          }	|                     |	          }
|                     |                     |
|          | j        ||d          S )a^  

        https://testnet.aftermath.finance/docs/#/CCXT/build_deposit
        https://testnet.aftermath.finance/docs/#/CCXT/submit_deposit

        transfer currency internally between wallets on the same account
        :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>`
        rF  )rH  rG  r   )rm  rn  r   )r   currencyr~   privatePostBuildDepositrP  privatePostSubmitDepositr   parse_transfer)r   r   r   rm  rn  r   rp  rT  rU  r   r   s              r   rU   zaftermath.transfer:  s     	==&& $, #
 
	 )))44&&r**0099 {{4..xBB-"E
 E
   	r   rU   rp  c           
          |                      |d          }||                      |d          d d |                     ||          d d d d d	S )Nr   r$   )	r   r$   r   r   rp  r   rm  rn  status)r   safe_currency_code)r   rU   rp  
currencyIds       r   rs  zaftermath.parse_transferc  sa    %%h77
""8T22//
HEE

 

 
	
r   r%  tagc                    |                                   |                     |          }d}|                     |dd          \  }}|t          | j        dz             |d| j        i|d}|                     |          }	|                     |	          }
|                     |
          }| 	                    | 
                    ||          ||d          S )aa  

        https://testnet.aftermath.finance/docs/#/CCXT/build_withdraw
        https://testnet.aftermath.finance/docs/#/CCXT/submit_withdraw

        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
        :param Account [params.account]: account id to use, required
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        NrV   r  z2 withdraw() requires a account parameter in paramsrF  )rG  rH  r   )addressFromr   )r   rp  r  r   r$   r~   privatePostBuildWithdrawrP  privatePostSubmitWithdrawr   parse_transaction)r   r   r   r%  rx  r   rp  r  rT  rU  r   r   s               r   rV   zaftermath.withdrawq  s     	==&&77
IVV?#DG.b$bccc $, 
 
	 **955&&r**11':: {{411(HEE"H
 H
   	r   transactionc                     i d|d|                      |d          d|                      |d          dd dd dd dd d	d d
d dd dd dd dd d|                      |d          dd dd dd d d d dS )Nr   r$   txidtx_idr   r   r%  rz  	addressTorx  tagFromtagTor   r   rp  r   ru  updatedcomment)internalfeenetworkr*  )r   r~  rp  s      r   r}  zaftermath.parse_transaction  s   
K
$"";55
 D$$['::
 	

 
 t
 4
 
 4
 t
 T
 D
 d
 ((f==
 d
  t!
" t#
$ )
 
 
 	
r   r   c                 j   |t          | j        dz             |                                  |                     |          }d}|                     |ddd          \  }}||d         |d| j        id}|                     |          }|                     |          }|                     |          }	|	S )	a  
        set the level of leverage for a market

        https://testnet.aftermath.finance/docs/#/CCXT/build_set_leverage
        https://testnet.aftermath.finance/docs/#/CCXT/submit_set_leverage

        :param float leverage: the rate of leverage
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param Account [params.account]: account id to use, required
        :returns dict: response from the exchange
        Nz) setLeverage() requires a symbol argumentrT   r  rG  r$   rF  )rG  r   r   rH  )	r   r$   r   r   rd  r~   privatePostBuildSetLeveragerP  privatePostSubmitSetLeverage)
r   r   r   r   r   r  rT  rU  r   r   s
             r   set_leveragezaftermath.set_leverage  s     >#DG.Y$YZZZV$$99&-QZ\ghh 4L $,	
 
	 --i88&&r**44W==, r   rU  c                    | j                             d          dk    rt          | j        dz             |                     |d          }|                     |          }|                     | j                   }|                     ||d          }|                     | j        d          }|t          | j        dz             |                     |          }| 
                    |                     d	          | 
                    |                     |          |                    }|                     |          }	|                     |d
          }
|	g}|
|dS )a   
        Helper to sign some transaction bytes and return a generic transaction execution request.
        :param dict [tx]: transaction bytes and the signing digest for them
        :returns dict: the input transaction bytes and the signed digest
        
suiprivkeyr   zT only support hex encoding private key, please transform bech32 encoding private keysigningDigested25519	publicKeyNz, requires hex encoding public key in options00transactionBytes)r  
signatures)r   findr   r$   r   base64_to_binarybase16_to_binaryeddsar   r   binary_concatbinary_to_base64)r   rU  r  digestr   	signaturehexPublicKeyr  suiSignature	base64Sigr  r  s               r   rP  zaftermath.sign_tx_ed25519  sk    ?--22tw)  A  A  A((_==&&}55**4?;;
JJvz9==	''kBB#DG.\$\]]])),77	))$*?*?*E*EtGYGYZ^ZoZopyZzZz  }F  HG  HG  H  H)),77	++B0BCC[
$4JOOOr   r  c                 .    |                      ||          S r:  )
safe_order)r   r  r   s      r   parse_orderzaftermath.parse_order  s    uf---r   httpCodereasonurlmethodheadersbodyc
                     |sd S |                     d          dk    r1|                     | j        d         |d           t          |          d S )NErrorr   r   r  )r  throw_broadly_matched_exceptionr   r   )
r   r  r  r  r  r  r  r   requestHeadersrequestBodys
             r   handle_errorszaftermath.handle_errors  s[     	4 99W""001I4QSTTT%%%tr   ry   POSTc                     | j         d         d         dz   |z   }|dk    r|                                  |dk    rddi}|                     |          }||||dS )	Nri   rg   /rz   r  zContent-Typezapplication/json)r  r  r  r  )rf   check_required_credentialsjson)r   pathri   r  r   r  r  r  s           r   signzaftermath.sign  sw    iv&,t3)++---V 2G 99V$$DfdwOOOr   r:  )F__name__
__module____qualname__r   r   r   r   dictr	   r   r   r   r   r   strr   r   r   r   r   r   r
   r   r   r   r  r  r  r  r   r  r  r   r(  r+  r   r   r0  r3  r   r2  r   r<  r   r   floatr   r?  rC  r   rA  rX  rW  ra  r   rh  rl  r   rU   rs  r   rV   r}  intr  rP  r  r  r  __classcell__)r   s   @r   r!   r!      s       U# U U U U U Un ')  Z    >$ 8     $& 8, 8,$v, 8, 8, 8, 8,te4 eF e e e eN 57 . . .;N . . . .	
 	
 	
:M 	
 	
 	
 	
 02 (3 (33 (3f (3 (3 (3 (3T 4  6    6 :>b " "s "3 "Y " " " "H 6:UW &= &=3 &=s &=# &=\`af\g &= &= &= &=P D & E     26DW[df %L %L# %Lc %LQT %Lkoptku %L %L %L %LN $& , ,( , , , ,@) ) ) ) )& %' - -4= - - - -4
T 
g 
 
 
 
 /3TXac ,+ ,+ ,+3 ,+c ,+hlmrhs ,+ ,+ ,+ ,+\ 24 0 0S 0 0 0 0 26b -7 -7w -7 -7 -7 -7^, ,t ,V ,x , , , , @D  MO  s C y Xa kp y|     gksu  3 i y RW `c    0 @B A+ A+D$6 A+d5k A+ A+ A+ A+F 37r ) )s )C ) ) ) ) ;?r 0+ 0+c 0+C 0+dSXk 0+ 0+ 0+ 0+d 24  S U    > =? - - -e -CU - - - -^ @B - -C - -FX - - - -^ [] ' 'S '% 'c 'c 'an ' ' ' 'R
 
t 
x 
= 
 
 
 
 KOWY + +S +% +# +C +^i + + + +Z
 
T 
X 
Q\ 
 
 
 
0 9=R 3 3S 3# 3 3 3 3jP$ P4 P P P P,. . .v . . . . .	c 	3 	S 	# 	X\ 	dg 	 	 	 	 &fRTX 	P 	P 	P 	P 	P 	P 	P 	Pr   r!   N)$ccxt.base.exchanger   ccxt.abstract.aftermathr   ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   ccxt.base.decimal_to_precisionr   r!    r   r   <module>r     s   ( ' ' ' ' ' / / / / / / }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }       * * * * * * . . . . . . ) ) ) ) ) ) 4 4 4 4 4 4HP HP HP HP HP+ HP HP HP HP HPr   