
    E#i#~                       S SK Jr  S SKJr  S SKrS SKrS SKJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-  S SK.J/r/  S SK0J1r1  S SK0J2r2  S SK0J3r3  S S	K0J4r4  S S
K0J5r5  S SK0J6r6  S SK0J7r7  S SK0J8r8  S SK0J9r9  S SK0J:r:  S SK0J;r;  S SK0J<r<  S SK0J=r=  S SK0J>r>  S SK0J?r?  S SK@JArA  S SKBJCrC   " S S\\5      rDg)    )Exchange)ImplicitAPIN)'AnyBalancesBorrowInterestBool
CurrenciesCurrencyDepositAddressFundingHistoryGreeksIntLedgerEntryLeverage	LeveragesLeverageTierLeverageTiersMarginModificationMarketNumOptionOptionChainOrder	OrderBookOrderRequestCancellationRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTradingFeeInterfaceTradingFeesTransactionMarketInterfaceTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountNotEnabled)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)OrderImmediatelyFillable)NotSupported)RateLimitExceeded)ExchangeNotAvailable)	TICK_SIZE)Precisec                     ^  \ rS rSrS\4U 4S jjrS\4U 4S jjr0 4S jr0 4S jr	0 4S\
4S jjrS	\4S
 jrSS\S\S\S\S\4
U 4S jjjr0 4S\\   4S jjr0 4S jr0 4S jr0 4S jrS r0 4S jrS rSS0 4S jrSS0 4S jrSS0 4S jrS rS r0 4S\4S jjr 0 4S	\S\!4S jjr"S0 4S \#S\$4S! jjr%SS\S\!4S" jjr&S# r'0 4S$\4S% jjr(0 4S$\S\\)   4S& jjr*0 4S$\S\)4S' jjr+SS( jr,0 4S	\S\-4S) jjr.0 4S\/4S* jjr0S+ r1SS\4S, jjr2S0 4S-\#4S. jjr3S0 4S-\#4S/ jjr4SS0\54S1 jjr6SSS0 4S	\S2\
S3\
4S4 jjr7S\\8   4S5 jr9SS\4S6 jjr:S0 4S	\S3\
S\;4S7 jjr<0 4S	\S\=4S8 jjr>SS9\?S\S\=4S: jjr@S0 4S \#S\A4S; jjrBS< rC0 4S\D4S= jjrES>SS0 4S	\S?\S2\
S3\
S\\F   4
S@ jjrGS>SS0 4S	\S2\
S3\
4SA jjrHSSS0 4S	\S2\
S3\
4SB jjrISS\S\F4SC jjrJSS0 4S	\S2\
S3\
S\\K   4SD jjrLSSS0 4SE\S	\S2\
S3\
4SF jjrMSSS0 4S	\S2\
S3\
4SG jjrNSSH\?S\S\K4SI jjrOSSS0 4S$\S2\
S3\
S\\P   4SJ jjrQSSS0 4S$\S2\
S3\
S\\P   4SK jjrRS0 4S$\SL\SSM\SN\S\P4
SO jjrTSP\4SQ jrUSR rVSSS\?S0\5S\P4ST jjrWS0 4S	\SU\XSV\YSL\SSW\Z4
SX jjr[0 4SY\\\   4SZ jjr]0 4SY\\\   4S[ jjr^S0 4S	\SU\XSV\YSL\SSW\Z4
S\ jjr_0 4S	\S]\S4S^ jjr`SS0 4SE\S	\SU\XSV\YSL\ZSW\Z4S_ jjraSS0 4SE\S	\SU\XSV\YSL\ZSW\Z4S` jjrbSP\4Sa jrcSSb\?S\S\d4Sc jjreS0 4SE\S	\4Sd jjrfS0 4SE\S	\4Se jjrgSSS0 4S	\S2\
S3\
S\\d   4Sf jjrhSSS0 4S	\S2\
S3\
S\\d   4Sg jjriSSS0 4S	\S2\
S3\
4Sh jjrjSSS0 4S	\S2\
S3\
4Si jjrkS0 4SE\S	\4Sj jjrlS0 4Sk\\   S	\4Sl jjrm0 4SY\\n   4Sm jjroS0 4S	\4Sn jjrp0 4S$\SL\SSo\Sp\S\q4
Sq jjrrSSr\?S0\5S\q4Ss jjrsS0 4St\tS	\4Su jjruSSv\?S\4Sw jjrv0 4S	\4Sx jjrwS0 4S \#S\\x   4Sy jjryS0 4S \#S\z4Sz jjr{0 4S	\S\\|   4S{ jjr}SS\\|   4S| jjr~SS\S\\|   4S} jjr0 4S	\S$\4S~ jjr0 4S$\4S jjr0 4S	\S$\SL\S4S jjr0 4S$\SL\S4S jjrSS0\54S jjrSSSS0 4S$\S	\S2\
S3\
S\\   4
S jjrSS\?S\S\4S jjrS r/ S0 SS4S jr0 4S	\4S jjrSS\?S\S\4S jjr0 4S	\SL\SS\4S jjr0 4S	\SL\SS\4S jjrSSS0 4S	\S2\
S3\
4S jjrSS\4S jjrSSS0 4S	\S2\
S3\
4S jjrSSS0 4S	\S2\
S3\
4S jjrS rS rSSS0 4S$\S2\
S3\
S\\   4S jjrSS\?S0\5S\4S jjrS rS0 4S\S	\4S jjr0 4S jrSS0 4S	\S2\
S3\
4S jjrSSS0 4S	\S2\
S3\
4S jjrSS\4S jjr0 4S	\S\4S jjrSS\?S\S\4S jjrS0 4S	\SV\YS\d4S jjr0 4S	\S\4S jjrS0 4S \#S\4S jjrSSt\?S\S\4S jjr0 4S	\S\4S jjr0 4S$\S\4S jjrSS\?S0\5S\S\4S jjrSSS0 4S \#S2\
S3\
S\\x   4S jjrS$\tS\S\S\S\?S\4S jrSrU =r$ )gate   returnc                 &  > U R                  [        [        U ]  5       0 SS_SS_SS/_SS_S	S
_SS_SS_SSSSSSSSSSSSS.SSSSSSSSSSSSSS.S.SSSSSSSSS.SSSSSSSSS.S.SSS.S._S0 SS _SS_SS_S S_S!S_S"S_S#S_S$S_S%S_S&S_S'S_S(S_S)S_S*S_S+S_S,S-_S.S-_0 S/S_S0S_S1S_S2S_S3S_S4S_S5S-_S6S_S7S_S8S_S9S_S:S_S;S_S<S-_S=S-_S>S_S?S-_E0 S@S-_SAS_SBS_SCS-_SDS_SES_SFSG_SHS_SIS_SJS_SKS_SLS_SMS_SNS_SOS-_SPS-_SQS_E0 SRS_SSS_STS_SUS_SVS-_SWS-_SXS_SYS_SZS_S[S_S\S_S]S_S^S_S_S_S`S-_SaS_SbS_E0 ScS_SdS_SeS_SfS_SgS_ShSG_SiS-_SjS_SkS_SlS-_SmS_SnS_SoS_SpS_SqS_SrS_SsS_ESSS-SSSSSSS-SS-SSSt.E_SuSvSwSx00SvSxSxSy.0SvSxSxSxSxSxSxSxSxSxSxSz.
0SvSxSxSxSxSxSxSxSxS{.0SvSxSxS|.0SvSxSxSxSxSxSxSxSxSxSxSxSxSxS}.0SvSxSxSxSxSxSxSxSxS~.0SvSxSxSxSxSxSxSxSxSxSxSxSxS.0SvSxSxSxSxS.0SvSxSxSxSxSxS.0S.
SSxS.SSx0S.0 SSx_SSx_SSx_SSx_SSx_SSx_SS_SS_SS_SS_SSx_SSx_SS_SSx_SSx_SSx_SSSSxS.S.SSSSS.SSSSS.SS0SS0S.0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSS.SS0S.SxSxSxSxSxSxSxSxSxSxS.
SSxSSSSSS.SSSSS.SS0S.0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSSSSSSS.
ESSSSSSSSS.SSS.SS0S.SxSxS.SxSxS.S.0 SSx_SSx_SSx_SSx_SSx_SSx_SSx_SSx_SSx_SSx_SSx_SSx_SSx_SSx_SSx_SSx_SSx_0 SSx_SSx_SSx_SSx_SSx_SSx_SSx_SSx_SSx_SS_SS_SS_SS_SS_SS_SS_SSx0SSSSS.S.SSSSSSSSSSSSS.SSSSSS.SSSSS.S.SSSSSSSSSSS.
SSSSS.SSS.S.0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSGS .GSS0SS0GS.0 GSS_GSS_GSS_GSS_GSS_GSS_GS	S_GS
S_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_SSSSSSGS.S.SSSSSSSGS.SSSGS.GSS0S.SvSSSSSSSSSGS.	0GS.S._GSGSGSGSGSGSGSGS GS!GS"GS#GS$GS$GS%._GS&0 GS'GS(_GS)GS*_GS+GS,_GS-GS._GS/GS0_GS1GS2_GS3GS4_GS5GS6_GS7GS8_GS9GS:_GS;GS<_GS=GS>_GS?GS@_GS,GSA_GSBGSC_GSDGSE_GSFGSG_GSHGSIGSJGSKGSL.E_GSMSSGSN._GSOGSPGSQ0_GSRGSSS-S-S GSTGSU0S0 GSVGSV_GSWGSX_GSYGSY_GSZGSY_GS[GS[_GS\GS[_GS]GS^_GS_GS^_GS`GS`_GSaGS`_GSbGSb_GScGSc_GSdGSe_GSfGSf_GSgGSh_GSiGSi_GSjGSk_0 GSlGSm_GSnGSn_GSoGSp_GSpGSp_GSqGSq_GSrGSs_GStGSu_GSvGSv_GSwGSw_GSxGSy_GSzGS{_GS|GS|_GS}GS~_GSGS_GSGS_GSGS_GSGS_EGSGSGSGSGSGSGSGSGSGSGSGSGSGSGS.EGSGSZGSZGS\GS\GS_GS_GSaGSaGScGScGS.GSGSGSGSGSGS.SSSGSGSSGSGSGSGSGSRGSRGS.GS/ GSQ0SYGSGSGS/00SYGSGS/00GS._GSSSSSS SSS SSSS-GS.S-S-SSS-SSGS.GSGS0SGSS GSS-GS.S-SS-SGS.SSS-GSS-GS.S SSS-GSGSS S S-GS.GSGS0GS.	GSGS0SS-SSSGS.GS.GSGS0S-S GS.GSS-0S-S GSGS.GSGS0GS.GSGS0GSGS0GS.GSGS0GSGS0GS.GS._GS[        _SSvSU R                  GS5      U R                  GS5      U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      //U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      //GS.GS.SGSSU R                  GS5      U R                  GS5      U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      //U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      /U R                  GS5      U R                  GS5      //GS.GS.GS.0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS [        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS	[        _0 GS
[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _E0 GS[        _GS[         _GS[         _GS["        _GS[$        _GS [$        _GS![        _GS"[        _GS#[        _GS$[        _GS%[        _GS&[        _GS'[        _GS([        _GS)[        _GS*[$        _GS+[$        _E0 GS,[        _GS-[        _GS.[        _GS/[        _GS0[        _GS1[        _GS2[        _GS3[        _GS4[        _GS5[        _GS6[&        _GS7[        _GS8[         _GS9[        _GS:[        _GS;[        _GS<[        _E0 GS=[        _GS>[        _GS?[        _GS@[        _GSA[        _GSB[        _GSC[        _GSD[        _GSE[        _GSF[        _GSG[        _GSH[        _GSI[        _GSJ[        _GSK[        _GSL[        _GSM["        _E[        [        [        [        [        [        [        [        [        [        [        GSN.E0 GSO.GSP.E5      $ (Q  Nidr?   nameGate	countriesKR	rateLimit2   versionv4	certifiedTprourlszOhttps://github.com/user-attachments/assets/64f988c5-07b6-4652-b5c1-679a6bf67c85z.https://www.gate.com/docs/developers/apiv4/en/zhttps://gate.comzhttps://api.gateio.ws/api/v4)walletfuturesmargindeliveryspotoptionssub_accountsearn)withdrawalsrO   rP   rQ   rR   rS   rT   subAccountsunifiedrebaterV   accountloan)publicprivatez%https://api-testnet.gateapi.io/api/v4)rP   rR   rT   rS   rO   rQ   rU   r[   z#https://www.gate.com/share/CCXTGATEg?)urldiscount)logodocwwwapitestreferralhasCORSrS   rQ   swapfutureoption	addMarginborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelOrdercancelOrderscancelOrdersForSymbolscreateMarketBuyOrderWithCostcreateMarketOrdercreateMarketOrderWithCostFcreateMarketSellOrderWithCostcreateOrdercreateOrderscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopLossOrdercreateStopMarketOrdercreateStopOrdercreateTakeProfitOrdercreateTriggerOrder	editOrderfetchBalancefetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchLeveragesfetchLeverageTiersfetchLiquidationsfetchMarginAdjustmentHistoryfetchMarginModefetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMySettlementHistoryfetchMyTradesfetchNetworkDepositAddress
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsHistoryfetchPremiumIndexOHLCVfetchSettlementHistoryfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFees)fetchTransactionFeesfetchUnderlyingAssetsfetchVolatilityHistoryfetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMarginsandboxsetLeveragesetMarginModesetPositionModesignIntransferwithdrawrd   getcurrency_chains   )
currencieshistory_loan_rate)
r   zcurrencies/{currency}currency_pairscurrency_pairs/{currency_pair}tickers
order_booktradescandlestickstimeinsurance_history)zuni/currency_pairsz"uni/currency_pairs/{currency_pair}loan_margin_tiersr   r   funding_bookzcross/currencieszcross/currencies/{currency})r   r   ){settle}/contracts{settle}/contracts/{contract}{settle}/order_book{settle}/trades{settle}/candlesticksz{settle}/premium_index{settle}/tickersz{settle}/funding_rate{settle}/insurancez{settle}/contract_statsz#{settle}/index_constituents/{index}z{settle}/liq_orders{settle}/risk_limit_tiers)r   r   r   r   r   r   r   r   )underlyingsexpirations	contractszcontracts/{contract}settlementszsettlements/{contract}r   r   zunderlying/tickers/{underlying}r   zunderlying/candlesticksr   )uni/currenciesuni/currencies/{currency}zdual/investment_planzstructured/products)collateral/currenciesmulti_collateral/currenciesmulti_collateral/ltvmulti_collateral/fixed_ratemulti_collateral/current_rate)
rO   rY   rS   rQ   
flash_swaprP   rR   rT   rV   r\      )rW   pushzwithdrawals/{withdrawal_id})postdeletedeposit_addressrW   depositssub_account_transfersorder_statuswithdraw_statussub_account_balancesg      @sub_account_margin_balancessub_account_futures_balances!sub_account_cross_margin_balancessaved_addressfeetotal_balancesmall_balancesmall_balance_historyr   )	transfersr   sub_account_to_sub_accountr   )r   r   )rU   zsub_accounts/{user_id}sub_accounts/{user_id}/keys!sub_accounts/{user_id}/keys/{key})rU   r  zsub_accounts/{user_id}/lockzsub_accounts/{user_id}/unlockr  )r   r   putr   accountsgUUUUUU?
borrowabletransferabletransferablesbatch_borrowableloansloan_recordsinterest_records
risk_unitsunified_modeestimate_ratecurrency_discount_tiersr   zleverage/user_currency_configleverage/user_currency_settingaccount_modeg*@)r	  portfolio_calculatorr  collateral_currenciesr  )r   r   r  )
r   	batch_feer  account_bookopen_ordersordersorders/{order_id}	my_tradesprice_ordersprice_orders/{order_id}g?g?)batch_orderscross_liquidate_ordersr  cancel_batch_orderscountdown_cancel_allamend_batch_ordersr  )r  r  r  r  r  )r   r   r   patchr  funding_accounts
auto_repayzuni/estimate_rate	uni/loanszuni/loan_recordszuni/interest_recordszuni/borrowablezuser/loan_margin_tierszuser/accountloans/{loan_id}loans/{loan_id}/repaymentloan_records/{loan_record_id})
r  zcross/accountszcross/account_bookcross/loanszcross/loans/{loan_id}cross/repaymentszcross/interest_recordszcross/transferablezcross/estimate_ratezcross/borrowable)r#  r$  zleverage/user_market_settingr	  merged_loansr&  r(  r)  )r%  r'  )r   r   r!  r   )r  r  )r  zorders/preview{settle}/accounts{settle}/account_book{settle}/positions{settle}/positions/{contract}z'{settle}/dual_comp/positions/{contract}{settle}/ordersz{settle}/orders_timerange{settle}/orders/{order_id}{settle}/my_tradesz{settle}/my_trades_timerange{settle}/position_close{settle}/liquidatesz{settle}/auto_deleveragesz{settle}/feez{settle}/risk_limit_table{settle}/price_orders {settle}/price_orders/{order_id}${settle}/positions/{contract}/margin&{settle}/positions/{contract}/leverage({settle}/positions/{contract}/risk_limitz{settle}/positions/cross_modez'{settle}/dual_comp/positions/cross_modez{settle}/dual_modez.{settle}/dual_comp/positions/{contract}/marginz0{settle}/dual_comp/positions/{contract}/leveragez2{settle}/dual_comp/positions/{contract}/risk_limitz{settle}/batch_ordersz{settle}/countdown_cancel_allz{settle}/batch_cancel_ordersz{settle}/batch_amend_ordersz{settle}/bbo_orders)r/  r0  r4  r5  )r+  r,  r-  r.  r/  r0  r1  r2  r3  z{settle}/settlementsr4  r5  )r6  r7  r8  r/  r4  )r   r   r   )
my_settlementsr  r  	positionszpositions/{contract}position_closer  r  r  mmp)r  r  r<  z	mmp/reset	uni/lendszuni/lend_recordszuni/interests/{currency}zuni/interest_status/{currency}z	uni/chartzuni/ratezstaking/eth2/rate_recordsdual/ordersstructured/orderszstaking/coinszstaking/order_listzstaking/award_listzstaking/assetsr   r   )r=  zstaking/eth2/swapr>  r?  zstaking/swapzuni/interest_reinvest)r   r   r  r!  collateral/orderszcollateral/orders/{order_id}zcollateral/repay_recordscollateral/collateralszcollateral/total_amountzcollateral/ltvmulti_collateral/ordersz"multi_collateral/orders/{order_id}multi_collateral/repaymulti_collateral/mortgagezmulti_collateral/currency_quotar   r   r   r   r   )r@  zcollateral/repayrA  rB  rC  rD  )detail	main_keys
rate_limit
stp_groupsstp_groups/{stp_id}/userszstp_groups/debit_fee	debit_fee)rH  rI  rJ  rI  )	zagency/transaction_historyzagency/commission_historyzpartner/transaction_historyzpartner/commission_historyzpartner/sub_listzbroker/commission_historyzbroker/transaction_historyz	user/infozuser/sub_relation)rW   rO   rX   rY   rS   rQ   r   rP   rR   rT   rV   r\   r[   rZ   
timeframes10s1m5m15m30m1h2h4h8h1d7d)rL  rM  rN  rO  rP  rQ  rR  rS  rT  rU  rV  1wcommonCurrenciesORTXREATORSASSASSF88MPHMPHAXISAXISDEFIBIFIBITCOINFILEBOXDEFIBOXBYNBEYONDFIEGGGOOSEFINANCEGTCGAMECOMGTC_HT
GAMECOM_HTGTC_BSCGAMECOM_BSCHITHITCHAINMMMILLIONMORPHERPOINT	GATEPOINTRAIRAIREFLEXINDEXREDRedLangSUPERBITCOINTRINITYNETWORKCREDITVAIOTTRACO)SBTCTNCVAITRACrequiredCredentials)apiKeysecretheaderszX-Gate-Channel-IdccxtrT   r   
expirationiQ BTCBRC20BTCBRCETHERC20TRXTRC20HECOHTHRC20BSCBEP20SOLMATICOPTIMISMOPETHADAAVAXCAVAX_CNEARARBONEARBEVMBASEBASEEVMSUICRONOSCROAPTSCROLL	SCROLLETHTAIKOTAIKOETHHYPEALGOLINEALINEAETHBLASTBLASTETHXLMRSKRBTCTONMNTCELOHBARZKSERAKLAYEOSACAXTZEGLDGLMR	AURORAEVMKONETGTEVMKSMSMOKTDOTSMLUNC)r  r  r  r  r  r  r  AURORAKON	GATECHAINKUSAMAOKCPOLKADOTLUNAOP)r  r  r  r  r  r  r  r  r  POLYGONPOLgtciocpocfok)ri  IOCPOPOCFOKcross_marginrP   rR   )fundingrS   rQ   r  crossisolatedri   rj   rP   rR   rk   rT   typesrS   ri   rj   rk   settlementCurrenciesusdtbtc)timeDifferenceadjustForTimeDifferencesandboxModeunifiedAccountrw   !createMarketBuyOrderRequiresPricenetworksnetworksByIdtimeInForceaccountsByTyper   ri   rj   features)r  r  r  GTD)
marginModetriggerPricetriggerDirectiontriggerPriceTypestopLossPricetakeProfitPriceattachedStopLossTakeProfitr  hedgedtrailingicebergselfTradePreventionleveragemarketBuyByCostmarketBuyRequiresPricemax(        )r  limitdaysBack	untilDayssymbolRequired)r  triggerr  r  d   )r  r  r  r  r  )r  r  r  r  r  r  daysBackCanceledr  r  )	r   rw   rx   r   r   r   fetchOrdersr   r   extendsdefault)lastmarkindex)r  r  
   )r  r  r  )r  r  r    )r  rw   rx   r   r   r   r   forDerivatives)linearinverse)r  rS   r
  ri   rj   precisionModez0.0020z1.5z0.001853z0.001756z0.00165z12.5z0.0015525z0.0014575z0.00135200z0.00125500z0.001151250z0.001052500z0.000953000z0.0008560000.0007511000z0.0006520000z0.000554000075000z0.00195)makertaker)	tierBasedfeeSide
percentager  r  tiersbasez0.00.0005z0.0000z-0.00005z-0.00008z-0.01000z-0.01002z-0.01005z-0.02000z-0.02005z0.00050z0.00048z0.00046z0.00044z0.00042z0.00040z0.00038z0.00036z0.00034z0.00032z0.00030)tradingri   INVALID_PARAM_VALUEINVALID_PROTOCOLINVALID_ARGUMENTINVALID_REQUEST_BODYMISSING_REQUIRED_PARAMBAD_REQUESTINVALID_CONTENT_TYPENOT_ACCEPTABLEMETHOD_NOT_ALLOWED	NOT_FOUNDAUTHENTICATION_FAILEDINVALID_CREDENTIALSINVALID_KEYIP_FORBIDDEN	READ_ONLYINVALID_SIGNATUREMISSING_REQUIRED_HEADERREQUEST_EXPIREDACCOUNT_LOCKED	FORBIDDENSUB_ACCOUNT_NOT_FOUNDSUB_ACCOUNT_LOCKEDMARGIN_BALANCE_EXCEPTIONMARGIN_TRANSFER_FAILEDTOO_MUCH_FUTURES_AVAILABLEFUTURES_BALANCE_NOT_ENOUGHACCOUNT_EXCEPTIONSUB_ACCOUNT_TRANSFER_FAILEDADDRESS_NOT_USEDTOO_FASTWITHDRAWAL_OVER_LIMITAPI_WITHDRAW_DISABLEDINVALID_WITHDRAW_IDINVALID_WITHDRAW_CANCEL_STATUSINVALID_PRECISIONINVALID_CURRENCYINVALID_CURRENCY_PAIRPOC_FILL_IMMEDIATELYORDER_NOT_FOUNDCLIENT_ID_NOT_FOUNDORDER_CLOSEDORDER_CANCELLEDQUANTITY_NOT_ENOUGHBALANCE_NOT_ENOUGHMARGIN_NOT_SUPPORTEDMARGIN_BALANCE_NOT_ENOUGHAMOUNT_TOO_LITTLEAMOUNT_TOO_MUCHREPEATED_CREATIONLOAN_NOT_FOUNDLOAN_RECORD_NOT_FOUNDNO_MATCHED_LOANNOT_MERGEABLE	NO_CHANGEREPAY_TOO_MUCHTOO_MANY_CURRENCY_PAIRSTOO_MANY_ORDERSTOO_MANY_REQUESTSMIXED_ACCOUNT_TYPEAUTO_BORROW_TOO_MUCHTRADE_RESTRICTEDUSER_NOT_FOUNDCONTRACT_NO_COUNTERCONTRACT_NOT_FOUNDRISK_LIMIT_EXCEEDEDINSUFFICIENT_AVAILABLELIQUIDATE_IMMEDIATELYLEVERAGE_TOO_HIGHLEVERAGE_TOO_LOWORDER_NOT_OWNEDORDER_FINISHEDPOSITION_CROSS_MARGINPOSITION_IN_LIQUIDATIONPOSITION_IN_CLOSEPOSITION_EMPTYREMOVE_TOO_MUCHRISK_LIMIT_NOT_MULTIPLERISK_LIMIT_TOO_HIGHRISK_LIMIT_TOO_lOWPRICE_TOO_DEVIATEDSIZE_TOO_LARGESIZE_TOO_SMALLPRICE_OVER_LIQUIDATIONPRICE_OVER_BANKRUPTORDER_POC_IMMEDIATE)INCREASE_POSITIONCONTRACT_IN_DELISTINGINTERNALSERVER_ERRORTOO_BUSYCROSS_ACCOUNT_NOT_FOUNDRISK_LIMIT_TOO_LOWAUTO_TRIGGER_PRICE_LESS_LASTAUTO_TRIGGER_PRICE_GREATE_LASTPOSITION_HOLDINGUSER_LOAN_EXCEEDED)exactbroad)fees
exceptions)deep_extendsuperr?   describer<   parse_numberr3   r2   r-   r.   r/   r1   r5   r:   r;   r6   r4   r8   r7   r0   )self	__class__s    Q/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/async_support/gate.pyr  gate.describe!   sb#   dD : < b?
&b?
Fb?
 $b?
 	b?

 tb?
 b?
 4b?
 iG) #A#A"@$B >#A(F >	 (F"@#A"@$B >#A'E#A"@ >#A > : $K$K#J G"I"I(O#J	 $K$K#J G"I"I(O#J	 . A #k9b?
