
    eit
                        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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)AccountAnyBalances
CurrenciesCurrencyIntMarginModificationMarketNumOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTransactionTransferEntry)List)ExchangeError)ArgumentsRequired)
BadRequest)InvalidOrder)RateLimitExceeded)	TICK_SIZE)Precisec                   h    e Zd Zdef fdZi fdZi fdZdjdededed	efd
Z	i fdefdZ
i fdZdedefdZdef fdZdi fdedededededee         fdZi fdZdi fdededededef
dZddi fdededededededefdZi fdZi fdefdZi fdee         fdZi fdefd Zdi fded!ede fd"Z!djd#e"d$ede#fd%Z$i fdede#fd&Z%di fd'e&de'fd(Z(djd$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+djd$ede,fd.Z-di fd'e&de.fd/Z/i fde0fd0Z1i fdefd1Z2di fd'e&dee3         fd2Z4djd3e"d$efd4Z5i fdee6         fd5Z7d6 Z8dddi fde9d,ed!edee         fd7Z:dddi fde9d,ed!edee         fd8Z;djd9e"d$edefd:Z<d;e9fd<Z=d= Z>d> Z?i fd?eded@edAede@f
dBZAdddi fd?e9d,ed!edee@         fdCZBdjdDe"dEeCde@fdFZDdddi fd?e9d,ed!edeeE         fdGZFdddi fd?e9d,ed!edeeE         fdHZGdjdIe"dEeCdeEfdJZHd;e9fdKZIdi fd?ededLedMe9deEf
dNZJdddi fde9d,ed!efdOZKdjdPe"d$edeLfdQZMdi fdReNde9fdSZOdi fdTede9fdUZPdi fdReNdTede9fdVZQdi fdede9fdWZRdi fde9fdXZSi fdYefdZZTi fdededeUfd[ZVi fdededeUfd\ZWi fdededeUfd]ZXdjd^e"d$edeUfd_ZYd`dai ddfdbZZdceNddedeedfedge"dhefdiZ[ xZ\S )klighterreturnc                 	   |                      t          t          |                                           i dddddg dddd	d
ddddddi dd ddddddddddddddddddddddddddddddd di d!dd"dd#dd$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1di d2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBdi dCddDddEddFddGddHddIddJddKddLddMddNddOddPddQddRddSdi dTddUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcddddi deddfddgddhddiddjddkddlddmddnddoddpddqddrddsddtdduddvdidwdxdydzd{d|d}d~ddd	ddddddddddddddddddddddddii dddddddddddddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddddddddi di dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt
          dt
          dt
          dt
          dt
          dt
          i dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          i dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          i dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          t
          t
          t
          t          t          t          t          d i ddddddddddddt          i ddd d d d dd	dddddd
ddddddddid          S (  Nidr%   nameLighter	countriesversionv1	rateLimit  	certifiedFproTdexhasCORSspotmarginswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMarginborrowMargincancelAllOrderscancelAllOrdersAftercancelOrdercancelOrderscancelOrdersForSymbolscloseAllPositionsclosePositioncreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopOrdercreateTriggerOrder	editOrderfetchAccountsfetchAllGreeksfetchBalancefetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchCanceledAndClosedOrdersfetchCanceledOrdersfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchLeverageTiersfetchLiquidationsfetchMarginModefetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionModefetchPositionsfetchPositionsRiskfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransferfetchTransfersfetchVolatilityHistoryfetchWithdrawalfetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMarginsandboxsetLeverage	setMarginsetMarginModesetPositionModetransferwithdraw
timeframes1m5m15m30m1h4h12h1d1w)	r   r   r   r   r   r   r   r   r   hostnamezzklighter.elliot.aiurlszOhttps://github.com/user-attachments/assets/ff1aaf96-bffb-4545-a750-5eba716e75d0zhttps://mainnet.{hostname})rootpublicprivatezhttps://testnet.{hostname}zhttps://lighter.xyz/zhttps://apidocs.lighter.xyz/z/https://docs.lighter.xyz/perpetual-futures/feesz"app.lighter.xyz/?referral=715955W9g?)urldiscount)logoapitestwwwdocfeesreferralr   get   ) infoaccountaccountsByL1AddressapikeysexchangeStatsassetDetailsorderBookDetailsorderBookOrders
orderBooksrecentTradesblockTxs	nextNoncetxtxFromL1TxHashtxsannouncementblockblocks)currentHeightcandlesfundingszfastbridge/infozfunding-rateswithdrawalDelay)sendTxsendTxBatch)r   postaccountLimitsaccountMetadatapnl
l1MetadataliquidationspositionFundingpublicPoolsMetadataaccountActiveOrdersaccountInactiveOrdersexporttrades
accountTxszdeposit/historyztransfer/historyzwithdraw/historyzreferral/pointstransferFeeInfo)changeAccountTierznotification/ackhttpExceptions
exceptions2150021501215022150321504215052150621507215082151121512216002160121602216032160421605216062160721608216112161221613216142170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740219012190221903)21904219052190623000230012300223003)exactbroadr   r   )takermakerrequiredCredentials)apiKeysecretwalletAddress
privateKeypasswordi0  )defaultTypechainIdaccountIndexapiKeyIndexwasmExecPathlibraryPathdefault)IOCFOKPOGTD)timeInForceleveragemarketBuyRequiresPricemarketBuyByCostselfTradePreventiontrailingiceberg)r   rH   )precisionModecommonCurrenciesoptionsfeatures)deep_extendsuperr%   describer   r    r!   r"   )self	__class__s    J/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/lighter.pyrL  zlighter.describe   s   gt 4 4 = = ? ? _B
)_B
I_B
 _B
 t	_B

 _B
 _B
 4_B
 4_B
  hhh %h 	h
 %h %h Th $Uh 'h h "4h 'h th h )%h  $U!h"  #h h$ /%h& ,U'h( 0)h* t+h, -h. &u/h0 (1h2 "53h4 %e5h6 T7h8  9h: !%;h< =h> &u?h@ "5AhB +EChD )%Eh h hF #EGhH ,UIhJ /KhL &uMhN $TOhP 'QhR (ShT "4UhV &uWhX (YhZ  [h\ *5]h^ +E_h` &uahb #Echd *5ehf $Tgh h hh uihj "5khl *5mhn +Eohp uqhr  sht %euhv $Uwhx "5yhz +E{h| }h~ !%h@ &uAhB  ChD dEhF $UGhH +EIh h hJ %eKhL "4MhN uOhP #EQhR eShT !$UhV uWhX #EYhZ  [h\ $U]h^ !$_h` %eahb )%chd tehf tghh ihj Tkh h hl umhn "5ohp #Eqhr  sht !$uhv )%whx "5yhz #D{h| }h~ #Eh@ &uAhB 4ChD tEhF TGhH  IhJ "5KhL DMh hN DOh h_B
d 
 
e_B
z -{_B
| i8:;  9:; 
 .5I? #  }_B
d  ! !!1! .q! "1	! (! '! +A! *1! %a! '! #A! $Q! a!  )!!!" q#!& ''!*  +!, !!-!. *+#$$%+,)*+,A! ! !H #$'( G( (T' *1 q	
 %a ' *1 .q .q 0 !! !! %a  *1!" +A#$ +A%( *1), *1-4 ./,-	 3 cQ Qe_B
H  I_B
L L]L]L ]L ]	L
 ]L ]L ]L ]L ]L ]L ]L \L \L \L \L  \!L" \#L L$ \%L& \'L( \)L* \+L, \-L. \/L0 \1L2 \3L4 \5L6 \7L8 \9L: \;L< \=L> \?L@ \ALB \CLD \EL L LF \GLH \ILJ \KLL \MLN \OLP \QLR \SLT \ULV \WLX \YLZ \[L\ \]L^ \_L` \aLb \cLd \eLf \gL L Lh \iLj \kLl \mLn \oLp \qLr \sLt \uLv \wLx \yLz \{L| \}L~ \L@ \ALB \CLD \ELF \GLH \IL LJ *))....WL L LZ]P PM_B
n	  o	_B
v	 "!&"!$ $w	_B
D
 ' "% $# $#  # $(#'"&#(	( ( %*27+0/4$)#($ $ Y
_B
 _B
 _B
 _ _ _	    c                     |                      | j        d          }||S d }|                     |dd          \  }}|                     |||||          }|| j        d<   |S )NsignerloadAccountr9  )	safe_dictrH  handle_option_and_paramsload_lighter_library)rM  r5  r2  r7  r6  paramsrR  r9  s           rO  load_accountzlighter.load_accountw  sq    h77M";;FMS`aaV**;[Zfgg!'XrP  c                    |                      | j        d          }|dS d}|                     |dd          \  }}d}|                     |ddd          \  }}d}|                     |ddd	          \  }}| j        duo
