
    iX                       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! d dl"m#Z# d dl$m%Z% d dl$m&Z& d dl$m'Z' d d	l$m(Z( d d
l$m)Z) d dl$m*Z* d dl$m+Z+ d dl$m,Z, d dl$m-Z- d dl$m.Z. d dl$m/Z/ 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l8m9Z9 d dl:m;Z;  G d dee          Z<dS )    )Exchange)ImplicitAPIN)Balances
Conversion
CurrenciesCurrencyFundingHistoryIntLiquidationLeverage
MarginModeMarginModificationMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersTradeTradingFeeInterfaceTradingFeesTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)CancelPending)NotSupported)DDoSProtection)RateLimitExceeded)ExchangeNotAvailable)OnMaintenance)InvalidNonce)RequestTimeout)	TICK_SIZE)Precisec                   d    e Zd Z fdZd Zd Zdi fdZi fdZi fdee	         fdZ
de	fd	Zi fd
Zi fdefdZi fdefdZdd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fdZdddi fdedededee         fdZddedefdZd Zi fdefdZddefdZdi fdededefdZdd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&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%Z-dde	de.fd&Z/d'ddi fdedededee.         fd(Z0i fde1fd)Z2de1fd*Z3d+ Z4dde	de5fd,Z6i fded-efd.Z7di fded/e8d0e9ded1e:f
d2Z;di fded/e8d0e9ded1e:f
d3Z<i fd4ee=         fd5Z>ddi fd6eded/e8d0e9de:d1e:fd7Z?di fd6edefd8Z@di fdefd9ZAdi fdefd:ZBdi fd6edefd;ZCdddi fdedededee5         fd<ZDdddi fdedededee5         fd=ZEdddi fdededefd>ZFdddi fdededefd?ZGdddi fdededefd@ZHddefdAZIdB ZJdddi fdedededee&         fdCZKi fdefdDZLdi fde#deeM         fdEZNdde	fdFZOdddi fdededefdGZPi fdefdHZQdde	fdIZRdddi fdedededeeS         fdJZTdde	fdKZUddededeeS         fdLZVi fdedeWfdMZXdde	deWfdNZYi fdedeWfdOZZi fdedeWfdPZ[i fdede\fdQZ]dde\fdRZ^di fdSedefdTZ_di fdUedefdVZ`di fdWeadefdXZbi fdefdYZcdde	fdZZddddi fdededefd[Zei fdeded\ed]edeff
d^Zgddefd_Zhd` ZiddefdaZjdi fdbe#fdcZki fdedefddZli fdededefdeZmi fdedefdfZni fdefdgZoddede	fdhZpdddi fdedededeeq         fdiZrdde	fdjZsi fdefdkZtdde	fdlZui fdefdmZvddefdnZwddddi fdedededefdoZxdde	fdpZydi fded0e9de5fdqZzi fdeeM         fdrZ{i fdede|fdsZ}dde|fdtZ~di fduedvede:defdwZdi fd6eduedvede:def
dxZddyedzedefd{Zi fdefd|Zd} Zg d~i ddfdZ xZS )bitgetc                 $5   |                      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 dCdDdEddFddGd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djddkddlddmddnddoddpddqddrddsddtdduddvddddddddwdxdydzd{d|d}d~ddddddddyd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ddddd̜idddddddd͜iddddΜidϜi ddѓddddddՓdddddddddddddddddddddddddddddddddddddd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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ѓ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d0dd1dd2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dddddddddddddd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i d`ddaddbddcdddddeddfddgddhdѓdidѓdjdѓdkdѓdldՓdmdՓdndՓdoddpdddddddddqdddddddddddr	ddddddddddѐds
dddddddddddtiddddddddddddddddui dvdՓdwdՓdxdՓdyddzdd{dѓd|dd}dd~dddՓ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 ddddddddddddddddddddddddddѓd dddddddddddddddddddddiiddd	|                     d
          |                     d
          d|                     d          |                     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          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          d0t          d1t          d2t          d3t          i d4t
          d5t          d6t          d7t          d8t
          d9t
          d:t
          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
          d`t
          dat
          dbt"          dct
          ddt"          det"          dft
          i dgt
          dht
          dit
          djt"          dkt
          dlt
          dmt"          dnt"          dot"          dpt"          dqt"          drt
          dst
          dtt
          dut
          dvt
          dwt
          i dxt
          dyt
          dzt
          d{t
          d|t
          d}t
          d~t
          dt
          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&          dt&          dt
          dt"          dt"          dt&          dt
          dt&          dt
          dt
          dt          dt          dt          dt"          dt"          dt"          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
          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          d0t"          d1t
          d2t          i d3t          d4t"          d5t"          d6t"          d7t"          d8t"          d9t"          d:t"          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          d`t          dat          dbt
          dct          ddt
          det          i dft
          dgt          dht          dit          djt          dkt          dlt          dmt
          dnt
          dot
          dpt
          dqt"          drt(          dst          dtt"          dut
          dvt          i dwt          dxt          dyt          dzt          d{t          d|t          d}t
          d~t          dt          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          d
dt
          iddt.          ddddddi dxddddd~dddddd dddydzd{d|d}dddddddd ddddTddgddddd	dd
