
    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! d d	lm"Z" d d
lm#Z# d dlm$Z$ d dlm%Z% d dlm&Z& d dl'm(Z( d dl)m*Z*  G d dee          Z+dS )    )Exchange)ImplicitAPI)AnyBalances
CurrenciesCurrencyIntLedgerEntryLeverageMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsFundingRateFundingRatesTradeTradingFeesTransaction)List)ExchangeError)AuthenticationError)ArgumentsRequired)
BadRequest)InsufficientFunds)InvalidOrder)NotSupported)NetworkError)RateLimitExceeded)	TICK_SIZE)Precisec                       e Zd Zdef fdZdef fdZi 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i fdefd
Zd Zdfde
dedefdZddi fdedededee         fdZdfdedefdZd Zi f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fdZdfdefdZ dddi fdededefdZ!i fde"fdZ#di fdedede$fdZ%dfdede&fdZ'dddi fded edededee&         f
d!Z(dfd"e
dede)fd#Z*d$efd%Z+d&efd'Z,d(efd)Z-di fded(e.d*e/d+e0d,e1f
d-Z2di fded(e.d*e/d+e0d,e1f
d.Z3i fd/ee4         fd0Z5ddi fd1eded(e.d*e/d+e1d,e1fd2Z6di fd1edefd3Z7di fd4ee         defd5Z8di fdefd6Z9di fd1edefd7Z:dddi fdedededee)         fd8Z;dddi fdedededee)         fd9Z<dddi fdedededee)         fd:Z=dddi fd1edededefd;Z>dddi fdededefd<Z?de@fd=ZAi fde@fd>ZBdddi fd?edededefd@ZCdfdAe
dBeDdeEfdCZFdD ZGdddi fd?edededeeE         fdEZHdfdFe
dBeDdeIfdGZJd&efdHZKdddi fd?edededeeI         fdIZLdddi fd?edededeeI         fdJZMdddi fd?edededeeI         fdKZNi fdLZOdM ZPdN ZQdO ZRdi fd?ed+e0dPedQedeIf
dRZSdfdeTfdSZUi fdedeTfdTZVdi fdUeWdefdVZXdfdWe
defdXZYi fdefdYZZdi fdedee[         fdZZ\d[ Z]d\d]i ddfd^Z^d_eWd`edaedbedce
ddefdeZ_ xZ`S )g	modetradereturnc                    |                      t          t          |                                           i ddddddgddd	d
dddddddddi dd ddddddddddddddddddddddddd dd!dd"dd#di d$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1dd2dd3dd4di d5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBddCddDddEdi dFddGddHddIddJddKddLddMddNddOddPddQddRddSddTddUddVddddddddWdddddddddXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdhdidjdjdidkdldmdndodpd
i dqdrdsdrdtdrdudrdvdrdwdrdxdrdydrdzdrd{drd|drd}drd~drddrddrddddi ddddddddrddrddrddrddrddrddrddrddrddrddrddrddrddrdrdrdrdrddrdrdrdrdrdrdrdddridi ddddddrddrddrddrddrddrddrddrddrddrddrddddrddrddri ddrddddddddddddddddddddddddddddrddri ddrddddddrddddrddrddrddrddrdddddd˓dddddddddddddddddМdrdrdќdrdrdrdrdrdrdrdrdҜdӜdiidddddd՜dddd|                     dئ          |                     d٦          dڜidddddޜddddd dddd dddddddddddddddiddd ddddddddddddddd ddd d dddddddid	ddidd d ddddddid dd d ddi i dt
          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          d t          dt          dt          dt          dt          t          t          t          t          t          t          t          di dt          d          S (  Nidr(   namez
Mode Trade	countriesKY	rateLimitd   versionv1	certifiedFproTdexhostnameztrade.mode.networkhasCORSspotmarginswapfutureoption	addMargincancelAllOrderscancelOrdercancelOrderscancelWithdrawcloseAllPositionsclosePositioncreateConvertTradecreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrdercreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrder$createOrderWithTakeProfitAndStopLosscreateReduceOnlyOrdercreateStopLimitOrdercreateStopLossOrdercreateStopMarketOrdercreateStopOrdercreateTakeProfitOrdercreateTrailingAmountOrdercreateTrailingPercentOrdercreateTriggerOrderfetchAccountsfetchBalancefetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchConvertCurrenciesfetchConvertQuotefetchCurrenciesfetchDepositAddressfetchDepositsfetchDepositsWithdrawalsfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchLedgerfetchLeveragefetchMarginAdjustmentHistoryfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionModefetchPositionsfetchPremiumIndexOHLCVfetchStatusemulated)fetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsfetchTransfersfetchWithdrawalsreduceMarginsetLeverage	setMarginsetPositionModetransferwithdraw
timeframes1m5m15m30m1h4h12h1d1w1mon1y)r   r   r   r   r   r   r   r   r   1Mr   urlszOhttps://github.com/user-attachments/assets/cec2b7f1-3b2b-4502-971b-447ee1937d6bzhttps://api-evm.orderly.org)publicprivatez#https://testnet-api-evm.orderly.orgzhttps://trade.mode.networkz(https://trade.mode.network?ref=MODETRADEg?)urldiscount)logoapitestwwwreferralr   zpublic/volume/stats   zpublic/broker/namezpublic/chain_info/{broker_id}zpublic/system_infozpublic/vault_balancezpublic/insurancefundzpublic/chain_infozfaucet/usdczpublic/accountget_accountregistration_nonceget_orderly_keyzpublic/liquidationzpublic/liquidated_positionszpublic/configzpublic/campaign/ranking
   zpublic/campaign/statszpublic/campaign/userzpublic/campaign/stats/detailszpublic/campaignszpublic/points/leaderboardzclient/pointszpublic/points/epochzpublic/points/epoch_dateszpublic/referral/check_ref_codezpublic/referral/verify_ref_codezreferral/admin_infozreferral/infozreferral/referee_infozreferral/referee_rebate_summaryzreferral/referee_historyzreferral/referral_historyzreferral/rebate_summaryzclient/distribution_historygQ?)z	tv/configz