| j        d
k    }|r;|9|7|5|                     || j        d         | j        ||          }|| j        d<   dS dS )a  
        if the required credentials are available in options, it will pre-load the lighter Signer to avoid delaying sensitive calls like createOrder the first time they're executed
 @param params
        :returns boolean: True if the signer was loaded, False otherwise
        rR  NTrS  r9  r7  api_key_indexr6  account_indexr   r5  F)rT  rH  rU  handle_option_and_params_2r2  rV  )rM  rW  rR  r9  r7  r6  privateKeyIsSets          rO  pre_load_lighter_libraryz lighter.pre_load_lighter_library  s    h774";;FMS`aaV"==fmUbdsttV#>>v}Vdfuvvf?$6ST_PR=R 	 7k>U\h\t..{DL<SUYUdfqs  A  AF%+DL"4urP  NrW  methodName1optionName1optionName2c                 
   d }|                      |||||          \  }}|| j        }||dk    r)t          | j        dz   |z   dz   |z   dz   |z   dz             |                     d|i          }|                     |d          }	t          |	t                    rS|                     |	d          }
|
)t          | j        dz   |z   dz   |z   d	z   |z   d
z             |
d         }|| j	        d<   | 
                    |          |gS )Nr    z() requires an /z1 parameter or walletAddress to fetch accountIndex
l1_addresssub_accountsr   z or z
 parameterindexr6  )r\  r1  r   r(   publicGetAccountsByL1Address	safe_list
isinstancelistrT  rH  parse_to_int)rM  rW  r_  r`  ra  defaultValuer6  r1  ressubAccountsr   s              rO  handle_account_indexzlighter.handle_account_index  sc   #>>v{T_alnz{{f .M$(;(;'#(CFW(WZe(ehk(kny(y  }p  )p  q  q  q33\=4QRRC0 ..n==K+t,, <..a88?+DGcMK,GJ[,[^i,ilr,r  vA  -A  DP  -P  Q  Q  Q&w//;^,!!,//88rP  r)   c                    d }|                      |ddd          \  }}|t          | j        dz             d }|                     |ddd          \  }}|                     ||          }|||d}|                     | j        d         | j        |||          }|                     || 	                    ||                    \  }}	||	d	}
| 
                    |
          S )
NcreateSubAccountr7  rZ  z5 createSubAccount() requires an apiKeyIndex parameterr6  r[  )noncerZ  r[  r5  tx_typetx_info)r\  r   r(   rp  fetch_noncerX  rH  r2  lighter_sign_create_sub_accountextendpublicPostSendTx)rM  r)   rW  r7  r6  rs  signRawrR  txTypetxInforequests              rO  create_sub_accountzlighter.create_sub_account  s   "==fFXZgixyyV#DG.e$efff#88ASUcetuuf  {;;()
 

 ""4<	#:DO[Zfhnoo==fdkkRY[aFbFbcc
 
 $$W---rP  c                    |                      |dd          }|.|                     i ddd          }|                     |d          }|                      |dd          }|.|                     i ddd          }|                     |d          }|                                 dz   ||d}|                     |                     | j        d	          |          S )
Nr7  rZ  
createAuthr   r6  r[  <   )deadlinerZ  r[  rR  )safe_integer_2r\  safe_integersecondslighter_create_auth_token
safe_valuerH  )rM  rW  r7  rn  r6  rss         rO  create_authzlighter.create_auth  s    ))&-QQ11"lMSbccC++C33K**6>?SS11"lNTcddC,,S!44L+()
 

 --doodlH.U.UWYZZZrP  nmc                 .   t          j        |d          }|                     |          }|dk     rt          | j        dz             |dk    rdS |dk    rt          | j        dz             t          d|          D ]}t          j        ||          }|S )N1r   z pow() requires m > 0.d   z pow() requires m < 100.r   )r#   
string_mulrl  r   r(   range)rM  r  r  rcis         rO  powzlighter.pow  s    q#&&a  q55TW'??@@@663s77TW'AABBBq! 	) 	)A"1a((AArP  enablec                     t          t          |                               |           || j        d<   d| j        d<   d S )NsandboxModei,  r5  )rK  r%   set_sandbox_moderH  )rM  r  rN  s     rO  r  zlighter.set_sandbox_mode  s?    gt--f555&,]#"%YrP  symboltypesideamountpricec                 
   |t          | j        dz             |                     |ddd          }|                                }|                     |          }	|                                }
d|                     |	d                   i}d}d}d}d}|                     |dd	d
          \  }}|t          | j        dz             |                     |ddd          \  }}|                     |dd          \  }}|                     |ddd          \  }}||d<   ||d<   |                     |          |d<   |                     |dd          }| 	                    |d|          }| 	                    |d          }| 	                    |d          }| 	                    |d          }|du}|du}|p|}|dk    }| 
                    |dd          }|                     |d|          }|                     |g d          }d}d}|rd}d}nd}|
dk    rd|d<   nd|d<   |rd}n|s|d k    rd}d}n
|dk    rd}d!}|                     |	d"          }d}|                     ||          }|                     d#|d$                   } |                     d#|d%                   }!d&}"|                     d'          }#|                     |d(d)|#          }$|                     |g d*          }|rU|                     |          }||rd}nd+}|                     ||          }"n6||rd,}nd-}|                     ||          }"n|                     ||          }||d.<   ||d/<   ||d0<   |rdnd|d<   |$|d(<   |                     t)          j        ||                     |d1<   |                     t)          j        ||!                    |d2<   |                     t)          j        |"|!                    |d3<   g }%|%                    |                     ||                     |s|rNd|%d         d(<   d4}&|dk    rd5}&nd6}&|                     |ddg          }'|                     |d7d8          }(|                     |d9dg|'          })|                     |ddg          }*|                     |d7d8          }+|                     |d9dg|*          },|Q|                     ||(|&d|)|                     ||'d:d;                    d         }-d|-d(<   |%                    |-           |Q|                     ||+|&d|,|                     ||*d:d<                    d         }-d|-d(<   |%                    |-           |%S )=a'  
 @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
        :param int [params.nonce]: nonce for the account
        :param int [params.apiKeyIndex]: apiKeyIndex
        :param int [params.accountIndex]: accountIndex
        :param int [params.orderExpiry]: orderExpiry
        :returns any[]: request to be sent to the exchange
        Nz( createOrder() requires a price argument
reduceOnlyreduce_onlyFmarket_indexr(   rH   r7     z0 createOrder() requires an apiKeyIndex parameterr6  r[  rs  orderExpiryr   rZ  triggerPrice	stopPricestopLossPricetakeProfitPricestopLoss
takeProfitMARKETr?  gtt)r  r  r?  r   BUYis_ask   iocr   10size_decimalsprice_decimals0	   client_order_indexclientOrderId)r  r  r?  postOnlyrs  r7  r  r  r  r  r  r           order_expiry
order_typetime_in_forcebase_amountavg_execution_pricetrigger_pricer   sellbuyr  limitr  T)r  r  )r  r  )r   r(   safe_bool_2uppermarketrl  rU  r\  safe_string_2r  safe_string_loweris_post_onlyomitrT  price_to_precisionr  rand_numberr  number_to_stringamount_to_precisionr#   r  appendry  safe_number_nsafe_stringcreate_order_request).rM  r  r  r  r  r  rW  r  	orderTyper  	orderSider~  rs  r7  r6  r  r  r  r  r  r  hasStopLosshasTakeProfitisConditionalisMarketOrderr?  r  orderTypeNumtimeInForceNum
marketInfo	amountStrpriceStramountScale
priceScaletriggerPriceStrdefaultClientOrderIdr  orderstriggerOrderSidestopLossOrderTriggerPricestopLossOrderTypestopLossOrderLimitPricetakeProfitOrderTriggerPricetakeProfitOrderTypetakeProfitOrderLimitPriceorderObjs.                                                 rO  r  zlighter.create_order_request  s     =#DG.X$XYYY%%flM5QQ
JJLL	V$$JJLL	D--fTl;;
 ";;FMS`beffV#DG.`$`aaa#>>v}Vdfuvvf55fmWUUv";;FMS`bcddV #. #'#4#4\#B#B ))&.+NNNN//&2CDD??6:66__V\::
t+#4/&9/"h.,,V]EJJ$$]D&AA6#L#L#LMM 	LNNL !GH !GH 		%NN  %%''%&N"#KK E))%&N"$K^^FF33
	**6599hhtZ%@AAXXdJ/?$@AA
