
    !:hh                       d dl mZ d dlmZ d dlZd dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ d dl,m-Z- d dl.m/Z/ d dl.m0Z0 d dl.m1Z1 d d	l.m2Z2 d d
l.m3Z3 d dl.m4Z4 d dl.m5Z5 d dl.m6Z6 d dl.m7Z7 d dl.m8Z8 d dl.m9Z9 d dl.m:Z: d dl.m;Z; d dl.m<Z< d dl.m=Z= d dl.m>Z> d dl.m?Z? d dl.m@Z@ d dl.mAZA d dlBmCZC d dlDmEZE  G d dee      ZFy)    )Exchange)ImplicitAPIN)%AnyBalancesBorrowInterest
ConversionCrossBorrowRate
CurrenciesCurrencyDepositAddressFundingHistoryIntIsolatedBorrowRateLedgerEntryLeverageLeverageTierLiquidationLongShortRatio
MarginModeMarginModificationMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTradingFeeInterfaceTradingFeesTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)NotSupported)DDoSProtection)RateLimitExceeded)ExchangeNotAvailable)OnMaintenance)InvalidNonce)RequestTimeout)CancelPending)	TICK_SIZE)Precisec                   	    e Zd Zdef fdZd Zdi fdZi fdefdZi fde	e
   fdZdede