tv/historyztv/symbol_infozpublic/funding_rate_historyzpublic/funding_rate/{symbol}zpublic/funding_rateszpublic/infozpublic/info/{symbol}zpublic/market_tradeszpublic/tokenzpublic/futureszpublic/futures/{symbol}register_account)getpostzclient/key_info   z!client/orderly_key_ip_restrictionzorder/{oid}zclient/order/{client_order_id}zalgo/order/{oid}z#algo/client/order/{client_order_id}ordersalgo/ordersztrade/{tid}tradeszorder/{oid}/tradeszclient/liquidator_liquidationsliquidationszasset/history<   zclient/holdingwithdraw_noncesettle_noncezpnl_settlement/historyzvolume/user/dailyzvolume/user/statszclient/statisticszclient/infozclient/statistics/daily	positionsgp=
ף
@zposition/{symbol}zfunding_fee/history   z notification/inbox/notificationsznotification/inbox/unreadzvolume/broker/dailybroker/fee_rate/defaultzbroker/user_infozorderbook/{symbol}klineorderly_keyz%client/set_orderly_key_ip_restrictionz'client/reset_orderly_key_ip_restrictionorderbatch-order
algo/orderliquidationclaim_insurance_fundwithdraw_request
settle_pnlznotification/inbox/mark_readz notification/inbox/mark_read_allzclient/leveragex   zclient/maintenance_configdelegate_signerdelegate_orderly_keydelegate_settle_pnl)delegate_withdraw_requestzbroker/fee_rate/setzbroker/fee_rate/set_defaultr   zreferral/createzreferral/updatezreferral/bindzreferral/edit_split)r   r   )r   r   zclient/orderzalgo/client/orderr   r   r   zclient/batch-order)r   r   putdeleterequiredCredentials)apiKeysecret	accountId
privateKeyfeestradingz0.0002z0.0005)	tierBased
percentagemakertakeroptionsCCXTMODE*0x6F7a338F2aA472838dEFD3283eB360d4Dff5D203)sandboxModebrokerIdverifyingContractAddressfeatures)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergmax  i )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   )r   r   r   daysBackCanceledr   r   r   r   r     )	sandboxrK   createOrdersrn   rs   rr   ru   rZ   ro   extendsdefault)r   price)r   r   )r   rK   forDerivatives)linearinverse)r   r9   r   r;   r<   z-1000z-1001z-1002z-1003z-1004z-1005z-1006z-1007z-1008z-1009z-1011z-1012z-1101z-1102z-1103z-1104z-1105)z-1201z-12022993215)exactbroad)commonCurrencies
exceptionsprecisionMode)deep_extendsuperr(   describeparse_numberr   r   r$   r   r!   r    r#   r%   )self	__class__s    L/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/modetrade.pyr  zmodetrade.describe   s   i 6 6 ? ? A A OD
+OD
LOD
 $OD
 	OD

 tOD
 OD
 4OD
 4OD
 ,OD
  TTT %T 	T
 %T %T UT "4T tT T !%T $UT  T %eT 'T  /!T" $T#T T$ ,U%T& 0'T( t)T* 7+T, (-T. '/T0 &t1T2 (3T4 "45T6 (7T8 ,U9T: -e;T< %d=T>  ?T@ ATB &uCTD #EET T TF $TGTH )%ITJ $UKTL "4MTN &uOTP  QTR +DSTT &tUTV 'WTX (YTZ #D[T\ *4]T^ $T_T` "5aTb tcTd  eTf /gT T Th "5iTj kTl !%mTn  oTp dqTr +EsTt !%uTv "4wTx dyTz !${T| t}T~ #DT@  ATB $UCTD !$ETF )%GTH tIT TJ  % %!##($(%/"'$( %#"#(! gT T TOD
~  OD
X i;< 
 DD  4E #  YOD
x / 11/ 0!/  <Q/  1!	/ 
 3A/  3A/  0/  *1/  -a/  *1/  1!/  .q/  1!/  :1/  ,Q/   6r!/ " 4R#/  / $ 3B%/ & <R'/ ( /)/ * 8+/ , ,Q-/ . 21// 0 81/ 2 =a3/ 4 >q5/ 6 217/ 8 ,Q9/ : 4Q;/ < >q=/ > 7?/ @ 8A/ B 6qC/ D :1E/  / F *+*+./;<<@45+,4545,-./78]/  /  / b /!c4 4l" -q" ?"  *1"  =a	" 
 /"  B1"  %a"  *1"  *1"  %a"  1!"  =a"  +A"  ,R"  -a"   -a!" " +A#"  " $ 5a%" & 0'" ( 0)" * 0+" , *2-" . 6r/" 0 (1" 2 03" 4 225" 6 ?7" 8 89" : 22;" < 6r=" > /?" @ 1!A" B $QC"  " F!)1!CQ! Fq! $Q	!
 *2! )!! *1! 3A! /! )!! ;B! ?! .s! 8! .r!  3B!!" 22#!$ :<35;=79/1/1-/353! ! !8 &'*+   
 &'*+,-12+,&'+,23	# 	#GM  M mD DFyOD
F "!#	$ $GOD
R !%"&!..x88!..x88	 SOD
b $&,X cOD
l #&+(,,0,1).+06:#'#'"&#(	( ( #($($(+027/4#')$ $. r% ',!$$(%+*/& & ',#'$)*/	# # ',!$#'$)*/( ( $(&+!$$(,0%+#'$)*/	* 	*  #u= =~ y  ) -1 15%*7 7$ $# # "#3  $	  ## iX XmOD
^ !#]0 0 .	
 Z Z \ Z \ . \ Z . \ \  \!" \#$ ('$,,#$1  47 < ']OD
 OD
 OD
 O O O	    enablec                 l    t          t          |                               |           || j        d<   d S )Nr   )r  r(   set_sandbox_moder   )r
  r  r  s     r  r  zmodetrade.set_sandbox_mode  s3    i//777&,]###r  c                     |                      |          }|                     |di           }|                     |d          }|d}n|dk    rd}nd}|ddd|dS )	az  
        the latest known information on the availability of the exchange API

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-system-maintenance-status

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `status structure <https://docs.ccxt.com/?id=exchange-status-structure>`
        datastatusNerror0okmaintenance)r  updatedetar   info)v1PublicGetPublicSystemInfo	safe_dictsafe_string)r
  paramsresponser  r  s        r  fetch_statuszmodetrade.fetch_status  s     33F;; ~~h33!!$11>FFs]]FF"F
 
 	
r  c                 X    |                      |          }|                     |d          S )a  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-system-maintenance-status

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        	timestamp)r  safe_integer)r
  r  r  s      r  
fetch_timezmodetrade.fetch_time  s/     33F;;   ;777r  marketc                    |                      |d          }|                    d          }d}|                      |d          }|                      |d          }|                     |          }|                     |          }|                      |d          }	|                     |	          }
|dz   |z   dz   |
z   }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#|                     |d$          |d%
S )&Nsymbol_r;   r      /:r+   basequotesettlebaseIdquoteIdsettleIdtyper9   Fr:   Tr<   r=   activecontractr   1	base_tick
quote_tick)amountr   minr   base_minbase_max	quote_min	quote_maxmin_notional)r   r8  r   costcreated_time)
r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedr  )r  splitsafe_currency_coder	  safe_numberr#  )r
  r%  marketIdparts
marketTyper/  r0  r,  r-  r1  r.  r'  s               r  parse_marketzmodetrade.parse_market  s   8 ##FH55s##
!!%++""5!,,&&v..''00((22--h77e#c)F20
(0
f0
 D0
 U	0

 f0
 f0
 w0
 0
 J0
 E0
 e0
 D0
 e0
 e0
 d0
  !0
" d#0
$  --c22"**6;??))&,??    
  ++FJ??++FJ?? 
  ++FK@@++FK@@ 
  ++FNCC  $ ((@@_0
 0
 0
 0	
r  c                     |                      |          }|                     |di           }|                     |dg           }|                     |          S )a=  
        retrieves data on all markets for modetrade

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-available-symbols

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r  rows)v1PublicGetPublicInfor  	safe_listparse_markets)r
  r  r  r  rR  s        r  fetch_marketszmodetrade.fetch_marketsA  sX     --f55H ~~h33~~dFB//!!$'''r  c                    i }|                      |          }|                     |di           }|                     |dg           }t          dt	          |                    D ]e}||         }|                     |d          }|                     |d          }	|                     |          }
d}i }t          dt	          |	                    D ]}|	|         }|                     |d          }|                     |                     |d                    }|||nt          j	        ||          }||ddd	ddd	d
ddd| 
                    |d          |                     |          |d	||<   |                     |||
|                     |          dd|ddddd	| 
                    |d          dd	d|d          ||
<   g|S )a3  
        fetches all available currencies on an exchange

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-token-info

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r  rR  r   tokenchain_detailsNchain_iddecimalsr9  )r   depositwithdrawal_fee)	r+   networkrH  r3  r\  r   feerG  r  minimum_withdraw_amount)r\  r   )r+   r,   coderG  r3  r_  networksr\  r   rH  r  )v1PublicGetPublicTokenr  rT  rangelenr  rK  parse_precisionr&   
string_minrL  r	  safe_currency_structure)r
  r  resultr  r  	tokenRowsirX  
currencyIdrb  ra  minPrecisionresultingNetworksjr^  	networkIdrG  s                    r  fetch_currencieszmodetrade.fetch_currenciesr  sP    ..v66. ~~h33NN444	q#i..)) 7	 7	AaLE))%99J~~e_==H**:66DL&(1c(mm,,  "1+ ,,WjAA	 001A1A':1V1VWW	(1=1E99GL^_hjvLwLwL#( $(#'% %
 $(#'$ $	 	 ## $++G5EFF!%!2!29!=!=#%0 0!),,(  77 "!..|<<-   $#   
  $//7PQQ#! !	 	 )9 9  F4LL, r  c                     |                      ||          }d }|0|                      ||          }|                     |          }||d}|S )Nr@  currency)r  rK  )r
  itemfeeTokenKeyfeeAmountKeyfeeCostr_  feeCurrencyIdfeeCurrencyCodes           r  parse_token_and_fee_tempz"modetrade.parse_token_and_fee_temp  sc    ""466 ,,T;??M"55mDDO+ C 
r  Ntradec                    d|v }|                      |d          }|                     |d          }|                     ||          }|d         }|                     |d          }|                     |d          }|                     |d          }	|                     |dd          }
|                     |
d	          }|||
d	<   t	          j        ||          }|                     |d
          }|                     |d          }d }|r |                     |d          dk    }|rdnd}|                     |||                     |          ||||||	|d |