#//22++F4H/[opp6  $\  $\  $\  ]  ] 	A--f55I(  %#$LL#$L"&"9"9&-"P"P ,  %#$LL#$L"&"9"9&/"R"R00@@I"- ,#1 '1!9(5$%!%!2!273EiQ\3]3]!^!^)-):):7;MhXb;c;c)d)d%&#'#4#4W5GYc5d5d#e#e dkk'622333 	(- 	(./F1I*+!u}}#)  #( (,(:(:8nVaEb(c(c% $ 0 067 K K&*&8&8G_C]_x&y&y#*.*<*<Z.ZeIf*g*g'"&"2"2:vw"O"O(,(:(::QbGc  fA  )B  )B%#44V=NP`bce|  C  J  J  KQ%>"&S S      23-.h'''%44V=PRbde  hA  CG  CN  CN  OU'B"&W W C C    23-.h'''rP  c                    ||t          | j        dz             d|v r|                     |d          S |                     | j        d          }||S |                     ||d          }|                     |d          S )Nz4 fetchNonce() requires accountIndex and apiKeyIndex.rs  )r[  rZ  )r   r(   r  rH  publicGetNextNonce)rM  r6  r7  rW  nonceInOptionsresponses         rO  rw  zlighter.fetch_nonce  s     k&9#DG.d$deeef$$VW555**4<AA%!!**\\g+h+hii  7333rP  c                 P   |                                   d}|                     |ddd          \  }}||d<   |                     |          }d}	|                     |ddd          \  }	}|                     ||||||          }
t          |
          }d}d}|dk    rT|
d         }|d         }|d	         <|                     | j        d	          }|||d	<   n|                     ||          |d	<   | 	                    | j        d
         | j
        |||          }d}d}|dk     r|                     ||          \  }}n'|	|
|d	         ||d}|                     ||          \  }}||d}|                     |          }|                     |                     ||          |          S )a  
        create a trade 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 str [params.timeInForce]: 'GTT' or 'IOC', default is 'GTT'
        :param int [params.clientOrderId]: client order id, should be unique for each order, default is a random number
        :param str [params.triggerPrice]: trigger price for stop loss or take profit orders, in units of the quote currency
        :param boolean [params.reduceOnly]: whether the order is reduce only, default False
        :param int [params.nonce]: nonce for the account
        :param int [params.apiKeyIndex]: apiKeyIndex
        :param int [params.accountIndex]: accountIndex
        :param int [params.orderExpiry]: orderExpiry
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        NrH   r6  r[  groupingTyper  r   rZ  rs  r5  r  )grouping_typer  rs  rZ  r[  rt  )load_marketsrp  r  rU  r  lenr  rH  rw  rX  r2  lighter_sign_create_order"lighter_sign_create_grouped_ordersrz  parse_orderrJ  )rM  r  r  r  r  r  rW  r6  r  r  orderRequeststotalOrderRequestsr7  orderr  rR  r|  r}  signingPayloadr~  r  s                        rO  create_orderzlighter.create_order  s   & 	#88P^`oppf!-~V$$#<<V]Tbdefff11&$feU[\\ //!!!!$E0KW~%!%!2!24<!I!I!-%3E'NN%)%5%5lK%P%PE'N""4<	#:DO[Zfhnoo!!!;;FEJJNFFF ".'w!,!- N "DDV^\\NFF
 
 ((11  0 05 A A6JJJrP  r(   c           
      <   d}|                      |ddd          \  }}|t          | j        dz             |                                  d}	|                     |ddd          \  }	}|                     |          }
|                     |
d          }|                     |	|          }|                     d	|d
                   }|                     d	|d                   }| 	                    |g d          }| 
                    |g d          }d}|                     ||          }d}|,|                     |          }|                     ||          }n|                     ||          }|                     |
d                   |                     |          |                     t          j        ||                    |                     t          j        ||                    |                     t          j        ||                    |||	d}|                     | j        d         | j        ||	|          }|                     ||                     ||                    \  }}||d}|                     |          }|                     ||
          S )a  
        cancels an order and places a new 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 the currency you want to trade in units of the 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 str [params.accountIndex]: account index
        :param str [params.apiKeyIndex]: api key index
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        NrN   r7  rZ  z. editOrder() requires an apiKeyIndex parameterr6  r[  r   r  r  r  )r  r  r  r  r  r(   )r  rg  r  r  r  rs  rZ  r[  r5  rt  )r\  r   r(   r  rp  r  rT  rw  r  safe_string_nr  r  r  r  rl  r#   r  rX  rH  r2  lighter_sign_modify_orderry  rz  r  )rM  r(   r  r  r  r  r  rW  r7  r6  r  r  rs  r  r  r  r  r  r  r{  rR  r|  r}  r~  r  s                            rO  
edit_orderzlighter.edit_order  s    "==fkS`bqrrV#DG.^$^___#88n^mnnfV$$^^FF33
  {;;hhtZ%@AAXXdJ/?$@AA
))&2s2s2stt6#d#d#dee	**6599#--f55I"55flKKOO00@@I --fTl;;&&r**,,W-?	;-W-WXX&&w'9(J'O'OPP!..w/A/S]/^/^__()	
 	
 ""4<	#:DO[Zfhnoo77GU[@\@\]]
 
 ((11&111rP  c                 x    |                      |          }|                     |d          }|dk    rdndddd|dS )aF  
        the latest known information on the availability of the exchange API

        https://apidocs.lighter.xyz/reference/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>`
        status200okerrorN)r  updatedetar   r   )rootGetr  )rM  rW  r  r  s       rO  fetch_statuszlighter.fetch_status  sV     <<'' !!(H55%ddW
 
 	
rP  c                 X    |                      |          }|                     |d          S )aI  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://apidocs.lighter.xyz/reference/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_timestamp)rM  rW  r  s      rO  
fetch_timezlighter.fetch_time!  s-     <<'' ""8[999rP  c                    |                      |          }|                     |dg           }g }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }d}	d}
|                     |          }|                     |	          }|                     |
          }|                     |dd          }|                     |dd	          }|d
n'|                     |                     |                    }|d
n'|                     |                     |                    }| 	                    |d          }|
                    i d|d|dz   |z   dz   |z   d|d|d|d|d|	d|