fd	Zi fdefd
Zi fdede	e   fdZdde
de	e   fdZdddi fdededede	e   fdZdi fdedededefdZdddi fdededede	e   fdZddededefdZdefdZi fdedefdZddedefdZdi fdedede fdZ!ddede
de"fdZ#i fdede"fd Z$i fdede"fd!Z%di fd"e&de'fd#Z(dd$ede
de)fd%Z*ddi fdededede	e)   fd&Z+i fdede,fd'Z-i fde.fd(Z/dde
fd)Z0dde
de1fd*Z2d+ddi fdededede	e1   fd,Z3i fde4fd-Z5de4fd.Z6defd/Z7dd0ede
de8fd1Z9i fded2efd3Z:di fded4e;d5e<ded6e=f
d7Z>di fded4e;d5e<ded6e=f
d8Z?i fd9e	e@   fd:ZAddi fd;eded4e;d5e<de=d6e=fd<ZBdi fd;edefd=ZCdi fdefd>ZDdi fdefd?ZEdi fd;edefd@ZFdddi fdededede	e8   fdAZGdddi fdededede	e8   fdBZHdddi fdededefdCZIdddi fdededefdDZJdddi fdededede	eK   fdEZLddFededeKfdGZMdH ZNdddi fdededede	e)   fdIZOi fdefdJZPdi fd"e&de	eQ   fdKZRddLede
fdMZSdddi fdededefdNZTi fdedeUfdOZVdi fd"e&deWfdPZXdde
deUfdQZYdddi fdededede	eZ   fdRZ[dde
fdSZ\ddedede	eZ   fdTZ]i fdede^fdUZ_ddVede
de^fdWZ`i fdedede^fdXZai fdedede^fdYZbi fdedecfdZZddd[ede
decfd\Zedi fd[edefd]Zfdi fd^edefd_Zgdi fd`ehdefdaZii fdefdbZjdde
fdcZkdddi fdededede	el   fddZmi fdededeedfedelf
dgZnddhededelfdiZodedefdjZpddefdkZqdi fdle&fdmZri fdedefdnZsi fdededefdoZti fdedefdpZui fdefdqZvddede
fdrZwdddi fdededede	ex   fdsZydde
fdtZzi fdede{fduZ|ddvede
de{fdwZ}i fdede~fdxZddefdyZddddi fdedededede	e   f
dzZddvede
defd{Zdi fded5e<de8fd|Zi fde	eQ   fd}Zi fdedefd~Zdd^edefdZdddi fd"e&dedede	eQ   fdZdi fdedede=defdZdi fd;ededede=def
dZdddi fdededede	e   fdZddedededefdZi fdefdZi fdedeUfdZddddi fdedededede	e   f
dZddvede
defdZdedededededefdZd Zg di ddfdZ xZS )bitgetreturnc                 6   | j                  t        t        |          i ddddddgddd	d
dddddi dd ddddddddddddddddddddddddddddddd di d!dd"dd#dd$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1di d2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBdi dCddDddEddFdGdHddIddJddKddLddMddNddOddPddQddRddSddTdi dUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcdddddedi dfddgddhddiddjdGdkddlddmddnddoddpddqddrddsddtdduddvdi dwddxddyddzdd{dd|dd}dd~ddddddddddddddddddddddddddddddddddddddddddddddddddg dddddddddidi dddddddddddddddddddddddddddddddddddddddddddd	idi ddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddddddddܜidddddddddݜiddddޜidߜi ddddddddۓdddddddddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddd dddddddddddi ddddddd	dd
dddddddddddddddddddddddddi ddddddddddddddddddd dd!dd"dd#dd$dd%dd&dd'ddddddddddddddddd(d)i d*dd+dd,dd-dd.dd/dd0dd1dd2dd3dd4dd5dd6dd7dd8dd9dd:di d;dd<dd=dd>dd?dd@ddAddBddCddDddEddFddGddHddIddJddKdddddddddddddddېdLi dMddNddOddPddQddRddSddTddUddVddWddXddYddZdۓd[dd\dd]di d^dd_dd`ddaddbddcdddddeddfddgddhddiddjddkddlddmddndi doddpddqddrddsddtdduddvddwddxddyddzdd{dd|dۓd}dۓd~dddddddddddd)dddddddddd	ddddddddddd
d)ddddddddddiddddddddddddddddi ddۓddۓddۓddddddddddddddۓddۓddddddddddd)i ddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddddid)i ddddddddddddddddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddddid)dddddېdidddddd dddd)i ddddddddddddddd	dd
ddddddddddddddddddddddddddddd)dddiiddd| j	                  d      | j	                  d      d| j	                  d      | j	                  d      dddddddd i d!t
        d"t        d#t        d$t
        d%t
        d&t        d't        d(t        d)t        d*t        d+t        d,t        d-t        d.t
        d/t        d0t        d1t        i d2t        d3t        d4t        d5t
        d6t
        d7t
        d8t        d9t        d:t        d;t        d<t        d=t        d>t        d?t        d@t        dAt        dBt        i dCt
        dDt        dEt        dFt        dGt
        dHt
        dIt
        dJt        dKt        dLt        dMt        dNt         dOt
        dPt"        dQt"        dRt"        dSt"        i dTt"        dUt
        dVt
        dWt
        dXt
        dYt
        dZt
        d[t
        d\t
        d]t
        d^t
        d_t
        d`t
        dat
        dbt
        dct
        ddt
        i det
        dft
        dgt        dht
        dit"        djt$        dkt        dlt
        dmt
        dnt
        dot
        dpt
        dqt"        drt
        dst"        dtt"        dut
        i dvt
        dwt
        dxt
        dyt"        dzt
        d{t
        d|t"        d}t"        d~t"        dt"        dt"        dt
        dt
        dt
        dt
        dt
        dt
        i dt
        dt
        dt
        dt
        dt
        dt
        dt
        dt
        dt
        dt
        dt
        dt
        dt        dt        dt&        dt
        dt
        i dt
        dt
        dt&        dt
        dt
        dt
        dt
        dt"        dt(        dt"        dt
        dt&        dt
        dt
        dt        dt"        dt
        i dt"        dt"        dt
        dt"        dt"        dt"        dt
        dt
        dt
        dt
        dt
        dt
        dt
        dt
        dt
        dt
        dt
        i dt
        dt
        dt
        dt
        dt
        dt
        dt
        dt        dt        dt
        dt
        dt
        dt
        dt
        dt
        dt        dt*        i dt
        dt
        dt
        dt
        dt
        dt&        dt
        dt
        dt
        dt
        dt
        dt
        dt
        dt        dt        dt        dt        i dt        dt*        dt
        dt        dt
        dt
        dt
        dt
        dt
        dt
        dt
        dt
        dt
        dt        dt"        dt"        dt"        i dt"        dt"        dt
        dt"        dt"        dt"        dt
        dt
        dt&        dt
        dt(        dt"        dt"        dt
        dt
        dt
        dt"        i dt
        dt&        d t&        dt
        dt"        dt"        dt&        dt
        dt&        dt
        dt
        d	t        d
t        dt        dt"        dt"        dt"        i dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        dt"        i d t"        d!t"        d"t"        d#t"        d$t"        d%t"        d&t"        d't
        d(t
        d)t
        d*t
        d+t
        d,t        d-t
        d.t
        d/t
        d0t
        i d1t        d2t        d3t
        d4t        d5t        d6t        d7t        d8t        d9t        d:t        d;t&        d<t        d=t        d>t        d?t"        d@t
        dAt        i dBt        dCt"        dDt"        dEt"        dFt"        dGt"        dHt"        dIt"        dJt
        dKt(        dLt"        dMt"        dNt"        dOt"        dPt"        dQt"        dRt"        i dSt"        dTt"        dUt"        dVt"        dWt"        dXt"        dYt"        dZt        d[t        d\t        d]t        d^t        d_t        d`t        dat        dbt,        dct
        i ddt
        det        dft        dgt        dht        dit        djt        dkt        dlt        dmt        dnt        dot        dpt        dqt
        drt        dst
        dtt        i dut
        dvt        dwt        dxt        dyt        dzt        d{t        d|t
        d}t
        d~t
        dt
        dt"        dt(        dt        dt"        dt
        dt        i dt        dt        dt        dt        dt        dt        dt
        dt        dt        dt        dt        dt        dt
        dt        dt        dt
        dt
        i dt        dt        dt        dt        dt        dt
        dt
        dt
        dt"        dt
        dt
        dt
        dt
        dt
        dt        dt        dt
        i dt
        dt
        dt
        dt
        dt
        dt        dt
        dt
        dt
        dt
        dt
        dt        dt
        dt
        dt
        dt
        dt        i dt"        dt        dt        dt
        dt
        dt&        dt&        dt
        dt
        dt&        dt(        dt"        dt"        dt        dt"        dt(        dt&        i dt"        dt        dt"        dt        dt        dt        dt        dt
        dt"        dt"        dt"        dt
        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt,        dt        dt        dt
        dt        dt        dt        dt        dt        dt        dt        dt
        dt        i dt
        dt
        dt        dt"        dt"        dt
        dt&        dt
        dt
        dt
        dt        dt        dt        dt        dt,        dt
        dt"        t"        t"        t"        t"        t"        t&        t"        t"        t
        t        t        t
        t
        t        ddt
        idd t.        dddddddi dd	d
dddddddddddddddddddddddddddddddd[ddgdddddddddddid`d d d d d d!d"d#d$d%d&d'd(d)d*d+d+d+d,d-d.d/d#d0d1d d2dd3d4d.d5dtd6d7id6d8iddLd6d9id:dd;d<d=d>d?d@dAdBddCdDddEdd@dFdGddHi dIdIdJdJdKdLdLdKdMdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d\d]d]d^d^d_d_d`d`i dadadbdcdddedfdgdhdhdididjdjdkdldmdmdndndodpdqdqdrdrdsdtdudvdwdxdydzi d{d{d|d}d~dddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddi dddddddddddddddddddddddddddddddÐdēdŐdƓdi d6didg dʢd˜ddddddd̜ddddddd̜dd͜dddddΜdddddϜdd
idd+d d1ddќdddddҜdd+ddddӜd dd+d d d1ddddԜddid֜	dddddd̜ddddddd̜dd͜dddddΜdddddלdؐdiddidۜdܐdidܐdidޜdܐdidܐdidޜdߜd      S (  NidrA   nameBitget	countriesSGversionv2	rateLimit2   	certifiedTprohasCORSspotmarginswapfutureoptionF	addMarginborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateConvertTradecreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrders$createOrderWithTakeProfitAndStopLosscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopLossOrdercreateStopMarketOrdercreateStopOrdercreateTakeProfitOrdercreateTrailingAmountOrdercreateTrailingPercentOrdercreateTriggerOrder	editOrderfetchAccountsfetchBalancefetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledAndClosedOrdersfetchCanceledOrdersfetchClosedOrdersfetchConvertCurrenciesfetchConvertQuotefetchConvertTradefetchConvertTradeHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchLeverageTiersfetchLiquidationsfetchLongShortRatiofetchLongShortRatioHistoryfetchMarginAdjustmentHistoryfetchMarginModefetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricefetchMyLiquidationsfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsfetchTransferfetchTransfersfetchWithdrawAddressesfetchWithdrawalfetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeverage	setMarginsetMarginModesetPositionModesignIntransferwithdraw
timeframes1m3m5m15m30m1h2h4h6h12h1d3d1w)r   r   r   r   r   r   r   r   r   r   r   r   r   1Mhostnamez
bitget.comurlszOhttps://github.com/user-attachments/assets/fbaa10cc-a277-441d-a5b7-997dd9a87658zhttps://api.{hostname})rQ   mixuserp2pbrokerrR   commontaxconvertcopyearnzhttps://www.bitget.com)z+https://www.bitget.com/api-doc/common/introz)https://www.bitget.com/api-doc/spot/introz-https://www.bitget.com/api-doc/contract/introz+https://www.bitget.com/api-doc/broker/introz+https://www.bitget.com/api-doc/margin/introz0https://www.bitget.com/api-doc/copytrading/introz)https://www.bitget.com/api-doc/earn/introz-https://bitgetlimited.github.io/apidoc/en/mixz.https://bitgetlimited.github.io/apidoc/en/spotz0https://bitgetlimited.github.io/apidoc/en/brokerz0https://bitgetlimited.github.io/apidoc/en/marginz&https://www.bitget.cc/zh-CN/rate?tab=1zMhttps://www.bitget.com/expressly?languageType=0&channelCode=ccxt&vipCode=tg9j)logoapiwwwdocfeesreferralr   get   )zv2/public/annoucementsv2/public/timezspot/v1/notice/queryAllNoticeszspot/v1/public/timezspot/v1/public/currenciesg	g@zspot/v1/public/productszspot/v1/public/productzspot/v1/market/tickerzspot/v1/market/tickerszspot/v1/market/fills   zspot/v1/market/fills-historyzspot/v1/market/candleszspot/v1/market/depthzspot/v1/market/spot-vip-levelzspot/v1/market/merge-depthzspot/v1/market/history-candleszspot/v1/public/loan/coinInfosz!spot/v1/public/loan/hour-interestzv2/spot/public/coins)	zv2/spot/public/symbolszv2/spot/market/vip-fee-ratezv2/spot/market/tickerszv2/spot/market/merge-depthzv2/spot/market/orderbookzv2/spot/market/candleszv2/spot/market/history-candleszv2/spot/market/fillszv2/spot/market/fills-historyzmix/v1/market/contractszmix/v1/market/depthzmix/v1/market/tickerzmix/v1/market/tickersz mix/v1/market/contract-vip-levelzmix/v1/market/fillszmix/v1/market/fills-historyzmix/v1/market/candleszmix/v1/market/indexzmix/v1/market/funding-timezmix/v1/market/history-fundRatezmix/v1/market/current-fundRatezmix/v1/market/open-interestzmix/v1/market/mark-pricezmix/v1/market/symbol-leveragez mix/v1/market/queryPositionLeverzmix/v1/market/open-limitzmix/v1/market/history-candlesz#mix/v1/market/history-index-candlesz"mix/v1/market/history-mark-candleszmix/v1/market/merge-depthzv2/mix/market/vip-fee-ratezv2/mix/market/merge-depthzv2/mix/market/tickerzv2/mix/market/tickerszv2/mix/market/fillszv2/mix/market/fills-historyzv2/mix/market/candleszv2/mix/market/history-candlesz#v2/mix/market/history-index-candlesz"v2/mix/market/history-mark-candleszv2/mix/market/open-interestzv2/mix/market/funding-timezv2/mix/market/symbol-price   )zv2/mix/market/history-fund-ratezv2/mix/market/current-fund-ratezv2/mix/market/contracts"v2/mix/market/query-position-leverz v2/mix/market/account-long-short)z+margin/v1/cross/public/interestRateAndLimitz.margin/v1/isolated/public/interestRateAndLimitzmargin/v1/cross/public/tierDataz"margin/v1/isolated/public/tierDatazmargin/v1/public/currencieszv2/margin/currenciesz!v2/margin/market/long-short-ratio)zv2/earn/loan/public/coinInfosz!v2/earn/loan/public/hour-interest)r   rQ   r   rR   r   zspot/v1/wallet/deposit-address   zspot/v1/wallet/withdrawal-listzspot/v1/wallet/deposit-listzspot/v1/account/getInfozspot/v1/account/assetszspot/v1/account/assets-litezspot/v1/account/transferRecordszspot/v1/convert/currencieszspot/v1/convert/convert-recordzspot/v1/loan/ongoing-orderszspot/v1/loan/repay-historyzspot/v1/loan/revise-historyzspot/v1/loan/borrow-historyzspot/v1/loan/debtszv2/spot/trade/orderInfozv2/spot/trade/unfilled-orderszv2/spot/trade/history-orders)zv2/spot/trade/fillsz v2/spot/trade/current-plan-orderz v2/spot/trade/history-plan-orderzv2/spot/account/infozv2/spot/account/assetsz!v2/spot/account/subaccount-assetszv2/spot/account/billszv2/spot/account/transferRecordszv2/account/funding-assetszv2/account/bot-assetszv2/account/all-account-balancezv2/spot/wallet/deposit-addresszv2/spot/wallet/deposit-recordsz!v2/spot/wallet/withdrawal-recordszspot/v1/wallet/transferzspot/v1/wallet/transfer-v2zspot/v1/wallet/subTransfer
   zspot/v1/wallet/withdrawalzspot/v1/wallet/withdrawal-v2zspot/v1/wallet/withdrawal-innerz"spot/v1/wallet/withdrawal-inner-v2z'spot/v1/account/sub-account-spot-assets   zspot/v1/account/billszspot/v1/trade/orderszspot/v1/trade/batch-orderszspot/v1/trade/cancel-orderzspot/v1/trade/cancel-order-v2z!spot/v1/trade/cancel-symbol-orderz!spot/v1/trade/cancel-batch-ordersz$spot/v1/trade/cancel-batch-orders-v2zspot/v1/trade/orderInfozspot/v1/trade/open-orderszspot/v1/trade/historyzspot/v1/trade/fillszspot/v1/plan/placePlanzspot/v1/plan/modifyPlanzspot/v1/plan/cancelPlanzspot/v1/plan/currentPlanzspot/v1/plan/historyPlanzspot/v1/plan/batchCancelPlanzspot/v1/convert/quoted-pricezspot/v1/convert/tradezspot/v1/loan/borrowzspot/v1/loan/repayzspot/v1/loan/revise-pledgez$spot/v1/trace/order/orderCurrentListz$spot/v1/trace/order/orderHistoryListz&spot/v1/trace/order/closeTrackingOrderzspot/v1/trace/order/updateTpslz$spot/v1/trace/order/followerEndOrderz spot/v1/trace/order/spotInfoListz&spot/v1/trace/config/getTraderSettingsz(spot/v1/trace/config/getFollowerSettingszspot/v1/trace/user/myTradersz&spot/v1/trace/config/setFollowerConfigzspot/v1/trace/user/myFollowersz#spot/v1/trace/config/setProductCodezspot/v1/trace/user/removeTraderz"spot/v1/trace/getRemovableFollowerz!spot/v1/trace/user/removeFollowerz$spot/v1/trace/profit/totalProfitInfoz$spot/v1/trace/profit/totalProfitListz"spot/v1/trace/profit/profitHisListz(spot/v1/trace/profit/profitHisDetailListz)spot/v1/trace/profit/waitProfitDetailList)z spot/v1/trace/user/getTraderInfozv2/spot/trade/place-orderzv2/spot/trade/cancel-orderzv2/spot/trade/batch-ordersz v2/spot/trade/batch-cancel-orderz!v2/spot/trade/cancel-symbol-orderzv2/spot/trade/place-plan-orderzv2/spot/trade/modify-plan-orderzv2/spot/trade/cancel-plan-orderz%v2/spot/trade/batch-cancel-plan-orderzv2/spot/wallet/transferz"v2/spot/wallet/subaccount-transferzv2/spot/wallet/withdrawalz v2/spot/wallet/cancel-withdrawalz%v2/spot/wallet/modify-deposit-account)r   postzmix/v1/account/accountzmix/v1/account/accountszmix/v1/position/singlePositionz!mix/v1/position/singlePosition-v2zmix/v1/position/allPositionzmix/v1/position/allPosition-v2z mix/v1/position/history-positionzmix/v1/account/accountBillz"mix/v1/account/accountBusinessBillzmix/v1/order/currentzmix/v1/order/marginCoinCurrentzmix/v1/order/historyzmix/v1/order/historyProductTypezmix/v1/order/detailzmix/v1/order/fillszmix/v1/order/allFillszmix/v1/plan/currentPlanzmix/v1/plan/historyPlanzmix/v1/trace/currentTrackzmix/v1/trace/followerOrderz"mix/v1/trace/followerHistoryOrderszmix/v1/trace/historyTrackzmix/v1/trace/summaryz%mix/v1/trace/profitSettleTokenIdGroupz mix/v1/trace/profitDateGroupListzmix/v1/trade/profitDateListzmix/v1/trace/waitProfitDateListzmix/v1/trace/traderSymbolszmix/v1/trace/traderListzmix/v1/trace/traderDetailzmix/v1/trace/queryTraceConfigzv2/mix/account/accountzv2/mix/account/accountsz!v2/mix/account/sub-account-assets)zv2/mix/account/open-countzv2/mix/account/billr   zv2/mix/position/single-positionzv2/mix/position/all-positionz v2/mix/position/history-positionzv2/mix/order/detailzv2/mix/order/fillszv2/mix/order/fill-historyzv2/mix/order/orders-pendingzv2/mix/order/orders-historyz v2/mix/order/orders-plan-pendingz v2/mix/order/orders-plan-historyz!v2/mix/market/position-long-shortz*mix/v1/account/sub-account-contract-assetszmix/v1/account/open-countzmix/v1/account/setLeveragezmix/v1/account/setMarginzmix/v1/account/setMarginModezmix/v1/account/setPositionModezmix/v1/order/placeOrderzmix/v1/order/batch-orderszmix/v1/order/cancel-orderz mix/v1/order/cancel-batch-orderszmix/v1/order/modifyOrderz!mix/v1/order/cancel-symbol-orderszmix/v1/order/cancel-all-ordersz mix/v1/order/close-all-positionszmix/v1/plan/placePlanzmix/v1/plan/modifyPlanzmix/v1/plan/modifyPlanPresetzmix/v1/plan/placeTPSLzmix/v1/plan/placeTrailStopzmix/v1/plan/placePositionsTPSLzmix/v1/plan/modifyTPSLPlanzmix/v1/plan/cancelPlanzmix/v1/plan/cancelSymbolPlanzmix/v1/plan/cancelAllPlanzmix/v1/trace/closeTrackOrderzmix/v1/trace/modifyTPSLz$mix/v1/trace/closeTrackOrderBySymbolzmix/v1/trace/setUpCopySymbolsz(mix/v1/trace/followerSetBatchTraceConfigz&mix/v1/trace/followerCloseByTrackingNozmix/v1/trace/followerCloseByAllzmix/v1/trace/followerSetTpslzmix/v1/trace/cancelCopyTraderzmix/v1/trace/traderUpdateConfigzmix/v1/trace/myTraderListzmix/v1/trace/myFollowerListzmix/v1/trace/removeFollowerz%mix/v1/trace/public/getFollowerConfigz%mix/v1/trace/report/order/historyListz%mix/v1/trace/report/order/currentListz'mix/v1/trace/queryTraderTpslRatioConfigz(mix/v1/trace/traderUpdateTpslRatioConfigzv2/mix/account/set-leveragezv2/mix/account/set-marginzv2/mix/account/set-margin-modez v2/mix/account/set-position-modezv2/mix/order/place-orderzv2/mix/order/click-backhandzv2/mix/order/batch-place-orderzv2/mix/order/modify-orderzv2/mix/order/cancel-order)z v2/mix/order/batch-cancel-orderszv2/mix/order/close-positionszv2/mix/order/place-tpsl-orderzv2/mix/order/place-plan-orderzv2/mix/order/modify-tpsl-orderzv2/mix/order/modify-plan-orderzv2/mix/order/cancel-plan-order)	zuser/v1/fee/queryzuser/v1/sub/virtual-listzuser/v1/sub/virtual-api-listzuser/v1/tax/spot-recordzuser/v1/tax/future-recordzuser/v1/tax/margin-recordzuser/v1/tax/p2p-recordzv2/user/virtual-subaccount-listz&v2/user/virtual-subaccount-apikey-list)
zuser/v1/sub/virtual-createzuser/v1/sub/virtual-modifyz$user/v1/sub/virtual-api-batch-createzuser/v1/sub/virtual-api-createzuser/v1/sub/virtual-api-modifyz!v2/user/create-virtual-subaccountz!v2/user/modify-virtual-subaccountz*v2/user/batch-create-subaccount-and-apikeyz(v2/user/create-virtual-subaccount-apikeyz(v2/user/modify-virtual-subaccount-apikey)zp2p/v1/merchant/merchantListzp2p/v1/merchant/merchantInfozp2p/v1/merchant/advListzp2p/v1/merchant/orderListzv2/p2p/merchantListzv2/p2p/merchantInfozv2/p2p/orderListzv2/p2p/advList)zbroker/v1/account/infozbroker/v1/account/sub-listzbroker/v1/account/sub-emailz!broker/v1/account/sub-spot-assetsz#broker/v1/account/sub-future-assetsz%broker/v1/account/subaccount-transferz$broker/v1/account/subaccount-depositz'broker/v1/account/subaccount-withdrawalzbroker/v1/account/sub-api-listzv2/broker/account/infoz!v2/broker/account/subaccount-listz"v2/broker/account/subaccount-emailz(v2/broker/account/subaccount-spot-assetsz*v2/broker/account/subaccount-future-assetsz'v2/broker/manage/subaccount-apikey-listzbroker/v1/account/sub-createzbroker/v1/account/sub-modifyz"broker/v1/account/sub-modify-emailzbroker/v1/account/sub-addressz broker/v1/account/sub-withdrawalz#broker/v1/account/sub-auto-transferz broker/v1/account/sub-api-createz broker/v1/account/sub-api-modifyz)v2/broker/account/modify-subaccount-emailz#v2/broker/account/create-subaccountz#v2/broker/account/modify-subaccountz$v2/broker/account/subaccount-addressz'v2/broker/account/subaccount-withdrawalz-v2/broker/account/set-subaccount-autotransferz)v2/broker/manage/create-subaccount-apikeyz)v2/broker/manage/modify-subaccount-apikeyz margin/v1/cross/account/riskRatez,margin/v1/cross/account/maxTransferOutAmountz/margin/v1/isolated/account/maxTransferOutAmountz#margin/v1/isolated/order/openOrdersz margin/v1/isolated/order/historyzmargin/v1/isolated/order/fillszmargin/v1/isolated/loan/listzmargin/v1/isolated/repay/listz margin/v1/isolated/interest/listz#margin/v1/isolated/liquidation/listzmargin/v1/isolated/fin/listz margin/v1/cross/order/openOrderszmargin/v1/cross/order/historyzmargin/v1/cross/order/fillszmargin/v1/cross/loan/listzmargin/v1/cross/repay/listzmargin/v1/cross/interest/listz margin/v1/cross/liquidation/listzmargin/v1/cross/fin/listzmargin/v1/cross/account/assetsz!margin/v1/isolated/account/assetsz v2/margin/crossed/borrow-historyzv2/margin/crossed/repay-historyz"v2/margin/crossed/interest-historyz%v2/margin/crossed/liquidation-historyz#v2/margin/crossed/financial-recordsz v2/margin/crossed/account/assetsz#v2/margin/crossed/account/risk-ratez/v2/margin/crossed/account/max-borrowable-amountz1v2/margin/crossed/account/max-transfer-out-amountz)v2/margin/crossed/interest-rate-and-limitzv2/margin/crossed/tier-datazv2/margin/crossed/open-ordersz v2/margin/crossed/history-orders)zv2/margin/crossed/fillsz!v2/margin/isolated/borrow-historyz v2/margin/isolated/repay-historyz#v2/margin/isolated/interest-historyz&v2/margin/isolated/liquidation-historyz$v2/margin/isolated/financial-recordsz!v2/margin/isolated/account/assetsz$v2/margin/isolated/account/risk-ratez0v2/margin/isolated/account/max-borrowable-amountz2v2/margin/isolated/account/max-transfer-out-amountz*v2/margin/isolated/interest-rate-and-limitzv2/margin/isolated/tier-datazv2/margin/isolated/open-ordersz!v2/margin/isolated/history-orderszv2/margin/isolated/fillszmargin/v1/cross/account/borrowz!margin/v1/isolated/account/borrowzmargin/v1/cross/account/repayz margin/v1/isolated/account/repayz#margin/v1/isolated/account/riskRatez+margin/v1/cross/account/maxBorrowableAmountz.margin/v1/isolated/account/maxBorrowableAmountz%margin/v1/isolated/account/flashRepayz0margin/v1/isolated/account/queryFlashRepayStatusz"margin/v1/cross/account/flashRepayz-margin/v1/cross/account/queryFlashRepayStatusz#margin/v1/isolated/order/placeOrderz(margin/v1/isolated/order/batchPlaceOrderz$margin/v1/isolated/order/cancelOrderz)margin/v1/isolated/order/batchCancelOrderz margin/v1/cross/order/placeOrderz%margin/v1/cross/order/batchPlaceOrderz!margin/v1/cross/order/cancelOrderz&margin/v1/cross/order/batchCancelOrderz v2/margin/crossed/account/borrowzv2/margin/crossed/account/repayz%v2/margin/crossed/account/flash-repayz2v2/margin/crossed/account/query-flash-repay-statuszv2/margin/crossed/place-orderz#v2/margin/crossed/batch-place-orderzv2/margin/crossed/cancel-orderz$v2/margin/crossed/batch-cancel-orderz!v2/margin/isolated/account/borrowz v2/margin/isolated/account/repayz&v2/margin/isolated/account/flash-repayz3v2/margin/isolated/account/query-flash-repay-statuszv2/margin/isolated/place-orderz$v2/margin/isolated/batch-place-orderzv2/margin/isolated/cancel-orderz%v2/margin/isolated/batch-cancel-orderz&v2/copy/mix-trader/order-current-trackz&v2/copy/mix-trader/order-history-trackz%v2/copy/mix-trader/order-total-detailz*v2/copy/mix-trader/profit-history-summarysz)v2/copy/mix-trader/profit-history-detailsz!v2/copy/mix-trader/profit-detailsz*v2/copy/mix-trader/profits-group-coin-datez'v2/copy/mix-trader/config-query-symbolsz)v2/copy/mix-trader/config-query-followersz)v2/copy/mix-follower/query-current-ordersz)v2/copy/mix-follower/query-history-ordersz#v2/copy/mix-follower/query-settingsz"v2/copy/mix-follower/query-tradersz)v2/copy/mix-follower/query-quantity-limitz v2/copy/mix-broker/query-tradersz'v2/copy/mix-broker/query-history-tracesz'v2/copy/mix-broker/query-current-traces)z#v2/copy/spot-trader/profit-summarysz*v2/copy/spot-trader/profit-history-detailsz"v2/copy/spot-trader/profit-detailsz&v2/copy/spot-trader/order-total-detailz'v2/copy/spot-trader/order-history-trackz'v2/copy/spot-trader/order-current-trackz)v2/copy/spot-trader/config-query-settingsz*v2/copy/spot-trader/config-query-followersz#v2/copy/spot-follower/query-tradersz*v2/copy/spot-follower/query-trader-symbolsz$v2/copy/spot-follower/query-settingsz*v2/copy/spot-follower/query-history-ordersz*v2/copy/spot-follower/query-current-ordersz$v2/copy/mix-trader/order-modify-tpslz(v2/copy/mix-trader/order-close-positionsz)v2/copy/mix-trader/config-setting-symbolsz&v2/copy/mix-trader/config-setting-basez)v2/copy/mix-trader/config-remove-followerz!v2/copy/mix-follower/setting-tpslzv2/copy/mix-follower/settingsz$v2/copy/mix-follower/close-positionsz"v2/copy/mix-follower/cancel-traderz%v2/copy/spot-trader/order-modify-tpslz(v2/copy/spot-trader/order-close-trackingz*v2/copy/spot-trader/config-setting-symbolsz*v2/copy/spot-trader/config-remove-followerz v2/copy/spot-follower/stop-orderzv2/copy/spot-follower/settingsz"v2/copy/spot-follower/setting-tpslz*v2/copy/spot-follower/order-close-trackingz#v2/copy/spot-follower/cancel-trader)zv2/tax/spot-recordzv2/tax/future-recordzv2/tax/margin-recordzv2/tax/p2p-record)zv2/convert/currencieszv2/convert/quoted-pricezv2/convert/convert-recordz v2/convert/bgb-convert-coin-listzv2/convert/bgb-convert-records)zv2/convert/tradezv2/convert/bgb-convertzv2/earn/savings/productzv2/earn/savings/accountzv2/earn/savings/assetszv2/earn/savings/recordszv2/earn/savings/subscribe-infoz v2/earn/savings/subscribe-resultzv2/earn/savings/redeem-resultzv2/earn/sharkfin/productzv2/earn/sharkfin/accountzv2/earn/sharkfin/assetszv2/earn/sharkfin/recordszv2/earn/sharkfin/subscribe-infoz!v2/earn/sharkfin/subscribe-resultzv2/earn/loan/ongoing-orderszv2/earn/loan/repay-historyzv2/earn/loan/revise-historyzv2/earn/loan/borrow-history)zv2/earn/loan/debtszv2/earn/loan/reduceszv2/earn/account/assets)zv2/earn/savings/subscribezv2/earn/savings/redeemzv2/earn/sharkfin/subscribezv2/earn/loan/borrowzv2/earn/loan/repayzv2/earn/loan/revise-pledgezv2/common/trade-rate)rQ   r   r   r   r   rR   r   r   r   r   r   )publicprivater   z0.002)takermaker0.0006z0.0004)rQ   rS   requiredCredentials)apiKeysecretpassword
exceptions1z,failure to get a peer from the ring-balancer40104001400230001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132038320403204432045320463204732048320493205032051320523205332057320543205532056320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032083330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330203302133022330233302433025330263302733028330293303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305933060330613306233063330643306521009340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334026340363403734038340393500135002350033500435005350083501035012350143501535017350193502035021350223502435025350263502935030350313503235037350393504035044350463504735048350493505035052350533505535057350583505935060350613506235063350643506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509936001360023600536101361023610336104361053610636107361083610936201362023620336204362053620636207362083620936210362113621236213362143621636217362183621936220362213622236223362243622536226362273622836229362304004014034044054154295001001100210034000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940031400374010240103401044010540106401074010840109402004020140202402034020440205402064020740208402094030040301403024030340304403054030640308403094040040401404024040340404404054040640407404084040940500405014050240503405044050540506405074050840509406004060140602406034060440605406064060740608406094070040701407024070340704407054070640707407084070940710407114071240713407144076240768408084110341114430114300143012430254311545110zinvalid signzinvalid currencyzinvalid symbolzinvalid periodzinvalid userzinvalid amountzinvalid typezinvalid orderIdzinvalid recordzinvalid accountIdzinvalid addresszaccesskey not Nonezillegal accesskeyzsign not nullz0req_time is too much difference from server timezpermissions not rightzillegal sign invalidzuser lockedzRequest Frequency Is Too Highzmore than a daily rate of cashz-more than the maximum daily withdrawal amountzneed to bind email or mobilezuser forbidzUser Prohibited Cash Withdrawalz.Cash Withdrawal Is Less Than The Minimum Valuez.Cash Withdrawal Is More Than The Maximum Valuez%the account with in 24 hours ban coinzorder cancel failzbase symbol errorzbase date errorzapi signature not validzgateway internal errorzaudit failedzorder queryorder invalidzmarket no need pricezlimit need pricezuserid not equal to account_idzyour balance is lowzaddress invalid cointypezsystem exception5000350004500065000750008500095001050014)5001550016500175001850019500205002150026zinvalid order query timezinvalid start timezinvalid end time200030100143111zinvalid size, valid range)exactbroadprecisionModecommonCurrencies
AstroPepeXDegenRebornzJade ProtocolomniTON)APXDEGENJADEOMNITONCOINtimeDifferencer   adjustForTimeDifference1min5min15min30min6Hutc12Hutc1Dutc3Dutc1Wutc1Mutc)r   r   r   r   r   r   r   r   r   r   r   r   1H2H4HdefaultTypedefaultSubTypelinear!createMarketBuyOrderRequiresPricer   p4svefillResponseFromRequest   <      ih  i  i  i  i`'  i  )r   r   r   r   r   r   r   r   r   r   r   r   r   i,  d   )r   r   r   r    publicSpotGetV2SpotMarketCandles)maxLimitPerTimeframemethodi     Z      )r   r   r   r   r   r   r   publicMixGetV2MixMarketCandles)maxRecentDaysPerTimeframerQ   rS   r  %publicSpotGetV2SpotMarketFillsHistory#publicMixGetV2MixMarketFillsHistory&publicMixGetV2MixMarketCurrentFundRateaccountsByTypecrossed_marginisolated_marginusdt_futuresusdc_futurescoin_futuresr   )rQ   crossisolatedrS   	usdc_swaprT   r   accountsByIdr  r  r  )rQ   r  r  r  r  r  r   sandboxModenetworksTRC20ERC20BEP20BSCATOMACA
AcalaTokenAPTAptosARBONEArbitrumOneARBNOVAArbitrumNovaAVAXCzC-ChainAVAXXzX-ChainARArweaveBCHBCHABITCIBTCCELOCSPRADACardanoCHZChilizChainCRC20CronosChainDOGEDOTEOSETHFETHFAIRETHWETCEGLDElrondFILFIOFTMFantomHRC20HECOONEHarmonyHNTHeliumICPIOTXIoTeXKARDIAKAIKAVAKDAKLAYKlaytnKSMKusamaLATLTCMINAMOVRMETIS
MetisTokenGLMRMoonbeamNEARNEARProtocolNULSOASYSOASISROSEr  ONTOntologyOPTIMISMOptimismOSMOOsmosisPOKTPocketNetworkMATICPolygonQTUMREEFSOLSYSSXPSolarXYMSymbolTTTLOSTelosTHETA
ThetaTokenVITEWAVESWAXWAXPWEMIXWEMIXMainnetXDCXDCNetworkXDCXRPFETFETCHNEMREI
REINetworkZILABBCABBCCoinRSKAZEROTRC10JUNOZKSYNC	zkSyncEraSTARKNETStarknetVICVICTIONnetworksById%privateMixGetV2MixPositionAllPositionGTC)EURVNDPLNCZKHUFDKKAUDCADNOKSEKCHFMXNCOPARSGBPBRLUAHZAR)r   defaultTimeInForcefiatCurrencies)lastmarkindex)triggerPriceTypeprice)IOCFOKPOGTD)
marginModetriggerPricer  triggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingmarketBuyRequiresPricemarketBuyByCostmax)r  limitdaysBack	untilDayssymbolRequired)r  triggerr  r  )r  r  r  r  r  )r  r  r  daysBackCanceledr  r  r  r  r  )	sandboxrc   rd   r   r   r   r   rx   r   )r  r  r  r  r  r  r  r  r  r  r  r     r  )extendsrc   r   rx   r  forPerps)r  inverse)rQ   r  rS   rT   )optionsfeatures)deep_extendsuperrA   describeparse_numberr+   r9   r-   r,   r;   r0   r<   r7   r1   r.   r:   r=   r4   r/   r2   r5   r3   r8   r>   )self	__class__s    E/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/bitget.pyr  zbitget.describe%   sB   fd < > GA
(GA
HGA
 $GA
 t	GA

 GA
 GA
 4GA
  www $w 	w
 $w %w Tw $Tw 'w "4w tw w $Tw  w %dw  '!w" /#w$ ,U%w& 0'w( t)w* +w, 7-w. &t/w0 (1w2 '3w4 &t5w6 (7w8 "49w: (;w< ,U=w> -d?w@ %dAwB TCwD  EwF GwH &tIwJ +EKwL )%MwN /OwP &tQwR $TSwT )$UwV $TWwX $UYwZ +D[w\ ']w^ (_w` "4awb cwd &tewf (gwh 1%iwj  kwl +Emwn *:owp +Dqwr &tswt 'uwv (wwx #Dywz *4{w| $T}w~ "4w@ *4AwB +ECwD tEwF  GwH %eIwJ $UKwL &uMwN -dOwP /QwR "4SwT +DUwV WwX !$YwZ !$[w\ &t]w^  _w` dawb $Tcwd +Eewf "4gwh diwj !$kwl "5mwn uowp #Eqwr  swt '
uwv $Uwwx !$ywz ({w| %e}w~ )%w@ uAwB tCwD EwF TGwH tIwJ "4KwL #DMwN $UOwP  QwR !$SwT )%UwV "5WwX #DYwZ [w\ #D]w^ &t_w` tawb Ucwd  ewf "4gwh %iwj Dkwl DmwGA
@ AGA
` aGA
b i43436663744 0 Ak=cGA
b  67./    <a 11  8  6q	 
 5a  4Q  5a  3A  ;A  5a  3A  <Q  9!  =a  <Q   @! " 3F# $ 78;<67:;8967>?45<=5 >  ( 5q( 11(  3A(  4Q	( 
 ?(  21(  :1(  4Q(  21(  9!(  =a(  =a(  :1(  7(  <Q(   ?!( " 7#( $ <Q%( & B1'( ( A!)( * 8+( , 9!-( . 8/( 0 3A1( 2 4Q3( 4 215( 6 :17( 8 4Q9( : <Q;( < B1=( > A!?( @ :1A( B 9!C( D 9!E( F @A?@78BC@BO( *X KLNO?@BC;<45AC 
 =>AB waH  <a  <a   :1   6r	  
 5a   :1   >q   9!   =a   :1   9!   :1   :1   1!   6q    <Q!  " ;A#  $ 45@A@A4667AB56?@9:56>@>?>?AB?  BC!5qC!8!C! 9"C! 8	C!
 ;AC! >qC! A!C! FsC! 4QC! 3AC! 9!C! 9!C! <QC! @C! @C!  CA!C!" 6q#C!$ 8%C!& 4Q'C!( 21)C!* 5a+C!, 6q-C!. 6q/C!0 71C!2 73C!4 ;A5C!6 ;A7C!8 4Q9C!: 21;C!< 1!=C!> 9!?C!@ CAAC!B CACC!D EaEC!F =aGC!H CAIC!J ?KC!L EaMC!N GOC!P ;AQC!R EaSC!T =aUC!V B1WC!X >qYC!Z A![C!\ @]C!^ CA_C!` CAaC!b A!cC!d GeC!f HgC!h AB9::;:<@AAB>??@?@EF78BC9:@AEFEC!EfP1 4a1 5q1  =a1  @	1 
 :11  =a1  ?1  9!1  A!1  3A1  =a1  3A1  >q1  211  1!1   4Q!1 " 6q#1 $ 6q%1 & 8'1 ( 9!)1 * A!+1 , 8-1 . 3A/1 0 DQ11 2 ?31 4 :151 6 >q71 8 9!91 : 6q;1 < 8=1 > <Q?1 @ 5aA1 B 6qC1 D @E1 F :;34BC?@<=@A34239:;<;<@A@AACa1 d;!H#;!7;! 9!;! 7	;!
 ;A;! =a;! 6q;! 8;! 8;! ?;! 7;! @;! =a;! ?;! 4Q;!  5a!;!" ;A#;!$ 4Q%;!& 9!';!( =a);!* 9!+;!, 5a-;!. ;A/;!0 81;!2 ;A3;!4 6q5;!6 CA7;!8 <Q9;!: G;;!< Ea=;!> >q?;!@ ;AA;!B <QC;!D >qE;!F 8G;!H :1I;!J :1K;!L DQM;!N DQO;!P DQQ;!R FqS;!T GU;!V :1W;!X 8Y;!Z =a[;!\ ?];!^ 7_;!` :2a;!b =bc;!d 8e;!f 8g;!h AB<>=>=>>?>?>?u;!god 2389<=789:9:67?@FG
  ;<:;DF>?>?ABABJLHIHI!4 <=<=789:343401./	  78:<;=ABCDEFDEGH>?67ACBCHIJKGH "!:B!:B! A"! <Q	!
 ?! B1! ?! ?! H! B2! B2! CA! Fq! LQ! H!  H!!%$L2 >2 JA2  Nq2  B1	2 
 ?2  =a2  ;A2  <Q2  ?2  B12  :12  ?2  <Q2  :12  82   9!!2 " <Q#2 $ ?%2 & 7'2 ( =a)2 * @+2 , ?-2 . >q/2 0 A!12 2 DQ32 4 B152 6 ?72 8 B192 : Nq;2 < PQR=2 > H?2 @ :1A2 B <QC2 D ?E2 F 89AB@ACDFGDEABDEPQRSJK<=>?AB89c2 f$!<a$!?$! <Q$! ?	$!
 B1$! J1$! Ma$! DQ$! OPQ$! A!$! LQ$! B1$! G$! CA$! H$!  ?!$!" DQ#$!$ @%$!& Ea'$!( ?)$!* >q+$!, DQ-$!. QRS/$!0 <Q1$!2 B13$!4 =a5$!6 CA7$!8 @9$!: ?;$!< Ea=$!> RST?$!@ =aA$!B CAC$!D >qE$!F DQG$!iYv Da Da  DQ  I!	 
 H  @  I!  Fq  H  H  H  B1  A!  H  ?   Fq! " Fq# $ DEJKBCFGGHGHIJJKCDJKDEJKJK= @!BA!F! H! Ea	!
 H! @! <Q! CA! A!! DQ! G! I!! I!! ?! =a!  A!!!" I!#!$ B1%!C5n 24464613	  67789:@A>?  1267!  5q 5q  5a  6q	 
 =a  ?  <Q  7  7  6q  7  >q  @  :1  9!   :1! " :1# $ 344567) . :;67:;3423:;!/B 2A OlGP	cGA
D !..w7!..w7
 "..x8!..x8	EGA
X " $YGA
b yy CDXy ,	y My My 0y 0y 0y 0y \y 0y  Z!y" ^#y$ ]%y& 0'y( -)y* 0+y, 0-y. ^/y0 01y2 ]3y4 ]5y6 ]7y8 19y: Z;y< Z=y> -?y@ ZAyB YCyD ZEyF ^GyH 0IyJ -KyL -MyN ]OyP ZQyR YSyT ZUyV ]WyX ]YyZ ][y\ 1]y` ]ayd -eyf -gyh ]iyj ]kyl \myn \oyp \qyr \syt \uyv ]wyx ]yyz ]{y| ]}y~ ]y@ ]AyB ]CyD ]EyF ]GyH ]IyJ ]KyL ]MyN ]OyP ]QyR ]SyT ]UyV ]WyX ]YyZ -[y\ ]]y^ \_y` .ayb 0cyd ]eyf ]gyh ]iyj ]kyl ]myn \oyp ]qyr \syt \uyv ]wyx ]yyz ]{y| ]}y~ \y@ ]AyB ]CyD \EyF \GyH \IyJ \KyL \MyN ]OyP ]QyR ]SyT ]UyV ]WyX ]YyZ ][y\ ]]y^ ]_y` ]ayb ]cyd ]eyf ]gyh ]iyj ]kyl ]myn ]oyp ]qyt -uyv -wyx .yyz ]{y| ]}y~ ]y@ ]AyB .CyD ]EyF ]GyH ]IyJ ]KyL \MyN ]OyP \QyR ]SyT .UyV ]WyX ]YyZ Z[y\ \]y^ ]_y` \ayb \cyd ]eyf \gyh \iyj \kyl ]myn ]oyp ]qyr ]syt ]uyv ]wyx ]yyz ]{y| ]}y~ ]y@ ]AyB ]CyD ]EyF ]GyH ]IyJ ]KyL ]MyN ]OyP ZQyR ZSyT ]UyV ]WyX ]YyZ ][y\ ]]y` ]ayb -cyd ^eyf ]gyh ]iyj ]kyl ]myn ]oyp .qyr ]syt ]uyv ]wyx ]yyz ]{y| ]}y~ ]y@ -AyB -CyD 0EyF -GyH -IyJ ^KyL ]MyN -OyP ]QyR ]SyT ]UyV ]WyX ]Yy\ ]]y^ ]_y` ]ayb ]cyd 0eyf \gyh \iyj \kyl \myn \oyp ]qyr \syt \uyv \wyx ]yyz ]{y| .}y~ ]y@ ]AyB \CyD \EyF ]GyH ]IyJ ]KyL \MyN ]OyP .QyR .SyT ]UyV \WyX \YyZ .[y\ ]]y^ ._y` ]ayb ]cyd Zeyf Zgyh Ziyj \kyl \myn \oyp \qyr \syt \uyv \wyx \yyz \{y| \}y~ \y@ \AyB \CyD \EyF \GyH \IyJ \KyL \MyN \OyP \QyR \SyT \UyV \WyX \YyZ \[y\ \]y^ \_y` ]ayb ]cyd ]eyf ]gyh ]iyj Zkyl ]myn ]oyp ]qyr ]syv Zwyx Zyyz ]{y| 0}y~ -y@	 -A	yB	 -C	yD	 -E	yF	 -G	yH	 -I	yJ	 .K	yL	 -M	yN	 -O	yP	 -Q	yR	 \S	yT	 ]U	yV	 ZW	yX	 ZY	yZ	 \[	y\	 \]	y^	 \_	y`	 \a	yb	 \c	yd	 \e	yf	 \g	yh	 ]i	yj	 ]k	yl	 \m	yn	 \o	yp	 \q	yr	 \s	yt	 \u	yv	 \w	yx	 \y	yz	 \{	y|	 \}	y~	 \	y@
 \A
yB
 \C
yD
 \E
yF
 \G
yL
 :M
yN
 .O
yP
 +Q
yR
 :S
yT
 :U
yV
 :W
yX
 >Y
yZ
 /[
y\
 -]
y^
 M_
y`
 Ma
yd
 0e
yf
 0g
yh
 0i
yj
 \k
yl
 \m
yn
 0o
yp
 Zq
yr
 \s
yt
 0u
yv
 0w
yx
 0y
yz
 0{
y|
 ]}
y~
 -
y@ ]AyB -CyD ]EyF -GyH ZIyJ -KyL 0MyN ZOyP ZQyR ]SyT ]UyV ]WyX ]YyZ \[y\ ]]y^ ]_y` \ayb ]cyd Zeyf Zgyh Ziyj Zkyl Zmyn Zoyp Zqyr ]syt -uyv Zwyx Zyyz Z{y| Z}y~ ]y@ ]AyB YCyD ]EyF ]GyH ZIyJ ZKyL ZMyN ZOyP ZQyR ]SyT ]UyV ]WyX \YyZ ][y\ ]]y^ ]_y` ]ayb ]cyd 0eyf 0gyh ]iyj ]kyl ]myn ]oyp ]qyr ]syt 1uyv ]wyx ]yyz ]{y| ]}y~ ]y@ ZAyB ]CyD ]EyF ]GyH ]IyJ ZKyL \MyN ZOyP ZQyR ]SyT ]UyV .WyX .YyZ ][y\ ]]y^ ._y` ]ayb \cyd \eyf ]gyh \iyj ]kyl .myn \oyp ]qyr \syv #$7wyx '	yyz %i{y| %j}y~ #My@ %lAyB #LCyD &|EyF %mGyH (IyJ &zKyL )*=MyN ()<OyP $%8QyR GSyT ,-=UyV +,?WyX "#3YyZ 45F[y\ 5j]y^ DZ_y` 3Mayb "#3cyd 67Geyf Ejgyh Ejiyj <=Mkyl (myn (oyp &}qyr ./Bsyt -muyv #Mwyx /
yyz +L{y| '}y~ 5my@ *+<AyB /CyD 'EyF ]GyH YIyJ -KyL -MyN ^OyP .QyR ]SyT \UyV *)))).))0=*4(2**-qyv 0CDcGA
l( Ym(GA
n( #&' !o(GA
|(_ !_)5_ $$&&""%'%%%% #""$$"""%'%%%%_F !G_N vO_P !(Q_R 4TS_T 'U_V -tW_\ 
 !  !! !!""&&'2" #&"%"%"%	1 #E #&"%#&"$"$"$"#1 #C9(]_n  "I !"G	 o_~ #F%_D !"- 1*!/, #E_V "&-'1$*$/$, !W_h ui_j  aWa W	a
 Ua 7a Fa <a 7a ma ~a Ya Ya )a  5!a" F#a$ W%a& 5'a( F)a* F+a, 9-a. =/a0 ]1a2 F3a4 55a6 57a8 I9a: F;a< 5=a> H?a@ 5AaB 5CaD 8EaF VGaH 9IaJ 8KaL 5MaN GOaP eQaR FSaT 5UaV HWaX 8YaZ 5[a\ 5]a^ F_a` Faab \cad Jeaf Ngah Fiaj Wkal Vman Foap :qar 
sat Iuav Owax Yyaz F{a| F}a~ 5a@ 5AaB 7CaD 8EaF 5GaH $IaJ GKaL \MaN FOaP WQaR 6SaT ^UaV ?WaX 5YaZ 7[a\ 5]a^ <_a` 5aab Jcad 5eaf Wgah Wiaj Fka| k}a~ 
a@ 9Aak_n  !o_t E# ', #a}_D  $&*(,$($(%*-
 -2)-+/ ).(-).1
 &*7 $(#'"&#(	( #($)26+/9"$H r% '+!$$(%'*.& ',#($)*.	# '+!$#'$)*/( $(&*!$$(,0%'#'$)*/	*  #OJX  &(,$($(%*-
 -2)-+/ )-(,)-1
 &+7 $(#'"&#(	( #'$(27+07"$H $Q& #D*Q+\ ": ": 	 ": ": 	AH}/GA
 G G	    c                 "    || j                   d<   y )Nr  )r  )r  enableds     r  set_sandbox_modezbitget.set_sandbox_mode  s    &-]#r  Nc                 P   d }| j                  dd |      \  }}d }||	|dk(  rdnd}| j                  |d|      }|;|9|d   }|dk(  rd}n,|dk(  rd	}n$|d
k(  rd}n|dk(  rd}n|dk(  s
|dk(  s|dk(  rd}nd}|t        | j                  dz         | j	                  |d      }||gS )NhandleProductTypeAndParamsr  USDT-FUTURESCOIN-FUTURESproductTypesettleUSDTUSDCUSDC-FUTURESSUSDTSUSDT-FUTURESSUSDCSUSDC-FUTURESSBTCSETHSEOSSCOIN-FUTURESz requires a productType param, one of "USDT-FUTURES", "USDC-FUTURES", "COIN-FUTURES", "SUSDT-FUTURES", "SUSDC-FUTURES" or "SCOIN-FUTURES")handle_sub_type_and_paramssafe_stringr/   rD   omit)r  marketparamssubTypedefaultProductTyper  r  s          r  handle_product_type_and_paramsz%bitget.handle_product_type_and_params  s   99:VX\^de!fn 5<x4Gn&&v}>PQf&8H%F,6!,7"-7"-F"&(8f>N-,#DGG  /z  %z  {  {6=1V$$r  c                 n    | j                  |      }| j                  |di       }| j                  |d      S )aY  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://www.bitget.com/api-doc/common/public/Get-Server-Time

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        data
serverTime)publicCommonGetV2PublicTime
safe_valuesafe_integer)r  r  responser  s       r  
fetch_timezbitget.fetch_time  s;     33F; x4  |44r  c                    | j                   d   r| j                          | j                  | j                   dddg      }g }d}t        dt	        |            D ]  }||   }|dk(  s|dk(  rTg d}t        dt	        |            D ]7  }|j                  | j                  | j                  |d	||   i                   9 f|dk(  rC|j                  | j                  |             d
}|j                  | j                  |             t        | j                  dz   |z   dz          |}	g }
g | j                   d<   g | j                   d<   t        dt	        |	            D ]  }| j                  |	|      }| j                  |dg       }| j                  |di       }| j                  |d      }|rJ|Ht        | j!                  |d      j#                               }|| j                   d<   || j                   d<   | j%                  |
|      }
 g }t        dt	        |
            D ]%  }|j                  | j'                  |
|                ' |S )a  
        retrieves data on all markets for bitget

        https://www.bitget.com/api-doc/spot/market/Get-Symbols
        https://www.bitget.com/api-doc/contract/market/Get-All-Symbols-Contracts
        https://www.bitget.com/api-doc/margin/common/support-currencies

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r  r   rQ   rS   Fr   rT   )r  r  r  r  r  r  r  T does not support  marketcrossMarginPairsDataisolatedMarginPairsDatar  isBorrowablesymbol)r  load_time_differencer  rangelenappend publicMixGetV2MixMarketContractsextend publicSpotGetV2SpotPublicSymbols!publicMarginGetV2MarginCurrenciesr6   rD   	safe_dict	safe_listr  listindex_bykeysarray_concatparse_market)r  r  typespromisesfetchMarginsitypesubTypesjresultsmarketsresr  	firstDatar  keysListresults                    r  fetch_marketszbitget.fetch_markets  sG    <<12%%'nvv>NOq#e*% 	VA8DDH$4~q#h-0 AOOD$I$I$++V\%x{_ K %   E Ef MN# F Fv NO"477-A#AD#H9#TUU	V /1+,24./q#g,' 
	;A..!,C>>#vr2DtQ3I++I~FL 8dH = B B DE7?34:B67++GT:
	; q#g,' 	9AMM$++GAJ78	9r  r  c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }| j                  |dg       }d }| j                  ||      r|}n'| j                  ||      r|}n| j                  |d      }| j                  |      }	|dz   |z   }
d }d}d}d}d}d }d }d }d }d }d }| j                  |d      }d }d}|d	}d
}| j	                  | j                  | j                  |d                  }| j	                  | j                  | j                  |d                  }| j                  || j                  d         }| j                  || j                  d         }||d}|xs |}n|dk(  rd}d
}|
dz   |	z   }
n|dk(  r| j                  |d      }| j                  |      }|j                  d      }| j                  |d      }| j                  |d      }|dd }| j                  |d      }|dd } ||z   | z   }!d}d
}|
dz   |	z   dz   |!z   }
d
}||	k(  }| }| j                  |d      }"| j                  |d      }#| j                  |d      }$| j                  |d      }%t        |$      }&t        |&j                  |"      |&_        |&j                          t        |&      }'| j	                  |'      }t        |%      }(t        |(j                  |#      |(_        |(j                          t        |(      })| j	                  |)      }d
d
d}| j                  |dd      }*d }+|*|*d k(  xs |*d!k(  }+d },|d"k(  r| j!                  |d#      },|rdnd }-i d$|d|
d%|d&|d'|	d(|d)|d*|d+|d	|d,|xr |d-|d|d|d.dd/|+d0|||| j!                  |d1      | j!                  |d2      |-||d d ||d3| j!                  |d4      | j!                  |d5      d6| j#                  |d7d8      | j!                  |d9      d6d d d6|,d d6d:| j                  |d;      |d<S )=Nr  	quoteCoinbaseCoinsupportMarginCoinsr   /F
symbolTyperQ   TpricePrecisionquantityPrecisionr  r  )r  r  	perpetualrS   :deliverydeliveryTime-r   r   r   rT   
pricePlacevolumePlacepriceEndStepsizeMultiplierstatussymbolStatusonlinenormalr  minTradeUSDTrD   basequoter  baseIdquoteIdsettleIdr  rR   marginModesrU   activecontracttakerFeeRatemakerFeeRate)amountr  minLevermaxLeverminr  minTradeNumminTradeAmountmaxTradeAmount)leverager  r  cost
launchTime)r  r  r   r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedinfo)r  safe_currency_coder  in_arrayr  parse_precisionr  r  iso8601splitr?   r  decimalsreducestrsafe_string_2safe_numbersafe_number_2).r  r  marketIdr  r  r  r  r  r  r  r  r  rS   rQ   rT   r  r   amountPrecisionr  r  r&  r'  r  r  isMarginTradingAllowedhasCrossMarginhasIsolatedMarginexpiryPartsyearPartdayPartyearmonthdayexpiryStringpriceDecimalsamountDecimals	priceStep
amountStepprecisepriceStringpreciseAmountamountStringr  r  minCostr%  s.                                                 r  r  zbitget.parse_market  s   t ##FH5""6;7!!&*5''0&&v.!__V5I2N==!34H]]7$67H''(:A>H((2e#%%fl;
!&DD!..t/C/CDDTDTU[]mDn/opN"//0D0DTEUEUV\^qEr0stO!]]8T\\BX5YZN $hE^8_ `'-K &4%E~"[(#.z)**6>B!%f!5,2237++K;**;:!}((a8al#e|c1#.4|CHv~G [F --flCM!..v}EN((@I))&2BCJi(G"7#3#3]CGNNg,K!..{;N#J/M%()?)?%PM"  "}-L"//=O K ##FHnE)Bv/AFF?&&v~>G$q$3
(3
f3
 D3
 U	3

 f3
 f3
 w3
 3
 D3
 D3
 d553
 ;3
 D3
 f3
 e3
  f!3
" #3
$ %%fn=%%fn=(,)'  ++FJ?++FJ?
  --fmEUV++F4DE
  
 #$ ((>e3
 3	
r  c                    | j                  |      }i }| j                  |dg       }| j                  | j                  dg       }t	        dt        |            D ]t  }||   }| j                  |d      }| j                  |      }	| j                  |dg       }
i }t	        dt        |
            D ]  }|