|d|          S )Nr+   executed_timestampr'  executed_priceexecuted_quantityorder_id	fee_assetr_  r@  sideis_makerr5  r   r   )r+   r"  datetimer'  r  r   r8  r@  r   takerOrMakerr2  r_  r  )	r#  r  safe_marketr{  r&   
string_mulsafe_string_lower
safe_tradeiso8601)r
  r|  r%  isFromFetchOrderr"  rM  r'  r   r8  r  r_  rx  r@  r  r+   r  isMakers                    r  parse_tradezmodetrade.parse_trade  s   8 !EM%%e-ABB	##E844!!(F33!  (899!!%)<==##E:66++E;FF""3//!CK!%00%%eV44eT**  	;&&uj99S@G&-:777L"Y//( 
  
   	r  r'  sincer   c                 T   |                                   |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |di           }|                     |dg           }	|                     |	|||          S )a<  
        get the list of most recent trades for a particular symbol

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-market-trades

        :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+   Nr   r  rR  )load_marketsr%  v1PublicGetPublicMarketTradesextendr  rT  parse_trades)
r
  r'  r  r   r  r%  requestr  r  rR  s
             r  fetch_tradeszmodetrade.fetch_trades  s     	V$$fTl
 $GG55dkk'66R6RSS  ~~h33~~dFB//  vue<<<r  c                    |                      |d          }|                     |          }|                     |d          }|                     |d          }|                     |d          }|                      |d          }|                      |d          }t          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|                     |	          iS )Nr'  next_funding_timeest_funding_rate_timestamplast_funding_rate_timestampr  	markPrice
indexPriceinterestRater  estimatedSettlePricer"  r  fundingRateest_funding_ratefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatelast_funding_ratepreviousFundingTimestamppreviousFundingDatetimeinterval)	r  r%  r#  r&   
string_subr	  r  rL  parse_funding_interval)
r
  r  r%  r'  r  estFundingRateTimestamplastFundingRateTimestampfundingTimeStringnextFundingTimeStringmillisecondsIntervals
             r  parse_funding_ratezmodetrade.parse_funding_rateA  s    !!+x88V$$#00>QRR"&"3"3KA]"^"^#'#4#4[B_#`#`  ,,[:WXX $ 0 0>Q R R&12GIZ[[
K
fX&
 
 $	

 D--c22
 #D
 0
 %<==
 4++K9KLL
  4
 t||,@AA
 t
 #D
 "4
 "4#3#3KAT#U#U
  '(@!
" &t||4L'M'M#
$ 334HII%
 
 	
r  c                 @    dddddd}|                      |||          S )Nr   r   8h16h24h)360000014400000288000005760000086400000r  )r
  r  	intervalss      r  r  z modetrade.parse_funding_intervalj  s7    
 
	 	8X>>>r  c                 .    |                      ||          S )a  
        fetch the current funding rate interval

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-predicted-funding-rate-for-one-market

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/?id=funding-rate-structure>`
        )fetch_funding_rate)r
  r'  r  s      r  fetch_funding_intervalz modetrade.fetch_funding_intervalt  s     &&vv666r  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     ||          S )a  
        fetch the current funding rate

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-predicted-funding-rate-for-one-market

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/?id=funding-rate-structure>`
        r'  r+   r  )r  r%  "v1PublicGetPublicFundingRateSymbolr  r  r  r
  r'  r  r%  r  r  r  s          r  r  zmodetrade.fetch_funding_rate  s     	V$$fTl
 ::4;;wPV;W;WXX  ~~h33&&tV444r  symbolsc                    |                                   |                     |          }|                     |          }|                     |di           }|                     |dg           }|                     ||          S )a  
        fetch the current funding rate for multiple markets

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-predicted-funding-rates-for-all-markets

        :param str[] symbols: unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of `funding rate structures <https://docs.ccxt.com/?id=funding-rate-structure>`
        r  rR  )r  market_symbolsv1PublicGetPublicFundingRatesr  rT  parse_funding_rates)r
  r  r  r  r  rR  s         r  fetch_funding_rateszmodetrade.fetch_funding_rates  s~     	%%g..55f==$ ~~h33~~dFB//''g666r  c           
         |                                   d}|                     |dd          \  }}|r|                     d||||dd          S i }|(|                     |          }|d         }|d         |d<   |||d	<   |                     d
||d          \  }}|                     |                     ||                    }|                     |di           }	|                     |	dg           }
g }t          dt          |
                    D ]}|
|         }|                     |d          }|                     |d          }|                    ||                     |          |                     |d          ||                     |          d           |                     |d          }|                     ||||          S )a  
        fetches historical funding rate prices

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-funding-rate-history-for-one-market

        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: timestamp in ms of the earliest funding rate to fetch
        :param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/?id=funding-rate-history-structure>` to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest funding rate
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/?id=funding-rate-history-structure>`
        Fre   paginatepage   Nr'  r+   start_tend_tgMbP?r  rR  r   funding_rate_timestampfunding_rate)r  r'  r  r"  r  r"  )r  handle_option_and_params fetch_paginated_call_incrementalr%  handle_until_option#v1PublicGetPublicFundingRateHistoryr  r  rT  rd  re  r  r#  appendsafe_symbolrL  r  sort_byfilter_by_symbol_since_limit)r
  r'  r  r   r  r  r  r%  r  r  ri  ratesrk  entryrM  r"  sorteds                    r  fetch_funding_rate_historyz$modetrade.fetch_funding_rate_history  s    	88AZ\fgg& 	~889RTZ\achjprxz|}}}[[((FH%F &tGH!&GI227GVUSS;;DKKQW<X<XYY( ~~h33fb11q#f++&& 
	 
	A1IE''x88H))%1IJJILL**844#//~FF& LL33      e[1100NNNr  c           	         |                      |d          }|                     ||          }|                      |d          }|                     d          }|                     |d          }|                     |d          }|                      |d          }	|	dk    rt          j        |          n|}|||||                     |          d |                     |          |dS )	Nr'  funding_feeUSDCupdated_timer  payment_typePay)r  r'  ra  r"  r  r+   r8  rate)	r  r  rK  r#  rL  r&   
string_negr  r	  )
r
  incomer%  rM  r'  r8  ra  r"  r  paymentTypes
             r  parse_incomezmodetrade.parse_income  s     ##FH55!!(F33!!&-88&&v..%%fn==	77&&v~>>0;u0D0D#F+++6"Y//''//	
 	
 		
r  c           	      f   |                                   d}|                     |dd          \  }}|r|                     d||||dd          S i }d}| |                     |          }|d         |d<   |||d	<   |                     |d
          }|                     |d
g          }|||d<   |t          |d          |d<   |                     |                     ||                    }	| 	                    |	di           }
| 
                    |