ddddddddddddd|                     |d          dk    ddd dd| 	                    |d!          | 	                    |d"          |d
d
d
d
||d#d
d
d$| 	                    |d%          d
d$d
d
d$| 	                    |d&          d
d$d'd
|d(           |S ))a  
        retrieves data on all markets for lighter

        https://apidocs.lighter.xyz/reference/orderbookdetails

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        order_book_detailsr   	market_idr  USDCr  supported_size_decimalsr  supported_price_decimalsNquote_multiplierr(   rd  :basequotesettlebaseIdquoteIdsettleIdr  r7   r5   Fr6   Tr8   r9   activer  contractlinear	taker_fee	maker_fee)r  r  minmaxmin_base_amountmin_quote_amount)r@  r  r  cost)inverser,  r-  contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedr   )publicGetOrderBookDetailsri  r  r  r  safe_currency_coder  parse_numberparse_precisionsafe_numberr  )rM  rW  r  marketsresultr  r  r(   r  r  r  r  r  r  amountDecimalspriceDecimalsamountPrecisionpricePrecisionquoteMultipliers                      rO  fetch_marketszlighter.fetch_markets4  sY    11&99Z ..+?DDq#g,,'' @	 @	AQZF!!&+66B%%fh77FGH**622D++G44E,,X66F!//IbccN ..v7GIcddM'5'=ddDDUDUVZVjVjkyVzVzD{D{O&3&;TT$BSBSTXThThivTwTwBxBxN"..v7IJJOMM 2b2$*u,s2V;2 2 	2
 &2 &2 72 H2 2 2 %2 2 %2 %2 $**68<<H2  D!2" $#2$ !))&+>>))&+>> /"&"-+   $#! !
  $//8IJJ# 
  $# 
  $//8JKK#  $  c2 2 2 2 2 2 2f rP  c                 |   |                      |          }|                                  |                     |dg           }i }t          dt	          |                    D ]}||         }|                     |d          }|                     |                     |d                    }|                     |d          }	|dk    }
d}d}|
r,|                     |d          }|                     |d	          }|                     |||| 	                    d
|	z             ddi |
|
d|dd|ddd|d          ||<   |S )a  
        fetches all available currencies on an exchange

        https://apidocs.lighter.xyz/reference/assetdetails

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        asset_detailsr   asset_idr  decimalsr  Nmin_transfer_amountmin_withdrawal_amountz1e-Tcryptor"  )depositr   )r(   r)   coder.  r  feenetworksrE  r   r  r/  r   )
publicGetAssetDetailsr^  ri  r  r  r  r2  r5  safe_currency_structurer3  )rM  rW  r  datar7  r  entryr(   rF  rA  isUSDC
depositMinwithdrawMins                rO  fetch_currencieszlighter.fetch_currencies  s    --f55%%'''& ~~h<<q#d))$$ !	 !	AGE!!%44B**4+;+;E8+L+LMMD''z::HfnFJK O!--e5JKK
"..u6MNN77!..ux/?@@!"   *#   
  +#! !	 	 +9 9  F4LL. rP  r  c           	      ^   |t          | j        dz             |                                  |                     |          }|d         dd}|t	          |d          |d<   |                     |                     ||                    }|                     ||d         ddd	d
d          }|S )a3  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://apidocs.lighter.xyz/reference/orderbookorders

        :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
        Nz, fetchOrderBook() requires a symbol argumentr(   r  )r  r  r  r  bidsasksr  remaining_base_amount)r   r(   r  r  r#  publicGetOrderBookOrdersry  parse_order_book)rM  r  r  rW  r  r~  r  r7  s           rO  fetch_order_bookzlighter.fetch_order_book  s     >#DG.\$\]]]V$$
 
 "5#GG00Wf1M1MNN< &&x1A4QWY`byzzrP  tickerr  c           
         |                      |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|          S )Nr  r  last_trade_pricedaily_price_highdaily_price_lowdaily_base_token_volumedaily_quote_token_volumedaily_price_changeopen_interestr  datetimehighlowbid	bidVolumeask	askVolumevwapopencloselastpreviousClosechange
percentageaverage
mark_priceindex_price)
baseVolumequoteVolume	markPrice
indexPriceopenInterestr   )r  safe_marketsafe_ticker)rM  rX  r  marketIdr  rk  rb  rc  rr  rs  rm  rv  s               rO  parse_tickerzlighter.parse_ticker(  s   z ##FK88!!(F33!(:;;(:;;v'899%%f.GHH
&&v/IJJ!!&*>??''@@ !
f!
!
 !
 D	!

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

        https://apidocs.lighter.xyz/reference/orderbookdetails

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nz) fetchTicker() requires a symbol argumentr  r(   r  r   )	r   r(   r  r  r1  ry  ri  rT  rz  )rM  r  rW  r  r~  r  rK  firsts           rO  fetch_tickerzlighter.fetch_ticker  s     >#DG.Y$YZZZV$$
 11$++gv2N2NOOZ ~~h(<bAAtQ++  ///rP  symbolsc                     |                                   |                     |          }|                     |          }|                     |dg           }|                     ||          S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://apidocs.lighter.xyz/reference/orderbookdetails

        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        r  )r  market_symbolsr1  ri  parse_tickers)rM  r~  rW  r  tickerss        rO  fetch_tickerszlighter.fetch_tickers  sh     	%%g..11&99..+?DD!!'7333rP  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Ntohlr  v)r  r5  )rM  ohlcvr  s      rO  parse_ohlcvzlighter.parse_ohlcv  s    $ eS))UC((UC((UC((UC((UC((
 	
rP  r   	timeframesincec                     |t          | j        dz             |                                  |                     |          }|                     |d          }|                     |dg          }|                                 }d}	d}
|>|}	||}
n~|2|                     |          }|                     |||z  dz            }
nJ|}
nG||n|}
d}||
|                     |          dz  |z  z
  }	n|
|                     |          dz  |z  z
  }	|d         d| 	                    | j
        ||          |	|
d}|                     |                     ||                    }|                     |d	g           }|                     |||||          S )
a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://apidocs.lighter.xyz/reference/candles

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest candle to fetch
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nz( fetchOHLCV() requires a symbol argumentuntilr/   r  r(   r   )r  
count_back
resolutionstart_timestampend_timestampr  )r   r(   r  r  r  r  millisecondsparse_timeframesumr  r   publicGetCandlesry  ri  parse_ohlcvs)rM  r  r  r  r  rW  r  r  nowstartTsendTsdurationdefaultLimitr~  r  ohlcvss                   rO  fetch_ohlcvzlighter.fetch_ohlcv  s    >#DG.X$XYYYV$$!!&'226G9--!!G "//	::5(84(?@@#/EEcEL $"6"6y"A"AD"H5"PP$"6"6y"A"AD"H<"WW**4?IyQQ&"
 
 ((Wf)E)EFF. #r22  E5IIIrP  c                     |                      |d          }i d|d|                     ||          dd dd dd dd dd d	d d
|                     |d          dd dd dd dd dd dd dd dd dd iS )Nr  r   r  rt  ru  interestRateestimatedSettlePricer  ra  fundingRateratefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r  safe_symbolr5  )rM  r  r  ry  s       rO  parse_funding_ratezlighter.parse_funding_rate=  s    ##Hk::
H
d&&x88
 
 $	

 D
 #D
 
 
 4++Hf==
 
 t
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 
 	
rP  c                    |                                   |                     |                     |                    }|                     |dg           }g }t	          dt          |                    D ]?}|                     ||         d          }|dk    r|                    ||                    @|                     ||          S )a  
        fetch the current funding rate for multiple symbols

        https://apidocs.lighter.xyz/reference/funding-rates

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        funding_ratesr   exchanger%   )	r  publicGetFundingRatesry  ri  r  r  r  r  parse_funding_rates)rM  r~  rW  r  rK  r7  r  r  s           rO  fetch_funding_rateszlighter.fetch_funding_rates\  s     	--dkk&.A.ABB ~~h<<q#d))$$ 	' 	'A''Q<<H9$$d1g&&&''888rP  c           	         |                                   d}|                     |ddd          \  }}|                     | j        ddd          }|                     |d|          }|                     |dd	          |d
}|                     |                     ||                    }d|i}|                     |dg           }t          dt          |                    D ]q}	||	         }
|dk    r|                     |
dg           }t          dt          |                    D ]}||         }|                     |d          }| 
                    |          }|                     |||                                           }t          j        |d         |                     |d                    |d<   t          j        |d         |                     |d                    |d<   |||<   Ȑ|                     |
d          }|                     |d|                                           }t          j        |d         |          |d<   ||d<   s|                     |          S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://apidocs.lighter.xyz/reference/account-1

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.by]: fetch balance by 'index' or 'l1_address', defaults to 'index'
        :param str [params.value]: fetch balance value, account index or l1 address
        :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
        NrQ   r6  r[  r4  r5   r  byrg  r  valuer   accountsr   assetsr  totalbalanceusedlocked_balance
collateralz
USDC(PERP)r  )r  rp  r  rH  r  publicGetAccountry  ri  r  r  r2  rT  r   r#   
string_addsafe_balance)rM  rW  r6  r4  r  r~  r  r7  r  r  r   r  jassetcodeIdrF  r  perpUSDCperpBalances                      rO  fetch_balancezlighter.fetch_balance}  sd    	#88Q_apqqf((~}V\]]<<""6499!
 
 ((Wf)E)EFFZ )>>(J;;q#h--(( 	- 	-AqkGv~~2>>q#f++.. + +A"1IE!--eX>>F226::D"nnVT4<<>>JJG'.'9'':JDL\L\]bdmLnLn'o'oGG$&-&8$JZJZ[`brJsJs&t&tGFO#*F4LL+  ++G\BB"nnV\4<<>>RR'.'9+g:NPX'Y'YG$!,v  (((rP  c                 ^    |                      |g|          }|                     |di           S )a%  
        fetch data on an open position

        https://apidocs.lighter.xyz/reference/account-1

        :param str symbol: unified market symbol of the market the position is held in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.by]: fetch balance by 'index' or 'l1_address', defaults to 'index'
        :param str [params.value]: fetch balance value, account index or l1 address
        :returns dict: a `position structure <https://docs.ccxt.com/?id=position-structure>`
        r   )fetch_positionsrT  )rM  r  rW  	positionss       rO  fetch_positionzlighter.fetch_position  s1     ((&6::	~~iB///rP  c                 <   |                                   d}|                     |ddd          \  }}|                     |dd          |d}|                     |                     ||                    }g }|                     |dg           }t          d	t          |                    D ]\}||         }	|                     |	d
g           }
t          d	t          |
                    D ]}|                    |
|                    ]| 	                    ||          S )a  
        fetch all open positions

        https://apidocs.lighter.xyz/reference/account-1

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.by]: fetch balance by 'index' or 'l1_address', defaults to 'index'
        :param str [params.value]: fetch balance value, account index or l1 address
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/?id=position-structure>`
        Nr   r6  r[  r  rg  r  r  r   r  )
r  rp  r  r  ry  ri  r  r  r  parse_positions)rM  r~  rW  r6  r~  r  allPositionsr  r  r   r  r  s               rO  r  zlighter.fetch_positions  s2    	#88AQSacrssf""6499!
 
 ((Wf)E)EFFd >>(J;;q#h--(( 	2 	2AqkGwR@@I1c)nn-- 2 2##IaL11112##L':::rP  positionc           
         |                      |d          }|                     ||          }|                     |d          }d }|
|dk    rdnd}|                     |d          }d }|
|dk    rdnd	}|                      |d
          }d }	| |                     |          }
|
dk    rd|
z  }	|                     i d|dd d|d         dd dd d	|d	k    dd d|d|                     |d          dd d|                     |d          dd d|                     |d          d|	d|                     |d          dd dd d d |                     |d           |                     |d!          |d d"          S )#Nr  signr   longshortmargin_moder   crossisolatedinitial_margin_fractionr  r   r(   r  r  ra  hedgedr  	contractsr  r)  
entryPriceavg_entry_pricert  notionalposition_valuer@  r  allocated_margininitialMarginmaintenanceMarginunrealized_pnlliquidation_price)initialMarginPercentagemaintenanceMarginPercentageunrealizedPnlliquidationPrice
marginModern  )r  rw  r  rl  safe_positionr5  )rM  r  r  ry  r  r  marginModeIdr  imfStrr@  imfs              rO  parse_positionzlighter.parse_position0  sO   ( ##Hk::!!(F33  622"aii66gD((=AA
#%1Q%6%6ZJ!!(,EFF##F++CQww9!! #
H#
$#
 fX&#
 	#

 #
 z1#
 d#
 D#
 ))(J??#
 D#
 $**85FGG#
 #
 ((3CDD#
 #
 $**85GHH#
  T!#
"  ##
$ (,+/!--h8HII $ 0 0;N O O$/#
 #
 #
   	rP  c                 D   |                                   d}|                     |ddd          \  }}|                     |dd          |d}|                     |                     ||                    }|                     |dg           }|                     ||          S )	a
  
        fetch all the accounts associated with a profile

        https://apidocs.lighter.xyz/reference/account-1

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.by]: fetch balance by 'index' or 'l1_address', defaults to 'index'
        :param str [params.value]: fetch balance value, account index or l1 address
        :returns dict: a dictionary of `account structures <https://docs.ccxt.com/?id=accounts-structure>` indexed by the account type
        NrO   r6  r[  r  rg  r  r  )r  rp  r  r  ry  ri  parse_accounts)rM  rW  r6  r~  r  r  s         rO  fetch_accountszlighter.fetch_accountsn  s     	#88R`bqrrf""6499!
 
 ((Wf)E)EFF@ >>(J;;""8V444rP  c                 t    |                      |d          }|                      |d          |dk    rdndd |dS )Naccount_typer[  r  main
subaccount)r(   r  rF  r   r  )rM  r   accountTypes      rO  parse_accountzlighter.parse_account  sR    4 &&w??""7O<<*c11FF	
 
 	
rP  c                 D   |t          | j        dz             |                                  d}|                     |ddd          \  }}d}|                     |ddd          \  }}|t          | j        dz             |                     | j        d	         | j        |||           |                     |          }|d
         |d}| 	                    | 
                    ||                    }	|                     |	dg           }
|                     |
|||          S )aA  
        fetch all unfilled currently open orders

        https://apidocs.lighter.xyz/reference/accountactiveorders

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.accountIndex]: account index
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nz- fetchOpenOrders() requires a symbol argumentry   r6  r[  r7  rZ  z4 fetchOpenOrders() requires an apiKeyIndex parameterr5  r(   )r  r[  r  )r   r(   r  rp  r\  rX  rH  r2  r  privateGetAccountActiveOrdersry  ri  parse_ordersrM  r  r  r  rW  r6  r7  r  r~  r  rK  s              rO  fetch_open_orderszlighter.fetch_open_orders  s<    >#DG.]$]^^^#88ARTbdsttf"==fFWYfhwxxV#DG.d$deee$,y14?KQ]_efffV$$)
 
 55dkk'66R6RSSV ~~h"55  vue<<<rP  c                 p   |t          | j        dz             |                                  d}|                     |ddd          \  }}d}|                     |ddd          \  }}|t          | j        dz             |                     | j        d	         | j        |||           |                     |          }|d
         |dd}|t          |d          |d<   | 
                    |                     ||                    }	|                     |	dg           }
|                     |
|||          S )aE  
        fetch all unfilled currently closed orders

        https://apidocs.lighter.xyz/reference/accountinactiveorders

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.accountIndex]: account index
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nz/ fetchClosedOrders() requires a symbol argumentrZ   r6  r[  r7  rZ  z6 fetchClosedOrders() requires an apiKeyIndex parameterr5  r(   r  )r  r[  r  r  r  )r   r(   r  rp  r\  rX  rH  r2  r  r#  privateGetAccountInactiveOrdersry  ri  r  r  s              rO  fetch_closed_orderszlighter.fetch_closed_orders  sW    >#DG._$_```#88ATVdfuvvf"==fFY[hjyzzV#DG.f$fggg$,y14?KQ]_efffV$$)
 

 "5#GG77GV8T8TUUV ~~h"55  vue<<<rP  r  c                    |                      |d          }|                     ||          }|                     |d          }|                     |d          }d }||rdnd}|                      |d          }|                     |                     |                      |d                              }d }	d }
|6|                    d          d	k    r|}	|                    d
          d	k    r|}
|                      |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%|          S )&Nr  r  r  r  r  r  r  	stop-lossr   take-profitr  r  r   r(   order_idr  client_order_idr  ra  lastTradeTimestamplastUpdateTimestamp
updated_atr  r?  r  r  r  r  r  r  r  r  initial_base_amountfilled_quote_amountfilled_base_amountrT  )r  r'  ro  filled	remainingr  rG  r   )r  rw  r  	safe_boolr3  	omit_zerofind
safe_orderr  iso8601parse_order_typeparse_order_time_in_forecesparse_order_status)rM  r  r  ry  r  isAskr  r  r  r  r  tifr  s                rO  r  zlighter.parse_order\  s   L ##E>::!!(F33''{;;	uh//"-66Dv..((8H8HP_8`8`)a)abbyy%%** ,yy''1,,".uo66!!%22  
E 
$""5*55 
 T^^D,>,>uFWYm,n,noo 
 	 

 Y// 
 !$ 
 "4#6#6ul#K#K 
 fX& 
 D))$// 
 4;;C@@ 
  
 $..>> 
 D 
 T%%eW55 
 L 
  ]! 
" # 
$ &&u.CDD$$U,ABB&&u.BCC))%1HII--f553 
  
  
4 5  	rP  r  c                     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}|                      |||          S )Nzin-progressri  pendingr  closedcanceledzcanceled-post-onlyzcanceled-reduce-onlyzcanceled-position-not-allowedrejectedzcanceled-margin-not-allowedzcanceled-too-much-slippagezcanceled-not-enough-liquidityzcanceled-self-tradezcanceled-expiredexpiredzcanceled-ocozcanceled-childzcanceled-liquidationr  rM  r  statusess      rO  r  zlighter.parse_order_status  s    
6
v
 F
 h	

 

 !*
 #J
 ,Z
 *:
 )*
 ,Z
 ":
 	
 J
 j
  #J!
$ &&999rP  c           
      H    dddddddddd	}|                      |||          S )Nr  r  twap)	r  r  r  zstop-loss-limitr  ztake-profit-limitr!  ztwap-subliquidationr  r  s      rO  r  zlighter.parse_order_type  sC    !&#!(#

 

 &&999rP  c                 >    dddd d}|                      |||          S )NGTCr;  r=  )zgood-till-timezimmediate-or-cancelz	post-onlyUnknownr  )rM  r  timeInForcess      rO  r  z#lighter.parse_order_time_in_foreces  s4    ##(	
 
 c3777rP  rF  fromAccount	toAccountc                    d}|                      |ddd          \  }}|t          | j        dz             |                                  d}|                     |ddd          \  }}d}|                      |ddd	|          \  }}|                     |          }	|	d
         dk    rQ|                     t          j        | 	                    dd          | 
                    ||                              }nt|	d
         dk    rQ|                     t          j        | 	                    dd          | 
                    ||                              }nt          | j        dz             |dk    rdnd}
|dk    rdnd}|                     ||          }|                     |dd          }|                     |dg          }||                     |	d                   |
||d||||d
}|                     | j        d         | j        |||          }|                     ||                     ||                    \  }}||d}|                     |          }|                     |          S )a  
        transfer currency internally between wallets on the same account
        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from(spot, perp)
        :param str toAccount: account to transfer to(spot, perp)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.accountIndex]: account index
        :param str [params.toAccountIndex]: to account index, defaults to fromAccountIndex
        :param str [params.apiKeyIndex]: api key index
        :param str [params.memo]: hex encoding memo
        :returns dict: a `transfer structure <https://docs.ccxt.com/?id=transfer-structure>`
        Nr   r7  rZ  z- transfer() requires an apiKeyIndex parameterr6  r[  toAccountIndexto_account_indexrF  r  r  6ETH8z0 transfer() only supports USDC and ETH transfersperpr   r   memo 0x000000000000000000000000000000r(   )
r+  asset_indexfrom_route_typeto_route_typer  usdc_feer0  rs  rZ  r[  r5  rt  )r\  r   r(   r  rp  currencyrl  r#   r  r  currency_to_precisionr   rw  r  r  rX  rH  r2  lighter_sign_transferry  rz  parse_transfer)rM  rF  r  r'  r(  rW  r7  r6  r*  r6  fromRouteTypetoRouteTypers  r0  r{  rR  r|  r}  r~  r  s                       rO  r   zlighter.transfer  s    "==fjR_apqqV#DG.]$]^^^#88^]lmmf!%!@!@Uegy  |H  "I  "I==&&Fv%%&&w'9$((4:M:MtOiOijnpvOwOw'x'xyyFFf&&&&w'9$((4:M:MtOiOijnpvOwOw'x'xyyFF*\ \]]])V33!%//aaa  {;;0RSS6F8,, .,,Xd^<<,(()
 
 ""4<	#:DO[Zfhnoo33FDKKQW<X<XYY
 
 ((11""8,,,rP  c                    d}|                      |dd          \  }}|r|                     d||||dddd	  	        S d}|                     |ddd          \  }}d|i}d}|                     |dd	d
          \  }}|t	          | j        dz             |                     | j        d         | j        |||           d}	|| 	                    |          }	| 
                    |                     ||                    }
|                     |
dg           }|                     |
d          }|                     |d          }||||d         d<   |                     ||	|||          S )a\  
        fetch a history of internal transfers made on an account

        https://apidocs.lighter.xyz/reference/transfer_history

        :param str code: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for
        :param int [limit]: the maximum number of  transfers structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.accountIndex]: account index
        :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 `transfer structures <https://docs.ccxt.com/?id=transfer-structure>`
        Fr   paginatecursorN2   r6  r[  r7  rZ  z3 fetchTransfers() requires an apiKeyIndex parameterr5  	transfersr   )rU  fetch_paginated_call_cursorrp  r\  r   r(   rX  rH  r2  r6  privateGetTransferHistoryry  ri  r  rT  parse_transfers)rM  rF  r  r  rW  r=  r6  r~  r7  r6  r  rowsr>  r|  s                 rO  fetch_transferszlighter.fetch_transfers  s    88AQS]^^& 	@334DdESXZ`bjltvz|~#88AQSacrssf\
 "==fFVXegvwwV#DG.c$cddd$,y14?KQ]_efff}}T**H11$++gv2N2NOO0 ~~hR88!!(H55tQ''F$6 &DGH##D(E5&IIIrP  r   r6  c           
         |                      |d          }|                     ||          }|                     |d          }|                     |di           }|                     |di           }|                      |d          ||                     |          ||                     |d          |                      |d          |                      |d          d |d		S )
Nr@  r  fromtor(   r  from_account_indexr+  )	r(   r  ra  r6  r  r'  r(  r  r   )r  r2  r  rT  r  r5  )rM  r   r6  
currencyIdrF  r  r'  r(  s           rO  r9  zlighter.parse_transferR  s    $ %%h
;;
&&z8<<%%h<<	nnXvr::NN8T266	""8T22"Y//&&x::++K9MNN)))5GHH

 

 
	
rP  c                 |   d}|                      |dd          \  }}|r|                     d||||dddd	  	        S d}|                     |ddd          \  }}|t          | j        d	z             |                                  d}|                     |dd
d          \  }}||d}d}	|                     |ddd          \  }	}|	t          | j        dz             |                     | j        d         | j	        |	||           d}
| | 
                    |          }
|
d         |d<   |                     |                     ||                    }|                     |dg           }|                     |d          }|                     |d          }||||d         d<   |                     ||
||          S )aa  
        fetch all deposits made to an account

        https://apidocs.lighter.xyz/reference/deposit_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
        :param str [params.accountIndex]: account index
        :param str [params.address]: l1_address
        :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 `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        Fr`   r=  r>  Nr?  addressre  z. fetchDeposits() requires an address parameterr6  r[  )r[  re  r7  rZ  z2 fetchDeposits() requires an apiKeyIndex parameterr5  r(   coindepositsr   )rU  rA  r\  r   r(   r  rp  rX  rH  r2  r6  privateGetDepositHistoryry  ri  r  rT  parse_transactions)rM  rF  r  r  rW  r=  rL  r6  r~  r7  r6  r  rK  r>  r|  s                  rO  fetch_depositszlighter.fetch_depositsu  s    88R\]]& 	33OT5RWY_aiksuy{}~~~99&/S\^jkk?#DG.^$^___#88R`bqrrf)!
 
 "==foWdfuvvV#DG.b$bccc$,y14?KQ]_efff}}T**H&tnGFO00Wf1M1MNN" ~~h
B77!!(H55tQ''F$6 &DGH&&tXueDDDrP  c                    d}|                      |dd          \  }}|r|                     d||||dddd	  	        S d}|                     |ddd          \  }}|                                  d|i}d}|                     |dd	d
          \  }}|t          | j        dz             |                     | j        d         | j	        |||           d}	| | 
                    |          }	|	d         |d<   |                     |                     ||                    }
|                     |
dg           }|                     |
d          }|                     |d          }||||d         d<   |                     ||	||          S )a=  
        fetch all withdrawals made from an account

        https://apidocs.lighter.xyz/reference/withdraw_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
        :param str [params.accountIndex]: account index
        :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 `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        Fr   r=  r>  Nr?  r6  r[  r7  rZ  z5 fetchWithdrawals() requires an apiKeyIndex parameterr5  r(   rM  	withdrawsr   )rU  rA  rp  r  r\  r   r(   rX  rH  r2  r6  privateGetWithdrawHistoryry  ri  r  rT  rP  )rM  rF  r  r  rW  r=  r6  r~  r7  r6  r  rK  r>  r|  s                 rO  fetch_withdrawalszlighter.fetch_withdrawals  s    88ASU_``& 	B334FeUZ\bdlnvx|  A  B  B  B#88ASUcetuuf\
 "==fFXZgixyyV#DG.e$efff$,y14?KQ]_efff}}T**H&tnGFO11$++gv2N2NOO$ ~~hR88!!(H55tQ''F$6 &DGH&&tXueDDDrP  transactionc                    |                      |d          }|d}n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S )Nr  rE  
withdrawalr  r  r   r(   txid
l1_tx_hashr6  r@  networkr  ra  rL  addressFrom	addressTotagtagFromtagTor  )commentrG  internal)r  r  r2  r5  parse_transaction_statusr  )rM  rV  r6  r  r  r  s         rO  parse_transactionzlighter.parse_transaction  s   , V44<DDD%%k;??	!!+x88
K
$"";55
 D$$[,??
 D	

 //0@0@j0Y0Y[cdd
 t
 d&&{H==
 d33F;;
 
 Y//
 t
 4
 
 4
 t
  T!
" t#
$ )
 
 
 	
rP  c                 >    ddddd}|                      |||          S )Nfailedr  r  )rf  r  	completed	claimabler  r  s      rO  rc  z lighter.parse_transaction_status"	  s4     	
 
 &&999rP  rL  r^  c           	      p   d}|                      |ddd          \  }}|t          | j        dz             |                                  d}|                     |ddd          \  }}|                     |          }|d         d	k    rQ|                     t          j        | 	                    d
d          | 
                    ||                              }nt|d         dk    rQ|                     t          j        | 	                    d
d          | 
                    ||                              }nt          | j        dz             |                     |dd          }	|                     |d          }|                     ||          }
|                     |d                   |	||
||d}|                     | j        d         | j        |||          }|                     ||                     ||                    \  }}||d}|                     |          }|                     |          S )aQ  
        make a withdrawal
        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str [tag]:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.accountIndex]: account index
        :param str [params.apiKeyIndex]: api key index
        :param int [params.routeType]: wallet type, 0: perp, 1: spot, default is 0
        :returns dict: a `transaction structure <https://docs.ccxt.com/?id=transaction-structure>`
        Nr   r7  rZ  z- withdraw() requires an apiKeyIndex parameterr6  r[  rF  r  r  r,  r-  r.  z0 withdraw() only supports USDC and ETH transfers	routeTyper   r(   )r2  
route_typer  rs  rZ  r[  r5  rt  )r\  r   r(   r  rp  r6  rl  r#   r  r  r7  r   r  r  rw  rX  rH  r2  lighter_sign_withdrawry  rz  rd  )rM  rF  r  rL  r^  rW  r7  r6  r6  rj  rs  r{  rR  r|  r}  r~  r  s                    rO  r   zlighter.withdraw+	  s@    "==fjR_apqqV#DG.]$]^^^#88^]lmmf==&&Fv%%&&w'9$((4:M:MtOiOijnpvOwOw'x'xyyFFf&&&&w'9$((4:M:MtOiOijnpvOwOw'x'xyyFF*\ \]]]%%fk1==	6;//  {;;,,Xd^<<#()
 
 ""4<	#:DO[Zfhnoo33FDKKQW<X<XYY
 
 ((11%%h///rP  c                    |                                   d}|                     |dd          \  }}|r|                     d||||dddd	  	        S d}|                     |ddd	          \  }}d}|                     |dd
d          \  }}|t          | j        dz             |                     | j        d         | j	        |||           dd|d}|t          |d          |d<   d}	|                     |ddd          \  }	}|	|	|d<   d}
| |                     |          }
|
d         |d<   |                     |                     ||                    }|                     |dg           }t          dt!          |                    D ]}|||         d	<   |                     |d          }|                     |d          }||||d         d<   |                     ||
|||          S )af  
        fetch all trades made by the user

        https://apidocs.lighter.xyz/reference/trades

        :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 str [params.accountIndex]: account index
        :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)
        :param int [params.until]: timestamp in ms of the latest trade to fetch
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Frt   r=  next_cursorr>  Nr?  r6  r[  r7  rZ  z2 fetchMyTrades() requires an apiKeyIndex parameterr5  r  r  )sort_byr  r[  r  r  rG  r(   r  r   r   )r  rU  rA  rp  r\  r   r(   rX  rH  r2  r#  r  privateGetTradesry  ri  r  r  r  rT  parse_trades)rM  r  r  r  rW  r=  r6  r7  r~  r  r  r  rK  r  
nextCursorr|  s                   rO  fetch_my_tradeszlighter.fetch_my_tradesZ	  s[    	88R\]]& 	F33OVUTY[acprz  }A  CE  F  F  F#88R`bqrrf"==foWdfuvvV#DG.b$bccc$,y14?KQ]_efff")
 

 "5#GG77QXZ`aav#GFO[[((F#)$<GK ((Wf)E)EFF@ ~~h"55q#d))$$ 	4 	4A'3DGO$$%%h>>
tQ''J$:%/DGM"  vueVDDDrP  tradec                 ,   |                      |d          }|                     ||          }|                     |d          }|                      |d          }|                      |d          }|                      |d          }|                     |d          }d }	d }
|=||k    rd}	|                      |d          }
n||k    rd	}	|                      |d
          }
d }|	||	dk    r|n| }|rdnd}|                     ||                      |d          ||                     |          |d         |
|                      |d          |	||                      |d          |                      |d          |                      |d          d d|          S )Nr  r  r[  ask_account_idbid_account_idis_maker_askr  ask_idr  bid_idr-  r,  trade_idr  r  r  size
usd_amount)r   r(   r  ra  r  r  r  r  takerOrMakerr  r  r'  rG  )r  rw  r  r  
safe_trader  )rM  rt  r  ry  r  r6  askAccountIdbidAccountId
isMakerAskr  orderIdr~  isMakers                rO  parse_tradezlighter.parse_trade	  s   6 ##E;77!!(F33%%e[99	''??''/?@@''/?@@^^E>::
#|++**5(;;--**5(;;
 6%)V^^jjj.G&-:777L""5*55"Y//X&$$UF33(%%eW55&&uf55$$UL99 
  
   	rP  r@  c                     |t          | j        dz             d}|                     |ddd          \  }}|t          | j        dz             |                     ||||          S )a  
        set the level of leverage for a market
        :param float leverage: the rate of leverage
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.accountIndex]: account index
        :param str [params.apiKeyIndex]: api key index
        :param str [params.marginMode]: margin mode, 'cross' or 'isolated'
        :returns dict: response from the exchange
        Nz) setLeverage() requires a symbol argumentr   r  r  z/ setLeverage() requires an marginMode parameter)r   r(   r\  modify_leverage_and_margin_mode)rM  r@  r  rW  r  s        rO  set_leveragezlighter.set_leverage	  s{     >#DG.Y$YZZZ
!<<V]T`bopp
F#DG._$_```33Hj&RXYYYrP  r  c                     |t          | j        dz             d}|                     |ddd          \  }}|t          | j        dz             |                     ||||          S )a  
        set margin mode to 'cross' or 'isolated'
        :param str marginMode: 'cross' or 'isolated'
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.accountIndex]: account index
        :param str [params.apiKeyIndex]: api key index
        :param int [params.leverage]: required leverage
        :returns dict: response from the exchange
        Nz1 setMarginMode() requires an marginMode parameterr   r@  z/ setMarginMode() requires an leverage parameter)r   r(   rU  r  )rM  r  r  rW  r@  s        rO  set_margin_modezlighter.set_margin_mode	  s|     #DG.a$abbb88R\^hii&#DG._$_```33Hj&RXYYYrP  c                    |dk    r|dk    rt          | j        dz             d }|                     |ddd          \  }}|t          | j        dz             |t          | j        dz             |                                  d }|                     |dd	d
          \  }}|                     |          }|                     ||          }|                     |d                   |                     d|z            |dk    rdnd|||d}	| 	                    | j
        d         | j        |||          }
|                     |
|                     |	|                    \  }}||d}|                     |          S )Nr  r  zd modifyLeverageAndMarginMode() requires a marginMode parameter that must be either cross or isolatedmodifyLeverageAndMarginModer7  rZ  z@ modifyLeverageAndMarginMode() requires an apiKeyIndex parameterz9 modifyLeverageAndMarginMode() requires a symbol argumentr6  r[  r(   i'  r   r   )r  r  r  rs  rZ  r[  r5  rt  )r   r(   r\  r   r  rp  r  rw  rl  rX  rH  r2  lighter_sign_update_leveragery  rz  )rM  r@  r  r  rW  r7  r6  r  rs  r{  rR  r|  r}  r~  s                 rO  r  z'lighter.modify_leverage_and_margin_mode
  s   '!!
j(@(@TW  (N  N  O  O  O"==fFcer  uD  E  EV#DG.p$pqqq>#DG.i$ijjj#88A^`np   A   AfV$$  {;; --fTl;;'+'8'89I'J'J!+w!6!611Q()
 
 ""4<	#:DO[Zfhnoo::64;;wX^C_C_``
 
 $$W---rP  c                    d}|                      |ddd          \  }}|t          | j        dz             |t          | j        dz             |                     |dd          }|                     |ddg          }|                                  d}|                     |dd	d
          \  }}|                     |          }|                     ||          }| 	                    |d                   |||d}	|| 	                    |          |	d<   n2|| 	                    |          |	d<   nt          | j        dz             | 
                    | j        d         | j        |||          }
|                     |
|                     |	|                    \  }}||d}|                     |          }|                     ||          S )a  
        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 str [params.accountIndex]: account index
        :param str [params.apiKeyIndex]: api key index
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr@   r7  rZ  z0 cancelOrder() requires an apiKeyIndex parameterz) cancelOrder() requires a symbol argumentr  r  r6  r[  r(   )r  rs  rZ  r[  order_indexz1 cancelOrder requires order id or client order idr5  rt  )r\  r   r(   r  r  r  rp  r  rw  rl  rX  rH  r2  lighter_sign_cancel_orderry  rz  r  )rM  r(   r  rW  r7  r  r6  r  rs  r{  rR  r|  r}  r~  r  s                  rO  cancel_orderzlighter.cancel_order0
  s    "==fmUbdsttV#DG.`$`aaa>#DG.Y$YZZZ**63GYY6$8/#JKK#88P^`oppfV$$  {;; --fTl;;()	
 
 $%)%6%6}%E%EGM""^%)%6%6r%:%:GM""#DG.a$abbb""4<	#:DO[Zfhnoo77GU[@\@\]]
 
 ((11&111rP  c                    d}|                      |ddd          \  }}|t          | j        dz             d}|                     |ddd          \  }}|                     |||          }dd|||d	}|                     | j        d
         | j        |||          }|                     || 	                    ||                    \  }}	||	d}
| 
                    |
          }|                     |g          S )a  
        cancel all open orders
        :param str [symbol]: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.accountIndex]: account index
        :param str [params.apiKeyIndex]: api key index
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nr>   r7  rZ  z4 cancelAllOrders() requires an apiKeyIndex parameterr6  r[  r   r  timers  rZ  r[  r5  rt  )r\  r   r(   rp  rw  rX  rH  r2  lighter_sign_cancel_all_ordersry  rz  r  )rM  r  rW  r7  r6  rs  r{  rR  r|  r}  r~  r  s               rO  cancel_all_orderszlighter.cancel_all_orders\
  s,    "==fFWYfhwxxV#DG.d$deee#88ARTbdsttf  {FCC()
 
 ""4<	#:DO[Zfhnoo<<VT[[QXZ`EaEabb
 
 ((11  (,,,rP  timeoutc                 8   |dk     s|dk    rt          | j        dz             d}|                     |ddd          \  }}|t          | j        dz             d}|                     |d	d
d          \  }}|                     ||          }d|                                 |z   |||d}|                     | j        d         | j	        |||          }| 
                    ||                     ||                    \  }}	||	d}
|                     |
          }|S )a  
        dead man's switch, cancel all orders after the given timeout
        :param number timeout: time in milliseconds, 0 represents cancel the timer
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: the api result
        i i d?Mz1 timeout should be between 5 minutes and 15 days.Nr@   r7  rZ  z9 cancelAllOrdersAfter() requires an apiKeyIndex parameterr?   r6  r[  r   r  r5  rt  )r   r(   r\  r   rp  rw  r  rX  rH  r2  r  ry  rz  )rM  r  rW  r7  r6  rs  r{  rR  r|  r}  r~  r  s               rO  cancel_all_orders_afterzlighter.cancel_all_orders_after|
  sT    f'J"6"6TW'ZZ[[["==fmUbdsttV#DG.i$ijjj#88AWYgixyyf  {;;%%'''1()
 
 ""4<	#:DO[Zfhnoo<<VT[[QXZ`EaEabb
 
 ((11rP  c                 `    ddi}|                      |||                     ||                    S )a4  
        add margin
        :param str symbol: unified market symbol
        :param float amount: amount of margin to add
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin structure <https://docs.ccxt.com/?id=add-margin-structure>`
        	directionr   
set_marginry  rM  r  r  rW  r~  s        rO  
add_marginzlighter.add_margin
  6     
 vvt{{7F/K/KLLLrP  c                 `    ddi}|                      |||                     ||                    S )aQ  
        remove margin from a position
        :param str symbol: unified market symbol
        :param float amount: the amount of margin to remove
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin structure <https://docs.ccxt.com/?id=reduce-margin-structure>`
        r  r   r  r  s        rO  reduce_marginzlighter.reduce_margin
  r  rP  c           
          d}|                      |ddd          \  }}|t          | j        dz             |                     |d          }|t          | j        dz             |                     |dd	g          st          | j        dz             |t          | j        d
z             |                                  d}|                     |ddd          \  }}|                     |          }|                     ||          }| 	                    |d                   | 	                    t          j        |                     dd          |                     d|                              ||||d}	|                     | j        d         | j        |||          }
|                     |
|                     |	|                    \  }}||d}|                     |          }|                     ||          S )a  
        Either adds or reduces margin in an isolated position in order to set the margin to a specific value
        :param str symbol: unified market symbol of the market to set margin in
        :param float amount: the amount to set the margin to
        :param dict [params]: parameters specific to the bingx api endpoint
        :param str [params.accountIndex]: account index
        :param str [params.apiKeyIndex]: api key index
        :returns dict: A `margin structure <https://docs.ccxt.com/?id=add-margin-structure>`
        Nr   r7  rZ  z. setMargin() requires an apiKeyIndex parameterr  z[ setMargin() requires a direction parameter either 1(increase margin) or 0(decrease margin)r   r   z' setMargin() requires a symbol argumentr6  r[  r(   r  r,  r  )r  usdc_amountr  rs  rZ  r[  r5  rt  )r\  r   r(   r  in_arrayr  rp  r  rw  rl  r#   r  r  r7  rX  rH  r2  lighter_sign_update_marginry  rz  parse_margin_modification)rM  r  r  rW  r7  r  r6  r  rs  r{  rR  r|  r}  r~  r  s                  rO  r  zlighter.set_margin
  sA    "==fkS`bqrrV#DG.^$^___%%fk::	#DG  /L  %L  M  M  M}}YA// 	M#DG  /L  %L  M  M  M>#DG.W$WXXX#88n^mnnfV$$  {;; --fTl;;,,W-?s@S@SUYUoUopvx~UU  .A  .A  B  B"()
 
 ""4<	#:DO[Zfhnoo88WV\A]A]^^
 
 ((11--h???rP  rK  c                     |                      |d          }||                     |d          d d d d dd ||                     |          d
S )Npredicted_execution_time_msr  r  )
r   r  r  r  r  r  rF  r  r  ra  )r  r  r  )rM  rK  r  r  s       rO  r  z!lighter.parse_margin_modification
  sa    %%d,IJJ	&&vx88"Y//
 
 	