|   }| j                  |d      }| j                  ||	      }|j                         }|||| j                  |d      dd	| j                  |d
      dd	dd| j                  |d      dk(  | j                  |d      dk(  | j                  |d      | j                  | j                  | j                  |d                  d	||<    | j                  |	|      }| j                  |||	||rdndddddddddd	ddd	ddd	ddd      ||	<   w |S )a  
        fetches all available currencies on an exchange

        https://www.bitget.com/api-doc/spot/market/Get-Coin-List

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r  r  r   coinchainschainminWithdrawAmountNr  minDepositAmount)r   depositwithdrawabletruerechargeablewithdrawFeewithdrawMinScale)	r-  rD   networkr+  r  r   rT  feer*  fiatcryptor  r   rT  r-  rD   coder  r  rE   r  rT  r   r[  r*  r+  r,  )publicSpotGetV2SpotPublicCoinsr  r  r  r  r  r  r.  network_id_to_codeupperr7  r  r0  r/  safe_currency_structure)r  r  r  r  r  r  r  entryrD   r`  rP  r  r  rQ  	networkIdrZ  isFiats                    r  fetch_currencieszbitget.fetch_currencies  s4    66v>D x46FKq#d)$ ;	AGE!!%0B**2.D__UHb9FH1c&k* q	 ,,UG<	11)TB!--/!#& $(#3#3E;N#O#'%
 $(#3#3E;M#N#'$	 # $ 0 0 G6 Q#//~F&P++E=A!%!2!243G3GHXHXY^`rHs3t!u%%!2 ]]48F77$"(h !  $#
  $#!
  $#   59 F4LA;	x r  r  c                    | j                          | j                  |      }i }d}d}| j                  d|d      \  }}|d   s|d   rFd}| j                  ||      \  }}||d<   |d   |d<   | j	                  | j                  ||            }n|dk(  r*|d   |d<   | j                  | j                  ||            }n|d	k(  ry| j                  |d
      }|t        | j                  dz         | j                  |d
      }| j                  |      }	|	d   |d<   | j                  | j                  ||            }nt        | j                  dz   |d   z         | j                  |dg       }
| j                  |
|      S )a  
        retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes for a single market

        https://www.bitget.com/api-doc/contract/position/Get-Query-Position-Lever
        https://www.bitget.com/api-doc/margin/cross/account/Cross-Tier-Data
        https://www.bitget.com/api-doc/margin/isolated/account/Isolated-Tier-Data

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: for spot margin 'cross' or 'isolated', default is 'isolated'
        :param str [params.code]: required for cross spot margin
        :param str [params.productType]: *contract only* 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES'
        :returns dict: a `leverage tiers structure <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`
        Nr   r  rS   rT   r  rD   r  r  r`  z4 fetchMarketLeverageTiers() requires a code argumentrO  z; fetchMarketLeverageTiers() symbol does not support market r  )load_marketsr  handle_margin_mode_and_paramsr  )publicMixGetV2MixMarketQueryPositionLeverr  (privateMarginGetV2MarginIsolatedTierDatar  r/   rD   r  currency'privateMarginGetV2MarginCrossedTierDatar0   r  parse_market_leverage_tiers)r  r  r  r  requestr  r  r  r`  rn  r  s              r  fetch_market_leverage_tiersz"bitget.fetch_market_leverage_tiersN  s    	V$
!??@Z\bdno
F6Nx 0K"&"E"Eff"UK%0GM" &tGHEEdkkRY[aFbcH:% &tGHDDT[[QXZ`EabH7"##FF3D|'2h(hiiYYvv.F}}T*H&tnGFOCCDKKPWY_D`aHTWW'ddgmnvgwwxxt 626//??r  c                    g }d}t        dt        |            D ]  }||   }| j                  |d      }||}| j                  |g d      }| j	                  |dd      }	|	|	n|d   }
| j                  |d      }|j                  | j                  |dd	      | j                  ||      | j                  |
      ||| j                  |d
d      | j                  |d      |d       |} |S )Nr   	startUnit)endUnitmaxBorrowableAmountbaseMaxBorrowableAmountrO  r  r  r  leveltierkeepMarginRatemaintainMarginRater"  )ry  r  rn  minNotionalmaxNotionalmaintenanceMarginRatemaxLeverager-  )r  r  r7  safe_number_nr6  r  r  safe_integer_2safe_symbolr.  r8  )r  r-  r  tiersr|  r  itemminimumNotionalr}  marginCurrency
currencyIdr9  s               r  rp  z"bitget.parse_market_leverage_tiers  s   J q#d)$ 	&A7D"..t[AO*-,,T3pqK!//fjIN,:,FVTZ^J''h7HLL++D'6B**8V< 33J?**)-););DBRTh)i#//jA	 	 &K'	&( r  r`  sincer  c                    | j                          d}| j                  |dd      \  }}|r| j                  dd|||dddd	      S || j                         dz
  }|| j                         d}d}|| j	                  |      }|d	   |d
<   |||d<   | j                  d||      \  }}| j                  | j                  ||            }| j                  |dg       }	| j                  |	d||      S )a  
        fetch all deposits made to an account

        https://www.bitget.com/api-doc/spot/account/Get-Deposit-Record

        :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 milliseconds
        :param str [params.idLessThan]: return records with id less than the provided value
        :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 `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Fr   paginateN
idLessThanr      X 	startTimeendTimerD   rO  r  r  r  )
rj  handle_option_and_paramsfetch_paginated_call_cursormillisecondsrn  handle_until_option(privateSpotGetV2SpotWalletDepositRecordsr  r  parse_transactions)
r  r`  r  r  r  r  rq  rn  r  rawTransactionss
             r  fetch_depositszbitget.fetch_deposits  s,    	88R\]&33OT5RWY_amo{  ~B  DG  H  H=%%'*4E((*
 }}T*H&tnGFO$GG229gvN@@WV\A]^0 ..62>&&eUKKr  r  addressc                 h   | j                  |       d}| j                  |      \  }}|t        | j                  dz         | j	                          | j                  |      }| j                  |      }|d   ||| j                  |||      dd}	|||	d<   | j                  | j                  |	|            }
| j                  |
di       }| j                  ||      }d|d	<   | j                  | j                  d
i       }| j                  |dd      }|r||d<   ||d<   ||d<   ||d<   ||d<   ||d<   |S )a3  
        make a withdrawal

        https://www.bitget.com/api-doc/spot/account/Wallet-Withdrawal

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.chain]: the blockchain network the withdrawal is taking place on
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nz* withdraw() requires a "network" parameterrD   on_chain)rO  r  rQ  sizetransferTypetagr  
withdrawalr  r   r  Trn  r  r  	addressTorZ  )check_addresshandle_network_code_and_paramsr/   rD   rj  rn  network_code_to_idcurrency_to_precision%privateSpotPostV2SpotWalletWithdrawalr  r  parse_transactionr  	safe_bool)r  r`  r  r  r  r  networkCodern  rf  rq  r  r  r  withdrawOptionsr  s                  r  r   zbitget.withdraw+	  sc    	7#"AA&IV#DGG.Z$Z[[==&++K8	TN..tV[I&
 ? GEN==dkk'SY>Z[ x4''h7%v//$,,
BG"&..B[]a"b"!%F:%F8F5M 'F9")F; +F9r  c                    | j                          d}| j                  |dd      \  }}|r| j                  dd|||dddd	      S d}|| j                  |      }|| j	                         dz
  }|| j	                         d}||d	   |d
<   | j                  d||      \  }}|||d<   | j                  | j                  ||            }| j                  |dg       }	| j                  |	|||      S )a  
        fetch all withdrawals made from an account

        https://www.bitget.com/api-doc/spot/account/Get-Withdraw-Record

        :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 milliseconds
        :param str [params.idLessThan]: return records with id less than the provided value
        :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 `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Fr   r  Nr  r  r  r  rD   rO  r  r  r  )