ddddidXddiddiddddddddddddddddddjddi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/d0d-d1dcdd2id3d4i          S (5  Nidr7   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fetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchLeverageTiersfetchLiquidationsfetchMarginAdjustmentHistoryfetchMarginModefetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionModefetchPositions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urlszdhttps://user-images.githubusercontent.com/1294454/195989417-4253ddb0-afbe-4a1c-9dea-9dbcd121fa5d.jpgzhttps://api.{hostname})rF   mixuserp2pbrokerrG   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/annoucementsz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-lever)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/currencies)zv2/earn/loan/public/coinInfosz!v2/earn/loan/public/hour-interest)r   rF   r   rG   r   zspot/v1/wallet/deposit-address   zspot/v1/wallet/withdrawal-listzspot/v1/wallet/deposit-listzspot/v1/account/getInfo   z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/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*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/reduces)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)rF   r   r   r   r   rG   r   r   r   r   r   )publicprivater   z0.002)takermaker0.0006z0.0004)rF   rH   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407684111443011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commonCurrencieszJade ProtocolDegenRebornTON)JADEDEGENTONCOINoptions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   p4sver   fillResponseFromRequestmethod publicSpotGetV2SpotMarketCandlespublicMixGetV2MixMarketCandles   4   S   x      ih    )r   r   r   10mr   r   r   r   r   r   r   r   r   r   r   )rF   rH   maxDaysPerTimeframe%publicSpotGetV2SpotMarketFillsHistory#publicMixGetV2MixMarketFillsHistoryaccountsByTypecrossed_marginisolated_marginusdt_futuresusdc_futurescoin_futuresr   )rF   crossisolatedrH   	usdc_swaprI   r   accountsByIdr  r  r  )rF   r  r  r  r  r  r   sandboxModenetworksTRC20ERC20BEP20)TRXETHBSCnetworksByIdr  )r  r  %privateMixGetV2MixPositionAllPositiondefaultTimeInForceGTC)deep_extendsuperr7   describeparse_numberr!   r0   r#   r"   r2   r&   r3   r.   r'   r$   r1   r,   r*   r%   r(   r+   r)   r/   r4   )self	__class__s    Q/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/bitget.pyr  zbitget.describe%   s=   fd 3 3 < < > > uA
(uA
HuA
 $uA
 t	uA

 uA
 uA
 4uA
  mmm $m 	m
 $m %m Tm $Tm 'm "4m tm m $Tm  m %dm  '!m" /#m m$ ,U%m& 0'm( t)m* +m, 7-m. &t/m0 (1m2 '3m4 &t5m6 (7m8 "49m: (;m< ,U=m> -d?m@ %dAmB TCmD  Em m mF GmH &tImJ +EKmL )%MmN /OmP &tQmR $TSmT )$UmV $TWmX 'YmZ ([m\ "4]m^ _m` &tamb (cmd  emf +Egm m mh *:imj +Dkml &tmmn #Domp *4qmr $Usmt "4umv *4wmx +Eymz t{m|  }m~ %em@ $UAmB /CmD "4EmF +DGmH Im m mJ !$KmL &tMmN  OmP dQmR $TSmT +EUmV "4WmX dYmZ !$[m\ "5]m^ u_m` #Eamb  cmd $Uemf !$gmh %eimj )%km m ml ummn tomp qmr Tsmt tumv "4wmx #Dymz $U{m|  }m~ !$m@ )%AmB "5CmD #DEmF GmH #DImJ &tKmL tMm mN #!%#'  Ym m muA
l  muA
L MuA
N ~43436663744  0   Ak= OuA
N  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?@78BCM'  '  ' )V KLNO?@BC;<45   	 =>AB   s_ _D <a <a  :1  6r	 
 5a  :1  >q  9!  =a  :1  9!  :1  :1  1!  6q   <Q! " ;A# $ 45@A@A4667AB56?@>?>?AB9     <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! 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! C! 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! C!h AB9::;:<@AAB>??@?@EF78BC9:@AEFEC! C! C!?c cJ0 4a0 5q0  =a0  @	0 
 :10  =a0  ?0  9!0  A!0  3A0  =a0  3A0  >q0  210  1!0   4Q!0 " 6q#0  0 $ 6q%0 & 8'0 ( 9!)0 * A!+0 , 8-0 . 3A/0 0 DQ10 2 ?30 4 :150 6 >q70 8 9!90 : 6q;0 < 8=0 > <Q?0 @ 5aA0 B 6qC0 D @E0  0 F :;34BC?@<=@A34239:;<;<@A@A_0  0  0 b;!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;! ;! ;!en nb 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 $ ?%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  2 F 89AB@ACDFGDEABDEPQRSJK<=>?AB89c2  2  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 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 5n 24464613	    67789:@A>?    1267! !    5q 5q  5a  6q	 
 =a  ?  <Q  7  7  6q  7  >q  @  :1  9!   :1! " :1# $ 3445'     , :;67:;3423:;! !- @ 2A Eg gCI	 I	OuA
b !..w77!..w77 
 "..x88!..x88 	 	cuA
v " $ $wuA
@ uu CDXu ,	u Mu Mu 0u 0u 0u 0u \u 0u  Z!u" ^#u$ ]%u& 0'u( -)u* 0+u u, 0-u. ^/u0 01u2 ]3u4 ]5u6 ]7u8 19u: Z;u< Z=u> -?u@ ZAuB YCuD ZEuF ^GuH 0IuJ -KuL -Mu u uN ]OuP ZQuR YSuT ZUuV ]WuX ]YuZ ][u\ 1]u` ]aud -euf -guh ]iuj ]kul \mun \oup \qur \su u ut \uuv ]wux ]yuz ]{u| ]}u~ ]u@ ]AuB ]CuD ]EuF ]GuH ]IuJ ]KuL ]MuN ]OuP ]QuR ]SuT ]Uu u uV ]WuX ]YuZ -[u\ ]]u^ \_u` .aub 0cud ]euf ]guh ]iuj ]kul ]mun \oup ]qur \sut \uuv ]wu u ux ]yuz ]{u| ]}u~ \u@ ]AuB ]CuD \EuF \GuH \IuJ \KuL \MuN ]OuP ]QuR ]SuT ]UuV ]WuX ]Yu u uZ ][u\ ]]u^ ]_u` ]aub ]cud ]euf ]guh ]iuj ]kul ]mun ]oup ]qut -uuv -wux .yuz ]{u| ]}u u u~ ]u@ ]AuB .CuD ]EuF ]GuH ]IuJ ]KuL \MuN ]OuP \QuR ]SuT .UuV ]WuX ]YuZ Z[u\ \]u^ ]_u u u` \aub \cud ]euf \guh \iuj \kul ]mun ]oup ]qur ]sut ]uuv ]wux ]yuz ]{u| ]}u~ ]u@ ]Au u uB ]CuD ]EuF ]GuH ]IuJ ]KuL ]MuN ]OuP ZQuR ZSuT ]UuV ]WuX ]YuZ ][u\ ]]u` ]aub -cud ^eu u uf ]guh ]iuj ]kul ]mun ]oup .qur ]sut ]uuv ]wux ]yuz ]{u| ]}u~ ]u@ -AuB -CuD 0EuF -Gu u uH -IuJ ^KuL ]MuN -OuP ]QuR ]SuT ]UuV ]WuX ]Yu\ ]]u^ ]_u` ]aub ]cud 0euf \guh \iuj \ku u ul \mun \oup ]qur \sut \uuv \wux ]yuz ]{u| .}u~ ]u@ ]AuB \CuD \EuF ]GuH ]IuJ ]KuL \Mu u uN ]OuP .QuR .SuT ]UuV \WuX \YuZ .[u\ ]]u^ ._u` ]aub ]cud Zeuf Zguh Ziuj \kul \mun \ou u up \qur \sut \uuv \wux \yuz \{u| \}u~ \u@ \AuB \CuD \EuF \GuH \IuJ \KuL \MuN \OuP \Qu u uR \SuT \UuV \WuX \YuZ \[u\ \]u^ \_u` ]aub ]cud ]euf ]guh ]iuj Zkul ]mun ]oup ]qur ]su u uv Zwux Zyuz ]{u| 0}u~ -u@	 -A	uB	 -C	uD	 -E	uF	 -G	uH	 -I	uJ	 .K	uL	 -M	uN	 -O	uP	 -Q	uR	 \S	uT	 ]U	uV	 ZW	u u uX	 ZY	uZ	 \[	u\	 \]	u^	 \_	u`	 \a	ub	 \c	ud	 \e	uf	 \g	uh	 ]i	uj	 ]k	ul	 \m	un	 \o	up	 \q	ur	 \s	ut	 \u	uv	 \w	ux	 \y	u u uz	 \{	u|	 \}	u~	 \	u@
 \A
uB
 \C
uD
 \E
uF
 \G
uL
 :M
uN
 .O
uP
 +Q
uR
 :S
uT
 :U
uV
 :W
uX
 >Y
uZ
 /[
u\
 -]
u^
 M_
u u u`
 Ma
ud
 0e
uf
 0g
uh
 0i
uj
 \k
ul
 \m
un
 0o
up
 Zq
ur
 \s
ut
 0u
uv
 0w
ux
 0y
uz
 0{
u|
 ]}
u~
 -
u@ ]AuB -Cu u uD ]EuF -GuH ZIuJ -KuL 0MuN ZOuP ZQuR ]SuT ]UuV ]WuX ]YuZ \[u\ ]]u^ ]_u` \aub ]cud Zeu u uf Zguh Ziuj Zkul Zmun Zoup Zqur ]sut -uuv Zwux Zyuz Z{u| Z}u~ ]u@ ]AuB YCuD ]EuF ]Gu u uH ZIuJ ZKuL ZMuN ZOuP ZQuR ]SuT ]UuV ]WuX \YuZ ][u\ ]]u^ ]_u` ]aub ]cud 0euf 0guh ]iu u uj ]kul ]mun ]oup ]qur ]sut 1uuv ]wux ]yuz ]{u| ]}u~ ]u@ ZAuB ]CuD ]EuF ]GuH ]IuJ ZKu u uL \MuN ZOuP ZQuR ]SuT ]UuV .WuX .YuZ ][u\ ]]u^ ]_u` ]aub \cud .euf \guh ]iuj \kun #$7ou u up '	qur %isut %juuv #Mwux %lyuz #L{u| &|}u~ %mu@ (AuB &zCuD )*=EuF ()<GuH $%8IuJ GKuL ,-=MuN +,?OuP "#3Qu u uR 45FSuT 5jUuV DZWuX 3MYuZ "#3[u\ 67G]u^ Ej_u` Ejaub <=Mcud (euf (guh &}iuj ./Bkul -mmun #Moup /
qur +Lsu u ut 'uuv 5mwux *+<yuz /{u| '}u~ ]u@ YAuB -CuD -EuF ^GuH .IuJ ]KuL \MuN \OuP \QuR \SuT \Uu uV *.))0=*4(2**-iu u un 0{@ @AuA
B( YC(uA
D( '& ! !E(uA
N(  m$$&&""%'%%%%  #""$$"""%'%%%%  mB !CmJ vKmL !(MmN 4TOmP 'QmR -tSmX  "D !"B !  !!! !!!"!""", , YmJ  "I !"G	   KmZ !"- 1*!/, # #[ml "&-'1$*$/$, ! !mm~ um@ """ AmJ ""! !KmR !E#SmX %eYmO(uA
 uA
 u u u	    c                     || j         d<   d S )Nr  )r  )r  enableds     r  set_sandbox_modezbitget.set_sandbox_mode  s    &-]###r  c                    |                     d          r|S d }|                    d          dk    r|                    d          dk    rt          | j        dz             |                    d          }|                     |d          }|                     |d          }|                    d          }|                     |d          }|                     |d          }|                    d          }	|                     |	d          }
|                     |	d          }d|z   d	z   |z   d
z   |
z   }||dz   |z   }n|dd         }|dd          }d|z   dz   |z   }|S )NS/:z. sandbox supports swap and future markets onlyr   r   -z/Sz:S   )
startswithfindr-   r9   splitsafe_string)r  symbolconvertedSymbol	splitBasepreviousBasepreviousQuoteSettleExpiry
splitQuotepreviousQuotepreviousSettleExpirysplitSettlepreviousSettleexpirybase	remainings                 r  convert_symbol_for_sandboxz!bitget.convert_symbol_for_sandbox  s   S!! 	M;;sb  {{32%%"47-]#]^^^S))I++Iq99L(,(8(8A(F(F%288==J ,,Z;;M#'#3#3J#B#B .44S99K!--k1==N%%k155F!L047-G$NQ__O!"1C"7&"@ !A#;Dqrr
I!Dj3.:Or  Nc                    d }|                      dd |          \  }}d }|5|3|                     | j        dd          }|r|dk    rdnd}n
|dk    rdnd}|                     |d	|          }|E|C|d
         }|dk    rd}n2|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             |                     |d	          }||gS )NhandleProductTypeAndParamsr  Fr  SUSDT-FUTURESSCOIN-FUTURESUSDT-FUTURESCOIN-FUTURESproductTypesettleUSDTUSDCUSDC-FUTURESSUSDTSUSDCSUSDC-FUTURESSBTCSETHSEOSz 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_boolr  r  r%   r9   omit)r  marketparamssubTypedefaultProductTyper  r	  r
  s           r  handle_product_type_and_paramsz%bitget.handle_product_type_and_params  sk   99:VX\^dee!fn..}eLLK a9@H9L9L__Sb""8?88K8K^^R`"&&v}>PQQf&8H%F,6!!,7""-7""-F""&(8(8f>N>N-,#DG  /z  %z  {  {  {6=11V$$r  c                     |                      |          }|                     |di           }|                     |d          S )a]  
        fetches the current integer timestamp in milliseconds from the exchange server
        :see: 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  sD     33F;; x44  |444r  returnc                    |                      | j        dd          }|                     | j        dddg          }|rdg}g }t          dt	          |                    D ]}||         }|dk    rsd}|rg d}ng d	}t          dt	          |                    D ]G}|                    |                     ||                     |d
||         i                               H|                    |                     ||         |                     |}|d         }	t          dt	          |                    D ]}|                     |	||                   }	|	S )aq  
        retrieves data on all markets for bitget
        :see: https://www.bitget.com/api-doc/spot/market/Get-Symbols
        :see: https://www.bitget.com/api-doc/contract/market/Get-All-Symbols-Contracts
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r  Fr   rF   rH   r   N)r  r  r  )r  r  r  r	  r   )	r  r  r   rangelenappendfetch_markets_by_typeextendarray_concat)
r  r  r  typespromisesitypesubTypesjresults
             r  fetch_marketszbitget.fetch_markets  s    nnT\=%HHnvv>NOO 	HEq#e**%% 	N 	NA8Dv~~ PRRRHHOOOHq#h--00  AOOD$>$>tT[[QW%x{Z F F % %    
  : :58V L LMMMM!q#h--(( 	< 	<A&&vx{;;FFr  c                 j	   |                      |d          }|                      |d          }|                      |d          }|                     |          }|                     |          }|                     |dg           }d }|                     ||          r|}n/|                     ||          r|}n|                      |d          }|                     |          }	|dz   |z   }
d }d}d}d}d}d }d }d }d }d }d }|                      |d          }|~d	}d
}|                     |                     |                      |d                              }|                     |                     |                      |d                              }n|dk    rd}d
}|
dz   |	z   }
n|dk    r|                     |d          }|                     |          }|                    d          }|                      |d          }|                      |d          }|dd         }|                      |d          }|dd         }||z   |z   }d}d
}|
dz   |	z   dz   |z   }
d
}||	k    }| }|                     |d          }|                     |d          }|                      |d          } |                      |d          }!t          |           }"t          |"j        |          |"_        |"                                 t          |"          }#|                     |#          }t          |!          }$t          |$j        |          |$_        |$                                 t          |$          }%|                     |%          }|                     |dd          }&d }'|&|&dk    p|&dk    }'d }(|dk    r|                     |d           }(|rdn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 ||d0|                     |d1          |                     |d2          d3|                     |dd4          |                     |d5          d3d d d3|(d d3d6|                     |d7          |d8S )9Nr  	quoteCoinbaseCoinsupportMarginCoinsr   r  F
symbolTyperF   TpricePrecisionquantityPrecision	perpetualrH   r  deliverydeliveryTimer  r   r   r   rI   
pricePlacevolumePlacepriceEndStepminTradeNumstatussymbolStatusonlinenormalr  minTradeUSDTr9   r   quoter
  baseIdquoteIdsettleIdr/  rG   rJ   activecontractr  takerFeeRatemakerFeeRate)amountpriceminLevermaxLeverminmaxminTradeAmountmaxTradeAmount)leveragerO  rP  cost
launchTime)inverser   r   contractSizer  expiryDatetimestrike
optionType	precisionlimitscreatedinfo)r  safe_currency_coder   in_arrayr  parse_precisionr!  iso8601r  r5   rU  decimalsreducestrsafe_string_2safe_numbersafe_number_2)*r  r  marketIdrI  rH  rG  r   r7  rJ  r
  r  r/  rH   rF   rI   rL  r9  amountPrecisionr  r[  r  r]  r8  expiryPartsyearPartdayPartyearmonthdayexpiryStringpriceDecimalsamountDecimals	priceStep
amountStepprecisePricepriceStringpreciseAmountamountStringrB  rK  minCostr\  s*                                             r  parse_marketzbitget.parse_market  s   t ##FH55""6;77!!&*55''00&&v..!__V5I2NN==!344 	?HH]]7$677 	?HH''(:A>>H((22e#%%fl;;
DD!..t/C/CDDTDTU[]mDnDn/o/oppN"//0D0DTEUEUV\^qErEr0s0sttOO[((#.z))**6>BB!%f!5!5,22377++K;;**;::!}((a88acl#e|c1#.4|CHv~G [F --flCCM!..v}EEN((@@I))&-@@J"9--L$'(=}$M$ML!!!!l++K!..{;;N#J//M%()?%P%PM"  """}--L"//==O##FHnEE)Bv/AFF??&&v~>>G$.qq$2
(2
f2
 D2
 U	2

 f2
 f2
 w2
 2
 D2
 D2
 d2
 D2
 f2
 e2
 f2
  !2
" f#2
$ %%fn==%%fn==(,)'   ++FJ??++FJ?? 
  --fmEUVV++F4DEE 
   
 #  $ ((>>c2
 2
 2
 2	
r  c                    d }|dk    r|                      |          }n?|dk    s|dk    r|                     |          }nt          | j        dz   |z   dz             |                     |dg           }|                     |          S )NrF   rH   rI    does not support  marketr  ) publicSpotGetV2SpotPublicSymbols publicMixGetV2MixMarketContractsr-   r9   r   parse_markets)r  r/  r  r"  r  s        r  r)  zbitget.fetch_markets_by_type  s    6>><<VDDHHfnn$("2"2<<VDDHHtw)==DyPQQQP x44!!$'''r  c                    |                      |          }i }|                     |dg           }t          dt          |                    D ]3}||         }|                     |d          }|                     |          }|                     |dg           }	i }
d}d}d}d}d}t          dt          |	                    D ]`}|	|         }|                     |d          }|                     |          }|                     |d          }|d	k    }|r|n|}|                     |d
          }|d	k    }|r|n|}|                     |d          }|||nt          j        ||          }|                     |d          }|||nt          j        ||          }|                     |d          }|||nt          j        ||          }||||                     |          dd|                     |          ddd|o||||                     |          dd	|
|<   b||||
dd|o||||                     |          dddd|                     |          dd|                     |          ddddd||<   5|S )a  
        fetches all available currencies on an exchange
        :see: 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   coinchainsFNchainwithdrawabletruerechargeablewithdrawFeeminWithdrawAmountminDepositAmountrS  )r   deposit)	rc  r9   networkra  rK  r   r  feer`  rO  r   r  rc  r9   coder  r/  r:   rK  r  r   r  r`  ra  rb  )	publicSpotGetV2SpotPublicCoinsr   r&  r'  r  rd  r5   
string_minr  )r  r  r"  r2  r  r.  entryr9   r  r  r  r  r   minWithdrawStringminDepositStringminWithdrawFeeStringr1  r  	networkIdr  withdrawEnabledcanWithdrawdepositEnabled
canDepositnetworkWithdrawFeeStringnetworkMinWithdrawStringnetworkMinDepositStrings                              r  fetch_currencieszbitget.fetch_currencies  s    66v>>< x44q#d))$$ M	 M	AGE!!%00B**2..D__UHb99FHGH $##' 1c&kk** & &q	 ,,UG<<	11)<<"&"2"25."I"I-7+6E;;X!%!1!1%!H!H+v5
)3A**'+/+;+;E=+Q+Q(+7H\Hd+C+Ckrk}  W  Ym  ln  ln(+/+;+;ECV+W+W(+7EVE^(@(@elew  yQ  Sd  fe  fe%*.*:*:5BT*U*U'*6CSC['>'>bibt  vM  O_  c`  c`$!#& $(#4#45M#N#N#'% %
 $(#4#45L#M#M#'$ $	 	 *8j +),,-EFF!%%% %!!* $!.h"$(()=>>!  $# 
  $001BCC#! !
  $001ABB#      5 F4LL8 r  r  c                 .   |                                   |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }i }d}d}|                     d|d          \  }}|d         s|d         rUd}	|                     ||          \  }	}|	|d<   |d	         |d
<   |                     |                     ||                    }n|dk    r5|d	         |d
<   | 	                    |                     ||                    }n|dk    r| 
                    |d          }
|
t          | j        dz             |                     |d          }|                     |
          }|d	         |d<   |                     |                     ||                    }n t!          | j        dz   |d
         z             |                     |dg           }|                     ||          S )a  
        retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes for a single market
        :see: https://www.bitget.com/api-doc/contract/position/Get-Query-Position-Lever
        :see: https://www.bitget.com/api-doc/margin/cross/account/Cross-Tier-Data
        :see: 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>`
        r  FNr   r  rH   rI   r	  r9   r  r  r  z4 fetchMarketLeverageTiers() requires a code argumentr  z; fetchMarketLeverageTiers() symbol does not support market r  )load_marketsr  r  r  r  handle_margin_mode_and_paramsr  )publicMixGetV2MixMarketQueryPositionLeverr*  (privateMarginGetV2MarginIsolatedTierDatar  r%   r9   r  currency'privateMarginGetV2MarginCrossedTierDatar&   r   parse_market_leverage_tiers)r  r  r  r  r  sandboxSymbolrequestr"  
marginModer	  r  r  r2  s                r  fetch_market_leverage_tiersz"bitget.fetch_market_leverage_tiers  s4    	nnT\=%HH 	) ;;FCCM[[//FF[[((F
!??@Z\bdnoo
F6N 	yx 0 	yK"&"E"Eff"U"UK%0GM" &tGHEEdkkRY[aFbFbccHH:%% &tGHDDT[[QXZ`EaEabbHH7""##FF33D|'2h(hiiiYYvv..F}}T**H&tnGFOCCDKKPWY_D`D`aaHHTW'ddgmnvgwwxxxt 6266//???r  r  c                    g }d}t          dt          |                    D ]}||         }|                     |d          }||}|                     |g d          }|                     |dd          }	|	|	n|d         }
|                    |                     |dd          |                     |
          |||                     |d	d
          |                     |d          |d           |}|S )Nr   	startUnit)endUnitmaxBorrowableAmountbaseMaxBorrowableAmountr  r6  r   leveltierkeepMarginRatemaintainMarginRaterX  )r  r  minNotionalmaxNotionalmaintenanceMarginRatemaxLeveragerc  )	r&  r'  rl  safe_number_nrk  r(  safe_integer_2rd  rm  )r  rc  r  tiersr  r.  itemminimumNotionalr  marginCurrency
currencyIds              r  r  z"bitget.parse_market_leverage_tiers  s$   J q#d))$$ 	& 	&A7D"..t[AAO*-,,T3p3p3pqqK!//fjIIN,:,FVTZ^JLL++D'6BB 33J??**)-););DBRTh)i)i#//jAA     &KKr  r  sincelimitc                 \   |                                   d}|                     |dd          \  }}|r|                     dd|||dddd	  	        S |t          | j        dz             |                     |          }||                                 dz
  }|d	         ||                                 d
}|||d<   |                     d||          \  }}|                     | 	                    ||                    }| 
                    |dg           }	|                     |	|||          S )a  
        fetch all deposits made to an account
        :see: 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>`
        Frv   paginateN
idLessThand   z+ fetchDeposits() requires a `code` argument    X r9   r  	startTimeendTimer  r  r  )r  handle_option_and_paramsfetch_paginated_call_cursorr%   r9   r  millisecondshandle_until_option(privateSpotGetV2SpotWalletDepositRecordsr*  	safe_listparse_transactions
r  r  r  r  r  r  r  r  r"  rawTransactionss
             r  fetch_depositszbitget.fetch_deposits6  sh    	88R\]]& 	H33OT5RWY_amo{  ~B  DG  H  H  H<#DG.[$[\\\==&&=%%''*4ETN((**
 

 $GG229gvNN@@WV\A]A]^^0 ..62>>&&%OOOr  rO  c                    |                      |           |                     |dd          }|                     |d          }|t          | j        dz             |                                  |                     |          }|                     |          }|d         |||dd}	|||	d<   |                     | 	                    |	|                    }
| 
                    |
d	i           }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}| 
                    | j        di           }|                     |dd          }|r_||d<   |                                 |d<   |                     |                                           |d<   ||d<   ||d<   ||d<   ||d<   ||d<   |S )a7  
        make a withdrawal
        :see: 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>`
        r  r  Nz= withdraw() requires a chain parameter or a network parameterr9   on_chain)r  addressr  sizetransferTypetagr  orderIdrc  txid	timestampdatetimeaddressFromr  	addressTorO  r/  
withdrawalr  rB  updatedtagFromtagTo)commentr  r   r  T)check_addressrk  r  r%   r9   r  r  network_code_to_id%privateSpotPostV2SpotWalletWithdrawalr*  r   r  r  r  r  rg  )r  r  rO  r  r  r  r  r  r  r  r"  r  r2  withdrawOptionsr  s                  r  r   zbitget.withdrawp  s    	7###""67I>>69--=#DG.m$mnnn==&&++E22	TN&
 
 ? GEN==dkk'SY>Z>Z[[ x44
$""433
H
 D
 	

 
 t
 4
 t
 
 d
 L
 
 d
 t
 t
  4!
" T#
$ '
 
 
* //$,
BGG"&..B[]a"b"b" 	&!%F:"&"3"3"5"5F;!%d.?.?.A.A!B!BF:%F8F5M 'F9")F; %F9r  c                 \   |                                   d}|                     |dd          \  }}|r|                     dd|||dddd	  	        S |t          | j        dz             |                     |          }||                                 dz
  }|d	         ||                                 d
}|                     d||          \  }}|||d<   |                     | 	                    ||                    }| 
                    |dg           }	|                     |	|||          S )a  
        fetch all withdrawals made from an account
        :see: 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  z. fetchWithdrawals() requires a `code` argumentr  r9   r  r  r  r  )r  r  r  r%   r9   r  r  r  +privateSpotGetV2SpotWalletWithdrawalRecordsr*  r  r  r  s
             r  fetch_withdrawalszbitget.fetch_withdrawals  sk    	88ASU_``& 	K334FeUZ\bdpr~  AE  GJ  K  K  K<#DG.^$^___==&&=%%''*4ETN((**
 

 229gvNN$GGCCDKKPWY_D`D`aa6 ..62>>&&%OOOr  r  c                    |                      |d          }|                     ||          }|                     |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }	t          j        |	          }
d }|                      |d          }|
-||                     |
          d}t          j        ||
          }i d	|                      |d
          d|d|                      |d          d|d|                     |          d|                     |          d|                      |d          d|                      |d          d|                      |d          d|                     |          d|                      |d          d|d| 	                    |          d|                     |d          dd d|d|d d |dS )Nr  cTimer  rB  r  r  r  )r  rY  r9   r  rc  r  tradeIdr  r  r  r  fromAddressr  	toAddressr  rO  r/  r  r  uTimer  r  )r  internalr  )
r  rd  r!  r5   
string_absr  
string_subrg  network_id_to_codeparse_transaction_status)r  transactionr  r  r  r  r  rB  r  feeCostStringfeeCostAbsStringr  r~  s                r  parse_transactionzbitget.parse_transaction  s   N %%k6::
&&z8<<%%k7;;	$$['::	!!+x88{E22((e<<"-m<<''V<<'#T->->?O-P-PQQC"-l<LMML
$"";	::
K
 D$$[)<<
 	

 Y//
 t..y99
 4++KGG
 t''[AA
 ))+{CC
 d''55
 D$$[&99
 
 d33F;;
 t((g>>
 t
  3!
" S#
$ )
 
 
 	
r  c                 @    dddddd}|                      |||          S )Nokpendingfailed)successPendingpending_reviewpending_review_failrejectr  r  rB  statusess      r  r  zbitget.parse_transaction_statusD	  s7     '#+
 
 &&999r  c                    |                                   |                     |dd          }|                     |d          }d}||                     ||          }|                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |di           }|                     ||          S )a  
        fetch the deposit address for a currency associated with self account
        :see: 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>`
        r  r  Nr  r9   r  )	r  rk  r  r  r  (privateSpotGetV2SpotWalletDepositAddressr*  	safe_dictparse_deposit_address)	r  r  r  networkCoder  r  r  r"  r  s	            r  fetch_deposit_addresszbitget.fetch_deposit_addressN	  s     	(()DD69--	"//TBBI==&&HTN
  (GG@@WV\A]A]^^ ~~h33))$999r  c                    |                      |d          }|                      |d          }|                     ||          }d }||                     ||          }||                      |d          |                      |d          ||dS )Nr  r  r  r  )r  r  r  r  rc  )r  rd  r  )r  depositAddressr  r  r  parsedCurrencyr  s          r  r  zbitget.parse_deposit_addresst	  s     %%nf==