D  ddd $d 	d
 $d $d Td $Td 'd "4d td d )$d /d $Td  ,U!d" 0#d$ t%d& 'd( &t)d* (+d, '-d. &t/d0 (1d2 "43d4 (5d6 %d7d8 T9d: ;d< &t=d> +E?d@ )%AdB $TCdD 'EdF (GdH "4IdJ &tKdL (MdN 1$OdP  QdR *:SdT +DUdV &tWdX #DYdZ *4[d\ $T]d^ t_d` "4adb *5cdd +Eedf tgdh  idj !$kdl %dmdn $Todp /qdr "5sdt +Dudv wdx !$ydz &t{d| +D}d~  d@ -dAdB dCdD $UEdF +DGdH "4IdJ tKdL #DMdN dOdP !$QdR  SdT '
UdV $UWdX !$YdZ ([d\ )%]d^ )$_d` tadb cdd Tedf tgdh "4idj #Dkdl )-)-*/$( $$('+#!&#'  GdEb?
N  -q  *+12   *+56./>?'(*+&',-$%12  23BC12./>?,-01;<	  ./*+ # 23=>34/0566701562378CD349:  $ 23=>34/05601239:	 ! +,+,)*45+,67*+'(?@,-78&'  " ./9:4534	  56;<45;<=> Ek` ,.$%!
 :1#$ -q )1  '  4Q	 
 +A  .q  3C  :3  ;C  @  ,Q  "1  ,S  ,Q  4Q   #A! & *-58:=-.	!'8 -069;>AD	  -0;>;>=@	! @  @#!$* & ('  +G  ,W	 
 /  $W  +G  /  )'  +G  ,W  6w  0  <W  =g   +G! & &.4;>E5<,3! +G 5 B $%)*(),-+,&'12)*,-78  -067&)3:4;25,/! '.18,37>	# 0"; D & *G  /  )'	 
 +G  0  (  /  3G  -g  5g  +G  $W  .w  8   +G! " <W# $ +2.529+25<076=293:077 < +2)0<C%,,39@+207	! 07=D"
 .w#Y/d '(12 
 '(./!	# / 3Q  1!  <Q	 
 Fq  .q  8  9!  1!  ;A  6q  21  8  +A  8   4Q! " ?# &!BA!Da! G! <Q	!
 Fq! 1!! Ma! OPQ! QRS! .s! 4S! <S! ;C! :3! 23!  4S!!& 9!  07:A5<@G	#S/ d 295<29=D/6:A297>3:4;5<@G  ELFMHO/65<! 07:A5<@G	#-!> /6(/,3)04;.5&-18)0#*  '.4;#*)0	! '.18#' 2 ' .  7  3G	 
 =g  (  '  8  *7  0  ,W  1'  1'  -g  -g   8! & *118+218,3! 4W  ("; D / :G  7  5g	 
 6w  -g  6w  A'  5g  8  >w  4W  :7  3G  :7   <W! & 29076=7>6=9@!'< '.)0*1*19@4;)0  +29@)0! 8# ( :A9@;B:A079@:A)018
 Ot[bOb?
T Ub?
r  !z!v! ! 
	!
 ! y! z! ~! y! ,! =! z! i! y! !  '!!" y#!$ '-+!sb?
` "$ab?
h #Vib?
n "#+0$"& %  6:959X9 59 U	9
 59 U9 D9 T9 59 U9 59 W9 9 59 X9  F!9" h#9$ I%9& 5'9( e)9* 5+9, 5-9. k/90 Z192 F394 F59: Z;9< Z=9> 5?9@ 6A9B 5C9D 5E9H FI9J FK9N '"   !"")"!(%  '"q9v ""$"$!#"$&"! !      &"&$2+ (%(( *'(# A! #.% #.%[rob?
T #&*(,,0,0)-+/6:#'#'"&#(	( #($)#'/3$)+/26)$. r% '+!%$(%'*/& ',#'$)*.	# '+#'$)!$*/( $(&*#'$)!$%'$(,0*/	*  #u=~ y  &&+$($(%)-$ r% ',%)&
 %e( ',%)!%*  #3#> "#3 "#3 	 "#3 "#3 	OoUb?
t Yub?
z "&$"&!..w7!..w7 "..s3T5F5Fw5OP!..u5t7H7H7ST!..s3T5F5Fy5QR!..s3T5F5Fy5QR!..v68I8I)8TU!..t4d6G6G	6RS!..t4d6G6G	6RS!..u5t7H7H7ST!..u5t7H7H7ST!..v68I8I)8TU!..v68I8I)8TU!..v68I8I)8TU!..v68I8I)8TU!..w79J9J99UV!..w79J9J99UV!..w79J9J99UV!..w79J9J99UV#"( "..s3T5F5Fw5OP!..u5t7H7H7ST!..s3T5F5Fy5QR!..s3T5F5Fy5QR!..v68I8I)8TU!..t4d6G6G	6RS!..t4d6G6G	6RS!..u5t7H7H7ST!..u5t7H7H7ST!..v68I8I)8TU!..v68I8I)8TU!..v68I8I)8TU!..v68I8I)8TU!..w79J9J99UV!..w79J9J99UV!..w79J9J99UV!..w79J9J99UV#"+(/b "&%"&!..u5!..x8 "..s3T5F5Fx5PQ!..u5t7H7H7TU!..s3T5F5Fz5RS!..s3T5F5Fz5RS!..v68I8I*8UV!..t4d6G6G
6ST!..t4d6G6G
6ST!..u5t7H7H7TU!..u5t7H7H7TU!..v68I8I*8UV!..v68I8I*8UV!..v68I8I*8UV!..v68I8I*8UV!..w79J9J:9VW!..w79J9J:9VW!..w79J9J:9VW!..w79J9J:9VW#"( "..s3T5F5Fy5QR!..u5t7H7H7ST!..s3T5F5Fy5QR!..s3T5F5Fy5QR!..v68I8I)8TU!..t4d6G6G	6RS!..t4d6G6G	6RS!..u5t7H7H7ST!..u5t7H7H7ST!..v68I8I)8TU!..v68I8I)8TU!..v68I8I)8TU!..v68I8I)8TU!..w79J9J99UV!..w79J9J99UV!..w79J9J99UV!..w79J9J99UV#")'.c`Fa):a&
a '
a +J	a
 -.?a ":a +Ja %ja )*a  a ,-@a *+>a "#6a #$7a  !1a  ()<!a" ./B#a$ &':%a& %&6'a(  !1)a* ,]+a, )*:-a. //a0 -m1a2 1-3a4 12C5a6 (7a8 2=9a: ';a<  1=a> ,]?a@ ,-AAaB *=CaD 5mEaF (GaH '	IaJ ,YKaL +,DMaN &}OaP *=QaR #LSaT &|UaV *<WaX )*;YaZ +L[a\ 01B]a^ (_a` &|aab (cad %meaf ,]gah &}iaj $]kal  man %moap .|qar &|sat ():uav ),wax +Myaz '(9{a| %&7}a~ *=a@ ))AaB *=CaD -.?EaF ,\GaH (IaJ 'KaL &}MaN %mOaP ,]QaR .}SaT (UaV %lWaX &}YaZ .}[a\ *=]a^ )-_a` ),aab %lcad %leaf -lgah *<iaj *+Ckal *6-: 4$8 4/<*44@6B(2*4AaD Gd{b?
 b b	    enablec                 H   > [         [        U ]  U5        XR                  S'   g )Nr  )r  r?   set_sandbox_moderT   )r  r  r  s     r  r  gate.set_sandbox_mode  s    dD*62&,]#r  c                 T  #    U R                  U R                  S5      nUcO   U R                  U5      I Sh  vN nU R                  US0 5      nU R	                  US5      S:H  U R                  S'   U R                  S   $  NH! [
         a  nSU R                  S'    SnAN/SnAff = f7f)a`  
:param dict [params]: extra parameters specific to the exchange API endpoint
returns unifiedAccount so the user can check if the unified account is enabled

https://www.gate.com/docs/developers/apiv4/#get-account-detail

:returns boolean: True or False if the enabled unified account is enabled or not and sets the unifiedAccount option if it is None
r  Nkeymode   F)	safe_boolrT   privateAccountGetDetail	safe_dictsafe_integer	Exception)r  paramsr  responseresultes         r  load_unified_statusgate.load_unified_status  s      6FG!7 "&!=!=f!EE%<151B1B661RVW1W-. ||,-- F  716-.7s>    B(B B 9B 1B( B 
B%B B( B%%B(c                 @   #    U R                  U5      I S h  vN $  N7fN)privateUnifiedPutUnifiedMode)r  r  s     r  upgrade_unified_trade_account"gate.upgrade_unified_trade_account  s     66v>>>>s   c                 d   #    U R                  U5      I Sh  vN nU R                  US5      $  N7f)a;  
fetches the current integer timestamp in milliseconds from the exchange server

https://www.gate.com/docs/developers/apiv4/en/#get-server-current-time

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int: the current integer timestamp in milliseconds from the exchange server
Nserver_time)publicSpotGetTimer  r  r  r  s      r  
fetch_timegate.fetch_time  s4      //77   =99 8s   0.0symbolc                     SnUnUR                  S5      nUR                  S5      nUR                  S5      nS nU R                  US5      nUR                  S5      S:  a  U R                  US5      nOU R                  US5      nUSS	 nU R                  US5      n	U R                  US
5      n
U R                  U5      nU R	                  U5      n0 SUS-   U-   S-   S-   U-   S-   U	-   S-   U
-   _SUS-   U-   S-   U-   S-   U-   S-   U	-   S-   U
-   _SU_SU_SU_SU_SU_SU_SS_SS_SS _SS _SS_SS_SS_SS_SS_SU R                  S 5      UUU
S!:X  a  S"OS#U R                  U	5      U R                  S 5      S S$.S S S%.S S S%.S S S%.S&.S S'.	E$ )(NUSDT-/_r   r   r        rC   20r  :r$  quotesettlebaseIdquoteIdsettleIdactiveFtyperk   r  r  rS   ri   rj   TrQ   1Ccallr  amountpriceminr  )r  r  cost)	contractcontractSizeexpiryexpiryDatetime
optionTypestrike	precisionlimitsinfo)splitsafe_stringfindconvert_expire_date	parse8601r  )r  r  r  r  optionParts
symbolBasemarketIdBaser$  r  r  r  datetime	timestamps                r  create_expired_option_market!gate.create_expired_option_market  s   ll3'\\#&
||C(!!+q1;;sb ##J2D##L!4DAa[F!!+q1%%k15
++F3NN8,	+
$*u$s*T1F:S@6ICOR\\+
dSj5(3.7#=FLvUX[[^hh+
 D+
 U	+

 f+
 d+
 u+
 +
 e+
 H+
 d+
 t+
 E+
 E+
 e+
  d!+
" e#+
$  --c2&%/3%6&U''/++C0  
  
   U+
 +	
r  NmarketIdmarket	delimiter
marketTypec                    > US L=(       a/    UR                  S5      S:  =(       d    UR                  S5      S:  nU(       a   XR                  ;  a  U R                  U5      $ [        [        U ]  XX45      $ )Nz-Cr  z-P)r  markets_by_idr  r  r?   safe_market)r  r  r  r  r  isOptionr  s         r  r  gate.safe_market  sh    D(hd0Cb0H/ghmm\`NadfNfX););;44X>>T4,XyUUr  c                   #    U R                   S   (       a  U R                  5       I Sh  vN   U R                  S5      (       a  U R                  5       I Sh  vN   / nU R	                  U R                   S5      nU R                  US/ SQ5      n[        S[        U5      5       H  nXE   nUS:X  a"  UR                  U R                  U5      5        M/  US	:X  a"  UR                  U R                  U5      5        MW  US
:X  a"  UR                  U R                  U5      5        M  US:X  d  M  UR                  U R                  U5      5        M     [        R                  " U6 I Sh  vN nU R                  U5      $  GNR GN' N7f)a'  
retrieves data on all markets for gate

https://www.gate.com/docs/developers/apiv4/en/#list-all-currency-pairs-supported                                     # spot
https://www.gate.com/docs/developers/apiv4/en/#list-all-supported-currency-pairs-supported-in-margin-trading         # margin
https://www.gate.com/docs/developers/apiv4/en/#list-all-futures-contracts                                            # swap
https://www.gate.com/docs/developers/apiv4/en/#list-all-futures-contracts-2                                          # future
https://www.gate.com/docs/developers/apiv4/en/#list-all-the-contracts-with-specified-underlying-and-expiration-time  # option

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
r  NFr   r  r  r   rS   ri   rj   rk   )rT   load_time_differencecheck_required_credentialsr  r  	safe_listrangelenappendfetch_spot_marketsfetch_swap_marketsfetch_future_marketsfetch_option_marketsasynciogatherarrays_concat)r  r  rawPromisesfetchMarketsOptionsr  ir  resultss           r  fetch_marketsgate.fetch_markets  sJ     <<12++---**511**,,,"nnT\\>J2G=abq#e*%AJV# ""4#:#:6#BCv%""4#:#:6#BCx'""4#<#<V#DEx'""4#<#<V#DE &  44!!'**) .," 5s:   (FE<-FE?CF,:F&F'F?FFc                   #    U R                  U5      nU R                  U5      n[        R                  " X#/6 I S h  vN u  pEU R	                  US5      n/ n[        S[        U5      5       GHK  nXX   n	U R                  U	S5      n
U R                  Xj5      nU R                  X5      nU
R                  S5      u  pU R                  U5      nU R                  U5      nU R                  US5      nU R                  USU5      nU R                  U R                  U R                  US5      5      5      nU R                  US5      nU R                  US5      nUS LnU R                  U	S	S
5      nUS:w  a  UOS nUR!                  0 SU
_SUS-   U-   _SU_SU_SS _SU_SU_SS _SS_SS_SU_SS_SS_SS_SUS:H  _SS_SS _S U R                  ["        R$                  " US5      5      U R                  ["        R$                  " US5      5      S S S S S UU R                  U R                  U R                  US 5      5      5      S!.U R                  S"5      U R                  USS#5      S$.U R                  U	S%U5      S S$.S S S$.U R                  US&5      U(       a  U R                  US'5      OS S$.S(.UUS).E5        GMN     U$  GN7f)*NrC   r   r  r   maker_fee_rateamount_precisiontrade_statusr  	buy_startr  r  r  r$  r  r  r  r  r  r  rS   TrQ   ri   Frj   rk   r  tradabler  r  100r  r  r  r   r  min_base_amountmin_quote_amountmax_quote_amountr  r  r  r  r  r  r  r  r  r  r  r  r  r  createdr  )publicMarginGetCurrencyPairspublicSpotGetCurrencyPairsr  r  index_byr  r  r  
safe_valuer  r  safe_currency_coder  parse_precisionsafe_numbersafe_integer_productr  r=   
string_div)r  r  marginPromisespotMarketsPromisemarginResponsespotMarketsResponsemarginMarketsr  r  
spotMarketrC   marginMarketr  r  r  r$  r  takerPercentmakerPercentamountPrecisiontradeStatusr  rQ   buyStart	createdTss                            r  r  gate.fetch_spot_markets)  su    99&A!<<VD4;NN]Dg4h.h+nd;L q#123A,/J!!*d3B??==L%%l?F hhsmOF**62D++G4E++FE:L++F4DlSL"//0D0DTEUEUV\^pEq0rsO**6>BK''
;HT)F00[$OH%-]IMM 3b3$*u,3 3 	3
 $3 &3 73 D3 3 3 &3 3 %3 %3 ;*43  E!3" $#3$  **7+=+=lE+RS**7+=+=lE+RS $"&"-!..t/C/CDDTDTU[]hDi/jk  $005#//
AF!
  $//
<M_#
  $#
  $//8JKOUt//8JK[_$ %e3 3! 4H Y /is   :KJ>JKc                   #    / nU R                  SS5      nU R                  S   (       a  S/n[        S[        U5      5       Ht  nX4   nSU0nU R	                  U R                  Xa5      5      I S h  vN n[        S[        U5      5       H(  nU R                  Xx   U5      n	UR                  U	5        M*     Mv     U$  NK7f)Nri   r   r  r  r   r  )get_settlement_currenciesrT   r  r  publicFuturesGetSettleContractsextendparse_contract_marketr  )
r  r  r  swapSettlementCurrenciescr  requestr  r  parsedMarkets
             r  r  gate.fetch_swap_markets  s     #'#A#A&.#Y <<&(.x$q#678A/2H(G "AA$++gB^__H1c(m,#99(+xPl+ - 9 	 `s   A/B?1B=2AB?c                   #    U R                   S   (       a  / $ / nU R                  SS5      n[        S[        U5      5       Ht  nX4   nSU0nU R	                  U R                  Xa5      5      I S h  vN n[        S[        U5      5       H(  nU R                  Xx   U5      n	UR                  U	5        M*     Mv     U$  NK7f)Nr  rj   r   r   r  )rT   r$  r  r   publicDeliveryGetSettleContractsr&  r'  r  )
r  r  r  futureSettlementCurrenciesr)  r  r*  r  r  r+  s
             r  r  gate.fetch_future_markets  s     <<&I%)%C%CHn%]"q#89:A14H(G "BB4;;wC_``H1c(m,#99(+xPl+ - ; 	 as   A.B>0B<1AB>c                 R   U R                  US5      nUR                  S5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  U5      nU R                  U5      n	U R                  U5      n
U R                  US5      nSnSnUb'  US	-   U	-   S
-   U
-   S-   U R	                  US5      -   nSnOUS	-   U	-   S
-   U
-   nU R                  US5      nU R                  US5      n[
        R                  " SU5      n[
        R                  " SU5      n[
        R                  " UU5      n[
        R                  " UU5      nX:H  nU R                  US5      nUS:X  a  Sn0 SU_SU_SU_SU	_SU
_SU_SU_SU_SU_SS_SS_SUS:H  _SUS:H  _SUS:H  _SS _S!S _S"U_U(       + U R                  S#5      U R                  S$5      U R                  U5      UU R                  U5      S S U R                  S5      U R                  US%5      S&.U R                  US'5      U R                  US(5      S).U R                  US*5      U R                  US+5      S).U R                  U5      U R                  U5      S).S S S).S,.U R                  US-S.5      US/.E$ )0NrD   r  r   r   r  expire_time ri   r  r  r  rj   order_price_deviate
mark_pricer  quanto_multiplierr  rC   r  r$  r  r  r  r  r  r  rS   FrQ   rk   r  Tr  r  r%  z0.0002order_price_roundr  leverage_minleverage_maxr  order_size_minorder_size_maxr	  create_timer  r
  )r  r  r  safe_timestampyymmddr=   
string_sub
string_add
string_mulr  iso8601r  r  )r  r  r  rC   partsr  r  dater$  r  r  r  r  r  priceDeviate	markPriceminMultipliermaxMultiplierminPricemaxPriceisLinearr  s                         r  r'  gate.parse_contract_market  sx   t ff-!!%+""5!,q)&&v.''0((2$$V];
CZ%'#-6<t{{6SU?VVF!JCZ%'#-6F''0EF$$V\:	**3=**3=%%mY?%%mY??''0CD3L2
"2
f2
 D2
 U	2

 f2
 f2
 w2
 2
 J2
 E2
 e2
 J&(2
 jH,2
 jH,2
 d2
  !2
" h#2
$ $|&&x0&&x0 --l;"ll62++C0))&2EF  ++FNC++FNC
  ++F4DE++F4DE
  ,,X6,,X6
  $ 00Mc2
 2	
r  c                 >  #    / nU R                  5       I S h  vN n[        S[        U5      5       GH  nX4   nU R                  0 U5      nXVS'   U R	                  U5      I S h  vN n[        S[        U5      5       GH  nXx   n	U R                  U	S5      n
UR                  S5      nU R                  US5      nU R                  US5      nU R                  U5      nU R                  U5      nUS-   U-   nU R                  U	S5      nU R                  U	S5      nU R                  U	S	5      nU(       a  S
OSnU(       a  SOSnUS-   U-   S-   U R                  U5      -   S-   U-   S-   U-   nU R                  U	S5      nU R                  U	S5      n[        R                  " SU5      n[        R                  " SU5      n[        R                  " UU5      n[        R                  " UU5      nUR                  0 SU
_SU_SU_SU_SU_SU_SU_SU_SS_SS_SS_S S_S!S_SS"_S#S"_S$S"_S%S"_SU R!                  S&5      U R!                  S&5      U R!                  S5      UU R#                  U5      U R!                  U5      UU R!                  S5      U R%                  U	S'5      S(.S S S).U R%                  U	S*5      U R%                  U	S+5      S).U R!                  U5      U R!                  U5      S).S S S).S,.U R                  U	S-5      U	S..E5        GM     GM     U$  GN GN7f)/Nr   
underlyingrD   r  r   r  expiration_timestrike_priceis_callr  Pr  r  r  r  r4  r5  r  rC   r  r$  r  r  r  r  r  r  rk   rS   FrQ   ri   rj   Tr  r  r  z0.0003r7  r  r  r:  r;  r	  r<  r
  )fetch_option_underlyingsr  r  r&  publicOptionsGetContractsr  r  r  r=  r  r>  r=   r?  r@  rA  r  r  rB  r  )r  r  r  r   r  rN  queryr  jr  rC   rC  r  r  r$  r  r  r  r  isCalloptionLetterr  rE  rF  rG  rH  rI  rJ  s                               r  r  gate.fetch_option_marketsc  s     99;;q#k*+A$JKKF+E",,!;;EBBHN 1c(m,!%%ff5"((-))%3**5!4..v6//8e+,,V5FG))&.A;&,s#'-V5
#-3dkk&6IICORXX[^^amm#//8MN ,,V\B	 ' 2 23 E ' 2 23 E"--mYG"--mYG 2"2f2 D2 U	2
 e2 f2 w2 2 H2 E2 e2 E2 e2 d2 d2  !2" d#2$  %!..x8!..x8$($5$5c$:$&*ll6&:"//7","&"3"3C"8!%!1!1&:M!N" $(#'%
 $(#3#3F<L#M#'#3#3F<L#M#
 $(#4#4X#>#'#4#4X#>"
 $(#'!$  $226=I"c2 2+ -W ,f i <
 Cs#   LLAL$L%J3LLc                    #    U R                  5       I S h  vN n/ n[        S[        U5      5       H/  nX   nU R                  US5      nUc  M  UR	                  U5        M1     U$  NP7f)Nr   rD   )publicOptionsGetUnderlyingsr  r  r  r  )r  underlyingsResponser   r  rN  rD   s         r  rS  gate.fetch_option_underlyings  sq     $($D$D$FF q#123A,/J##J7D""4(	 4
 ! Gs   A)A'5A)A)c                    0 nUb3  US   (       a  US   US'   US   (       d  US   US'   XC/$ US   US'    XC/$ US:H  nUS:H  nU(       d  U(       a4  U(       a  S	OS
nU R                  USU5      nU R                  US5      nXS'   XC/$ )a  
@ignore
       Fills request params contract, settle, currency_pair, market and account where applicable
       :param dict market: CCXT market, required when type is None
       :param str type: 'spot', 'swap', or 'future', required when market is None
       :param dict [params]: request parameters
       :returns: the api request object, and the new params object with non-needed parameters removed
       r  rC   rk   r  r  currency_pairri   rj   r  r  )safe_string_loweromit)	r  r  r  r  r*  ri   rj   defaultSettler  s	            r  prepare_requestgate.prepare_request  s     j!&,Tl
#h'(.z(:GH%    ,2$<(    6>DX%Fv*.E//-P684$*!  r  Fc                     U R                  X#5      u  pE0 nU(       d'  Uc  [        U R                  S-   5      eXFS'   US   US'   Xe/$ )  
@ignore
       Fills request params currency_pair, market and account where applicable for spot order methods like fetchOpenOrders, cancelAllOrders
       :param dict market: CCXT market
       :param bool trigger: True if for a trigger order
       :param dict [params]: request parameters
       :returns: the api request object, and the new params object with non-needed parameters removed
       zL spotOrderPrepareRequest() requires a market argument for non-trigger ordersr[   rC   r_  )get_margin_moder2   rC   r  r  r  r  r  rU  r*  s          r  spot_order_prepare_requestgate.spot_order_prepare_request
  sd     !00A
~'  3A  )A  B  B!+I'-d|GO$r  c                 p    U R                  X#5      u  pESU0nUb  U(       a  US   US'   Xe/$ US   US'   Xe/$ )rf  r[   rC   r  r_  )rg  rh  s          r   multi_order_spot_prepare_request%gate.multi_order_spot_prepare_request  s`     !00A
z
 $*4L!  ,2$<(r  c                 b   U R                  U R                  SSS5      nU R                  USSU5      nU R                  USS/5      nUS:X  a  SnOUS:X  a  SnOUS	:X  a  SnU(       a&  US:X  a  S
nUS:X  a  [        U R                  S-   5      eSnU R                  USS5      u  pRU(       a  SnXB/$ )a_  
@ignore
       Gets the margin type for self api call
       :param bool trigger: True if for a trigger order
       :param dict [params]: Request params
       :returns: The marginMode and the updated request params with marginMode removed, marginMode value is the value that can be read by the "account" property specified in gates api docs
       defaultMarginModer  rS   r[   r  r  r  rQ   r3  normalzA getMarginMode() does not support trigger orders for cross marginFgetMarginModer  rY   )safe_string_lower_2rT   ra  r3   rC   handle_option_and_params)r  r  r  ro  r  isUnifiedAccounts         r  rg  gate.get_margin_mode1  s     !44T\\CVXdflm--flIO`a
6L)#<= 'J:%!J2JV#%
^+ +n!noo #'#@#@Zj#k "J##r  c                     U R                  U R                  U0 5      nU R                  X20 5      nUS:X  a  S/OS/nU R                  USU5      $ )Nri   r  r  r  )r  rT   )r  r  methodrT   fetchMarketsContractOptionsrb  s         r  r$  gate.get_settlement_currenciesN  sP    //$,,b9&*oogr&J#%)V^5':<RTabbr  c                   #    U R                  U R                  S5      nUb  0 $ U R                  U5      I Sh  vN nU R                  US5      n0 n[	        S[        U5      5       GHm  nX6   nU R                  US5      nU R                  U5      n	U R                  USU5      (       a  SOSn
U R                  US/ 5      n0 n[	        S[        U5      5       H{  nX   nU R                  US	5      nU R                  U5      nUUUSU R                  US
5      (       + U R                  US5      (       + SU R                  S5      SSS.SSS.S.S.	UU'   M}     U R                  UU	U R                  US	5      U
U R                  US5      (       + U R                  US
5      (       + U R                  US5      (       + SUU R                  S5      US.5      XY'   GMp     U$  GN7f)a  
fetches all available currencies on an exchange

https://www.gate.com/docs/developers/apiv4/en/#list-all-currencies-details

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
	apiBackupNcurrencyr   T	leveragedcryptochainsrD   deposit_disabledwithdraw_disabledz0.0001r  )depositr   )	r  rC   networkr  r  r   r   r  r  delisted)rC   coderD   r  r  r  r   r   r  r  r  )r  rN   publicSpotGetCurrenciesr  r  r  r  r  is_leveraged_currencyr  network_id_to_coder  r  safe_currency_structure)r  r  r{  r  indexedCurrenciesr  r  entry
currencyIdr  r  r  r  rV  chain	networkIdnetworkCodes                    r  fetch_currenciesgate.fetch_currenciesT  s     OODII{;	 I55f==N !MM(J?q#h-(AKE))%<J**:6D"&"<"<ZO`"a"a;goD^^E8R8FH1c&k*	 ,,UF;	"55i@!#*"#'>>%9K#LL$(NN5:M$N N!%!2!28!< $(#'$
 $(#'%	)%	 +0  77 ((7"nnUJ??#~~e5GHH $u6I JJ$!..x89 FLA )Z m >s   6GGF"Gc                 D  #    U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      eU R	                  USU5      u  pEU R                  U R                  XE5      5      I Sh  vN nU R                  U5      $  N N7f)a<  
fetch the current funding rate

https://www.gate.com/docs/developers/apiv4/en/#get-a-single-contract

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
Nri   z0 fetchFundingRate() supports swap contracts only)load_marketsr  r4   rC   rc  'publicFuturesGetSettleContractsContractr&  parse_funding_rate)r  r  r  r  r*  rU  r  s          r  fetch_funding_rategate.fetch_funding_rate  s      !!!V$f~DGG&XXYY--fdFCEEdkkRYFabbZ &&x00e 	"
 cs"   B BA/B BB B symbolsc                 P  #    U R                  5       I Sh  vN   U R                  U5      nSnUb#  U R                  US5      nU R                  U5      nU R	                  USU5      u  pVU R                  U R                  XV5      5      I Sh  vN nU R                  Xq5      $  N N7f)a  
fetch the funding rate for multiple markets

https://www.gate.com/docs/developers/apiv4/en/#list-all-futures-contracts

:param str[]|None 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-rates-structure>`, indexed by market symbols
Nr   ri   )r  market_symbolsr  r  rc  r%  r&  parse_funding_rates)r  r  r  r  firstSymbolr*  rU  r  s           r  fetch_funding_ratesgate.fetch_funding_rates  s      !!!%%g.**7A6K[[-F--fffE==dkk'>YZZZ ''::i 	" [s"   B&B"A5B&B$B&$B&c                     U R                  US5      nU R                  X2SS5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n	U R                  US	5      n
[        R
                  " S
U R                  US5      5      n0 SU_SU_SU_SU_SU_SS _SS _SS _SU_SU	_SU R                  U	5      _SU
_SS _SS _SS _SS _SS _SU R                  U5      0E$ )NrD   r  ri   r5  index_priceinterest_ratefunding_ratefunding_next_applyfunding_rate_indicative1000funding_intervalr  r  rF  
indexPriceinterestRateestimatedSettlePricer  r  fundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r  safe_symbolr  r=  r=   rA  rB  parse_funding_interval)r  r  r  r  r  rF  r  r  r  fundingTimefundingRateIndicativefundingIntervals               r  r  gate.parse_funding_rate7  s   V ##Hf5!!(C@$$X|<	%%h>
''/B&&x@))(4HI $ 0 0;T U!,,VT5E5EhPb5cd
H
f
 
 *	

 L
 #D
 
 
 ;
 
 t||K8
 4
 #D
 "4
 "4
  '!
" &t#
$ 33OD%
 	
r  c                 6    SSSSSS.nU R                  X!U5      $ )NrQ  rS  rT  16h24h)360000014400000288000005760000086400000r  )r  r  	intervalss      r  r  gate.parse_funding_interval  s-    
	 	X>>r  r  c                 *  #    U R                  5       I S h  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I S h  vN nU R	                  US5      nU R                  US5      nU R                  U5      n0 n[        S[        U5      5       Hb  n	Xi   n
U R                  U
S5      nU(       a  M"  U R                  U
S5      nU R                  U
S5      nU R                  U
S5      nU
UUUUS	.X'   Md     U$  N N7f)
Nr|  rC   multichain_addressesr   obtain_failedr  address
payment_id)r  r  r|  r  tag)
r  r|  privateWalletGetDepositAddressr&  r  r  r  r  r  r  )r  r  r  r|  r*  r  	addressesr  r  r  r  obtainFailedr  r  r  s                  r  fetch_network_deposit_address"gate.fetch_network_deposit_address  s"    !!!==&
 <<T[[=YZZOOH.DE	%%h
;
&&z2q#i.)ALE  ,,UODL&&ug6G&&ui8G""5,7C "FO# *0 E 	"
 [s"   DD?DDB9DDc                 x  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  US/ 5      nU R                  US5      nU R                  Xs5      nU R                  USS5      nU R                  US5      $  N Na7f)aR  
fetch a dictionary of addresses for a currency, indexed by network
:param str code: unified currency code of the currency for the deposit address
:param dict [params]: extra parameters specific to the api endpoint
:returns dict: a dictionary of `address structures <https://docs.ccxt.com/#/?id=address-structure>` indexed by the network
Nr|  rC   r  Fr  )	r  r|  r  r&  r  r  safe_currencyparse_deposit_addressesr  )	r  r  r  r|  r*  r  r  r  parseds	            r  "fetch_deposit_addresses_by_network'gate.fetch_deposit_addresses_by_network  s      !!!==&
 <<T[[=YZZ+A2F%%h
;
%%j;--fdEB}}VY// 	"
 [s"   B:B6?B:B8A B:8B:c                    #    U R                  5       I Sh  vN   SnU R                  U5      u  p2U R                  X5      I Sh  vN nU R                  XU5      nXE   $  NH N7f)a  
fetch the deposit address for a currency associated with self account

https://www.gate.com/docs/developers/apiv4/en/#generate-currency-deposit-address

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.network]: unified network code(not used directly by gate.com but used by ccxt to filter the response)
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
N)r  handle_network_code_and_paramsr  )select_network_code_from_unified_networks)r  r  r  r  chainsIndexedByIdselectedNetworkIdOrCodes         r  fetch_deposit_addressgate.fetch_deposit_address  sn      !!!"AA&I"&"I"I$"WW"&"P"PQUdu"v 99 	" Xs!   A#A-A#A!A#!A#c           
          U R                  US5      nU R                  U5        UU R                  US5      UU R                  US5      U R                  U R                  US5      5      S.$ )Nr  r  r  r  )r  r|  r  r  r  )r  check_addressr  )r  depositAddressr|  r  s       r  parse_deposit_addressgate.parse_deposit_address  sp     "">9=7#"((6:##NLA..t/?/?PW/XY
 	
r  c                    #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  XS5      $  NU N7f)a7  
fetch the trading fees for a market

https://www.gate.com/docs/developers/apiv4/en/#retrieve-personal-trading-fee

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
Nr_  rC   )r  r  privateWalletGetFeer&  parse_trading_feer  r  r  r  r*  r  s         r  fetch_trading_feegate.fetch_trading_fee  ss      !!!V$VD\
 11$++g2NOO %%h77) 	"
 Ps!   A0A,?A0A.A0.A0c                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  U5      $  N. N7f)a?  