rj  r  r  rn  r  r  +privateSpotGetV2SpotWalletWithdrawalRecordsr  r  r  )
r  r`  r  r  r  r  rn  rq  r  r  s
             r  fetch_withdrawalszbitget.fetch_withdrawalsd	  s5    	88ASU_`&334FeUZ\bdpr~  AE  GJ  K  K}}T*H=%%'*4E((*
 &tnGFO229gvN$GGCCDKKPWY_D`a6 ..62>&&%OOr  transactionrn  c                 ~   | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	d }
|	t        j                  |	      }
d }| j                  |d      }|
*|| j                  |
      d}t        j                  ||
      }i d	| j                  |d
      d|d| j                  |d      d|d| j                  |      d| j                  |      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |      d| j                  |d      d|d| j                  |      d| j                  |d      dd d|d|d d |dS )NrO  cTimerQ  r  r  r[  r  rn  r#  rD   orderIdr-  txidtradeId	timestampdatetimerZ  addressFromfromAddressr  	toAddressr  r  r  rn  updateduTimetagFromtagTo)commentinternalr[  )
r  r.  r  r?   
string_absr  
string_subr1  rb  parse_transaction_status)r  r  rn  r  r`  r  rf  r  r  feeCostStringfeeCostAbsStringr[  rL  s                r  r  zbitget.parse_transaction	  sM   N %%k6:
&&z8<%%k7;	$$[':	!!+x8{E2((e<$&11-@''V<'#T->->?O-PQC"--l<LML
$"";	:
K
 D$$[)<
 	

 Y/
 t..y9
 4++KG
 t''[A
 ))+{C
 d''5
 D$$[&9
 
 d33F;
 t((g>
 t
  3!
" S#
$ )
 	
r  r  c                 8    dddddd}| j                  |||      S )Nokpendingfailed)successPendingpending_reviewpending_review_failrejectr  r  r  statusess      r  r  zbitget.parse_transaction_status	  s/     '#+
 &&99r  c                 8   | j                          d}| j                  |      \  }}| j                  |      }d|d   i}|| j                  ||      |d<   | j	                  | j                  ||            }| j                  |di       }| j                  ||      S )a  
        fetch the deposit address for a currency associated with self account

        https://www.bitget.com/api-doc/spot/account/Get-Deposit-Address

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        NrO  rD   rQ  r  )rj  r  rn  r  (privateSpotGetV2SpotWalletDepositAddressr  r  parse_deposit_address)r  r`  r  r  rn  rq  r  r  s           r  fetch_deposit_addresszbitget.fetch_deposit_address	  s     	"AA&IV==&HTN
 "#66{DIGG@@WV\A]^ ~~h3))$99r  c                     | j                  |d      }| j                  |d      }| j                  ||      }d }|| j                  ||      }|||| j                  |d      | j                  |d      dS )NrO  rQ  r  r  )r-  rn  rZ  r  r  )r  r.  rb  )r  depositAddressrn  r  rf  parsedCurrencyrZ  s          r  r  zbitget.parse_deposit_address 
  s     %%nf=
$$^W=	00XF --iHG"&''	B##NE:
 	
r  c                    | j                          | j                  |      }d|d   i}|||d<   d}|d   r"| j                  | j                  ||            }n=d}| j	                  ||      \  }}||d<   | j                  | j                  ||            }| j                  |di       }| j                  |d      }	| j                  ||d   |	      S )	a}  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://www.bitget.com/api-doc/spot/market/Get-Orderbook
        https://www.bitget.com/api-doc/contract/market/Get-Merge-Depth

        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        r  rD   Nr  rQ   r  r  ts)	rj  r  "publicSpotGetV2SpotMarketOrderbookr  r  !publicMixGetV2MixMarketMergeDepthr  r  parse_order_book)
r  r  r  r  r  rq  r  r  r  r  s
             r  fetch_order_bookzbitget.fetch_order_book8
  s     	V$fTl
 $GG&>>>t{{7TZ?[\HK"&"E"Eff"UK%0GM"==dkk'SY>Z[H x4%%dD1	$$T6(+;YGGr  tickerc           
      Z   | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |dd      }| j                  |d      }|| j                  ||d d      }	|}
n| j                  ||d d	      }	|}
| j	                  i d|	d
|d| j                  |      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      dd d|
d|d|dd d|dt        j                  |d      dd | j                  |d       | j                  |d!      | j                  |d"      | j                  |d#      |d$|      S )%Nr  lastPrr  	change24hopen24open24hopenr  rQ   r  r  highhigh24hlowlow24hbidbidPr	bidVolumebidSzaskaskPr	askVolumeaskSzvwapcloser  previousClosechange
percentage100average
baseVolumequoteVolume
indexPrice	markPrice)r  r  r  r  r-  )r  safe_integer_omit_zeror6  r  safe_tickerr1  r?   
string_mul)r  r  r  r9  r  r  r  r  r  r  	openValues              r  parse_tickerzbitget.parse_tickerc
  sC   ^ ##FH5  2//=	!!&+6##FHi@/ <%%hjIFI%%hfEFI !
f!
!
 Y/!
 D$$VY7	!

 4##FH5!
 4##FG4!
 ))&':!
 4##FG4!
 ))&':!
 D!
 I!
 U!
 E!
 T!
 f!
  ',,VU;!!
" t#!
$ **6<@++FMB**6<@))&+>-!
. / 	r  c                 n   | j                          | j                  |      }d|d   i}d}|d   r"| j                  | j                  ||            }n=d}| j	                  ||      \  }}||d<   | j                  | j                  ||            }| j                  |dg       }| j                  |d   |      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://www.bitget.com/api-doc/spot/market/Get-Tickers
        https://www.bitget.com/api-doc/contract/market/Get-Ticker

        :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>`
        r  rD   NrQ   r  r  r   )rj  r   publicSpotGetV2SpotMarketTickersr  r  publicMixGetV2MixMarketTickerr  r  r  r  r  r  rq  r  r  r  s           r  fetch_tickerzbitget.fetch_ticker
  s     	V$fTl
 &><<T[[RX=YZHK"&"E"Eff"UK%0GM"99$++gv:VWH@ ~~h3  a&11r  c                 Z   | j                          | j                  |      }d|d   i}d}|d   rt        | j                  dz         d}| j	                  ||      \  }}||d<   | j                  | j                  ||            }| j                  |dg       }| j                  |d   |      S )	a  
        fetches the mark price for a specific market

        https://www.bitget.com/api-doc/contract/market/Get-Symbol-Price

        :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>`
        r  rD   NrQ   z3 fetchMarkPrice() is not supported for spot marketsr  r  r   )	rj  r  r6   rD   r  "publicMixGetV2MixMarketSymbolPricer  r  r  r  s           r  fetch_mark_pricezbitget.fetch_mark_price3  s     	V$fTl
 &>tww)^^__K"&"E"Eff"UK%0GM">>t{{7TZ?[\H~~h3  a&11r  symbolsc                    | j                          d}|#| j                  |d      }| j                  |      }d}i }d}| j                  d||      \  }}| j	                  |d      }d}	| j                  ||      \  }	}|dk(  r$|"| j                  | j                  ||            }n&|	|d<   | j                  | j                  ||            }| j                  |dg       }
| j                  |
|      S )aE  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://www.bitget.com/api-doc/spot/market/Get-Tickers
        https://www.bitget.com/api-doc/contract/market/Get-All-Symbol-Ticker

        :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
        :param str [params.subType]: *contract only* 'linear', 'inverse'
        :param str [params.productType]: *contract only* 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES'
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nr   r   r  rQ   r  r  )rj  r  r  handle_market_type_and_paramsr  r  r   r  publicMixGetV2MixMarketTickersr  parse_tickers)r  r  r  r  r  r  rq  r  passedSubTyper  r  s              r  fetch_tickerszbitget.fetch_tickersM  s    	__Wa0F[[(F99.&RXYf ((;"AA&&QV6>m3<<T[[RX=YZH%0GM"::4;;wPV;WXHt ~~h3!!$00r  tradec                    | j                  |d      }| j                  ||      }| j                  |dd      }d }| j                  |d      }| j                  |d      }||d   n|}	|	k| j	                  | j                  |	d            }
d|
i}| j                  |	d	      }| j                  |	d
      du }|r||d<   nt        j                  |      |d<   | j                  || j                  |d      | j                  |d      || j                  |d      | j                  |d      | j                  |d      | j                  |dd      | j                  |dd      | j                  |dd      || j                  |      |d|      S )Nr  r  r  	feeDetailposModer   feeCoinrn  totalFee	deductionTr#  r  r  side	orderType
tradeScopepriceAvgr  r  r  r  r  )r-  rD   orderr  r  r  takerOrMakerr  r  r#  r  r  r[  )r  r  r  r  r.  r?   
string_neg
safe_tradesafe_string_lowerr6  r1  )r  r  r  r9  r  r  r[  r  r  feeStructurecurrencyCoder  r  s                r  parse_tradezbitget.parse_trade  s   f ##E84!!(F3''w=	OOE;7	""5)4(/(;y|)#2243C3CLR[3\]LLC !,,\:FM(({CtKI+F%00?F""5)4%%eY7**5&9$$UK8 ,,ULA''z7C((fE&&umXF"Y/ 
  	r  c           	         | j                          d}| j                  |dd      \  }}|r| j                  d||||dd      S | j                  |      }d|d   i}||d   rt	        |d	      |d
<   n||d
<   | j                  | j                  di       }d}	|d   r| j                  |di       }
| j                  |
dd      }| j                  |d|      }| j                  |d      }|dk(  r?| j                  d||      \  }}|||d<   | j                  | j                  ||            }	n|dk(  r| j                  | j                  ||            }	n| j                  |di       }| j                  |dd      }| j                  |d|      }| j                  |d      }d}| j                  ||      \  }}||d<   |dk(  r?| j                  d||      \  }}|||d<   | j                  | j                  ||            }	n&|dk(  r!| j                  | j                  ||            }	| j!                  |	dg       }| j#                  ||||      S )a  
        get the list of most recent trades for a particular symbol

        https://www.bitget.com/api-doc/spot/market/Get-Recent-Trades
        https://www.bitget.com/api-doc/spot/market/Get-Market-Trades
        https://www.bitget.com/api-doc/contract/market/Get-Recent-Fills
        https://www.bitget.com/api-doc/contract/market/Get-Fills-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]: *only applies to publicSpotGetV2SpotMarketFillsHistory and publicMixGetV2MixMarketFillsHistory* the latest time in ms to fetch trades for
        :param boolean [params.paginate]: *only applies to publicSpotGetV2SpotMarketFillsHistory and publicMixGetV2MixMarketFillsHistory* default False, when True will automatically paginate by calling self endpoint multiple times
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        Fr   r  r  r  rD   Nr    r  rQ   r  r  r  r  publicSpotGetV2SpotMarketFillsrS   r  r  publicMixGetV2MixMarketFillsr  )rj  r  r  r  r  r  r  r  r  r  r  r  r#  r  r  r$  r  parse_trades)r  r  r  r  r  r  r  rq  r  r  spotOptionsdefaultSpotMethod
spotMethodswapOptionsdefaultSwapMethod
swapMethodr  r  s                     r  fetch_tradeszbitget.fetch_trades   s   " 	88PZ[&33M65RWY_amo{||V$fTl
 j!#&ud#3 #( //$,,rB&>//'62>K $ 0 0hHo p))&(<MNJYYvx0FDD"&":":9gv"V$+0GK(EEdkkRY[aFbc??>>t{{7TZ?[\//'62>K $ 0 0hHm n))&(<MNJYYvx0FK"&"E"Eff"UK%0GM"BB"&":":9gv"V$+0GK(CCDKKPWY_D`a==<<T[[RX=YZL ~~h3  vue<<r  c                 <   | j                          | j                  |      }d|d   i}d}| j                  d|      \  }}|d   r|d|d<   nd|d<   nd|d<   | j                  | j	                  ||            }| j                  |d	i       }| j                  ||      S )
a  
        fetch the trading fees for a market

        https://www.bitget.com/api-doc/common/public/Get-Trade-Rate

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'isolated' or 'cross', for finding the fee rate of spot margin trading pairs
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        r  rD   Nr   rQ   rR   businessTyper   r  )rj  r  rk  !privateCommonGetV2CommonTradeRater  r  parse_trading_fee)r  r  r  r  rq  r  r  r  s           r  fetch_trading_feezbitget.fetch_trading_fee  s     	V$fTl
 
!??@QSYZ
F&>%*2'*0'&+GN#99$++gv:VW x4%%dF33r  c                    | j                          d}d}d}| j                  d|      \  }}| j                  dd|      \  }}|dk(  rM| j                  |dd      }| j	                  |d      }||r| j                  |      }nh| j                  |      }nV|dk(  s|dk(  r.d}| j                  d|      \  }}||d<   | j                  |      }nt        | j                  d	z   |z   d
z         | j                  |dg       }i }t        dt        |            D ]U  }	||	   }
| j                  |
d      }| j                  |dd|      }| j!                  |      }| j#                  |
|      }|||<   W |S )a  
        fetch the trading fees for multiple markets

        https://www.bitget.com/api-doc/spot/market/Get-Symbols
        https://www.bitget.com/api-doc/contract/market/Get-All-Symbols-Contracts
        https://www.bitget.com/api-doc/margin/common/support-currencies

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.productType]: *contract only* 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES'
        :param boolean [params.margin]: set to True for spot margin
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        Nr   rQ   rR   FrS   rT   r  r  r  r  r   r  )rj  rk  r	  r  r  r  r  r  r  r6   rD   r  r  r  r  r  r  r0  )r  r  r  r  
marketTyperR   r  r  r  r  re  r9  r  r  r[  s                  r  fetch_trading_feeszbitget.fetch_trading_fees  s    	

!??@RTZ[
F!??@RTXZ`a
F^^FHe<FYYvx0F&6AA&I@@HF"
h(>K"&"E"EdF"SK$/F=!<<VDHtww)==
JYVWWP x4q#d)$ 	!AGE''x8H%%hdJGF[[(F((7C F6N	! r  c                     | j                  |d      }|| j                  ||      | j                  |d      | j                  |d      d d dS )Nr  r  r  )r-  r  r   r   r  	tierBased)r  r  r7  )r  r  r  r9  s       r  r0  zbitget.parse_trading_fee  sW    ##D(3&&x8%%dN;%%dN;
 	
r  c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr   r   r      r      )r  r7  )r  ohlcvr  s      r  parse_ohlcvzbitget.parse_ohlcv*  sn     eQ'UA&UA&UA&UA&UA&
 	
r  r   c           	         | j                          d}d}d}| j                  |dd      }	| j                  |dd      }
d}| j                  |dd	      \  }}|r|
r|n|}| j                  d||||||      S | j	                  |      }|d
   rd
nd}| j
                  d   |   }|d   | j                  |||      d}d}| j                         }| j                  |      dz  }| j                  |d      }|du}|du}|du}| j                  |dg      }|d
   rd
nd}| j                  | j
                  d   |i       }| j                  |di       }| j                  |||      }| j                  | j
                  d   di       }| j                  ||      }||dz
  |z  z
  }|rt        ||      }t        ||      }n|}||z  }d} d}!|r |} ||d<   |s| j                  | |      }!|!|d<   |r|}!|!|d<   |s|!|z
  } d}"| | |k  s|	rId}"t        ||      }||z  }|!|z
  } | |d<   |d
   s'd}#|!| z
  |#|z  kD  r| j                  | |#|z        }!|!|d<   ||d<   d}$|d
   rF|"r"| j                  | j                  ||            }$n| j!                  | j                  ||            }$nd}%| j#                  |d      \  }%}d}&| j%                  ||      \  }&}|&|d<   | j                  ||      }'|%dk(  r| j'                  |'      }$n<|%dk(  r| j)                  |'      }$n%|"r| j+                  |'      }$n| j-                  |'      }$|$dk(  rg S | j/                  |$d|$      }(| j1                  |(||||      S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://www.bitget.com/api-doc/spot/market/Get-Candle-Data
        https://www.bitget.com/api-doc/spot/market/Get-History-Candle-Data
        https://www.bitget.com/api-doc/contract/market/Get-Candle-Data
        https://www.bitget.com/api-doc/contract/market/Get-History-Candle-Data
        https://www.bitget.com/api-doc/contract/market/Get-History-Index-Candle-Data
        https://www.bitget.com/api-doc/contract/market/Get-History-Mark-Candle-Data

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest candle to fetch
        :param boolean [params.useHistoryEndpoint]: whether to force to use historical endpoint(it has max limit of 200)
        :param boolean [params.useHistoryEndpointForPagination]: whether to force to use historical endpoint for pagination(default True)
        :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)
        :param str [params.price]: *swap only* "mark"(to fetch mark price candles) or "index"(to fetch index price candles)
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        r  r"  r   useHistoryEndpointFuseHistoryEndpointForPaginationTr   r  rQ   rS   r   rD   )r  granularity \&untilNr  r  r   r  r  r  r  r  r  r  r   r  )rj  r  r  "fetch_paginated_call_deterministicr  r  r  r  parse_timeframer  r  r  r  sum'publicSpotGetV2SpotMarketHistoryCandlesr  r  handle_param_stringr  )publicMixGetV2MixMarketHistoryMarkCandles*publicMixGetV2MixMarketHistoryIndexCandles%publicMixGetV2MixMarketHistoryCandlesr  r  parse_ohlcvs))r  r  	timeframer  r  r  defaultLimitmaxLimitForRecentEndpointmaxLimitForHistoryEndpointr=  r>  r  limitForPaginationr  r3  r   rq  msInDaynowdurationrA  limitDefinedsinceDefineduntilDefinedkeyohlcOptionsr  maxLimitForThisTimeframerecentEndpointDaysMaprecentEndpointAvailableDaysrecentEndpointBoundaryTslimitMultipliedDurationcalculatedStartTimecalculatedEndTimehistoricalEndpointNeededmaxDistanceDaysForContractsr  	priceTyper  extendedr  s)                                            r  fetch_ohlcvzbitget.fetch_ohlcv?  sL   . 	$(!%("!^^F4H%P*...Abdh*i'88zZ&?^!;d}::<QVX]_hjp  sE  F  FV$%f~V6
\\,/
;
Tl++J	9M
 !''	2T9!!&'2D(D(D(6G9- vfFnnT\\,%?bI#~~k;QSUV#'#4#45I9V[#\  $t||L/IKfhj k&*&7&78My&Y##&*E*IW)T#T 89E78E E"'("2 # "'#(GK $(HH-@BY$Z!%6	" %!2GI&7:Q&Q# $) +0CG_0_dv'+$9:E&+h&6#"36M"M#6GK &>.0+$'::=X[b=bb(,1DFadkFk(l%):GI& &>'GGT[]cHde@@WV\A]^I $ 8 8 IIvK"&"E"Eff"UK%0GM"{{7F3HF"II(Sg%JJ8T+#II(SH#BB8LHr>I~~h9  vy%GGr  c                    | j                          i }d}d}d}| j                  dd|      \  }}| j                  d|      \  }}|dk(  s|dk(  r>d}| j                  d|      \  }}||d<   | j	                  | j                  ||            }n|dk(  r"| j                  | j                  ||            }nl|dk(  r"| j                  | j                  ||            }nE|dk(  r"| j                  | j                  ||            }nt        | j                  d	z   |z   d
z         | j                  |dg       }| j                  |      S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://www.bitget.com/api-doc/spot/account/Get-Account-Assets
        https://www.bitget.com/api-doc/contract/account/Get-Account-List
        https://www.bitget.com/api-doc/margin/cross/account/Get-Cross-Assets
        https://www.bitget.com/api-doc/margin/isolated/account/Get-Isolated-Assets
        https://bitgetlimited.github.io/apidoc/en/margin/#get-cross-assets
        https://bitgetlimited.github.io/apidoc/en/margin/#get-isolated-assets

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.productType]: *contract only* 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES'
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        Nrr   rS   rT   r  r  r  rQ   z! fetchBalance() does not support z	 accountsr  )rj  r	  rk  r  !privateMixGetV2MixAccountAccountsr  -privateMarginGetMarginV1IsolatedAccountAssets*privateMarginGetMarginV1CrossAccountAssets!privateSpotGetV2SpotAccountAssetsr6   rD   r  parse_balance)r  r  rq  r3  r  r  r  r  s           r  fetch_balancezbitget.fetch_balance  s\    	

!??PTV\]
F!??PVW
F& jH&<K"&"E"EdF"SK%0GM"==dkk'SY>Z[H:%II$++V]_eJfgH7"FFt{{SZ\bGcdH6!==dkk'SY>Z[Htww)LLzY\gghhp x4!!$''r  c                    d|i}t        dt        |            D ].  }||   }| j                         }| j                  |dd      }| j	                  |      }| j                  |d      }|V| j                  |d      }	| j                  |d      |d<   | j                  |d	      |d
<   t        j                  ||	      |d<   n| j                  |d      }
| j                  |d      }|||d<   | j                  |d      |d
<   nB|
|d<   | j                  |d      }| j                  |d      }t        j                  ||      |d<   |||<   1 | j                  |      S )Nr-  r   
marginCoinrO  borrowinteresttransferablefreetotalAmounttotaldebt	availablemaxTransferOutaccountEquityfrozenlockedused)	r  r  accountr6  r.  r  r?   
string_addsafe_balance)r  balancer  r  re  r{  r  r`  rn  ro  spotAccountFreecontractAccountFreerx  ry  s                 r  rj  zbitget.parse_balance>  s{   (z q#g,' 	#AAJEllnG++E<HJ**:6D%%eX6F!++E:>"&"2"25."I#'#3#3E=#I ")"4"4VX"F #'"2"25+"F&*&6&6u>N&O#&2&9GFO'+'7'7'OGG$&5GFO!--eX>F!--eX>F&-&8&8&HGFO"F4L/	#0   ((r  c                     i dddddddddddddd	d
d	dd	dddddddddddddd	}| j                  |||      S )Nnewr  initnot_triggerpartial_fillpartially_fillpartially_filled	triggeredclosed	full_fillfilledfail_triggerrejectedcancelcanceled	cancelledlivefail_executeexecutedr  r  s      r  parse_order_statuszbitget.parse_order_status  s    
6
F
 6
 F	

 f
 
 
 
 h
 J
 j
 
 

 F
 J
  !
$ &&99r  r  c                    | j                  |d      }|8| j                  || j                  |d      | j                  |dd      dd|      S d|v }|rdnd	}||d
   }| j                  |d      }| j                  ||d |      }| j	                  |dd      }| j                  |d      }| j                  |dd      }	| j                  |d|	      }	d }
| j                  |d      }|*| j                  t        j                  |            |d   d}
| j                  |d      }|t        j                  |      }t        |j                               }d }t        dt        |            D ]  }||   }| j                  |d      |} n | j                  t        j                  | j                  |d                  | j!                  | j                  |d            d}
d }| j#                  |d      }|dk(  rd}d}d }| j                  |d      }|	|dk(  rdnd}d }d }| j                  |d       }|%| j                  |d!      }| j                  |d       }n%| j                  |d"d#      }| j                  |d!      }d }d }| j                  |d$      }||}| j                  |d%      }n$| j                  |d%      }| j                  |d&      }| j                  |d'      }| j                  |d(      }|d)k(  r|r	|d*k(  rd+nd*}| j                  i d,|d-| j                  |dd.      d| j                  |dd      d/|d0| j%                  |      d1|d2|d|d   d
| j                  |d3      d'|d"|d4|d5| j                  |d6d7      d8|d9|d:d d;|||| j'                  |d<      | j)                  |d=d>      | j)                  |d?d@      | j+                  |	      |
d dA|      S )BNerrorMsgr  clientOrderId	clientOidr  )r-  rD   r  r  posSider  rQ   r  r  r  ctimer  r  state
planStatusr[  r  )r#  rn  r  r   feeCoinCoder  force	POST_ONLYTr  
reduceOnlyNOF	basePricer  r  executePricebaseSizer  r  r  r  
hedge_modebuysellr-  rD   r  r  r  lastTradeTimestamplastUpdateTimestampr  r  r#  r  	quoteSizer  r  	remainingr  r  presetStopSurplusPricestopSurplusTriggerPricepresetStopLossPricestopLossTriggerPrice)postOnlyr  r  r  r  r  r[  trades)r  
safe_orderr6  safe_marketr  r  r  r?   r  r  jsonloadsr  valuesr  r  r.  safe_string_upperr1  r7  r8  r  )r  r  r  errorMessageisContractOrderr3  r9  r  updateTimestamp	rawStatusr[  r  r  parsedFeeDetail	feeValues	feeObjectr  feeValuer  r  r  reduceOnlyRawr  r  r  r  r  r  r  r  s                                 r  parse_orderzbitget.parse_order  s   ^ ''z:#??&&ui8!%!3!3E?K!X$	$
   %-#2Z
J##E84!!(FD*E''w@	++E7;&&uh@	$$UL)D	((6$ ))'*<*<]*KL"8,C OOE;7	 "jj3O_3356II1c)n- $Q<??8];G (I	 ))'*<*<T=M=MiYc=d*ef 33D4D4DYP]4^_C ,,UG<+%HK
((=$#0D#8tJ$$UK8	 $$UJ7E&&uk:G&&ug~FE&&uj9G##E:6D%%eV4F##E62D%%e\:Fv.""5)4l"z"em6%D   
E 
$$$UIv> 
 T//T 
 	 

 Y/ 
 !/ 
 "? 
 fX& 
 D$$UK8 
 D 
 U 
 d 
 D&&um[I 
 w 
 f 
  ! 
" ;# 
$ !$ ,,UNC#11%9QSlm!//7LNde--i83 
4 5 	r  r#  c                     | j                          | j                  |      }|d   st        | j                  dz         ddi}| j	                  |dd|d| j                  ||            S )a|  
        create a market buy order by providing the symbol and cost

        https://www.bitget.com/api-doc/spot/trade/Place-Order
        https://www.bitget.com/api-doc/margin/cross/trade/Cross-Place-Order
        https://www.bitget.com/api-doc/margin/isolated/trade/Isolated-Place-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
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rQ   z9 createMarketBuyOrderWithCost() supports spot orders onlyr  Fr  r  N)rj  r  r6   rD   create_orderr  )r  r  r#  r  r  reqs         r  !create_market_buy_order_with_costz(bitget.create_market_buy_order_with_cost!  sp     	V$f~tww)ddee/
   5$dkkRUW]F^__r  r  r  r  c                    | j                          | j                  |      }| j                  d|      }|d   }	| j                  |dd      }