rP  r   GETc                 j   d }|dk    r'|                      | j        d         d                   }n7|                      | j        d         |                   dz   | j        z   dz   |z   }|dk    rd|                     |          i}|r(|dk    rd	d
i}|}n|d|                     |          z   z  }||||dS )Nr   r   r   z/api/rd  r   AuthorizationPOSTzContent-Typezmultipart/form-data?)r   methodbodyheaders)implode_hostnamer   r,   r  	rawencode)rM  pathr   r  rW  r  r  r   s           rO  r  zlighter.sign
  s    &==''	%(8(BCCCC''	%(8(=>>H4<WZ]]`ddC)!1!1&!9!9G  	4"$9 sT^^F3333fdwOOOrP  httpCodereasonr   r  r  r  c
                 B   |sd S |                      |d          }
|                      |d          }|
l|
dk    rf|
dk    r`| j        dz   |z   }|                     | j        d         ||           |                     | j        d         |
|           t          |          d S )NrF  msgr  r  rc  r+  r*  )r  r(   throw_broadly_matched_exceptionr   throw_exactly_matched_exceptionr   )rM  r  r  r   r  r  r  r  requestHeadersrequestBodyrF  messagefeedbacks                rO  handle_errorszlighter.handle_errors  s     	4 &11""8U33w}t+H001I7T\]]]001I4QYZZZ)))trP  )N)]__name__
__module____qualname__r   rL  rX  r^  objectstrrp  r  r  r  boolr  r   r   floatr   r   r  rw  r  r   r  r
  r
   r  r   r=  r   rP  r   rW  dictr   rz  r}  r   r   r  rk  r  r  r   r  r   r  r   r  r  r   r  r  r   r  r  r   r  r   r  r  r  r  r   r   rE  r	   r9  r   rQ  rU  rd  rc  r   rs  r   r  intr  r  r  r  r  r  r   r  r  r  r  r  r  __classcell__)rN  s   @rO  r%   r%      s       `# ` ` ` ` ` `D SU     /1    ,&9 &96 &9 &9RU &9dg &9 &9 &9 &9P 46 . .s . . . .* "$ [ [ [ ["S S    &t & & & & & &
 os{} G G3 Gi Gy GZ_ Ghk G  CG  HK  CL G G G GR =? 	4 	4 	4 	4 gksu CK CK3 CKi CKy CKRW CK`c CK CK CK CKJ `drv  @B 52 52S 52# 52Y 52i 52Y\ 52lo 52  GL 52 52 52 52n #% 
 
 
 
4 !# : :s : : : :& $& y y$v, y y y yv ') A AZ A A A AF :>b 4 4s 43 4Y 4 4 4 4l_ _4 _ _6 _ _ _ _B 02 @0 @03 @0f @0 @0 @0 @0D 04B 4 4W 47 4 4 4 4 
 
 
4 
 
 
 
4 9=4^bkm FJ FJ# FJ# FJS FJX[ FJrvw{r| FJ FJ FJ FJP
 
6 
[ 
 
 
 
> 6:" 9 97 9 9 9 9 9B $& T) T)( T) T) T) T)l 24 0 0S 0 0 0 0 26b L; L;w L;T(^ L; L; L; L;\< <t <V < < < <| %' 35 354= 35 35 35 35j 
  
  
D /3TXac H= H= H=3 H=c H=hlmrhs H= H= H= H=T 154VZce K= K=# K=S K=PS K=jnotju K= K= K= K=ZR R Rv R R R R Rh: : : : :*: : :8 8 8 [] 6- 6-S 6-% 6-c 6-c 6-an 6- 6- 6- 6-p +/TPT]_ <J <JC <Js <J# <Jdhivdw <J <J <J <J|!
 !
t !
x !
= !
 !
 !
 !
F *.Dt\^ =E =E3 =Ec =E =Ecghsct =E =E =E =E~ -1tRV_a 8E 8Ec 8E 8EC 8Efjkvfw 8E 8E 8E 8Et2
 2
T 2
X 2
Q\ 2
 2
 2
 2
h:s : : : : KOWY -0 -0S -0% -0# -0C -0^i -0 -0 -0 -0^ -1tRV_a QE QEc QE QEC QE QE QE QEf= = =v = = = = =~ 9=R Z ZS Z# Z Z Z Z& >B" Z Z# Zs Z Z Z Z& ]aik . . . .VY . . . .< 37r *2 *2s *2C *2 *2 *2 *2X /32 - - - - - -@ <>  s    @ =? M M Me MCU M M M M @B M MC M MFX M M M M =? )@ )@ )@e )@CU )@ )@ )@ )@V
 
d 
F 
N` 
 
 
 
 &eBSW P P P P(c 3 S # X\ dg        rP  r%   N))ccxt.base.exchanger   ccxt.abstract.lighterr   ccxt.base.typesr   r   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!   ccxt.base.decimal_to_precisionr"   ccxt.base.preciser#   r%    rP  rO  <module>r     s'   ( ' ' ' ' ' - - - - - - ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~       * * * * * * . . . . . . ' ' ' ' ' ' ) ) ) ) ) ) . . . . . . 4 4 4 4 4 4 % % % % % %A, A, A, A, A,h A, A, A, A, A,rP  