$$^W==	00XFF --iHHG&''	BB##NE::"
 
 	
r  c                    |                                   |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }d|d         i}|||d<   d}|d         r*|                     |                     ||                    }nId}	|                     ||          \  }	}|	|d<   |                     |                     ||                    }| 	                    |d	i           }
| 
                    |
d
          }|                     |
|d         |          S )a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://www.bitget.com/api-doc/spot/market/Get-Orderbook
        :see: 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  FNr  r9   r  rF   r	  r  ts)r  r  r  r  r  "publicSpotGetV2SpotMarketOrderbookr*  r  !publicMixGetV2MixMarketMergeDepthr   r!  parse_order_book)r  r  r  r  r  r  r  r  r"  r	  r  r  s               r  fetch_order_bookzbitget.fetch_order_book	  s]    	nnT\=%HH 	) ;;FCCM[[//FF[[((FfTl
 $GG&> 	\>>t{{7TZ?[?[\\HHK"&"E"Eff"U"UK%0GM"==dkk'SY>Z>Z[[H x44%%dD11	$$T6(+;YGGGr  c                    |                      |d          }|                      |d          }|                     |                      |d                    }d }||                     |          }|                      |d          }|                      |d          }|                      |d          }	|	|                     ||d d          }
|}n|                     ||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t          j        |d          dd |                      |d          |                      |d           |d!|          S )"Nr  lastPrr  	change24hopen24openrL  rF   r  r  highhigh24hlowlow24hbidbidPr	bidVolumebidSzaskaskPr	askVolumeaskSzvwapcloselastpreviousClosechange
percentage100average
baseVolumequoteVolume)r5  r6  rc  )r  	omit_zeroparse_to_intsafe_symbolsafe_tickerrg  r5   
string_mul)r  tickerr  rn  r.  timestampStringr  r1  r  r   r  	openValues               r  parse_tickerzbitget.parse_ticker	  s   N ##FH55  22..)9)9&$)G)GHH	&))/::I!!&+66!!&(33// <%%hjIIFII%%hfEEFI !
f!
!
 Y//!
 D$$VY77	!

 4##FH55!
 4##FG44!
 ))&'::!
 4##FG44!
 ))&'::!
 D!
 I!
 U!
 E!
 T!
 f!
  ',VU;;!!
" t#!
$ **6<@@++FMBB)!
 !
 !
* +  	r  c                 ^   |                                   |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }d|d         i}d}|d         r*|                     |                     ||                    }nId}|                     ||          \  }}||d<   |                     |                     ||                    }| 	                    |dg           }	| 
                    |	d	         |          S )
a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: https://www.bitget.com/api-doc/spot/market/Get-Tickers
        :see: 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  FNr  r9   rF   r	  r  r   )r  r  r  r  r   publicSpotGetV2SpotMarketTickersr*  r  publicMixGetV2MixMarketTickerr  r?  )
r  r  r  r  r  r  r  r"  r	  r  s
             r  fetch_tickerzbitget.fetch_ticker*
  s5    	nnT\=%HH 	) ;;FCCM[[//FF[[((FfTl
 &> 	X<<T[[RX=Y=YZZHHK"&"E"Eff"U"UK%0GM"99$++gv:V:VWWH@ ~~h33  a&111r  symbolsc                    |                                   d}|t|                     |d          }|                     | j        dd          }|r+|                     |          }|                     |          }n|                     |          }d}i }d}	|                     d||          \  }	}|                     |d          }
d}|                     ||          \  }}|	dk    r,|
*| 	                    | 
                    ||                    }n.||d<   |                     | 
                    ||                    }|                     |d	g           }|                     ||          S )
aO  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: https://www.bitget.com/api-doc/spot/market/Get-Tickers
        :see: 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  Fr   r  rF   r	  r  )r  r   r  r  r  r  handle_market_type_and_paramsr  r  rA  r*  publicMixGetV2MixMarketTickersr  parse_tickers)r  rD  r  r  r  r  r  r"  r  r/  passedSubTyper	  r  s                r  fetch_tickerszbitget.fetch_tickers
  sw    	__Wa00F..}eLLK - $ ? ? G G]33V,,99.&RXYYf ((;;"AA&&QQV6>>m3<<T[[RX=Y=YZZHH%0GM"::4;;wPV;W;WXXHt ~~h33!!$000r  c                    |                      |d          }|                     ||          }|                     |dd          }d }|                     |d          }|                      |d          }||d         n|}	|	z|                     |                      |	d                    }
d|
i}|                      |	d	          }|                      |	d          du }|r||d<   nt          j        |          |d<   |                     ||                      |d          |                      |d          ||                     |d          |                      |d          |                      |d          | 	                    |dd          | 	                    |dd          | 	                    |dd          || 
                    |          |d|          S )Nr  r  r  	feeDetailposModer   feeCoinr  totalFeeyes	deductionTFrY  r  r  side	orderType
tradeScopepriceAvgrP  r5  r  r6  rO  )rc  r9   orderr  rR  r/  takerOrMakerrP  rO  rY  r  r  r  )r  r9  r  r   rd  r5   
string_neg
safe_tradesafe_string_lowerrk  rg  )r  trader  rn  r  r  r  rL  rM  feeStructurecurrencyCoder  rQ  s                r  parse_tradezbitget.parse_trade
  s   f ##E844!!(F33''w==	OOE;77	""5)44(/(;y||)#2243C3CLR[3\3\]]LLC !,,\:FFM(({CCtKI @+F%0??F""5)44%%eY77**5&99$$UK88 ,,ULAA''z7CC((fEE&&umXFF"Y// 
  
   	r  c           	         |                                   d}|                     |dd          \  }}|r|                     d||||dd          S |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }d|d         i}	|!|d	         rt          |d
          |	d<   n||	d<   |                     | j        di           }
d}|d         r|                     |
di           }| 	                    |dd          }| 	                    |d|          }| 
                    |d          }|dk    rL|                     d|	|          \  }	}|||	d<   |                     |                     |	|                    }n+|dk    r)|                     |                     |	|                    }n|                     |
di           }| 	                    |dd          }| 	                    |d|          }| 
                    |d          }d}|                     ||          \  }}||	d<   |dk    rK|                     d|	|          \  }	}|||	d<   |                     |                     |	|                    }n/|dk    r)|                     |                     |	|                    }|                     |dg           }|                     ||||          S )a  
        get the list of most recent trades for a particular symbol
        :see: https://www.bitget.com/api-doc/spot/market/Get-Recent-Trades
        :see: https://www.bitget.com/api-doc/spot/market/Get-Market-Trades
        :see: https://www.bitget.com/api-doc/contract/market/Get-Recent-Fills
        :see: 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  Nr  r9   rL  r  r  rF   r  r  r  r  publicSpotGetV2SpotMarketFillsrH   r  r	  publicMixGetV2MixMarketFillsr  )r  r  r  r  r  r  r  rT  r   r  r  r  r  r*  r`  r  r  ra  r  parse_trades)r  r  r  r  r  r  r  r  r  r  r  r"  spotOptionsdefaultSpotMethod
spotMethodswapOptionsdefaultSwapMethod
swapMethodr	  r  s                       r  fetch_tradeszbitget.fetch_trades^  sQ    	88PZ[[& 	}33M65RWY_amo{|||nnT\=%HH 	) ;;FCCM[[//FF[[((FfTl
 j! )#&ud#3#3  #( //$,rBB&> 	[//'62>>K $ 0 0hHo p p))&(<MNNJYYvx00FDDD"&":":9gv"V"V$+0GK(EEdkkRY[aFbFbcc???>>t{{7TZ?[?[\\//'62>>K $ 0 0hHm n n))&(<MNNJYYvx00FK"&"E"Eff"U"UK%0GM"BBB"&":":9gv"V"V$+0GK(CCDKKPWY_D`D`aa===<<T[[RX=Y=YZZL ~~h33  vue<<<r  c                    |                                   |                     |          }d|d         i}d}|                     d|          \  }}|d         r|d|d<   nd|d<   nd|d<   |                     |                     ||                    }|                     |d	i           }|                     ||          S )
a  
        fetch the trading fees for a market
        :see: 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  r9   Nr   rF   rG   businessTyperL  r  )r  r  r  !privateCommonGetV2CommonTradeRater*  r   parse_trading_fee)r  r  r  r  r  r  r"  r  s           r  fetch_trading_feezbitget.fetch_trading_fee  s     	V$$fTl
 
!??@QSYZZ
F&> 	1%*2''*0''&0GN#99$++gv:V:VWW x44%%dF333r  c                 b   |                                   d}d}d}|                     d|          \  }}|                     dd|          \  }}|dk    r]|                     |dd          }|                     |d          }||r|                     |          }nu|                     |          }n_|dk    s|dk    r6d}|                     d|          \  }}||d<   |                     |          }nt          | j
        d	z   |z   d
z             |                     |dg           }i }t          dt          |                    D ]h}	||	         }
|                     |
d          }|                     |dd|          }|                     |          }|                     |
|          }|||<   i|S )a  
        fetch the trading fees for multiple markets
        :see: https://www.bitget.com/api-doc/spot/market/Get-Symbols
        :see: https://www.bitget.com/api-doc/contract/market/Get-All-Symbols-Contracts
        :see: 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   rF   rG   FrH   rI   r	  r  r  r  r   r  )r  r  rF  r  r  !publicMarginGetV2MarginCurrenciesr  r  r  r-   r9   r   r&  r'  r  r9  r  rm  )r  r  r"  r  
marketTyperG   r	  r  r2  r.  r  rn  r  r  r  s                  r  fetch_trading_feeszbitget.fetch_trading_fees  s    	

!??@RTZ[[
F!??@RTXZ`aa
F^^FHe<<FYYvx00F&6&AA&II@@HHF""
h(>(>K"&"E"EdF"S"SK$/F=!<<VDDHHtw)==
JYVWWWP x44q#d))$$ 	! 	!AGE''x88H%%hdJGGF[[((F((77C F6NNr  c                     |                      |d          }||                     ||          |                     |d          |                     |d          d d dS )Nr  rN  rM  )rc  r  r   r   r2  	tierBasedr  r9  rl  )r  r  r  rn  s       r  rm  zbitget.parse_trading_fee]  sh    ##D(33&&x88%%dN;;%%dN;;
 
 	
r  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r   r   r  r      )r!  rl  )r  ohlcvr  s      r  parse_ohlcvzbitget.parse_ohlcvh  s     eQ''UA&&UA&&UA&&UA&&UA&&
 	
r  r   c           	         |                                   d}d}d}d}	|                     |dd          \  }	}|	r|                     d||||||          S |                     | j        dd          }
d}|
r+|                     |          }|                     |          }n|                     |          }|d	         rd	nd
}| j        d         |         }d}|                     |          dz  }|d         |                     |||          d}| 	                    |dd          }|du}|du}|du}| 
                    |ddg          }d}|                                 }|                     | j        di           }|                     |di           }|                     ||d          }|||z  z
  }|rt          ||          }||d<   n|}||z  }d}d}|r$|}||d<   |s|                     ||          }||d<   |r|}||d<   |s||z
  }|duo||k    }|r|rt          ||          |d<   |d	         rX|r+|                     |                     ||                    }nH|                     |                     ||                    }nd} |rc|s+t          ||                     || |z                      |d<   n6||z
  | |z  k    r*t'          | j        dz   t+          |           z   dz             d}!|                     |d          \  }!}d}"|                     ||          \  }"}|"|d<   |                     ||          }#|!dk    r|                     |#          }nI|!dk    r|                     |#          }n-|r|                     |#          }n|                     |#          }|dk    rg S |                     |d|          }$|                     |$||||          S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :see: https://www.bitget.com/api-doc/spot/market/Get-Candle-Data
        :see: https://www.bitget.com/api-doc/spot/market/Get-History-Candle-Data
        :see: https://www.bitget.com/api-doc/contract/market/Get-Candle-Data
        :see: https://www.bitget.com/api-doc/contract/market/Get-History-Candle-Data
        :see: https://www.bitget.com/api-doc/contract/market/Get-History-Index-Candle-Data
        :see: 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.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   Fr   r  r  NrF   rH   r    \&r9   )r  granularityuntiltillr  r  r  r  r  Z   z6 fetchOHLCV() between start and end must be less than z daysrP  r	  markindex r  )r  r  "fetch_paginated_call_deterministicr  r  r  r  parse_timeframer  r  r  r  r  r!  rT  sum'publicSpotGetV2SpotMarketHistoryCandlesr*  r  r&   r9   rj  handle_param_stringr  )publicMixGetV2MixMarketHistoryMarkCandles*publicMixGetV2MixMarketHistoryIndexCandles%publicMixGetV2MixMarketHistoryCandlesr  r  parse_ohlcvs)%r  r  	timeframer  r  r  defaultLimitmaxLimitForRecentEndpointmaxLimitForHistoryEndpointr  r  r  r  rq  r   msInDaydurationr  r}  limitDefinedsinceDefineduntilDefinedr"  nowohlcOptionsretrievableDaysMapmaxRetrievableDaysForRecentendpointTsBoundarylimitMultipliedDurationcalculatedStartTimecalculatedEndTimehistoricalEndpointNeededmaxDistanceDaysForContracts	priceTyper	  extendedr  s%                                        r  fetch_ohlcvzbitget.fetch_ohlcv}  s   & 	$(!%("88zZZ& 	N::<QVX]_hjp  sM  N  N  NnnT\=%HH 	) ;;FCCM[[//FF[[((F%f~9VV6
\,/
;
''	22T9Tl++J	9MM
 
 ##FGV<<D(D(D(6GV#455!! nnT\<DD!^^K9NPRSS&*&7&78JIWY&Z&Z# #>#HH 	!899E$GG E"'("2 #  	7"'#(GK  7$(HH-@BY$Z$Z!%6	" 	R %!2GI R&7:Q&Q#$7t$C#tJ]asJs # 	J J#&u.H#I#I &> 	M' _GGT[]cHdHdee@@WV\A]A]^^*,' V# V),->PknuPu@v@v)w)wGI&&&)<<?Z]d?ddd$TW/g%gjm  oJ  kK  kK  &K  NU  &U  V  V  VI $ 8 8 I IIvK"&"E"Eff"U"UK%0GM"{{7F33HF""II(SSg%%JJ8TT+ M#II(SSHH#BB8LLHr>>I~~h99  vy%GGGr  c                    |                                   i }d}d}d}|                     dd|          \  }}|                     d|          \  }}|dk    s|dk    rJd}|                     d|          \  }}||d<   |                     |                     ||                    }n|dk    r*|                     |                     ||                    }n}|dk    r*|                     |                     ||                    }nM|dk    r*|                     |                     ||                    }nt          | j
        d	z   |z   d
z             |                     |dg           }|                     |          S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://www.bitget.com/api-doc/spot/account/Get-Account-Assets
        :see: https://www.bitget.com/api-doc/contract/account/Get-Account-List
        :see: https://www.bitget.com/api-doc/margin/cross/account/Get-Cross-Assets
        :see: https://www.bitget.com/api-doc/margin/isolated/account/Get-Isolated-Assets
        :see: https://bitgetlimited.github.io/apidoc/en/margin/#get-cross-assets
        :see: 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>`
        Nrg   rH   rI   r	  r  r  rF   z! fetchBalance() does not support z	 accountsr  )r  rF  r  r  !privateMixGetV2MixAccountAccountsr*  -privateMarginGetMarginV1IsolatedAccountAssets*privateMarginGetMarginV1CrossAccountAssets!privateSpotGetV2SpotAccountAssetsr-   r9   r   parse_balance)r  r  r  rq  r  r"  r	  r  s           r  fetch_balancezbitget.fetch_balance  s    	

!??PTV\]]
F!??PVWW
F&  jH&<&<K"&"E"EdF"S"SK%0GM"==dkk'SY>Z>Z[[HH:%%II$++V]_eJfJfggHH7""FFt{{SZ\bGcGcddHH6!!==dkk'SY>Z>Z[[HHtw)LLzY\gghhhp x44!!$'''r  c                 0   d|i}t          dt          |                    D ]_}||         }|                                 }|                     |dd          }|                     |          }|                     |d          }|a|                     |d          }	|                     |d          |d<   |                     |d	          |d
<   t          j        ||	          |d<   n|                     |d          }
|                     |d          }|||d<   |                     |d          |d
<   nI|
|d<   |                     |d          }|                     |d          }t          j        ||          |d<   |||<   a|                     |          S )Nrc  r   
marginCoinr  borrowinteresttransferablefreetotalAmounttotaldebt	availablemaxTransferOutaccountEquityfrozenlockedused)	r&  r'  accountrk  rd  r  r5   
string_addsafe_balance)r  balancer2  r.  r  r  r  r  r  r  spotAccountFreecontractAccountFreer  r  s                 r  r  zbitget.parse_balancep  s   '"z q#g,,'' 	# 	#AAJEllnnG++E<HHJ**:66D%%eX66F!++E:>>"&"2"25."I"I#'#3#3E=#I#I ")"4VX"F"F #'"2"25+"F"F&*&6&6u>N&O&O#&2&9GFO'+'7'7'O'OGG$$&5GFO!--eX>>F!--eX>>F&-&8&H&HGFO"F4LL  (((r  c                     i dddddddddddddd	d
d	dd	dddddddddddddd	}|                      |||          S )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99r  c                 H	   |                      |d          }|D|                     ||                      |d          |                     |dd          dd|          S d|v }|rdnd	}||d
         }|                      |d          }|                     ||d |          }|                     |dd          }|                     |d          }|                     |dd          }	d }
|                      |d          }|0|                     t          j        |                    |d         d}
| 	                    |d          }|t          j        |          }t          |                                          }d }t          dt          |                    D ]$}||         }| 	                    |d          |} n%|                     t          j        |                      |d                              |                     |                      |d                    d}
d }|                     |d          }|dk    rd}d}d }|                      |d          }|
|dk    rdnd}d }d }|                      |d          }|-|                      |d           }|                      |d          }n-|                     |d!d"          }|                      |d           }d }d }|                      |d#          }||}|                      |d$          }n,|                      |d$          }|                      |d%          }|                      |d&          }|                      |d'          }|d(k    r|r
|d)k    rd*nd)}|                     i d+|d,|                     |dd-          d|                     |dd          d.|d/|                     |          d0|d1|d|d         d
|                      |d2          d&|d!|d3|d4|                     |d5d6          d7|d8|d9d d:||||                     |d;          |                     |d;          |                     |d<d=          |                     |d>d?          |                     |	          |
d d@	|          S )ANerrorMsgr  clientOrderId	clientOidr  )rc  r9   r  rB  posSiderL  rF   r/  r  r  ctimer  rB  stater  r
  )rY  r  rL  r   feeCoinCoderO  force	POST_ONLYTPO
reduceOnlyNOF	basePricerU  rP  executePricebaseSizer  r5  rR  rM  
hedge_modebuysellrc  r9   r  r  r  lastTradeTimestamplastUpdateTimestamprS  rO  rY  r6  	quoteSizer4  r  r  timeInForcetriggerPricepresetStopSurplusPricestopSurplusTriggerPricepresetStopLossPricestopLossTriggerPrice)	postOnlyr  	stopPricer  takeProfitPricestopLossPricerB  r  trades)r  
safe_orderrk  safe_marketr  r!  r  r5   r  r   jsonloadslistvaluesr&  r'  rd  safe_string_upperrg  rl  rm  r  )r  rV  r  errorMessageisContractOrderrq  rn  r  updateTimestamp	rawStatusr  r  rL  parsedFeeDetail	feeValues	feeObjectr.  feeValuer  r  r  reduceOnlyRawrP  r4  r  r  r  r  rR  rM  s                                 r  parse_orderzbitget.parse_order  s   ^ ''z::#??&&ui88!%!3!3E?K!X!X$	$ $
    %-#2>ZZ
J##E844!!(FD*EE''w@@	++E7;;&&uh@@	((66$ ))'*<]*K*KLL"8, C OOE;77	 "j33O_335566II1c)nn--  $Q<??8];;G (IE H ))'*<T=M=MiYc=d=d*e*eff 33D4D4DYP]4^4^__ C ,,UG<<+%%HK
((==$#0D#8#8tJ$$UK88	 $$UJ77E&&uk::GG&&ug~FFE&&uj99G##E:66D%%eV44FF##E622D%%e\::Fv..""5)44l""z""emm66%D   
E 
$$$UIv>> 
 T//TT 
 	 

 Y// 
 !/ 
 "? 
 fX& 
 D$$UK88 
 D 
 U 
 d 
 D&&um[II 
 w 
 f 
  ! 
" ;# 
$ !$))%@@ ,,UNCC#11%9QSlmm!//7LNdee--i885 
  
  
6 7  	r  rY  c                     |                                   |                     |          }|d         st          | j        dz             d|d<   |                     |dd|d|          S )a  
        create a market buy order by providing the symbol and cost
        :see: https://www.bitget.com/api-doc/spot/trade/Place-Order
        :see: https://www.bitget.com/api-doc/margin/cross/trade/Cross-Place-Order
        :see: 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>`
        rF   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr  r  r  N)r  r  r-   r9   create_order)r  r  rY  r  r  s        r  !create_market_buy_order_with_costz(bitget.create_market_buy_order_with_costS  ss     	V$$f~ 	ftw)ddeee6;23  5$fMMMr  r/  rR  rP  c                 h   |                                   |                     |          }|                     d|          }|d         }	|                     |dd          }