| j	                  |d      }| j	                  |d      }| j                  |dd      }|d	u}|
d	u}|d	u}|d	u}|xs |}| j                  ||||||      }d	}|d
   rT|r| j                  |      }n{|	dk(  r| j                  |      }nd|	dk(  r| j                  |      }nM| j                  |      }n;|s|r| j                  |      }n%|r| j                  |      }n| j                  |      }| j                  |di       }| j                  ||      S )a  
        create a trade order

        https://www.bitget.com/api-doc/spot/trade/Place-Order
        https://www.bitget.com/api-doc/spot/plan/Place-Plan-Order
        https://www.bitget.com/api-doc/contract/trade/Place-Order
        https://www.bitget.com/api-doc/contract/plan/Place-Tpsl-Order
        https://www.bitget.com/api-doc/contract/plan/Place-Plan-Order
        https://www.bitget.com/api-doc/margin/cross/trade/Cross-Place-Order
        https://www.bitget.com/api-doc/margin/isolated/trade/Isolated-Place-Order

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much 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 float [params.cost]: *spot only* how much you want to trade in units of the quote currency, for market buy orders only
        :param float [params.triggerPrice]: *swap only* The price at which a trigger order is triggered at
        :param float [params.stopLossPrice]: *swap only* The price at which a stop loss order is triggered at
        :param float [params.takeProfitPrice]: *swap only* The price at which a take profit order is triggered at
        :param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered(perpetual swap markets only)
        :param float [params.takeProfit.triggerPrice]: *swap only* take profit trigger price
        :param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered(perpetual swap markets only)
        :param float [params.stopLoss.triggerPrice]: *swap only* stop loss trigger price
        :param str [params.timeInForce]: "GTC", "IOC", "FOK", or "PO"
        :param str [params.marginMode]: 'isolated' or 'cross' for spot margin trading
        :param str [params.loanType]: *spot margin only* 'normal', 'autoLoan', 'autoRepay', or 'autoLoanAndRepay' default is 'normal'
        :param str [params.holdSide]: *contract stopLossPrice, takeProfitPrice only* Two-way position: ('long' or 'short'), one-way position: ('buy' or 'sell')
        :param float [params.stopLoss.price]: *swap only* the execution price for a stop loss attached to a trigger order
        :param float [params.takeProfit.price]: *swap only* the execution price for a take profit attached to a trigger order
        :param str [params.stopLoss.type]: *swap only* the type for a stop loss attached to a trigger order, 'fill_price', 'index_price' or 'mark_price', default is 'mark_price'
        :param str [params.takeProfit.type]: *swap only* the type for a take profit attached to a trigger order, 'fill_price', 'index_price' or 'mark_price', default is 'mark_price'
        :param str [params.trailingPercent]: *swap and future only* the percent to trail away from the current market price, rate can not be greater than 10
        :param str [params.trailingTriggerPrice]: *swap and future only* the price to trigger a trailing stop order, default uses the price argument
        :param str [params.triggerType]: *swap and future only* 'fill_price', 'mark_price' or 'index_price'
        :param boolean [params.oneWayMode]: *swap and future only* required to set self to True in one_way_mode and you can leave self in hedge_mode, can adjust the mode using the setPositionMode() method
        :param bool [params.hedged]: *swap and future only* True for hedged mode, False for one way mode, default is False
        :param bool [params.reduceOnly]: True or False whether the order is reduce-only
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rc   r   	stopPricer  r  r  trailingPercentcallbackRatioNrQ   r  r  r  )rj  r  rk  safe_value_2r  r6  create_order_request(privateSpotPostV2SpotTradePlacePlanOrder+privateMarginPostV2MarginIsolatedPlaceOrder*privateMarginPostV2MarginCrossedPlaceOrder$privateSpotPostV2SpotTradePlaceOrder&privateMixPostV2MixOrderPlacePlanOrder&privateMixPostV2MixOrderPlaceTpslOrder"privateMixPostV2MixOrderPlaceOrderr  r  )r  r  r  r  r  r  r  r  marginParamsr  r  r  takeProfitTriggerPricer  isTrailingPercentOrderisTriggerOrderisStopLossTriggerOrderisTakeProfitTriggerOrderisStopLossOrTakeProfitTriggerrq  r  r  s                         r  r  zbitget.create_order7  s   T 	V$99-P!!_
((nM#vG!%9J!K,,V5FX!0!<%T1!5T!A#9#E (>(ZBZ%++FD$vV&>HHQz)KKGTw&JJ7SDDWM!7FFwO.FFwOBB7K ~~h3f--r  c                 @   | j                  |      }d }d }	| j                  d||      \  }}| j                  d|      \  }	}|d   |d}
|dk(  }| j                  |dd      }| j	                  |d      }| j	                  |d      }| j	                  |d	      }| j	                  |d
      }|d u}|d u}|d u}|d u}|d u}|xs |}|xs |}| j                  |d| j                  |            }| j                  |dd      }|d u}| j                  ||||      dkD  rt        | j                  dz         |dk(  r| j                  ||      |
d<   | j                  |ddd      }| j                  |dd      }| j                  |dd      }| j                  |dd      }d }| j                  ||dk(  |      \  }}| j                  | j                  d      } | j                  |d|       }!|rd|
d<   n |!dk(  rd|
d<   n|!dk(  rd|
d<   n
|!dk(  rd|
d<   | j!                  |g d       }|d!k(  s|d"k(  r|d#   |
d$<   | j#                  ||      |
d%<   d }"| j%                  ||      \  }"}|"|
d&<   |||
d<   |s|s|r||
d<   |rU|st'        | j                  d'z         |t)        | j                  d(z         d)|
d*<   | j                  ||      |
d<   ||
d<   n|rd+|
d*<   | j                  ||      |
d<   || j                  ||      |
d,<   |rg| j+                  |dd      }#| j                  ||#      |
d-<   | j-                  |d      }$| j                  ||$      |
d.<   | j                  |d/d      }%|%|
d0<   |r| j+                  |dd      }&| j                  ||&      |
d1<   | j-                  |d      }'| j                  ||'      |
d2<   | j                  |d/d      }(|(|
d3<   n|r`|st        | j                  d4z         |d5k(  rd6nd7|
d8<   |r| j                  ||      |
d<   d9|
d*<   nq|ro| j                  ||      |
d<   d:|
d*<   nT|r(| j                  |dd      }#| j                  ||#      |
d;<   |r(| j                  |dd      }&| j                  ||&      |
d<<   |s|	d=}	|	d=k(  rd>nd?})|)|
d@<   d }*| j/                  |dAd      \  }*}d }+| j/                  |dB      \  }+}|+|+ }*|},|r|*sdC|
d<   n|d5k(  rdDnd5},dE|
dF<   n|*rdG|
dF<   |,|
dH<   n|dIk(  ro|s|rt1        | j                  dJz         ||
dH<   d }-d }.dK}/| j3                  |ddLdK      \  }/}|r|d5k(  rdM}.| j-                  |dN      }0| j!                  |dN      }|0| j5                  ||0      }-n|/re|t1        | j                  dOz         | j                  |      }1| j                  |      }2t7        j8                  |1|2      }3| j5                  ||3      }-n'| j5                  ||      }-ndP}.| j#                  ||      }-|||
d<   |	dQ|
dR<   |r|d5k(  r|-|
dS<   nd|-|
dT<   n^|-|-|
d%<   |U|.|
d*<   ||
d<   | j                  ||      |
d<   |4| j                  ||      |
d,<   nt;        | j                  dUz   |z   dVz         | j=                  |
|      S )WNrc   rD   )r  r  r  r  r  r  r  stopLoss
takeProfittrailingTriggerPricer  r  r   zk createOrder() params can only contain one of triggerPrice, stopLossPrice, takeProfitPrice, trailingPercentr  r  r  triggerType
mark_pricer  Fr  r  r  r  	post_onlyr  rs  r  r  )r  r  r  r  r  r  r  r  r  r  r  rS   rT   r  rm  r  r  z; createOrder() bitget trailing orders must be market orderszL createOrder() bitget trailing orders must have a trailingTriggerPrice param
track_planplanTypenormal_planr  r  stopLossExecutePricer  stopLossTriggerTyper  stopSurplusExecutePricestopSurplusTriggerTypezI createOrder() bitget stopLoss or takeProfit orders must be market ordersr  longshortholdSidepos_loss
pos_profitr  r  r  crossedr  r  r  
oneWayModeYESr  Close	tradeSideOpenr  rQ   z_ createOrder() does not support stop loss/take profit orders on spot markets, only swap marketsTr  rs  r#  z 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 in the amount argumentr  r  loanTyper  r  z  createOrder() does not support  orders)r  r	  rk  r  r  r  number_to_stringr6  rE  r+   rD   price_to_precisionr  handle_post_onlyr  r  r  amount_to_precisionr  r0   r/   r8  r7  handle_param_boolr4   r  cost_to_precisionr?   r  r6   r  )4r  r  r  r  r  r  r  r  r3  r  rq  isMarketOrderr  r  r  r  r  r  r  r  
isStopLossisTakeProfitr  isStopLossOrTakeProfitr  r  r  r  r  r  exchangeSpecificTifParamr  r  r  r  slTriggerPriceslPriceslTypetpTriggerPricetpPricetpTypemarginModeRequestr  r  requestSidequantityr  r  r#  rL  rJ  quoteAmounts4                                                       r  r  zbitget.create_order_request  st   V$

!??vW]^
F!??vV
FTl
 (((nM#vG!%9J!K??6:6__V\:
%T1!5T!A#9#E T)
!-(>(ZBZ%!+!;|#//8NPTPePefkPlm,,V5FX!0!<88N$:<TVlmpqq  +X  !X  Y  Y7?#66vuEGG--f6H-Yef^^FL%@
**6;P#'#5#5fg}#U 00@X\g@giop&!33DLLBVW,,V]DVW*GGE!$GGE!$GGE!$GG6  $T  U& jH&<$*:$6GL!"66vvFGFOK"&"E"Eff"UK%0GM"('4$!>BX)9&%$$TWW/l%lmm'/+DGG  7E  -E  F  F&2
#*.*A*A&J^*_'+:(&3
#*.*A*A&,*W'$.2.E.Efe.TGN+%)%7%7.R]%^N6:6M6MfVd6eG23"..xAG6:6M6MfV]6^G23!--hMF5;G12%)%7%7
NT_%`N9=9P9PQWYg9hG56"..z7CG9=9P9PQWY`9aG56!--j&,OF8>G45.$'2}(}~~15fW
#).2.E.EfNb.cGN+*4GJ'-.2.E.EfNd.eGN+*6GJ'%)%6%6xQ\%]N595L5LVUc5dG12%)%6%6z>S^%_N8<8O8OPVXf8gG450%!(J2<2GIj!(9%!%!7!7%!P!
%)%;%;FL%Q"
F)!+^F"!05- 26fU/6,/5,"-6!,0F"477  .O  $O  P  P"GFOHH04-8<8U8UV\^k  nQ  SW  9X5-v$%-"''7662##55fdCH6}*477  6q  ,q  r  r'+'<'<V'D&*&;&;E&B&-&8&8{&S#'#9#9&+#N#55ffEH#33FFC('4$%&.
# dem+3GK(*2GJ''&.GFO+*2GJ'-=GM*.2.E.Efl.[GN+(262I2I&RW2X/tww)KKjX[ddee{{7F++r  ordersc           	      `   | j                          g }d}d}t        dt        |            D ]  }||   }| j                  |d      }||}n||k7  rt	        | j
                  dz         | j                  |d      }	| j                  |d      }
| j                  |d      }| j                  |d      }| j                  |d	i       }| j                  d
|      }|d   }|"||}n||k7  rt	        | j
                  dz         | j                  ||	|
|||      }|j                  |        | j                  |      }|d   |d}d}|d   s|d   rH|d}|dk(  rdnd}||d<   |d   |d<   d}| j                  ||      \  }}||d<   | j                  |      }n?|dk(  r| j                  |      }n(|dk(  r| j                  |      }n| j                  |      }| j                  |di       }| j                  |dg       }| j                  |dg       }| j!                  ||      }| j#                  ||      S )a  
        create a list of trade orders(all orders should be of the same symbol)

        https://www.bitget.com/api-doc/spot/trade/Batch-Place-Orders
        https://www.bitget.com/api-doc/contract/trade/Batch-Order
        https://www.bitget.com/api-doc/margin/isolated/trade/Isolated-Batch-Order
        https://www.bitget.com/api-doc/margin/cross/trade/Cross-Batch-Order

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the api endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   r  z; createOrders() requires all orders to have the same symbolr  r  r  r  r  rd   zS createOrders() requires all orders to have the same margin mode(isolated or cross)rD   )r  	orderListrS   rT   r  r  r  r  r  rm  r  r  failureListsuccessList)rj  r  r  r  r0   rD   r  rk  r  r  r  r  'privateMixPostV2MixOrderBatchPlaceOrder0privateMarginPostV2MarginIsolatedBatchPlaceOrder/privateMarginPostV2MarginCrossedBatchPlaceOrder%privateSpotPostV2SpotTradeBatchOrdersr  parse_orders)r  r
  r  ordersRequestsr  r  r  rawOrderr9  r  r  r  r  orderParamsmarginResultcurrentMarginModeorderRequestr  rq  r  r  r  r  failure	orderInfoboths                             r  create_orderszbitget.create_orders;  s    	
q#f+& 	0AayH''(;H~!X%$TWW/l%lmm##Hf5D##Hf5D__Xx8FOOHg6E//(HbAK==nkZL ,Q ,%!2J!%66(  4I  *I  J  J44XtT6SXZefL!!,/-	0. V$Tl'
 6Nx 0!$
.8G.C	*$5GL!$*:$6GL!K"&"E"Eff"UK%0GM"CCGLH:%LLWUH7"KKGTHAA'JH0 x4//$r:OOD-<	  G4  v..r  rD   c                 :   | j                          | j                  |      }d|i}	|dk(  }
| j                  |dd      }|du}| j                  |d      }|du}| j                  |d      }|du}| j                  |d      }| j                  |d	      }|du}|du}| j	                  |d
| j                  |            }| j                  |dd      }|du}| j                  ||||      dkD  rt        | j                  dz         | j                  |dd      }|||	d<   | j                  |g d      }d}|d   r|t        | j                  dz         | j                  | j                  dd      }|r~|
r||dk(  rw|t        | j                  dz         | j                  |      }| j                  |      }| j                  t!        j"                  ||            }| j%                  ||      |	d<   n| j'                  ||      |	d<   ||	d<   | j%                  ||      |	d<   | j%                  ||      |	d<   | j)                  | j+                  |	|            }n"|d   s&|d   s!t        | j                  dz   |d   z   dz         |d    |	d!<   d}| j-                  ||      \  }}||	d"<   |s0|s.| j'                  ||      |	d#<   ||s| j%                  ||      |	d$<   |rY|
st/        | j                  d%z         || j%                  ||      |	d&<   ||	d<   | j1                  | j+                  |	|            }nF|s|r|d'   |	d(<   | j'                  ||      |	d<   || j%                  ||      |	d<   |r| j%                  ||      |	d<   n|r| j%                  ||      |	d<   | j3                  | j+                  |	|            }n|r	| j%                  ||      |	d&<   |rg| j5                  |dd      }| j%                  ||      |	d)<   | j7                  |d*      } | j%                  ||       |	d+<   | j	                  |dd,      }!|!|	d-<   |rg| j5                  |dd      }"| j%                  ||"      |	d.<   | j7                  |d*      }#| j%                  ||#      |	d/<   | j	                  |dd,      }$|$|	d0<   | j1                  | j+                  |	|            }n| j9                         }%| j                  |d1d2|%      }&| j                  |d2      }|&|	d1<   |r(| j                  |dd      }| j%                  ||      |	d3<   |r(| j                  |dd      }"| j%                  ||"      |	d4<   | j;                  | j+                  |	|            }| j=                  |d5i       }'| j?                  |'|      S )6a
  
        edit a trade order

        https://www.bitget.com/api-doc/spot/plan/Modify-Plan-Order
        https://www.bitget.com/api-doc/contract/trade/Modify-Order
        https://www.bitget.com/api-doc/contract/plan/Modify-Tpsl-Order
        https://www.bitget.com/api-doc/contract/plan/Modify-Plan-Order

        :param str id: cancel 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 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 float [params.triggerPrice]: the price that a trigger order is triggered at
        :param float [params.stopLossPrice]: *swap only* The price at which a stop loss order is triggered at
        :param float [params.takeProfitPrice]: *swap only* The price at which a take profit order is triggered at
        :param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered(perpetual swap markets only)
        :param float [params.takeProfit.triggerPrice]: *swap only* take profit trigger price
        :param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered(perpetual swap markets only)
        :param float [params.stopLoss.triggerPrice]: *swap only* stop loss trigger price
        :param float [params.stopLoss.price]: *swap only* the execution price for a stop loss attached to a trigger order
        :param float [params.takeProfit.price]: *swap only* the execution price for a take profit attached to a trigger order
        :param str [params.stopLoss.type]: *swap only* the type for a stop loss attached to a trigger order, 'fill_price', 'index_price' or 'mark_price', default is 'mark_price'
        :param str [params.takeProfit.type]: *swap only* the type for a take profit attached to a trigger order, 'fill_price', 'index_price' or 'mark_price', default is 'mark_price'
        :param str [params.trailingPercent]: *swap and future only* the percent to trail away from the current market price, rate can not be greater than 10
        :param str [params.trailingTriggerPrice]: *swap and future only* the price to trigger a trailing stop order, default uses the price argument
        :param str [params.newTriggerType]: *swap and future only* 'fill_price', 'mark_price' or 'index_price'
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  r  r  Nr  r  r  r  r  r  newCallbackRatior   zi editOrder() params can only contain one of triggerPrice, stopLossPrice, takeProfitPrice, trailingPercentr  r  )	r  r  r  r  r  r  r  r  r  rQ   z3 editOrder() only supports plan/trigger spot orderseditMarketBuyOrderRequiresPriceTr  a    editOrder() requires price argument for market buy orders on spot markets to calculate the total amount to spend(amount * price), alternatively set the editMarketBuyOrderRequiresPrice option to False and pass in the cost to spend into the amount parameterr  r  r  rS   rT   z editOrder() does not support r  r  rD   r  r  newSizenewPricez9 editOrder() bitget trailing orders must be market ordersnewTriggerPricer  rm  newStopLossTriggerPricer  newStopLossExecutePricer  newStopLossTriggerTypenewSurplusTriggerPricenewStopSurplusExecutePricenewStopSurplusTriggerTypenewClientOidnewClientOrderIdnewPresetStopLossPricenewPresetStopSurplusPricer  ) rj  r  r  r  r  r  r6  rE  r+   rD   r  r6   r  r  r4   r  r?   r  r  r  )privateSpotPostV2SpotTradeModifyPlanOrderr  r  r0   'privateMixPostV2MixOrderModifyPlanOrder'privateMixPostV2MixOrderModifyTpslOrderr8  r7  uuid#privateMixPostV2MixOrderModifyOrderr  r  )(r  rD   r  r  r  r  r  r  r  rq  r  r  r  r  isStopLossOrderr  isTakeProfitOrderr  r  r  r  r  r  r  r  r  r   rL  rJ  r#  r  r   r  r  r  r  r  defaultNewClientOrderIdr+  r  s(                                           r  
edit_orderzbitget.edit_order  sa   @ 	V$r
 (((nM%T1@'t3//&2CD+47??6:6__V\:
T)
!-#//8NPTPePefkPlm,,V5FHZ[!0!<88NO5FH^_bcc  +V  !V  W  W**6;P$#0GK 6  $z  {&>#"477-b#bcc.2nnT\\Klnr.s+.=dem=&tww  2t  (t  u  u#'#8#8#@L"&"7"7">K,,W-?-?k-Z[D&*&=&=fd&KGFO"&":":66"J#'GK &*&=&=fl&SGN#&*&=&=fe&LGN#EEdkkRY[aFbcH6NVH-="477-M#MPVW]P^#^aj#jkk &tGHK"&"E"Eff"UK%0GM"$_%)%=%=ff%M	"%/E*.*A*A&%*PGJ'%$$TWW/j%jkk'3151H1HQe1fG-..=*+GGT[]cHde"o(.z(:%"&":":66"J$.2.E.Efe.TGN+".2.E.Efm.\GN+&.2.E.Efo.^GN+GGT[]cHde-1-D-DV\-Z)*%)%7%7.R]%^N9=9P9PQWYg9hG56"..xAG9=9P9PQWY`9aG56!--hMF8>G45%)%7%7
NT_%`N8<8O8OPVXf8gG45"..z7CG<@<S<STZ\c<dG89!--j&,OF;AG78GGT[]cHde*.))+'#'#5#5fnN`by#z 6+=>*:'%)%6%6xQ\%]N8<8O8OPVXf8gG45%)%6%6z>S^%_N;?;R;RSY[i;jG78CCDKKPWY_D`a ~~h3f--r  c                    |t        | j                  dz         | j                          | j                  |      }d}d}| j	                  d|      \  }}i }| j                  |d      }| j                  |dd      }	| j                  |g d      }|d   r|	s|d	   |d
<   |d   s|d   r|	s||d<   |d   s|d   rd}
| j                  ||      \  }
}|
|d<   |	s|rg }d|i}|j                  |       ||d<   |r;| j                  |dd      }||d<   | j                  | j                  ||            }n|	r"| j                  | j                  ||            }n| j                  | j                  ||            }n|d   r|N|dk(  r"| j                  | j                  ||            }n|dk(  r| j                  | j                  ||            }ng|	r"| j!                  | j                  ||            }nC| j#                  | j                  ||            }n!t%        | j                  dz   |d   z   dz         | j                  |di       }d}|d   s|d   r|	r| j                  |dg       }|d   }n|}| j'                  ||      S )a  
        cancels an open order

        https://www.bitget.com/api-doc/spot/trade/Cancel-Order
        https://www.bitget.com/api-doc/spot/plan/Cancel-Plan-Order
        https://www.bitget.com/api-doc/contract/trade/Cancel-Order
        https://www.bitget.com/api-doc/contract/plan/Cancel-Plan-Order
        https://www.bitget.com/api-doc/margin/cross/trade/Cross-Cancel-Order
        https://www.bitget.com/api-doc/margin/isolated/trade/Isolated-Cancel-Order

        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'isolated' or 'cross' for spot margin trading
        :param boolean [params.trigger]: set to True for canceling trigger orders
        :param str [params.planType]: *swap only* either profit_plan, loss_plan, normal_plan, pos_profit, pos_loss, moving_plan or track_plan
        :param boolean [params.trailing]: set to True if you want to cancel a trailing order
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz) cancelOrder() requires a symbol argumentrZ   r  stopr  r8  r  r  rQ   rD   r  rS   rT   r  r  orderIdListr  r  r  r  z  cancelOrder() does not support r  r  r  r  r   )r/   rD   rj  r  rk  r  r  r  r  r  r  'privateMixPostV2MixOrderCancelPlanOrderr  #privateMixPostV2MixOrderCancelOrder,privateMarginPostV2MarginIsolatedCancelOrder+privateMarginPostV2MarginCrossedCancelOrder)privateSpotPostV2SpotTradeCancelPlanOrder%privateSpotPostV2SpotTradeCancelOrderr6   r  )r  rD   r  r  r  r  r  rq  r  r  r  r:  r  r  r  r  r  s                    r  cancel_orderzbitget.cancel_order)  s   ( >#DGG.Y$YZZV$
!??vV
F??6:6##FFI>6#BCv7 &tGH6(#3!#GI6Nx 0K"&"E"Eff"UK%0GM"( r! ""7+)4&++FJM&.
#GGT[]cHdeGGT[]cHdeCCDKKPWY_D`aF^%+#PPQUQ\Q\]dflQmnH7*#OOPTP[P[\cekPlmH#MMdkkZaciNjkH#II$++V]_eJfgHtww)KKfU[n\_hhiiT x46NfX.GmR@IaLEEv..r  c                    |t        | j                  dz         | j                          | j                  |      }d}| j	                  d|      \  }}| j                  |dd      }| j                  |ddg      }g }t        dt        |            D ]  }||   }	d|	i}
|j                  |
        d|d	   i}|d
   r|||d<   n||d<   d}|d
   rm|I|dk(  r"| j                  | j                  ||            }n| j                  | j                  ||            }n| j                  | j                  ||            }nad}| j                  ||      \  }}||d<   |r"| j                  | j                  ||            }n!| j!                  | j                  ||            }| j#                  |di       }| j%                  |dg       }| j'                  ||      S )a  
        cancel multiple orders

        https://www.bitget.com/api-doc/spot/trade/Batch-Cancel-Orders
        https://www.bitget.com/api-doc/contract/trade/Batch-Cancel-Orders
        https://www.bitget.com/api-doc/contract/plan/Cancel-Plan-Order
        https://www.bitget.com/api-doc/margin/cross/trade/Cross-Batch-Cancel-Order
        https://www.bitget.com/api-doc/margin/isolated/trade/Isolated-Batch-Cancel-Orders

        :param str[] ids: order ids
        :param str symbol: unified market symbol, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'isolated' or 'cross' for spot margin trading
        :param boolean [params.trigger]: *contract only* set to True for canceling trigger orders
        :returns dict: an array of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz* cancelOrders() requires a symbol argumentr[   r8  r  r   r  r  rD   rQ   r  r:  r  r  r  r  )r/   rD   rj  r  rk  r  r  r  r  r  0privateMarginPostV2MarginCrossedBatchCancelOrderr  1privateMarginPostV2MarginIsolatedBatchCancelOrder*privateSpotPostV2SpotTradeBatchCancelOrderr  r;  )privateMixPostV2MixOrderBatchCancelOrdersr  r  r  )r  idsr  r  r  r  r  r:  r  individualIdr  rq  r  r  r  r
  s                   r  cancel_orderszbitget.cancel_orders  s	   " >#DGG.Z$Z[[V$
!??PVW
F##FFI>6FI#67q#c(# 	(Aq6L<G w'	( fTl
 &>z1#.GK %0GM"&>%(#TTUYU`U`ahjpUqrH#UUVZVaVabikqVrsHJJ4;;W^`fKghK"&"E"Eff"UK%0GM"GGT[]cHdeII$++V]_eJfg" x4mR8  00r  c           	         |t        | j                  dz         | j                          | j                  |      }d}| j	                  d|      \  }}d|d   i}| j                  |dd      }| j                  |ddg      }d}|d   r|K|d	k(  r#| j                  | j                  ||            }n?| j                  | j                  ||            }n|r*d
|d   gi}| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |d      }	| j                  |d      }
| j                  |
d      }| j                  || j!                  |ddd      |	| j#                  |	      d      gS d}| j%                  ||      \  }}||d<   |r"| j'                  | j                  ||            }n!| j)                  | j                  ||            }| j                  |d      }| j+                  |dd      }| j+                  |dd      }| j-                  ||      }| j/                  |      S )aP  
        cancel all open orders

        https://www.bitget.com/api-doc/spot/trade/Cancel-Symbol-Orders
        https://www.bitget.com/api-doc/spot/plan/Batch-Cancel-Plan-Order
        https://www.bitget.com/api-doc/contract/trade/Batch-Cancel-Orders
        https://bitgetlimited.github.io/apidoc/en/margin/#isolated-batch-cancel-orders
        https://bitgetlimited.github.io/apidoc/en/margin/#cross-batch-cancel-order

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'isolated' or 'cross' for spot margin trading
        :param boolean [params.trigger]: *contract only* set to True for canceling trigger orders
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz- cancelAllOrders() requires a symbol argumentrY   r  rD   r8  r  rQ   r  
symbolListrequestTimer  )r-  r  r  r  r  
resultListr  r  r  )r/   rD   rj  r  rk  safe_bool_2r  3privateMarginPostMarginV1CrossOrderBatchCancelOrderr  6privateMarginPostMarginV1IsolatedOrderBatchCancelOrder.privateSpotPostV2SpotTradeBatchCancelPlanOrder+privateSpotPostV2SpotTradeCancelSymbolOrderr  r  r  r  r  r1  r  r;  rF  safe_list_2r  r  )r  r  r  r  r  rq  r  r  stopRequestr  responseDatar9  r  r  rM  r  responseLists                    r  cancel_all_orderszbitget.cancel_all_orders  s}     >#DGG.]$]^^V$
!??@QSYZ
FfTl
 ""669=6FI#67&>%(#WWX\XcXcdkmsXtuH#ZZ[_[f[fgnpv[wxH$ $vd|n)K  $RRSWS^S^_jlrSstH#OOPTP[P[\cekPlmH !--hF	#~~h?++L(COO ("&"2"28T4"P%.$(LL$;	%   K"&"E"Eff"UK%0GM"GGT[]cHdeII$++V]_eJfg ~~h/%%dL-H