dg           }|                     ||||          S )aV  
        fetch the history of funding payments paid and received on self account

        https://orderly.network/docs/build-on-omnichain/evm-api/restful-api/private/get-funding-fee-history

        :param str [symbol]: unified market symbol
        :param int [since]: the earliest time in ms to fetch funding history for
        :param int [limit]: the maximum number of funding history structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict: a `funding history structure <https://docs.ccxt.com/?id=funding-history-structure>`
        Fra   r  r  r   Nr+   r'  r  untilr  sizer  rR  )r  r  r  r%  r#  omitr:  v1PrivateGetFundingFeeHistoryr  r  rT  parse_incomes)r
  r'  r  r   r  r  r  r%  r  r  r  rR  s               r  fetch_funding_historyzmodetrade.fetch_funding_history$  s`    	88AVXbcc& 	{889NPVX]_dflntvyzzz[[((F &tGH!&GI!!&'226G9--$GG!%ooGFO55dkk'66R6RSS0 ~~h33~~dFB//!!$u===r  c           
         |                                   |                     |          }|                     |di           }|                     |d          }|                     |d          }i }t	          dt          | j                            D ]g}| j        |         }|||                     t          j	        |d                    |                     t          j	        |d                    ddd||<   h|S )av  
        fetch the trading fees for multiple markets

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-account-information

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/?id=fee-structure>` indexed by market symbols
        r  futures_maker_fee_ratefutures_taker_fee_rater   10000T)r  r'  r   r   r   r   )
r  v1PrivateGetClientInfor  r  rd  re  r  r	  r&   
string_div)	r
  r  r  r  r   r   ri  rk  r'  s	            r  fetch_trading_feeszmodetrade.fetch_trading_fees_  s     	..v668 ~~h33  '?@@  '?@@q#dl++,, 		 		A\!_F  **7+=eW+M+MNN**7+=eW+M+MNN"! F6NN r  c           	      x   |                                   |                     |          }d|d         i}|t          |d          }||d<   |                     |                     ||                    }|                     |di           }|                     |d          }|                     |||dd	d
d          S )aT  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/orderbook-snapshot

        :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+   Nr   	max_levelr  r"  bidsasksr   quantity)r  r%  r:  v1PrivateGetOrderbookSymbolr  r  r#  parse_order_book)	r
  r'  r   r  r%  r  r  r  r"  s	            r  fetch_order_bookzmodetrade.fetch_order_book  s     	V$$fTl
 t$$E#(GK 33DKK4P4PQQ$ ~~h33%%dK88	$$T69ffgWabbbr  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nstart_timestampopenhighlowclosevolume)r#  rL  )r
  ohlcvr%  s      r  parse_ohlcvzmodetrade.parse_ohlcv  s    e%677UF++UF++UE**UG,,UH--
 	
r  r   	timeframec                    |                                   |                     |          }|d         |                     | j        ||          d}|t	          |d          |d<   |                     |                     ||                    }|                     |di           }	|                     |	dg           }
| 	                    |
||||          S )a  

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-kline

        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'  r2  Nr   r   r  rR  )
r  r%  r  r   r:  v1PrivateGetKliner  r  rT  parse_ohlcvs)r
  r'  r  r  r   r  r%  r  r  r  rR  s              r  fetch_ohlcvzmodetrade.fetch_ohlcv  s     	V$$Tl$$T_iKK
 
 "5$//GG))$++gv*F*FGG~~h33* ~~dFB//  vy%GGGr  r   c                    |                      |g d          }|                     |g d          }|                     |                     |dd                    }|                     |d          }|                     ||          }|d         }|                     |dd          }|                     |dd	          }	|                     |d
d          }
|                     |dd          }|                     |dd          }|                     |d          }||rdnd}| 	                    |d          }|                     |                     |dd                    }|                     |                     |dd                    }t          j        |
|          }|                     |dd          }|                     |dd          }|                     |d          }|                     |d          }d }d }|                     |d          }||                     |d          }|                     |dg           }t          |          }|dk    rX|                     |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/|          S )0N)r"  rA  createdTime)r  orderIdalgoOrderIdclient_order_idclientOrderIdr'  order_pricer   order_quantityr  order_amountr8  
order_typer2  r  
algoStatussuccessNEWREJECTEDr  executedtotalExecutedQuantityaverage_executed_priceaverageExecutedPrice	total_feetotalFeer  feeAssetTransactionsr   childOrdersr   r   updatedTimer  r+   r"  r  lastTradeTimestamplastUpdateTimestampr   postOnly
reduceOnlyreduce_onlyr   r   rs  )averager8  filled	remainingr@  r   r_  r  )safe_integer_nsafe_string_n	omit_zerosafe_string_2r  r  safe_string_lower_2safe_value_2	safe_boolr  r&   r  
safe_valuerL  re  safe_integer_2
safe_orderr  parse_order_statusparse_order_typeparse_time_in_force)r
  r   r%  r"  r  r  rM  r'  r   r8  r@  	orderTyper  r  r  r+  r*  r,  r_  feeCurrencytransactionsr   r   r   r#  firstinnerChildOrdersinnerChildOrdersLengthtakeProfitOrderstopLossOrderr&  s                                  r  parse_orderzmodetrade.parse_order  s,   \ ''/[/[/[\\	$$U,R,R,RSSt'9'9%ARTc'd'dee##E844!!(F33!""5-AA##E+;ZHH!!%BB,,UL&II	""5(LAA..	22&7UUZF%%eV44 1 1%E\ ] ]^^..!3!3E;SUk!l!lmm&tV44	{J??((ZHHun==''~>>#!ooe];;"OOK33E#umRHH%()9%:%:"%))"&//2BA"F"F $0@! D D"&"2"2?N"S"S $ 0 0 O O"11%WW  
' 
] 
  
 Y//	 

 !$ 
 "#6 
 d--f55 
 f 
 D)))44 
 433I>> 
  
 $..>> 
 D 
 U 
 L 
  ! 
" ]# 
$ ""'  9 
  
  
: ;  	r  r   c                 <    dddd}|                      ||d           S )Nr   r   r   )iocfok	post_onlyr  )r
  r   timeInForcess      r  r9  zmodetrade.parse_time_in_forcef  s1    
 

 k4@@@r  r  c           
      P    |#dddddddddd	}|                      |||          S |S )Nr  closedcanceledrejected)	r  FILLEDCANCEL_SENTCANCEL_ALL_SENT	CANCELLEDPARTIAL_FILLEDr  
INCOMPLETE	COMPLETEDr  r
  r  statusess      r  r7  zmodetrade.parse_order_statusn  sN    ")#-'"(&$%
 
H ##Hff===r  r2  c                 <    dddd}|                      |||          S )Nr   r%  )LIMITMARKET	POST_ONLY)r  r
  r2  typess      r  r8  zmodetrade.parse_order_type~  s1     
 

 %%eT4888r  r  r8  r   c                    |                      |dd          }|                                }|                     |          }	|                                }
|	d         |
d}|                     |dd          }|                     |d          }|                     |d          }|d	u}|d	u}|                     |d
          }|d	up|p|p|                     |d          d	u}|dk    }|                     |d          }|                     |d	|          }|rdnd}|rdnd}|rdnd}|||<   |s|rd|d<   n|dk    rd|d<   n|dk    rd|d<   |r||d<   ||                     ||          ||<   |r|s| 	                    ||          ||<   n|dk    r| 	                    ||          ||<   | 
                    |g d          }|||d<   ||                     ||          |d<   d|d<   n|s|rd|d<   |	d         d dg d!}|d"         }|
d#k    rd$nd#}|rI|                     |dd|          }|d|                     ||          d%d&d'}|                    |           |rI|                     |dd|          }|d|                     ||          d%d&d'} |                    |            |g|d"<   |                     |g d(          }|                     ||          S ))aL  
 @ignore
        helper function to build the request
        :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 you want to trade in units of the base currency
        :param float [price]: the price that 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
        :returns dict: request to be sent to the exchange
        r(  r)  r+   )r'  r  r   	stopPricestopLoss
takeProfitNalgoTyper#  rW  r   r  r  r   r  r2  r  rX  rE  r   rD  r   POSITIONAL_TP_SLclOrdIDr  r  r  trigger_priceSTOP	algo_typeTP_SLF)r'  r)  re  child_ordersrg  BUYSELLrV  T)r  re  rc  r2  r)  )r(  r)  rb  r  r  r'  r   r\  r   r]  r^  )safe_bool_2upperr%  r0  r4  r  r  is_post_onlyprice_to_precisionamount_to_precisionr.  safe_number_2r  r  r  )!r
  r'  r2  r  r8  r   r  r(  r:  r%  	orderSider  r   r]  r^  hasStopLosshasTakeProfitr_  isConditionalisMarketr   r'  orderQtyKeypriceKeytypeKeyr  outterOrderr#  	closeSider   rA  r   r@  s!                                    r  create_order_requestzmodetrade.create_order_request  s     %%flMJJ
JJLL	V$$JJLL	Tl
 
 ))&.+NN??6:66__V\::
d*"$.##FJ77$D0  IK  I=  IUYUdUdekmzU{U{  DH  VH(,,V]CC$$XtV<<$1Gjj7G+>77);&&|$ 	. .(3%%%%(-%%%%(-% 	0%/GM" $ 7 7 F FGH 	LM 	L#'#;#;FF#K#KGK  +++#'#;#;FF#K#KGK **63b3b3bcc$)6G%&#'+'>'>v|'T'TGO$#)GK   	4M 	4#*GK  ,$/ "	! !K &n5K#,#5#5EI 	2 $ 2 28^WV^ _ _%!(%)%<%<V]%S%S##'' ' ""=111 	4"&"4"4ZQXZd"e"e%!(%)%<%<V_%U%U##') ) ""?333'2mGN#6  $B  $B  $B  C  C{{7F+++r  c                 L   |                                   |                     |          }|                     ||||||          }|                     |dd          }	|                     |d          }
|                     |d          }|	dup|
dup|dup|                     |d          du}d}|r|                     |          }n|                     |          }|                     |d          }|                     |d          |d<   | 	                    ||          }||d	<   |S )
a  
        create a trade order

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/create-order
        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/create-algo-order

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: The price a trigger order is triggered at
        :param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered(perpetual swap markets only)
        :param float [params.takeProfit.triggerPrice]: take profit trigger price
        :param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered(perpetual swap markets only)
        :param float [params.stopLoss.triggerPrice]: stop loss trigger price
        :param float [params.algoType]: 'STOP'or 'TP_SL' or 'POSITIONAL_TP_SL'
        :param float [params.cost]: *spot market buy only* the quote quantity that can be used alternative for the amount
        :param str [params.clientOrderId]: a unique id for the order
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r   r\  r]  r^  Nr#  r  r"  r2  )
r  r%  rz  r0  r4  v1PrivatePostAlgoOrderv1PrivatePostOrderr  r#  rB  )r
  r'  r2  r  r8  r   r  r%  r  r   r]  r^  rs  r  r  r   s                   r  create_orderzmodetrade.create_order  sd   . 	V$$++FD$vVV))&.+NN??6:66__V\::
$D0  [HD4H  [J^bLb  [gkgvgvw}  @M  hN  hN  VZ  hZ 	8227;;HH ..w77H  ~~h// --hDD[  v..fr  r   c           	         |                                   g }t          dt          |                    D ]?}||         }|                     |d          }|                     |d          }|                     |d          }|                     |d          }	|                     |d          }
|                     |di           }|                     |dd	          }|                     |d
          }|                     |d          }|dup|dup|dup|                     |d          du}|rt          | j        dz             | 	                    ||||	|
|          }|
                    |           Ad|i}|                     |                     ||                    }|                     |di           }|                     |dg           }|                     |          S )a  
        *contract only* create a list of trade orders

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/batch-create-order

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r   r'  r2  r  r8  r   r  r   r\  r]  r^  Nr#  z+ createOrders() only support non-stop orderr   r  rR  )r  rd  re  r  r4  r  r0  r"   r+   rz  r  v1PrivatePostBatchOrderr  rT  parse_orders)r
  r   r  ordersRequestsrk  rawOrderrM  r2  r  r8  r   orderParamsr   r]  r^  rs  orderRequestr  r  r  rR  s                        r  create_orderszmodetrade.create_orders#  s    	q#f++&& 	0 	0AayH''(;;H##Hf55D##Hf55D__Xx88FOOHg66E..8R@@K--k>;WWL{J??HlCCJ(4  d8L  dPZbfPf  dkokzkz  |G  IV  lW  lW  _c  lcM \"47-Z#Z[[[44XtT6SXZeffL!!,////n
 //GV0L0LMM$ ~~h33~~dFB//  &&&r  r+   c                 r   |                                   |                     |          }d|i}	|                     |g d          }
|
|                     ||
          |	d<   |
dup|                     |d          du}|rdnd}|rdnd	}||                     ||          |	|<   ||                     ||          |	|<   |                     |g d
          }d}|r*|                     |                     |	|                    }n|d         |	d<   |	                                |	d<   |	                                }| 
                    |d          }|dk    }|                     |d|          }|rd|	d<   n|dk    rd|	d<   n|dk    rd|	d<   n||	d<   |                     |g d          }|                     |g d          }|||	d<   |                     |                     |	|                    }|                     |di           }|                     |d          |d<   |                     ||          S )a,  
        edit a trade order

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/edit-order
        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/edit-algo-order

        :param str id: order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of 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 a trigger order is triggered at
        :param float [params.stopLossPrice]: price to trigger stop-loss orders
        :param float [params.takeProfitPrice]: price to trigger take-profit orders
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r  )r   r\  r   r   Nr   r#  r  r  r   r  )r\  r   r   r   trailingTriggerPricetrailingAmounttrailingPercentr+   r'  r  r   rW  rX  r  rE  r   rD  r   ra  )rb  r  r  r'  r   r  r  r"  )r  r%  r.  rm  r4  rn  r  v1PrivatePutAlgoOrderr  rk  r  rl  v1PrivatePutOrderr  r#  rB  )r
  r+   r'  r2  r  r8  r   r  r%  r  r   rs  ru  rv  r  r:  r   rt  r'  r  r  s                        r  
edit_orderzmodetrade.edit_orderX  s   & 	V$$
 ))&2s2s2stt#&*&=&=fl&S&SGN#%T1jtv}7]7]ei7i$1Gjj7G+>77 $ 7 7 F FGH#'#;#;FF#K#KGK 6  $b  $b  $b  c  c 	L11$++gv2N2NOOHH &tGH"jjllGFO

I00GGK H,H((4@@H 2(3%%%%(-%%%%(-%%(1% ..v7f7f7fggMYYv'q'q'qrrF(-:)* --dkk'6.J.JKKH ~~h33 --hDD[f---r  c                 H   |                      |ddd          }|                     |ddg          }|s|t          | j        dz             |                                  d}||                     |          }d|d         i}|                     |dd	          }|                     |d
|          }|du}	d}
|rx|	rG||d
<   |                     |g d          }|                     | 	                    ||                    }
n||d<   | 
                    | 	                    ||                    }
nw|	rG||d
<   |                     |g d          }|                     | 	                    ||                    }
n.||d<   |                     | 	                    ||                    }
d|i}|	r||d
<   n||d<   |r)| 	                    |                     |
          |          S |                     |
di           }| 	                    |                     |          |          S )au  

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-order
        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-order-by-client_order_id
        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-algo-order
        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-algo-order-by-client_order_id

        cancels an open order
        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: whether the order is a stop/algo order
        :param str [params.clientOrderId]: a unique id for the order
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        stopr   FNz) cancelOrder() requires a symbol argumentr'  r+   rb  r  r  ra  r  r  )rj  r  r   r+   r  r%  r0  r  v1PrivateDeleteAlgoClientOrderr  v1PrivateDeleteAlgoOrderv1PrivateDeleteClientOrderv1PrivateDeleteOrderrB  r  )r
  r+   r'  r  r   r%  r  clientOrderIdUnifiedclientOrderIdExchangeSpecificisByClientOrderr  extendParamsr  s                r  cancel_orderzmodetrade.cancel_order  sl     ""669eDD6FI#677 	[FN#DG.Y$YZZZ[[((FfTl
  $11&)_UU(,(8(8ARTh(i(i%7tC 	S W-J)*6+Z+Z+Z[[>>t{{7TZ?[?[\\&(
#88Wf9U9UVV S-J)*6+Z+Z+Z[[::4;;wPV;W;WXX&(
#44T[[&5Q5QRR  '/ 	$.KL*++!#L 	I;;t//99<HHH~~h33{{4++D11<@@@r  idsc                    |                                   |                     |g d          }|                     |g d          }i }d}|rBd                    |          |d<   |                     |                     ||                    }nAd                    |          |d<   |                     |                     ||                    }|                     d|i          gS )a  
        cancel multiple orders

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/batch-cancel-orders
        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/batch-cancel-orders-by-client_order_id

        :param str[] ids: order ids
        :param str [symbol]: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str[] [params.client_order_ids]: max length 10 e.g. ["my_id_1","my_id_2"], encode the double quotes. No space after comma
        :returns dict: an list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        )clOrdIDsclientOrderIdsclient_order_idsN,r  	order_idsr  )r  safe_list_nr  joinv1PrivateDeleteClientBatchOrderr  v1PrivateDeleteBatchOrderr6  )r
  r  r'  r  r  r  r  s          r  cancel_orderszmodetrade.cancel_orders  s     	))&2d2d2dee6#U#U#UVV 	T*-((>*B*BG&';;DKKQW<X<XYYHH#&88C==GK 55dkk'66R6RSSH H!
    	r  c                    |                                   |                     |dd          }|                     |ddg          }i }| |                     |          }|d         |d<   d}|r*|                     |                     ||                    }n)|                     |                     ||                    }|                     d|i          gS )a>  

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-all-pending-algo-orders
        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-orders-in-bulk

        cancel all open orders in a market
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: whether the order is a stop/algo order
        :returns dict: an list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        r  r   Nr+   r'  r  )r  rj  r  r%  v1PrivateDeleteAlgoOrdersr  v1PrivateDeleteOrdersr6  )r
  r'  r  r   r  r%  r  s          r  cancel_all_orderszmodetrade.cancel_all_orders  s     	""669==6FI#677[[((F &tGH 	P55dkk'66R6RSSHH11$++gv2N2NOOH" OO  
 	
r  c                    |                                   d}||                     |          }|                     |ddd          }i }|                     |g d          }|                     |g d          }d}|r`|r/||d<   |                     |                     ||                    }n||d<   |                     |                     ||                    }n_|r/||d<   |                     |                     ||                    }n.||d<   | 	                    |                     ||                    }| 
                    |d	|          }	|                     |	|          S )