|                     |d          }|                     |d          }|                     |dd          }|d	u}|
d	u}|d	u}|d	u}|p|}|                     ||||||          }d	}|d
         rf|r|                     |          }n|	dk    r|                     |          }ny|	dk    r| 	                    |          }n]| 
                    |          }nG|s|r|                     |          }n-|r|                     |          }n|                     |          }|                     |di           }|                     ||          S )a  
        create a trade order
        :see: https://www.bitget.com/api-doc/spot/trade/Place-Order
        :see: https://www.bitget.com/api-doc/spot/plan/Place-Plan-Order
        :see: https://www.bitget.com/api-doc/contract/trade/Place-Order
        :see: https://www.bitget.com/api-doc/contract/plan/Place-Tpsl-Order
        :see: https://www.bitget.com/api-doc/contract/plan/Place-Plan-Order
        :see: https://www.bitget.com/api-doc/margin/cross/trade/Cross-Place-Order
        :see: 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 fullfilled, 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
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rX   r   r  r  r  r  trailingPercentcallbackRatioNrF   r  r  r  )r  r  r  safe_value_2r   rk  create_order_request(privateSpotPostV2SpotTradePlacePlanOrder+privateMarginPostV2MarginIsolatedPlaceOrder*privateMarginPostV2MarginCrossedPlaceOrder$privateSpotPostV2SpotTradePlaceOrder&privateMixPostV2MixOrderPlacePlanOrder&privateMixPostV2MixOrderPlaceTpslOrder"privateMixPostV2MixOrderPlaceOrderr  r  )r  r  r/  rR  rO  rP  r  r  marginParamsr  r  r  takeProfitTriggerPricer  isTrailingPercentOrderisTriggerOrderisStopLossTriggerOrderisTakeProfitTriggerOrderisStopLossOrTakeProfitTriggerr  r"  r  s                         r  r  zbitget.create_ordere  s   L 	V$$99-PP!!_
((nMM#vGG!%9J!K!K,,V5FXX!0!<%T1!5T!A#9#E (>(ZBZ%++FD$vVV&> 	L NHHQQz))KKGTTw&&JJ7SSDDWMM L!7 LFFwOO. LFFwOOBB7KK ~~h33f---r  c                 ~   |                      | j        dd          }d }|r+|                     |          }	|                     |	          }n|                     |          }d }
d }|                     d||          \  }
}|                     d|          \  }}|d         |d}|dk    }|                     |dd          }|                     |d	          }|                     |d
          }|                     |d          }|                     |d          }|d u}|d u}|d u}|d u}|d u}|p|}|p|}|                     |d| 	                    |                    }| 
                    |dd          }|d u}|                     ||||          dk    rt          | j        dz             |dk    r|                     ||          |d<   |                     |dd          }|                      |dd          }| 
                    |dd          }| 
                    |dd          } d }!|                     || dk    |          \  }!}|                     | j        d          }"|                     |d|"          }#|!rd|d<   n#|#dk    rd|d<   n|#dk    rd|d<   n|#dk    rd|d<   |                     |g d           }|
d!k    s|
d"k    r |d#         |d$<   |                     ||          |d%<   d }$|                     ||          \  }$}|$|d&<   |||d<   |s|s|r||d<   |rW|st)          | j        d'z             |t+          | j        d(z             d)|d*<   |                     ||          |d<   ||d<   n|r4d+|d*<   |                     ||          |d<   ||                     ||          |d,<   |r{|                     |dd          }%|                     ||%          |d-<   |                     |d          }&|                     ||&          |d.<   |                     |d/d          }'|'|d0<   |r{|                     |dd          }(|                     ||(          |d1<   |                     |d          })|                     ||)          |d2<   |                     |d/d          }*|*|d3<   n|rh|st          | j        d4z             |d5k    rd6nd7|d8<   |r|                     ||          |d<   d9|d*<   n|r|                     ||          |d<   d:|d*<   nd|r0|                     |dd          }%|                     ||%          |d;<   |r0|                     |dd          }(|                     ||(          |d<<   |sh|d=}|d=k    rd>nd?}+|+|d@<   |                      |dAd          },|                     |dA          }|}-|r|,rdB|d<   n|d5k    rdCnd5}-dD|dE<   n|,sdF|dE<   |-|dG<   n|
dHk    r|s|rt1          | j        dIz             ||dG<   d }.d }/dJ}0|                     |ddKdJ          \  }0}|r|d5k    rdL}/|                     |dM          }1|                     |dM          }|1|                     ||1          }.n|0ro|t1          | j        dNz             | 	                    |          }2| 	                    |          }3t7          j        |2|3          }4|                     ||4          }.n/|                     ||          }.ndO}/|                     ||          }.|||d<   |dP|dQ<   |0r|r|d5k    r|.|dR<   nk|.|dS<   ne|.|.|d%<   |>|/|d*<   ||d<   |                     ||          |d<   ||                     ||          |d,<   nt;          | j        dTz   |
z   dUz             |                     ||          S )VNr  FrX   r9   )r  rS  r  r  r  r  r  stopLoss
takeProfittrailingTriggerPricer  r	  r   zk createOrder() params can only contain one of triggerPrice, stopLossPrice, takeProfitPrice, trailingPercentr  rP  triggerType
mark_pricer  r  r  r  r  	post_onlyr  r  FOKIOC)r  r  r  r  r  r  r  r  r  r  r  rH   rI   rJ  r  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  
oneWayModeYESr  Close	tradeSideOpenrR  rF   z_ createOrder() does not support stop loss/take profit orders on spot markets, only swap marketsTr  r  rY  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 argumentrO  rE  loanTyper  r  z  createOrder() does not support  orders)r  r  r  r  rF  r  r
  r   r  number_to_stringrk  r  r!   r9   price_to_precisionhandle_post_onlyr  r  amount_to_precisionr  r&   r%   rm  rl  r*   r  cost_to_precisionr5   r;  r-   r*  )5r  r  r/  rR  rO  rP  r  r  r  r  rq  r  r  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marginModeRequestr0  requestSidequantityr$  r  rY  r~  r|  quoteAmounts5                                                        r  r  zbitget.create_order_request  s=
   nnT\=%HH 	) ;;FCCM[[//FF[[((F

!??vW]^^
F!??vVV
FTl
 
 (((nMM#vGG!%9J!K!K??6:66__V\::
%T1!5T!A#9#E T)
!-(>(ZBZ%!+!;|#//8NPTPePefkPlPlmm,,V5FXX!0!<88N$:<TVlmmpqqq  +X  !X  Y  Y  Y7??#66vuEEGG&&v}lKK^^FL%@@
**6;PP#'#5#5fg}#U#U 00@X\g@giopp&!33DLBVWW,,V]DVWW 	%*GGE!!$GGE!!$GGE!!$GG6  $T  $T  $T  U  U&  jH&<&<$*:$6GL!"66vvFFGFOK"&"E"Eff"U"UK%0GM"('4$ 5!> 5BX 5)4&% +h$ n$TW/l%lmmm'/+DG  7E  -E  F  F  F&2
#*.*A*A&J^*_*_'+:(( #h&3
#*.*A*A&,*W*W'$.2.E.Efe.T.TGN+ <%)%7%7.R]%^%^N6:6M6MfVd6e6eG23"..xAAG6:6M6MfV]6^6^G23!--hMMF5;G12 ?%)%7%7
NT_%`%`N9=9P9PQWYg9h9hG56"..z7CCG9=9P9PQWY`9a9aG56!--j&,OOF8>G45. h$ '2}(}~~~15ffW
#) 7.2.E.EfNb.c.cGN+*4GJ''- 7.2.E.EfNd.e.eGN+*6GJ' e%)%6%6xQ\%]%]N595L5LVUc5d5dG12 h%)%6%6z>S^%_%_N8<8O8OPVXf8g8gG450 .%!(J2<2G2GIIj!(9%!^^FL%HH
6<88" 	6! 705-- 26ffU/6,,% 6/5,"-6!!, P0F P"47  .O  $O  P  P  P"GFOHH04-8<8U8UV\^k  nQ  SW  9X  9X5-v D$%--"''776622##55fdCCHH6 	F}*47  6q  ,q  r  r  r'+'<'<V'D'D&*&;&;E&B&B&-&8{&S&S#'#9#9&+#N#N#55ffEEHH#33FFCC('4$%&.
#4 3 3DTYMM+3GK((*2GJ'''&.GFO+*2GJ'-8GM*.2.E.Efl.[.[GN+(262I2I&RW2X2X/tw)KKjX[ddeee{{7F+++r  ordersc           	         |                                   g }d}d}t          dt          |                    D ]#}||         }|                     |d          }||}n||k    rt	          | j        dz             |                     |d          }	|                     |d          }
|                     |d          }|                     |d          }|                     |d	i           }|                     d
|          }|d         }|"||}n||k    rt	          | j        dz             |                     ||	|
|||          }|	                    |           %| 
                    | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }|d         |d}d}|d         s|d         rT|d}|dk    rdnd}||d<   |d         |d<   d}|                     ||          \  }}||d<   |                     |          }nM|dk    r|                     |          }n1|dk    r|                     |          }n|                     |          }|                     |di           }|                     |dg           }|                     |dg           }|                     ||          }|                     ||          S )a  
        create a list of trade orders(all orders should be of the same symbol)
        :see: https://www.bitget.com/api-doc/spot/trade/Batch-Place-Orders
        :see: https://www.bitget.com/api-doc/contract/trade/Batch-Order
        :see: https://www.bitget.com/api-doc/margin/isolated/trade/Isolated-Batch-Order
        :see: 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/  rR  rO  rP  r  rY   zS createOrders() requires all orders to have the same margin mode(isolated or cross)r  Fr9   )r  	orderListrH   rI   r  r/  r  r  rJ  r  r	  r  failureListsuccessList)r  r&  r'  r  r&   r9   r   r  r  r(  r  r  r  r  r  'privateMixPostV2MixOrderBatchPlaceOrder0privateMarginPostV2MarginIsolatedBatchPlaceOrder/privateMarginPostV2MarginCrossedBatchPlaceOrder%privateSpotPostV2SpotTradeBatchOrdersr+  parse_orders)r  rK  r  ordersRequestsr  r  r.  rawOrderrn  r/  rR  rO  rP  orderParamsmarginResultcurrentMarginModeorderRequestr  r  r  r  r"  rG  r	  r  failure	orderInfoboths                               r  create_orderszbitget.create_ordersf  sT    	
q#f++&& 	0 	0AayH''(;;H~!X%%$TW/l%lmmm##Hf55D##Hf55D__Xx88FOOHg66E//(HbAAK==nkZZL ,Q ,%!2JJ!%666(  4I  *I  J  J  J44XtT6SXZeffL!!,////nnT\=%HH 	) ;;FCCM[[//FF[[((FTl'
 
 6N 	Kx 0 	K!$
.8G.C.C		*$5GL!$*:$6GL!K"&"E"Eff"U"UK%0GM"CCGLLHH:%%LLWUUHH7""KKGTTHHAA'JJH0 x44//$r::OOD-<<	  G44  v...r  r9   c                    |                                   |                     | j        dd          }d}	|r+|                     |          }
|                     |
          }	n|                     |          }	d|i}|dk    }|                     |dd          }|du}|                     |d          }|du}|                     |d	          }|du}|                     |d
          }|                     |d          }|du}|du}|                     |d|                     |                    }| 	                    |dd          }|du}| 
                    ||||          dk    rt          | j        dz             | 	                    |dd          }|||d<   |                     |g d          }d}|	d         r&|                     | j        dd          }|r|r|dk    r|t          | j        dz             |                     |          }|                     |          }|                     t!          j        ||                    }|                     ||          |d<   n|                     ||          |d<   ||d<   |                     ||          |d<   |                     ||          |d<   |                     |                     ||                    }n|	d         s+|	d         s#t-          | j        dz   |	d         z   d z             |	d!         |d"<   d} |                     |	|          \  } }| |d#<   |s8|s6|                     ||          |d$<   ||s|                     ||          |d%<   |rd|st1          | j        d&z             ||                     ||          |d'<   ||d<   |                     |                     ||                    }n|s|r|	d(         |d)<   |                     ||          |d<   |                     ||          |d<   |r|                     ||          |d<   n|r|                     ||          |d<   |                     |                     ||                    }n|r=|                     ||          |d'<   |r{|                     |dd          }!|                     ||!          |d*<   |                     |d+          }"|                     ||"          |d,<   |                     |dd-          }#|#|d.<   |r{|                     |dd          }$|                     ||$          |d/<   |                     |d+          }%|                     ||%          |d0<   |                     |dd-          }&|&|d1<   |                     |                     ||                    }n|                                 }'| 	                    |d2d3|'          }(|                     |d3          }|(|d2<   |r0|                     |dd          }!|                     ||!          |d4<   |r0|                     |dd          }$|                     ||$          |d5<   |                     |                     ||                    }|                     |d6i           })|                      |)|	          S )7a  
        edit a trade order
        :see: https://www.bitget.com/api-doc/spot/plan/Modify-Plan-Order
        :see: https://www.bitget.com/api-doc/contract/trade/Modify-Order
        :see: https://www.bitget.com/api-doc/contract/plan/Modify-Tpsl-Order
        :see: 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 fullfilled, in units of the base 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  FNr  r  r  r  r  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  rF   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  rS  r  rH   rI   z editOrder() does not support r/  r6  r9   r  r	  newSizenewPricez9 editOrder() bitget trailing orders must be market ordersnewTriggerPricerJ  r  newStopLossTriggerPricerP  newStopLossExecutePricer  newStopLossTriggerTypenewSurplusTriggerPricenewStopSurplusExecutePricenewStopSurplusTriggerTypenewClientOidnewClientOrderIdnewPresetStopLossPricenewPresetStopSurplusPricer  )!r  r  r  r  r  r
  r   r  r7  rk  r  r!   r9   r  r*   r  r5   r;  r8  r:  )privateSpotPostV2SpotTradeModifyPlanOrderr*  r-   r  r&   'privateMixPostV2MixOrderModifyPlanOrder'privateMixPostV2MixOrderModifyTpslOrderrm  rl  uuid#privateMixPostV2MixOrderModifyOrderr  r  )*r  r9   r  r/  rR  rO  rP  r  r  r  r  r  r<  r  r  r  isStopLossOrderr  isTakeProfitOrderr  r  r=  r>  r  r  r  r  r"  ra  r~  r|  rY  r	  rA  rB  rC  rD  rE  rF  defaultNewClientOrderIdrl  r  s*                                             r  