&&tYF(([A  ..r  c                    |t        | j                  dz         | j                          | j                  |      }d|i}d}|d   r"| j	                  | j                  ||            }nq|d   s|d   rF|d   |d<   d}| j                  ||      \  }}||d	<   | j                  | j                  ||            }n!t        | j                  d
z   |d   z   dz         t        |t              rt        j                  |      }| j                  |d      }|"t        |t              s| j                  ||      S | j!                  |dg       }	| j                  |	di       }
| j                  |
|      S )a  
        fetches information on an order made by the user

        https://www.bitget.com/api-doc/spot/trade/Get-Order-Info
        https://www.bitget.com/api-doc/contract/trade/Get-Order-Details

        :param str id: the order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz( fetchOrder() requires a symbol argumentr  rQ   rS   rT   rD   r  r  z fetchOrder() does not support r  r  r  r   )r/   rD   rj  r  "privateSpotGetV2SpotTradeOrderInfor  r  privateMixGetV2MixOrderDetailr6   
isinstancer5  r  r  r  r  r  r  )r  rD   r  r  r  rq  r  r  r  dataListfirsts              r  fetch_orderzbitget.fetch_orderU  su    >#DGG.X$XYYV$r
 &>>>t{{7TZ?[\HF^vh/ &tGHK"&"E"Eff"UK%0GM"99$++gv:VWHtww)JJVTZ^[^gghhH h$zz(+H~~h/dD)''f55>>(FB7xB/v..r  c           	      J   | j                          d}d}i }d}| j                  d|      \  }}|V| j                  |      }|d   |d<   | j                  | j                  ddd      }	d|v r|d   n|	}
| j                  |d|
      }n1| j                  | j                  ddd      }	| j                  |d|	      }d}| j                  |dd	      \  }}|r%d}|dk(  r|d
}nd}| j                  d|||||d      S d}| j                  |d      }| j                  |dd      }| j                  |d      du}|xs |}| j                  |g d      }| j                  d||      \  }}|||d<   |||d<   |dk(  s|dk(  s|,| j                  |dd      }| j                  |d      }|||d<   d}| j                  |dg      }|dk(  r|j|| j                         dz
  }||d<   |dk(  r#| j                  | j                  ||            }n#|dk(  r| j                  | j                  ||            }n|r"| j!                  | j                  ||            }n| j#                  | j                  ||            }nd}| j%                  ||      \  }}||d<   |r:| j                  |dd      }||d<   | j'                  | j                  ||            }n]|r:| j                  |dd      }||d<   | j'                  | j                  ||            }n!| j)                  | j                  ||            }| j+                  |d      }|dk(  r+||rN| j-                  |d g       }| j/                  ||||      S | j-                  |d!g       }| j/                  ||||      S | j/                  ||||      S )"a  
        fetch all unfilled currently open orders

        https://www.bitget.com/api-doc/spot/trade/Get-Unfilled-Orders
        https://www.bitget.com/api-doc/spot/plan/Get-Current-Plan-Order
        https://www.bitget.com/api-doc/contract/trade/Get-Orders-Pending
        https://www.bitget.com/api-doc/contract/plan/get-orders-plan-pending
        https://www.bitget.com/api-doc/margin/cross/trade/Get-Cross-Open-Orders
        https://www.bitget.com/api-doc/margin/isolated/trade/Isolated-Open-Orders

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of open order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch orders for
        :param str [params.planType]: *contract stop only* 'normal_plan': average trigger order, 'profit_loss': opened tp/sl orders, 'track_plan': trailing stop order, default is 'normal_plan'
        :param boolean [params.trigger]: set to True for fetching trigger orders
        :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)
        :param str [params.isPlan]: *swap only* 'plan' for stop orders and 'profit_loss' for tp/sl orders, default is 'plan'
        :param boolean [params.trailing]: set to True if you want to fetch trailing orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   rD   r  r  rQ   r  Fr  minIdendIdr  r  r8  r  r  r9  r  r  r  rS   rT   r  r  r  r  r  r  r  r  r  r  entrustedList)rj  rk  r  r6  r  r  r  r  r  rN  r  r  r  *privateMarginGetV2MarginIsolatedOpenOrdersr  )privateMarginGetV2MarginCrossedOpenOrders)privateSpotGetV2SpotTradeCurrentPlanOrder'privateSpotGetV2SpotTradeUnfilledOrdersr  (privateMixGetV2MixOrderOrdersPlanPending$privateMixGetV2MixOrderOrdersPendingr  r  r  )r  r  r  r  r  r  r  rq  r  r  r3  r  cursorReceivedr  r  r  planTypeDefined	isTriggerr  queryr  r  r  rM  r  s                            r  fetch_open_orderszbitget.fetch_open_orders  s-   . 	
!??@QSYZ
F[[(F &tGH,,T\\;Lm]cdK,2f,<;J##FFJ?D,,T\\;Lm]cdK##FFK@D88ART^_&!Nv~)%,N!(334EvuV[]ces  vB  C  C>>&*5""669=**6:>dJ/	6#BC229gvN#(GK $GGFN 0j6L ..v{OTMYYv7F('4$		&6(+6>%= --/*<E+0GK(+#NNt{{[bdiOjkH7*#MMdkkZachNijH#MMdkkZachNijH#KKDKKX_afLghHK!%!D!DVU!SK%0GM"++FJM&.
#HHU\^cIde++E:}M&.
#HHU\^cIdeDDT[[QXZ_E`a` x06>&7!^^D+rB
((VUEJJ^^D/2>F$$VVUEBB  vue<<r  c                 p    | j                          | j                  ||||      }| j                  |dd      S )a  
        fetches information on multiple closed orders made by the user

        https://www.bitget.com/api-doc/spot/trade/Get-History-Orders
        https://www.bitget.com/api-doc/spot/plan/Get-History-Plan-Order
        https://www.bitget.com/api-doc/contract/trade/Get-Orders-History
        https://www.bitget.com/api-doc/contract/plan/orders-plan-history
        https://www.bitget.com/api-doc/margin/cross/trade/Get-Cross-Order-History
        https://www.bitget.com/api-doc/margin/isolated/trade/Get-Isolated-Order-History

        :param str symbol: unified market symbol of the closed orders
        :param int [since]: timestamp in ms of the earliest order
        :param int [limit]: the max number of closed orders to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch orders for
        :param str [params.planType]: *contract stop only* 'normal_plan': average trigger order, 'profit_loss': opened tp/sl orders, 'track_plan': trailing stop order, default is 'normal_plan'
        :param boolean [params.trigger]: set to True for fetching trigger orders
        :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)
        :param str [params.isPlan]: *swap only* 'plan' for stop orders and 'profit_loss' for tp/sl orders, default is 'plan'
        :param boolean [params.trailing]: set to True if you want to fetch trailing orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  rj   fetch_canceled_and_closed_orders	filter_byr  r  r  r  r  r
  s         r  fetch_closed_orderszbitget.fetch_closed_orders  s9    . 	66vueVT~~fh99r  c                 p    | j                          | j                  ||||      }| j                  |dd      S )a  
        fetches information on multiple canceled orders made by the user

        https://www.bitget.com/api-doc/spot/trade/Get-History-Orders
        https://www.bitget.com/api-doc/spot/plan/Get-History-Plan-Order
        https://www.bitget.com/api-doc/contract/trade/Get-Orders-History
        https://www.bitget.com/api-doc/contract/plan/orders-plan-history
        https://www.bitget.com/api-doc/margin/cross/trade/Get-Cross-Order-History
        https://www.bitget.com/api-doc/margin/isolated/trade/Get-Isolated-Order-History

        :param str symbol: unified market symbol of the canceled orders
        :param int [since]: timestamp in ms of the earliest order
        :param int [limit]: the max number of canceled orders to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch orders for
        :param str [params.planType]: *contract stop only* 'normal_plan': average trigger order, 'profit_loss': opened tp/sl orders, 'track_plan': trailing stop order, default is 'normal_plan'
        :param boolean [params.trigger]: set to True for fetching trigger orders
        :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)
        :param str [params.isPlan]: *swap only* 'plan' for stop orders and 'profit_loss' for tp/sl orders, default is 'plan'
        :param boolean [params.trailing]: set to True if you want to fetch trailing orders
        :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  ro  rr  s         r  fetch_canceled_orderszbitget.fetch_canceled_orders  s9    . 	66vueVT~~fh
;;r  c           	         | j                          d}i }|| j                  |      }|d   |d<   d}| j                  d||      \  }}d}| j                  d|      \  }}d}	| j	                  |dd      \  }	}|	r%d}
|dk(  r|d}
nd	}
| j                  d|||||
d
      S d}| j                  |d      }| j                  |dd      }| j                  |g d      }| j                  d||      \  }}|||d<   |||d<   |dk(  s|dk(  s|,| j                  |dd      }| j                  |d      }|||d<   | j                         }|dk(  r|]|
|dz
  }||d<   |dk(  r#| j                  | j                  ||            }n|dk(  r| j                  | j                  ||            }ne|rv|t        | j                   dz         | j#                  |ddg      }| j                  |dg      }|
|dz
  }||d<   |||d<   | j%                  | j                  ||            }n| j'                  | j                  ||            }nd}| j)                  ||      \  }}||d<   | j+                  |d      du}|r:| j+                  |dd      }||d<   | j-                  | j                  ||            }n_|s|r:| j+                  |dd      }||d<   | j-                  | j                  ||            }n!| j/                  | j                  ||            }| j1                  |di       }|dk(  r)||rJ| j3                  | j1                  |d g       |||      S | j3                  | j1                  |d!g       |||      S t5        |t6              rt9        j:                  |      }| j=                  |dg       }| j3                  ||||      S )"a  

        https://www.bitget.com/api-doc/spot/trade/Get-History-Orders
        https://www.bitget.com/api-doc/spot/plan/Get-History-Plan-Order
        https://www.bitget.com/api-doc/contract/trade/Get-Orders-History
        https://www.bitget.com/api-doc/contract/plan/orders-plan-history
        https://www.bitget.com/api-doc/margin/cross/trade/Get-Cross-Order-History
        https://www.bitget.com/api-doc/margin/isolated/trade/Get-Isolated-Order-History

        fetches information on multiple canceled and closed orders made by the user
        :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 int [params.until]: the latest time in ms to fetch orders for
        :param str [params.planType]: *contract stop only* 'normal_plan': average trigger order, 'profit_loss': opened tp/sl orders, 'track_plan': trailing stop order, default is 'normal_plan'
        :param boolean [params.trigger]: set to True for fetching trigger orders
        :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)
        :param str [params.isPlan]: *swap only* 'plan' for stop orders and 'profit_loss' for tp/sl orders, default is 'plan'
        :param boolean [params.trailing]: set to True if you want to fetch trailing orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        NrD   r  rv   Fr  rQ   r`  ra  r  r  r8  r  r9  r  r  r  rS   rT   r  r  r  r  r  z: fetchCanceledAndClosedOrders() requires a symbol argumentrA  r  r  r  r  r  r  rb  )rj  r  r	  rk  r  r  r  rN  r  r  r6  r  -privateMarginGetV2MarginIsolatedHistoryOrdersr  ,privateMarginGetV2MarginCrossedHistoryOrdersr/   rD   safe_integer_n)privateSpotGetV2SpotTradeHistoryPlanOrder&privateSpotGetV2SpotTradeHistoryOrdersr  r  (privateMixGetV2MixOrderOrdersPlanHistory$privateMixGetV2MixOrderOrdersHistoryr  r  r[  r5  r  r  r  )r  r  r  r  r  r  rq  r3  r  r  ri  r  r  r  r  rR  r  r  rj  r  r  r
  s                         r  rp  z'bitget.fetch_canceled_and_closed_orders  s`   . 	[[(F &tGH
!??@^`fhno
F
!??@^`fg
F88A_akl&!NV#)%,N!(334RTZ\achjp  sA  CO  P  P>>&*5""669=6#BC229gvN#(GK $GG& jH&<*BX ..v{OTMYYv7F('4$!%=*,E+0GK(+#QQRVR]R]^egmRnoH7*#PPQUQ\Q\]dflQmnH>+DGG6r,rss--fy'6JK6G95=*,E+0GK(?),GI&II$++V]_eJfgFFt{{SZ\bGcdK"&"E"Eff"UK%0GM""..vzB$NO++FJM&.
#HHU\^dIefO++FJN&.
#HHU\^dIefDDT[[QXZ`Eabf x4&7(({B)OQWY^`eff$$T__T?B%OQWY^`effh$zz(+H&"5  >>r  c           	      L   | j                          | j                  |d      }| j                  |d      }d}|| j                  |      }d}| j	                  d||      \  }}d}| j                  |dd      \  }}|r d}	|dk7  rd}	| j                  d|||||	d      S d}
i }|| j                  |      }
|
d	   |d
<   | j                  d||      \  }}|||d<   |||d<   d}|dk(  r"| j                  | j                  ||            }nG||d	   |d<   d}| j                  ||      \  }}||d<   | j                  | j                  ||            }| j                  |d      }|dk(  s|dk(  r'| j                  |dg       }| j                  ||
||      S | j                  ||
||      S )a  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

        https://www.bitget.com/api-doc/spot/account/Get-Account-Bills
        https://www.bitget.com/api-doc/contract/account/Get-Account-Bill

        :param str [code]: unified currency code, default is None
        :param int [since]: timestamp in ms of the earliest ledger entry, default is None
        :param int [limit]: max number of ledger entries to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: end time in ms
        :param str [params.symbol]: *contract only* unified market symbol
        :param str [params.productType]: *contract only* 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES'
        :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>`
        r  Nr   Fr  rQ   ra  r  rD   rO  r  r  r  r  r  rS   rT   bills)rj  r  r  r  r	  r  r  rn  r   privateSpotGetV2SpotAccountBillsr  r  privateMixGetV2MixAccountBillr  parse_ledger)r  r`  r  r  r  r  r  r3  r  ri  rn  rq  r  r  r  r  s                   r  fetch_ledgerzbitget.fetch_ledger+  s   " 	!!&(368,[[(F
!??vW]^
F88PZ[&!NV#!(33M65RWY_aoq}~~}}T*H&tnGFO229gvN#(GK $GG<<T[[RX=YZH!$*4L!K"&"E"Eff"UK%0GM"99$++gv:VWHZ x0& jH&<OOD'26E$$UHeUCC  x>>r  r  c                 @   | j                  |d      }| j                  ||      }| j                  ||      }| j                  |d      }| j	                  |d      }| j                  |dd      }| j                  |dd      }| j                  t        j                  |            }	d}
|j                  d	      d
k\  rd}
| j                  || j                  |d      || j                  |      |
d d d | j                  | j                  |d            ||	d |d ||dd|      S )NrO  r  r~  r   r[  r  r  inr  r   outbillIdr.  r  )r-  rD   r  r  	directionr{  referenceIdreferenceAccountr  rn  r  beforeafterr  r[  )r  r.  safe_currencyr  r7  r8  r6  r  r?   r  findsafe_ledger_entryr1  parse_ledger_type)r  r  rn  r  r`  r  r  r[  	amountRawr  r  s              r  parse_ledger_entryzbitget.parse_ledger_entry  s<   8 %%dF3
&&z8<%%j(;%%dG4	  y1  vu5&&tVX>	""7#5#5i#@A	>>#!#I%%""42"Y/" $**4+;+;D.+QR '
& ' 	r  c                    i ddddddddddddddd	dd
dddddddddddddddddi ddddddddddddddddddd dd!dd"dd#d$d%d$d&d'd(d'd)d'ddd*d+ddd,}| j                  |||      S )-Ntrans_to_crossr   trans_from_crosstrans_to_exchangetrans_from_exchangetrans_to_isolatedtrans_from_isolatedtrans_to_contracttrans_from_contracttrans_to_otctrans_from_otc	open_longr  
close_long
open_shortclose_shortforce_close_longforce_close_shortburst_long_loss_queryburst_short_loss_query	force_buy
force_sell	burst_buy
burst_selldelivery_long
settlementdelivery_shortcontract_settle_feer[  append_marginr  adjust_down_lever_append_marginreduce_marginauto_append_margincash_gift_issuecashbackcash_gift_recyclebonus_issuerebatebonus_recyclebonus_expiredrT  r  )transfer_intransfer_outrT  r   r  r  r  )r  r  r  s      r  r  zbitget.parse_ledger_type  s   )
j)

)
  )
 ":	)

  )
 ":)
  )
 ":)
 J)
 j)
 )
 ')
 ')
 7)
 )
   !)
" $W#)
$ %g%)
& ')
( '))
* +)
, '-)
. \/)
0 l1)
2 "53)
4 ]5)
6 .}7)
8 ]9)
: !-;)
< z=)
>  ?)
@ 8A)
B XC)
D XE)
F && $Q)
T tT22r  c           	         |t        | j                  dz         | j                          | j                  |      }d}| j	                  d|      \  }}d}| j                  |dd      \  }}|r%d}|d   r|d}nd}| j                  d|||||d	      S d}	d
|d   i}
| j                  d|
|      \  }
}|||
d<   |||
d<   |d   r|f|| j                         dz
  |
d<   |dk(  r"| j                  | j                  |
|            }	n|dk(  r| j                  | j                  |
|            }	n_| j                  | j                  |
|            }	n=d}| j                  ||      \  }}||
d<   | j                  | j                  |
|            }	| j                  |	d      }|d   s|d   r'| j!                  |dg       }| j#                  ||||      S |'| j!                  |dg       }| j#                  ||||      S | j#                  ||||      S )a(  
        fetch all trades made by the user

        https://www.bitget.com/api-doc/spot/trade/Get-Fills
        https://www.bitget.com/api-doc/contract/trade/Get-Order-Fills
        https://www.bitget.com/api-doc/margin/cross/trade/Get-Cross-Order-Fills
        https://www.bitget.com/api-doc/margin/isolated/trade/Get-Isolated-Transaction-Details

        :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 int [params.until]: the latest time in ms to fetch trades for
        :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 Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nz+ fetchMyTrades() requires a symbol argumentr   Fr  rQ   r`  ra  r  r  rD   r  r  r  r  r  r  r  r  rS   rT   fillListfills)r/   rD   rj  r  rk  r  r  r  r  %privateMarginGetV2MarginIsolatedFillsr  $privateMarginGetV2MarginCrossedFillsprivateSpotGetV2SpotTradeFillsr  privateMixGetV2MixOrderFillsr  r  r%  )r  r  r  r  r  r  r  r  ri  r  rq  r  r  r  r  s                  r  fetch_my_tradeszbitget.fetch_my_trades  sj   " >#DGG.[$[\\V$
!??QWX
F88R\]&!Nf~)%,N!(33OVUTY[acqs  A  AfTl
 229gvN#(GK $GG&>%=+/+<+<+>+KGK(+#II$++V]_eJfgH7*#HHU\^dIefH>>t{{7TZ?[\K"&"E"Eff"UK%0GM"88Wf9UVHH x06Nx 0~~dJ;H$$XvueDD#NN4"5E$$UFE5AA  vue<<r  c                 <   | j                          | j                  |      }d}| j                  ||      \  }}|d   |d   |d}| j                  | j	                  ||            }| j                  |dg       }| j                  |di       }| j                  ||      S )a  
        fetch data on a single open contract trade position

        https://www.bitget.com/api-doc/contract/position/get-single-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>`
        NrD   r  r  rm  r  r  r   )rj  r  r  (privateMixGetV2MixPositionSinglePositionr  r  r  parse_position	r  r  r  r  r  rq  r  r  r]  s	            r  fetch_positionzbitget.fetch_position  s     	V$"AA&&QVTl ,&

 @@WV\A]^> ~~h3tQ+""5&11r  c           	      (   | j                          d}| j                  |dd      \  }}|r| j                  dddd|dd      S d}| j                  |dd      }|rd}n| j                  |dd	d
      \  }}d}|#| j	                  |d      }| j                  |      }d}| j                  ||      \  }}d|i}	d}
d}|d
k(  r| j	                  |dd      }||d   }nD|dk(  rd}n<|dk(  rd}n4|dk(  rd}n,|dk(  rd}n$|dk(  s|dk(  r|t        | j                  dz         ||	d<   | j                  | j                  |	|            }
n-d}||d   |	d<   | j                  | j                  |	|            }
g }|s| j                  |
dg       }n&| j                  |
di       }| j                  |dg       }g }t        dt        |            D ]&  }|j!                  | j#                  ||   |             ( | j%                  |      }| j'                  |d|d      S )a  
        fetch all open positions

        https://www.bitget.com/api-doc/contract/position/get-all-position
        https://www.bitget.com/api-doc/contract/position/Get-History-Position

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginCoin]: the settle currency of the positions, needs to match the productType
        :param str [params.productType]: 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES'
        :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)
        :param boolean [params.useHistoryEndpoint]: default False, when True  will use the historic endpoint to fetch positions
        :param str [params.method]: either(default) 'privateMixGetV2MixPositionAllPosition' or 'privateMixGetV2MixPositionHistoryPosition'
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Fr   r  Nra  r  r=  )privateMixGetV2MixPositionHistoryPositionr  rr  r   r  rm  r  r  r  r  r  r  r  r  r  r  r  zN fetchPositions() requires a marginCoin parameter that matches the productTypeTrD   r  r  r  )rj  r  r  r  r  r  r  r/   rD   rr  r  r  r  r  r  r  r  r  market_symbolsfilter_by_array_positions)r  r  r  r  r  r=  r  r]  r  rq  r  	isHistoryrm  positionr  r  r  s                    r  fetch_positionszbitget.fetch_positions  s     	88AQS]^&334DdDRVX^`giuvv!^^F4H%P@F!::6CSU]  `G  HNFF$$Wa0E[['F"AA&&QV;
 	<<))&,GJ"#J/
.#
.#
/$
/$
0k^6S%+DGG  7G  -G  H  H$.GL!AA$++gW]B^_HI!$*4L!EEdkkRY[aFbcH~ ~~h;H>>(FB7D~~dFB7Hq#h-( 	DAMM$--hqk6BC	D%%g.--fhOOr  r  c                 	   | j                  |d      }| j                  ||d d      }|d   }| j                  |dd      }| j                  |d      }d }d }| j                  |d      }	| j                  |d      }
|dk(  rt        j                  |
|	      }n	|d	k(  rd
}|
}| j                  |d      }d }|dk(  rd}n|dk(  rd}| j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |d      }| j                  |dd      }| j                  |d      }t        j                  ||      }|t        j                  ||      }| j                  t        j                  ||            }|| j                  |d      }| j                  |d      }t        j                  ||      }t        j                  ||      }| j                  | j                  | j                  |d                  }d}d}||dk(  rt        j                  |d      rt        j                  |
|      }|}|dk(  r*t        j                  |      }t        j                  |      }t        j                  d|      }t        j                  ||      }|dk(  rt        j                  ||      }nt        j                  ||      }| j                  t        j                  ||            }t        j                  ||      } t        j                  t        j                  ||      |       }!t        j                  t        j                  |	|d       d!      }"| j!                  i d"|d#| j                  |d$      d|d%| j                  |      d|d|d&| j                  |      d'| j                  |	      d(| j                  |d)      d*| j                  |"      d+|d|d| j                  |      d,| j                  |d-      d.|d/|d0|| j#                  |      | j%                  |d1      | j                  |!      | j                  |      | j                  |      | j                  |      | j                  |      | j                  |      | j                  |d2      d d d3      S )4Nr  r  r  r  r  unrealizedPL
marginSizer  r  r  r  r  Tone_way_modeFr  r"  r%  rs  openPriceAvgopenAvgPricerz  closeTotalPosr  liquidationPricer   z0.99940r  r   r  r   r  r-  rD   r  notional
entryPriceunrealizedPnlrealizedPnlpnlr  	contracts	lastPricecloseAvgPricer  r  r  utimemarginRatio)r  r  maintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager"  r  r  r  )r  r  r  r?   r|  r  r  r6  r  
string_divr  r7  	omit_zero	string_gtr  r  safe_positionr1  r  )#r  r  r  r9  r  r  r  r  r  r  rawCollateralholdModer  r  r"  contractSizeNumberr%  
baseAmountr  r  openNotionalr  r  r  r  r  calcTakerFeeRatecalcTakerFeeMultsignedMargin	signedMmpmmrMinusOne	numerator
feeToCloser  r  s#                                      r  r  zbitget.parse_position[  s&   Z ##Hh7!!(FD*E!'''7C	%%h=