a  

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-order-by-order_id
        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-order-by-client_order_id
        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-algo-order-by-order_id
        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-algo-order-by-client_order_id

        fetches information on an order made by the user
        :param str id: the order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: whether the order is a stop/algo order
        :param str [params.clientOrderId]: a unique id for the order
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr  r   Fra  )r  r   rb  r  r  r  oidr  )r  r%  rj  r.  r  (v1PrivateGetAlgoClientOrderClientOrderIdr  v1PrivateGetAlgoOrderOid$v1PrivateGetClientOrderClientOrderIdv1PrivateGetOrderOidr  rB  )
r
  r+   r'  r  r%  r   r  r  r  r   s
             r  fetch_orderzmodetrade.fetch_order;  s     	[[((F""669eDD**63b3b3bcc6#e#e#eff 	S W-:)*HHU\^dIeIeff!#88Wf9U9UVV S-:)*DDT[[QXZ`EaEabb!#44T[[&5Q5QRR8 &(;;///r  c           	         |                                   d}|                     |ddd          }|rdnd}|                     |dd          \  }}|r|                     d||||d|          S i }d	}	|                     |ddg          }| |                     |          }	|	d
         |d<   |||d<   |||d<   n||d<   |rd|d<   |                     d||          \  }}d	}
|r*|                     |                     ||                    }
n)| 	                    |                     ||                    }
| 
                    |