edit_orderzbitget.edit_order  s   < 	nnT\=%HH 	) ;;FCCM[[//FF[[((Fr
 (((nMM%T1@@'t3//&2CDD+47??6:66__V\::
T)
!-#//8NPTPePefkPlPlmm,,V5FHZ[[!0!<88NO5FH^__bccc  +V  !V  W  W  W**6;PP$#0GK 6  $z  $z  $z  {  {&> G	b.2nnT\Klnr.s.s+. 	K= 	Kdemm=&tw  2t  (t  u  u  u#'#8#8#@#@L"&"7"7">">K,,W-?k-Z-Z[[D&*&=&=fd&K&KGFOO"&":":66"J"J#'GK &*&=&=fl&S&SGN#&*&=&=fe&L&LGN#EEdkkRY[aFbFbccHH6N lVH-= l"47-M#MPVW]P^#^aj#jkkk &tGHK"&"E"Eff"U"UK%0GM"$ Q_ Q%)%=%=ff%M%M	"%/E%*.*A*A&%*P*PGJ'% ,b$ l$TW/j%jkkk'3151H1HQe1f1fG-..=*+GGT[]cHdHdee" %bo %b(.z(:%"&":":66"J"J*.*A*A&%*P*P'" _.2.E.Efm.\.\GN++& _.2.E.Efo.^.^GN+GGT[]cHdHdee b-1-D-DV\-Z-Z)* ?%)%7%7.R]%^%^N9=9P9PQWYg9h9hG56"..xAAG9=9P9PQWY`9a9aG56!--hMMF8>G45 B%)%7%7
NT_%`%`N8<8O8OPVXf8g8gG45"..z7CCG<@<S<STZ\c<d<dG89!--j&,OOF;AG78GGT[]cHdHdee*.))++'#'#5#5fnN`by#z#z 6+=>>*:' h%)%6%6xQ\%]%]N8<8O8OPVXf8g8gG45 k%)%6%6z>S^%_%_N;?;R;RSY[i;j;jG78CCDKKPWY_D`D`aa ~~h33f---r  c                    |t          | j        dz             |                                  |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }d}d}|                     d|          \  }}i }	|                     |d          }
| 	                    |dd          }| 
                    |g d	          }|d
         r|s|d         |	d<   |d         s|d         r|s||	d<   |d         s|d         rd}|                     ||          \  }}||	d<   |s|
r g }d|i}|                    |           ||	d<   |
rG|                     |dd          }||	d<   |                     |                     |	|                    }n:|r+|                     |                     |	|                    }n|                     |                     |	|                    }n|d
         r|`|dk    r*|                     |                     |	|                    }n|dk    r)|                     |                     |	|                    }ny|r*|                     |                     |	|                    }nM|                     |                     |	|                    }n#t+          | j        dz   |d         z   dz             |                     |di           }d}|d         s|d         r"|r |                     |dg           }|d         }n|}|                     ||          S )a  
        cancels an open order
        :see: https://www.bitget.com/api-doc/spot/trade/Cancel-Order
        :see: https://www.bitget.com/api-doc/spot/plan/Cancel-Plan-Order
        :see: https://www.bitget.com/api-doc/contract/trade/Cancel-Order
        :see: https://www.bitget.com/api-doc/contract/plan/Cancel-Plan-Order
        :see: https://www.bitget.com/api-doc/margin/cross/trade/Cross-Cancel-Order
        :see: 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.stop]: 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 argumentr  FrO   trailingstoptriggerrz  r{  ry  rF   r9   r  rH   rI   r  r	  orderIdListr$  r#  r  r  z  cancelOrder() does not support r/  r6  r  rO  r   )r%   r9   r  r  r  r  r  r  r   r
  r  r  r(  r  'privateMixPostV2MixOrderCancelPlanOrderr*  #privateMixPostV2MixOrderCancelOrder,privateMarginPostV2MarginIsolatedCancelOrder+privateMarginPostV2MarginCrossedCancelOrder)privateSpotPostV2SpotTradeCancelPlanOrder%privateSpotPostV2SpotTradeCancelOrderr-   r  )r  r9   r  r  r  r  r  r  r"  r  ry  rz  r	  r}  r  r$  r  rV  r\  s                      r  cancel_orderzbitget.cancel_orderY  s   $ >#DG.Y$YZZZnnT\=%HH 	) ;;FCCM[[//FF[[((F
!??vVV
F??6:66  ;;6#B#B#BCCv 	-4 	- &tGH 	$6(#3 	$ 	$!#GI6N 	jx 0 	jK"&"E"Eff"U"UK%0GM" 5x 5 r ""7+++)4& b++FJMM&.
#GGT[]cHdHdee bGGT[]cHdHdeeCCDKKPWY_D`D`aaF^ 	j%++#PPQUQ\Q\]dflQmQmnnHH7**#OOPTP[P[\cekPlPlmmH h#MMdkkZaciNjNjkkHH#II$++V]_eJfJfggHHtw)KKfU[n\_hhiiiT x446N 	fX. 	D 	mR@@IaLEEEv...r  c                    |t          | j        dz             |                                  |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }d}|                     d|          \  }}|                     |dd          }| 	                    |ddg          }g }	t          dt          |                    D ]#}
||
         }d	|i}|	                    |           $d
|d         i}|d         r||	|d<   n|	|d<   d}|d         r|Z|dk    r*|                     |                     ||                    }n|                     |                     ||                    }n|                     |                     ||                    }nud}|                     ||          \  }}||d<   |r*|                     |                     ||                    }n)|                     |                     ||                    }|                     |di           }|                     |dg           }|                     ||          S )a  
        cancel multiple orders
        :see: https://www.bitget.com/api-doc/spot/trade/Batch-Cancel-Orders
        :see: https://www.bitget.com/api-doc/contract/trade/Batch-Cancel-Orders
        :see: https://www.bitget.com/api-doc/contract/plan/Cancel-Plan-Order
        :see: https://www.bitget.com/api-doc/margin/cross/trade/Cross-Batch-Cancel-Order
        :see: 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.stop]: *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  FrP   rz  r{  r   r  r  r9   rF   rM  r}  r  r	  r  rO  )r%   r9   r  r  r  r  r  r  r
  r  r&  r'  r(  0privateMarginPostV2MarginCrossedBatchCancelOrderr*  1privateMarginPostV2MarginIsolatedBatchCancelOrder*privateSpotPostV2SpotTradeBatchCancelOrderr  r~  )privateMixPostV2MixOrderBatchCancelOrdersr   r  rT  )r  idsr  r  r  r  r  r  rz  r}  r.  individualIdr  r  r"  r	  r  rK  s                     r  cancel_orderszbitget.cancel_orders  s    >#DG.Z$Z[[[nnT\=%HH 	) ;;FCCM[[//FF[[((F
!??PVWW
F  ;;6FI#677q#c((## 	( 	(Aq6L<G w''''fTl
 &> 	1z1#.GK  %0GM"&> 	h%((#TTUYU`U`ahjpUqUqrrHH#UUVZVaVabikqVrVrssHHJJ4;;W^`fKgKghhK"&"E"Eff"U"UK%0GM" hGGT[]cHdHdeeII$++V]_eJfJfgg" x44mR88  000r  c                 B   |t          | j        dz             |                                  |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }d}|                     d|          \  }}d|d         i}|                     |dd	          }| 	                    |dd	g          }d}	|d
         r|[|dk    r+| 
                    |                     ||                    }	n |                     |                     ||                    }	n|r5d|d         gi}
|                     |                     |
|                    }	n|                     |                     ||                    }	nud}|                     ||          \  }}||d<   |r*|                     |                     ||                    }	n)|                     |                     ||                    }	|	S )ai  
        cancel all open orders
        :see: https://www.bitget.com/api-doc/spot/trade/Cancel-Symbol-Orders
        :see: https://www.bitget.com/api-doc/spot/plan/Batch-Cancel-Plan-Order
        :see: https://www.bitget.com/api-doc/contract/trade/Batch-Cancel-Orders
        :see: https://bitgetlimited.github.io/apidoc/en/margin/#isolated-batch-cancel-orders
        :see: 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.stop]: *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 argumentr  FrN   r  r9   rz  r{  rF   r  
symbolListr	  )r%   r9   r  r  r  r  r  r  safe_bool_2r  3privateMarginPostMarginV1CrossOrderBatchCancelOrderr*  6privateMarginPostMarginV1IsolatedOrderBatchCancelOrder.privateSpotPostV2SpotTradeBatchCancelPlanOrder+privateSpotPostV2SpotTradeCancelSymbolOrderr  r~  r  )r  r  r  r  r  r  r  r  rz  r"  stopRequestr	  s               r  cancel_all_orderszbitget.cancel_all_orders"  sP    >#DG.]$]^^^nnT\=%HH 	) ;;FCCM[[//FF[[((F
!??@QSYZZ
FfTl
 	::6FI#677&> 	h%((#WWX\XcXcdkmsXtXtuuHH#ZZ[_[f[fgnpv[w[wxxHH n$vd|n#K  $RRSWS^S^_jlrSsSsttHH#OOPTP[P[\cekPlPlmmHHK"&"E"Eff"U"UK%0GM" hGGT[]cHdHdeeII$++V]_eJfJfgg^ r  c                    |t          | j        dz             |                                  |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }d|i}d}|d         r*|                     |                     ||                    }n|d         s|d         rU|d	         |d
<   d}	| 	                    ||          \  }	}|	|d<   | 
                    |                     ||                    }n#t          | j        dz   |d         z   dz             t          |t                    rt          j        |          }|                     |d          }
|
+t          |
t"                    s|                     |
|          S |                     |dg           }|                     |di           }|                     ||          S )a  
        fetches information on an order made by the user
        :see: https://www.bitget.com/api-doc/spot/trade/Get-Order-Info
        :see: https://www.bitget.com/api-doc/contract/trade/Get-Order-Details
        :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  Fr  rF   rH   rI   r9   r  r	  z fetchOrder() does not support r/  r6  r  r   )r%   r9   r  r  r  r  r  "privateSpotGetV2SpotTradeOrderInfor*  r  privateMixGetV2MixOrderDetailr-   
isinstancerj  r  r  r  r  r  r  )r  r9   r  r  r  r  r  r  r"  r	  r  dataListfirsts                r  fetch_orderzbitget.fetch_order  s    >#DG.X$XYYYnnT\=%HH 	) ;;FCCM[[//FF[[((Fr
 &> 		i>>t{{7TZ?[?[\\HHF^ 	ivh/ 	i &tGHK"&"E"Eff"U"UK%0GM"99$++gv:V:VWWHHtw)JJVTZ^[^gghhhH h$$ 	,z(++H~~h//jt&<&<##D&111>>(FB77xB//v...r  c           	      *	   |                                   |                     | j        dd          }d}d}i }d}	|                     d|          \  }	}||r+|                     |          }
|                     |
          }n|                     |          }|d         |d<   |                     | j        ddd          }d	|v r|d	         n|}|                     |d	|          }n4|                     | j        ddd          }|                     |d	|          }d}|                     |dd
          \  }}|r*d}|dk    r|	d}nd}| 	                    d|||||d          S d}|                     |d          }| 
                    |dd          }|                     |d          du}|p|}|                     |g d          }|                     d||          \  }}|||d<   |||d<   |dk    s|dk    s|	4|                     |dd          }|                     |d          }|||d<   d}|                     |d	g          }|dk    r|	||                                 dz
  }||d<   |	dk    r+|                     |                     ||                    }na|	dk    r)|                     |                     ||                    }n0|r+|                     |                     ||                    }n|                     |                     ||                    }nd}|                     ||          \  }}||d<   |rF|                     |dd          }||d<   |                     |                     ||                    }nq|rF|                     |dd          }||d<   |                     |                     ||                    }n)|                     |                     ||                    }|                     |d           }|dk    r4|	|r/|                     |d!g           }|                     ||||          S n/|                     |d"g           }|                     ||||          S |                     ||||          S )#a  
        fetch all unfilled currently open orders
        :see: https://www.bitget.com/api-doc/spot/trade/Get-Unfilled-Orders
        :see: https://www.bitget.com/api-doc/spot/plan/Get-Current-Plan-Order
        :see: https://www.bitget.com/api-doc/contract/trade/Get-Orders-Pending
        :see: https://www.bitget.com/api-doc/contract/plan/get-orders-plan-pending
        :see: https://www.bitget.com/api-doc/margin/cross/trade/Get-Cross-Open-Orders
        :see: 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.stop]: 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  FNr   r9   r  r  rF   r/  r  minIdendIdr  ry  rz  r{  r$  r|  r  r  r  rH   rI   r  r  r  r  r  r	  r#  r%  r  rM  entrustedList)r  r  r  r  r  r  rk  r  r  r  r  r  r  r  *privateMarginGetV2MarginIsolatedOpenOrdersr*  )privateMarginGetV2MarginCrossedOpenOrders)privateSpotGetV2SpotTradeCurrentPlanOrder'privateSpotGetV2SpotTradeUnfilledOrdersr  (privateMixGetV2MixOrderOrdersPlanPending$privateMixGetV2MixOrderOrdersPendingr   r  rT  )r  r  r  r  r  r  r  r/  r  r  r  r  rq  r  cursorReceivedr"  ry  rz  planTypeDefinedisStopr  queryr	  r$  r  
resultListr2  s                              r  fetch_open_orderszbitget.fetch_open_orders  s;   * 	nnT\=%HH
!??@QSYZZ
F - $ ? ? G G]33V,, &tGH,,T\;Lm]cddK,2f,<,<;J##FFJ??DD,,T\;Lm]cddK##FFK@@D88ART^__& 	C!Nv~~)%,N!(334EvuV[]ces  vB  C  C  C>>&*55	::**6:>>dJ)/6#B#B#BCC229gvNN#(GK $GGFNN 0 0j6L ..v{OTTMYYv77F('4$		&6(++6>>%= --//*<E+0GK(++#NNt{{[bdiOjOjkkHH7**#MMdkkZachNiNijjH i#MMdkkZachNiNijjHH#KKDKKX_afLgLghhHHK!%!D!DVU!S!SK%0GM" 	b++FJMM&.
#HHU\^cIdIdee b++E:}MM&.
#HHU\^cIdIdeeDDT[[QXZ_E`E`aa` x006>>&4&!^^D+rBB
((VUEJJJ ' ^^D/2>>F$$VVUEBBB  vue<<<r  c                     |                                   |                     ||||          }|                     |dd          S )a{  
        fetches information on multiple closed orders made by the user
        :see: https://www.bitget.com/api-doc/spot/trade/Get-History-Orders
        :see: https://www.bitget.com/api-doc/spot/plan/Get-History-Plan-Order
        :see: https://www.bitget.com/api-doc/contract/trade/Get-Orders-History
        :see: https://www.bitget.com/api-doc/contract/plan/orders-plan-history
        :see: https://www.bitget.com/api-doc/margin/cross/trade/Get-Cross-Order-History
        :see: 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 entries 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)
        :param str [params.isPlan]: *swap only* 'plan' for stop orders and 'profit_loss' for tp/sl orders, default is 'plan'
        :param str [params.productType]: *contract only* 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES'
        :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>`
        rB  r  r   fetch_canceled_and_closed_orders	filter_byr  r  r  r  r  rK  s         r  fetch_closed_orderszbitget.fetch_closed_orders  sE    ( 	66vueVTT~~fh999r  c                     |                                   |                     ||||          }|                     |dd          S )a~  
        fetches information on multiple canceled orders made by the user
        :see: https://www.bitget.com/api-doc/spot/trade/Get-History-Orders
        :see: https://www.bitget.com/api-doc/spot/plan/Get-History-Plan-Order
        :see: https://www.bitget.com/api-doc/contract/trade/Get-Orders-History
        :see: https://www.bitget.com/api-doc/contract/plan/orders-plan-history
        :see: https://www.bitget.com/api-doc/margin/cross/trade/Get-Cross-Order-History
        :see: 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 entries 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)
        :param str [params.isPlan]: *swap only* 'plan' for stop orders and 'profit_loss' for tp/sl orders, default is 'plan'
        :param str [params.productType]: *contract only* 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES'
        :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>`
        rB  r  r  r  s         r  fetch_canceled_orderszbitget.fetch_canceled_orders)  sE    ( 	66vueVTT~~fh
;;;r  c           	      	   |                                   |                     | j        dd          }d}|r||                     |          }|}i }| |                     |          }|d         |d<   d}	|                     d||          \  }	}d}
|                     d|          \  }
}d}|                     |dd          \  }}|r*d}|	dk    r|
d	}nd
}|                     d|||||d          S d}| 	                    |d          }| 
                    |dd          }|                     |g d          }|                     d||          \  }}|||d<   |||d<   |	dk    s|	dk    s|