((>B((<@# ++M=IJ9$ J)M##Hi8|#F'F*5##Hj9!__V^D,,-?@%%h8
''..Q
&*&6&6xAQ&R#))*jA #..|XFM%%g&8&8\&RS	((?CI$$X{;	%%j)<")"4"4]H"M,,T^^D<L<LXWi<j-kl##$:+CIZIZ[egjIk"--mZHL3Iw&11,?#..y9	!,,S)<K**:|DIv~%00>NO#..y:JK	#001C1CI{1[\''2BC
#..w/A/AB]_g/hjtu''(:(:=-YZ([]bc
!! #
H#
$""8Y7#
 f#
 ))(3	#

 *#
  0#
 $++J7#
 T..}=#
 4++He<#
 $++J7#
 #
 .#
 **95#
 ))(OD#
 D#
  f!#
" ##
$ Y/#'#4#4Xw#G!%!2!23D!E+/+<+<=X+Y++J7!..}='+'8'89P'Q))(3++HmD!#9#
  	r  c           
         |t        | j                  dz         | j                          d}| j                  |dd      \  }}|r| j	                  d||||dd      S | j                  |      }d}| j                  ||      \  }}|d   |d	}|||d
<   | j                  | j                  ||            }	| j                  |	dg       }
g }t        dt        |
            D ]s  }|
|   }| j                  |d      }| j                  ||      }| j                  |d      }|j                  ||| j!                  |d      || j#                  |      d       u | j%                  |d      }| j'                  ||d   ||      S )aN  
        fetches historical funding rate prices

        https://www.bitget.com/api-doc/contract/market/Get-History-Funding-Rate

        :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 to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentFr   r  pageNor  rD   r  r  pageSizer  r   r  fundingTimefundingRate)r-  r  r  r  r  r  )r/   rD   rj  r   fetch_paginated_call_incrementalr  r  &publicMixGetV2MixMarketHistoryFundRater  r  r  r  r  r  r  r  r7  r1  sort_byfilter_by_symbol_since_limit)r  r  r  r  r  r  r  r  rq  r  r  ratesr  re  r9  symbolInnerr  sorteds                     r  fetch_funding_rate_historyz!bitget.fetch_funding_rate_history  s    >#DGG.e$eff88AZ\fg&889RTZ\achjprz|  A  AV$"AA&&QVTl&
 "'GJ>>t{{7TZ?[\ x4q#d)$ 	AGE''x8H**8V<K))%?ILL%#//}E& LL3 	 e[1009I5RWXXr  c                    | j                          | j                  |      }|d   st        | j                  dz         d}| j	                  ||      \  }}|d   |d}d}| j                  |ddd      \  }}d}|dk(  r"| j                  | j                  ||            }n&|d	k(  r!| j                  | j                  ||            }| j                  |d
g       }| j                  |d   |      S )aH  
        fetch the current funding rate

        https://www.bitget.com/api-doc/contract/market/Get-Current-Funding-Rate
        https://www.bitget.com/api-doc/contract/market/Get-Symbol-Next-Funding-Time

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.method]: either(default) 'publicMixGetV2MixMarketCurrentFundRate' or 'publicMixGetV2MixMarketFundingTime'
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        rS   z0 fetchFundingRate() supports swap contracts onlyNrD   r  r   r  r  "publicMixGetV2MixMarketFundingTimer  r   )rj  r  r1   rD   r  r  r  r  r  r  parse_funding_rate)	r  r  r  r  r  rq  r  r  r  s	            r  fetch_funding_ratezbitget.fetch_funding_rate=  s    	V$f~DGG&XXYY"AA&&QVTl&
 66v?QS[  ^F  G==BB4;;wX^C_`H$ ;;>>t{{7TZ?[\H ~~h3&&tAw77r  c                 Z   | j                          d}|#| j                  |d      }| j                  |      }i }d}| j                  ||      \  }}||d<   | j	                  | j                  ||            }| j                  |      }| j                  |dg       }| j                  ||      S )a  
        fetch the current funding rates for all markets

        https://www.bitget.com/api-doc/contract/market/Get-All-Symbol-Ticker

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: *contract only* 'linear', 'inverse'
        :param str [params.productType]: *contract only* 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES'
        :returns dict: a dictionary of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rates-structure>`, indexed by market symbols
        Nr   r  r  )	rj  r  r  r  r
  r  r  r  parse_funding_rates)	r  r  r  r  r  rq  r  r  r  s	            r  fetch_funding_rateszbitget.fetch_funding_rates|  s     	__Wa0F[[(F"AA&&QV!,66t{{7F7STB %%g.~~h3''g66r  c                    | j                  |d      }| j                  ||d d      }| j                  |dd      }| j                  |dd      }| j	                  |d      }| j                  |d      }| j                  |d	      }	d }
||d
z   }
i d|d|d|d	|	dd dd d|d| j                  |      d| j                  |d      d|d| j                  |      dd dd dd dd dd dd d|
iS )Nr  rS   nextFundingTime
nextUpdate
ratePeriodfundingRateIntervalr  r  r  hr-  interestRateestimatedSettlePricer  r  r  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r  r  r  r6  r  r7  r1  )r  r  r  r9  r  r  r  r  r  r  intervalStrings              r  r  zbitget.parse_funding_rate  s   r ##Hh7!!(FD&A..x9JLY%%h>ST%%h5	$$X{;	%%h=
%^N
H
f
 
 *	

 D
 #D
 
 Y/
 4++HmD
  0
 t||,<=
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 	
r  c           	      Z   | j                          |t        | j                  dz         d}| j                  |dd      \  }}|r| j	                  d||||dd      S | j                  |      }|d   st        | j                  d	z         d}| j                  ||      \  }}|d
   |d   d|d}| j                  d||      \  }}|||d<   |||d<   | j                  | j                  ||            }	| j                  |	di       }
| j                  |
dg       }| j                  ||||      S )a<  
        fetch the funding history

        https://www.bitget.com/api-doc/contract/account/Get-Account-Bill

        :param str symbol: unified market symbol
        :param int [since]: the starting timestamp in milliseconds
        :param int [limit]: the number of entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch funding history for
        :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 history structures <https://docs.ccxt.com/#/?id=funding-history-structure>`
        Nz1 fetchFundingHistory() requires a symbol argumentFr   r  ra  r  rS   z3 fetchFundingHistory() supports swap contracts onlyrD   r  r  )r  rm  r.  r  r  r  r  r  r  )rj  r/   rD   r  r  r  r1   r  r  r  r  r  parse_funding_histories)r  r  r  r  r  r  r  r  rq  r  r  r  s               r  fetch_funding_historyzbitget.fetch_funding_history  sd    	>#DGG.a$abb88AVXbc&334I6SXZ_agipr~V$f~DGG&[[\\"AA&&QVTl ,1&	
 229gvN#(GK $GG55dkk'66RS. x4w3++FFE5IIr  c           
      "   | j                  |d      }| j                  |d      }| j                  |d      }|| j                  ||d d      || j                  |      | j	                  |      | j                  |d      | j                  |d      dS )Nr  rO  r  rS   r  r  )r-  r  r  r  r`  r  rD   )r  r  r  r1  r.  r7  )r  r  r  r9  r  r  s         r  parse_funding_historyzbitget.parse_funding_historyN  s     ##Hh7%%h7
%%h8	&&xvF"Y/++J7&&x:""8X6
 	
r  c                    g }t        dt        |            D ]@  }||   }| j                  |d      }|dk7  r |j                  | j	                  ||             B | j                  |d      }	d }
||d   }
| j                  |	|
||      S )Nr   r.  r  r  r  )r  r  r  r  r#  r   r  )r  r  r  r  r  r  r  r  businessr  r  s              r  r   zbitget.parse_funding_historiesh  s    q#i.) 	HA |H''.AH00MM$44XvFG	H fk2H%F00NNr  c                    | j                          | j                  |d      }| j                  |      }d }| j                  ||      \  }}|d   |d   | j	                  ||      ||d}| j                  |d      }| j                  | j                  ||            }	| j                  | j                  |	|      | j                  |      |d      S )Nr  rD   r  )r  rm  r  r  r  )r  r  )
rj  r  r  r  r  r  #privateMixPostV2MixAccountSetMarginr  parse_margin_modificationr  )
r  r  r  r  r  r  r  r  rq  r  s
             r  modify_margin_helperzbitget.modify_margin_helperv  s    ##FJ7V$"AA&&QVTl ,..vv> &
 6:.;;DKKQW<XY {{499(FK''/N
  	r  r  c                 ^    | j                  |d      }|dk(  rdnd}||d   d dd d |d   |d d d
S )	Nr`  00000r  r  r  r  r  )
r-  r  r  r  r  rs  r`  r  r  r  r  )r  r  r  	errorCoder  s        r  r(  z bitget.parse_margin_modification  sV     $$T62	#w.XX&$8$
 	
r  c                     |dkD  rt        | j                  dz         | j                  |d      }|t        | j                  dz         | j	                  ||d|      S )a  
        remove margin from a position

        https://www.bitget.com/api-doc/contract/account/Change-Margin

        :param str symbol: unified market symbol
        :param float amount: the amount of margin to remove
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=reduce-margin-structure>`
        r   z9 reduceMargin() amount parameter must be a negative valuer  zC reduceMargin() requires a holdSide parameter, either long or shortr4  )r0   rD   r  r/   r)  r  r  r  r  r  s        r  r  zbitget.reduce_margin  sd     A:TWW'bbcc##FJ7#DGG.s$stt((6JJr  c                     | j                  |d      }|t        | j                  dz         | j                  ||d|      S )a  
        add margin

        https://www.bitget.com/api-doc/contract/account/Change-Margin

        :param str symbol: unified market symbol
        :param float amount: the 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>`
        r  z@ addMargin() requires a holdSide parameter, either long or shortadd)r  r/   rD   r)  r.  s        r  
add_marginzbitget.add_margin  sH     ##FJ7#DGG.p$pqq((GGr  c                    | j                          | j                  |      }d}| j                  ||      \  }}|d   |d   |d}| j                  | j	                  ||            }| j                  |di       }| j                  ||      S )ag  
        fetch the set leverage for a market

        https://www.bitget.com/api-doc/contract/account/Get-Single-Account

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `leverage structure <https://docs.ccxt.com/#/?id=leverage-structure>`
        NrD   r  r  r  )rj  r  r   privateMixGetV2MixAccountAccountr  r  parse_leverager  r  r  r  r  rq  r  r  s           r  fetch_leveragezbitget.fetch_leverage  s     	V$"AA&&QVTl ,&

 88Wf9UV: ~~h3""400r  r"  c                     | j                  |d      dk(  }|rdnd}|rdnd}||d   |rdnd| j                  ||      | j                  ||      d	S )
Nr  r  crossedMarginLeverageisolatedLongLeverisolatedShortLeverr  r  r  )r-  r  r  longLeverageshortLeverage)r  r  )r  r"  r  isCrossMarginMode
longLevKeyshortLevKeys         r  r4  zbitget.parse_leverage  sl     ,,X|D	Q0A,GZ
1B-H\X&%6'J --h
C!..xE
 	
r  c                 $   |t        | j                  dz         | j                          | j                  |      }d}| j	                  ||      \  }}|d   |d   | j                  |      |d}| j                  | j                  ||            }|S )a  
        set the level of leverage for a market

        https://www.bitget.com/api-doc/contract/account/Change-Leverage

        :param int leverage: the rate of leverage
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.holdSide]: *isolated only* position direction, 'long' or 'short'
        :returns dict: response from the exchange
        Nz) setLeverage() requires a symbol argumentrD   r  )r  rm  r"  r  )r/   rD   rj  r  r  r  %privateMixPostV2MixAccountSetLeverager  )r  r"  r  r  r  r  rq  r  s           r  set_leveragezbitget.set_leverage  s     >#DGG.Y$YZZV$"AA&&QVTl ,--h7&	
 ==dkk'SY>Z[  r  r  c                 x   |t        | j                  dz         |j                         }|dk(  rd}|dk7  r|dk7  rt        | j                  dz         | j                          | j	                  |      }d}| j                  ||      \  }}|d   |d   ||d	}| j                  | j                  ||            }|S )
at  
        set margin mode to 'cross' or 'isolated'

        https://www.bitget.com/api-doc/contract/account/Change-Margin-Mode

        :param str marginMode: 'cross' or 'isolated'
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        Nz+ setMarginMode() requires a symbol argumentr  r  r  zE setMarginMode() marginMode must be either isolated or crossed(cross)rD   r  )r  rm  r  r  )r/   rD   lowerrj  r  r  'privateMixPostV2MixAccountSetMarginModer  )r  r  r  r  r  r  rq  r  s           r  set_margin_modezbitget.set_margin_mode8  s     >#DGG.[$[\\%%'
 "J*$:+B#DGG.u$uvvV$"AA&&QVTl ,$&	
 ??GU[@\] r  r  c                     | j                          |rdnd}d}|| j                  |      }d}| j                  ||      \  }}||d}| j                  | j	                  ||            }|S )a5  
        set hedged to True or False for a market

        https://www.bitget.com/api-doc/contract/account/Change-Hold-Mode

        :param bool hedged: set to True to use dualSidePosition
        :param str symbol: not used by bitget setPositionMode()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.productType]: required if symbol is None: 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES'
        :returns dict: response from the exchange
        r  r  N)r  r  )rj  r  r  )privateMixPostV2MixAccountSetPositionModer  )	r  r  r  r  r  r  r  rq  r  s	            r  set_position_modezbitget.set_position_modee  s     	"(,n[[(F"AA&&QV&
 AA$++gW]B^_ r  c                 H   | j                          | j                  |      }|d   st        | j                  dz         d}| j	                  ||      \  }}|d   |d}| j                  | j                  ||            }| j                  |di       }| j                  ||      S )aq  
        retrieves the open interest of a contract trading pair

        https://www.bitget.com/api-doc/contract/market/Get-Open-Interest

        :param str symbol: unified CCXT market symbol
        :param dict [params]: exchange specific parameters
        :returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
        r  z3 fetchOpenInterest() supports contract markets onlyNrD   r  r  )	rj  r  r0   rD   r  #publicMixGetV2MixMarketOpenInterestr  r  parse_open_interestr5  s           r  fetch_open_interestzbitget.fetch_open_interest  s     	V$j!TWW'\\]]"AA&&QVTl&
 ;;DKKQW<XY" ~~h3''f55r  c           	         | j                  |dg       }| j                  |d      }| j                  |d   d      }| j                  | j	                  ||d d      | j                  |d   d      d || j                  |      |d|      S )NopenInterestListr  r   r  r  r  )r  openInterestAmountopenInterestValuer  r  r-  )r  r  r  safe_open_interestr  r7  r1  )r  ro  r  r  r  r9  s         r  rL  zbitget.parse_open_interest  s     x);R@%%h5	##DGX6&&&&xzJ"&"2"247F"C!%"Y/(
  	r  c                 8   |t        | j                  dz         | j                          d}| j                  dd|      \  }}| j	                  |d|      }| j                  |d      }| j                  | j                  di       }| j	                  ||      }| j                  |      }|d   |d}	|||	d<   |||	d	<   | j                  d
|	|      \  }	}| j                  | j                  |	|            }
| j                  |
dg       }| j                  ||||      S )a  
        fetch a history of internal transfers made on an account

        https://www.bitget.com/api-doc/spot/account/Get-Account-TransferRecords

        :param str code: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for
        :param int [limit]: the maximum number of transfers structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
        Nz* fetchTransfers() requires a code argumentr   fromAccountr  rD   )rO  fromTyper  r  r  r  )r/   rD   rj  r	  r  r  r  r  rn  r  *privateSpotGetV2SpotAccountTransferRecordsr  r  parse_transfers)r  r`  r  r  r  r  rT  r  rn  rq  r  r  s               r  fetch_transferszbitget.fetch_transfers  s6    <#DGG.Z$Z[[99:JDRXYf&&v}dC6=17GL<==&TN
 #(GK $GG229gvNBB4;;wX^C_`, ~~h3##D(E5AAr  rT  	toAccountc                    | j                          | j                  |      }| j                  | j                  di       }| j	                  ||      }| j	                  ||      }	||	||d   d}
| j	                  |d      }| j                  |d      }d}|| j                  |      }|d   |
d<   | j                  | j                  |
|            }| j                  |di       }| j                  |d      |d<   | j                  ||      S )	a  
        transfer currency internally between wallets on the same account

        https://www.bitget.com/api-doc/spot/account/Wallet-Transfer

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.symbol]: unified CCXT market symbol, required when transferring to or from an account type that is a leveraged position-by-position account
        :param str [params.clientOid]: custom id
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        r  rD   )rU  toTyper  rO  r  Nr  rL  r  )rj  rn  r  r  r  r  r  #privateSpotPostV2SpotWalletTransferr  r  parse_transfer)r  r`  r  rT  rY  r  rn  r  rU  r[  rq  r  r  r  r  s                  r  r   zbitget.transfer  s    	==&7GL##NK@!!.)< TN	
 !!&(368,[[(F &tGH;;DKKQW<XY x4&&x?T
""422r  r   c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  | j                  di       }| j                  |||      }| j                  |d      }	| j                  ||	|	      }
|| j                  |d      || j                  |      | j                  ||      | j                  |d      ||
| j                  |      d		S )
Nr  r  rO  rU  r  r[  
transferIdr  )	r-  rD   r  r  rn  r  rT  rY  r  )	r  r  r  r  r  r1  r.  r7  parse_transfer_status)r  r   rn  r  r  r  fromAccountRawr  rT  toAccountRawrY  s              r  r]  zbitget.parse_transfer2  s    2 %%h5	''(;%%h7
))(J?t||^RH&&|^^T''(;$$\<N	""8\:"Y///
HE&&x8&"008

 
	
r  c                 0    ddi}| j                  |||      S )N
successfulr  r  r  s      r  r`  zbitget.parse_transfer_status_  s%    $
 &&99r  c                    | j                  |dg       }t        |      }|d d dd d di d}t        d|      D ]  }||   }| j                  |d      }| j                  |d      }	| j	                  ||	      }
d d d| j                  |d      ddd	|d
   |
<   |dk(  se| j                  |d      |d   d<   d|d   d<    |S )NrP  )r[  r  )r-  r   rT  r  r   rQ  r`  rX  F)rT  r   r  r   r   r[  r  )r  r  r  r  rb  r7  )r  r[  rn  rP  chainsLengthr  r  rQ  rf  r  r  s              r  parse_deposit_withdraw_feez!bitget.parse_deposit_withdraw_feee  s   . h36{"
 " 
 q,' 	9A1IE((8I++Hf=L11)\JK#'t<$($4$4UM$JZ_`/F:{+ q ,0,<,<UM,Rz"5)38z"<0	9 r  codesc                     | j                          | j                  |      }| j                  |dg       }| j                  ||d      S )ag  
        fetch deposit and withdraw fees

        https://www.bitget.com/api-doc/spot/market/Get-Coin-List

        :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>`
        r  rO  )rj  ra  r  parse_deposit_withdraw_fees)r  rh  r  r  r  s        r  fetch_deposit_withdraw_feesz"bitget.fetch_deposit_withdraw_fees  sI     	66v>< ~~h3//eVDDr  c                     | j                          | j                  |      }|d   | j                  ||      d}| j                  | j	                  ||            }| j                  |di       }| j                  ||      S )a  
        create a loan to borrow margin

        https://www.bitget.com/api-doc/margin/cross/account/Cross-Borrow

        :param str code: unified currency code of the currency to borrow
        :param str amount: the amount to borrow
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        rD   )rO  borrowAmountr  )rj  rn  r  -privateMarginPostV2MarginCrossedAccountBorrowr  r  parse_margin_loanr  r`  r  r  rn  rq  r  r  s           r  borrow_cross_marginzbitget.borrow_cross_margin  s     	==&TN 66tVD
 EEdkkRY[aFbc x4%%dH55r  c                 ,   | j                          | j                  |      }| j                  |      }|d   | j                  ||      |d   d}| j	                  | j                  ||            }| j                  |di       }	| j                  |	||      S )a  
        create a loan to borrow margin

        https://www.bitget.com/api-doc/margin/isolated/account/Isolated-Borrow

        :param str symbol: unified market symbol
        :param str code: unified currency code of the currency to borrow
        :param str amount: the amount to borrow
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        rD   )rO  rm  r  r  )rj  rn  r  r  .privateMarginPostV2MarginIsolatedAccountBorrowr  r  ro  
r  r  r`  r  r  rn  r  rq  r  r  s
             r  borrow_isolated_marginzbitget.borrow_isolated_margin  s     	==&V$TN 66tVDTl

 FFt{{SZ\bGcd x4%%dHf==r  c                 ,   | j                          | j                  |      }| j                  |      }|d   | j                  ||      |d   d}| j	                  | j                  ||            }| j                  |di       }	| j                  |	||      S )a  
        repay borrowed margin and interest

        https://www.bitget.com/api-doc/margin/isolated/account/Isolated-Repay

        :param str symbol: unified market symbol
        :param str code: unified currency code of the currency to repay
        :param str amount: the amount to repay
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        rD   )rO  repayAmountr  r  )rj  rn  r  r  -privateMarginPostV2MarginIsolatedAccountRepayr  r  ro  rt  s
             r  repay_isolated_marginzbitget.repay_isolated_margin
  s     	==&V$TN55dFCTl

 EEdkkRY[aFbc x4%%dHf==r  c                     | j                          | j                  |      }|d   | j                  ||      d}| j                  | j	                  ||            }| j                  |di       }| j                  ||      S )a  
        repay borrowed margin and interest

        https://www.bitget.com/api-doc/margin/cross/account/Cross-Repay

        :param str code: unified currency code of the currency to repay
        :param str amount: the amount to repay
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        rD   )rO  rw  r  )rj  rn  r  ,privateMarginPostV2MarginCrossedAccountRepayr  r  ro  rp  s           r  repay_cross_marginzbitget.repay_cross_margin0  s     	==&TN55dFC
 DDT[[QXZ`Eab x4%%dH55r  c                     | j                  |d      }| j                  |d      }d }|| j                  ||d d      }| j                  |dd      | j                  ||      | j	                  |dd      |d d |dS )	NrO  r  rQ   loanIdrepayIdrm  rw  )rD   rn  r  r  r  r  r-  )r  r  r6  r.  r8  )r  r-  rn  r  r  r9  r  s          r  ro  zbitget.parse_margin_loanR  s    L %%dF3
##D(3%%hfEF$$T8Y?//
HE((~}M
 	
r  c           	         | j                          d}| j                  |dd      \  }}|r| j                  d||||dd      S d}|| j                  |      }d}| j	                  d||      \  }}|dk7  rt        | j                  dz         i }| j                  d	||      \  }}|||d
<   n| j                         dz
  |d
<   |||d<   d}	d}
| j                  d|d      \  }
}|
dk(  rD|t        | j                  dz         |d   |d<   | j                  | j                  ||            }	n&|
dk(  r!| j                  | j                  ||            }	| j                  |	di       }| j                  |dg       }| j!                  ||||      S )a-  
        retrieves the users liquidated positions

        https://www.bitget.com/api-doc/margin/cross/record/Get-Cross-Liquidation-Records
        https://www.bitget.com/api-doc/margin/isolated/record/Get-Isolated-Liquidation-Records

        :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 bitget api endpoint
        :param int [params.until]: timestamp in ms of the latest liquidation
        :param str [params.marginMode]: 'cross' or 'isolated' default value is 'cross'
        :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: an array of `liquidation structures <https://docs.ccxt.com/#/?id=liquidation-structure>`
        Fr   r  r`  r  NrQ   z8 fetchMyLiquidations() supports spot margin markets onlyr  r  r  r  r  r  z1 fetchMyLiquidations() requires a symbol argumentrD   r  r  rM  )rj  r  r  r  r	  r6   rD   r  r  rk  r/   2privateMarginGetV2MarginIsolatedLiquidationHistoryr  1privateMarginGetV2MarginCrossedLiquidationHistoryr  r  parse_liquidations)r  r  r  r  r  r  r  r  rq  r  r  r  liquidationss                r  fetch_my_liquidationszbitget.fetch_my_liquidations  s     	88AVXbc&334I6SXZ_agipr~[[(F99:OQWY_`f6>tww)ccdd229gvN#(GK #'#4#4#6#CGK $GG
!??@UW]_fg
F#~'2e(eff &tGHNNt{{[bdjOklH7"MMdkkZaciNjkHj x4~~dL"=&&|VUEJJr  c                 R   | j                  |d      }| j                  |d      }| j                  |dd      }| j                  |d      }t        j                  ||      }| j                  || j                  ||      d d d d | j                  |      || j                  |      d	      S )Nr  
liqEndTimeLiqFeeliqFee	totalDebt)	r-  r  r  r%  r  	baseValue
quoteValuer  r  )	r  r  r6  r?   r|  safe_liquidationr  r  r1  )r  liquidationr  r9  r  liquidationFeer  quoteValueStrings           r  parse_liquidationzbitget.parse_liquidation  s    > ##K:%%k<@	++K8L$$[+>	"--niH$$&&x8 ++,<="Y/
&
 
 
	r  c                 2   | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |d      }| j                  |dg       }| j                  |di       }||d<   | j                  ||      S )a  
        fetch the rate of interest to borrow a currency for margin trading

        https://www.bitget.com/api-doc/margin/isolated/account/Isolated-Margin-Interest-Rate-And-Max-Borrowable-Amount

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `isolated borrow rate structure <https://docs.ccxt.com/#/?id=isolated-borrow-rate-structure>`
        r  rD   rL  r  r   r  )rj  r  4privateMarginGetV2MarginIsolatedInterestRateAndLimitr  r  r  parse_isolated_borrow_rate)	r  r  r  r  rq  r  r  r  r]  s	            r  fetch_isolated_borrow_ratez!bitget.fetch_isolated_borrow_rate  s     	V$fTl
 LLT[[Y`bhMijT %%h>	x4a,&k..uf==r  r-  c           
      l   | j                  |d      }| j                  ||d d      }| j                  |d      }| j                  |d      }| j                  |d      }|| j                  |      | j	                  |d      | j                  |      | j	                  |d      d|| j                  |      |d		S )
Nr  rQ   r  r  r  baseDailyInterestRatequoteDailyInterestRater@  )	r  r  baseRater  	quoteRateperiodr  r  r-  )r  r  r  r.  r7  r1  )r  r-  r  r9  r  r  r  r  s           r  r  z!bitget.parse_isolated_borrow_rate\  s    F ##D(3!!(FD&A!!$
3""45%%dK8	++F3((/FG,,W5))$0HI"Y/

 
	
r  c                 2   | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |d      }| j                  |dg       }| j                  |di       }||d<   | j                  ||      S )a  
        fetch the rate of interest to borrow a currency for margin trading

        https://www.bitget.com/api-doc/margin/cross/account/Get-Cross-Margin-Interest-Rate-And-Borrowable

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.symbol]: required for isolated margin
        :returns dict: a `borrow rate structure <https://github.com/ccxt/ccxt/wiki/Manual#borrow-rate-structure>`
        rO  rD   rL  r  r   r  )rj  rn  3privateMarginGetV2MarginCrossedInterestRateAndLimitr  r  r  parse_borrow_rate)	r  r`  r  rn  rq  r  r  r  r]  s	            r  fetch_cross_borrow_ratezbitget.fetch_cross_borrow_rate  s     	==&HTN
 KKDKKX_agLhi6 %%h>	x4a,&k%%eX66r  c                     | j                  |d      }| j                  |d      }| j                  ||      | j                  |d      d|| j	                  |      |dS )NrO  r  dailyInterestRater@  )rn  rater  r  r  r-  )r  r  r.  r7  r1  )r  r-  rn  r  r  s        r  r  zbitget.parse_borrow_rate  sh    ( %%dF3
%%dK8	//
HE$$T+>?"Y/
 	
r  c           	         | j                          d}| j                  |dd      \  }}|r| j                  d||||dd      S d}|| j                  |      }i }d}	|| j	                  |      }	|	d   |d<   |||d	<   n| j                         d
z
  |d	<   |||d<   d}
d}| j                  d|d      \  }}|dk(  rD|t        | j                  dz         |d   |d<   | j                  | j                  ||            }
n&|dk(  r!| j                  | j                  ||            }
| j                  |
di       }| j                  |dg       }| j                  ||      }| j                  ||||      S )a  
        fetch the interest owed by the user for borrowing currency for margin trading

        https://www.bitget.com/api-doc/margin/cross/record/Get-Cross-Interest-Records
        https://www.bitget.com/api-doc/margin/isolated/record/Get-Isolated-Interest-Records

        :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.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 `borrow interest structures <https://docs.ccxt.com/#/?id=borrow-interest-structure>`
        Frs   r  r`  r  NrD   rO  r  r  r  r  r  z1 fetchBorrowInterest() requires a symbol argumentr  r  rM  )rj  r  r  r  rn  r  rk  r/   rD   /privateMarginGetV2MarginIsolatedInterestHistoryr  .privateMarginGetV2MarginCrossedInterestHistoryr  parse_borrow_interestsfilter_by_currency_since_limit)r  r`  r  r  r  r  r  r  rq  rn  r  r  r  rowsro  s                  r  fetch_borrow_interestzbitget.fetch_borrow_interest  s    	88AVXbc&334I6SXZ_agipr~[[(F}}T*H&tnGFO#(GK #'#4#4#6#CGK $GG
!??@UW]_fg
F#~'2e(eff &tGHKKDKKX_agLhiH7"JJ4;;W^`fKghHf x4t\26..tV<228T5%PPr  c                 N   | j                  |d      }| j                  ||      }|dnd}| j                  |d      }|| j                  |d      | j                  | j                  |d            | j	                  |d      | j	                  |d      d ||| j                  |      d	S )	Nr  r  r  r  interestCoininterestAmountr  )	r-  r  rn  ro  r  amountBorrowedr  r  r  )r  r  r  r.  r7  r1  )r  r-  r  r9  r  r  s         r  parse_borrow_interestzbitget.parse_borrow_interestC  s    : ##D(3!!(F3$,$8Zw
%%dG4	&&vx8//0@0@~0VW((/?@ ,,T3FG"$"Y/

 
	