d|
          }|                     |d          }|                     ||	||          S )a>  
        fetches information on multiple orders made by the user

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-orders
        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-algo-orders

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: whether the order is a stop/algo order
        :param boolean [params.is_triggered]: whether the order has been triggered(False by default)
        :param str [params.side]: 'buy' or 'sell'
        :param boolean [params.paginate]: set to True if you want to fetch orders with pagination
        :param int params['until']: timestamp in ms of the latest order to fetch
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Fr  r   r0   r   ru   r  r  Nr+   r'  r  r  rd  re  r  r  rR  )r  rj  r  r  r  r%  r  v1PrivateGetAlgoOrdersr  v1PrivateGetOrdersr4  rT  r  )r
  r'  r  r   r  r  	isTriggermaxLimitr  r%  r  r  r   s                r  fetch_orderszmodetrade.fetch_orders  s   $ 	$$VVYFF	$.33388PZ[[& 	x88PUW\^dflnvwww6FI#677[[((F &tGH!&GI#GFOO&GFO 	*#)GK 227GVLL 	M224;;w3O3OPPHH..t{{7F/K/KLLHF x::f--  >>>r  c                     |                                   |                     |ddi          }|                     ||||          S )>  
        fetches information on multiple orders made by the user

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-orders
        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-algo-orders

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: whether the order is a stop/algo order
        :param boolean [params.is_triggered]: whether the order has been triggered(False by default)
        :param str [params.side]: 'buy' or 'sell'
        :param int params['until']: timestamp in ms of the latest order to fetch
        :param boolean [params.paginate]: set to True if you want to fetch orders with pagination
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        r  rQ  r  r  r  r
  r'  r  r   r  extendedParamss         r  fetch_open_orderszmodetrade.fetch_open_orders  sH    $ 	Vh-EFF  ~FFFr  c                     |                                   |                     |ddi          }|                     ||||          S )r  r  rR  r  r  s         r  fetch_closed_orderszmodetrade.fetch_closed_orders  sH    $ 	Vh-DEE  ~FFFr  c                 D   |                                   d}||                     |          }d|i}|                     |                     ||                    }|                     |di           }	|                     |	dg           }
|                     |
||||          S )aE  
        fetch all the trades made from a single order

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-all-trades-of-specific-order

        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Nr  r  rR  )r  r%  v1PrivateGetOrderOidTradesr  r  rT  r  )r
  r+   r'  r  r   r  r%  r  r  r  r   s              r  fetch_order_tradeszmodetrade.fetch_order_trades  s     	[[((F2
 224;;w3O3OPP, ~~h33fb11  vFFFr  c           	      $   |                                   d}|                     |dd          \  }}|r|                     d||||dd          S i }d}| |                     |          }|d         |d<   |||d	<   |||d
<   nd|d
<   |                     d||          \  }}|                     |                     ||                    }|                     |di           }	|                     |	dg           }
| 	                    |
||||          S )a  

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-trades

        fetch all trades made by the user
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: set to True if you want to fetch trades with pagination
        :param int params['until']: timestamp in ms of the latest trade to fetch
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Frn   r  r  r   Nr+   r'  r  r  r  r  rR  )
r  r  r  r%  r  v1PrivateGetTradesr  r  rT  r  )r
  r'  r  r   r  r  r  r%  r  r  r   s              r  fetch_my_tradeszmodetrade.fetch_my_trades-  sC    	88R\]]& 	u88&RWY^`fhnpsttt[[((F &tGH!&GI#GFOO!GFO227GVLL**4;;w+G+GHH6 ~~h33fb11  vFFFr  c                    d|i}|                      |dg           }t          dt          |                    D ]~}||         }|                     |                     |d                    }|                                 }|                     |d          |d<   |                     |d          |d<   |||<   |                     |          S )Nr  holdingr   rX  totalfrozenused)rT  rd  re  rK  r  accountsafe_balance)r
  r  ri  balancesrk  balancera  r  s           r  parse_balancezmodetrade.parse_balancek  s    H
 >>(Ir::q#h--(( 	# 	#AqkG**4+;+;GW+M+MNNDllnnG#//CCGG"..wAAGFO"F4LL  (((r  c                     |                                   |                     |          }|                     |d          }|                     |          S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-current-holding

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
        r  )r  v1PrivateGetClientHoldingr  r  r
  r  r  r  s       r  fetch_balancezmodetrade.fetch_balancey  sR     	11&99  ~~h//!!$'''r  ra  c                    |                                   i }d }| |                     |          }|d         |d<   |||d<   |||d<   |                     |d          }|                     |d          }|||d<   |                     |                     ||                    }|                     |di           }	||                     |	dg           gS )Nr+   balance_tokenr  pageSizer2  r  rR  )r  rt  r  r  v1PrivateGetAssetHistoryr  r  rT  )
r
  ra  r  r   r  r  rt  transactionTyper  r  s
             r  get_asset_history_rowsz modetrade.get_asset_history_rows  s    !}}T**H'/~GO$!&GI"'GJ**66::66**&-GFO00Wf1M1MNN4 ~~h33$..vr::;;r  ru  rt  c                    |                      |d          }|                     ||          }|                     ||          }|                     |d          }|                      |d          }|dk    rdnd}|                     |d          }|                     |dd	          }	|                     |                      |d
          ||                      |d          d |                      |d          |                     |                      |d                    |d d |	|||                     |          | 	                    |                      |d                    |d|          S )NrX  r8  
token_sideDEPOSITinoutrA  	fee_token
fee_amountr+   r  tx_idr  r2  )r+   rt  r  referenceAccountreferenceIdr  r8  beforeafterr_  	directionr"  r  r2  r  )
r  rK  safe_currencyrL  r#  r{  safe_ledger_entryparse_transaction_statusr  parse_ledger_entry_type)
r
  ru  rt  rl  ra  r8  r  r  r"  r_  s
             r  parse_ledger_entryzmodetrade.parse_ledger_entry  sv   %%dG44
&&z8<<%%j(;;!!$11l33!Y..DDU	%%dN;;	++D+|LL%%""4..''i88 $++D'::33D4D4DT84T4TUU""Y//001A1A$1O1OPP'
 '
  !  	r  c                 :    ddd}|                      |||          S )Ntransactionr   )BALANCE