4|                     |dd          }|                     |d          }|||d<   |                                 }|	dk    r#|
n|
|dz
  }||d<   |
dk    r+|                     |                     ||                    }n|
dk    r)|                     |                     ||                    }n|r|t%          | j        dz             |                     |g d          }|                     |ddg          }|
|dz
  }||d<   |||d<   |                     |                     ||                    }n|                     |                     ||                    }nd}|                     ||          \  }}||d<   |rF|                     |dd           }||d<   |                     |                     ||                    }nq|rF|                     |dd!          }||d<   |                     |                     ||                    }n)|                     |                     ||                    }| 	                    |d"i           }|	dk    r2|
|r-|                     | 	                    |d#g           |||          S n-|                     | 	                    |d$g           |||          S t9          |t:                    rt=          j        |          }|                      |d"g           }|                     ||||          S )%a  
        :see: https://www.bitget.com/api-doc/spot/trade/Get-History-Orders
        :see: https://www.bitget.com/api-doc/spot/plan/Get-History-Plan-Order
        :see: https://www.bitget.com/api-doc/contract/trade/Get-Orders-History
        :see: https://www.bitget.com/api-doc/contract/plan/orders-plan-history
        :see: https://www.bitget.com/api-doc/margin/cross/trade/Get-Cross-Order-History
        :see: 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
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  FNr9   r  rk   r  rF   r  r  r  ry  rz  r{  r|  r  r  r  rH   rI   r  r  r  r  r  z: fetchCanceledAndClosedOrders() requires a symbol argument)r  r}  r~  r}  r~  r	  r$  r#  r%  r  rM  r  )!r  r  r  r  r  rF  r  r  r  r   r  r  r  rk  r  -privateMarginGetV2MarginIsolatedHistoryOrdersr*  ,privateMarginGetV2MarginCrossedHistoryOrdersr%   r9   safe_integer_n)privateSpotGetV2SpotTradeHistoryPlanOrder&privateSpotGetV2SpotTradeHistoryOrdersr  r  (privateMixGetV2MixOrderOrdersPlanHistory$privateMixGetV2MixOrderOrdersHistoryrT  r  rj  r  r  r  )r  r  r  r  r  r  r  r  r  rq  r  r  r  r"  ry  rz  r  r  r  r	  r$  r  rK  s                          r  r  z'bitget.fetch_canceled_and_closed_ordersA  sW    	nnT\=%HH 	'! $ ? ? G G&[[((F &tGH
!??@^`fhnoo
F
!??@^`fgg
F88A_akll& 	P!NV##)%,N!(334RTZ\achjp  sA  CO  P  P  P??6:66	::6#B#B#BCC229gvNN#(GK $GG&  jH&<&<*BX ..v{OTTMYYv77F('4$!!%=*,E+0GK(++#QQRVR]R]^egmRnRnooHH7**#PPQUQ\Q\]dflQmQmnnH i~/:v0vwww"11&:V:V:VWWG!YYv/@AAF} #j 0/4,-0	*#MMdkkZaciNjNjkkHH#JJ4;;W^`fKgKghhHHK"&"E"Eff"U"UK%0GM" 	c++FJMM&.
#HHU\^dIeIeff c++FJNN&.
#HHU\^dIeIeffDDT[[QXZ`EaEabbf x44&4&(({B)O)OQWY^`efff ' $$T__T?B%O%OQWY^`efffh$$ 	,z(++H&"55  >>>r  c           	         |                                   |                     |d          }|                     |d          }d}|^|                     | j        dd          }|r+|                     |          }|                     |          }n|                     |          }d}	|                     d||          \  }	}d}
|                     |dd          \  }
}|
r%d}|	dk    rd}| 	                    d|||||d	          S d}i }| | 
                    |          }|d
         |d<   |                     d||          \  }}|||d<   |||d<   d}|	dk    r*|                     |                     ||                    }nV||d
         |d<   d}|                     ||          \  }}||d<   |                     |                     ||                    }|                     |d          }|	dk    s|	dk    r/|                     |dg           }|                     ||||          S |                     ||||          S )a  
        :see: https://www.bitget.com/api-doc/spot/account/Get-Account-Bills
        :see: https://www.bitget.com/api-doc/contract/account/Get-Account-Bill
        fetch the history of changes, actions done by the user or operations that altered balance of the user
        :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 entrys 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-structure>`
        r  Nr  Fr   r  rF   r  r  r9   r  r  r  r  r	  r  rH   rI   bills)r  r  r  r  r  r  r  rF  r  r  r  r   privateSpotGetV2SpotAccountBillsr*  r  privateMixGetV2MixAccountBillr   parse_ledger)r  r  r  r  r  r  r  r  r  rq  r  r  r  r  r"  r	  r  r  s                     r  fetch_ledgerzbitget.fetch_ledgerZ  s    	!!&(3368,,..}eLLK - $ ? ? G G]33V,,
!??vW]^^
F88PZ[[& 	!NV##!(33M65RWY_aoq}~~~}}T**H&tnGFO229gvNN#(GK $GG<<T[[RX=Y=YZZHH!$*4L!K"&"E"Eff"U"UK%0GM"99$++gv:V:VWWHZ x00&  jH&<&<OOD'266E$$UHeUCCC  x>>>r  c                 V   |                      |d          }|                     ||          }|                     |d          }|                     |d          }|                     |dd          }|                     |dd          }|                     t          j        |                    }	d}
|	                    d	          d
k    rd}
||                      |d          || 
                    |          |
d d d |                     |                      |d                    ||	d |d |dS )Nr  r  r  r   r  r  rO  inr  r   outbillIdrk  )rc  r9   r  r  	directionr  referenceIdreferenceAccountr/  r  rO  beforeafterrB  r  )r  rd  r!  rl  rm  rk  r  r5   r  r  rg  parse_ledger_type)r  r  r  r  r  r  r  r  	amountRawrO  r  s              r  parse_ledger_entryzbitget.parse_ledger_entry  s;   8 %%dF33
&&z8<<%%dG44	  y11  vu55&&tVX>>	""7#5i#@#@AA	>>#!##I""422"Y//" $**4+;+;D.+Q+QR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,}|                      |||          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_expiredr  r  )transfer_intransfer_outr  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22r  c           	      |   |t          | j        dz             |                                  |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }d}|                     d|          \  }}d}	|                     |dd          \  }	}|	r,d}
|d         r|d}
nd	}
| 	                    d|||||
d
          S d}d|d         i}| 
                    d||          \  }}|||d<   |||d<   |d         r||||                                 dz
  |d<   |dk    r*|                     |                     ||                    }n|dk    r)|                     |                     ||                    }ns|                     |                     ||                    }nId}|                     ||          \  }}||d<   |                     |                     ||                    }|                     |d          }|d         s|d         r/|                     |dg           }|                     ||||          S |/|                     |dg           }|                     ||||          S |                     ||||          S )a>  
        fetch all trades made by the user
        :see: https://www.bitget.com/api-doc/spot/trade/Get-Fills
        :see: https://www.bitget.com/api-doc/contract/trade/Get-Order-Fills
        :see: https://www.bitget.com/api-doc/margin/cross/trade/Get-Cross-Order-Fills
        :see: 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   r  rF   r  r  r  r  r9   r  r  r  r  r  r  r	  r  rH   rI   fillListfills)r%   r9   r  r  r  r  r  r  r  r  r  r  %privateMarginGetV2MarginIsolatedFillsr*  $privateMarginGetV2MarginCrossedFillsprivateSpotGetV2SpotTradeFillsr  privateMixGetV2MixOrderFillsr   r  rb  )r  r  r  r  r  r  r  r  r  r  r  r"  r  r	  r  r  r  s                    r  fetch_my_tradeszbitget.fetch_my_trades(  s&    >#DG.[$[\\\nnT\=%HH 	) ;;FCCM[[//FF[[((F
!??QWXX
F88R\]]& 	A!Nf~ ))%,N!(33OVUTY[acqs  A  A  AfTl
 229gvNN#(GK $GG&> 	W%=+/+<+<+>+>+KGK(++#II$++V]_eJfJfggHH7**#HHU\^dIeIeffH>>t{{7TZ?[?[\\K"&"E"Eff"U"UK%0GM"88Wf9U9UVVHH x006N 	Bx 0 	B~~dJ;;H$$XvueDDD#NN4"55E$$UFE5AAA  vue<<<r  c                    |                                   |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }d}|                     ||          \  }}|d         |d         |d}|                     |                     ||                    }|                     |dg           }	| 	                    |	di           }
| 
                    |
|          S )	a  
        fetch data on a single open contract trade position
        :see: 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>`
        r  FNr9   rJ  r  r  r	  r  r   )r  r  r  r  r  r  (privateMixGetV2MixPositionSinglePositionr*  r  r  parse_position)r  r  r  r  r  r  r	  r  r"  r  r  s              r  fetch_positionzbitget.fetch_position  s    	nnT\=%HH 	) ;;FCCM[[//FF[[((F"AA&&QQVTl ,&
 

 @@WV\A]A]^^> ~~h33tQ++""5&111r  c           	         |                                   d}|                     |dd          \  }}|r|                     dddd|dd          S d}|                     |dd          }|rd}n|                     |dd	d
          \  }}d}|t|                     |d          }|                     | j        dd          }|r+|                     |          }	|                     |	          }n|                     |          }d}
|                     ||          \  }
}d|
i}d}d}|d
k    r|                     |dd          }|	|d         }nI|
dk    rd}n@|
dk    rd}n7|
dk    rd}n.|
dk    rd}n%|
dk    s|
dk    r|t          | j
        dz             ||d<   |                     |                     ||                    }n8d}||d         |d<   |                     |                     ||                    }g }|s|                     |dg           }n.|                     |di           }|                     |dg           }g }t!          dt#          |                    D ]1}|                    |                     ||         |                     2|                     |          }|                     |d|d          S ) a  
        fetch all open positions
        :see: https://www.bitget.com/api-doc/contract/position/get-all-position
        :see: 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  Nr  r  useHistoryEndpoint)privateMixGetV2MixPositionHistoryPositionr  r  r   r  r	  r  r  rJ  r  r  r  r  r  r  r  r  r  zN fetchPositions() requires a marginCoin parameter that matches the productTypeTr9   r  r  r  )r  r  r  r  r  r  r  r  r  r%   r9   r  r*  r  r  r  r&  r'  r(  r  market_symbolsfilter_by_array_positions)r  rD  r  r  r  r  r  r  r  r  r	  r  r"  	isHistoryr  positionr  r2  r.  s                      r  fetch_positionszbitget.fetch_positions  s^    	88AQS]^^& 	w334DdDRVX^`giuvvv!^^F4H%PP 	H@FF!::6CSU]  `G  H  HNFF$$Wa00E..}eLLK , $ ? ? F F]33U++"AA&&QQV;
 	<<<))&,GGJ"#J/

..#

..#

//$

//$

00k^6S6S%+DG  7G  -G  H  H  H$.GL!AA$++gW]B^B^__HHI!$*4L!EEdkkRY[aFbFbccH~  	8~~h;;HH>>(FB77D~~dFB77Hq#h--(( 	D 	DAMM$--hqk6BBCCCC%%g..--fhOOOr  c                 
   |                      |d          }|                     ||d d          }|d         }|                     |dd          }|                      |d          }d }d }|                      |d          }	|                      |d          }
|dk    rt          j        |
|	          }n
|d	k    rd
}|
}|                      |d          }d }|dk    rd}n|dk    rd}|                      |d          }|                      |d          }|                     |d          }|                     |          }|                      |d          }|                     |dd          }|                      |d          }t          j        ||          }|t          j	        ||          }| 
                    t          j	        ||                    }||                     |d          }|                      |d          }t          j        ||          }t          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        ||          }| 
                    t          j	        ||                    }t          j        ||          } t          j        t          j        ||          |           }!t          j        t          j	        |	|d           d!          }"|                     i d"|d#|                      |d$          d|d%| 
                    |          d|d|d&| 
                    |          d'| 
                    |	          d(|                     |d)          d*| 
                    |"          d+|d|d| 
                    |          d,|                     |d-          d.|d/|d0||                     |          |                     |d1          | 
                    |!          | 
                    |          | 
                    |          | 
                    |          | 
                    |          | 
                    |          |                     |d2          d d d3          S )4Nr  rL  r  r  r  unrealizedPL
marginSizer  r/  r  rM  r  Tone_way_modeFr,  rX  r\  r  openPriceAvgopenAvgPricer  closeTotalPos	markPriceliquidationPricer   z0.99940r+  r   r*  r   r3  rc  r9   r  notional
entryPriceunrealizedPnlrealizedPnlpnlr2  	contracts	lastPricecloseAvgPricerR  hedgedr  utimemarginRatio)r  r  maintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentagerX  r   r  r  )r  r  r  r5   r  r   r7  rk  r;  
string_divr  rl  r7  	string_gtrX  r  safe_positionrg  r!  )#r  r
  r  rn  r  r  r  r#  r$  r  rawCollateralholdModer  rR  rX  contractSizeNumberr\  
baseAmountr  r"  openNotionalr  r  r  r%  r  calcTakerFeeRatecalcTakerFeeMultsignedMargin	signedMmpmmrMinusOne	numerator
feeToCloser!  r2  s#                                      r  r  zbitget.parse_position  s   Z ##Hh77!!(FD*EE!'''7CC	%%h==

((>BB((<@@## +M=IIJJ9$$ J)M##Hi88|##FF''F*55##Hj99!__V^DD,,-?@@%%h88
''..QQ
&*&6&6xAQ&R&R#)*jAA #.|XFFM%%g&8\&R&RSS	((?CCI$$X{;;	%j)<<")"4]H"M"M,,T^^D<L<LXWi<j<j-k-kll##$:+C+CIZ[egjIkIk+C"-mZHHL3Iw&1,??#.y99	!,S)<<K*:|DDIv~~%0>NOO#.y:JKK	#001CI{1[1[\\'2BCC
#.w/AB]_g/h/hjtuu'(:=-YZ([([]bcc
!! #
H#
$""8Y77#
 f#
 ))(33	#

 *#
  0#
 $++J77#
 T..}==#
 4++He<<#
 $++J77#
 #
 .#
 **955#
 ))(ODD#
 D#
  f!#
" ##
$ Y//#'#4#4Xw#G#G!%!2!23D!E!E+/+<+<=X+Y+Y++J77!..}=='+'8'89P'Q'Q))(33++HmDD!#9#
 #
 #
   	r  c           
      ,   |t          | j        dz             |                                  d}|                     |dd          \  }}|r|                     d||||dd          S |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }d}	| 	                    ||          \  }	}|d	         |	d
}
|||
d<   | 
                    |                     |
|                    }|                     |dg           }g }t          dt          |                    D ]}||         }|                     |d          }|                     ||          }|                     |d          }|                    |||                     |d          ||                     |          d           |                     |d          }|                     ||d         ||          S )aR  
        fetches historical funding rate prices
        :see: 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  r  r9   r  r	  pageSizer  r   r  fundingTimefundingRate)rc  r  r:  r  r  r  )r%   r9   r  r   fetch_paginated_call_incrementalr  r  r  r  r  &publicMixGetV2MixMarketHistoryFundRater*  r   r&  r'  r  r9  r!  r(  rl  rg  sort_byfilter_by_symbol_since_limit)r  r  r  r  r  r  r  r  r  r	  r  r"  r  ratesr.  r  rn  symbolInnerr  sorteds                       r  fetch_funding_rate_historyz!bitget.fetch_funding_rate_history7  sY    >#DG.e$efff88AZ\fgg& 	A889RTZ\achjprz|  A  A  AnnT\=%HH 	) ;;FCCM[[//FF[[((F"AA&&QQVTl&
 
 "'GJ>>t{{7TZ?[?[\\ x44q#d))$$ 	 	AGE''x88H**8V<<K))%??ILL%#//}EE& LL33      e[11009I5RWXXXr  c                 ,   |                                   |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }|d         st          | j        dz             d}|                     ||          \  }}|d         |d}|                     | 	                    ||                    }| 
                    |dg           }	|                     |	d	         |          S )
as  
        fetch the current funding rate
        :see: https://www.bitget.com/api-doc/contract/market/Get-Current-Funding-Rate
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        r  FNrH   z0 fetchFundingRate() supports swap contracts onlyr9   r7  r  r   )r  r  r  r  r  r'   r9   r  &publicMixGetV2MixMarketCurrentFundRater*  r   parse_funding_rate
r  r  r  r  r  r  r	  r  r"  r  s
             r  fetch_funding_ratezbitget.fetch_funding_ratez  s    	nnT\=%HH 	) ;;FCCM[[//FF[[((Ff~ 	ZDG&XXYYY"AA&&QQVTl&
 
 >>t{{7TZ?[?[\\ x44&&tAw777r  c                     |                      |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 S )Nr  rH   rc  r  
indexPriceinterestRateestimatedSettlePricer  r  r:  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeru  )r  rL  r  rn  r  s        r  rE  zbitget.parse_funding_rate  s    ##Hh77!!(FD&AA
H
f
 
 $	

 D
 #D
 
 
 4++HmDD
 
 t
 t
 #D
 "4
 "4
  '!
" &t#
 	
r  c           	      V   |                                   |t          | j        dz             d}|                     |dd          \  }}|r|                     d||||dd          S |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }|d	         st          | j        d
z             d}	| 
                    ||          \  }	}|d         |d         d|	d}