fetch the trading fees for multiple markets

https://www.gate.com/docs/developers/apiv4/en/#retrieve-personal-trading-fee

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
N)r  r  parse_trading_feesr  s      r  fetch_trading_feesgate.fetch_trading_fees	  sG      !!!11&99 &&x00! 	"9s   A	AA	AA	A	c                     0 n[        S[        U R                  5      5       H6  nU R                  U   nU R                  U5      nU R	                  X5      X$'   M8     U$ Nr   )r  r  r  r  r  )r  r  r  r  r  r  s         r  r  gate.parse_trading_fees#	  sU    q#dll+,A\\!_F[[(F!33HEFN - r  c                    U R                  US5      nU(       a  SOSnU(       a  SOSnU R                  US5      nU(       a  SOUnU(       a  SOUnUU R                  US	5      U R                  X5      U R                  X5      S S S
.$ )Ngt_discountgt_taker_fee	taker_feegt_maker_fee	maker_feer  futures_taker_feefutures_maker_feer  )r  r  r  r  r"  r   )r  r  r  )	r  r  r  
gtDiscountr  r  r  takerKeymakerKeys	            r  r  gate.parse_trading_fee+	  s     __T=9
",+",+??6:6*2&*2&&&vx8%%d5%%d5
 	
r  codesc                 `  #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN n0 n0 n[        S[        U5      5       H  n0 nX6   nU R	                  US5      nU R                  U5      n	Ub  U R                  X5      (       d  MG  U R                  US5      n
U
c  U R                  US5      nO_[        U
R                  5       5      n[        S[        U5      5       H-  nX   nU R                  U5      nU R                  X   5      X^'   M/     USUS.XI'   M     U$  GN N7f)a  
@deprecated
       please use fetchDepositWithdrawFees instead

       https://www.gate.com/docs/developers/apiv4/en/#retrieve-withdrawal-status

       :param str[]|None codes: list of unified currency codes
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :returns dict: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
       Nr   r|  withdraw_fix_on_chainswithdraw_fix)r   r  r  )r  privateWalletGetWithdrawStatusr  r  r  r  in_arrayr  r  listkeysr  r  )r  r  r  r  r  withdrawFeesr  r  r  r  withdrawFixOnChains
networkIdsrV  r  r  s                  r  fetch_transaction_feesgate.fetch_transaction_feesI	  s7     !!!<<VDD$ q#h-(ALKE))%<J**:6D!4==+E+E"&//%9Q"R"*#//~F!"5":":"<=
q#j/2A *I"&"9"9)"DK040A0ABUB`0aL- 3
 )FL! )* U 	"Ds    D.D)D.D,C:D.,D.c                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  X1S5      $  N/ N7f)aH  
fetch deposit and withdraw fees

https://www.gate.com/docs/developers/apiv4/en/#retrieve-withdrawal-status

:param str[]|None codes: list of unified currency codes
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
Nr|  )r  r  parse_deposit_withdraw_fees)r  r  r  r  s       r  fetch_deposit_withdraw_fees gate.fetch_deposit_withdraw_fees	  sI      !!!<<VDD( //LL+ 	"Ds   A
AA
AA
A
r|  c                    U R                  US5      nUU R                  US5      SS.U R                  US5      SS.0 S.nUb|  [        UR                  5       5      n[	        S[        U5      5       HJ  nXV   nU R                  XpR                  US5      5      nU R                  X7   5      SS.S S S.S	.US
   U'   ML     U$ )Nr  r  F)r   r"  r  )r  r   r  r  r   r|  )r   r  r  )	r  r  r  r  r  r  r  r  r  )	r  r   r|  r  r  	chainKeysr  chainKeyr  s	            r  parse_deposit_withdraw_feegate.parse_deposit_withdraw_fee	  s    $ #ooc3KL''^<#
 ''Y7# 
 *05578I1c)n-$<"55h@P@PQTV`@ab  $001D1NO&+!
  $&* 	3z";/ . r  sincer  c                 ,  #    U R                  5       I Sh  vN   SnUb  U R                  U5      nUS   nU R                  SXT5      u  pgU R                  XVU5      u  pSUS'   Ub  U R	                  US-  5      US'   Ub  X8S'   Sn
US	:X  a)  U R                  U R                  X5      5      I Sh  vN n
OGUS
:X  a)  U R                  U R                  X5      5      I Sh  vN n
O[        U R                  S-   5      eU R                  XX#5      $  N N` N37f)aH  
fetch the history of funding payments paid and received on self account

https://www.gate.com/docs/developers/apiv4/en/#query-account-book-2
https://www.gate.com/docs/developers/apiv4/en/#query-account-book-3

:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch funding history for
:param int [limit]: the maximum number of funding history structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
Nr  r   fundr  r  fromr  ri   rj   z= fetchFundingHistory() only support swap & future market type)r  r  handle_market_type_and_paramsrc  parse_to_int"privateFuturesGetSettleAccountBookr&  #privateDeliveryGetSettleAccountBookr9   rC   parse_funding_histories)r  r  r  r  r  r  r  rU  r*  requestParamsr  s              r  fetch_funding_historygate.fetch_funding_history	  s#     !!![[(FH%F889NPV_!%!5!5fE!J "//=GFO$G6>!DDT[[QXEhiiHX!EEdkkRYFijjHtww)hhii ++HeKKC 	"  jjs4   DDBD/D0.DD0DDDc                     / n[        S[        U5      5       H)  nX   nU R                  U5      nUR                  U5        M+     U R	                  US5      n	U R                  XX45      $ )Nr   r  )r  r  parse_funding_historyr  sort_byfilter_by_symbol_since_limit)
r  r  r  r  r  r  r  r  r  sorteds
             r  r  gate.parse_funding_histories
  sd    q#h-(AKE007GMM'" ) fk200NNr  c           
         U R                  US5      nU R                  US5      nU R                  XBSS5      nUU R                  US5      U R                  US5      UU R                  U5      S U R	                  US5      S.$ )	Nr   textr  ri   r  r  change)r  r  r  r  r  rC   r  )r=  r  r  rB  r  )r  r  r  r  r  s        r  r  gate.parse_funding_history

  s     ''f5	##D&1!!(C@&&vx8$$VX6"Y/&&tX6
 	
r  c           	        #    U R                  5       I Sh  vN   U R                  U5      nU R                  XDS   U5      u  pVUb'  US   (       a  [        US5      nO[        US5      nX%S'   SUS'   SnUS   (       d
  US	   (       a)  U R	                  U R                  XV5      5      I Sh  vN nOUS
   (       a)  U R                  U R                  XV5      5      I Sh  vN nO~US   (       a)  U R                  U R                  XV5      5      I Sh  vN nOKUS   (       a)  U R                  U R                  XV5      5      I Sh  vN nO[        U R                  S-   5      eU R                  US5      nUS   (       d  US-  nUS   (       a  SOSn	US   (       a  SOSn
U R                  US5      nU R                  XqUSSX5      nXS'   U$  GN GN$ N N N7f)a  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://www.gate.com/docs/developers/apiv4/en/#retrieve-order-book
https://www.gate.com/docs/developers/apiv4/en/#futures-order-book
https://www.gate.com/docs/developers/apiv4/en/#futures-order-book-2
https://www.gate.com/docs/developers/apiv4/en/#options-order-book

:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: the maximum amount of order book entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
Nr  rS   r  i,  r  Twith_idrQ   ri   rj   rk   z. fetchOrderBook() not support self market typecurrentr   pr   srC   bidsasksnonce)r  r  rc  r  publicSpotGetOrderBookr&  publicFuturesGetSettleOrderBook publicDeliveryGetSettleOrderBookpublicOptionsGetOrderBookr9   rC   r  parse_order_book)r  r  r  r  r  r*  rU  r  r  priceKey	amountKeyr.  r  s                r  fetch_order_bookgate.fetch_order_book!
  s     !!!V$ --fVnfMf~E4(E3$G!	&>VH-!88W9TUUHF^!AA$++gB]^^HH!BB4;;wC^__HH!;;DKK<WXXHtww)YYZZB %%h	:	f~!D(Iv1CAS	!!(D1&&xFFT\hwK 	"( V^_XsY   GGBG+G,2GG2GG2GGBGGGGGc                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  USU5      u  pESnUS   (       d
  US   (       a)  U R                  U R	                  XE5      5      I Sh  vN nOUS   (       a)  U R                  U R	                  XE5      5      I Sh  vN nOUS   (       a)  U R                  U R	                  XE5      5      I Sh  vN nOvUS   (       aT  US   nUR                  S5      nU R                  US	5      US
'   U R                  U R	                  XE5      5      I Sh  vN nO[        U R                  S-   5      eSn	US   (       a1  [        S	[        U5      5       H  n
Xj   nUS   US   :X  d  M  Un	  O   OU R                  US	5      n	U R                  X5      $  GN GNE GN N N7f)a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://www.gate.com/docs/developers/apiv4/en/#get-details-of-a-specifc-order
https://www.gate.com/docs/developers/apiv4/en/#list-futures-tickers
https://www.gate.com/docs/developers/apiv4/en/#list-futures-tickers-2
https://www.gate.com/docs/developers/apiv4/en/#list-tickers-of-options-contracts

: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>`
NrS   rQ   ri   rj   rk   rC   r  r   rN  z+ fetchTicker() not support self market typerD   )r  r  rc  publicSpotGetTickersr&  publicFuturesGetSettleTickerspublicDeliveryGetSettleTickersr  r  publicOptionsGetTickersr9   rC   r  r  r  parse_ticker)r  r  r  r  r*  rU  r  r  r  tickerr  r  s               r  fetch_tickergate.fetch_ticker
  s     !!!V$--fdFC&>VH-!66t{{77RSSHF^!??G@[\\HH!@@WA\]]HHd|H"..-K$($4$4[!$DGL!!99$++g:UVVHtww)VVWW(1c(m, =F4L0"F	 - __Xq1F  005 	"
 T\]
 Ws`   G	F<A#G	:F?;2G	-G.2G	 G!AG	>G?AG	+G	?G	G	G	G	r>  c           
         U R                  U/ SQ5      nSU;   a  SOSnU R                  X2SU5      nU R                  USS5      nU R                  U/ SQ5      nU R                  U/ S	Q5      nU R                  US
5      n	U R                  US5      n
U R                  USS5      nU R                  USS5      nU R	                  US5      nU R                  USS5      nUS:X  a  SnU R                  USS5      nUS:X  a  SnU R                  US5      nU R                  0 SU_SU_SU R                  U5      _SU	_SU
_SU_SU_SU_S U_S!S _S"S _S#U_SU_S$S _S%S _S&U_S'S _UUU R                  US5      U R                  US(5      US).EU5      $ )*N)r_  r  rD   r5  r  rS   r  r  
last_price)
lowest_aska
ask1_price)highest_bidb
bid1_pricehigh_24hlow_24hB	bid1_sizeA	ask1_sizetbase_volumevolume_24h_basenanr  quote_volumevolume_24h_quotechange_percentager  r  r  highlowbid	bidVolumeask	askVolumevwapopenclosepreviousCloser%  r"  averager  )
baseVolumequoteVolumerF  r  r  )safe_string_nr  safe_string_2r  r  safe_tickerrB  )r  r>  r  r  r  r  r  rZ  rX  rV  rW  rY  r[  r  ra  rb  r"  s                    r  r=  gate.parse_ticker
  sG   J %%f.ST$0F$:Z
!!(CD!!&&,?  )JK  )KL
3vy1&&vsK@	&&vsK@	%%fc2	''?PQ
J((AST%K%%f.AB
 !
f!
!
 Y/!
 D	!

 3!
 3!
 !
 3!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  *!!
" t#!
$ %&))&,?**6=A-!
. / 	r  c                 r  #    U R                  5       I Sh  vN   U R                  U5      nU R                  US5      nSnUb  U R                  U5      nU R	                  SXB5      u  pVU R                  SXV5      u  pxSn	SUS'   US:X  d  US:X  a)  U R                  U R                  Xx5      5      I Sh  vN n	OUS:X  a)  U R                  U R                  Xx5      5      I Sh  vN n	OUS	:X  a)  U R                  U R                  Xx5      5      I Sh  vN n	OUS
:X  ag  U R                  SUS5        US   n
U
R                  S5      nU R                  US5      US'   U R                  U R                  Xx5      5      I Sh  vN n	O[        U R                  S-   5      eU R                  X5      $  GN N N N N77f)a  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://www.gate.com/docs/developers/apiv4/en/#get-details-of-a-specifc-order
https://www.gate.com/docs/developers/apiv4/en/#list-futures-tickers
https://www.gate.com/docs/developers/apiv4/en/#list-futures-tickers-2
https://www.gate.com/docs/developers/apiv4/en/#list-tickers-of-options-contracts