COLLATERALr  rY  s      r  r  z!modetrade.parse_ledger_entry_type  s.    $$
 
 tT222r  c                     |                      ||||          }|                     |d          }|                     |d          }|                     |||||          S )a  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-asset-history

        :param str [code]: unified currency code, default is None
        :param int [since]: timestamp in ms of the earliest ledger entry, default is None
        :param int [limit]: max number of ledger entries to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ledger structure <https://docs.ccxt.com/?id=ledger-entry-structure>`
        r   r   )r  r4  rT  parse_ledger)r
  ra  r  r   r  currencyRowsrt  rR  s           r  fetch_ledgerzmodetrade.fetch_ledger  s_     224vNN??<33~~lA..  xvFFFr  r  c                    |                      |d          }|                     |d          }|dk    r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S ) NrX  r  r   
withdrawalr  r  target_addresssource_addressrA  r  r+   withdraw_idtxidr  r"  r  addressaddressFrom	addressTotagextratagFromtagTor2  r8  rt  r  r  r  comment)internalr_  r^  )r  r  r{  r#  r0  r  rL  r  )	r
  r  rt  ra  movementDirectionr_  r  r  r"  s	            r  parse_transactionzmodetrade.parse_transaction  s    W55 22;MM
** ,++KlSS$$[2BCC	&&{4DEE%%k>BB	
K
$$$[$FF
 D$$['::
 	

 Y//
 t
 ;
 
 4##K99
 t
 T
 %
 d&&{H==
 
 d33D4D4D[RZ4[4[\\
  t((nEE!
" t#
$ )
 
 
 	
r  c                 @    dddddd}|                      |||          S )Npendingr  rJ  )r  
CONFIRMING
PROCESSINGrR  CANCELEDr  rS  s      r  r  z"modetrade.parse_transaction_status	  s7    ##"
 
 &&999r  c           	      b    ddi}|                      ||||                     ||                    S )a'  
        fetch all deposits made to an account

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-asset-history

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        r  r  fetch_deposits_withdrawalsr  r
  ra  r  r   r  r  s         r  fetch_depositszmodetrade.fetch_deposits 	  s;     I
 ..tUE4;;wX^C_C_```r  c           	      b    ddi}|                      ||||                     ||                    S )a2  
        fetch all withdrawals made from an account

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-asset-history

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        r  WITHDRAWr	  r  s         r  fetch_withdrawalszmodetrade.fetch_withdrawals1	  s;     J
 ..tUE4;;wX^C_C_```r  c           	          i }|                      ||||                     ||                    }|                     |d          }|                     |d          }|                     |||||          S )a  
        fetch history of deposits and withdrawals

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-asset-history

        :param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
        :param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
        :param int [limit]: max number of deposit/withdrawals to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `transaction structure <https://docs.ccxt.com/?id=transaction-structure>`
        r   r   )r  r  r4  rT  parse_transactions)	r
  ra  r  r   r  r  r  rt  rR  s	            r  r
  z$modetrade.fetch_deposits_withdrawalsB	  sv     224t{{SZ\bGcGcdd??<33~~lA.. &&tXueVLLLr  c                     |                      |          }|                     |di           }|                     |d          S )Nr  r   )v1PrivateGetWithdrawNoncer  rL  r  s       r  get_withdraw_noncezmodetrade.get_withdraw_nonce_	  sC    11&99 ~~h33&6777r  c                 6    d|                      |dd          z   S )N0xkeccakhex)hash)r
  messages     r  hash_messagezmodetrade.hash_messagem	  s    dii59999r  c                 6   |                      |dd          |dd          dd           }|d         }|d         }|                     |                     d|d                             }d|                    dd	          z   |                    dd	          z   |z   S )
N	secp256k1rs   vr  @   r  )ecdsaint_to_base16sumrjust)r
  r  r   	signaturer  r   r"  s          r  	sign_hashzmodetrade.sign_hashp	  s    JJtCDDz:cdd+;[$OO	cNcNtxxIcN;;<<aggb#&&&S)9)99A==r  c                 d    |                      |                     |          |dd                    S )Nr  )r)  r  )r
  r  r   s      r  sign_messagezmodetrade.sign_messagew	  s-    ~~d//88*STT:JKKKr  r  r  c           
      r   |                                   |                     |           |1|                                }|dk    rt          | j        dz             |                     |          }|                     | j        d          }|                     |d          }|                     |di           }	|                     |	|i           }
| 	                    |
d          }|t          | j        dz             |                     |          }|                                 }|d	|d
d}ddddddddddddddddddddddgi}|                     | j        dd          |                     |          ||t          |          ||d}|                     |||          }|                     || j                  }||||d}|                     |d          }|                     |                     ||                    }|                     |di           }|                     ||          S )a  
        make a withdrawal

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/create-withdraw-request

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/?id=transaction-structure>`
        Nr  z withdraw() only support USDCr   chainIdrb  r+   z% withdraw() require chainId parameterOrderlyr5  )r-  r,   verifyingContractr1   Withdrawr   string)r,   r2  uint256receiverr  rX  r8  withdrawNonceuint64r"  keyBrokerIdmode)r   r-  r3  rX  r8  r4  r"  )r(  userAddressr/  r  r  )r  check_addressrk  r"   r+   rt  r  r   r  rL  r   r  nonceparse_to_intstreth_encode_structured_datar+  r   r  v1PrivatePostWithdrawRequestr  r  )r
  ra  r8  r  r  r  rt  r   r-  currencyNetworkscoinNetworkcoinNetworkIdr4  r:  domainmessageTypeswithdrawRequestmsgr(  r  r  r  s                         r  r   zmodetrade.withdrawz	  s    	7###::<<Dv~~"47-L#LMMM==&&#'#3#3DLB\#]#] ""6955>>(JCCnn%5wCC((d;; TW'NNOOO//77

!9	
 
 #X66"I66#Y77 (33!955((;;$h77

 ((}fMM((11&kk*!
 !
 --flOTT%%c4?;;	""!9&	
 
 69--44T[[&5Q5QRR ~~h33%%dH555r  c                 J    |                      |d          }||d         d ||dS )Nmax_leverager'  )r  r'  r   longLeverageshortLeverage)r#  )r
  r   r%  leverageValues       r  parse_leveragezmodetrade.parse_leverage	  s:    ))(NCCX&)*
 
 	
r  c                     |                                   |                     |          }|                     |          }|                     |di           }|                     ||          S )a  
        fetch the set leverage for a market

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-account-information

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `leverage structure <https://docs.ccxt.com/?id=leverage-structure>`
        r  )r  r%  r  r  rK  )r
  r'  r  r%  r  r  s         r  fetch_leveragezmodetrade.fetch_leverage	  sg     	V$$..v668 ~~h33""4000r  r   c                     |                                   |dk     }|dk    }|s|rt          | j        dz             d|i}|                     |                     ||                    S )a  
        set the level of leverage for a market

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/update-leverage-setting

        :param int [leverage]: the rate of leverage
        :param str [symbol]: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        r   2   z$ leverage should be between 1 and 50r   )r  r   r+   v1PrivatePostClientLeverager  )r
  r   r'  r  isMinLeverageisMaxLeverager  s          r  set_leveragezmodetrade.set_leverage	  s     	 1 2 	OM 	OTW'MMNNN
 //GV0L0LMMMr  positionc                    |                      |d          }|                     ||          }|                      |d          }d }t          j        |d          rd}nd}|                      |d          }|                      |d          }|                     |d          }|                      |d	          }	|                      |d
          }
t          j        |          }t          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 d d          S )Nr'  position_qtyr  longshortrB  
mark_pricer"  average_open_priceunsettled_pnlr  r+   r  r&  initialMargininitialMarginPercentagemaintenanceMarginmaintenanceMarginPercentage
entryPricenotionalr   unrealizedPnl	contractsmarginRatioest_liq_pricecross)liquidationPricer  	lastPrice
collateralr   
marginTyper  r   r   r   r   )r  r  r&   	string_gtr#  
string_absr  safe_positionr  r	  rL  )r
  rT  r%  r4  r  r  rB  r  r"  r`  unrealisedPnlra  s               r  parse_positionzmodetrade.parse_position
  s   . ##Hh77!!(F33.99T3'' 	DDD''??$$X|<<	%%h<<	%%h0DEE
((?CC!$''%dI66!! #
H#
$#
 d&&vx88#
 	#

 Y//#
 "4#
 T#
 &t#
  #
 *4#
 $++J77#
 ))(33#
 #
 T..}==#
 **400#
  D--l;;!#