|                     d|
|          \  }
}|||
d<   |||
d<   |                     |                     |
|                    }|                     |di           }|                     |dg           }|                     ||||          S )a@  
        fetch the funding history
        :see: 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  r  r  r  rH   z3 fetchFundingHistory() supports swap contracts onlyr9   rJ  r  )r  r  rk  r	  r  r  r  r  r  )r  r%   r9   r  r  r  r  r  r  r'   r  r  r  r*  r   parse_funding_histories)r  r  r  r  r  r  r  r  r  r	  r  r"  r  r2  s                 r  fetch_funding_historyzbitget.fetch_funding_history  s    	>#DG.a$abbb88AVXbcc& 	@334I6SXZ_agipr~nnT\=%HH 	) ;;FCCM[[//FF[[((Ff~ 	]DG&[[\\\"AA&&QQVTl ,1&	
 
 229gvNN#(GK $GG55dkk'66R6RSS. x44w33++FFE5IIIr  c           
      b   |                      |d          }|                      |d          }|                     |d          }||                     ||d d          ||                     |          |                     |          |                     |d          |                      |d          dS )Nr  r  r  rH   rO  r  )rc  r  r  r  r  rO  r9   )r  r!  r9  rg  rd  rl  )r  rL  r  rn  r  r  s         r  parse_funding_historyzbitget.parse_funding_history  s     ##Hh77%%h77
%%h88	&&xvFF"Y//++J77&&x::""8X66
 
 	
r  c                 <   g }t          dt          |                    D ]P}||         }|                     |d          }|dk    r'|                    |                     ||                     Q|                     |d          }	|                     |	||          S )Nr   rk  r  r  )r&  r'  r  r(  rX  r=  filter_by_since_limit)
r  r  r  r  r  r2  r.  rL  businessrA  s
             r  rU  zbitget.parse_funding_histories  s    q#i..)) 	H 	HA |H''.AAH000MM$44XvFFGGGGfk22))&%???r  c                    |                                   |                     |d          }|                     | j        dd          }d }|r+|                     |          }|                     |          }n|                     |          }d }	|                     ||          \  }	}|d         |d         |                     ||          ||	d}
|                     |d          }| 	                    | 
                    |
|                    }| 
                    |                     ||          |                     |          |d          S )Nr,  r  Fr9   rJ  )r  r  rO  r,  r	  )rO  r/  )r  r  r  r  r  r  r  r:  r  #privateMixPostV2MixAccountSetMarginr*  parse_margin_modificationr  )r  r  rO  r/  r  r,  r  r  r  r	  r  r"  s               r  modify_margin_helperzbitget.modify_margin_helper)  sX   ##FJ77nnT\=%HH 	) ;;FCCM[[//FF[[((F"AA&&QQVTl ,..vv>> &
 
 6:..;;DKKQW<X<XYY {{499(FKK''//N
 N
   	r  c                 t    |                      |d          }|dk    rdnd}||d         d dd d |d         |d d d
S )	Nr  00000r  r  r  r  r
  )
rc  r  r/  r  rO  r  r  rB  r  r  r
  )r  r  r  	errorCoderB  s        r  r^  z bitget.parse_margin_modificationK  sc     $$T622	#w..XX&$8$
 
 	
r  c                     |dk    rt          | j        dz             |                     |d          }|t          | j        dz             |                     ||d|          S )a  
        remove margin from a position
        :see: 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,  NzC reduceMargin() requires a holdSide parameter, either long or shortri  )r&   r9   r  r%   r_  r  r  rO  r  r,  s        r  r  zbitget.reduce_margine  sn     A::TW'bbccc##FJ77#DG.s$sttt((6JJJr  c                     |                      |d          }|t          | j        dz             |                     ||d|          S )a  
        add margin
        :see: 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,  Nz@ addMargin() requires a holdSide parameter, either long or shortadd)r  r%   r9   r_  rd  s        r  
add_marginzbitget.add_marginu  sO     ##FJ77#DG.p$pqqq((GGGr  c                    |                                   |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }d}|                     ||          \  }}|d         |d         |d}|                     |                     ||                    }|                     |di           }	| 	                    |	|          S )ak  
        fetch the set leverage for a market
        :see: 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>`
        r  FNr9   rJ  r   r  )
r  r  r  r  r  r   privateMixGetV2MixAccountAccountr*  r  parse_leveragerF  s
             r  fetch_leveragezbitget.fetch_leverage  s     	nnT\=%HH 	) ;;FCCM[[//FF[[((F"AA&&QQVTl ,&
 

 88Wf9U9UVV: ~~h33""4000r  c                 n    ||d         d|                      |d          |                      |d          dS )Nr  r  isolatedLongLeverisolatedShortLever)rc  r  r  longLeverageshortLeverage)r!  )r  rX  r  s      r  rj  zbitget.parse_leverage  sG    X&$ --h8KLL!..x9MNN
 
 	
r  rX  c                    |t          | j        dz             |                                  |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }d}|                     ||          \  }}|d         |d         |                     |          |d}| 	                    | 
                    ||                    }	|	S )a  
        set the level of leverage for a market
        :see: 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 argumentr  Fr9   rJ  )r  r  rX  r	  )r%   r9   r  r  r  r  r  r  r7  %privateMixPostV2MixAccountSetLeverager*  )
r  rX  r  r  r  r  r  r	  r  r"  s
             r  set_leveragezbitget.set_leverage  s    >#DG.Y$YZZZnnT\=%HH 	) ;;FCCM[[//FF[[((F"AA&&QQVTl ,--h77&	
 
 ==dkk'SY>Z>Z[[  r  r  c                 L   |t          | j        dz             |                                }|dk    rd}|dk    r|dk    rt          | j        dz             |                                  |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }d}|                     ||          \  }}|d	         |d
         ||d}| 	                    | 
                    ||                    }	|	S )ax  
        set margin mode to 'cross' or 'isolated'
        :see: 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)r  Fr9   rJ  )r  r  r  r	  )r%   r9   lowerr  r  r  r  r  r  'privateMixPostV2MixAccountSetMarginModer*  )
r  r  r  r  r  r  r  r	  r  r"  s
             r  set_margin_modezbitget.set_margin_mode  sC    >#DG.[$[\\\%%''
  "J*$$:+B+B#DG.u$uvvvnnT\=%HH 	) ;;FCCM[[//FF[[((F"AA&&QQVTl ,$&	
 
 ??GU[@\@\]] r  r  c                    |                                   |rdnd}d}|^|                     | j        dd          }|r+|                     |          }|                     |          }n|                     |          }d}|                     ||          \  }}||d}	|                     |                     |	|                    }
|
S )a9  
        set hedged to True or False for a market
        :see: 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  Nr  F)rM  r	  )r  r  r  r  r  r  )privateMixPostV2MixAccountSetPositionModer*  )r  r  r  r  rM  r  r  r  r	  r  r"  s              r  set_position_modezbitget.set_position_mode#  s     	"(<,,n..}eLLK - $ ? ? G G]33V,,"AA&&QQV&
 
 AA$++gW]B^B^__ r  c                     |                                   |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }|d         st          | j        dz             d}|                     ||          \  }}|d         |d}|                     | 	                    ||                    }| 
                    |di           }	|                     |	|          S )	au  
        retrieves the open interest of a contract trading pair
        :see: 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  FNrL  z3 fetchOpenInterest() supports contract markets onlyr9   r7  r  )r  r  r  r  r  r&   r9   r  #publicMixGetV2MixMarketOpenInterestr*  r  parse_open_interestrF  s
             r  fetch_open_interestzbitget.fetch_open_interestJ  s    	nnT\=%HH 	) ;;FCCM[[//FF[[((Fj! 	^TW'\\]]]"AA&&QQVTl&
 
 ;;DKKQW<X<XYY" ~~h33''f555r  c           	      T   |                      |dg           }|                     |d          }|                     |d         d          }|                     |                     ||d d          |                     |d         d          d ||                     |          |d|          S )NopenInterestListr  r   r  rL  r  )r  openInterestAmountopenInterestValuer  r  rc  )r   r!  r  safe_open_interestr9  rl  rg  )r  r  r  r  r  rn  s         r  r}  zbitget.parse_open_interestv  s     x);R@@%%h55	##DGX66&&&&xzJJ"&"2"247F"C"C!%"Y//(
 (
   	r  c                    |t          | j        dz             |                                  d}|                     dd|          \  }}|                     |d|          }|                     |d          }|                     | j        di           }|                     ||          }|                     |          }|d         |d}	|||	d<   |||	d	<   | 	                    d
|	|          \  }	}| 
                    |                     |	|                    }
|                     |
dg           }|                     ||||          S )a  
        fetch a history of internal transfers made on an account
        :see: 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  r9   )r  fromTyper  r  r  r  )r%   r9   r  rF  r  r  r   r  r  r  *privateSpotGetV2SpotAccountTransferRecordsr*  r  parse_transfers)r  r  r  r  r  r/  r  r  r  r  r"  r  s               r  fetch_transferszbitget.fetch_transfers  sa    <#DG.Z$Z[[[99:JDRXYYf&&v}dCC6=117GLL<<==&&TN
 
 #(GK $GG229gvNNBB4;;wX^C_C_``, ~~h33##D(E5AAAr  r  	toAccountc                 |   |                                   |                     |          }|                     | j        di           }|                     ||          }|                     ||          }	||	||d         d}
|                     |d          }|                     |d          }d}| |                     |          }|d         |
d<   |                     |                     |
|                    }|                     |di           }| 	                    |d          |d<   | 
                    ||          S )	a  
        transfer currency internally between wallets on the same account
        :see: 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  r9   )r  toTyperO  r  r  Nr  requestTimer  )r  r  r   r  r  r  r  #privateSpotPostV2SpotWalletTransferr*  r!  parse_transfer)r  r  rO  r  r  r  r  r  r  r  r  r  r  r"  r  s                  r  r   zbitget.transfer  sA    	==&&7GLL##NK@@!!.)<< TN	
 
 !!&(3368,,[[((F &tGH;;DKKQW<X<XYY x44&&x??T
""4222r  c                 N   |                      |d          }|                     |d          }|                     |d          }|                     |d          }|                     | j        di           }|                     |||          }|                     |d          }	|                     ||	|	          }
||                     |d          ||                     |          |                     ||          |                     |d          ||
|                     |          d		S )
Nr  rB  r  r  r  r  
transferIdr  )	rc  r9   r  r  r  rO  r  r  rB  )	r!  rZ  r  r   r  rg  rd  rl  parse_transfer_status)r  r   r  r  rB  r  fromAccountRawr  r  toAccountRawr  s              r  r  zbitget.parse_transfer  s&   2 %%h55	''(;;%%h77
))(J??t|^RHH&&|^^TT''(;;$$\<NN	""8\::"Y////
HEE&&x88&"0088

 

 
	
r  c                 8    ddi}|                      |||          S )N
successfulr  r
  r  s      r  r  zbitget.parse_transfer_status   s(    $
 &&999r  c                    |                      |dg           }t          |          }|d d dd d di d}t          d|          D ]}||         }|                     |d          }|                     |d          }	|                     ||	          }
d d d|                     |d          ddd	|d
         |
<   |dk    r*|                     |d          |d         d<   d|d         d<   |S )Nr  )r  r2  )rc  r   r  r  r   r  r  r  F)r  r   r  r   r   r  r2  )r   r'  r&  r  r  rl  )r  r  r  r  chainsLengthr2  r.  r  r  r]  r  s              r  parse_deposit_withdraw_feez!bitget.parse_deposit_withdraw_fee&  s;   . h336{{" 
 "  
 
 q,'' 	9 	9A1IE((88I++Hf==L11)\JJK#'t<<$($4$4UM$J$JZ_``/ /F:{+ q  ,0,<,<UM,R,Rz"5)38z"<0r  codesc                     |                                   |                     |          }|                     |dg           }|                     ||d          S )ak  
        fetch deposit and withdraw fees
        :see: 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  r  )r  r  r  parse_deposit_withdraw_fees)r  r  r  r"  r  s        r  fetch_deposit_withdraw_feesz"bitget.fetch_deposit_withdraw_feesY  sX     	66v>>< ~~h33//eVDDDr  c                 >   |                                   |                     |          }|d         |                     ||          d}|                     |                     ||                    }|                     |di           }|                     ||          S )a  
        create a loan to borrow margin
        :see: 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>`
        r9   )r  borrowAmountr  )r  r  currency_to_precision-privateMarginPostV2MarginCrossedAccountBorrowr*  r   parse_margin_loanr  r  rO  r  r  r  r"  r  s           r  borrow_cross_marginzbitget.borrow_cross_margin  s     	==&&TN 66tVDD
 
 EEdkkRY[aFbFbcc x44%%dH555r  c                 x   |                                   |                     |          }|                     |          }|d         |                     ||          |d         d}|                     |                     ||                    }|                     |di           }	|                     |	||          S )a  
        create a loan to borrow margin
        :see: 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>`
        r9   )r  r  r  r  )r  r  r  r  .privateMarginPostV2MarginIsolatedAccountBorrowr*  r   r  
r  r  r  rO  r  r  r  r  r"  r  s
             r  borrow_isolated_marginzbitget.borrow_isolated_margin  s     	==&&V$$TN 66tVDDTl
 

 FFt{{SZ\bGcGcdd x44%%dHf===r  c                 x   |                                   |                     |          }|                     |          }|d         |                     ||          |d         d}|                     |                     ||                    }|                     |di           }	|                     |	||          S )a  
        repay borrowed margin and interest
        :see: 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>`
        r9   )r  repayAmountr  r  )r  r  r  r  -privateMarginPostV2MarginIsolatedAccountRepayr*  r   r  r  s
             r  repay_isolated_marginzbitget.repay_isolated_margin  s     	==&&V$$TN55dFCCTl
 

 EEdkkRY[aFbFbcc x44%%dHf===r  c                 >   |                                   |                     |          }|d         |                     ||          d}|                     |                     ||                    }|                     |di           }|                     ||          S )a  
        repay borrowed margin and interest
        :see: 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>`
        r9   )r  r  r  )r  r  r  ,privateMarginPostV2MarginCrossedAccountRepayr*  r   r  r  s           r  repay_cross_marginzbitget.repay_cross_margin  s     	==&&TN55dFCC
 
 DDT[[QXZ`EaEabb x44%%dH555r  c                 "   |                      |d          }|                      |d          }d }||                     ||d d          }|                     |dd          |                     ||          |                     |dd          |d d |dS )	Nr  r  rF   loanIdrepayIdr  r  )r9   r  rO  r  r  r  rc  )r  r9  rk  rd  rm  )r  rc  r  r  r  rn  r  s          r  r  zbitget.parse_margin_loan	  s    L %%dF33
##D(33%%hfEEF$$T8Y??//
HEE((~}MM
 
 	
r  c           	         |                                   d}|                     |dd          \  }}|r|                     d||||dd          S d}||                     |          }d}|                     d||          \  }}|dk    rt          | j        dz             i }|                     d	||          \  }}|||d
<   n|                                 dz
  |d
<   |||d<   d}	d}
| 	                    d|d          \  }
}|
dk    rN|t          | j        dz             |d         |d<   |                     |                     ||                    }	n/|
dk    r)|                     |                     ||                    }	|                     |	di           }|                     |dg           }|                     ||||          S )a7  
        retrieves the users liquidated positions
        :see: https://www.bitget.com/api-doc/margin/cross/record/Get-Cross-Liquidation-Records
        :see: 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  NrF   z8 fetchMyLiquidations() supports spot margin markets onlyr  r  r  r  r  r  z1 fetchMyLiquidations() requires a symbol argumentr9   r  r  r  )r  r  r  r  rF  r-   r9   r  r  r  r%   2privateMarginGetV2MarginIsolatedLiquidationHistoryr*  1privateMarginGetV2MarginCrossedLiquidationHistoryr   r  parse_liquidations)r  r  r  r  r  r  r  r/  r  r"  r  r  liquidationss                r  fetch_my_liquidationszbitget.fetch_my_liquidations>  s    	88AVXbcc& 	@334I6SXZ_agipr~[[((F99:OQWY_``f6>>tw)ccddd229gvNN#(GK  #'#4#4#6#6#CGK $GG
!??@UW]_fgg
F##~'2e(efff &tGHNNt{{[bdjOkOkllHH7""MMdkkZaciNjNjkkHj x44~~dL"==&&|VUEJJJr  c                    |                      |d          }|                     |d          }|                     |dd          }|                      |d          }t          j        ||          }|                     ||                     ||          d d d d |                     |          ||                     |          d	          S )Nr  
liqEndTimeLiqFeeliqFee	totalDebt)	rc  r  r  r\  rP  	baseValue
quoteValuer  r  )	r  r!  rk  r5   r  safe_liquidationr9  r  rg  )r  liquidationr  rn  r  liquidationFeer  quoteValueStrings           r  parse_liquidationzbitget.parse_liquidation  s    > ##K::%%k<@@	++K8LL$$[+>>	"-niHH$$&&x88 ++,<=="Y//
&
 