: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>`
Nr   r   utc0timezonerS   rQ   ri   rj   rk   r  rC   r  rN  z fetchTickers() not support self market type, provide symbols or set params["defaultType"] to one from spot/margin/swap/future/option)r  r  r  r  r  rc  r9  r&  r:  r;  check_required_argumentr  r<  r9   rC   parse_tickers)r  r  r  firstr  r  rU  r*  r  r  r  r  s               r  fetch_tickersgate.fetch_tickers/  s     !!!%%g.  !,[['F88X!%!5!5dD!H$
6>TX-!66t{{77Z[[HV^!??G@cddHX!@@WAdeeHX(()Ld|H"..-K$($4$4[!$DGL!!99$++g:]^^Htww  *q   q  r  r!!(441 	" \de _sY   F7F,BF72F/3.F7!F1".F7F3A,F7=F5>/F7/F71F73F75F7c                     U R                  5       nU R                  USS5      US'   U R                  US5      US'   U R                  US5      US'   SU;   a  U R                  US5      US'   U$ )	Nfreezelockedused	availablefreetotalborroweddebt)r[   rd  r  )r  r  r[   s      r  parse_balance_helpergate.parse_balance_helperV  su    ,,.,,UHhG**5+>++E7;"..ujAGFOr  c                 ,	  #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  US5      nU R                  US5      nSnU R	                  USS5      u  p1U R                  SSU5      u  pEU R                  SXE5      u  pgU R                  SU5      u  pUb  U R                  U5      n
U
S   US'   SnU(       a*  U R                  U R                  Xa5      5      I Sh  vN nGOUS:X  a  US:X  a*  U R                  U R                  Xi5      5      I Sh  vN nGOKUS	:X  a*  U R                  U R                  Xi5      5      I Sh  vN nGOUS
:X  a)  U R                  U R                  Xi5      5      I Sh  vN nO[        U R                  S-   5      eUS:X  a)  U R!                  U R                  Xi5      5      I Sh  vN nOUS:X  a)  U R#                  U R                  Xi5      5      I Sh  vN nOvUS:X  a)  U R%                  U R                  Xi5      5      I Sh  vN nOGUS:X  a)  U R'                  U R                  Xi5      5      I Sh  vN nO[        U R                  S-   5      eUS:H  =(       d    US:H  =(       d    US:H  nU(       a  U/nSU0nUS	:H  =(       a    US:H  nUnSU;   al  / nU R)                  US/ 5      n[+        UR-                  5       5      n[/        S[1        U5      5       H#  nUU   nUU   nUUS'   UR3                  U5        M%     Un[/        S[1        U5      5       GH  nUU   nU(       a  U R                  US5      nU R5                  USSS	5      nU R)                  US0 5      nU R)                  US0 5      nU R7                  U R                  US5      5      nU R7                  U R                  US5      5      n0 nU R9                  U5      UU'   U R9                  U5      UU'   U R;                  U5      UU'   M  U R7                  U R                  US5      5      nU R9                  U5      UU'   GM     U(       a  UnU$ U R;                  U5      nU$  GN` GNK GN GNV GN) GN GN GN GN` GN47f)ai  

https://www.gate.com/docs/developers/apiv4/en/#margin-account-list
https://www.gate.com/docs/developers/apiv4/en/#get-unified-account-information
https://www.gate.com/docs/developers/apiv4/en/#list-spot-trading-accounts
https://www.gate.com/docs/developers/apiv4/en/#get-futures-account
https://www.gate.com/docs/developers/apiv4/en/#get-futures-account-2
https://www.gate.com/docs/developers/apiv4/en/#query-account-information

:param dict [params]: exchange specific parameters
:param str [params.type]: spot, margin, swap or future, if not provided self.options['defaultType'] is used
:param str [params.settle]: 'btc' or 'usdt' - settle currency for perpetual swap and future - default="usdt" for swap and "btc" for future
:param str [params.marginMode]: 'cross' or 'isolated' - marginMode for margin trading if not provided self.options['defaultMarginMode'] is used
:param str [params.symbol]: margin only - unified ccxt symbol
:param boolean [params.unifiedAccount]: default False, set to True for fetching the unified account balance
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nr  Fr   r  rC   r_  rS   rQ   r  z+ fetchBalance() not support self marginModer  ri   rj   rk   z, fetchBalance() not support self market typer  balancesr   r|  r  r$  r  )r  r  r  ra  rs  r  rc  rg  r  privateUnifiedGetAccountsr&  privateSpotGetAccountsprivateMarginGetAccountsprivateMarginGetCrossAccountsr9   rC   privateMarginGetFundingAccountsprivateFuturesGetSettleAccounts privateDeliveryGetSettleAccountsprivateOptionsGetAccountsr  r  r  r  r  r  r  r  rx  safe_balance) r  r  r  rt  r  rU  r*  r  r  requestQueryr  r  r  r  r  dataflatBalancesr{  r  r  r  contentr  r  symbolInnerr$  r  baseCode	quoteCode	subResultr  returnResults                                    r  fetch_balancegate.fetch_balance_  sT    $ !!!&&(((!!&(368, #'#@#@Yi#j 88vV!%!5!5dD!H#'#7#7}#M 
[[(F'-d|GO$!;;DKK<XYYHV^V#!%!<!<T[[=_!``x'!%!>!>t{{7?a!bb~-!%!C!CDKKPWDf!gg"477-Z#Z[[Y!AA$++gBdeeHV^!AA$++gBdeeHX!BB4;;wCeffHX!;;DKK<^__Htww)WWXXV^P)9Ptx?O zHD H
 )<dfnLtZ<H (D1c$i(!!W
":.&0
###G,	 )
  Dq#d)$AGE++E?C"..xsHMufb9w;2243C3CD*3UV 33D4D4DUJ4WX	"$	&*&?&?&E	(#'+'@'@'G	)$&*&7&7	&B{#..t/?/?z/RS#88?t %  "*v 04/@/@/HO 	"( Z abg fef_s   RQ6RQ9CR3Q<45R)Q?*/RR/R	R
ARR.R?R .R.R/.RRHR9R<R?RRRRRRRrM  	timeframec           	      T  #    U R                  5       I Sh  vN   U R                  U5      nSnU R                  USS5      u  puU(       a  U R                  SXXBUS5      I Sh  vN $ US   (       a  U R	                  XX4U5      I Sh  vN $ U R                  US5      n0 n	U R                  USU5      u  pU R                  U R                  X"5      U	S'   US	   (       a  S
OSn
Uc  U
O
[        XJ5      nU R                  US5      nUb&  U R                  US-  5      nU R                  US5      nUby  U R                  U5      nU R                  US-  5      U	S'   US-
  U-  nU R                  U	S   U5      nU R                  5       n[        X5      nUb  [        UU5      U	S'   OUU	S'   OUb  XS'   XIS'   SnUS	   (       a  US:H  nUS:H  nU(       d  U(       a   US-   US   -   U	S	'   U R                  US5      nUS   (       a)  U R                  U R!                  X5      5      I Sh  vN nO[US   (       a(  U R#                  U R!                  X5      5      I Sh  vN nO(U R%                  U R!                  X5      5      I Sh  vN nU R'                  UXbX45      $  GN GN: GN N| NK N$7f)aw  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://www.gate.com/docs/developers/apiv4/en/#market-candlesticks       # spot
https://www.gate.com/docs/developers/apiv4/en/#get-futures-candlesticks  # swap
https://www.gate.com/docs/developers/apiv4/en/#market-candlesticks       # future
https://www.gate.com/docs/developers/apiv4/en/#get-options-candlesticks  # option

: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, limit is conflicted with since and params["until"], If either since and params["until"] is specified, request will be rejected
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.price]: "mark" or "index" for mark price and index price candles
:param int [params.until]: timestamp in ms of the latest candle to fetch
: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 int[][]: A list of candles ordered, open, high, low, close, volume(units in quote currency)
NFr   paginater  rk   r  r  r  r	  untilr  r   tor  r  r  r  rC   rj   ri   )r  r  rs  "fetch_paginated_call_deterministicfetch_option_ohlcvr  rc  rK  r  r  r  ra  parse_timeframesumseconds#publicDeliveryGetSettleCandlesticksr&  "publicFuturesGetSettleCandlestickspublicSpotGetCandlesticksparse_ohlcvs)r  r  r  r  r  r  r  r  r  r*  maxLimitr  durationdistancetoTimestampcurrentTimestampr  r  isMarkisIndexs                       r  fetch_ohlcvgate.fetch_ohlcvz  s    & !!!V$88zZ@@v^cpvx|}}}(00ERXYYY  1..vtVD"..t	U
!*-44"]U1E!!&'2%%edl3EYYvw/F++I6H"//=GFO	X-H((76?H=K#||~[3B  #B "  %$G*voF'G&+ckF4L&@
#673h!%!I!I$++V]Jf!gg!%!H!HU\Ie!ff!;;DKK<XYYH  6eKK] 	"
 ~YD hfYsk   J(JAJ("J#$J(JFJ(%J"&2J(J$(J(J&J(J(J("J($J(&J(c                 F  #    U R                  5       I S h  vN   U R                  U5      n0 nU R                  US U5      u  puU R                  U R                  X"5      US'   U R                  U R                  Xu5      5      I S h  vN nU R                  XX#U5      $  N N7f)Nr  )r  r  rc  r  rK  publicOptionsGetCandlesticksr&  r  )	r  r  r  r  r  r  r  r*  r  s	            r  r  gate.fetch_option_ohlcv  s     !!!V$..vtVD"..t	U
::4;;w;WXX  9UKK 	"
 Ys"   B!BA.B!BB!B!c           
        #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R	                  SXUSU5      I Sh  vN $ U R                  U5      nUS   (       d  [        U R                  S-   5      e0 nU R                  USU5      u  ptUb  X7S	'   Ub  U R                  US
-  5      US'   U R                  US5      nUb)  U R                  US5      nU R                  US
-  5      US'   U R                  U R                  Xt5      5      I Sh  vN n	/ n
[        S[        U	5      5       HO  nX   nU R                  US5      nU
R!                  UUU R#                  US5      UU R%                  U5      S.5        MQ     U R'                  U
S5      nU R)                  XS   X#5      $  GN GNj N7f)a  
fetches historical funding rate prices

https://www.gate.com/docs/developers/apiv4/en/#funding-rate-history

:param str symbol: unified symbol of the market to fetch the funding rate history for
:param int [since]: timestamp in ms of the earliest funding rate to fetch
:param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>` to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest funding rate to fetch
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
Nz5 fetchFundingRateHistory() requires a symbol argumentFr   r  rT  ri   z7 fetchFundingRateHistory() supports swap contracts onlyr  r  r  r  r  r   rO  r)r  r  r  r  r  r  r  )r2   rC   r  rs  r  r  r4   rc  r  r  ra  !publicFuturesGetSettleFundingRater&  r  r  r=  r  r  rB  r  r   )r  r  r  r  r  r  r  r*  r  r  ratesr  r  r  r!  s                  r  fetch_funding_rate_historygate.fetch_funding_rate_history  s     >#DGG.e$eff!!!88AZ\fg@@AZ\bkprvx~V$f~DGG&__``..vtVD$G"//=GFO!!&'2YYvw/F --edl;GDM??G@\]] q#h-(AKE++E37ILL #//s;& LL3  ) e[1009I5XXK 	" @ ^s5   /GG:G,G-CG=G>BGGGc           	         [        U[        5      (       ah  U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ U R                  US5      U R                  US5      U R                  US	5      U R                  US
5      U R                  US5      U R                  US5      /$ )Nr      r     r     rO  ohlr)  v)
isinstancer  r=  r  )r  ohlcvr  s      r  parse_ohlcvgate.parse_ohlcv  s    2 eT""##E1-  *  *  *  *  *  ##E3/  ,  ,  ,  ,  , r  c                   #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX45      I Sh  vN $ U R                  U5      nU R	                  USU5      u  pxU R                  USS5      n	U	b*  U R                  US/5      nU R                  U	S-  5      US'   Ub  [        US5      US'   Ub!  US	   (       a  U R                  US-  5      US
'   Sn
US   S:X  d	  US   S:X  a)  U R                  U R                  Xx5      5      I Sh  vN n
OUS   (       a)  U R                  U R                  Xx5      5      I Sh  vN n
O}US   (       a)  U R                  U R                  Xx5      5      I Sh  vN n
OJUS   S:X  a)  U R                  U R                  Xx5      5      I Sh  vN n
O[        U R                  S-   5      eU R!                  XX#5      $  GN GN N N Nk N;7f)a  
get the list of most recent trades for a particular symbol

https://www.gate.com/docs/developers/apiv4/en/#retrieve-market-trades
https://www.gate.com/docs/developers/apiv4/en/#futures-trading-history
https://www.gate.com/docs/developers/apiv4/en/#futures-trading-history-2
https://www.gate.com/docs/developers/apiv4/en/#options-trade-history

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest trade to fetch
: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 Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
NFr   r  r  r  r  r  r  r  r  rS   rQ   ri   rj   rk   z, fetchTrades() not support self market type.)r  rs  fetch_paginated_call_dynamicr  rc  safe_integer_2ra  r  r  publicSpotGetTradesr&  publicFuturesGetSettleTradespublicDeliveryGetSettleTradespublicOptionsGetTradesr9   rC   parse_trades)r  r  r  r  r  r  r  r*  rU  r  r  s              r  fetch_tradesgate.fetch_trades+  s    " !!!88PZ[::=&Y^gggV$, --fdFC##FD':YYvy1F --edl;GDM"5$/GG&"4"//=GFO&>V#vf~'A!55dkk'6QRRHF^!>>t{{7?Z[[HH!??G@[\\HF^x'!88W9TUUHtww)WWXXR   5@@o 	" hD S[\Usj   G=G/8G=G2CG='G5(2G=G72G=G91G=?G; 0G=2G=5G=7G=9G=;G=rC   c                    #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  X#USU05      I Sh  vN nU$  N# N7f)a  
fetch all the trades made from a single order

https://www.gate.com/docs/developers/apiv4/en/#list-personal-trading-history
https://www.gate.com/docs/developers/apiv4/en/#list-personal-trading-history-2
https://www.gate.com/docs/developers/apiv4/en/#list-personal-trading-history-3
https://www.gate.com/docs/developers/apiv4/en/#list-personal-trading-history-4