" 4##
$ !% 0 0? K K**955!!#9#
 #
 #
   	r  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d          }|                     ||          S )a  

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-one-position-info

        fetch data on an open position
        :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
        :returns dict: a `position structure <https://docs.ccxt.com/?id=position-structure>`
        r'  r+   r  )r  r%  v1PrivateGetPositionSymbolr  r  ro  r  s          r  fetch_positionzmodetrade.fetch_positionV
  s     	V$$fTl
 224;;w3O3OPP6 ~~h//""4000r  c                     |                                   |                     |          }|                     |di           }|                     |dg           }|                     ||          S )a  
        fetch all open positions

        https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-all-positions-info

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/?id=position-structure>`
        r  rR  )r  v1PrivateGetPositionsr  rT  parse_positions)r
  r  r  r  ri  r   s         r  fetch_positionszmodetrade.fetch_positions
  sl     	--f55N &"55NN66266	##Iw777r  c                 *    |                                  S N)milliseconds)r
  s    r  r:  zmodetrade.nonce
  s      """r  r   GETc                 >   |d         }|d         }|                      ||          }	|                     | j        d         |                   }
|
d|z   dz   z  }
|                     ||                     |                    }|                     |          }|dk    r$|
|	z  }
|r|
d|                     |          z   z  }
nX|                                  |dk    p|dk    }|d	k    p|d
k    p|dk    }|r|r|                     | j	        dd          }|sp| 
                    | j	        dd          }|dk    rI|                     |dg           }t          dt          |                    D ]}||d         |         d<   n||d<   |                     |          }d}t          |                                           }|
|	z  }
| j        }|                    d          dk     rd|z   }| j        ||d}||z   dz   |z   dz   |	z   }|dk    s|dk    r |                     |          }||z  }d|d<   nE|r6|
d|                     |          z   z  }
|d|                     |          z   z  }d|d<   |dk    rd}| j        }|                    d          dk    r|                    d          }|d         }|                     |                     |          |                     |          d          }|                     |                     |                    |d<   |
|||dS )Nr   r   r   r*  r   ?POSTPUTr   r   r   r   Fr   r   r   	order_tag zed25519:)zorderly-account-idzorderly-keyzorderly-timestampzapplication/jsonzcontent-typez!application/x-www-form-urlencodedDELETEed25519zorderly-signature)r   methodbodyheaders)implode_paramsimplode_hostnamer   r  extract_paramskeysort	urlencodecheck_required_credentialsr3  r   r  rT  rd  re  r<  r:  r   findr   json	rawencoder   rJ  eddsaencodebase58_to_binaryurlencode_base64base64_to_binary)r
  pathsectionr  r  r  r  r1   accesspathWithParamsr   isPostOrPutisOrderisSandboxModer   
ordersListrk  authtsr   r   rN  r(  s                          r  signzmodetrade.sign
  s   !*,,T6::##DIe$4V$<==sW}s""64#6#6t#<#<==f%%X>!C 4sT^^F3333++--- F*=foKl*VdgoVAVG 
.w 
. $t|]E R R$ 7#//j*UUH},,%)^^FHb%I%I
!&q#j//!:!: H HA?GF8,Q/<<H /7{+f--DTZZ\\""B>!C[F{{:&&**#f,&*n%%' G
 ;$w.4~ED6U??yy((*<'' 93!7!777CC$.."8"888D*M'X%%D[F{{:&&!++Z00q

4;;t#4#4d6K6KF6S6SU^__I+/+@+@AVAVW`AaAa+b+bG'(fdwOOOr  httpCodereasonr   r  r  r  c
                 P   |sd S |                      |d          }
|                     |d          }|
ss| j        dz   |                     |          z   }|                     | j        d         ||           |                     | j        d         ||           t          |          d S )Nr  ra   r  r  )r3  r  r+   r  throw_broadly_matched_exceptionr  throw_exactly_matched_exceptionr   )r
  r  r  r   r  r  r  r  requestHeadersrequestBodyr  	errorCodefeedbacks                r  handle_errorszmodetrade.handle_errors
  s     	4
 ..955$$Xv66	 	*w}tyy':'::H001I4QYZZZ001I9V^___)))tr  rx  )a__name__
__module____qualname__r   r  boolr  r   r	   r$  dictr   rP  r   rV  r   rq  r{  r   r  r<  r  r   r  r  r  r  r   r   r  r   r  r  r  r   r  r   r  listr  r  r   rB  r9  r7  r8  r   r   floatr   rz  r~  r   r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r   r
   r  r  r  r   r  r  r  r  r
  r  r  r)  r+  r   r   rK  rM  intrS  ro  rr  r   rv  r:  r  r  __classcell__)r  s   @r  r(   r(      s       P# P P P P P Pd-t - - - - - - #% "
 "
 "
 "
H !# 8 8s 8 8 8 8,V
4 V
F V
 V
 V
 V
p $& /( /($v, /( /( /( /(b ') [ [Z [ [ [ [z
 
 
= = =v = = = = =~ 6:UW %= %=3 %=s %=# %=\`af\g %= %= %= %=N'
 '
f '
 '
 '
 '
 '
R? ? ? :< 
7 
7S 
7 
7 
7 
7 
7 68  5  5  5K  5  5  5  5D 6:"  7  77  7  7  7  7  7D 8<$]ajl >O >O >OC >OWZ >O >O >O >O@
 
6 
 
 
 
@ 37TX\eg 9> 9>C 9>s 9>RU 9> 9> 9> 9>v )+ 4 4{ 4 4 4 4l :>b 'c 'cs 'c3 'cY 'c 'c 'c 'cR
 
 
4 
 
 
 
 9=4^bkm ,H ,H# ,H# ,HS ,HX[ ,Hrvw{r| ,H ,H ,H ,H\n n nv n n n n n`As A A A A     9S 9 9 9 9 os{} W, W,3 W,i W,y W,Z_ W,hk W, W, W, W,r gksu B B3 Bi By BRW B`c B B B BH @B 3' 3'D$6 3' 3' 3' 3'j `drv  @B G. G.S G.# G.Y G.i G.Y\ G.lo G. G. G. G.R 37r FA FAs FAC FA FA FA FAP ;?r # #c #C # # # #J /32 +
 +
 +
 +
 +
 +
Z 26b C0 C0c C03 C0 C0 C0 C0J *.Dt\^ Q? Q?3 Q?c Q? Q?cghmcn Q? Q? Q? Q?f /3TXac G G G3 Gc Ghlmrhs G G G G, 154VZce G G# GS GPS Gjnotju G G G G, 9=4^bkm ,G ,GS ,G# ,GS ,GX[ ,G ,G ,G ,G\ -1tRV_a <G <Gc <G <GC <G <G <G <G|) ) ) ) ) $& ( (( ( ( ( (: 26DW[df *< *<3 *<c *<QT *<kn *< *< *< *<X t x ;    63 3 3 (,$TZ\ G G GC Gs Gaefqar G G G G"
 
T 
X 
Q\ 
 
 
 
B:s : : : : *.Dt\^ a a3 ac a acghsct a a a a" -1tRV_a a ac a aC afjkvfw a a a a" 6:[_hj M Ms M# MUX Most  pA M M M M: )+ 8 8 8 8: : :> > >L L L KOWY K6 K6S K6% K6# K6C K6^i K6 K6 K6 K6Z
 
x 
 
 
 
 24 )1 )1S )1 )1 )1 )1 )1V 9=R N NS N# N N N N*C Ct CV C C C CJ 24 +1 +1S +1 +1 +1 +1Z 26b 48 48w 48T(^ 48 48 48 48l# # # "*%DW[ 8P 8P 8P 8Ptc 3 S # X\ dg        r  r(   N),ccxt.base.exchanger   ccxt.abstract.modetrader   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   r   r    r!   r"   r#   r$   ccxt.base.decimal_to_precisionr%   ccxt.base.preciser&   r(    r  r  <module>r     sc   ( ' ' ' ' ' / / / / / / s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s       * * * * * * 0 0 0 0 0 0 . . . . . . ' ' ' ' ' ' . . . . . . ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) . . . . . . 4 4 4 4 4 4 % % % % % %m+ m+ m+ m+ m++ m+ m+ m+ m+ m+r  