r  c                 H   | j                          | j                  |      }d}| j                  ||      \  }}|d   |d}|||d<   | j                  | j	                  ||            }| j                  |di       }| j                  |dg       }	| j                  |	d   |      S )a  
        closes an open position for a market

        https://www.bitget.com/api-doc/contract/trade/Flash-Close-Position

        :param str symbol: unified CCXT market symbol
        :param str [side]: one-way mode: 'buy' or 'sell', hedge-mode: 'long' or 'short'
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        NrD   r  r  r  r  r   )rj  r  r  &privateMixPostV2MixOrderClosePositionsr  r  r  r  )
r  r  r  r  r  r  rq  r  r  r  s
             r  close_positionzbitget.close_positionp  s     	V$"AA&&QVTl&
 "&GJ>>t{{7TZ?[\$ x4t]B7a&11r  c                    | j                          d}| j                  d|      \  }}d|i}| j                  | j                  ||            }| j	                  |di       }| j                  |dg       }| j                  |d|      S )a  
        closes all open positions for a market type

        https://www.bitget.com/api-doc/contract/trade/Flash-Close-Position

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.productType]: 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES'
        :returns dict[]: A list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
        Nr  r  r  )rj  r  r  r  r  r  parse_positions)r  r  r  rq  r  r  r  s          r  close_all_positionszbitget.close_all_positions  s     	"AA$OV;
 >>t{{7TZ?[\$ x4NN4;	##ItV<<r  c                    | j                          | j                  |      }d}| j                  ||      \  }}|d   |d   |d}| j                  | j	                  ||            }| j                  |di       }| j                  ||      S )a  
        fetches the margin mode of a trading pair

        https://www.bitget.com/api-doc/contract/account/Get-Single-Account

        :param str symbol: unified symbol of the market to fetch the margin mode for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin mode structure <https://docs.ccxt.com/#/?id=margin-mode-structure>`
        NrD   r  r  r  )rj  r  r  r3  r  r  parse_margin_moder5  s           r  fetch_margin_modezbitget.fetch_margin_mode  s     	V$"AA&&QVTl ,&

 88Wf9UV: ~~h3%%dF33r  c                 J    | j                  |d      }|dk(  rdn|}||d   |dS )Nr  r  r  r  )r-  r  r  r  )r  r  r  
marginTypes       r  r  zbitget.parse_margin_mode  s:    %%j,?
!+y!8Wz
X&$
 	
r  c                    | j                          | j                  |d      }| j                  |d      }i }|,t        |      }|dkD  r| j	                  |d         }|d   |d<   |||d<   |||d<   |||d<   | j                  | j                  ||            }	| j                  |	d      }
| j                  |
d	      }| j                  |||      }| j                  |||      S )
a  
        fetches historical positions

        https://www.bitget.com/api-doc/contract/position/Get-History-Position

        :param str[] [symbols]: unified contract symbols
        :param int [since]: timestamp in ms of the earliest position to fetch, default=3 months ago, max range for params["until"] - since is 3 months
        :param int [limit]: the maximum amount of records to fetch, default=20, max=100
        :param dict params: extra parameters specific to the exchange api endpoint
        :param int [params.until]: timestamp in ms of the latest position to fetch, max range for params["until"] - since is 3 months

 EXCHANGE SPECIFIC PARAMETERS
        :param str [params.productType]: USDT-FUTURES(default), COIN-FUTURES, USDC-FUTURES, SUSDT-FUTURES, SCOIN-FUTURES, or SUSDC-FUTURES
        :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
        rA  r   rD   r  r  r  r  r  r  )rj  r  r  r  r  r  r  r  r  r  filter_by_since_limit)r  r  r  r  r  rA  rq  symbolsLengthr  r  r  rV  	positionss                r  fetch_positions_historyzbitget.fetch_positions_history  s     	!!&'267+LMq WQZ0$*4L!#(GK $GG!&GIAA$++gW]B^_< ~~h/~~dF3((wG	)))UEBBr  fromCodetoCodec                 j   | j                          ||| j                  |      d}| j                  | j                  ||            }| j	                  |di       }| j                  |d|      }| j                  |      }	| j                  |d|      }
| j                  |
      }| j                  ||	|      S )aC  
        fetch a quote for converting from one currency to another

        https://www.bitget.com/api-doc/common/convert/Get-Quoted-Price

        :param str fromCode: the currency that you want to sell and convert from
        :param str toCode: the currency that you want to buy and convert into
        :param float [amount]: how much you want to trade in units of the from currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
        )fromCointoCoinfromCoinSizer  r  r  )rj  r  %privateConvertGetV2ConvertQuotedPricer  r  r  rn  parse_conversion)r  r  r  r  r  rq  r  r  fromCurrencyIdfromCurrencytoCurrencyId
toCurrencys               r  fetch_convert_quotezbitget.fetch_convert_quote?   s     	  11&9

 ==dkk'SY>Z[" ~~h3))$
HE}}^4''h?]]<0
$$T<DDr  c                    | j                          | j                  |dd      }|t        | j                  dz         | j                  |dd      }|t        | j                  dz         | j	                  |ddg      }|||| j                  |      ||d}| j                  | j                  ||            }	| j                  |	d	i       }
| j                  |
d
|      }| j                  |      }| j                  |
d|      S )aG  
        convert from one currency to another

        https://www.bitget.com/api-doc/common/convert/Trade

        :param str id: the id of the trade that you want to make
        :param str fromCode: the currency that you want to sell and convert from
        :param str toCode: the currency that you want to buy and convert into
        :param float amount: how much you want to trade in units of the from currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str params['price']: the price of the conversion, obtained from fetchConvertQuote()
        :param str params['toAmount']: the amount you want to trade in units of the toCurrency, obtained from fetchConvertQuote()
        :returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
        r  	cnvtPriceNz0 createConvertTrade() requires a price parametertoAmount
toCoinSizez3 createConvertTrade() requires a toAmount parameter)traceIdr  r  r  r  r  r  r  )rj  r6  r/   rD   r  r   privateConvertPostV2ConvertTrader  r  r  rn  r  )r  rD   r  r  r  r  r  r  rq  r  r  r  r  s                r  create_convert_tradezbitget.create_convert_tradei   s    	""67K@=#DGG.`$`aa%%fj,G#DGG.c$cdd6GZ#89  11&9"
 88Wf9UV ~~h3''h?]]<0
$$T4<<r  c                    | j                          i }d}| j                         }|||d<   n||z
  |d<   | j                  |dd      }|||d<   n||d<   |||d<   | j                  |d      }| j	                  | j                  ||            }	| j                  |	di       }
| j                  |
dg       }| j                  ||dd	||      S )
a"  
        fetch the users history of conversion trades

        https://www.bitget.com/api-doc/common/convert/Get-Convert-Record

        :param str [code]: the unified currency code
        :param int [since]: the earliest time in ms to fetch conversions for
        :param int [limit]: the maximum number of conversion structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `conversion structures <https://docs.ccxt.com/#/?id=conversion-structure>`
        r@  r  r  rA  r  r  r\  r  r  )	rj  r  r6  r  'privateConvertGetV2ConvertConvertRecordr  r  r  parse_conversions)r  r`  r  r  r  rq  rQ  rR  r  r  r  r\  s               r  fetch_convert_trade_historyz"bitget.fetch_convert_trade_history   s     	!#(GK #&=GK $$VY@!(GI!$GI$GG67+??GU[@\]. ~~h3>>$
B7%%hj(ESXYYr  
conversionr  r  c                    | j                  |d      }| j                  |d      }| j                  ||      }| j                  |d      }| j                  ||      }||| j                  |      | j	                  |dd      || j                  |d      || j                  |d      | j                  |d      | j                  |d	      d

S )Nr  r  r  rD   r  r  r  r  r[  )
r-  r  r  rD   r  
fromAmountr  r  r  r[  )r  r  r.  r1  r6  r7  )	r  r  r  r  r  r  r  tor  s	            r  r  zbitget.parse_conversion   s    H %%j$7	##J
;**8\Bj(3((Z8"Y/$$ZyA$**:~F ((\B%%j+>##J6
 	
r  c                    | j                          | j                  |      }i }| j                  |dg       }t        dt	        |            D ]z  }||   }| j                  |d      }| j                  |      }|||ddddd| j                  |d      dd| j                  |d      | j                  |d      dddddddd	dd
||<   | |S )a+  
        fetches all available currencies that can be converted

        https://www.bitget.com/api-doc/common/convert/Get-Convert-Currencies

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r  r   rO  Nru  	minAmount	maxAmountr  r^  r_  )rj  $privateConvertGetV2ConvertCurrenciesr  r  r  r  r.  r7  )	r  r  r  r  r  r  re  rD   r`  s	            r  fetch_convert_currencieszbitget.fetch_convert_currencies!  s
    	<<VD  ~~h3q#d)$ 	AGE!!%0B**2.D  ,,UK@!  $//{C#//{C
  $#!
  $#   5F4L		@ r  c                 4   | j                          | j                  |      }d}| j                  ||      \  }}|d   |d}| j                  | j	                  ||            }| j                  |dg       }| j                  |di       }| j                  ||      S )a|  
        fetch the current funding rate interval

        https://www.bitget.com/api-doc/contract/market/Get-Symbol-Next-Funding-Time

        :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>`
        NrD   r  r  r   )rj  r  r  r  r  r  r  r  r  s	            r  fetch_funding_intervalzbitget.fetch_funding_intervalF!  s     	V$"AA&&QVTl&
 ::4;;wPV;WX ~~h3tQ+&&uf55r  rL  c                 H   | j                          | j                  |      }d|d   i}|||d<   d}|d   s|d   r"| j                  | j                  ||            }n!| j	                  | j                  ||            }| j                  |dg       }	| j                  |	|      S )a  
        fetches the long short ratio history for a unified market symbol

        https://www.bitget.com/api-doc/common/apidata/Margin-Ls-Ratio
        https://www.bitget.com/api-doc/common/apidata/Account-Long-Short

        :param str symbol: unified symbol of the market to fetch the long short ratio for
        :param str [timeframe]: the period for the ratio
        :param int [since]: the earliest time in ms to fetch ratios for
        :param int [limit]: the maximum number of long short ratio structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of `long short ratio structures <https://docs.ccxt.com/#/?id=long-short-ratio-structure>`
        r  rD   Nr  rS   rT   r  )rj  r  'publicMixGetV2MixMarketAccountLongShortr  +publicMarginGetV2MarginMarketLongShortRatior  parse_long_short_ratio_history)
r  r  rL  r  r  r  r  rq  r  r  s
             r  fetch_long_short_ratio_historyz%bitget.fetch_long_short_ratio_historyk!  s     	V$fTl
   )GH&>VH-CCDKKPWY_D`aH" GGT[]cHdeH ~~h3224@@r  c           
          | j                  |d      }| j                  |d      }|| j                  ||d d      || j                  |      d | j	                  |dd      dS )Nr  r  r  longShortRatiolongShortAccountRatio)r-  r  r  r  rL  r  )r  r  r  r1  r8  )r  r-  r  r9  r  s        r  parse_long_short_ratiozbitget.parse_long_short_ratio!  sm    ##D(3//d;	&&xzJ"Y/"007GI`a
 	
r  reasonurlr  headersbodyc
                    |sy | j                  |dd      }
| j                  dz   |z   }|
d uxr |
dk7  xr |
dk7  }|r@| j                  | j                  d   |
|       | j	                  | j                  d   |
|       | j                  |dd	      }|d uxr |d
k7  }|r | j                  | j                  d   ||       |s|rt        |      y )Nerr_msgmsg rB  r  r  r  r`  err_coder+  )r6  rD   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr+   )r  r`  r  r  r  r  r  r  requestHeadersrequestBodymessagefeedbacknonEmptyMessager,  nonZeroErrorCodes                  r  handle_errorszbitget.handle_errors!  s    6 $$Xy%@77S=4'#4/_gm_'U^J^001I7T\]001I7T\]&&xD	%T1M	W8L001I9V^_))r  c                 B    | j                         | j                  d   z
  S )Nr  )r  r  )r  s    r  noncezbitget.nonce!  s       "T\\2B%CCCr  GETc                 z   |d   dk(  }|d   }d}	d| j                  ||      z   }
|	|
z   }| j                  | j                  d   |         |z   }| j                  || j	                  |            }|sE|dk(  r@t        |j                               }t        |      }|dkD  r|dz   | j                  |      z   }|r.| j                          t        | j                               }||z   |z   }|d	k(  r| j                  |      }||z  }nU|rSd| j                  | j                  |            z   }|j                  d
      dkD  r|j                  d
d      }||z  }||z  }| j!                  | j#                  |      | j#                  | j$                        t&        j(                  d      }| j+                  | j,                  d      }| j.                  ||| j0                  |d}|d	k(  rd|d<   | j3                  | j,                  ddd      }|r/|dk7  r*|i }| j+                  |d      }|dk7  r|dk7  r
|dk7  rd|d<   ||||dS )Nr   r   r   z/apir  r   r  ?POSTz%24$base64r   )z
ACCESS-KEYzACCESS-SIGNzACCESS-TIMESTAMPzACCESS-PASSPHRASEzX-CHANNEL-API-CODEzapplication/jsonzContent-Typer  r  Fr   r  r  r  r  r   
PAPTRADING)r  r  r  r  )implode_paramsimplode_hostnamer   r  extract_paramsr  r  r  	urlencodecheck_required_credentialsr5  r  r  keysortr  replacehmacencoder   hashlibsha256r  r  r   r   rN  )r  pathr   r  r  r  r  signedendpointpathPartrq  payloadr  rl  r  
keysLengthr  auth
queryInner	signaturer   r  r  s                          r  signzbitget.sign!  sI   Q9$q6++D&99W$##DIIe$4X$>?'I		&$"5"5d";<6U?

%DTJA~Ci$.."77++-DJJL)Iv%/Dyy(!$t~~dll66J'K!KJ!u-2%/%7%7s%C
:%CJ&D		$++d"3T[[5Mw~~_ghI%%dllH=F"kk($-%)]]&,G *<'&&t||]IuUD$44**6=AK.[O5SZeixZx(+%fdwOOr  )N)NNN)NN)__name__
__module____qualname__r   r  r  r  r   r  r*   r   r  dictr  r
   rh  r5  r   rr  rp  r   r(   r  floatr   r  r   r  r  r   r  r  r   r  r!   r  r  r  r    r"   r  r%   r   r,  r&   r1  r'   r4  r0  r  r;  rd  r   rk  rj  r  r   r  r  r   r   r   r  r  r   r  r6  rA  rI  rW  r^  rm  rs  ru  rp  r   r  r  r  r  r  r   r  r  r  r#   r	  r$   r  r  r   r!  r#  r   r   r)  r(  r  r1  r   r6  r4  rB  rF  boolrI  rM  rL  r)   rX  r   r]  r`  rg  rk  rq  ru  ry  r|  ro  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  intr  r  r  __classcell__)r  s   @r  rA   rA   #   sR   H# HT4. 59 %@ !# 5s 5. $& 0$v, 0dE
4 E
F E
N ') jZ jX ?A b@# b@T,EW b@H; ;$|J\ ;z *.Dt\^ :L3 :Lc :L :Lcghsct :Lx DHPR 7S 7% 7# 7Wb 7r -1tRV_a >Pc >P >PC >Pfjkvfw >P@K
T K
X K
Q\ K
Z:s : 79 #:# #:^ #:J
h 
R` 
0 :>b )Hs )H3 )HY )HVt4 t t6 tl 02 X23 X2f X2t 46 2s 2& 24 04B \1W \17 \1|s sv s sj 6:UW b=3 b=s b=# b=\`af\g b=H 57 &4 &4;N &4P )+ q{ qf	
f 	

 
4 
* 26DW[df @H# @Hc @HQT @Hkoptku @HD $& {(( {(zV) V)p: :*t tv t tl RT ` `5 `, gksu U.3 U.i U.y U.RW U.`c U.n os{} k,3 k,i k,y k,Z_ k,hk k,Z @B Y/D$6 Y/v `drv  @B Q.S Q.# Q.Y Q.i Q.Y\ Q.lo Q.f 37r s/s s/C s/j 04B J1 J1X /32 i/ i/V 26b i/c i/3 i/Z /3TXac U= U=3 U=c U=hlmrhs U=n 154VZce :# :S :PS :jnotju :6 37TX\eg <C <s <RU <6 >BPTcgpr Z?s Z?# Z?]` Z?x (,$TZ\ d? d?C d?s d?aefqar d?L:t :x :; :x+3Z -1tRV_a c=c c= c=C c=fjkpfq c=J 24 42S 42l 26b DPw DPT(^ DPLat aV aF 8<$]ajl =Y =YC =YWZ =Y~ 68 =8 =8K =8~ 6:" 877 87 87tV
6 V
[ V
p 37TX\eg >JC >Js >JRU >Jlpq  mA >J@
f 
4OS OX[ Ogklzg{ O FH 3 L^ 8
d 
F 
N` 
4 @B KC K KFX K$ =? H He HCU H  24 11S 11 11f

t 

V 

x 

 9=R )S )# )V >B" +# +s +Z =A " "c "H 79 &6# &6PF 0 +/TPT]_ 7BC 7Bs 7B# 7Bdhivdw 7Br [] .3S .3% .3c .3c .3an .3`+
t +
x +
= +
Z:C :C :1 1f <@ *E *EX DF 6 6U 6B TV #>S #> #>U #>J LN $>C $>s $>L <>  6s  6D3
 3
 3
j 37TX\eg dKC dKs dKRU dKlpq|l} dKL.V .` >@ => =>DV =>~2
t 2
V 2
Oa 2
h 9; /7C /7 /7b
 
> 15DW[jnwy aQ# aQc aQQT aQdg aQ  C  DR  S aQF+
$ +
 +
. +
Z =A )2S )2	 )2PU )2V *, $=X $=L 57 14 14: 14f
D 
* 
 :>D_cln @Cw @Cc @CY\ @Csw  yA  tB @CD MQY[ (EC (E (Ec (E`j (ET W[ce 0=s 0=c 0=3 0=PS 0=jt 0=d 7;\`ik 5Z 5Z3 5ZVY 5Zptu  qA 5Zn4
4 4
x 4
\d 4
pz 4
l /1 <Z <| :< #6S #6 #6J <@RVeix|  FH 7AS 7AC 7A_b 7Aru 7A  MQ  R`  Ma 7Ar

4 

 

> 

)# )s ) )c )TX )`c )VD  b$T /Pr  rA   )Gccxt.base.exchanger   ccxt.abstract.bitgetr   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)   typingr*   ccxt.base.errorsr+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   ccxt.base.decimal_to_precisionr>   ccxt.base.preciser?   rA    r  r  <module>r,     s    ( ,   T  T  T  T  T  T  T  T  T  T  * 0 - - . ' & . + ) * ) + . 1 * ) + * 4 %jGPX{ jGPr  