
    E#i                    $   S SK Jr  S SKJr  S SKJrJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJr  S SKJr  S SKJr  S SKJr  S SKJ r   S SKJ!r!  S S	KJ"r"  S S
KJ#r#  S SKJ$r$  S SKJ%r%  S SKJ&r&  S SK'J(r(  S SK)J*r*   " S S\\5      r+g)    )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                   |  ^  \ rS rSrS\4U 4S jjrS\4U 4S jjr0 4S jr0 4S\	4S jjr
S\S\4S	 jr0 4S\\   4S
 jjr0 4S\4S jjrS rShS\S\S\4S jjrSS0 4S\S\	S\	S\\   4S jjrShS\S\4S jjrS r0 4S\S\4S jjr0 4S\S\4S jjrS0 4S\S\4S jjrSSS0 4S\S\	S\	4S jjr ShS\4S jjr!SSS0 4S\S\	S\	4S jjr"0 4S\#4S jjr$S0 4S\S\	S\%4S jjr&ShS\S\'4S jjr(S SS0 4S\S!\S\	S\	S\\'   4
S" jjr)ShS#\S\S\*4S$ jjr+S%\4S& jr,S'\4S( jr-S)\4S* jr.S0 4S\S)\/S+\0S,\1S-\24
S. jjr3S0 4S\S)\/S+\0S,\1S-\24
S/ jjr40 4S0\\5   4S1 jjr6SS0 4S2\S\S)\/S+\0S,\2S-\24S3 jjr7S0 4S2\S\4S4 jjr8S0 4S5\\   S\4S6 jjr9S0 4S\4S7 jjr:S0 4S2\S\4S8 jjr;SSS0 4S\S\	S\	S\\*   4S9 jjr<SSS0 4S\S\	S\	S\\*   4S: jjr=SSS0 4S\S\	S\	S\\*   4S; jjr>SSS0 4S2\S\S\	S\	4S< jjr?SSS0 4S\S\	S\	4S= jjr@S\A4S> jrB0 4S\A4S? jjrCSSS0 4S@\S\	S\	S\4SA jjrDShSB\SC\ES\F4SD jjrGSE rHSSS0 4S@\S\	S\	S\\F   4SF jjrIShSG\SC\ES\J4SH jjrKS'\4SI jrLSSS0 4S@\S\	S\	S\\J   4SJ jjrMSSS0 4S@\S\	S\	S\\J   4SK jjrNSSS0 4S@\S\	S\	S\\J   4SL jjrO0 4SM jrPSN rQSO rRSP rSS0 4S@\S,\1SQ\SR\S\J4
SS jjrTShS\U4ST jjrV0 4S\S\U4SU jjrWS0 4SV\XS\4SW jjrYShSX\S\4SY jjrZ0 4S\4SZ jjr[S0 4S\S\\\   4S[ jjr]S\ r^S]S^0 SS4S_ jr_S`\XSa\Sb\Sc\Sd\Se\4Sf jr`SgraU =rb$ )i	modetrade   returnc                   > U R                  [        [        U ]  5       0 SS_SS_SS/_SS_S	S
_SS_SS_SS_SS_S0 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 S$S_S%S_S&S_S'S_S(S_S)S_S*S_S+S_S,S_S-S_S.S_S/S_S0S_S1S_S2S_S3S_S4S_E0 S5S_S6S_S7S_S8S_S9S_S:S_S;S_S<S_S=S_S>S_S?S_S@S_SAS_SBS_SCS_SDS_SES_E0 SFS_SGS_SHS_SIS_SJS_SKS_SLS_SMS_SNS_SOS_SPS_SQS_SRS_SSS_STS_SUS_SVS_ESSSSSSSWSSSSSSSSSX.E_SYSZS[S\S]S^S_S`SaSbScSdSe._SfSgShShSi.SjSjSi.SkSlSmSn.So._SpS
0 SqSr_SsSr_StSr_SuSr_SvSr_SwSr_SxSr_SySr_SzSr_S{Sr_S|Sr_S}Sr_S~Sr_SSr_SSr_SS_SS_0 SS_SS_SS_SSr_SSr_SSr_SSr_SSr_SSr_SSr_SSr_SSr_SSr_SSr_SSr_SSr_SSr_ESrSrSrSrSSrSrSrSrSrSrSrS.ESSr0S.0 SS_SS_SSr_SSr_SSr_SSr_SSr_SSr_SSr_SSr_SSr_SSr_SSr_SS_SSr_SSr_SSr_0 SSr_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSr_SSr_E0 SSr_SS_SS_SSr_SS_SSr_SSr_SSr_SSr_SSr_SS_SS_SS_SS_SS_SS_SS_SSSSSSSSS.ESrSrS.SrSrSrSrSrSrSrSrS.S.Si.0_SSSSSS._SSSSU R	                  S5      U R	                  S5      S.0_SSSSS._SSSSS SSSS SSSSS.SSSSSSSS.SS0SSS SSS.SSSSS.SSSSSS.S SSS S SSSSS.SS0S.	SS0SS S SS.S.S.SS0S S.S S S.S._0 0 S[
        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _GS [        _GS[        _GS[        _GS[        _GS[        _[        [        [        [        [        [        [        GS.E0 GS.[        GS.E5      $ (  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     )	sandboxrL   createOrdersro   rt   rs   rv   r[   rp   extendsdefault)r   price)r   r   )r   rL   forDerivatives)linearinverse)r   r:   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    V/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/async_support/modetrade.pyr	  modetrade.describe   s}   i ? 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$ ,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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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J  % %!##($(%/"'$( %#"#(! g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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DFyOD
F "!#	$GOD
R !%"&!..x8!..x8	SOD
b $&,XcOD
l #&+(,,0,1).+06:#'#'"&#(	( #($($(+027/4#')$. r% ',!$$(%+*/& ',#'$)*/	# ',!$#'$)*/( $(&+!$$(,0%+#'$)*/	*  #u=~ y  ) -1 15%*7$# "#3  $	 ##iXmOD
^ !#]0 0 .	
 Z Z \ Z \ . \ Z . \ \  \!" \#$ ('$,,#$147< ']OD
 O O	    enablec                 H   > [         [        U ]  U5        XR                  S'   g )Nr   )r  r(   set_sandbox_moder   )r  r  r  s     r  r  modetrade.set_sandbox_mode  s    i/7&,]#r  c                    #    U R                  U5      I Sh  vN nU R                  US0 5      nU R                  US5      nUc  SnOUS:X  a  SnOSnUSSSUS.$  NB7f)	aT  
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>`
Ndatastatuserror0okmaintenance)r  updatedetar   info)v1PublicGetPublicSystemInfo	safe_dictsafe_string)r  paramsresponser  r  s        r  fetch_statusmodetrade.fetch_status  sz      99&AA ~~h3!!$1>Fs]F"F
 	
' Bs   AAAAc                 d   #    U R                  U5      I Sh  vN nU R                  US5      $  N7f)aW  
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
N	timestamp)r  safe_integer)r  r!  r"  s      r  
fetch_timemodetrade.fetch_time  s5      99&AA   ;77 Bs   0.0marketc                    U R                  US5      nUR                  S5      nSnU R                  US5      nU R                  US5      nU R                  U5      nU R                  U5      nU R                  US5      n	U R                  U	5      n
US-   U-   S-   U
-   n0 SU_SU_S	U_S
U_SU
_SU_SU_SU	_SU_SS_SS_SS_SS_SS_SS _SS_SS_SU R                  S5      S S S S U R	                  US5      U R	                  US5      S.S S S.U R	                  US5      U R	                  US5      S.U R	                  US 5      U R	                  US!5      S.U R	                  US"5      S S.S#.U R                  US$5      US%.
E$ )&Nsymbol_r<   r      /:r,   basequotesettlebaseIdquoteIdsettleIdtyper:   Fr;   Tr=   r>   activecontractr   1	base_tick
quote_tick)amountr   minr   base_minbase_max	quote_min	quote_maxmin_notional)r   r=  r   costcreated_time)
r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedr  )r   splitsafe_currency_coder
  safe_numberr'  )r  r*  marketIdparts
marketTyper4  r5  r1  r2  r6  r3  r,  s               r  parse_marketmodetrade.parse_market  sR   8 ##FH5s#
!!%+""5!,&&v.''0((2--h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"**6;?))&,?  
  ++FJ?++FJ?
  ++FK@++FK@
  ++FNC$ ((@_0
 0	
r  c                    #    U R                  U5      I Sh  vN nU R                  US0 5      nU R                  US/ 5      nU R                  U5      $  N;7f)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
Nr  rows)v1PublicGetPublicInfor  	safe_listparse_markets)r  r!  r"  r  rX  s        r  fetch_marketsmodetrade.fetch_marketsA  sX      33F;;H ~~h3~~dFB/!!$''M <s   AA<Ac                 *  #    0 nU R                  U5      I Sh  vN nU R                  US0 5      nU R                  US/ 5      n[        S[	        U5      5       GH0  nXV   nU R                  US5      nU R                  US5      n	U R                  U5      n
Sn0 n[        S[	        U	5      5       H  nX   nU R                  US5      nU R                  U R                  US5      5      nUb  Uc  UO[        R                  " UU5      nUUSSS	.SSS	.S
.SSSU R                  US5      U R                  U5      US.	X'   M     U R                  UUU
U R                  U5      SSUSSSSS	.U R                  US5      SS	.S.US.5      X*'   GM3     U$  GNw7f)a  
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
Nr  rX  r   tokenchain_detailschain_iddecimalsr>  )r   depositwithdrawal_fee)	r,   networkrM  r8  rc  r   feerL  r  minimum_withdraw_amount)rc  r   )r,   r-   coderL  r8  rf  networksrc  r   rM  r  )v1PublicGetPublicTokenr  rZ  rangelenr   rP  parse_precisionr&   
string_minrQ  r
  safe_currency_structure)r  r!  resultr"  r  	tokenRowsir_  
currencyIdri  rh  minPrecisionresultingNetworksjre  	networkIdrL  s                    r  fetch_currenciesmodetrade.fetch_currenciesr  s     44V<<. ~~h3NN44	q#i.)ALE))%9J~~e_=H**:6DL&(1c(m,"+ ,,WjA	 001A1A':1VW	(1=1E9GL^L^_hjvLwL#( $(#'%
 $(#'$	 ## $++G5EF!%!2!29!=#%0!, -6  77 "!..|<-   $# 
  $//7PQ#!	 )9 FLE *p c =s   FFE7Fc                     U R                  X5      nS nUb'  U R                  X5      nU R                  U5      nUUS.nU$ )NrE  currency)r   rP  )r  itemfeeTokenKeyfeeAmountKeyfeeCostrf  feeCurrencyIdfeeCurrencyCodes           r  parse_token_and_fee_temp"modetrade.parse_token_and_fee_temp  sQ    ""46 ,,T?M"55mDO+C 
r  Ntradec                 h   SU;   nU R                  US5      nU R                  US5      nU R                  XR5      nUS   nU R                  US5      nU R                  US5      nU R                  US5      n	U R                  USS5      n
U R                  U
S	5      nUb  XS	'   [        R
                  " Xx5      nU R                  US
5      nU R                  US5      nS nU(       a   U R                  US5      S:H  nU(       a  SOSnU R                  UUU R                  U5      UUUUUU	US U
US.U5      $ )Nr,   executed_timestampr,  executed_priceexecuted_quantityorder_id	fee_assetrf  rE  sideis_makerr:  r   r   )r,   r&  datetimer,  r  r   r=  rE  r   takerOrMakerr7  rf  r  )	r'  r   safe_marketr  r&   
string_mulsafe_string_lower
safe_tradeiso8601)r  r  r*  isFromFetchOrderr&  rR  r,  r   r=  r  rf  r  rE  r  r,   r  isMakers                    r  parse_trademodetrade.parse_trade  s_   8 !EM%%e-AB	##E84!!(3!  (89!!%)<=##E:6++E;F""3/!K!!%0%%eV4eT* &&uj9S@G&-77L"Y/( 
  	r  r,  sincer   c                 @  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nUb  X6S'   U R                  U R                  Xd5      5      I Sh  vN nU R	                  US0 5      nU R                  US/ 5      n	U R                  XX#5      $  N N>7f)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>`
Nr,  r,   r   r  rX  )load_marketsr*  v1PublicGetPublicMarketTradesextendr  rZ  parse_trades)
r  r,  r  r   r!  r*  requestr"  r  rX  s
             r  fetch_tradesmodetrade.fetch_trades  s      !!!V$fTl
 $G;;DKK<XYY  ~~h3~~dFB/  u<<3 	" Zs"   BBABB=BBc                 v   U R                  US5      nU R                  U5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n[        R                  " X5      n	0 SU_SUS   _SS _SS _SU R                  S	5      _S
S _SU_SU R                  U5      _SU R                  US5      _SU_SU R                  U5      _SS _SS _SS _SU R                  US5      _SU_SU R                  U5      _SU R                  U	5      0E$ )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  rQ  parse_funding_interval)
r  r  r*  r,  r  estFundingRateTimestamplastFundingRateTimestampfundingTimeStringnextFundingTimeStringmillisecondsIntervals
             r  parse_funding_ratemodetrade.parse_funding_rateA  s    !!+x8V$#00>QR"&"3"3KA]"^#'#4#4[B_#`  ,,[:WX $ 0 0>Q R&112G[
K
fX&
 
 $	

 D--c2
 #D
 0
 %<=
 4++K9KL
  4
 t||,@A
 t
 #D
 "4
 "4#3#3KAT#U
  '(@!
" &t||4L'M#
$ 334HI%
 	
r  c                 6    SSSSSS.nU R                  X!U5      $ )Nr   r   8h16h24h)360000014400000288000005760000086400000r   )r  r  	intervalss      r  r   modetrade.parse_funding_intervalj  s-    
	 	X>>r  c                 @   #    U R                  X5      I Sh  vN $  N7f)ao  
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>`
N)fetch_funding_rate)r  r,  r!  s      r  fetch_funding_interval modetrade.fetch_funding_intervalt  s      ,,V<<<<s   c                 
  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  US0 5      nU R                  Xc5      $  Nh N*7f)af  
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>`
Nr,  r,   r  )r  r*  "v1PublicGetPublicFundingRateSymbolr  r  r  r  r,  r!  r*  r  r"  r  s          r  r  modetrade.fetch_funding_rate  s      !!!V$fTl
 @@WA]^^  ~~h3&&t44- 	"
 _s!   BA??BB)BBsymbolsc                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  U5      I Sh  vN nU R                  US0 5      nU R	                  US/ 5      nU R                  XQ5      $  Ne N=7f)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>`
Nr  rX  )r  market_symbolsv1PublicGetPublicFundingRatesr  rZ  parse_funding_rates)r  r  r!  r"  r  rX  s         r  fetch_funding_ratesmodetrade.fetch_funding_rates  s{      !!!%%g.;;FCC$ ~~h3~~dFB/''66- 	"Cs!   B A<)B  A><B >B c           
      :  #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX4SS5      I Sh  vN $ 0 nUb  U R                  U5      nUS   nUS   US'   Ub  X&S	'   U R	                  S
XdS5      u  pdU R                  U R                  Xd5      5      I Sh  vN nU R                  US0 5      n	U R                  U	S/ 5      n
/ n[        S[        U
5      5       Hp  nX   nU R                  US5      nU R                  US5      nUR                  UU R                  U5      U R                  US5      UU R!                  U5      S.5        Mr     U R#                  US5      nU R%                  UXU5      $  GN} GNE N7f)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>`
NFrf   paginatepage   r,  r,   start_tend_tgMbP?r  rX  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  rZ  rk  rl  r   r'  appendsafe_symbolrQ  r  sort_byfilter_by_symbol_since_limit)r  r,  r  r   r!  r  r  r*  r"  r  rp  ratesrr  entryrR  r&  sorteds                    r  fetch_funding_rate_history$modetrade.fetch_funding_rate_history  s     !!!88AZ\fg>>?XZ`inx~  AC  D  D  D[[(FH%F &tGH!&I227GUSAA$++gB^__( ~~h3fb1q#f+&AIE''x8H))%1IJILL**84#//~F& LL3 	 ' e[100NNa 	" D `s5   FF:FFA&F8F9CFFFc           	         U R                  US5      nU R                  X25      nU R                  US5      nU R                  S5      nU R                  US5      nU R	                  US5      nU R                  US5      n	U	S:X  a  [
        R                  " U5      OUnUUUUU R                  U5      S U R                  U5      US.$ )	Nr,  funding_feeUSDCupdated_timer  payment_typePay)r  r,  rh  r&  r  r,   r=  rate)	r   r  rP  r'  rQ  r&   
string_negr  r
  )
r  incomer*  rR  r,  r=  rh  r&  r  paymentTypes
             r  parse_incomemodetrade.parse_income  s     ##FH5!!(3!!&-8&&v.%%fn=	7&&v~>0;u0D##F+6"Y/''/	
 		
r  c           	      H  #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX4SS5      I Sh  vN $ 0 nSnUb  U R                  U5      nUS   US'   Ub  X&S	'   U R	                  US
5      nU R                  US
/5      nUb  XS'   Ub  [        US5      US'   U R                  U R                  Xd5      5      I Sh  vN n	U R                  U	S0 5      n
U R                  U
S/ 5      nU R                  XX#5      $  GN N NA7f)a  
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>`
NFrb   r  r  r   r,   r,  r  untilr  sizer  rX  )r  r  r  r*  r'  omitr?  v1PrivateGetFundingFeeHistoryr  r  rZ  parse_incomes)r  r,  r  r   r!  r  r  r*  r  r"  r  rX  s               r  fetch_funding_historymodetrade.fetch_funding_history$  sL     !!!88AVXbc>>?TV\ejtz|  A  A  A[[(F &tGH!&I!!&'26G9-$G!%oGFO;;DKK<XYY0 ~~h3~~dFB/!!$==Y 	" A Zs4   D"D:D"DBD"D =D"D" D"c           
        #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  US0 5      nU R                  US5      nU R                  US5      n0 n[	        S[        U R                  5      5       He  nU R                  U   nUUU R                  [        R                  " US5      5      U R                  [        R                  " US5      5      SSS.Xh'   Mg     U$  N N7f)	aP  
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
Nr  futures_maker_fee_ratefutures_taker_fee_rater   10000T)r  r,  r   r   r   r   )
r  v1PrivateGetClientInfor  r   rk  rl  r  r
  r&   
string_div)	r  r!  r"  r  r   r   rp  rr  r,  s	            r  fetch_trading_feesmodetrade.fetch_trading_fees_  s      !!!44V<<8 ~~h3  '?@  '?@q#dll+,A\\!_F  **7+=+=eW+MN**7+=+=eW+MN"!FN - W 	"<s    C;C7C;C9CC;9C;c           	      ^  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nUb  [        US5      nX%S'   U R                  U R	                  XS5      5      I Sh  vN nU R                  US0 5      nU R                  US5      nU R                  XqUSS	S
S5      $  N NA7f)a  
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
Nr,  r,   r   	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_bookmodetrade.fetch_order_book  s      !!!V$fTl
 t$E#(K 99$++g:VWW$ ~~h3%%dK8	$$T9ffgWabb9 	" Xs#   B-B)AB-)B+*A B-+B-c           	          U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )Nstart_timestampopenhighlowclosevolume)r'  rQ  )r  ohlcvr*  s      r  parse_ohlcvmodetrade.parse_ohlcv  sm    e%67UF+UF+UE*UG,UH-
 	
r  r   	timeframec                   #    U R                  5       I Sh  vN   U R                  U5      nUS   U R                  U R                  X"5      S.nUb  [	        US5      US'   U R                  U R                  Xu5      5      I Sh  vN nU R                  US0 5      n	U R                  U	S/ 5      n
U R                  XX#U5      $  N N?7f)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
Nr,   )r,  r7  r   r   r  rX  )
r  r*  r   r   r?  v1PrivateGetKliner  r  rZ  parse_ohlcvs)r  r,  r  r  r   r!  r*  r  r"  r  rX  s              r  fetch_ohlcvmodetrade.fetch_ohlcv  s      !!!V$Tl$$T__iK
 "5$/GG//G0LMM~~h3* ~~dFB/  yGG? 	" Ns"   CCA,CC>CCr   c                    U R                  U/ SQ5      nU R                  U/ SQ5      nU R                  U R                  USS5      5      nU R	                  US5      nU R                  Xb5      nUS   nU R                  USS5      nU R                  USS	5      n	U R                  US
S5      n
U R                  USS5      nU R                  USS5      nU R                  US5      nUb  U(       a  SOSnU R                  US5      nU R                  U R                  USS5      5      nU R                  U R                  USS5      5      n[        R                  " X5      nU R                  USS5      nU R                  USS5      nU R                  US5      nU R                  US5      nS nS nU R                  US5      nUb~  U R                  US5      nU R                  US/ 5      n[        U5      nUS:  aH  U R                  US5      nU R                  US 5      nU R                  US5      nU R                  US5      nU R                  US!S"5      nU R!                  0 S#U_SU_S$U_S%U R#                  U5      _S&S _S'U_SU R%                  U5      _SU_SU R'                  U5      _S(U R)                  U5      _S)S _S*U R                  US+5      _SU_SU_SU_S,U_S-U_UU	UUU
UUUS..US/.EU5      $ )0N)r&  rF  createdTime)r  orderIdalgoOrderIdclient_order_idclientOrderIdr,  order_pricer   order_quantityr  order_amountr=  
order_typer7  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   r{  )averager=  filled	remainingrE  r   rf  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_valuerQ  rl  safe_integer_2
safe_orderr  parse_order_statusparse_order_typeparse_time_in_force)r  r   r*  r&  r&  r)  rR  r,  r   r=  rE  	orderTyper  r/  r  rB  rA  rC  rf  feeCurrencytransactionsr   r   r   r:  firstinnerChildOrdersinnerChildOrdersLengthtakeProfitOrderstopLossOrderr=  s                                  r  parse_ordermodetrade.parse_order  s   \ ''/[\	$$U,RSt'9'9%ARTc'de##E84!!(3!""5-A##E+;ZH!!%B,,UL&I	""5(LA..	2&UZF%%eV4 1 1%E\ ]^..!3!3E;SUk!lm&&t4	{J?((ZHun=''~>#!ooe];"OOK3E#umRH%()9%:"%)"&//2BA"F $0@! D"&"2"2?N"S $ 0 0 O"11%W  
' 
] 
  
 Y/	 

 !$ 
 "#6 
 d--f5 
 f 
 D)))4 
 433I> 
  
 $..> 
 D 
 U 
 L 
  ! 
" ]# 
$ ""' 9 
: ; 	r  r   c                 2    SSSS.nU R                  X!S 5      $ )Nr   r   r   )iocfok	post_onlyr  )r  r   timeInForcess      r  rP  modetrade.parse_time_in_forcef  s'    

 4@@r  r  c           
      H    Ub  SSSSSSSSSS.	nU R                  X!U5      $ U$ )Nr  closedcanceledrejected)	r0  FILLEDCANCEL_SENTCANCEL_ALL_SENT	CANCELLEDPARTIAL_FILLEDr1  
INCOMPLETE	COMPLETEDr  r  r  statusess      r  rN  modetrade.parse_order_statusn  sD    ")#-'"(&$%
H ##Hf==r  r7  c                 2    SSSS.nU R                  X!U5      $ )Nr   r*  )LIMITMARKET	POST_ONLY)r  r  r7  typess      r  rO  modetrade.parse_order_type~  s'     

 %%e488r  r  r=  r   c                 X   U R                  USS5      nUR                  5       nU R                  U5      n	UR                  5       n
U	S   U
S.nU R                  USS5      nU R	                  US5      nU R	                  US5      nU R                  US	5      nUS
L=(       d*    US
L=(       d    US
L=(       d    U R	                  US5      S
LnUS:H  nU R                  US5      nU R                  US
U5      nU(       a  SOSnU(       a  SOSnU(       a  SOSnXU'   U(       d$  U(       a  SUS'   OUS:X  a  SUS'   OUS:X  a  SUS'   U(       a  X{S'   Ub  U R                  X5      UU'   U(       a  U(       d  U R                  X5      UU'   OUS:w  a  U R                  X5      UU'   U R                  U/ SQ5      nUb  UUS'   Ub  U R                  X5      US'   SUS'   OUc  Ub  SUS'   U	S   S S/ S!.nUS"   nU
S#:X  a  S$OS#nUb=  U R                  USSU5      nUSU R                  UU5      S%S&S'.nUR                  U5        Ub=  U R                  USSU5      nUSU R                  UU5      S%S&S'.nUR                  U5        U/US"'   U R                  U/ S(Q5      nU R                  X5      $ ))aB  
@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
takeProfitalgoTypeNr:  rq  r   r  r+  r   r*  r7  r-  rr  r]  r   r\  r   POSITIONAL_TP_SLclOrdIDr)  r(  r(  trigger_priceSTOP	algo_typeTP_SLF)r,  r@  r  child_ordersr  BUYSELLrp  T)r  r  r~  r7  r@  )r?  r@  r}  r)  r(  r>  r   rw  r   rx  ry  )safe_bool_2upperr*  rG  rK  r   r  is_post_onlyprice_to_precisionamount_to_precisionrE  safe_number_2r  r  r  )r  r,  r7  r  r=  r   r!  r?  rQ  r*  	orderSider  r   rx  ry  rz  isConditionalisMarketr   r>  orderQtyKeypriceKeytypeKeyr)  outterOrderr:  	closeSider   rX  r   rW  s                                  r  create_order_requestmodetrade.create_order_request  s0    %%flMJ
JJL	V$JJL	Tl
 ))&.+N??6:6__V\:
##FJ7$D0  [HD4H  [J^bLb  [gkgvgvw}  @M  hN  VZ  hZ(,,V]C$$XtV<$1j7G+7)&|$(3%%(-%%(-%%/M" $ 7 7 FGHM#'#;#;F#KGK ++#'#;#;F#KGK **63bc$)6G%&#'+'>'>v'TGO$#)GK "
(>#*GK  ,$/ "	!K &n5K#,#5EI# $ 2 28^WV^ _%!(%)%<%<V]%S##'' ""=1%"&"4"4ZQXZd"e%!(%)%<%<V_%U##') ""?3'2mGN#6  $B  C{{7++r  c                 \  #    U R                  5       I Sh  vN   U R                  U5      nU R                  XX4XV5      nU R                  USS5      n	U R	                  US5      n
U R	                  US5      nU	SL=(       d*    U
SL=(       d    USL=(       d    U R	                  US5      SLnSnU(       a  U R                  U5      I Sh  vN nOU R                  U5      I Sh  vN nU R                  US5      nU R                  US5      US'   U R                  X5      nX/S	'   U$  GN N_ NG7f)
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>`
Nr   rw  rx  ry  r:  r  r&  r7  )
r  r*  r  rG  rK  v1PrivatePostAlgoOrderv1PrivatePostOrderr  r'  rY  )r  r,  r7  r  r=  r   r!  r*  r  r   rx  ry  r  r"  r  r   s                   r  create_ordermodetrade.create_order  sH    . !!!V$++F$V))&.+N??6:6__V\:
$D0  [HD4H  [J^bLb  [gkgvgvw}  @M  hN  VZ  hZ!88AAH "44W==H  ~~h/ --hD[  .fW 	" B >s5   D,D%B1D,D(	D,"D*#AD,(D,*D,r   c           	        #    U R                  5       I Sh  vN   / n[        S[        U5      5       GH$  nX   nU R                  US5      nU R                  US5      nU R                  US5      nU R	                  US5      n	U R	                  US5      n
U R                  US0 5      nU R                  US	S
5      nU R	                  US5      nU R	                  US5      nUSL=(       d*    USL=(       d    USL=(       d    U R	                  US5      SLnU(       a  [        U R                  S-   5      eU R                  XgXX5      nUR                  U5        GM'     SU0nU R                  U R                  UU5      5      I Sh  vN nU R                  US0 5      nU R                  US/ 5      nU R                  U5      $  GN N>7f)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>`
Nr   r,  r7  r  r=  r   r!  r   rw  rx  ry  r:  z+ createOrders() only support non-stop orderr   r  rX  )r  rk  rl  r   rK  r  rG  r"   r,   r  r  v1PrivatePostBatchOrderr  rZ  parse_orders)r  r   r!  ordersRequestsrr  rawOrderrR  r7  r  r=  r   orderParamsr   rx  ry  r  orderRequestr  r"  r  rX  s                        r  create_ordersmodetrade.create_orders!  s     !!!q#f+&AyH''(;H##Hf5D##Hf5D__Xx8FOOHg6E..8R@K--k>;WL{J?HlCJ(4  d8L  dPZbfPf  dkokzkz  |G  IV  lW  _c  lcM"477-Z#Z[[44XTSXfL!!,/ '" n
 55dkk'66RSS$ ~~h3~~dFB/  &&S 	"* Ts"   GF?E,GG<GGr,   c                 8  #    U R                  5       I Sh  vN   U R                  U5      nSU0n	U R                  U/ SQ5      n
U
b  U R                  X*5      U	S'   U
SL=(       d    U R	                  US5      SLnU(       a  SOSnU(       a  SOS	nUb  U R                  X&5      X'   Ub  U R                  X%5      X'   U R                  U/ S
Q5      nSnU(       a)  U R                  U R                  X5      5      I Sh  vN nOUS   U	S'   UR                  5       U	S'   UR                  5       nU R                  US5      nUS:H  nU R                  USU5      nU(       a  SU	S'   OUS:X  a  SU	S'   OUS:X  a  SU	S'   OXS'   U R                  U/ SQ5      nU R                  U/ SQ5      nUb  UU	S'   U R                  U R                  X5      5      I Sh  vN nU R                  US0 5      nU R                  US5      US'   U R                  UU5      $  GN GN ND7f)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>`
Nr  )r   rw  r   r   r   r:  r  r+  r   r*  )rw  r   r   r   trailingTriggerPricetrailingAmounttrailingPercentr,   r,  r  r   rq  rr  r-  r]  r   r\  r   r|  )r}  r)  r(  r>  r   r(  r  r&  )r  r*  rE  r  rK  r  r  v1PrivatePutAlgoOrderr  r  r  r  v1PrivatePutOrderr  r'  rY  )r  r,   r,  r7  r  r=  r   r!  r*  r  r   r  r  r  r"  rQ  r   r  r>  r)  r  s                        r  
edit_ordermodetrade.edit_orderV  s7    & !!!V$
 ))&2st#&*&=&=f&SGN#%T1jtv}7]ei7i$1j7G+7 $ 7 7 FG#'#;#;F#KG 6  $b  c!77G8TUUH &tGH"jjlGFO

I00GK H,H((4@H(3%%(-%%(-%(1% ..v7fgMYYv'qrF(-:)* "33DKK4PQQH ~~h3 --hD[f--i 	"$ V, Rs5   HHC%H<H=CHH?HHHc                 8  #    U R                  USSS5      nU R                  USS/5      nU(       d  Uc  [        U R                  S-   5      eU R	                  5       I Sh  vN   SnUb  U R                  U5      nSUS   0nU R                  USS	5      nU R                  US
U5      nUSLn	Sn
U(       au  U	(       aA  XS
'   U R                  U/ SQ5      nU R                  U R                  Xc5      5      I Sh  vN n
OXS'   U R                  U R                  Xc5      5      I Sh  vN n
OtU	(       aA  XS
'   U R                  U/ SQ5      nU R                  U R                  Xc5      5      I Sh  vN n
O,XS'   U R                  U R                  Xc5      5      I Sh  vN n
SU0nU	(       a  XS
'   OXS'   U(       a!  U R                  U R                  U
5      U5      $ U R                  U
S0 5      nU R                  U R                  U5      U5      $  GN GN N N N~7f)a  

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,   r}  r)  r(  r|  r  r  )r  r  r   r,   r  r*  rG  r   v1PrivateDeleteAlgoClientOrderr  v1PrivateDeleteAlgoOrderv1PrivateDeleteClientOrderv1PrivateDeleteOrderrY  r  )r  r,   r,  r!  r   r*  r  clientOrderIdUnifiedclientOrderIdExchangeSpecificisByClientOrderr"  extendParamsr  s                r  cancel_ordermodetrade.cancel_order  s      ""669eD6FI#67FN#DGG.Y$YZZ!!![[(FfTl
  $11&)_U(,(8(8ARTh(i%7tC-J)*6+Z[!%!D!DT[[QXEa!bb&(
#!%!>!>t{{7?[!\\-J)*6+Z[!%!@!@WA]!^^&(
#!%!:!:4;;w;W!XX  '/.K*+!#;;t//9<HH~~h3{{4++D1<@@e 	" c ]
 _ Ys]   AH H!BH7H8,H$H%AH,H-,HHA5HHHHHidsc                   #    U R                  5       I Sh  vN   U R                  U/ SQ5      nU R                  U/ SQ5      n0 nSnU(       a=  SR                  U5      US'   U R	                  U R                  XS5      5      I Sh  vN nO<SR                  U5      US'   U R                  U R                  XS5      5      I Sh  vN nU R                  SU05      /$  N NW N7f)aQ  
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>`
N)clOrdIDsclientOrderIdsclient_order_ids,r  	order_idsr  )r  safe_list_nr  joinv1PrivateDeleteClientBatchOrderr  v1PrivateDeleteBatchOrderrM  )r  r  r,  r!  r  r  r"  s          r  cancel_ordersmodetrade.cancel_orders  s      !!!))&2de6#UV*-((>*BG&'!AA$++gB^__H#&88C=GK !;;DKK<XYYH H!
   	) 	" ` Zs4   C!CA.C!C<C!CC!C!C!c                   #    U R                  5       I Sh  vN   U R                  USS5      nU R                  USS/5      n0 nUb  U R                  U5      nUS   US'   SnU(       a)  U R	                  U R                  XB5      5      I Sh  vN nO(U R                  U R                  XB5      5      I Sh  vN nU R                  SU05      /$  N NC N7f)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>`
Nr  r   r,   r,  r  )r  r  r  r*  v1PrivateDeleteAlgoOrdersr  v1PrivateDeleteOrdersrM  )r  r,  r!  r   r  r*  r"  s          r  cancel_all_ordersmodetrade.cancel_all_orders  s      !!!""669=6FI#67[[(F &tGH!;;DKK<XYYH!77G8TUUH" OO 
 	
7 	" ZUs4   CCA5CC(C5C6CCCc                   #    U R                  5       I Sh  vN   SnUb  U R                  U5      nU R                  USSS5      n0 nU R                  U/ SQ5      nU R	                  U/ SQ5      nSnU(       aa  U(       a-  XvS'   U R                  U R                  Xc5      5      I Sh  vN nOXS'   U R                  U R                  Xc5      5      I Sh  vN nO`U(       a-  XvS'   U R                  U R                  Xc5      5      I Sh  vN nO,XS'   U R                  U R                  Xc5      5      I Sh  vN nU R                  US	U5      n	U R                  X5      $  GNG N N N\ N17f)
aB  

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   Fr|  )r  r   r}  r)  r(  r(  oidr  )r  r*  r  rE  r  (v1PrivateGetAlgoClientOrderClientOrderIdr  v1PrivateGetAlgoOrderOid$v1PrivateGetClientOrderClientOrderIdv1PrivateGetOrderOidr  rY  )
r  r,   r,  r!  r*  r   r  r)  r"  r   s
             r  fetch_ordermodetrade.fetch_order9  sT      !!![[(F""669eD**63bc6#ef-:)*!%!N!Nt{{[bOk!ll!#!%!>!>t{{7?[!\\-:)*!%!J!J4;;W^Kg!hh!#!%!:!:4;;w;W!XX8 &(;//g 	" m ] i YsX   E(EBE(&E ',E(E"3E(E$,E(4E&5)E( E("E($E(&E(c           	        #    U R                  5       I Sh  vN   SnU R                  USSS5      nU(       a  SOSnU R                  USS5      u  pTU(       a  U R                  SXX4S	U5      I Sh  vN $ 0 nSn	U R	                  USS/5      nUb  U R                  U5      n	U	S
   US'   Ub  X(S'   Ub  X8S'   OXxS'   U(       a  SUS'   U R                  SX5      u  pSn
U(       a)  U R                  U R                  X5      5      I Sh  vN n
O(U R                  U R                  X5      5      I Sh  vN n
U R                  U
SU
5      nU R                  US5      nU R                  XX#5      $  GNW N Ni NB7f)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>`
NFr  r   r1   r   rv   r  r  r,   r,  r  r  r  r  r  r  rX  )r  r  r  r  r  r*  r  v1PrivateGetAlgoOrdersr  v1PrivateGetOrdersrK  rZ  r  )r  r,  r  r   r!  r  	isTriggermaxLimitr  r*  r"  r  r   s                r  fetch_ordersmodetrade.fetch_orders~  s    $ !!!$$VVYF	$3388PZ[>>}f]blrt|}}}6FI#67[[(F &tGH!&I#FO&FO#)GK 227GL!88W9UVVH!44T[[5QRRHF x:f-  >> 	" ~$ WRsG   E6E-AE60E01BE6E2	(E61E42<E60E62E64E6c                    #    U R                  5       I Sh  vN   U R                  USS05      nU R                  XX55      I Sh  vN $  N2 N7f)  
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>`
Nr  rj  r  r  r  r  r,  r  r   r!  extendedParamss         r  fetch_open_ordersmodetrade.fetch_open_orders  sL     $ !!!Vh-EF&&veLLL 	"L!   AA	-AAAAc                    #    U R                  5       I Sh  vN   U R                  USS05      nU R                  XX55      I Sh  vN $  N2 N7f)r  Nr  rk  r  r  s         r  fetch_closed_ordersmodetrade.fetch_closed_orders  sL     $ !!!Vh-DE&&veLLL 	"Lr  c                 8  #    U R                  5       I Sh  vN   SnUb  U R                  U5      nSU0nU R                  U R                  Xu5      5      I Sh  vN nU R	                  US0 5      n	U R                  U	S/ 5      n
U R                  XX4U5      $  N N?7f)a  
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  rX  )r  r*  v1PrivateGetOrderOidTradesr  r  rZ  r  )r  r,   r,  r  r   r!  r*  r  r"  r  r   s              r  fetch_order_tradesmodetrade.fetch_order_trades  s      !!![[(F2
 88W9UVV, ~~h3fb1  vFF? 	" Ws"   BBABB>BBc           	        #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX4SS5      I Sh  vN $ 0 nSnUb  U R                  U5      nUS   US'   Ub  X&S	'   Ub  X6S
'   OSUS
'   U R	                  SXd5      u  pdU R                  U R                  Xd5      5      I Sh  vN nU R                  US0 5      n	U R                  U	S/ 5      n
U R                  XX#U5      $  N N NA7f)at  

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>`
NFro   r  r  r   r,   r,  r  r  r  r  rX  )
r  r  r  r*  r  v1PrivateGetTradesr  r  rZ  r  )r  r,  r  r   r!  r  r  r*  r"  r  r   s              r  fetch_my_tradesmodetrade.fetch_my_trades+  s&     !!!88R\]>>PV_dntvyzzz[[(F &tGH!&I#FO!GFO227GL00W1MNN6 ~~h3fb1  vFF] 	" { Os4   DC?:DDA/DD>DDDc                 P   SU0nU R                  US/ 5      n[        S[        U5      5       Hf  nX4   nU R                  U R	                  US5      5      nU R                  5       nU R	                  US5      US'   U R	                  US5      US'   XrU'   Mh     U R                  U5      $ )Nr  holdingr   r_  totalfrozenused)rZ  rk  rl  rP  r   accountsafe_balance)r  r"  rp  balancesrr  balancerh  r  s           r  parse_balancemodetrade.parse_balancei  s    H
 >>(Ir:q#h-(AkG**4+;+;GW+MNDllnG#//CGG"..wAGFO"4L )   ((r  c                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  US5      nU R                  U5      $  N@ N)7f)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>`
Nr  )r  v1PrivateGetClientHoldingr  r  r  r!  r"  r  s       r  fetch_balancemodetrade.fetch_balancew  sW      !!!77??  ~~h/!!$''% 	"?s   AAAA(AArh  c                   #    U R                  5       I S h  vN   0 nS nUb  U R                  U5      nUS   US'   Ub  X%S'   Ub  X5S'   U R                  US5      nU R                  US5      nUb  XuS'   U R	                  U R                  XT5      5      I S h  vN nU R                  US0 5      n	X`R                  U	S/ 5      /$  N N-7f)Nr,   balance_tokenr  pageSizer7  r  rX  )r  r|  r   r  v1PrivateGetAssetHistoryr  r  rZ  )
r  rh  r  r   r!  r  r|  transactionTyper"  r  s
             r  get_asset_history_rows modetrade.get_asset_history_rows  s     !!!!}}T*H'/~GO$!&I"'J**66:66*&-FO66t{{77STT4 ~~h3..vr:;;S 	" Us"   CCB CC,CCr}  r|  c                 N   U R                  US5      nU R                  X25      nU R                  X25      nU R                  US5      nU R                  US5      nUS:X  a  SOSnU R	                  US5      nU R                  USS	5      n	U R                  U R                  US
5      UU R                  US5      S U R                  US5      U R                  U R                  US5      5      US S U	UUU R                  U5      U R                  U R                  US5      5      US.U5      $ )Nr_  r=  
token_sideDEPOSITinoutrF  	fee_token
fee_amountr,   r  tx_idr  r7  )r,   r|  r  referenceAccountreferenceIdr  r=  beforeafterrf  	directionr&  r  r7  r  )
r   rP  safe_currencyrQ  r'  r  safe_ledger_entryparse_transaction_statusr  parse_ledger_entry_type)
r  r}  r|  rs  rh  r=  r  r  r&  rf  s
             r  parse_ledger_entrymodetrade.parse_ledger_entry  s6   %%dG4
&&z<%%j;!!$1l3!Y.DU	%%dN;	++D+|L%%""4.''i8 $++D':33D4D4DT84TU""Y/001A1A$1OP'
  ! 	r  c                 0    SSS.nU R                  X!U5      $ )Ntransactionr   )BALANCE