&
 
 
 
	r  c                 x   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d          }|                     |dg           }|                     |di           }||d<   |                     ||          S )a  
        fetch the rate of interest to borrow a currency for margin trading
        :see: 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  r9   r  r  r   r  )r  r  4privateMarginGetV2MarginIsolatedInterestRateAndLimitr*  r!  r   parse_isolated_borrow_rate)	r  r  r  r  r  r"  r  r  r  s	            r  fetch_isolated_borrow_ratez!bitget.fetch_isolated_borrow_rate  s     	V$$fTl
 LLT[[Y`bhMiMijjT %%h>>	x44a,,&k..uf===r  c           
         |                      |d          }|                     ||d d          }|                      |d          }|                      |d          }|                     |d          }||                     |          |                     |d          |                     |          |                     |d          d||                     |          |d		S )
Nr  rF   r6  r5  r  baseDailyInterestRatequoteDailyInterestRater{  )	r  r   baseRaterG  	quoteRateperiodr  r  rc  )r  r9  r!  rd  rl  rg  )r  rc  r  rn  r  rH  rI  r  s           r  r  z!bitget.parse_isolated_borrow_rate  s    F ##D(33!!(FD&AA!!$
33""455%%dK88	++F33((/FGG,,W55))$0HII"Y//

 

 
	
r  c                 x   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d          }|                     |dg           }|                     |di           }||d<   |                     ||          S )a  
        fetch the rate of interest to borrow a currency for margin trading
        :see: 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>`
        r  r9   r  r  r   r  )r  r  3privateMarginGetV2MarginCrossedInterestRateAndLimitr*  r!  r   parse_borrow_rate)	r  r  r  r  r  r"  r  r  r  s	            r  fetch_cross_borrow_ratezbitget.fetch_cross_borrow_rateC  s     	==&&HTN
 KKDKKX_agLhLhii6 %%h>>	x44a,,&k%%eX666r  c                     |                      |d          }|                     |d          }|                     ||          |                     |d          d||                     |          |dS )Nr  r  dailyInterestRater{  )r  rater  r  r  rc  )r  r!  rd  rl  rg  )r  rc  r  r  r  s        r  r  zbitget.parse_borrow_rater  s|    ( %%dF33
%%dK88	//
HEE$$T+>??"Y//
 
 	
r  c           	      f   |                                   d}|                     |dd          \  }}|r|                     d||||dd          S d}||                     |          }i }d}	| |                     |          }	|	d         |d<   |||d	<   n|                                 d
z
  |d	<   |||d<   d}
d}|                     d|d          \  }}|dk    rN|t          | j        dz             |d         |d<   | 	                    | 
                    ||                    }
n/|dk    r)|                     | 
                    ||                    }
|                     |
di           }|                     |dg           }|                     ||          }|                     ||||          S )a  
        fetch the interest owed by the user for borrowing currency for margin trading
        :see: https://www.bitget.com/api-doc/margin/cross/record/Get-Cross-Interest-Records
        :see: 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>`
        Frh   r  r  r  Nr9   r  r  r  r  r  r  z1 fetchBorrowInterest() requires a symbol argumentr  r  r  )r  r  r  r  r  r  r  r%   r9   /privateMarginGetV2MarginIsolatedInterestHistoryr*  .privateMarginGetV2MarginCrossedInterestHistoryr   parse_borrow_interestsfilter_by_currency_since_limit)r  r  r  r  r  r  r  r  r  r  r"  r  r  rowsr  s                  r  fetch_borrow_interestzbitget.fetch_borrow_interest  s    	88AVXbcc& 	@334I6SXZ_agipr~[[((F}}T**H&tnGFO#(GK  #'#4#4#6#6#CGK $GG
!??@UW]_fgg
F##~'2e(efff &tGHKKDKKX_agLhLhiiHH7""JJ4;;W^`fKgKghhHf x44t\266..tV<<228T5%PPPr  c           
         |                      |d          }|                     ||          }|dnd}|                     |d          }|                      |d          ||                     |                      |d                    |                     |d          |                     |d          d ||                     |          |d	S )	Nr  r  r  r  interestCoininterestAmountr  )	r  r  r  r  rJ  amountBorrowedr  r  rc  )r  r  r!  rd  rl  rg  )r  rc  r  rn  r  r  s         r  parse_borrow_interestzbitget.parse_borrow_interest  s    : ##D(33!!(F33$,$8ZZw
%%dG44	&&vx88$//0@0@~0V0VWW((/?@@ ,,T3FGG""Y//

 

 
	
r  c                 *   |                                   |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }d}|                     ||          \  }}|d         |d}|||d<   |                     |                     ||                    }	|                     |	di           }
| 	                    |
dg           }| 
                    |d	         |          S )
a  
        closes an open position for a market
        :see: 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>`
        r  FNr9   r7  r,  r  rO  r   )r  r  r  r  r  r  &privateMixPostV2MixOrderClosePositionsr*  r   r  r  )r  r  rR  r  r  r  r  r	  r  r"  r  rV  s               r  close_positionzbitget.close_position  s     	nnT\=%HH 	) ;;FCCM[[//FF[[((F"AA&&QQVTl&
 
 "&GJ>>t{{7TZ?[?[\\$ x44t]B77a&111r  c                 D   |                                   d}|                     d|          \  }}d|i}|                     |                     ||                    }|                     |di           }|                     |dg           }|                     |d|          S )a  
        closes all open positions for a market type
        :see: 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  rO  )r  r  r  r*  r   r  parse_positions)r  r  r	  r  r"  r  r\  s          r  close_all_positionszbitget.close_all_positionsN  s     	"AA$OOV;
 >>t{{7TZ?[?[\\$ x44NN4;;	##ItV<<<r  c                    |                                   |                     | j        dd          }d}|r+|                     |          }|                     |          }n|                     |          }d}|                     ||          \  }}|d         |d         |d}|                     |                     ||                    }|                     |di           }	| 	                    |	|          S )a  
        fetches the margin mode of a trading pair
        :see: 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>`
        r  FNr9   rJ  r   r  )
r  r  r  r  r  r  ri  r*  r  parse_margin_moderF  s
             r  fetch_margin_modezbitget.fetch_margin_moder  s     	nnT\=%HH 	) ;;FCCM[[//FF[[((F"AA&&QQVTl ,&
 

 88Wf9U9UVV: ~~h33%%dF333r  c                 Z    |                      |d          }|dk    rdn|}||d         |dS )Nr  r/  r  r  )rc  r  r  r
  )r  r  r  
marginTypes       r  r  zbitget.parse_margin_mode  sG    %%j,??
!+y!8!8WWz
X&$
 
 	
r  fromCodetoCodec                    |                                   |||                     |          d}|                     |                     ||                    }|                     |di           }|                     |d|          }|                     |          }	|                     |d|          }
|                     |
          }|                     ||	|          S )aG  
        fetch a quote for converting from one currency to another
        :see: 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  )r  r7  %privateConvertGetV2ConvertQuotedPricer*  r  r  r  parse_conversion)r  r  r  rO  r  r  r"  r  fromCurrencyIdfromCurrencytoCurrencyId
toCurrencys               r  fetch_convert_quotezbitget.fetch_convert_quote  s     	  11&99
 

 ==dkk'SY>Z>Z[[" ~~h33))$
HEE}}^44''h??]]<00
$$T<DDDr  c                 X   |                                   |                     |dd          }|t          | j        dz             |                     |dd          }|t          | j        dz             |                     |ddg          }||||                     |          ||d}|                     |                     ||                    }	|                     |	d	i           }
| 	                    |
d
|          }| 
                    |          }|                     |
d|          S )aK  
        convert from one currency to another
        :see: 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>`
        rP  	cnvtPriceNz0 createConvertTrade() requires a price parametertoAmount
toCoinSizez3 createConvertTrade() requires a toAmount parameter)traceIdr  r  r  r  r  r  r  )r  rk  r%   r9   r  r7   privateConvertPostV2ConvertTrader*  r  r  r  r  )r  r9   r  r  rO  r  rP  r  r  r"  r  r  r  s                r  create_convert_tradezbitget.create_convert_trade  s9    	""67K@@=#DG.`$`aaa%%fj,GG#DG.c$cddd6GZ#899  11&99"
 
 88Wf9U9UVV ~~h33''h??]]<00
$$T4<<<r  r  r  c                    |                      |d          }|                     |d          }|                     ||          }|                     |d          }|                     ||          }|||                     |          |                     |d          ||                     |d          ||                     |d          |                     |d          |                     |d          d	
S )
Nr  r  r  r  r  r  r  r  )
rc  r  r  r9   r  
fromAmountr  r  rP  r  )r!  r  rd  rg  rl  )	r  
conversionr  r  r  r  r  tor  s	            r  r  zbitget.parse_conversion
  s    . %%j$77	##J
;;**8\BBj(33((Z88"Y//"":y99$**:~FF ((\BB%%j+>>##J66
 
 	
r  c                    |                                   |                     |          }i }|                     |dg           }t          dt	          |                    D ]}||         }|                     |d          }|                     |          }|||ddddd|                     |d          dd|                     |d          |                     |d          dddddddd	dd
||<   |S )a/  
        fetches all available currencies that can be converted
        :see: 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   r  Nr  	minAmount	maxAmountrS  r  r  )r  $privateConvertGetV2ConvertCurrenciesr  r&  r'  r  rd  rl  )	r  r  r"  r2  r  r.  r  r9   r  s	            r  fetch_convert_currencieszbitget.fetch_convert_currencies3  sD    	<<VDD  ~~h33q#d))$$ 	 	AGE!!%00B**2..D  ,,UK@@!  $//{CC#//{CC 
  $#! !
  $#      5 F4LL8 r  c
                    |sd S |                      |d          }
|                     |dd          }| j        dz   |z   }|
d uo|
dk    }|rD|                     | j        d         |
|           |                     | j        d         |
|           |d uo|dk    }|r"|                     | j        d         ||           |s|rt          |          d S )	Nerr_msgr  err_code r  r  r  ra  )r  rk  r9   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr!   )r  r  reasonurlr  headersbodyr"  requestHeadersrequestBodymessagerb  feedbacknonEmptyMessagenonZeroErrorCodes                  r  handle_errorszbitget.handle_errorso  s	    	42 ""8Y77&&xDD	7S=4'#4/Dgm 	^001I7T\]]]001I7T\]]]%T1M	W8L 	`001I9V^___ 	* 	*)))tr  GETc                 f   |d         dk    }|d         }d}	d|                      ||          z   }
|	|
z   }|                     | j        d         |                   |z   }|                     ||                     |                    }|sW|dk    rQt          |                                          }t          |          }|dk    r|dz   |                     |          z   }|rI| 	                                 t          |                                           }||z   |z   }|d	k    r|                     |          }||z  }nf|rdd|                     |                     |                    z   }|                    d
          dk    r|                    d
d          }||z  }||z  }|                     |                     |          |                     | j                  t&          j        d          }|                     | j        d          }| j        ||| j        |d}|d	k    rd|d<   ||||dS )Nr   r   r   z/apir  r   r  ?POSTz%24r  $base64r   )z
ACCESS-KEYzACCESS-SIGNzACCESS-TIMESTAMPzACCESS-PASSPHRASEzX-CHANNEL-API-CODEzapplication/jsonzContent-Type)r  r  r  r  )implode_paramsimplode_hostnamer   r  extract_paramsr  keysr'  	urlencodecheck_required_credentialsrj  r  r  keysortr  replacehmacencoder   hashlibsha256r  r  r   r   )r  pathr   r  r  r  r  signedendpointpathPartr  payloadr  r  r$  
keysLengthr  auth
queryInner	signaturer   s                        r  signzbitget.sign  s@   Q9$q6++D&999W$##DIe$4X$>??'I		&$"5"5d";";<< 	86U??

%%DTJA~~Ci$.."7"77 	=++---D--//00Iv%/Dyy(( '!$t~~dll66J6J'K'K!KJ!u--22%/%7%7s%C%C
:%CJ&D		$++d"3"3T[[5M5Mw~_ghhI%%dlH==F"k($-%)]&, G *<'fdwOOOr  )N)NNN)NN)__name__
__module____qualname__r  r  r  r  r#  r    r   r3  r  r)  r   r  rj  r  r  r   r
   r   r  floatr   r  r   r   r  r  r  r   r  r   r?  rC  r   r   rJ  r   r^  ri  r   rn  r   rr  rm  r  ry  r  r   r  r  r  r   r  r  r   r   r   r  r  r   r^  rw  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  rB  rG  rE  r	   rV  rX  rU  r   r_  r^  r  rg  r   rk  rj  rs  rw  boolrz  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  r6  __classcell__)r  s   @r  r7   r7   #   s       v v v v vp+. . .  6 59 % % % %> !# 5 5 5 5* $&    $v,        Dw
f w
 w
 w
 w
r 24 P( P( P( P(d ') u uZ u u u un ?A f@ f@# f@ f@ f@ f@P9 9 9 9 9 9v *.Dt\^ 8P 8P3 8Pc 8P 8Pcghsct 8P 8P 8P 8Pt ?C2 J JS J% J J J JX -1tRV_a ;P ;Pc ;P ;PC ;Pfjkvfw ;P ;P ;P ;PzI
 I
x I
; I
 I
 I
 I
V: : : 79 $: $:# $: $: $: $:L
 
h 
 
 
 
0 :>b -H -Hs -H3 -HY -H -H -H -H^m m6 mV m m m m^ 02 \2 \23 \2f \2 \2 \2 \2| 04B _1 _1W _17 _1 _1 _1 _1Bs s s5 s s s sj 6:UW f= f=3 f=s f=# f=\`af\g f= f= f= f=P 57 $4 $4 $4;N $4 $4 $4 $4L )+ o o{ o o o ob	
 	
f 	
 	
 	
 	

 
 
4 
 
 
 
* 26DW[df vH vH# vHc vHQT vHkoptku vH vH vH vHp $& y( y(( y( y( y( y(vV) V) V) V) V)p: : :*t t t5 t t t tl RT N N N5 N N N N$ gksu Q. Q.3 Q.i Q.y Q.RW Q.`c Q. Q. Q. Q.f os{} l, l,3 l,i l,y l,Z_ l,hk l, l, l, l,\ @B ]/ ]/D$6 ]/ ]/ ]/ ]/~ `drv  @B R. R.S R.# R.Y R.i R.Y\ R.lo R. R. R. R.h 37r w/ w/s w/C w/ w/ w/ w/r 04B N1 N1 N1 N1 N1 N1` /32 d d d d d dL 26b k/ k/c k/3 k/ k/ k/ k/^ /3TXac X= X= X=3 X=c X=hlmrhs X= X= X= X=t 154VZce : :# :S :PS :jnotju : : : :0 37TX\eg < <C <s <RU < < < <0 >BPTcgpr W? W?s W?# W?]` W? W? W? W?r (,$TZ\ g? g? g?C g?s g? g? g? g?R6
 6
 6
 6
 6
 6
p+3 +3 +3Z -1tRV_a g= g=c g= g=C g=fjkpfq g= g= g= g=R 24 82 82S 82 82 82 82t 26b GP GPw GPT(^ GP GP GP GPRa av a a a aF 8<$]ajl AY AY AYC AYWZ AY AY AY AYF 68 '8 '8 '8 '8 '8 '8R
 
6 
 
 
 
: 37TX\eg BJ BJC BJs BJRU BJlpq  mA BJ BJ BJ BJH
 
f 
 
 
 
4	@ 	@S 	@X[ 	@gklzg{ 	@ 	@ 	@ 	@ FH    3  L^        D
 
f 
HZ 
 
 
 
4 9; K KC K?Q K K K K  68 H H H<N H H H H 24 51 51S 51 51 51 51 51n
 
x 
 
 
 
 9=R - -S -# - - - -^ >B" / /# /s / / / /b =A % % %c % % % %N 79 *6 *6# *6 *6 *6 *6X F    0 +/TPT]_ 5B 5BC 5Bs 5B# 5B 5B 5B 5Bn [] ,3 ,3S ,3% ,3c ,3c ,3an ,3 ,3 ,3 ,3\+
 +
 +
 +
 +
 +
Z: : :1 1 1 1 1 1f <@ (E (E (E (E (E (ET DF 6 6 6U 6 6 6 6> TV !> !>S !> !>U !> !> !> !>F LN "> ">C ">s "> "> "> ">H <> 6 6s 6 6 6 6@3
 3
 3
 3
 3
 3
 3
j 37TX\eg bK bKC bKs bKRU bKlpq|l} bK bK bK bKH. .V . . . .` >@ ;> ;> ;> ;> ;> ;>z2
 2
v 2
 2
 2
 2
h 9; -7 -7C -7 -7 -7 -7^
 
 
 
 
 
> 15DW[jnwy _Q _Q# _Qc _QQT _Qdg _Q _Q _Q _QB+
 +
& +
 +
 +
 +
Z =A -2 -2S -2	 -2PU -2 -2 -2 -2^ *, "= "=X "= "= "= "=H 57 54 54 54: 54 54 54 54n
 
J 
 
 
 
 MQY[ &E &EC &E &Ec &E`j &E &E &E &EP W[ce .= .=s .=c .=3 .=PS .=jt .= .= .= .=`'
 '
 '
V^ '
jt '
 '
 '
 '
R /1 : :Z : : : :x' ' 'R  b$T 'P 'P 'P 'P 'P 'P 'P 'Pr  r7   )=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   typingr    ccxt.base.errorsr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   ccxt.base.decimal_to_precisionr4   ccxt.base.preciser5   r7    r  r  <module>rE     sy   ( ' ' ' ' ' , , , , , ,   D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D       * * * * * * 0 0 0 0 0 0 - - - - - - - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . + + + + + + ) ) ) ) ) ) * * * * * * * * * * * * ) ) ) ) ) ) + + + + + + . . . . . . 1 1 1 1 1 1 * * * * * * ) ) ) ) ) ) + + + + + + 4 4 4 4 4 4 % % % % % %\~P \~P \~P \~P \~PX{ \~P \~P \~P \~P \~Pr  