:param str id: order id
:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch trades for
:param int [limit]: the maximum number of trades to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
Nz. fetchOrderTrades() requires a symbol argumentorder_id)r2   rC   r  fetch_my_trades)r  rC   r  r  r  r  r  s          r  fetch_order_tradesgate.fetch_order_trades  sb       >#DGG.^$^__!!!( --fUZQSDTUU+ 	"( Vs!   /AAAAAAc                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX45      I Sh  vN $ SnSn0 nUb  U R	                  U5      OSn	U R                  US5      n
U R                  US/5      nU R                  SX5      u  pdUS:H  =(       d    US:H  =(       d    US:H  nU(       a-  U R                  XU5      u  pUS:X  a  U R                  US	5      nO#U	b  U	S
   US'   U R                  SU5      u  ptXxS'   Ub  X8S'   Ub  U R                  US-  5      US'   U
b  U R                  U
S-  5      US'   SnUS:X  d  US:X  a)  U R                  U R                  X5      5      I Sh  vN nOUS:X  a)  U R                  U R                  X5      5      I Sh  vN nOvUS:X  a)  U R                  U R                  X5      5      I Sh  vN nOGUS:X  a)  U R                  U R                  X5      5      I Sh  vN nO[!        U R"                  S-   5      eU R%                  XX#5      $  GNH GN3 GN N N Nk N>7f)a  
Fetch personal trading history

https://www.gate.com/docs/developers/apiv4/en/#list-personal-trading-history
https://www.gate.com/docs/developers/apiv4/en/#list-personal-trading-history-2
https://www.gate.com/docs/developers/apiv4/en/#list-personal-trading-history-3
https://www.gate.com/docs/developers/apiv4/en/#list-personal-trading-history-4

: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.marginMode]: 'cross' or 'isolated' - marginMode for margin trading if not provided self.options['defaultMarginMode'] is used
:param str [params.type]: 'spot', 'swap', or 'future', if not provided self.options['defaultMarginMode'] is used
:param int [params.until]: The latest timestamp, in ms, that fetched trades were made
:param int [params.page]: *spot only* Page number
:param str [params.order_id]: *spot only* Filter trades with specified order ID. symbol is also required if self field is present
:param str [params.order]: *contract only* Futures order ID, return related data only if specified
:param int [params.offset]: *contract only* list offset, starting from 0
:param str [params.last_id]: *contract only* specify list staring point using the id of last record in previous list-query results
:param int [params.count_total]: *contract only* whether to return total number matched, default to 0(no return)
:param bool [params.unifiedAccount]: set to True for fetching trades in a unified account
:param bool [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
NFr   r  r  ri   rj   rk   r  rC   r_  r[   r  r  r  r  rS   rQ   z. fetchMyTrades() not support self market type.)r  r  rs  r  r  r  ra  r  rc  rg  r  privateSpotGetMyTradesr&  (privateFuturesGetSettleMyTradesTimerange privateDeliveryGetSettleMyTradesprivateOptionsGetMyTradesr9   rC   r  )r  r  r  r  r  r  r  r  r*  r  r  r  r  s                r  r  gate.fetch_my_trades  sl    4 !!!&&(((88R\]::?F[`iii
)/);V$$!!&'26G9-99/6ZFNO(8Odh>N"226HOGx6:6!+1$<(!%!5!5eV!DJ!+I$G"//=GFO --edl;GDM6>TX-!88W9UVVHV^!JJ4;;W^KghhHX!BB4;;wC_``HX!;;DKK<XYYHtww)YYZZB   5@@Q 	"( j4 Wh`Ysz   I/II/I!8I/'I$(D9I/!I'".I/I).I/?I+ .I/.I-/0I/!I/$I/'I/)I/+I/-I/tradec                 j   U R                  USS5      nS nU R                  US5      nUb.  [        R                  " US5      nUSS nU R	                  U5      nOU R                  USS5      nU R                  US	S
5      nS
U;   a  S
OSnU R                  XbSU5      nU R                  USS5      nU R                  US5      n	[        R                  " US5      (       a  SOSn
[        R                  " U5      nU R                  USSU
5      nU R                  US5      nU R                  US5      nU R                  U R                  US5      5      nU R                  U R                  US5      5      n/ nUbL  U R                  US5      nU R                  U5      nUc  U R                  US5      nUR                  UUS.5        Ub  UR                  USS.5        Ub  UR                  USS.5        U R                  US5      nU R                  UUUU R                  U5      US   US UUU	US S US .U5      $ )!NrC   trade_idcreate_time_msr  r      r   r<  r_  r  rS   r  r  sizer  r  sellbuysider  r  r   gt_fee	point_feefee_currencyr  )r  r|  GT	GatePointroler  )r  rC   r  r  r  orderr  r  takerOrMakerr  r  r  r   r  )rd  r  r=   rA  r  safe_timestamp_2r  	string_lt
string_abs	omit_zeror  r  
safe_traderB  )r  r  r  rC   r  msStringr  r  amountStringpriceStringcontractSider  orderId	feeAmountgtFeepointFeer  feeCurrencyIdfeeCurrencyCoder  s                       r  parse_tradegate.parse_tradeB  sn   L tZ8	##E+;<))(F;H"~H))(3I--eV]KI%%e_jI$.%$7Zf
!!(CD))%6B&&ug6!(!2!2<!E!Ev5)),7!!%F""5*5$$UE2	t//x@A>>$"2"25+"FG  ,,UNCM"55mDO&"&"2"268"DKK!+  KK   KK '  ''v6"Y/X&( " 
  	r  c                   #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX45      I Sh  vN $ 0 nSnUb  U R                  U5      nUS   US'   Ub  X6S'   Ub-  U R	                  US-  5      nXS	'   U R                  US
5      US'   U R                  SXdS5      u  pdU R                  U R                  Xd5      5      I Sh  vN n	U R                  X5      $  N N N7f)a  
fetch all deposits made to an account

https://www.gate.com/docs/developers/apiv4/en/#retrieve-deposit-records

: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 int [params.until]: end time in ms
: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>`
NFr   r  rC   r|  r  r  r   ' r  MbP?)
r  rs  r  r|  r  r  handle_until_optionprivateWalletGetDepositsr&  parse_transactions
r  r  r  r  r  r  r*  r|  startr  s
             r  fetch_depositsgate.fetch_deposits  s     !!!88R\]::?DY^ggg}}T*H"*4.GJ$G%%edl3E#FO HHU,=>GDM224%P66t{{77STT&&x::% 	" h U4   C?C98C?C;BC?#C=$C?;C?=C?c                   #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX45      I Sh  vN $ 0 nSnUb  U R                  U5      nUS   US'   Ub  X6S'   Ub-  U R	                  US-  5      nXS	'   U R                  US
5      US'   U R                  SXdS5      u  pdU R                  U R                  Xd5      5      I Sh  vN n	U R                  X5      $  N N N7f)a  
fetch all withdrawals made from an account

https://www.gate.com/docs/developers/apiv4/en/#retrieve-withdrawal-records

: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 int [params.until]: end time in ms
: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>`
NFr   r  rC   r|  r  r  r  r  r  r  )
r  rs  r  r|  r  r  r  privateWalletGetWithdrawalsr&  r  r  s
             r  fetch_withdrawalsgate.fetch_withdrawals  s     !!!88ASU_`::;Mt\ajjj}}T*H"*4.GJ$G%%edl3E#FO HHU,=>GDM224%P99$++g:VWW&&x::% 	" k Xr  r  r  r  c                   #    U R                  XE5      u  pEU R                  U5        U R                  5       I Sh  vN   U R                  U5      nUS   UU R	                  X5      S.nUb  XGS'   SnU R                  U5      u  pUb  U R                  U5      US'   U R                  U R                  Xu5      5      I Sh  vN n	U R                  X5      $  N N7f)a  
make a withdrawal

https://www.gate.com/docs/developers/apiv4/en/#withdraw

:param str code: unified currency code
:param float amount: the amount to withdraw
:param str address: the address to withdraw to
:param str tag:
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
NrC   )r|  r  r  memor  )
handle_withdraw_tag_and_paramsr  r  r|  currency_to_precisionr  network_code_to_id!privateWithdrawalsPostWithdrawalsr&  parse_transaction)
r  r  r  r  r  r  r|  r*  r  r  s
             r  r   gate.withdraw'  s      99#F7#!!!==& 00>

 ?!FO"AA&I"#66{CGG??G@\]] %%h99/ 	" ^s"   8CCBC>C?CCstatusc                 F    SSSSSSSSSSSSSS.nU R                  X!U5      $ )Npendingcanceledfailedok)PENDREQUESTDMOVEMANUALVERIFYPROCESEXTPEND	SPLITPENDCANCELFAILINVALIDDONEBCODEr  r  r
  statusess      r  parse_transaction_statusgate.parse_transaction_statusO  sE      " 
 &99r  c                 0    SSS.nU R                  X!U5      $ )Nr  
withdrawal)dwr  )r  r  r  s      r  parse_transaction_typegate.parse_transaction_typea  s$    
 T22r  transactionc                    U R                  US5      nS nU R                  US5      nUbT  US   S:X  a7  [        R                  " US5      (       a  SOSn[        R                  " U5      nOU R	                  US   5      nU R                  USS	5      nUS:X  a  [        R                  " XV5      nU R                  US
5      nU R                  US5      nU R                  U5      n	U R                  US5      n
U R                  US5      nU R                  U5      nU R                  US5      nU R                  US5      nU R                  US5      n0 SU_SU_SU
_SU	_SU R                  U5      _SU R                  U5      _SU_SS _SS _SU_SS _SS _SU_SU_SU_SU R                  U5      _SS _S S U	U R                  U5      S.S.E$ )NrC   r  r   rG  r  r  r"  r   
fee_amountr  r|  txidr
  r  r  r  r  r  	addressToaddressFromr  tagTotagFromr  r  updatedr|  r  )internalcommentr   )r  r=   	string_gtr  r%  rd  r?  safe_string_upperr  r  r=  r  r  rB  )r  r'  r|  rC   r  r  feeCostStringr  r  r  r*  	rawStatusr
  r  r  r  s                   r  r  gate.parse_transactionh  sY   z k40''X>>!u|$+$5$5lC$H$Hyl&11,?222a59**;|L<"--lJL**;@	%%k:>
&&z2V4$$[(;	..y9"";	:{F3''[A	
K
"
 D
 	

 d''5
 t..y9
 w
 
 4
 3
 T
 t
 f
 D
 
  Y/!
" t#
$  ))-8)
 	
r  r  r  r  c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  U5      nU R                  US5      nU R	                  USS5      n	U R                  USU	5      n
U R                  US5      nU
SLnUSLnU=(       d    UnU(       + =(       a    USL nU R                  XX4XV5      nSnUS   (       d
  US   (       a;  U(       a  U R                  U5      I Sh  vN nOU R                  U5      I Sh  vN nOUS	   (       a;  U(       a  U R                  U5      I Sh  vN nOxU R                  U5      I Sh  vN nO^US
   (       a;  U(       a  U R                  U5      I Sh  vN nO3U R                  U5      I Sh  vN nOU R                  U5      I Sh  vN nU R                  UU5      $  GN GN N N N N NX N@ N(7f)a
  
Create an order on the exchange

https://www.gate.com/docs/developers/apiv4/en/#create-an-order
https://www.gate.com/docs/developers/apiv4/en/#create-a-price-triggered-order
https://www.gate.com/docs/developers/apiv4/en/#create-a-futures-order
https://www.gate.com/docs/developers/apiv4/en/#create-a-price-triggered-order-2
https://www.gate.com/docs/developers/apiv4/en/#create-a-futures-order-2
https://www.gate.com/docs/developers/apiv4/en/#create-a-price-triggered-order-3
https://www.gate.com/docs/developers/apiv4/en/#create-an-options-order

:param str symbol: Unified CCXT market symbol
:param str type: 'limit' or 'market' *"market" is contract only*
:param str side: 'buy' or 'sell'
:param float amount: the amount of currency to trade
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
:param dict [params]:  extra parameters specific to the exchange API endpoint
:param float [params.triggerPrice]: The price at which a trigger order is triggered at
:param str [params.timeInForce]: "GTC", "IOC", or "PO"
:param float [params.stopLossPrice]: The price at which a stop loss order is triggered at
:param float [params.takeProfitPrice]: The price at which a take profit order is triggered at
:param str [params.marginMode]: 'cross' or 'isolated' - marginMode for margin trading if not provided self.options['defaultMarginMode'] is used
:param int [params.iceberg]: Amount to display for the iceberg order, Null or 0 for normal orders, Set to -1 to hide the order completely
:param str [params.text]: User defined information
:param str [params.account]: *spot and margin only* "spot", "margin" or "cross_margin"
:param bool [params.auto_borrow]: *margin only* Used in margin or cross margin trading to allow automatic loan of insufficient amount if balance is not enough
:param str [params.settle]: *contract only* Unified Currency Code for settle currency
:param bool [params.reduceOnly]: *contract only* Indicates if self order is to reduce the size of a position
:param bool [params.close]: *contract only* Set to close the position, with size set to 0
:param bool [params.auto_size]: *contract only* Set side to close dual-mode position, close_long closes the long side, while close_short the short one, size also needs to be set to 0
:param int [params.price_type]: *contract only* 0 latest deal price, 1 mark price, 2 index price
:param float [params.cost]: *spot market buy only* the quote quantity that can be used alternative for the amount
:param bool [params.unifiedAccount]: set to True for creating an order in the unified account
:returns dict|None: `An order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr  r  	stopPricer  r  rS   rQ   ri   rj   )r  r  r  r  safe_value_2create_order_requestprivateSpotPostOrdersprivateSpotPostPriceOrdersprivateFuturesPostSettleOrders#privateFuturesPostSettlePriceOrdersprivateDeliveryPostSettleOrders$privateDeliveryPostSettlePriceOrdersprivateOptionsPostOrdersparse_order)r  r  r  r  r  r  r  r  r  r  r  r  isStopLossOrderisTakeProfitOrderisTpslnonTriggerOrderorderRequestr  s                     r  create_ordergate.create_order  s    H !!!&&(((V$//&)4((MN//&2CD't3+47 5$5$*:'T/00tU[&>VH-!%!;!;L!II!%!@!@!NNF^!%!D!D\!RR!%!I!I,!WWH!%!E!El!SS!%!J!J<!XX!::<HHHB &11} 	"( JN SW TXHs   G GG GCG 7G8G G*G <G=G G*G GG GG 5G6G G G G G G G G G r  c           	      T   / n/ n[        U5      nUS:X  a  [        U R                  S-   5      eUS:  a  [        U R                  S-   5      e[        S[        U5      5       H  nX   nU R	                  US5      nUR                  U5        U R	                  US5      n	U R	                  US5      n
U R                  US5      nU R                  US	5      nU R                  US
0 5      nU R                  X5      nU R                  U/ SQ5      nUb  [        U R                  S-   5      eSUS'   U R                  XXX5      nUR                  U5        M     U R                  US SSS5      nU R                  US   5      nUS   (       d
  US   (       a  [        U R                  S-   5      eU$ )Nr   z+ createOrders() requires at least one orderr  z8 createOrders() accepts a maximum of 10 orders at a timer  r  r  r  r  r  )r  r9  r  r  ze createOrders() does not support advanced order properties(stopPrice, takeProfitPrice, stopLossPrice)TtextIsRequiredFrj   rk   z; createOrders() does not support futures or options markets)r  r3   rC   r  r  r  r  r&  safe_value_nr9   r;  r  r  )r  r  r  ordersRequestsorderSymbolsordersLengthr  rawOrderr  r  r  r  r  orderParamsextendedParamstriggerValuerH  r  r  s                      r  create_orders_requestgate.create_orders_requestY  s   6{1TWW'TTUU"TWW'aabbq#f+&AyH''(;H)##Hf5D##Hf5D__Xx8FOOHg6E//(HbAK![[=N,,[:{|L'"477  .U  $U  V  V/3N+,44XTSXiL!!,/ '  %%lD%tLWQZ((vh/tww)ffggr  c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  X5      nUS   nU R                  US   5      nSnUS   (       a  U R	                  U5      I Sh  vN nO#US   (       a  U R                  U5      I Sh  vN nU R                  U5      $  N N N= N7f)aB  
create a list of trade orders

https://www.gate.com/docs/developers/apiv4/en/#get-a-single-order-2
https://www.gate.com/docs/developers/apiv4/en/#create-a-batch-of-orders
https://www.gate.com/docs/developers/apiv4/en/#create-a-batch-of-futures-orders

:param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr   r  rS   ri   )r  r  rU  r  privateSpotPostBatchOrders#privateFuturesPostSettleBatchOrdersparse_orders)r  r  r  rN  
firstOrderr  r  s          r  create_ordersgate.create_ordersw  s      !!!&&(((33FCAY
Z12&>!<<^LLHF^!EEnUUH  ** 	"( MUsD   B?B7B?B9AB?=B;>#B?!B="B?9B?;B?=B?c                    U R                  U5      nUS   nU R                  US5      n	U R                  USS5      n
U R                  USU
5      nU R                  US5      nUS LnUS LnU=(       d    UnU(       a  U(       a  [        U R                  S-   5      eU R                  US5      nU R                  U/ S	Q5      nS nU R                  US
:H  US:H  U5      u  nnU R                  U5      nU(       a  SnU R                  U/ SQ5      nUS:H  nUS
:H  nU(       a!  Uc  [        U R                  S-   U-   S-   5      eU(       ao  US:X  d  US:X  a  [        U R                  S-   5      eUc?  U R                  U R                  SS5      nU R                  U R                  S   US5      nUnU(       a  SnU(       aV  U R                  US5      nU(       a  SnO:U R                  X5      nUS:X  a  [        R                  " U5      OUn[        U5      nS nU(       + =(       a    U	S L nU(       Ga3  U(       aU  US   US.nUS   (       d  US   US'   U(       a  SUS'   OUS:X  a  SOU R!                  X5      US'   Ub  UUS '   Ub  UUS!'   GO?S nU R#                  S"U5      u  nnUS   UUUS#.nU(       a  US$:X  a  S nS%nU R%                  US&S'S%5      u  nnU R'                  US(5      n U R                  US(5      nU b  U R)                  UU 5      nOU(       ag  Uc  [+        U R                  S)-   5      eU R-                  U5      n!U R-                  U5      n"[        R.                  " U!U"5      n#U R)                  UU#5      nOU R)                  X5      nUUS*'   OU R                  X5      US*'   U(       a  U R!                  X5      US'   Ub  UUS+'   U R1                  US,S-5      n$U R3                  US.S"5      n%U$bP  [5        U$5      S/:  a  [7        U R                  S0-   5      eU R                  U/ S1Q5      nU$S   S2:w  a  S3U$-   n$U$US,'   GO;U%(       a  S3U R9                  5       -   US,'   GOUS   (       a  [;        U R                  S4-   5      eU(       Ga  US   US.US   S5.nUS
:X  a	  SUS6   S'   OUS:X  a  SOU R!                  X5      US6   S'   U	c  S n&S n'U(       a  US$:X  a  S7OS8n&U R!                  X5      n'O"U(       a  US$:X  a  S8OS7n&U R!                  X5      n'U R=                  US9S5      n(U(S:  d  U(S8:  a  [7        U R                  S:-   5      eU R                  US9/5      nU(U R!                  UU'5      U&S;.US'   Ub  UUS6   S '   Ub  UUS6   S!'   OU R                  U R                  S&0 5      n)S nU R#                  S%U5      u  nnUc  SnUUU R!                  X5      U R                  X5      UUS<.US   S=.nU	c  U R=                  U)S>5      n*U R=                  US>U*5      n+S n&S n'U(       a  US$:X  a  S?OS@n&U R!                  X5      n'O"U(       a  US$:X  a  S@OS?n&U R!                  X5      n'U R!                  UU'5      U&U+SA.US'   U R?                  UU5      $ )BNr  r  r  r9  r  r  zG createOrder() stopLossPrice and takeProfitPrice cannot both be defined
reduceOnly)r  tiftime_in_forcer  r  )r9  r  r  r  r_  r  postOnlyr  z- createOrder() requires a price argument for  ordersr  zF createOrder() timeInForce for market order can only be "FOK" or "IOC"defaultTimeInForcer  r  r  r   r^  r  rC   )r  r  rk   r  r  r  r  reduce_onlyr`  F)r_  r  r[   r  r  Trw   r  r  a	   createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend(quote quantity) in the amount argumentr  ra  r$  clientOrderIdrL     zF createOrder() clientOrderId or text param must be up to 28 characters)r$  rf  rL  rO  t-z: createOrder() conditional option orders are not supported)initialr  ri  r   r  
price_typezT createOrder() price_type should be 0 latest deal price, 1 mark price, 2 index price)rj  r  rule)r  r  r  r  r[   ra  )r  r  r  z>=z<=)r  rk  r  ) r  r  r:  r-   rC   safe_string_lower_nhandle_post_onlyhandle_time_in_forcera  r2   r  rT   amount_to_precisionr=   
string_negintprice_to_precisionrg  rs  r  cost_to_precisionr6   number_to_stringrA  rd  r  r  r3   uuid16r9   r  r&  ),r  r  r  r  r  r  r  r  r  r  r  r  r  rD  rE  rF  r_  exchangeSpecificTimeInForcerb  r  isLimitOrderisMarketOrder
defaultTifexchangeSpecificTifisCloseamountToPrecisionsignedAmountr*  rG  r  quoteAmountr  r  r  r  costRequestrf  rL  rk  triggerOrderPrice	priceTyperT   defaultExpirationr  s,                                               r  r;  gate.create_order_request  sg   V$*%//&)4((MN//&2CD't3+47 5$50*s stt__V\:
&*&>&>vGn&o#001AC^bgCgiop&//7K 6  $N  O)EM#DGG.]$]`d$dgp$pqqu$+*>#DGG.v$vww&!%!1!1$,,@TV[!\J*.*:*:4<<;VXbdi*j'"5Koofg6G$($<$<V$L!IMQWw112CD^o\*$*:'T/ !'t"	 h'(.z(:GH% '*GG$/4zs@W@WX^@fGG$)-7GM**%0GEN!
%)%9%9%%H"
F &,D\ ) 
 !dem"&K8<5@D@]@]^dfs  vY  [_  A`=5v++FF;D!YYvv6F'&*&<&<VT&J: =".tww  :E  0E  #F  F+/+@+@+HL*.*?*?*FK*1*<*<\;*WK*.*@*@*UK&*&<&<V&L(3GH%(,(@(@(PGH%'+'>'>v'MGG$*/:GO, ..vvOM!^^F4DeLN(
 }%*$TWW/w%wxx6+VW #s*$(=$8M"/!&*T[[]&:GFOh"477-i#ijj %+4L &  %Z0 8#25GI&w/:?1*#4KbKbciKqGI&w/?D(,%& &*U]q,0,C,CF,Z)*%)U]q,0,C,CF,\) $ 1 1&, JI 1}	A(  4J  *J  K  K!YYv~>F '0!%!8!8AR!S $	*GI& )8BGI&}5*0;GI&u- //$,,rJ!
%)%9%9$%G"
F&"'K !% $!%!8!8!G"&":":6"J#-)4 %Tl
 ?(,(9(9'<(P%!%!2!26<IZ![JD(,%& )-tD,0,C,CF,Z)*(,tD,0,C,CF,\)!%!8!8AR!S $&0*GI&
 {{7F++r  r  c                 "  #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS'   U R                  USSUSU5      I Sh  vN $  Nr N\ N7f)a  
create a market buy order by providing the symbol and cost

https://www.gate.com/docs/developers/apiv4/en/#create-an-order

:param str symbol: unified symbol of the market to create an order in
:param float cost: how much you want to trade in units of the quote currency
:param dict [params]: extra parameters specific to the exchange API endpoint
:param bool [params.unifiedAccount]: set to True for creating a unified account order
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
NrS   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr  r  r  )r  r  r  r9   rC   rI  )r  r  r  r  r  s        r  !create_market_buy_order_with_cost&gate.create_market_buy_order_with_costb  s      !!!&&(((V$f~tww)ddee6;23&&vxdFSSS 	"(
 Ts2   BB	BBABBBBBc                    U R                  U5      nS n	U R                  SX5      u  pU R                  U	5      n
SnU R                  USS5      u  pU(       a  Sn
US:H  nU
S:X  a+  U(       d$  [	        U R
                  S-   U-   S-   U	-   S	-   5      e[        U5      US
   U
S.nUb  US   (       a  U R                  X%5      US'   OaUS:X  a8  U R                  [        R                  " U R                  X%5      5      5      US'   O#U R                  U R                  X%5      5      US'   Ub  U R                  X&5      US'   US   (       d  US   US'   U R                  X5      $ )Nr   Fr  rY   r  rS   z editOrder() does not support z orders for  marketsrC   )r  r_  r[   r  r  r  r  r  r  )r  r  convert_type_to_accountrs  r6   rC   strro  parse_to_numericr=   rp  rr  r&  )r  rC   r  r  r  r  r  r  r  r  r[   rt  rw  r*  s                 r  edit_order_requestgate.edit_order_requestv  sv   V$
!??V\
..z: #'#@#@Vf#g Gf"477-M#MPT#TWe#ehr#ru#  A  AB#D\

 f~$($<$<V$L!6>&*&;&;G<N<NtOgOghnOw<x&yGFO&*&;&;D<T<TU[<d&eGFO#66vEGGf~ &z 2GH{{7++r  c           	      d  #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  U5      nU R                  XX4XVU5      n	Sn
US   (       a  U R	                  U	5      I Sh  vN n
OU R                  U	5      I Sh  vN n
U R                  X5      $  N N{ N3 N7f)a]  
edit a trade order, gate currently only supports the modification of the price or amount fields

https://www.gate.com/docs/developers/apiv4/en/#amend-an-order
https://www.gate.com/docs/developers/apiv4/en/#amend-an-order-2

: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 bool [params.unifiedAccount]: set to True for editing an order in a unified account
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
NrS   )r  r  r  r  privateSpotPatchOrdersOrderId$privateFuturesPutSettleOrdersOrderIdrC  )r  rC   r  r  r  r  r  r  r  extendedRequestr  s              r  
edit_ordergate.edit_order  s     " !!!&&(((V$11"d&Y_`&>!??PPH!FFWWH@ 11Q 	"(
 QWsD   B0B(B0B*A	B08B,9B0B.B0*B0,B0.B0c                 B    SSSSSSSSSSSS.nU R                  X!U5      $ )Nr]  closedr  )r]  _newfilled	cancelled
liquidatedr  r  expiredfinishedfinish	succeededr  r  s      r  parse_order_statusgate.parse_order_status  s?    #" ! !
 &99r  r  c           
      
   U R                  USS5      nU(       d6  U R                  U R                  US5      USU R                  US5      S.5      $ U R                  USS0 5      nU R	                  US	0 5      nU R                  US
5      nU R                  US5      nU R                  USS5      nU R                  USS5      n	U R                  US5      n
U R                  US5      nU R                  US
U5      nU R                  USU5      nU R                  USSU5      nUS:X  a  SnUS:H  nU R                  USSU	5      n	U R                  USU
5      n
U R                  USU5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  USS5      nU(       a  U	nSnU(       aN  [        R                  " US5      =(       a    US:H  nU(       a  SOSn[        R                  " U	S5      (       a  SOSn
U R                  U/ SQ5      nU R                  US5      nUc  U R                  US S!5      nU R                  US"5      nUc  U R                  US#S$5      nS
nS%U;   d  SU;   a  S&nU R                  US%SU5      nU R                  UUS'U5      n/ nU R                  US(5      nUb  UR!                  S)US*.5        U R                  US+5      nUb3  UR!                  U R#                  U R                  US,5      5      US*.5        U R                  US-5      nUbG  UR!                  U R#                  U R                  US.5      5      [        R$                  " U5      S*.5        ['        U5      nUS/:  nU R)                  U5      n[        R*                  " U5      nU R                  US05      n U S&:X  aa  U R                  US5      n!U R-                  U!5      nUS:X  a8  U
S:X  a2  [        R.                  " UU!5      nS nU	n[        R.                  " U	U!5      n	U R                  0 SU R                  US5      _S1U R                  US5      _S2U_S3U R1                  U5      _S4U_S5U_S6U_SU_S7U_S8U_S9U R	                  US:5      _SU
_SU_S;U_S<U_S[        R*                  " U	5      _S=[        R*                  " U5      _S UU(       a  S OU R	                  US>5      U(       a  UO/ S US?.EU5      $ )@Nr  Tr$  rejectedrC   )rf  r  r
  rC   r  ri  r  r  r  ra  r`  r  r  r  r  r  r  leftfilled_totalavg_deal_price
fill_pricer  r  r  r  r  r  )	finish_asr
  r]  r  r<  ctimeupdate_time_msupdate_timefinish_timer_  rS   r  r  r  r0  r   r  rebated_feerebated_fee_currencyr   r[   rf  r  r  lastTradeTimestampr
  r  r  rb  r_  is_reduce_onlyr  r`  r  r   )r  	remainingr   r  r   r  )r  
safe_orderr  r:  r  safe_string_upper_2rd  r  safe_number_2r=   string_equalsr3  rc  r  r  r  r  r  rp  r  r  r  r  r  rB  )"r  r  r  r  r  r  r  r  r  r  r  r  rb  remainingStringr  r  r`  rx  r6  r  r  r  exchangeSymbolr  r  r  r   rZ   numFeeCurrenciesmultipleFeeCurrenciesr
  r  r[   averageStrings"                                     r  rC  gate.parse_order  s   ` NN5+t<	??!%!1!1%!@$&&ud3	$   ui<//%B7##C4V,..sOUK##C6:V,  g.##E:x@vt4..uoukZ%K4'##E8VVDvt4  7**5&9~6''9$$U,<lK$OD#11%=X;RWCWM,8'D#--fc::5D&&u.MN	%%e-=>	--e]GLI!..u6FG%!%!6!6um]![
u$(e*;J++E?HhW!!.&#zJ  1KK   ue,?KK 33D4D4DUN4[\  !!%7KK 33D4D4DULb4cd**62  t9 01 4((3&&7	""5)4f ,,U4DEM''6G tu}#..N	 ++FMB  
$""5$/ 
T--eV< 
  
 Y/	 

 !"4 
 f 
 f 
 D 
 ; 
  
 $//%1AB 
 D 
 U 
 L 
 w 
  g((0! 
" G&&t,# 
$ "04doodA6N1Dr/ 
0 1 	r  c                    Uc  S OU R                  U5      nU R                  U/ SQS5      nU R                  U/ SQ5      nU R                  USS5      nUnUb$  U R                  USS/5      nUS   S:w  a  SU-   nUnU R	                  S	XC5      u  pUS
:H  =(       d    US:H  =(       d    US:H  n
U
(       a  U R                  XHU	5      OU R                  XEU	5      u  p[        U5      US'   X/$ )Nr  is_stop_orderstopFr  r  r  r$  rf  r   rO  rh  r   ri   rj   rk   r  )r  safe_bool_nra  rd  r  rc  ri  r  )r  rC   r  r  r  r  rf  r  r  rU  r  r*  r  s                r  fetch_order_requestgate.fetch_order_request  s
    .t{{6/B""6+OQVW6#GH**66?K$YYv'@AFQ3& $} 4#G88vVFNO(8Odh>NNV!5!5fE!J\`\{\{  }C  NS  ]T!'l
''r  c                 Z  #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   Uc  SOU R                  U5      nU R                  SXC5      nU R	                  US5      nU R                  U/ SQS5      nU R                  XU5      u  pSn
US:X  d  US:X  a[  U(       a*  U R                  U R                  X5      5      I Sh  vN n
GO/U R                  U R                  X5      5      I Sh  vN n
GOUS:X  aY  U(       a)  U R                  U R                  X5      5      I Sh  vN n
OU R                  U R                  X5      5      I Sh  vN n
OUS	:X  aY  U(       a)  U R                  U R                  X5      5      I Sh  vN n
OpU R                  U R                  X5      5      I Sh  vN n
OGUS
:X  a)  U R                  U R                  X5      5      I Sh  vN n
O[        U R                   S-   5      eU R#                  X5      $  GN GN GNM GN& N N N No NB7f)a  
Retrieves information on an order

https://www.gate.com/docs/developers/apiv4/en/#get-a-single-order
https://www.gate.com/docs/developers/apiv4/en/#get-a-single-order-2
https://www.gate.com/docs/developers/apiv4/en/#get-a-single-order-3
https://www.gate.com/docs/developers/apiv4/en/#get-a-single-order-4

:param str id: Order id
:param str symbol: Unified market symbol, *required for spot and margin*
:param dict [params]: Parameters specified by the exchange api
:param bool [params.trigger]: True if the order being fetched is a trigger order
:param str [params.marginMode]: 'cross' or 'isolated' - marginMode for margin trading if not provided self.options['defaultMarginMode'] is used
:param str [params.type]: 'spot', 'swap', or 'future', if not provided self.options['defaultMarginMode'] is used
:param str [params.settle]: 'btc' or 'usdt' - settle currency for perpetual swap and future - market settle currency is used if symbol is not None, default="usdt" for swap and "btc" for future
:param bool [params.unifiedAccount]: set to True for fetching a unified account order
:returns: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr   r   r  FrS   rQ   ri   rj   rk   z* fetchOrder() not support self market type)r  r  r  r  r  r  r   privateSpotGetPriceOrdersOrderIdr&  privateSpotGetOrdersOrderId)privateFuturesGetSettlePriceOrdersOrderId$privateFuturesGetSettleOrdersOrderId*privateDeliveryGetSettlePriceOrdersOrderId%privateDeliveryGetSettleOrdersOrderIdprivateOptionsGetOrdersOrderIdr9   rC   rC  )r  rC   r  r  r  r  r  r  r*  r  r  s              r  fetch_ordergate.fetch_order  s    & !!!&&((( .t{{6/B33L&Q*""6+OQVW!%!9!9"f!M6>TX-!%!F!Ft{{SZGj!kk!%!A!A$++gBe!ffV^!%!O!OPTP[P[\cPs!tt!%!J!J4;;W^Kn!ooX!%!P!PQUQ\Q\]dQt!uu!%!K!KDKKX_Lo!ppX!@@WAdeeHtww)UUVV117 	"( lf uo vpes   H+HH+HBH+H)H+8H96H+/H!0(H+H#5H+H%(H+7H'8.H+&H)'/H+H+H+H+!H+#H+%H+'H+)H+c                 D   #    U R                  SXX45      I Sh  vN $  N7f)a  
fetch all unfilled currently open orders

https://www.gate.com/docs/developers/apiv4/en/#list-all-open-orders
https://www.gate.com/docs/developers/apiv4/en/#retrieve-running-auto-order-list

: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 bool [params.trigger]: True for fetching trigger orders
:param str [params.type]: spot, margin, swap or future, if not provided self.options['defaultType'] is used
:param str [params.marginMode]: 'cross' or 'isolated' - marginMode for type='margin', if not provided self.options['defaultMarginMode'] is used
:param bool [params.unifiedAccount]: set to True for fetching unified account orders
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
r]  N)fetch_orders_by_status)r  r  r  r  r  s        r  fetch_open_ordersgate.fetch_open_orders   s"     " 00VVVV     c                 
  #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  US5      nSnUb  U R                  U5      nUS   nU R	                  SXd5      nU R                  US5      nSn	U R                  USSS5      u  pU	(       d'  Uc  Ub  US:w  a  U R                  S	XX45      I Sh  vN $ U R                  US
5      n0 n
U R                  XhU5      u  pUb  U R                  US-  5      U
S'   Ub)  U R                  US5      nU R                  US-  5      U
S'   Ub  X:S'   U R                  U R                  X5      5      I Sh  vN nU R                  XX#5      $  GNc GNN N N7f)a  
fetches information on multiple closed orders made by the user

https://www.gate.com/docs/developers/apiv4/en/#list-orders
https://www.gate.com/docs/developers/apiv4/en/#retrieve-running-auto-order-list
https://www.gate.com/docs/developers/apiv4/en/#list-futures-orders
https://www.gate.com/docs/developers/apiv4/en/#list-all-auto-orders
https://www.gate.com/docs/developers/apiv4/en/#list-futures-orders-2
https://www.gate.com/docs/developers/apiv4/en/#list-all-auto-orders-2
https://www.gate.com/docs/developers/apiv4/en/#list-options-orders
https://www.gate.com/docs/developers/apiv4/en/#list-futures-orders-by-time-range

:param str symbol: unified market symbol of the market orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param bool [params.trigger]: True for fetching trigger orders
:param str [params.type]: spot, swap or future, if not provided self.options['defaultType'] is used
:param str [params.marginMode]: 'cross' or 'isolated' - marginMode for margin trading if not provided self.options['defaultMarginMode'] is used
:param boolean [params.historical]: *swap only* True for using historical endpoint
:param bool [params.unifiedAccount]: set to True for fetching unified account orders
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr  r  r   r   F
historicalri   r  r  r  r  r  r  )r  r  r  r  r  r  rs  r  ra  rc  r  &privateFuturesGetSettleOrdersTimeranger&  rZ  )r  r  r  r  r  r  r  resr  useHistoricalr*  r  s               r  fetch_closed_ordersgate.fetch_closed_orders3  s    0 !!!&&(((!!&'2[[(FH%F001DfUQ' $ = =fFY[gin o5=U]PV44ZPU^^^66*..vVD"//=GFOYYvw/F --edl;GDM$GDDT[[QXEabb  5@@1 	"( _ csE   FE9FE<BFE?BF"F#F<F?FFc                 t   S nUb  U R                  U5      nUS   nS nU R                  USS5      u  puS nU R                  SXe5      u  pUS:H  =(       d    US:H  n	0 n
U	(       a  U R                  XgU5      OU R	                  XhU5      u  pU	(       a  U(       a  U R                  U
S5      n
US:X  a  S	nXS
'   Ub  XJS'   U	(       aX  Ub  U R                  US-  5      U
S'   U R                  US5      nUb)  U R                  US5      nU R                  US-  5      U
S'   U R                  USS5      u  pUb  XS'   X/$ )Nr  r  r  fetchOrdersByStatusrS   rQ   r[   r  r  r
  r  r  r  r  r  lastIdlast_id)	r  handle_param_bool_2r  rl  rc  ra  r  r  handle_param_string_2)r  r
  r  r  r  r  r  r  r  rS   r*  r  r  finalParamss                 r   prepare_orders_by_status_request%gate.prepare_orders_by_status_requeste  so   [[(FH%F2269fM99:OQW`5DH$4\`$??QWXfjfzfz  |B  JP  gQGii3GXF"$G "&"3"3EDL"A%%fg6E 673 $ 1 1%$, ?"889U!'I%%r  c                   #    U R                  5       I S h  vN   U R                  5       I S h  vN   S nUb  U R                  U5      nUS   nU R                  USS5      nU R	                  SXe5      nU R                  US5      n	U R                  XX4U5      u  pU	S:H  =(       d    U	S:H  nUS:H  nU=(       a    U=(       a    U(       + nS nU(       a  U(       d[  U(       a*  U R                  U R                  X5      5      I S h  vN nGOYU R                  U R                  X5      5      I S h  vN nGO/U R                  U R                  X5      5      I S h  vN nGOU	S	:X  aY  U(       a)  U R                  U R                  X5      5      I S h  vN nOU R                  U R                  X5      5      I S h  vN nOU	S
:X  aY  U(       a)  U R                  U R                  X5      5      I S h  vN nOpU R                  U R                  X5      5      I S h  vN nOGU	S:X  a)  U R                  U R                  X5      5      I S h  vN nO[!        U R"                  S-   5      eUnU(       aE  / n[%        S['        U5      5       H*  nU R)                  UU   S5      nU R+                  UU5      nM,     U R-                  UXcU5      nU R/                  UX#U5      $  GN GN GN GN GN GNX GN2 N N N7f)Nr  r  r  r  r   rS   rQ   r]  ri   rj   rk   z+ fetchOrders() not support self market typer  )r  r  r  safe_bool_2r  r  r  privateSpotGetOpenOrdersr&  privateSpotGetOrdersprivateSpotGetPriceOrders"privateFuturesGetSettlePriceOrdersprivateFuturesGetSettleOrders#privateDeliveryGetSettlePriceOrdersprivateDeliveryGetSettleOrdersprivateOptionsGetOrdersr9   rC   r  r  r  array_concatrZ  r   )r  r
  r  r  r  r  r  r  r  r  r*  r  rS   
openStatusopenSpotOrdersr  r  r  ordersInnerr  s                       r  r  gate.fetch_orders_by_status  s    !!!&&((([[(FH%F((FC001FWQ'!%!F!FvW\ek!l5DH$4&
<*<W%)%B%B4;;wCf%ggH%)%>%>t{{7?b%ccH!%!?!?G@c!ddV^!%!H!HU\Il!mm!%!C!CDKKPWDg!hhX!%!I!I$++V]Jm!nn!%!D!DT[[QXEh!iiX!99$++g:]^^Htww)VVWWf F1c(m,"oohqk8D**6;? - ""66%@00NN} 	"("  hcd nh oi^s   K2KK2KCK2K)K2-K .)K2K#6K2K&(K27K)85K2-K,.(K2K..K2K0BK2K2K2 K2#K2&K2)K2,K2.K20K2c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   Uc  SOU R                  U5      nU R                  U/ SQS5      nU R	                  U/ SQ5      nU R                  SXC5      u  pgUS:X  d  US:X  a  U R                  XEU5      OU R                  XFU5      u  pXS'   Sn
US:X  d  US:X  a[  U(       a*  U R                  U R                  X5      5      I Sh  vN n
GO/U R                  U R                  X5      5      I Sh  vN n
GOUS:X  aY  U(       a)  U R                  U R                  X5      5      I Sh  vN n
OU R                  U R                  X5      5      I Sh  vN n
OUS	:X  aY  U(       a)  U R                  U R                  X5      5      I Sh  vN n
OpU R                  U R                  X5      5      I Sh  vN n
OGUS
:X  a)  U R                  U R                  X5      5      I Sh  vN n
O[!        U R"                  S-   5      eU R%                  X5      $  GN% GN GNM GN& N N N No NB7f)a  
Cancels an open order

https://www.gate.com/docs/developers/apiv4/en/#cancel-a-single-order
https://www.gate.com/docs/developers/apiv4/en/#cancel-a-single-order-2
https://www.gate.com/docs/developers/apiv4/en/#cancel-a-single-order-3
https://www.gate.com/docs/developers/apiv4/en/#cancel-a-single-order-4

:param str id: Order id
:param str symbol: Unified market symbol
:param dict [params]: Parameters specified by the exchange api
:param bool [params.trigger]: True if the order to be cancelled is a trigger order
:param bool [params.unifiedAccount]: set to True for canceling unified account orders
:returns: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr  Frp   rS   rQ   r  ri   rj   rk   z+ cancelOrder() not support self market type)r  r  r  r  ra  r  ri  rc  #privateSpotDeletePriceOrdersOrderIdr&  privateSpotDeleteOrdersOrderId,privateFuturesDeleteSettlePriceOrdersOrderId'privateFuturesDeleteSettleOrdersOrderId-privateDeliveryDeleteSettlePriceOrdersOrderId(privateDeliveryDeleteSettleOrdersOrderId!privateOptionsDeleteOrdersOrderIdr9   rC   rC  )r  rC   r  r  r  r  r  rU  r*  r  r  s              r  cancel_ordergate.cancel_orderE  s'      !!!&&((( .t{{6/B""6+OQVW6#GH88W]aek]koswo!@!@RW!X  GK  G[  G[  \b  jo  Gp 
6>TX-!%!I!I$++V]Jm!nn!%!D!DT[[QXEh!iiV^!%!R!RSWS^S^_fSv!ww!%!M!MdkkZaNq!rrX!%!S!STXT_T_`gTw!xx!%!N!Nt{{[bOr!ssX!CCDKKPWDghhHtww)VVWWd 11[ 	"( oi xr yshs   IH;IH>CI4I5)II6II(I>I	?5I4I5(II.II/I>IIII	IIIIidsc                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SnUb  U R                  U5      nSnUc  SOUS   nU R                  USU5      nU R	                  SXC5      u  pSUS:H  nU(       a  Uc  [        U R                  S-   5      eU(       aQ  / n	[        S[        U5      5       H  n
X   nUUS.nU	R                  U5        M     U R                  X5      I Sh  vN $ SU0nU/n[        S[        U5      5       H  n
UR                  X   5        M     U R                  U5      I Sh  vN nU R                  U5      $  GNE GN0 Nj N7f)	a,  
cancel multiple orders

https://www.gate.com/docs/developers/apiv4/en/#cancel-a-batch-of-orders-with-an-id-list
https://www.gate.com/docs/developers/apiv4/en/#cancel-a-batch-of-orders-with-an-id-list-2

:param str[] ids: order ids
: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 bool [params.unifiedAccount]: set to True for canceling unified account orders
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr  r  rq   rS   z9 cancelOrders requires a symbol argument for spot marketsr   )rC   r  )r  r  r  r`  r  r2   rC   r  r  r  cancel_orders_for_symbols)privateFuturesPostSettleBatchCancelOrdersrZ  )r  r  r  r  r  r  rb  r  isSpotrN  r  rC   	orderItemr*  	finalListr  s                   r  cancel_ordersgate.cancel_orders  so     !!!&&((([[(F#)>x8H''-H99.&Y&.v~#DGG.i$ijjN1c#h'V$#	 %%i0 ( 77OOOf
 I	q#c(#ASV$ $GG	RR  **; 	"(( P SsE   E%EE%ECE%6E!7AE%E#E%E%!E%#E%c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   / n[        S[        U5      5       Hw  nX   nU R	                  US5      nU R                  U5      nUS   (       d  [        U R                  S-   5      eU R	                  US5      nUUS   S.n	UR                  U	5        My     U R                  U5      I Sh  vN n
U R                  U
5      $  N N N7f)aO  
cancel multiple orders for multiple symbols

https://www.gate.com/docs/developers/apiv4/en/#cancel-a-batch-of-orders-with-an-id-list

:param CancellationRequest[] orders: list of order ids with symbol, example [{"id": "a", "symbol": "BTC/USDT"}, {"id": "b", "symbol": "ETH/USDT"}]
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str[] [params.clientOrderIds]: client order ids
:param bool [params.unifiedAccount]: set to True for canceling unified account orders
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr   r  rS   z4 cancelOrdersForSymbols() supports only spot marketsrC   )rC   r_  )r  r  r  r  r  r  r9   rC   r   privateSpotPostCancelBatchOrdersrZ  )r  r  r  rN  r  r  r  r  rC   r  r  s              r  r  gate.cancel_orders_for_symbols  s      !!!&&(((q#f+&AIE%%eX6F[[(F&>"477-c#cdd!!%.B!'I !!), ' >>~NN   **1 	"( Os2   C5C/C5C1B*C5C3C51C53C5c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   Uc  SOU R                  U5      nU R                  USS5      nU R	                  USS/5      nU R                  SX25      u  pVUS:X  a  U R                  X4U5      OU R                  X5U5      u  pxSn	US:X  d  US:X  a[  U(       a*  U R                  U R                  Xx5      5      I Sh  vN n	GO/U R                  U R                  Xx5      5      I Sh  vN n	GOUS:X  aY  U(       a)  U R                  U R                  Xx5      5      I Sh  vN n	OU R                  U R                  Xx5      5      I Sh  vN n	OUS:X  aY  U(       a)  U R                  U R                  Xx5      5      I Sh  vN n	OpU R                  U R                  Xx5      5      I Sh  vN n	OGUS	:X  a)  U R                  U R                  Xx5      5      I Sh  vN n	O[!        U R"                  S
-   5      eU R%                  X5      $  GN GN GNM GN& N N N No NB7f)a  
cancel all open orders

https://www.gate.com/docs/developers/apiv4/en/#cancel-all-open-orders-in-specified-currency-pair
https://www.gate.com/docs/developers/apiv4/en/#cancel-all-open-orders-matched
https://www.gate.com/docs/developers/apiv4/en/#cancel-all-open-orders-matched-2
https://www.gate.com/docs/developers/apiv4/en/#cancel-all-open-orders-matched-3

: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 bool [params.unifiedAccount]: set to True for canceling unified account orders
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr  r  ro   rS   rQ   ri   rj   rk   z/ cancelAllOrders() not support self market type)r  r  r  r  ra  r  rl  rc  privateSpotDeletePriceOrdersr&  privateSpotDeleteOrders%privateFuturesDeleteSettlePriceOrders privateFuturesDeleteSettleOrders&privateDeliveryDeleteSettlePriceOrders!privateDeliveryDeleteSettleOrdersprivateOptionsDeleteOrdersr9   rC   rZ  )
r  r  r  r  r  r  rU  r*  r  r  s
             r  cancel_all_ordersgate.cancel_all_orders  s     !!!&&((( .t{{6/B""669=6FI#67889JF[cgkqcq!F!FvX]!^x|  yM  yM  NT  \a  yb6>TX-!%!B!B4;;wCf!gg!%!=!=dkk'>a!bbV^!%!K!KDKKX_Lo!pp!%!F!Ft{{SZGj!kkX!%!L!LT[[Y`Mp!qq!%!G!GT[Hk!llX!<<T[[=`aaHtww)ZZ[[:   22o 	"( hb qk rlas   IH/IH2B9I(H5))IH86I	H;
(I2H=35I(H?)(II.I I/I2I5I8I;I=I?IIIfromAccount	toAccountc                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  U5      nU R                  U5      nU R                  X5      n	US   U	S.n
XpR                  S   ;  a
  SU
S'   XzS'   OXzS'   XR                  S   ;  a
  SU
S'   XS'   OXS'   US:X  d  US:X  aY  U R                  US	S5      nUc  [        U R                  S
-   5      eU R                  U5      nUS   U
S'   U R                  US	5      nUS:X  d  US:X  d  US:X  d  US:X  a  US   U
S'   U R                  U R                  X5      5      I Sh  vN nU R                  X5      $  GNO N7f)az  
transfer currency internally between wallets on the same account

https://www.gate.com/docs/developers/apiv4/en/#transfer-between-trading-accounts

:param str code: unified currency code for currency being transferred
:param float amount: the amount of currency to transfer
:param str fromAccount: the account to transfer currency from
:param str toAccount: the account to transfer currency to
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.symbol]: Unified market symbol *required for type == margin*
:returns: A `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
NrC   r|  r  r  rQ   r  r_  r  r  zA transfer requires params["symbol"] for isolated margin transfersrP   rR   r  )r  r|  r  r  rT   rd  r2   rC   r  ra  privateWalletPostTransfersr&  parse_transfer)r  r  r  r  r  r  r|  fromIdtoId	truncatedr*  r  r  r  s                 r  r   gate.transfer]  s     !!!==&--k:++I6..t<	 
 ,,'788&GFO'-O$$FO%566$GDM'+O$ DMX!1''/JF~'2u(uvv[[(F'-d|GO$YYvx0FI4:#56Y;NTZ^hTh (GH88W9UVV ""866Q 	"8 Ws"   E*E%D8E*E(E*(E*r   c           
      Z    U R                  US5      S S U R                  S U5      S S S S US.	$ )Ntx_id)	rC   r  r  r|  r  r  r  r
  r  )r  r  )r  r   r|  s      r  r  gate.parse_transfer  sC     ""8W5//h?

 
	
r  r  c                   #    Uc  [        U R                  S-   5      eUS:  d  US:  a  [        U R                  S-   5      eU R                  5       I Sh  vN   U R	                  U5      nU R                  USU5      u  pVU R                  U R                  SS5      nU R                  US5      nU R                  USU5      n	U R                  U5      n
Ub  S	n	Un
U	S	:X  d  U	S
:X  a
  XS'   SUS'   OXS'   SnUS   (       a*  U R                  U R                  XV5      5      I Sh  vN nU$ US   (       a*  U R                  U R                  XV5      5      I Sh  vN nU$ [        U R                  S-   5      e GN! NU N#7f)a  
set the level of leverage for a market

https://www.gate.com/docs/developers/apiv4/en/#update-position-leverage
https://www.gate.com/docs/developers/apiv4/en/#update-position-leverage-2

:param float leverage: the rate of leverage
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from the exchange
Nz) setLeverage() requires a symbol argumentr   r   z3 setLeverage() leverage should be between 1 and 100r  ro  cross_leverage_limitr  r  r  r  ri   rj   z+ setLeverage() not support self market type)r2   rC   r3   r  r  rc  rd  rT   r  rt  1privateFuturesPostSettlePositionsContractLeverager&  2privateDeliveryPostSettlePositionsContractLeverager9   )r  r  r  r  r  r*  rU  ro  crossLeverageLimitr  stringifiedMarginr  s               r  set_leveragegate.set_leverage  s     >#DGG.Y$YZZ qLhnTWW'\\]]!!!V$--fdFC ..t||\K^_!--e5KL%%e\;LM
 11(;) J 2 J.$@.?*+"%GJ"3J&>!SSTXT_T_`gToppH@ ? H!TTUYU`U`ahUpqqH< 9 tww)VVWW+ 	"" qqs7   AE=E6CE=#E9$3E=E;E=9E=;E=positionc                    U R                  US5      nU R                  X2SS5      nU R                  USS5      nU R                  US5      nUc=  [        R                  " US5      (       a  SnO[        R
                  " US5      (       a  SnU R                  US	5      nU R                  US
5      nU R                  US5      nS n	Ub  US:X  a  Sn	OSn	U R                  US5      n
S nU
cC  Sn[        R                  " X5      n
[        R                  " [        R                  " Xx5      U
5      nU R                  USS5      nUS:X  a  S nU R                  0 SU_SS _SU R                  US5      _SU_SU R                  U5      _SU R                  USS5      _SU R                  U5      _SU R                  [        R                  " X5      5      _SU R                  [        R                  " Xg5      5      _SU R                  U5      _SU R                  US 5      _S!U R                  U5      _SU R                  US5      _S"U R                  US#5      _S$U R                  US%S&5      _S'U R                  [        R                  " U5      5      _S(U R                  US(5      _S U R                  US)5      U R                  US*5      S U R                  US+5      U	US S S S,.
E5      $ )-Nr  r  r  
accum_sizer  r  longshortmaintenance_ratevaluer  r  r  pnl_feer  	open_timefirst_open_timer   r  rC   r  r  r  lastUpdateTimestampr  r   initialMargininitialMarginPercentagemaintenanceMarginmaintenanceMarginPercentage
entryPriceentry_pricenotionalunrealizedPnlunrealised_pnlrealizedPnlrealised_pnlpnlr   r  	liq_pricer5  rQ   )
marginRatioliquidationPricerF  	lastPrice
collateralr  r  r"  r  r  )r  r  rd  r=   r3  r  rA  r@  r  r  safe_positionrB  r  r  r  r  )r  r%  r  r  r  r  maintenanceRater6  r  r  feePaidinitialMarginStringtakerFeer  s                 r  parse_positiongate.parse_position  sH   V ##Hj9!!(CD!!(FLA&1<  s++""4--**85GH##Hg6##Hj9
3$
'
 ""8Y7"? H((<G")"4"4W5G5G5[]d"e))(KARS	>I!! #
H#
$#
 d&&vx8#
 	#

 Y/#
 "4#8#8=RX#Y#
 T../BC#
 &t'8'89K9KL_9j'k#
  !2!273E3Eo3`!a#
 *4+<+<_+M#
 $**8]C#
 ))(3#
 ((:>#
 T--h8HI#
 4--hN#
  **7+=+=d+CD!#
" D,,V^D##
$   $ 0 0; G))(LA**8X>$!#7#
  	r  c                   #    U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      e0 nU R	                  X3S   U5      u  pBU R                  XB5      nSnUS   (       a  U R                  U5      I Sh  vN nOFUS   (       a  U R                  U5      I Sh  vN nO"US   S:X  a  U R                  U5      I Sh  vN nU R                  Xc5      $  N N^ N< N7f)a  
fetch data on an open contract position

https://www.gate.com/docs/developers/apiv4/en/#get-single-position
https://www.gate.com/docs/developers/apiv4/en/#get-single-position-2
https://www.gate.com/docs/developers/apiv4/en/#get-specified-contract-position

:param str symbol: unified market symbol of the market the position is held in
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
Nr  z/ fetchPosition() supports contract markets onlyr  ri   rj   rk   )
r  r  r3   rC   rc  r&  (privateFuturesGetSettlePositionsContract)privateDeliveryGetSettlePositionsContract"privateOptionsGetPositionsContractrF  )r  r  r  r  r*  r  r  s          r  fetch_positiongate.fetch_positionw  s      !!!V$j!TWW'XXYY..vf~vN++g6&>!JJ?[[HH!KKO\\HF^x'!DD_UUHr ""844M 	" \\UsF   C=C5BC=C7#C=<C9="C=C; C=7C=9C=;C=c                   #    U R                  5       I Sh  vN   SnU R                  USSSS5      nUb%  [        U5      nUS:  a  U R                  US   5      nSn0 nU R	                  SX25      u  pRUb  US:X  a  SnUS:X  a/  Ub+  US   nUR                  S	5      nU R                  US5      US
'   OU R                  SXR5      u  pbSn	US:X  a)  U R                  U R                  Xb5      5      I Sh  vN n	O]US:X  a)  U R                  U R                  Xb5      5      I Sh  vN n	O.US:X  a(  U R                  U R                  Xb5      5      I Sh  vN n	U R                  X5      $  GNO Nv NI N7f)a  
fetch all open positions

https://www.gate.com/docs/developers/apiv4/en/#list-all-positions-of-a-user
https://www.gate.com/docs/developers/apiv4/en/#list-all-positions-of-a-user-2
https://www.gate.com/docs/developers/apiv4/en/#list-user-s-positions-of-specified-underlying

:param str[]|None symbols: Not used by gate, but parsed internally by CCXT
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.settle]: 'btc' or 'usdt' - settle currency for perpetual swap and future - default="usdt" for swap and "btc" for future
:param str [params.type]: swap, future or option, if not provided self.options['defaultType'] is used
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
NTr   r   rS   ri   rk   rC   r  rN  rj   )r  r  r  r  r  r  r  rc   privateFuturesGetSettlePositionsr&  !privateDeliveryGetSettlePositionsprivateOptionsGetPositionsparse_positions)
r  r  r  r  symbolsLengthr  r*  r  r  r  s
             r  fetch_positionsgate.fetch_positions  sv     !!!%%gtT4FLMq WQZ099:JF[LdfnD8"!$<&nnS1(,(8(8a(H%"224FOG6>!BB4;;wC_``HX!CCDKKPWD`aaHX!<<T[[=YZZHz ##H66m 	"* aaZsF   E.E%CE.1E(2.E. E*!.E.E,E.(E.*E.,E.c                   #    U R                  5       I Sh  vN   U R                  SSU5      u  p4U R                  SX45      u  pVUS:w  a  US:w  a  [        U R                  S-   5      eSnUS:X  a)  U R                  U R                  XV5      5      I Sh  vN nOGUS:X  a)  U R                  U R                  XV5      5      I Sh  vN nO[        U R                  S-   5      eU R                  XqS5      $  N N` N37f)a  
retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes

https://www.gate.com/docs/developers/apiv4/en/#list-all-futures-contracts
https://www.gate.com/docs/developers/apiv4/en/#list-all-futures-contracts-2

:param str[] [symbols]: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `leverage tiers structures <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`, indexed by market symbols
Nr   rj   ri   z1 fetchLeverageTiers only supports swap and futurez2 fetchLeverageTiers() not support self market typerD   )
r  r  rc  r3   rC   r%  r&  r.  r9   parse_leverage_tiers)r  r  r  r  rU  r*  r  r  s           r  fetch_leverage_tiersgate.fetch_leverage_tiers1  s      !!!889MtU[\!%!5!5dD!H8TWW'ZZ[[6>!AA$++gBeffHX!BB4;;wCfggHtww)]]^^z ((FCCQ 	" ggs4   C8C2A<C8C4.C8C60C84C86C8c                 n  #    U R                  5       I Sh  vN   U R                  U5      nU R                  SX25      u  pEU R                  X4U5      u  pgUS:w  a  US:w  a  [	        U R
                  S-   5      eU R                  U R                  Xg5      5      I Sh  vN nU R                  X5      $  N N7f)a  
retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes for a single market

https://www.gate.com/docs/developers/apiv4/en/#list-risk-limit-tiers

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `leverage tiers structure <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`
Nr   rj   ri   z7 fetchMarketLeverageTiers only supports swap and future)	r  r  r  rc  r3   rC   $publicFuturesGetSettleRiskLimitTiersr&  parse_market_leverage_tiers)	r  r  r  r  r  rU  r*  r  r  s	            r  fetch_market_leverage_tiers gate.fetch_market_leverage_tiers  s      !!!V$889SU[d!%!5!5fE!J8TWW'``aaBB4;;wCfgg //AA% 	" hs"   B5B1BB5B3B53B5c                 R   U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n[        R                  " SU5      nUn	Un
Sn/ n[        R                  " X5      (       Ga  [        R                  " X5      nUR                  U R                  [        R                  " X5      5      U R                  X2S S5      U R                  US	5      U R                  U5      U R                  U5      U R                  U	5      U R                  [        R                  " SU
5      5      US
.5        [        R                  " X5      n	[        R                  " X5      n
Un[        R                  " X5      (       a  GM  U$ )NrD   r*  r9  risk_limit_steprisk_limit_maxr  r  r  r  tierr  r|  minNotionalmaxNotionalmaintenanceMarginRatemaxLeverager  )r  r=   r  r  r@  r  r  r  )r  r  r  r  maintenanceMarginUnitleverageMaxriskLimitStepriskLimitMaxinitialMarginUnitrf  initialMarginRatiofloorr#  caps                 r  parse_emulated_leverage_tiers"gate.parse_emulated_leverage_tiers  s   ##D&1 $ 0 07I J&&t^<((/@A''.>?#..sK@ 5.44$$U:CLL))'*<*<S*PQ**8T:N ,,VX>#007#005)-):):;P)Q#001C1CCI[1\]	 	 %,$6$67L$d!!(!3!34F!ZE 44 r  c                 b   [        U[        5      (       d  U R                  X5      $ Sn/ n[        S[	        U5      5       Hk  nX   nU R                  US5      nUR                  U R                  US5      US   US   UUU R                  US5      U R                  US5      US.5        UnMm     U$ )	Nr   
risk_limitr   r  r$  r*  r9  rb  )r  r  rp  r  r  r  r  r  )r  r  r  rd  r#  r  itemre  s           r  r\   gate.parse_market_leverage_tiers  s     $%%55dCCq#d)$A7D**4>KLLA *"6N**)-)9)9$@R)S#//nE	 	 &K % r  c                 \  #    U R                  5       I Sh  vN   U R                  U5      nUS   R                  5       U R                  X#5      S.nU R	                  U5      nUS   US'   SUS'   U R                  U R                  Xd5      5      I Sh  vN nU R                  X5      $  N N7f)aT  
repay borrowed margin and interest

https://www.gate.com/docs/apiv4/en/#repay-a-loan

:param str symbol: unified market symbol
:param str code: unified currency code of the currency to repay
:param float amount: the amount to repay
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.mode]: 'all' or 'partial' payment mode, extra parameter required for isolated margin
:param str [params.id]: '34267567' loan id, extra parameter required for isolated margin
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
NrC   r  r_  repayr  r  r|  upperr  r  privateMarginPostUniLoansr&  parse_margin_loan)	r  r  r  r  r  r|  r*  r  r  s	            r  repay_isolated_margingate.repay_isolated_margin   s      !!!==& ,,.00>
 V$#)$< !77G8TUU %%h99 	" Vs"   B,B(A;B,B*B,*B,c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  U5      nUS   R                  5       U R	                  X5      S.nSnU R                  USS5      u  pcSnU(       a.  SUS'   U R                  U R                  XS5      5      I Sh  vN nO:U R                  U R                  XS5      5      I Sh  vN nU R                  US	5      nU R                  Xt5      $  N N NT N-7f)
a  
repay cross margin borrowed margin and interest

https://www.gate.com/docs/developers/apiv4/en/#cross-margin-repayments
https://www.gate.com/docs/developers/apiv4/en/#borrow-or-repay

:param str code: unified currency code of the currency to repay
:param float amount: the amount to repay
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.mode]: 'all' or 'partial' payment mode, extra parameter required for isolated margin
:param str [params.id]: '34267567' loan id, extra parameter required for isolated margin
:param boolean [params.unifiedAccount]: set to True for repaying in the unified account
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
NrC   r  Fr   r  rw  r  r   )r  r  r|  ry  r  rs  privateUnifiedPostLoansr&   privateMarginPostCrossRepaymentsr  r{  r  r  r  r  r|  r*  rt  r  s           r  repay_cross_margingate.repay_cross_margin  s      !!!&&(((==& ,,.00>
 !#'#@#@I[]m#n %GFO!99$++g:VWWH!BB4;;wC_``H~~h2H" %%h99A 	"( X`sD   D
DD
DBD
1D2(D
D(D
D
D
D
c                 `  #    U R                  5       I Sh  vN   U R                  U5      nUS   R                  5       U R                  X#5      S.nSnU R	                  U5      nUS   US'   SUS'   U R                  U R                  Xd5      5      I Sh  vN nU R                  Xu5      $  N N7f)a  
create a loan to borrow margin

https://www.gate.com/docs/developers/apiv4/en/#marginuni

:param str symbol: unified market symbol, required for isolated margin
:param str code: unified currency code of the currency to borrow
:param float amount: the amount to borrow
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.rate]: '0.0002' or '0.002' extra parameter required for isolated margin
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
NrC   r  r_  borrowr  rx  )	r  r  r  r  r  r|  r*  r  r  s	            r  borrow_isolated_margingate.borrow_isolated_marginN  s      !!!==& ,,.00>
 V$#)$< "77G8TUU( %%h99= 	" Vs"   B.B*A=B.B,B.,B.c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  U5      nUS   R                  5       U R	                  X5      S.nSnU R                  USS5      u  pcSnU(       a.  SUS'   U R                  U R                  XS5      5      I Sh  vN nO(U R                  U R                  XS5      5      I Sh  vN nU R                  Xt5      $  N N NB N7f)	ap  
create a loan to borrow margin

https://www.gate.com/docs/apiv4/en/#create-a-cross-margin-borrow-loan
https://www.gate.com/docs/developers/apiv4/en/#borrow-or-repay

:param str code: unified currency code of the currency to borrow
:param float amount: the amount to borrow
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.rate]: '0.0002' or '0.002' extra parameter required for isolated margin
:param boolean [params.unifiedAccount]: set to True for borrowing in the unified account
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
NrC   r  Frm   r  r  r  )
r  r  r|  ry  r  rs  r  r&  privateMarginPostCrossLoansr{  r  s           r  borrow_cross_margingate.borrow_cross_margin{  s      !!!&&(((==& ,,.00>
 !#'#@#@I\^n#o &GFO!99$++g:VWWH!==dkk'>Z[[H %%h99; 	"( X[sD   C8C0C8C2BC81C42(C8C6C82C84C86C8c           	         U R                  U R                  SSS5      nU R                  US5      nUS:X  a  U R                  US5      nU R	                  US5      nU R	                  US5      nU R                  US5      U R                  XR5      U R                  US	5      U R                  US S
S5      UU R                  U5      US.$ )Nro  r  r  r<  r  r|  r_  rC   r  r  rQ   )rC   r|  r  r  r  r  r  )	rd  rT   r  r=  r  r  r  r  rB  )r  r  r|  r  r  r  r  s          r  r{  gate.parse_margin_loan  s    J ''6I<Y`a
%%dM:	#++D-@I%%dJ7
##D/:##D$///
E&&tX6&&xsHE"Y/
 	
r  c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SnU R                  USS5      u  pe0 nU R                  SXu5      u  puSnUb  U R	                  U5      nUS   US'   Sn	Ub  U R                  U5      n	Ub  X7S'   Ub  XGS	'   Sn
SnU R                  SUS
5      u  pU(       a)  U R                  U R                  Xu5      5      I Sh  vN n
OhUS:X  a4  U	b  U	S   US'   U R                  U R                  Xu5      5      I Sh  vN n
O.US
:X  a(  U R                  U R                  Xu5      5      I Sh  vN n
U R                  X5      nU R                  XX45      $  GN` GNK N N^ N17f)ah  
fetch the interest owed by the user for borrowing currency for margin trading

https://www.gate.com/docs/developers/apiv4/en/#list-interest-records
https://www.gate.com/docs/developers/apiv4/en/#interest-records-for-the-cross-margin-account
https://www.gate.com/docs/developers/apiv4/en/#list-interest-records-2

:param str [code]: unified currency code
:param str [symbol]: unified market symbol when fetching interest in isolated markets
:param int [since]: the earliest time in ms to fetch borrow interest for
:param int [limit]: the maximum number of structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.unifiedAccount]: set to True for fetching borrow interest in the unified account
:returns dict[]: a list of `borrow interest structures <https://docs.ccxt.com/#/?id=borrow-interest-structure>`
NFr   r  r  rC   r|  r  r  r  r  r_  )r  r  rs  r  r|  r  handle_margin_mode_and_params privateUnifiedGetInterestRecordsr&  "privateMarginGetUniInterestRecords$privateMarginGetCrossInterestRecordsparse_borrow_interestsfilter_by_currency_since_limit)r  r  r  r  r  r  rt  r*  r|  r  r  r  interests                r  fetch_borrow_interestgate.fetch_borrow_interest  s      !!!&&((( #'#@#@I^`p#q 224I}}T*H"*4.GJ[[(F#FO$G
!??@UW]_fg
!BB4;;wC_``H:%!+1$<(!DDT[[QXEabbH7"!FFt{{SZGcddH..x@2285PP; 	"(( a cdsV   FE6FE9B6F%E<&9FE> .FF (F9F<F>F Fr  c                 N   U R                  US5      nU R                  X25      nUb  SOSnU R                  US5      nUU R                  US5      U R                  U R                  US5      5      U R	                  US5      U R	                  US5      S UUU R                  U5      S	.	$ )
Nr_  r  r  r<  r  r|  r  actual_rate)	r  r  r|  r  r  amountBorrowedr  r  r  )r  r  r  r  r  rB  )r  r  r  r  r  r  s         r  parse_borrow_interestgate.parse_borrow_interest  s    ##D/:!!(3$,$8Zw
%%dM:	&&vx8//0@0@z0RS((z: ,,T=A"$"Y/

 
	
r  c                 B    U R                  5       U R                  S   -
  $ )Nr  )millisecondsrT   )r  s    r  r.  
gate.nonce  s       "T\\2B%CCCr  GETc                    US   nUS   nU R                  X@R                  U5      5      n	UR                  S5      S:  n
U
(       aq  UR                  S5      (       a[  U R	                  US5      nU R                  X5      n/ nUn[        S[        U5      5       H  nUR                  XN   5        M     UnUn	OK[        U[        5      (       a%  U R                  US0 5      nU R                  X5      nOU R                  X5      nUS:X  a  SOSU-   nSU-   U-   nUS:X  d  US	:X  a  UnU R                  S
   U   U   nUc  [        U R                  S-   U-   S-   5      eUU-  nUS:X  a   U	(       a  USU R                  U	5      -   -  nGOEU R!                  5         SnSnUS:X  d  US:X  aY  US:X  aS  UR#                  S5      nU R%                  USS5      nUR                  S5      S:  =(       d    UR                  S5      S:  nUS:X  d  US:X  d  U(       d  US:X  at  U	(       aU  U R                  U	5      nUR                  S5      S:  a'  UR                  S5      S:  a  UR'                  SS5      nUSU-   -  nUS:X  a  U R)                  U	5      nOVU R                  U	S0 5      nU(       a  U R                  U5      nUSU-   -  nU R                  U	S5      n	U R)                  U	5      nUc  SOUnU R+                  U R-                  U5      S5      nU R/                  5       nU R1                  US-  5      n[3        U5      nSU R4                  -   U-   nUR7                  5       UUUU/nSR9                  U5      nU R;                  U R-                  U5      U R-                  U R<                  5      [>        R@                  5      n U RB                  UU S S!.nUX6US".$ )#Nr   r   r  r  batch_cancel_ordersr3  r  rX   rW   rd   z! does not have a testnet for the z market type.r]   ?FrP   rR   POSTdualr:  r  DELETEPATCHzcurrencies=z%2C,rU  sha512r  z/api/
zapplication/json)KEY	TimestampSIGNzContent-Type)r_   rw  bodyr  )"ra  extract_paramsr  endswithr  implode_paramsr  r  r  r  r  r  rN   r9   rC   	urlencoder  r  r  replacejsonhashencoder.  r  r  rJ   ry  joinhmacr  hashlibr  r  )!r  pathrd   rw  r  r  r  authenticationr  rU  containsSettler  	newParams	anyParamsr  rl  endPart
entirePathr_   queryStringrequiresURLEncoding	pathParts
secondParturlQueryParamsbodyPayloadbodySignaturer.  r  timestampStringsignaturePathpayloadArraypayload	signatures!                                    r  sign	gate.sign   s   Q1v		&"5"5d";<8,r1dmm,ABB ^^FA.F&&t4DII1c)n-  + .FE%% OOFAr2E&&t3D&&t4D"3:4Z')
M!t}'< Jii~.t4;tww)LLtSVeeffzX%sT^^E222++-K"'"
(:6AQ JJsO	!--iB?
'1v'>!'C&kYdIeijIj#%Vx%7<OTZ^eTe"&.."7K"''6!;@P@PQV@W[\@\&1&9&9%&E3,,CW$99U+D!%!D!"&.."@K3,,C		%1yy'!%"DK IIdkk+&>IMJJLE))%$,7I!)nO#dll2Z?M"LLNM;WfgLii-G		$++g"6DKK8PRYR`R`aI{{,! 2	G fwOOr  c                   #    U R                  5       I S h  vN   U R                  U5      nU R                  US U5      u  pVU R                  U5      US'   S nUS   (       a)  U R	                  U R                  XV5      5      I S h  vN nOKUS   (       a)  U R                  U R                  XV5      5      I S h  vN nO[        U R                  S-   5      eU R                  Xt5      $  N Nc N27f)Nr%  ri   rj   z2 modifyMarginHelper() not support self market type)
r  r  rc  rt  /privateFuturesPostSettlePositionsContractMarginr&  0privateDeliveryPostSettlePositionsContractMarginr9   rC   parse_margin_modification)r  r  r  r  r  r*  rU  r  s           r  modify_margin_helpergate.modify_margin_helpern  s     !!!V$--fdFC 11&9&>!QQRVR]R]^eRmnnHH!RRSWS^S^_fSnooHtww)]]^^--h?? 	" oos4   C,C&A-C,C(2C,7C*8/C,(C,*C,r  c                     U R                  US5      nU R                  X2SS5      nU R                  US5      nUUS   S SS UU R                  US5      SS S S.
$ )	Nr  r  rQ   r  r  r  r  )
r  r  r  r  r  ru  r  r
  r  r  )r  r  r  r  )r  r  r  r  ru  s        r  r  gate.parse_margin_modification|  st    8 ##D*5!!(CD  x0X&$OOFG4
 	
r  c                 D   #    U R                  X* U5      I Sh  vN $  N7f)a  
remove margin from a position

https://www.gate.com/docs/developers/apiv4/en/#update-position-margin
https://www.gate.com/docs/developers/apiv4/en/#update-position-margin-2

: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>`
Nr  r  r  r  r  s       r  reduce_margingate.reduce_margin  s"      ..vwGGGGr  c                 B   #    U R                  XU5      I Sh  vN $  N7f)a  
add margin

https://www.gate.com/docs/developers/apiv4/en/#update-position-margin
https://www.gate.com/docs/developers/apiv4/en/#update-position-margin-2

: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>`
Nr  r  s       r  
add_margingate.add_margin  s       ..vvFFFFs   rN  c           	         #    U R                  5       I Sh  vN   SnU R                  USSS5      u  peU(       a  U R                  SXXBUS5      I Sh  vN $ U R                  U5      nUS   (       d  [	        U R
                  S-   5      eUS   US	   U R                  U R                  X"5      S
.nUb  XHS'   Ub  X8S'   U R                  U R                  X5      5      I Sh  vN n	U R                  XX45      $  N N N7f)a  
Retrieves the open interest of a currency

https://www.gate.com/docs/developers/apiv4/en/#futures-stats

:param str symbol: Unified CCXT market symbol
:param str timeframe: "5m", "15m", "30m", "1h", "4h", "1d"
:param int [since]: the time(ms) of the earliest record to retrieve unix timestamp
:param int [limit]: default 30
:param dict [params]: exchange specific parameters
: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} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
NFr   r  r   ri   z/ fetchOpenInterest() supports swap markets onlyrC   r  )r  r  r  r  r  )r  rs  r  r  r3   rC   r  rK  #publicFuturesGetSettleContractStatsr&  parse_open_interests_history)
r  r  r  r  r  r  r  r  r*  r  s
             r  fetch_open_interest_history gate.fetch_open_interest_history  s#     !!!88A[]gino@@A[]clq  E  GJ  K  K  KV$f~TWW'XXYYtZ((()O

 $G#FOAA$++gB^__, 005PPO 	" K `s4   C>C8;C>C:BC>!C<"C>:C><C>c                     U R                  US5      nU R                  US5      U R                  US5      U R                  US5      UU R                  U5      US.$ )Nr   r  open_interestopen_interest_usd)r  openInterestAmountopenInterestValuer  r  r  )r=  r  r  rB  )r  r  r  r  s       r  parse_open_interestgate.parse_open_interest  sc    & ''&9	&&vx8"&"2"28_"M!%!1!1(<O!P"Y/
 	
r  c                 ,  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nSnU R	                  SXT5      u  pdUS:w  a  [        U R                  S-   5      eUS   nUR                  S5      nSU R                  US	5      0n	Ub  X)S
'   Ub  X9S'   U R                  U R                  X5      5      I Sh  vN n
U R                  X5      nU R                  US5      nU R                  XX#5      $  N N;7f)a  
fetches historical settlement records

https://www.gate.com/docs/developers/apiv4/en/#list-settlement-history-2

:param str symbol: unified market symbol of the settlement history, required on gate
:param int [since]: timestamp in ms
:param int [limit]: number of records
:param dict [params]: exchange specific params
:returns dict[]: a list of `settlement history objects <https://docs.ccxt.com/#/?id=settlement-history-structure>`
Nz4 fetchSettlementHistory() requires a symbol argumentr   rk   z6 fetchSettlementHistory() supports option markets onlyrC   r  rN  r   r  r  r  )r2   rC   r  r  r  r9   r  r  publicOptionsGetSettlementsr&  parse_settlementsr  r   )r  r  r  r  r  r  r  r  r  r*  r  r   r!  s                r  fetch_settlement_historygate.fetch_settlement_history  s"     >#DGG.d$dee!!!V$99:RTZc8tww)aabb$<nnS)$**;:
 #FO$G99$++g:VWW ,,X>k;700NN= 	" Xs"   /DDB$DD:DDc                   #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nSnU R	                  SXT5      u  pdUS:w  a  [        U R                  S-   5      eUS   nUR                  S5      nU R                  US5      US	.n	Ub  X)S
'   Ub  X9S'   U R                  U R                  X5      5      I Sh  vN n
U R                  U
S0 5      nU R                  US/ 5      nU R                  X5      nU R                  US5      nU R                  XS   X#5      $  GN	 Ne7f)at  
fetches historical settlement records of the user

https://www.gate.com/docs/developers/apiv4/en/#list-my-options-settlements

:param str symbol: unified market symbol of the settlement history
:param int [since]: timestamp in ms
:param int [limit]: number of records
:param dict [params]: exchange specific params
:returns dict[]: a list of [settlement history objects]
Nz6 fetchMySettlementHistory() requires a symbol argumentr   rk   z8 fetchMySettlementHistory() supports option markets onlyrC   r  r   )rN  r  r  r  r  r  r  r  )r2   rC   r  r  r  r9   r  r  privateOptionsGetMySettlementsr&  r  r  r  r   )r  r  r  r  r  r  r  r  r  r*  r  r  r  r   r!  s                  r  fetch_my_settlement_history gate.fetch_my_settlement_historyF  sM     >#DGG.f$fgg!!!V$99:TV\e8tww)ccdd$<nnS)**;: 
 #FO$G<<T[[=YZZ  8R8vvr2,,T:k;7009I5XXI 	"  [s#   /D?D:B%D?D=A#D?=D?c                     U R                  US5      nU R                  US5      nUU R                  XB5      U R                  US5      UU R	                  U5      S.$ )Nr   r  settle_price)r  r  r  r  r  )r=  r  r  r  rB  )r  
settlementr  r  r  s        r  parse_settlementgate.parse_settlementz  sb    6 ''
F;	##J
;&&x8%%j.A"Y/
 	
r  c                     / n[        S[        U5      5       H&  nUR                  U R                  X   U5      5        M(     U$ r  )r  r  r  r  )r  r   r  r  r  s        r  r  gate.parse_settlements  s?    > q#k*+AMM$//GH ,r  c                   #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX45      I Sh  vN $ SnSnSn0 n	U R                  SSU5      u  pdUS:X  d  US:X  a  Ub  U R	                  U5      nUS   U	S'   US	:X  d  US
:X  a3  US	:X  a  SOSn
U R                  USU
5      nU R                  US5      nXS'   Ub  X)S'   Ub  X9S'   U R                  SX5      u  pUS:X  a)  U R                  U R                  X5      5      I Sh  vN nOUS:X  a)  U R                  U R                  X5      5      I Sh  vN nOUS	:X  a)  U R                  U R                  X5      5      I Sh  vN nO]US
:X  a)  U R                  U R                  X5      5      I Sh  vN nO.US:X  a(  U R                  U R                  X5      5      I Sh  vN nU R                  XX#5      $  GN GN N N N~ NQ N$7f)a.  
fetch the history of changes, actions done by the user or operations that altered the balance of the user

https://www.gate.com/docs/developers/apiv4/en/#query-account-book
https://www.gate.com/docs/developers/apiv4/en/#list-margin-account-balance-change-history
https://www.gate.com/docs/developers/apiv4/en/#query-account-book-2
https://www.gate.com/docs/developers/apiv4/en/#query-account-book-3
https://www.gate.com/docs/developers/apiv4/en/#list-account-changing-history

:param str [code]: unified currency code
:param int [since]: timestamp in ms of the earliest ledger entry
:param int [limit]: max number of ledger entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: end time in ms
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
NFr   r  rS   rQ   rC   r|  ri   rj   r  r  r  r  r  r  rk   )r  rs  r  r  r|  r`  ra  r  privateSpotGetAccountBookr&  privateMarginGetAccountBookr  r  privateOptionsGetAccountBookparse_ledger)r  r  r  r  r  r  r  r|  r  r*  rb  r  s               r  fetch_ledgergate.fetch_ledger  s
    $ !!!88PZ[::=$W\eee99-vVFN 0==.&.tn
#FN 0'+v~FEM++FHmLFYYvx0F &H#FO$G224I6>!;;DKK<XYYHX!==dkk'>Z[[HV^!DDT[[QXEabbHX!EEdkkRYFbccHX!>>t{{7?[\\Hj   UBBm 	" f* Z[bc\s|   HG68HG9CH#G<$.HG>.HH .H0H1.HH H9H<H>H HHHrt  c                 
   S nU R                  US5      n[        R                  " US5      (       a  Sn[        R                  " U5      nOSnU R                  US5      nU R	                  XR5      nU R                  US5      nU R                  US5      nS n[        U5      S:  a  [        U5      nO[        U5      S	-  nU R                  US
5      n	U R                  US5      n
U R                  [        R                  " X5      5      nU R                  UU R                  US5      US S S U R                  U5      U R                  XR5      U R                  U5      UU R                  U5      UU R                  US
5      S S S.U5      $ )Nr%  r  outinr|  r  r   r  r  balancerC   )r  rC   	directionr[   referenceAccountreferenceIdr  r|  r  r  r  beforeafterr
  r   )r  r=   r  r  r  r  rq  r  r?  safe_ledger_entryparse_ledger_entry_typer  rB  r  )r  rt  r|  r  r  r  r  rawTimestampr  balanceStringchangeStringr	  s               r  parse_ledger_entrygate.parse_ledger_entry-  s   Z 	!!$1VS))I''/FI%%dJ7
%%j;f-''f5	|r!L)IL)D0I((y9''h7""7#5#5m#RS%%""4." $006//
E''/"Y/%%dI6'
  ! 	r  c                    0 SS_SS_SS_SS_SS_SS_S	S_S
S_SS_SS_SS_SS_SS_SS_SS_SS_SS_0 SS_SS_SS_SS_SS_SS_SS_SS_S S_S!S_S"S"_S#S$_S%S_S&S_S'S_S(S)_S*S_ESSSS)S+.EnU R                  X!U5      $ ),Nr  r   r"  sub_account_transferr   	margin_in
margin_outmargin_funding_inmargin_funding_outcross_margin_incross_margin_outcopy_trading_incopy_trading_outquant_in	quant_out
futures_infutures_outdelivery_indelivery_out	new_orderr  
order_fillreferral_feerZ   	order_feer   r  lendr\   redeemprofitflash_swap_buyflash_swap_sellunknownsetr  prem
point_refrr  	point_dnwzdeposit/withdrawr  )refrr   r;  dnwr  )r  r  
ledgerTypes      r  r  gate.parse_ledger_entry_type  s   '
y'
'
 #J'
 	'

 *'
  '
 !*'
 z'
 
'
 z'
 
'
 
'
 '
 *'
 :'
  :!'
" J#'
$ %'
& '''
( H)'
* +'
, 
-'
. F/'
0 f1'
2 j3'
4 g5'
6 w7'
8 y9'
: <;'
< G='
> (?'
@ A'
B +C'
D EE'
F %M'

P 
$77r  r  c                    #    Ub  U R                  U5      OSnU R                  USU5      u  pVXS'   U R                  U R                  XV5      5      I Sh  vN $  N7f)a  
set dual/hedged mode to True or False for a swap market, make sure all positions are closed and no orders are open before setting dual mode

https://www.gate.com/docs/developers/apiv4/en/#enable-or-disable-dual-mode

:param bool hedged: set to True to enable dual mode
:param str|None symbol: if passed, dual mode is set for all markets with the same settle currency
:param dict params: extra parameters specific to the exchange API endpoint
:param str params['settle']: settle currency
:returns dict: response from the exchange
Nri   	dual_mode)r  rc   privateFuturesPostSettleDualModer&  )r  r  r  r  r  r*  rU  s          r  set_position_modegate.set_position_mode  sZ      *0);V$$--fffE%::4;;w;VWWWWs   AAAAc                   #    U R                  5       I Sh  vN   SnU R                  SSU5      u  p!Ub  US:X  a  SnUS:w  a  [        U R                  S-   5      eU R	                  U5      I Sh  vN n/ n[        S[        U5      5       H/  nX5   nU R                  US5      nUc  M  UR                  U5        M1     U$  N NR7f)a  
fetches the market ids of underlying assets for a specific contract market type

https://www.gate.com/docs/developers/apiv4/en/#list-all-underlyings

:param dict [params]: exchange specific params
:param str [params.type]: the contract market type, 'option', 'swap' or 'future', the default is 'option'
:returns dict[]: a list of `underlying assets <https://docs.ccxt.com/#/?id=underlying-assets-structure>`
Nr   rS   rk   z5 fetchUnderlyingAssets() supports option markets onlyr   rD   )	r  r  r9   rC   r[  r  r  r  r  )r  r  r  r  r   r  rN  rD   s           r  fetch_underlying_assetsgate.fetch_underlying_assets  s      !!!
!??@WY]_ef
J&$8!J!tww)``aa99&AA q#h-(A!J##J7D""4(	 )
 / 	" Bs(   CC AC/C05C)CCc                 v  #    U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      eUS   US   S.nUb  X&S'   Ub  X6S'   U R	                  S	Xd5      u  pdU R                  U R                  Xd5      5      I Sh  vN nU R                  XuX#5      $  N N7f)
aB  
retrieves the public liquidations of a trading pair

https://www.gate.com/docs/developers/apiv4/en/#retrieve-liquidation-history

:param str symbol: unified CCXT market symbol
:param int [since]: the earliest time in ms to fetch liquidations for
:param int [limit]: the maximum number of liquidation structures to retrieve
:param dict [params]: exchange specific parameters for the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest liquidation
:returns dict: an array of `liquidation structures <https://docs.ccxt.com/#/?id=liquidation-structure>`
Nri   z/ fetchLiquidations() supports swap markets onlyr  rC   )r  r  r  r  r  )r  r  r9   rC   r  publicFuturesGetSettleLiqOrdersr&  parse_liquidations)r  r  r  r  r  r  r*  r  s           r  fetch_liquidationsgate.fetch_liquidations  s      !!!V$f~tww)ZZ[[Z(t
 #FO$G224I==dkk'>Z[[ &&xFF5 	" \s"   B9B5BB9B7B97B9c                    #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nSUS   0nSnUS   (       d
  US   (       a  Ub  X6S'   US   US	'   O5US
   (       a+  US   nUR	                  S5      n	U R                  U	S5      US'   US   (       a)  U R                  U R                  Xd5      5      I Sh  vN nOUS   (       a)  U R                  U R                  Xd5      5      I Sh  vN nOTUS
   (       a)  U R                  U R                  Xd5      5      I Sh  vN nO![        U R                  S-   US   -   S-   5      eU R                  XuX#5      $  GND N Np N?7f)a  
retrieves the users liquidated positions

https://www.gate.com/docs/developers/apiv4/en/#list-liquidation-history
https://www.gate.com/docs/developers/apiv4/en/#list-liquidation-history-2
https://www.gate.com/docs/developers/apiv4/en/#list-user-s-liquidation-history-of-specified-underlying

:param str symbol: unified CCXT market symbol
:param int [since]: the earliest time in ms to fetch liquidations for
:param int [limit]: the maximum number of liquidation structures to retrieve
:param dict [params]: exchange specific parameters for the exchange API endpoint
:returns dict: an array of `liquidation structures <https://docs.ccxt.com/#/?id=liquidation-structure>`
Nz1 fetchMyLiquidations() requires a symbol argumentr  rC   ri   rj   r  r  r  rk   r  r   rN  z( fetchMyLiquidations() does not support r  rc  )r2   rC   r  r  r  r  !privateFuturesGetSettleLiquidatesr&  "privateDeliveryGetSettleLiquidatesprivateOptionsGetPositionCloser9   r>  )
r  r  r  r  r  r  r*  r  r  r  s
             r  fetch_my_liquidationsgate.fetch_my_liquidations  su     >#DGG.a$abb!!!V$t
 6Nx 0 #(  &z 2GHHd|H"..-K$($4$4[!$DGL!&>!CCDKKPWD`aaHH!DDT[[QXEabbHH!@@WA]^^Htww)SSV\]cVddgppqqD &&xFFo 	" bb^sF   /E>E5B$E>E82E>	E:
2E><E<=9E>8E>:E><E>c                    U R                  US5      nU R                  US5      nU R                  USS5      nU R                  USS5      n[        R                  " [        R
                  " XV5      5      nU R                  US5      nU R                  USS	5      n	[        R                  " Xx5      n
U R                  US
5      nUc  [        R                  " X5      nU R                  US5      nS nUS:X  a  SnOIUS:X  a  SnO@Ub=  [        R                  " US5      (       a  SnO[        R                  " US5      (       a  SnU R                  UU R                  X25      U R                  U5      U R                  U5      U R                  U	5      UU R                  U
5      U R                  [        R                  " U5      5      UU R                  U5      S.
5      $ )Nr  r   r  settle_sizer  r  r  r<  r  r;  r  r(  r  r)  r  )
r  r  r   r  r  r  	baseValue
quoteValuer  r  )r  r=  rd  r=   r  r?  rA  r`  r3  r  safe_liquidationr  r  rB  )r  liquidationr  r  r  r  r  contractsStringcontractSizeStringr  baseValueStringquoteValueStringoptPosr  s                 r  parse_liquidationgate.parse_liquidationP  s   R ##K<''V<	!!+v}EVS9!,,W-?-?-KL!--fnE((k<P!,,_Q++K?#&11/O ''V<VDwD$$T3// D&&tS11!D$$&&x8**?; --.@A&&{3**?;++G,>,>?O,PQ"Y/&
  	r  c                 h  #    U R                  5       I Sh  vN   U R                  U5      nSUS   S   0nU R                  U R                  XB5      5      I Sh  vN nUS   n[	        S[        U5      5       H1  nXW   nU R                  US5      n	X:X  d  M   U R                  X5      s  $    g N NV7f)a  
fetches an option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract

https://www.gate.com/docs/developers/apiv4/en/#list-tickers-of-options-contracts

:param str symbol: unified symbol of the market to fetch greeks for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `greeks structure <https://docs.ccxt.com/#/?id=greeks-structure>`
NrN  r  rC   r   rD   )r  r  r<  r&  r  r  r  parse_greeks)
r  r  r  r  r*  r  r  r  r  entryMarketIds
             r  fetch_greeksgate.fetch_greeks  s      !!!V$&.6
 55dkk'6RSS. $<q#h-(AKE ,,UF;M(((77	 )
 E 	"
 Ts(   B2B.AB2B0:B2B20B2greeksc                    U R                  US5      nU R                  X25      n0 SU_SS _SS _SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _S	S _S
U R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _U R                  US   S   5      US.E$ )NrD   r  r  r  deltagammathetavegarhobidSizerL  askSizerN  bidImpliedVolatilitybid_ivaskImpliedVolatilityask_ivmarkImpliedVolatilitymark_ivbidPricerH  askPricerE  rF  r5  r?  rB  r  underlying_price)underlyingPricer  )r  r  r  r  )r  rY  r  r  r  s        r  rU  gate.parse_greeks  s   * ##FF3!!(3
f

 
 T%%fg6	

 T%%fg6
 T%%fg6
 D$$VV4
 4
 t''<
 t''<
 #D$4$4VX$F
 #D$4$4VX$F
 $T%5%5fi%H
 ((>
 ((>
  ))&,?!
" ))&,?#
$  $00@R1ST'
 	
r  c                 ~   #    SS0nU R                  XC5      nUc  SnU R                  USUSSU5      I Sh  vN $  N7f)a  
closes open positions for a market

https://www.gate.com/docs/developers/apiv4/en/#create-a-futures-order
https://www.gate.com/docs/developers/apiv4/en/#create-a-futures-order-2
https://www.gate.com/docs/developers/apiv4/en/#create-an-options-order

:param str symbol: Unified CCXT market symbol
:param str side: 'buy' or 'sell'
:param dict [params]: extra parameters specific to the okx api endpoint
:returns dict[]: `A list of position structures <https://docs.ccxt.com/#/?id=position-structure>`
r^  TNr3  r  r   )r&  rI  )r  r  r  r  r*  s        r  close_positiongate.close_position  sN      T
 W-<D&&vxq$OOOOs   4=;=c                 b  #    U R                  5       I Sh  vN   SnUb  U R                  U5      n0 nSnU R                  US5      nU R                  US5      nUS   (       aa  US   US'   U(       a)  U R	                  U R                  XB5      5      I Sh  vN nOzU R                  U R                  XB5      5      I Sh  vN nOQU(       a)  U R                  U R                  XB5      5      I Sh  vN nO![        U R                  S-   US   -   S-   5      eU R                  XS5      $  GN N Nl N>7f)	aV  
fetch the set leverage for a market

https://www.gate.com/docs/developers/apiv4/en/#get-unified-account-information
https://www.gate.com/docs/developers/apiv4/en/#get-detail-of-lending-market
https://www.gate.com/docs/developers/apiv4/en/#query-one-single-margin-currency-pair-deprecated

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.unified]: default False, set to True for fetching the unified accounts leverage
:returns dict: a `leverage structure <https://docs.ccxt.com/#/?id=leverage-structure>`
NrY   rS   rC   r_  z" fetchLeverage() does not support r  r  )r  r  r  ra  +publicMarginGetUniCurrencyPairsCurrencyPairr&  (publicMarginGetCurrencyPairsCurrencyPairr|  r9   rC   parse_leverage)r  r  r  r  r*  r  	isUnifieds          r  fetch_leveragegate.fetch_leverage  s'     !!![[(FNN695	69-&>'-d|GO$!%!Q!QRVR]R]^eRn!oo "&!N!Nt{{[bOk!ll !;;DKK<XYYHh tww)MMPVW]P^^akkll""844s 	" p m ZsF   D/D&A>D/D)(D/>D+?/D/.D-/8D/)D/+D/-D/c                 V  #    U R                  5       I Sh  vN   U R                  U5      nSnU R                  US5      nU R                  US5      nSnU(       a  SnU R	                  U5      I Sh  vN nOU R                  U5      I Sh  vN nU R                  X1US5      $  N N3 N7f)a]  
fetch the set leverage for all leverage markets, only spot margin is supported on gate

https://www.gate.com/docs/developers/apiv4/en/#list-lending-markets
https://www.gate.com/docs/developers/apiv4/en/#list-all-supported-currency-pairs-supported-in-margin-trading-deprecated

:param str[] symbols: a list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.unified]: default False, set to True for fetching unified account leverages
:returns dict: a list of `leverage structures <https://docs.ccxt.com/#/?id=leverage-structure>`
NrY   rC   r_  rS   )r  r  r  ra  publicMarginGetUniCurrencyPairsr  parse_leverages)r  r  r  r  rt  marketIdRequests         r  fetch_leveragesgate.fetch_leveragesw  s      !!!%%g.NN695	69--O!AA&IIH ">>vFFH ##HOOG 	" J Gs4   B)B#AB)1B%2B)B'B)%B)'B)c                 ~    U R                  USS5      nU R                  US5      nUU R                  X2SS5      S UUS.$ )Nr_  rC   r  r  rS   )r  r  r  longLeverageshortLeverage)rd  r  r  )r  r  r  r  leverageValues        r  rs  gate.parse_leverage  sP    %%hF))(J?&&xfE)*
 	
r  c                    #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  USU5      $  NW N7f)af  
fetches option data that is commonly found in an option chain

https://www.gate.com/docs/developers/apiv4/en/#query-specified-contract-detail

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `option chain structure <https://docs.ccxt.com/#/?id=option-chain-structure>`
Nr  rC   )r  r  !publicOptionsGetContractsContractr&  parse_optionr  s         r  fetch_optiongate.fetch_option  sy      !!!V$t
 ??G@\]]R   488] 	"
 ^s!   A2A.?A2A0A20A2c                    #    U R                  5       I Sh  vN   U R                  U5      nSUS   S-   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  USS5      $  NZ N7f)a`  
fetches data for an underlying asset that is commonly found in an option chain

https://www.gate.com/docs/developers/apiv4/en/#list-all-the-contracts-with-specified-underlying-and-expiration-time

:param str code: base currency to fetch an option chain for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.underlying]: the underlying asset, can be obtained from fetchUnderlyingAssets()
:param int [params.expiration]: unix timestamp of the expiration time
:returns dict: a list of `option chain structures <https://docs.ccxt.com/#/?id=option-chain-structure>`
NrN  r  _USDTrD   )r  r|  rT  r&  parse_option_chain)r  r  r  r|  r*  r  s         r  fetch_option_chaingate.fetch_option_chain  s      !!!==&(6*W4
 77G8TUUV &&xv>>a 	"
 Vs"   A5A1AA5A3A53A5r  c                    U R                  US5      nU R                  XC5      nU R                  US5      n0 SU_SS _SUS   _SU_SU R                  U5      _SS _S	S _S
U R	                  US5      _SU R	                  US5      _SS _SU R	                  US5      _SU R	                  US5      _SU R	                  US5      _SS _SS _SS _SS _$ )NrD   r<  r  r|  r  r  r  impliedVolatilityopenInterestrh  rH  ri  rE  midPricerF  r5  r?  rB  rk  rj  r%  r"  ra  rb  )r  r  r=  rB  r  )r  r  r|  r  r  r  s         r  r  gate.parse_option+  s[   R ##E62!!(3''}=	
E

 fX&
 	

 Y/
  
 D
 ((=
 ((=
 
 ))%>
 ))%>
 t//7IJ
 d
 $
  $!
" 4#
 	
r  c                   #    U R                  5       I Sh  vN   SnUb%  [        U5      nUS:X  a  U R                  US   5      nSnU R                  SXTS5      u  ptU R	                  US5      nU R                  US5      n0 n	U R                  XWU5      u  pUb  X9S'   Ub  U R                  US-  5      U	S	'   Ub  U R                  US-  5      U	S
'   Sn
US:X  a)  U R                  U R                  X5      5      I Sh  vN n
OJUS:X  a)  U R                  U R                  X5      5      I Sh  vN n
O[        U R                  S-   U-   5      eU R                  XU5      $  GNH Nd N77f)a  
       fetches historical positions

       https://www.gate.com/docs/developers/apiv4/#list-position-close-history
       https://www.gate.com/docs/developers/apiv4/#list-position-close-history-2

       :param str[] symbols: unified conract symbols, must all have the same settle currency and the same market type
       :param int [since]: the earliest time in ms to fetch positions for
       :param int [limit]: the maximum amount of records to fetch, default=1000
       :param dict params: extra parameters specific to the exchange api endpoint
       :param int [params.until]: the latest time in ms to fetch positions for

EXCHANGE SPECIFIC PARAMETERS
       :param int [params.offset]: list offset, starting from 0
       :param str [params.side]: long or short
       :param str [params.pnl]: query profit or loss
       :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
       Nr   r   r   ri   r  r  r  r  r  rj   z: fetchPositionsHistory() does not support markets of type )r  r  r  r  r  ra  rc  r  $privateFuturesGetSettlePositionCloser&  %privateDeliveryGetSettlePositionCloser9   rC   rR  )r  r  r  r  r  r  rS  r  r  r*  r  s              r  fetch_positions_historygate.fetch_positions_historyk  sy    & !!!LM!WQZ0
!??@WY_iop
!!&'267+..v6J$G"//=GFO --edl;GDM!FFt{{SZGcddH8#!GGT[HdeeHtww)eehrrss* ##Hv>>[ 	"( ees4   E%EC%E%<E!=.E%+E#,3E%!E%#E%reasonr_   rw  r  r  c
                     Uc  g U R                  US5      n
U
b<  U R                  S-   U-   nU R                  U R                  S   X5        [	        U5      eg )Nlabel r  )r  rC   throw_exactly_matched_exceptionr  r-   )r  r  r  r_   rw  r  r  r  requestHeadersrequestBodyr  feedbacks               r  handle_errorsgate.handle_errors  s^       73ww}t+H001I5[))r   )NNNNr  )NN)__name__
__module____qualname____firstlineno__r   r  boolr  r  r  r   r  r  r  r    r   r*   r  r,   r  r  r  r  r'  r  rS  rc  ri  rl  rg  r$  r	   r  r$   r  r!   r%   r  r  r  r  r   r  r  r  r'   r  r(   r  r  r  r  r
  r
   r  r  r   r  r  r   r6  r"   r?  dictr=  r#   rm  rx  r   r  r  r  r  r  r  r&   r  r  r  r  r)   r  r   floatr   r  r%  r  r   r   r   rI  r   rU  r\  r;  r  r  r  r  r   rC  r  r  r  r  r  r  r  r  r   r  r  r+   r   r  rq  r#  rF  rL  r   rT  r   rX  r   r]  rp  r\  r|  r  r  r  r{  r   r  r  r.  r  r  r   r  r  r  r  r  r  r  r  r  r   r   r  r  r7  r:  r?  rE  rR  r   rW  rU  rn  r   ru  r   r{  rs  r   r  r   r  r  r  r  __static_attributes____classcell__)r  s   @r  r?   r?      s.   c# cJ#-t - 02 .B :< ? ') :S :"=
3 =
~VC V VRU Vjm V  zI V V *, "+V "+H /1 ob /1   13  g
R 13 vp& &*R !8 15eB  $ 7;ERT  *$:c -/ c: cJ <> <1s <1+ <1| <@ >; >;| >;@G
6 G
[ G
R? EG # #J JL 0S 0PTUcPd 0& =? : :> :$
( ;= 8c 8AT 8@ /1 1[ 16
f 
< =A 5' 5n BFb Mw MB. .` 9=4^bkm .L# .LS .LX[ .L`OnI] O
& 
. @DB sS s sS\ sj 68 '1 '1F '1Rn4 n n6 n` 6:" %57 %5 %5N *, Y Yv ?CQUdhqs AL AL AL3 AL^a ALx|  ~B  yC ALF ?CQUdhqs Ls L3 L^a L >BPTcgpr 5Ys 5Y# 5Y]` 5Yn+ +4 +Z <@d[] hA hAS hA hAbfglbm hAT ?CQUdhqs '3 ' '3 '^a 'R 37TX\eg BAC BAs BARU BAH_ _v _ _B 04$UYbd  ;  ;C  ;s  ;imnyiz  ;D 37TX\eg  ;C  ;s  ;RU  ;lpq|l}  ;D QU]_ &:3 &: &: &:# &:do &:P:s :$3k
T k
X k
Q\ k
Z mqy{ B2 B2I B2Y B2X] B2fi B2H HJ D,> < FH +$|*< +0 os{} Q,3 Q,i Q,y Q,Z_ Q,hk Q,f XZ Tc T T( hlz~  HJ ,S ,# ,Y ,i ,ad ,tw ,B fjx|  FH 923 92 929 92I 92_b 92ru 92v: : { {v { {z :>b (c (3 (" 8<B .2C .2 .2` 59tZ^gi Wc W WTW Wnrsxny W& 7;\`ik 0A 0A3 0AVY 0Aptuzp{ 0Ad FJX\koxz &s &RU &eh &> BFTXgktv O3 Oc Oad OB 9=R }2S }2# }2~ AER *+tCy *+# *+X Y[ $+d;N6O $+L 59 E3c E3N ac 673 67 67C 67TW 67gt 67p
t 
x 
= 
, ?C2 C3 C CJEt EV EN 8: R53 R5h 8<B d7W d74PX> d7L =A sD' sDP] sDj EG B B4P\K] B<$|BT 8 $|J\ @ RT :# :S :: BD /:S /:b Z\ +:3 +:c +:5 +:Z JL +:c +:5 +:Z3
 3
j 7;$]apt} -Q -QC -QWZ -Qjm -Q  EI  JX  EY -Q^
$ 
 
. 
"D  b$T LP\ FH @ @*
d *
F *
N` *
X FH H# Hu HL^ H CE Gs GE GI[ G HLZ^mqz| 5Q 5QTW 5Qgj 5Qn
F 
: <@daenp ,OS ,O ,O[^ ,O\ ?CQUdhqs 2Y 2Y3 2Y^a 2Yh#
J"H .2SW`b hCs hC# hCS hCgklwgx hCTPt Px P; Pd)8V CGr Xd XC X" 46 !F BFTXac 'Gs 'G3 'Gc 'GR 9=4^bkm GG# GGS GGX[ GGRMV M^ 68 , ,F ,\+
4 +
 +
6 +
Z CGr P3 Pi PV[ P* 8: f53 f5h f5P 8<B /PW /P9 /Pb	
t 	
V 	
x 	
 68 89 89F 89t :< <?S <? <?|>
$ >
( >
6 >
]c >
@ @DRVeirt @?W @?C @?_b @?y}  G  zH @?D# s  c TX `c  r  r?   )E ccxt.async_support.base.exchanger   ccxt.abstract.gater   r  r  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   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   typingr,   ccxt.base.errorsr-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   ccxt.base.decimal_to_precisionr<   ccxt.base.preciser=   r?   r  r  r  <module>r     s    6 *   ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  ]  * 0 - . - . ' & . ) * 5 ) . 1 4 %^z8[ ^zr  