COLLATERALr  rs  s      r  r  !modetrade.parse_ledger_entry_type  s$    $$
 T22r  c                    #    U R                  XX45      I Sh  vN nU R                  US5      nU R                  US5      nU R                  XvX#U5      $  N;7f)a3  
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>`
Nr   r   )r   rK  rZ  parse_ledger)r  rh  r  r   r!  currencyRowsr|  rX  s           r  fetch_ledgermodetrade.fetch_ledger  sW      "88eTT??<3~~lA.  vFF Us   AA<Ar  c                 `   U R                  US5      nU R                  US5      nUS:X  a  SnU R                  USS5      nU R                  US5      nU R                  US5      nU R                  US	5      n0 S
U_SU R	                  USS5      _SU R                  US5      _SU_SU R                  U5      _SS _SU_SU_SU R                  US5      _SS _SS _SU_SU R                  US5      _SU_SU R                  U R                  US5      5      _SU R                  US5      _SS _S US S.E$ ) Nr_  r  r   
withdrawalr  r  target_addresssource_addressrF  r  r,   withdraw_idtxidr	  r&  r  addressaddressFrom	addressTotagextratagFromtagTor7  r=  r|  r  r  r  comment)internalrf  re  )r   r  r  r'  rG  r  rQ  r  )	r  r  r|  rh  movementDirectionrf  r'  r&  r&  s	            r  parse_transactionmodetrade.parse_transaction  s   W5 22;M
* ,++KlS$$[2BC	&&{4DE%%k>B	
K
$$$[$F
 D$$[':
 	

 Y/
 t
 ;
 
 4##K9
 t
 T
 %
 d&&{H=
 
 d33D4D4D[RZ4[\
  t((nE!
" t#
$ )
 	
r  c                 6    SSSSSS.nU R                  X!U5      $ )Npendingr  rc  )r0  
CONFIRMING
PROCESSINGrk  CANCELEDr  rl  s      r  r  "modetrade.parse_transaction_status	  s-    ##"
 &99r  c           	      h   #    SS0nU R                  XX0R                  XT5      5      I Sh  vN $  N7f)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  Nfetch_deposits_withdrawalsr  r  rh  r  r   r!  r  s         r  fetch_depositsmodetrade.fetch_deposits	  s8      I
 44T%U\Ieffff   )202c           	      h   #    SS0nU R                  XX0R                  XT5      5      I Sh  vN $  N7f)a  
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  WITHDRAWNr8  r:  s         r  fetch_withdrawalsmodetrade.fetch_withdrawals/	  s8      J
 44T%U\Ieffffr=  c           	         #    0 nU R                  XX0R                  XT5      5      I Sh  vN nU R                  US5      nU R                  US5      nU R	                  XX#U5      $  N;7f)aF  
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>`
Nr   r   )r   r  rK  rZ  parse_transactions)	r  rh  r  r   r!  r  r  r|  rX  s	            r  r9  $modetrade.fetch_deposits_withdrawals@	  sh      !88e[[Y`Mijj??<3~~lA. &&tuVLL ks   'A'A%<A'c                    #    U R                  U5      I S h  vN nU R                  US0 5      nU R                  US5      $  N)7f)Nr  r   )v1PrivateGetWithdrawNoncer  rQ  r  s       r  get_withdraw_noncemodetrade.get_withdraw_nonce]	  sF     77?? ~~h3&677 @s   AA*Ac                 .    SU R                  USS5      -   $ )N0xkeccakhex)hash)r  messages     r  hash_messagemodetrade.hash_messagek	  s    dii5999r  c                     U R                  USS  USS  SS 5      nUS   nUS   nU R                  U R                  SUS   5      5      nSUR                  SS	5      -   UR                  SS	5      -   U-   $ )
N	secp256k1rs   vrJ  @   r  )ecdsaint_to_base16sumrjust)r  rM  r   	signaturerT  rU  rW  s          r  	sign_hashmodetrade.sign_hashn	  s    JJtCDz:cd+;[$O	cNcNtxxIcN;<aggb#&&S)99A==r  c                 J    U R                  U R                  U5      USS  5      $ )NrR  )r^  rO  )r  rN  r   s      r  sign_messagemodetrade.sign_messageu	  s%    ~~d//8*ST:JKKr  r%  r(  c           
      4  #    U R                  5       I Sh  vN   U R                  U5        Ub.  UR                  5       nUS:w  a  [        U R                  S-   5      eU R                  U5      nU R                  U R                  S5      nU R                  US5      nU R                  US0 5      n	U R                  X0 5      n
U R                  U
S5      nUc  [        U R                  S-   5      eU R                  U5      I Sh  vN nU R                  5       nUS	US
S.nSSSS.SSS.SSS.SSS.SSS.SSS.SSS./0nU R                  U R                  SS5      U R                  U5      UU[        U5      UUS.nU R                  XU5      nU R!                  UU R"                  5      nUUUUS.nU R%                  US5      nU R'                  U R)                  UU5      5      I Sh  vN nU R                  US0 5      nU R+                  UU5      $  GN GN N/7f)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   chainIdri  r,   z% withdraw() require chainId parameterOrderlyr:  )rd  r-   verifyingContractr2   Withdrawr   string)r-   r7  uint256receiverr%  r_  r=  withdrawNonceuint64r&  keyBrokerIdmode)r   rd  rj  r_  r=  rk  r&  )r]  userAddressrf  rN  r  )r  check_addressr  r"   r,   r|  r   r   r  rQ  r   rG  nonceparse_to_intstreth_encode_structured_datara  r   r  v1PrivatePostWithdrawRequestr  r/  )r  rh  r=  r%  r(  r!  r|  r   rd  currencyNetworkscoinNetworkcoinNetworkIdrk  rq  domainmessageTypeswithdrawRequestmsgr]  r  r"  r  s                         r  r   modetrade.withdrawx	  s>     !!!7#::<Dv~"477-L#LMM==&#'#3#3DLLB\#] ""695>>(JCnn%5C((d; TWW'NNOO"55f==

!9	
 #X6"I6#Y7 (3!95((;$h7

 ((}fM((1&k*!
 --fOT%%c4??;	""!9&	
 69-::4;;wPV;WXX ~~h3%%dH55} 	" >J Ys5   HHC+HHC#H&H'*HHHc                 <    U R                  US5      nUUS   S UUS.$ )Nmax_leverager,  )r  r,  r   longLeverageshortLeverage)r'  )r  r   r*  leverageValues       r  parse_leveragemodetrade.parse_leverage	  s2    ))(NCX&)*
 	
r  c                    #    U R                  5       I Sh  vN   U R                  U5      nU R                  U5      I Sh  vN nU R                  US0 5      nU R	                  XS5      $  NR N*7f)aR  
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>`
Nr  )r  r*  r  r  r  )r  r,  r!  r*  r"  r  s         r  fetch_leveragemodetrade.fetch_leverage	  sg      !!!V$44V<<8 ~~h3""400? 	"<s!   A-A))A- A+)A-+A-r   c                    #    U R                  5       I Sh  vN   US:  nUS:  nU(       d  U(       a  [        U R                  S-   5      eSU0nU R                  U R	                  Xc5      5      I Sh  vN $  N` N7f)aV  
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
Nr   2   z$ leverage should be between 1 and 50r   )r  r   r,   v1PrivatePostClientLeverager  )r  r   r,  r!  isMinLeverageisMaxLeverager  s          r  set_leveragemodetrade.set_leverage	  s{      !!! 1 2MTWW'MMNN
 55dkk'6RSSS 	" Ts"   A;A7AA;2A93A;9A;positionc                 t   U R                  US5      nU R                  X25      nU R                  US5      nS n[        R                  " US5      (       a  SnOSnU R                  US5      nU R                  US5      nU R	                  US5      nU R                  US	5      n	U R                  US
5      n
[        R
                  " U5      n[        R                  " XG5      nU R                  0 SU_SS _SU R                  US5      _SU_SU R                  U5      _SS _SS _SS _SS _SS _SU R                  U	5      _SU R                  U5      _SS _SU R                  U
5      _SU R                  U5      _SU R                  U5      _SS _U R                  US5      U R                  U5      S S SS US S S S S.E5      $ )Nr,  position_qtyr  longshortrG  
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
  rQ  )r  r  r*  r9  r  r  rG  r  r&  r  unrealisedPnlr  s               r  parse_positionmodetrade.parse_position
  sB   . ##Hh7!!(3.9T3''DD''?$$X|<	%%h<	%%h0DE
((?C!!$'%%d6!! #
H#
$#
 d&&vx8#
 	#

 Y/#
 "4#
 T#
 &t#
  #
 *4#
 $++J7#
 ))(3#
 #
 T..}=#
 **40#
  D--l;!#
" 4##
$ !% 0 0? K**95!!#9#
  	r  c                   #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  US5      nU R                  Xc5      $  Ng N)7f)aq  

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>`
Nr,  r,   r  )r  r*  v1PrivateGetPositionSymbolr  r  r  r  s          r  fetch_positionmodetrade.fetch_positionT
  s      !!!V$fTl
 88W9UVV6 ~~h/""400C 	"
 Ws!   BA>?BB (B Bc                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  US0 5      nU R                  US/ 5      nU R	                  XQ5      $  NT N=7f)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>`
Nr  rX  )r  v1PrivateGetPositionsr  rZ  parse_positions)r  r  r!  r"  rp  r   s         r  fetch_positionsmodetrade.fetch_positions
  sm      !!!33F;;N &"5NN6626	##I77U 	";s   A/A+A/A-<A/-A/c                 "    U R                  5       $ N)milliseconds)r  s    r  rq  modetrade.nonce
  s      ""r  r   GETc                    US   nUS   nU R                  X5      n	U R                  U R                  S   U   5      n
U
SU-   S-   -  n
U R                  X@R	                  U5      5      nU R                  U5      nUS:X  a$  X-  n
U(       a  U
SU R                  U5      -   -  n
GO=U R                  5         US:H  =(       d    US:H  nUS	:H  =(       d    US
:H  =(       d    US:H  nU(       a  U(       a  U R                  U R                  SS5      nU(       da  U R                  U R                  SS5      nUS:X  a:  U R                  US/ 5      n[        S[        U5      5       H  nXS   U   S'   M     OXS'   U R                  U5      nSn[        U R                  5       5      nX-  n
U R                   nUR#                  S5      S:  a  SU-   nU R$                  UUS.nUU-   S-   U-   S-   U	-   nUS:X  d  US:X  a  U R'                  U5      nUU-  nSUS'   OBU(       a.  U
SU R                  U5      -   -  n
USU R)                  U5      -   -  nSUS'   US:X  a  SnU R*                  nUR#                  S5      S:  a  UR-                  S5      nUS   nU R/                  U R1                  U5      U R3                  U5      S5      nU R5                  U R7                  U5      5      US'   XXeS.$ )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_credentialsrJ  r   r   rZ  rk  rl  rs  rq  r   findr   json	rawencoder   rO  eddsaencodebase58_to_binaryurlencode_base64base64_to_binary)r  pathsectionr  r!  r  r  r2   accesspathWithParamsr   isPostOrPutisOrderisSandboxModer   
ordersListrr  authtsr   r   rS  r]  s                          r  signmodetrade.sign
  s   !*,,T:##DIIe$4V$<=sW}s""6#6#6t#<=f%X!CsT^^F333++- F*=foKl*VdgoVAVGw $t||]E R$#//j*UH},%)^^FHb%I
!&q#j/!:A?G8,Q/< "; /7{+f-DTZZ\"B!C[[F{{:&*#f,&*nn%%'G
 ;$w.4~ED6U?yy(*<'3!777CC$.."888D*M'X%D[[F{{:&!+Z0q

4;;t#4d6K6KF6SU^_I+/+@+@AVAVW`Aa+bG'(dOOr  httpCodereasonr   r  r  r  c
                 >   U(       d  g U R                  US5      n
U R                  US5      nU
(       dj  U R                  S-   U R                  U5      -   nU R	                  U R
                  S   Xl5        U R                  U R
                  S   X5        [        U5      eg )Nr/  rh   r  r  )rJ  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_errorsmodetrade.handle_errors
  s    
 ..95$$Xv6	ww}tyy'::H001I4Z001I9_))r   r  )c__name__
__module____qualname____firstlineno__r   r	  boolr  r#  r	   r(  dictr   rU  r   r\  r   rx  r  r   r  rs  r  r   r  r  r  r  r   r   r  r   r  r  r  r   r	  r   r  listr  r"  r   rY  rP  rN  rO  r   r   floatr   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@  r9  rG  rO  r^  ra  r   r   r  r  intr  r  r  r   r  rq  r  r  __static_attributes____classcell__)r  s   @r  r(   r(      s   P# Pd-t - )+ "
H ') 8S 8,V
4 V
F V
p *, /(V /(b -/ [: [z
= =v = =~ <@d[] %= %=S %= %=bfglbm %=N'
f '
 '
R? @B 
=3 
=k 
= <>  5s  5+  5D <@  7  7|  7D >BPTcgpr >Os >O# >O]` >O@
6 
@ 9=4^bkm 9># 9>S 9>X[ 9>v /1 4[ 4l @DB 'cS 'c 'cS\ 'cR
 
4 
 ?CQUdhqs ,H ,H ,H3 ,H^a ,Hx|  ~B  yC ,H\n nv n n`As A  9S 9 os{} U,3 U,i U,y U,Z_ U,hk U,n mqy{ B BI BY BX] Bfi BH FH 3'$|*< 3'j fjx|  FH G.3 G. G.9 G.I G._b G.ru G.R 9=R FAS FA# FAP AER #tCy ## #J 59 +
c +
Z 8<B C0C C0 C0J 04$UYbd Q? Q?C Q?s Q?imnsit Q?f 59tZ^gi Mc M MTW Mnrsxny M, 7;\`ik M M3 MVY Mptuzp{ M, ?CQUdhqs ,G3 ,G ,G3 ,G^a ,G\ 37TX\eg <GC <Gs <GRU <G|) ) *, ( (: 8<$]ajl *< *<C *<WZ *<qt *<Xt x ; 63 .2SW`b Gs G# GS Ggklwgx G"
T 
X 
Q\ 
B:s : 04$UYbd g gC gs gimnyiz g" 37TX\eg gC gs gRU glpq|l} g" <@daenp MS M M[^ Muy  {F  vG M: /1 8:>L QU]_ K63 K6 K6 K6# K6do K6Z
x 
 8: )13 )1h )1V ?C2 T3 T T*Ct CV CJ 8: +13 +1Z 8<B 48W 484PX> 48l# "*%DW[ 8Ptc 3 S # X\ dg  r  r(   N), ccxt.async_support.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  r  <module>r     se    6 / s  s  s  s  s  s  * 0 . ' . ) ) ) . 4 %k++ k+r  