
    !:hY                       d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- d dl.m/Z/ d dl0m1Z1 d dl0m2Z2 d dl0m3Z3 d d	l0m4Z4 d d
l0m5Z5 d dl0m6Z6 d dl0m7Z7 d dl0m8Z8 d dl0m9Z9 d dl0m:Z: d dl0m;Z; d dl0m<Z< d dl0m=Z= d dl0m>Z> d dl0m?Z? d dl0m@Z@ d dl0mAZA d dlBmCZC d dlDmEZE  G d dee      ZFy)    )Exchange)ImplicitAPIN)(AnyBalancesBorrowInterest
ConversionCrossBorrowRate
CurrenciesCurrencyDepositAddressFundingHistoryGreeksIntLedgerEntryLeverageLeverageTierLeverageTiersLiquidationLongShortRatioMarketNumOptionOptionChainOrder	OrderBookOrderRequestCancellationRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTradingFeeInterfaceTradingFeesTransactionMarketInterfaceTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)NoChange)MarginModeAlreadySet)ManualInteractionNeeded)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)RateLimitExceeded)InvalidNonce)RequestTimeout)	TICK_SIZE)Precisec                       e Zd Zdef fdZdefdZd Zd Zi fdZ	i fdZ
d	efd
Zddededededef
 fdZi fdZd	edefdZd	edefdZd	edefdZi fdefdZi fdefdZi fdee   fdZdee   fdZdee   fdZdee   fdZddedede fdZ!i fd	ede fd Z"di fd!e#de$fd"Z%di fd!e#d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(Z)dded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fd+Z.dd,edede/fd-Z0ddi fd	ed&ed'edee/   fd.Z1di fd	ed'ede2fd/Z3de4fd0Z5i fde4fd1Z6d2efd3Z7d4efd5Z8dd6edede9fd7Z:i fd	edede9fd8Z;i fd	edede9fd9Z<di fd	ed:e=d;e>dede?de9fd<Z@di d=fd	ed:e=d;e>dede?f
d>ZAi fd?eeB   dee9   fd@ZCddi fdAed	ed:e=d;e>de?de?fdBZDddi fdAed	ed:e=d;e>de?de?de9fdCZEi fd?eeB   dee9   fdDZFdi fdAed	efdEZGdi fdAed	ede9fdFZHdi fd	edee9   fdGZIi fdHefdIZJi fd?eeK   fdJZLdi fd	efdKZMdi fdAed	ede9fdLZNdi fdAed	ede9fdMZOdddi fd	ed&ed'edee9   fdNZPdddi fd	ed&ed'edee9   fdOZQdi fdAed	ede9fdPZRdi fdAed	ede9fdQZSdddi fd	ed&ed'edee9   fdRZTdddi fd	ed&ed'edee9   fdSZUdddi fd	ed&ed'edee9   fdTZVdddi fd	ed&ed'edee9   fdUZWdddi fdAed	ed&ed'edee/   f
dVZXdddi fd	ed&ed'edee/   fdWZYddXeZde[fdYZ\i fdZedee[   fd[Z]i fdZede[fd\Z^dddi fdZed&ed'edee_   fd]Z`dddi fdZed&ed'edee_   fd^Zad2efd_Zbdd`edXeZde_fdaZcdddi fdZed&ed'edeed   fdbZeddcedXeZdedfddZfde Zgdi fdZededfede_fdgZhi fd	edeifdhZjdi fd!e#deei   fdiZkddjededeifdkZli fd	edemfdlZnddmededemfdnZodi fdoed	efdpZpdi fdmed	efdqZqdi fdred	efdsZrdtddi fd	ed&ed'efduZsi fd	efdvZtdtddi fd	ed&ed'efdwZuddefdxZvi fdZedewfdyZxddXeZfdzZyddddi fdZed	ed&ed'edeez   f
d{Z{ddi fdZed&ed'efd|Z|dd}ededezfd~Z}i fdZedededede~f
dZdddi fdZed&ed'edee~   fdZi fdZedefdZi fdZefdZddXeZdefdZd2edefdZddedXeZde~fdZi fd	edee   fdZi fd	edee   fdZddededefdZi fd	edefdZi fdefdZddXeZdefdZdi fde#fdZdddi fd	ed&ed'efdZdddi fd	ed&ed'efdZd Zd Zi fdZefdZd Zi fd	edefdZddededefdZdddi fd	ed&ed'edee   fdZddedefdZdi fd	efdZdi fd!e#defdZdd!e#defdZddedee   fdZdddi fd	ed&ed'edee   fdZddedefdZi fd	edefdZi fdZedefdZddedXeZdedefdZdddi fd!e#d&ed'edeei   fdZi fdefdZdi fdedede?defdZdi fdAededede?def
dZdi fdAedZedefdZdddi fdZed&ed'edee   fdZddedeZdeZdefdZddddi fd	eded&ed'edee   f
dZdd}ededefdZddi ddfdZdedededededefdZ xZS )bybitreturnc                 *.   | j                  t        t        |          i ddddddgddd	d d
ddddddddi ddddddddddddddddddddddddddd dd!dd"dd#di d$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1dd2dd3d4d5di d6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBddCddDddEddFdi dGddHd4dIddJddKd4dLddMddNddOddPddQddRddSddTddUddVddWdi dXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcdddddeddfddgddhdi diddjd4dkddlddmddnddoddpddqddrddsddtdduddvddwddxddydddddddddzd{d|d}d~ddddddddddddddddddddddddddddddddg ddddddi 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i ddddddddddddddddddddddddddddddddddddddd̜i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i ddddddddddddddddddddddddؓd dddddddddi ddΓddddd	dؓd
dؓddddddddddddddddddddddddi ddddddddddddؓddddddd dd!dd"dd#d$d%d$d&d$d'dd(di d)dd*dd+dΓd,dd-dd.dd/dd0dΓd1dd2dؓd3dؓd4dd5dؓd6dؓd7d8d9dؓd:di d;dd<dd=dd>dd?dd@ddAddBddCddDddEddFddGddHddIddJddKdi dLddMddNddOddPddQddRddSddTddUddVddWddXddYddZdd[dd\dؓddd]i ddГd^dГd_dГd`dГdadГdbdГdcdؓdddؓdedfdgdhdiddjdfdkdfdldؓdmdؓdndؓdodؓi dpdؓdqdؓdrdؓdsddtdduddvddwddxdΓdydГdzdd{dd|dd}dd~ddddd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i ddddddddddddddddddddddddddddddddfddؓi ddddddddؓddؓddؓddؓddؓddؓddؓddГddГddddddГddГddГdddddddddddddddŜdƜdǜdȐdt        idi dt
        dt
        dt
        dt
        dt        dt        dt        dt        dt
        dt
        dt
        dt        dt
        dt
        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt
        dt        dt
        dt        dt        dt        dt        dt        dt        dt        dt
        i dt
        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt
        dt        dt
        dt        i dt        dt
        d t        dt        dt        dt        dt        dt
        dt        dt        dt        d	t
        d
t
        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt
        dt        dt        dt
        dt
        dt
        dt
        dt
        i d t        d!t        d"t        d#t        d$t        d%t        d&t        d't        d(t        d)t
        d*t
        d+t
        d,t        d-t        d.t        d/t        d0t        i d1t        d2t        d3t        d4t        d5t        d6t        d7t        d8t        d9t        d:t        d;t        d<t        d=t        d>t        d?t        d@t        dAt
        i dBt
        dCt
        dDt
        dEt        dFt
        dGt        dHt
        dIt
        dJt
        dKt        dLt
        dMt
        dNt
        dOt        dPt        dQt         dRt         i dSt
        dTt        dUt        dVt        dWt
        dXt
        dYt
        dZt        d[t        d\t        d]t        d^t
        d_t
        d`t
        dat        dbt        dct        i ddt        det        dft        dgt        dht        dit        djt        dkt        dlt        dmt        dnt        dot
        dpt        dqt        drt        dst        dtt
        i dut        dvt        dwt        dxt        dyt        dzt
        d{t
        d|t
        d}t
        d~t        dt
        dt        dt
        dt        dt        dt        dt        i dt
        dt        dt
        dt
        dt        dt        dt        dt
        dt        dt        dt
        dt
        dt
        dt
        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt
        dt
        dt
        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt"        dt        dt        dt        dt        dt        dt        dt        dt
        dt
        dt
        dt
        dt        dt        i dt        dt        dt        dt
        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt
        dt        dt        dt        dt        i dt        dt        dt        dt        dt$        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        d t        dt        dt        dt
        dt
        dt
        dt
        dt
        dt
        d	t
        d
t
        dt
        dt
        dt
        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 d0t        d1t        d2t        d3t        d4t        d5t        d6t        d7t        d8t        d9t        d:t        d;t        d<t        d=t        d>t        d?t        d@t        i dAt        dBt        dCt
        dDt
        dEt
        dFt
        dGt
        dHt
        dIt
        dJt        dKt        dLt        dMt        dNt        dOt        dPt        dQt        i dRt        dSt        dTt        dUt        dVt        dWt        dXt        dYt        dZt        d[t        d\t        d]t        d^t        d_t        d`t        dat        dbt        i dct        ddt        det        dft        dgt        dht        dit        djt        dkt        dlt        dmt        dnt        dot        dpt        dqt        drt        dst        i dtt        dut        dvt        dwt        dxt        dyt        dzt        d{t        d|t        d}t        d~t        dt
        dt
        dt        dt        dt
        dt
        dt        it&        t"        t        t        t        t        t        dddt(        di dddddYg ddd dd dd dddddddddddddddddddddddddddddddddd
ddddddddi ddddddddddddddddddddddddddddddÓdĐdēdŐdœi dƐdƓdǐdǓdȐdȓdɐdɓdʐdʓdːd˓d̐d̓d͐d͓dΐdΓdϐdГdѐdѓdҐdғdӐdӓdԐdԓdՐdՓd֐d֓dאdד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ddidd ddddddddddddddddddddddddddd	dddddddd
ddidddddddddddddddddd dddddddddddiddid
dd dd dddddddiddidddiddiddddddddddi i dd d!      S ("  NidrB   nameBybit	countriesVGversionv5	userAgent	rateLimit   hostnamez	bybit.comproT	certifiedhasCORSspotmarginswapfutureoptionborrowCrossMargincancelAllOrderscancelAllOrdersAftercancelOrdercancelOrderscancelOrdersForSymbolscloseAllPositionsFclosePositioncreateConvertTradecreateMarketBuyOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrders$createOrderWithTakeProfitAndStopLosscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopLossOrdercreateStopMarketOrdercreateStopOrdercreateTakeProfitOrdercreateTrailingAmountOrdercreateTriggerOrder	editOrder
editOrdersfetchBalancefetchBidsAsksemulatedfetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledAndClosedOrdersfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchConvertCurrenciesfetchConvertQuotefetchConvertTradefetchConvertTradeHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchLeverageTiersfetchLongShortRatiofetchLongShortRatioHistoryfetchMarginAdjustmentHistoryfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionsfetchPositionsHistoryfetchPremiumIndexOHLCVfetchSettlementHistoryfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsfetchTransfersfetchUnderlyingAssetsfetchVolatilityHistoryfetchWithdrawals)repayCrossMarginsandboxsetLeveragesetMarginModesetPositionModetransferwithdraw
timeframes135153060120240360720DWM)1m3m5m15m30m1h2h4h6h12h1d1w1Murlszhttps://api-testnet.{hostname})rT   futuresv2publicprivatezOhttps://github.com/user-attachments/assets/97a5d0b3-de10-423d-90e1-6620960025edzhttps://api.{hostname}zhttps://api-demo.{hostname}zhttps://www.bybit.com)z.https://bybit-exchange.github.io/docs/inverse/z-https://bybit-exchange.github.io/docs/linear/z!https://github.com/bybit-exchangez5https://help.bybit.com/hc/en-us/articles/360039261154z1https://www.bybit.com/register?affiliate_id=35953)testlogoapidemotradingwwwdocfeesreferralr   getzspot/v3/public/symbols   zspot/v3/public/quote/depthz!spot/v3/public/quote/depth/mergedzspot/v3/public/quote/tradeszspot/v3/public/quote/klinez spot/v3/public/quote/ticker/24hrz!spot/v3/public/quote/ticker/pricez&spot/v3/public/quote/ticker/bookTickerzspot/v3/public/server-timezspot/v3/public/infosz#spot/v3/public/margin-product-infosz#spot/v3/public/margin-ensure-tokenszv3/public/timez*contract/v3/public/copytrading/symbol/listz#derivatives/v3/public/order-book/L2zderivatives/v3/public/klinezderivatives/v3/public/tickersz&derivatives/v3/public/instruments-infoz&derivatives/v3/public/mark-price-klinez'derivatives/v3/public/index-price-klinez2derivatives/v3/public/funding/history-funding-ratez%derivatives/v3/public/risk-limit/listz$derivatives/v3/public/delivery-pricez"derivatives/v3/public/recent-tradez#derivatives/v3/public/open-interestzderivatives/v3/public/insurancezv5/announcements/index   zv5/market/timezv5/market/klinezv5/market/mark-price-klinezv5/market/index-price-klinez#v5/market/premium-index-price-klinezv5/market/instruments-infozv5/market/orderbookzv5/market/tickerszv5/market/funding/historyzv5/market/recent-tradezv5/market/open-interestzv5/market/historical-volatilityzv5/market/insurancezv5/market/risk-limitzv5/market/delivery-pricezv5/market/account-ratiozv5/spot-lever-token/infozv5/spot-lever-token/referencezv5/spot-margin-trade/datazv5/spot-margin-trade/collateralzv5/spot-cross-margin-trade/dataz'v5/spot-cross-margin-trade/pledge-tokenz'v5/spot-cross-margin-trade/borrow-tokenzv5/crypto-loan/collateral-data)zv5/crypto-loan/loanable-datav5/ins-loan/product-infos!v5/ins-loan/ensure-tokens-convertzv5/earn/productzv2/private/wallet/fund/records   zspot/v3/private/orderg      @zspot/v3/private/open-orderszspot/v3/private/history-orderszspot/v3/private/my-tradeszspot/v3/private/accountzspot/v3/private/referencezspot/v3/private/recordz#spot/v3/private/cross-margin-orders
   z$spot/v3/private/cross-margin-accountz&spot/v3/private/cross-margin-loan-infoz*spot/v3/private/cross-margin-repay-historyz!spot/v3/private/margin-loan-infosz#spot/v3/private/margin-repaid-infoszspot/v3/private/margin-ltvz3asset/v3/private/transfer/inter-transfer/list/query2   z/asset/v3/private/transfer/sub-member/list/queryz8asset/v3/private/transfer/sub-member-transfer/list/queryz7asset/v3/private/transfer/universal-transfer/list/queryz asset/v3/private/coin-info/queryz&asset/v3/private/deposit/address/queryz*contract/v3/private/copytrading/order/list   z-contract/v3/private/copytrading/position/list(   z.contract/v3/private/copytrading/wallet/balancez'contract/v3/private/position/limit-infoz)contract/v3/private/order/unfilled-orderszcontract/v3/private/order/listz!contract/v3/private/position/listz"contract/v3/private/execution/listz'contract/v3/private/position/closed-pnlz*contract/v3/private/account/wallet/balancez$contract/v3/private/account/fee-ratez/contract/v3/private/account/wallet/fund-recordsz(unified/v3/private/order/unfilled-orderszunified/v3/private/order/listz unified/v3/private/position/listz!unified/v3/private/execution/listz"unified/v3/private/delivery-recordz$unified/v3/private/settlement-recordz)unified/v3/private/account/wallet/balancez*unified/v3/private/account/transaction-logz)unified/v3/private/account/borrow-historyz&unified/v3/private/account/borrow-ratezunified/v3/private/account/infoz!user/v3/private/frozen-sub-memberz!user/v3/private/query-sub-memberszuser/v3/private/query-apizuser/v3/private/get-member-typez2asset/v3/private/transfer/transfer-coin/list/queryz4asset/v3/private/transfer/account-coin/balance/queryz5asset/v3/private/transfer/account-coins/balance/queryz*asset/v3/private/transfer/asset-info/queryz2asset/v3/public/deposit/allowed-deposit-list/queryg(\?z%asset/v3/private/deposit/record/queryz&asset/v3/private/withdraw/record/queryzv5/order/realtimezv5/order/historyzv5/order/spot-borrow-checkzv5/position/listzv5/execution/listzv5/position/closed-pnlzv5/position/move-historyzv5/pre-upgrade/order/historyzv5/pre-upgrade/execution/listz"v5/pre-upgrade/position/closed-pnlz&v5/pre-upgrade/account/transaction-logz$v5/pre-upgrade/asset/delivery-recordz&v5/pre-upgrade/asset/settlement-recordzv5/account/wallet-balancezv5/account/borrow-historyzv5/account/collateral-infozv5/asset/coin-greekszv5/account/fee-ratezv5/account/infozv5/account/transaction-logz#v5/account/contract-transaction-logzv5/account/smp-groupzv5/account/mmp-statezv5/account/withdrawalz!v5/asset/exchange/query-coin-listg      ?z&v5/asset/exchange/convert-result-queryz'v5/asset/exchange/query-convert-historyzv5/asset/exchange/order-recordzv5/asset/delivery-recordzv5/asset/settlement-recordz"v5/asset/transfer/query-asset-infoz-v5/asset/transfer/query-account-coins-balancez,v5/asset/transfer/query-account-coin-balancez*v5/asset/transfer/query-transfer-coin-listz+v5/asset/transfer/query-inter-transfer-listz'v5/asset/transfer/query-sub-member-listz/v5/asset/transfer/query-universal-transfer-listz#v5/asset/deposit/query-allowed-listzv5/asset/deposit/query-recordz(v5/asset/deposit/query-sub-member-recordz&v5/asset/deposit/query-internal-recordzv5/asset/deposit/query-addressz)v5/asset/deposit/query-sub-member-addresszv5/asset/coin/query-info   zv5/asset/withdraw/query-recordz%v5/asset/withdraw/withdrawable-amountzv5/asset/withdraw/vasp/listzv5/user/query-sub-memberszv5/user/query-apizv5/user/sub-apikeyszv5/user/get-member-typezv5/user/aff-customer-infozv5/user/del-submemberzv5/user/submemberszv5/affiliate/aff-user-listz v5/spot-lever-token/order-recordz*v5/spot-margin-trade/interest-rate-historyzv5/spot-margin-trade/statez$v5/spot-cross-margin-trade/loan-infoz"v5/spot-cross-margin-trade/accountz!v5/spot-cross-margin-trade/ordersz(v5/spot-cross-margin-trade/repay-historyz1v5/crypto-loan/borrowable-collateralisable-numberzv5/crypto-loan/ongoing-ordersz v5/crypto-loan/repayment-historyzv5/crypto-loan/borrow-historyz$v5/crypto-loan/max-collateral-amountz!v5/crypto-loan/adjustment-historyr   r   zv5/ins-loan/loan-orderzv5/ins-loan/repaid-historyzv5/ins-loan/ltv-convertzv5/lending/infozv5/lending/history-orderzv5/lending/accountzv5/broker/earning-recordzv5/broker/earnings-infozv5/broker/account-infoz/v5/broker/asset/query-sub-member-deposit-record)zv5/earn/orderzv5/earn/positionzspot/v3/private/cancel-orderzspot/v3/private/cancel-ordersz$spot/v3/private/cancel-orders-by-idszspot/v3/private/purchasezspot/v3/private/redeemz!spot/v3/private/cross-margin-loanz"spot/v3/private/cross-margin-repayz(asset/v3/private/transfer/inter-transfer   z asset/v3/private/withdraw/createi,  z asset/v3/private/withdraw/cancelz-asset/v3/private/transfer/sub-member-transferz2asset/v3/private/transfer/transfer-sub-member-savez,asset/v3/private/transfer/universal-transferz!user/v3/private/create-sub-memberzuser/v3/private/create-sub-apizuser/v3/private/update-apizuser/v3/private/delete-apizuser/v3/private/update-sub-apizuser/v3/private/delete-sub-apiz,contract/v3/private/copytrading/order/createz,contract/v3/private/copytrading/order/cancelz+contract/v3/private/copytrading/order/closez.contract/v3/private/copytrading/position/closez5contract/v3/private/copytrading/position/set-leveragez/contract/v3/private/copytrading/wallet/transferz2contract/v3/private/copytrading/order/trading-stopz contract/v3/private/order/createz contract/v3/private/order/cancelz$contract/v3/private/order/cancel-allz!contract/v3/private/order/replacez0contract/v3/private/position/set-auto-add-marginz,contract/v3/private/position/switch-isolatedz(contract/v3/private/position/switch-modez-contract/v3/private/position/switch-tpsl-modez)contract/v3/private/position/set-leveragez)contract/v3/private/position/trading-stopz+contract/v3/private/position/set-risk-limitz)contract/v3/private/account/setMarginModezunified/v3/private/order/createz unified/v3/private/order/replacezunified/v3/private/order/cancelz%unified/v3/private/order/create-batchz&unified/v3/private/order/replace-batchz%unified/v3/private/order/cancel-batchz#unified/v3/private/order/cancel-allz(unified/v3/private/position/set-leveragez,unified/v3/private/position/tpsl/switch-modez*unified/v3/private/position/set-risk-limitz(unified/v3/private/position/trading-stopz2unified/v3/private/account/upgrade-unified-accountz(unified/v3/private/account/setMarginModez*fht/compliance/tax/v3/private/registertimez$fht/compliance/tax/v3/private/createz$fht/compliance/tax/v3/private/statusz!fht/compliance/tax/v3/private/urlzv5/order/createzv5/order/amendzv5/order/cancelzv5/order/cancel-allzv5/order/create-batchzv5/order/amend-batchzv5/order/cancel-batchz v5/order/disconnected-cancel-allzv5/position/set-leveragezv5/position/switch-isolatedzv5/position/set-tpsl-modezv5/position/switch-modezv5/position/set-risk-limitzv5/position/trading-stopzv5/position/set-auto-add-marginzv5/position/add-marginzv5/position/move-positionszv5/position/confirm-pending-mmrzv5/account/upgrade-to-utazv5/account/quick-repaymentzv5/account/set-margin-modezv5/account/set-hedging-modezv5/account/mmp-modifyzv5/account/mmp-resetzv5/asset/exchange/quote-applyz!v5/asset/exchange/convert-executez v5/asset/transfer/inter-transferz*v5/asset/transfer/save-transfer-sub-memberz$v5/asset/transfer/universal-transferz#v5/asset/deposit/deposit-to-accountzv5/asset/withdraw/createzv5/asset/withdraw/cancelzv5/user/create-sub-memberzv5/user/create-sub-apizv5/user/frozen-sub-memberzv5/user/update-apizv5/user/update-sub-apizv5/user/delete-apizv5/user/delete-sub-apizv5/spot-lever-token/purchasezv5/spot-lever-token/redeemz v5/spot-margin-trade/switch-modez!v5/spot-margin-trade/set-leveragezv5/spot-cross-margin-trade/loanz v5/spot-cross-margin-trade/repayz!v5/spot-cross-margin-trade/switch)zv5/crypto-loan/borrowzv5/crypto-loan/repayzv5/crypto-loan/adjust-ltvzv5/ins-loan/association-uidzv5/lending/purchasezv5/lending/redeemzv5/lending/redeem-cancelz v5/account/set-collateral-switchz&v5/account/set-collateral-switch-batchzv5/account/demo-apply-moneyzv5/broker/award/infoz v5/broker/award/distribute-awardz#v5/broker/award/distribution-recordzv5/earn/place-order)r   post)r   r   httpExceptions403
exceptionsz-10009z-1004z-1021z-1103z-1140z-1197z-2013z-2015z-6017z-6025z-60295004700110001100021000310004100051000610007100081000910010100141001610017100181002010024100271002810029121371220112141100028110001110003110004110005110006110007110008110009110010110011110012110013110014110015110016110017110018110019110020110021110022110023110024110025110026110027110028110029110030110031110032110033110034110035110036110037110038110039110040110041110042110043110044110045110046110047110048110049110050110051110052110053110054110055110056110057110058110059110060110061110062110063110064110065110066110067110068110069110070110071110072110073110092110093110094130006130021130074131001131084131200131201131202131203131204131205131206131207131208131209131210131211131212131213131214131215131216131217131231131232131002131003131004131085131086131088131089131090131091131092131093131094131095131096131097131098131099140001140003140004140005140006140007140008140009140010140011140012140013140014140015140016140017140018140019140020140021140022140023140024140025140026140027140028140029140030140031140032140033140034140035140036140037140038140039140040140041140042140043140044140045140046140047140048140049140050140051140052140053140054140055140056140057140058140059140060140061140062140063140064140065140066140067140068140069140070170001170005170007170010170011170019170031170032170033170034170035170036170037170105170115170116170117170121170124170130170131170132170133170134170135170136170137170139170140170141170142170143170144170145170146170147170148170149170150170151170157170159170190170191170192170193170194170195170196170197170198170199170200170201170202170203170204170206170210170213170217170218170221170222170223170224170226170227170228170229170234170241175000175001175002175003175004175005175006175007175008175009175010175012175013175014175015175016175017175027176002176004176003176006176005176008176007176010176009176012176011176014176013176015176016176017176018176019176020176021176022176023176024176025176026176027176028176029176030176031176034176035176036176037176038176039176040181000181001181002181003181004182000181017200012000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232003120070200712008430001300033000430005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3004130042300433004430045300493005030051300523005430057300633006730068300743007530078330043402634036350153400993400045310011631001983200300)zNot supported symbolszRequest timeoutzunknown orderInfozinvalid api_keyoc_diffnew_oczopenapi sign params error!)exactbroadprecisionModeoptionsusePrivateInstrumentsInfoenableDemoTrading)rT   linearinverserX   enableUnifiedMarginenableUnifiedAccountunifiedMarginStatus!createMarketBuyOrderRequiresPricecreateUnifiedMarginAccountdefaultTypedefaultSubTyper  defaultSettleUSDTcodeBTC
recvWindowi  timeDifferencer   adjustForTimeDifferenceloadAllOptionsloadExpiredOptionsCCXTSPOTCONTRACTOPTION
INVESTMENTUNIFIEDFUND)
rT   rU   rW   rV   rX   
investmentunifiedfundingfundcontractr  r  r  r  )r  MARGINr  r  r  r  r  ERC20ETHTRC20TRXBEP20BSCSOLACAADAALGOAPTAPTOSARARBONEARBIAVAXCCAVAXAVAXXXAVAXATOMBCHBEP2BNBCHZDCRDGBDOGEDOTEGLDEOSETCETHFETHWFILSTEPFITFIFLOWFTMGLMRHBARHNTICPICXKDAKLAYKMAKSMLTCMATICMINAMOVRNEARNEMOASYSOASOASISROSEOMNIONEOPTIMISMOPPOKTQTUMRVNSCSCRTSTXTHETATONWAVESWAXWAXPXDCXECXLMXRPXTZXYMZENZILZKSYNC)r  r  r  r	  SPL5min15min30minr   r   r   )r   r   r   r   r   r   )brokerIdaccountsByTypeaccountsByIdnetworksnetworksByIddefaultNetworkdefaultNetworks	intervals)lastmarkindex)triggerPriceTypeprice)IOCFOKPOGTD)
marginModetriggerPricer0  triggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedselfTradePreventiontrailingicebergleveragemarketBuyRequiresPricemarketBuyByCostmaxd   i     )r6  limitdaysBack	untilDayssymbolRequired)r6  triggerr?  rJ  )r6  rG  rK  r?  rJ  )r6  rG  rH  daysBackCanceledrI  rK  r?  rJ  rG    )
r   rd   re   r   r   r   r   r{   r   rq   default)r0  r8  r;  rB  )extendsrd   rO  )r  r  )rN  rT   rV   rW   g~jtH?g-C6?)feeSide	tierBased
percentagetakermaker)rQ  rR  r   deposit)tradingr  )featuresr   )deep_extendsuperrB   describer<   r3   r9   r/   r.   r=   r0   r1   r:   r8   r5   r6   r;   r>   r7   r4   r?   )self	__class__s    D/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/bybit.pyrZ  zbybit.describe"   s9   eT ; = n@
'n@
Gn@
 $n@
 t	n@

 n@
 n@
 n@
 4n@
 n@
  nnn $n 	n
 $n $n $Tn "4n 'n tn n )$n $Un  n %dn  /!n" 0#n$ t%n& 'n( 7)n* &t+n, (-n. '/n0 &t1n2 (3n4 "45n6 (7n8 ,T9n: %d;n< T=n> d?n@ AnB  CnD &uEnF +EGnH )%InJ /KnL &tMnN #DOnP $TQnR )$SnT $TUnV $TWnX +DYnZ '[n\ (]n^ "4_n` anb &tcnd (enf 1$gnh  inj *:knl +Dmnn &tonp #Jqnr *4snt $Tunv twnx "4ynz *5{n| +E}n~ tn@  AnB %dCnD &uEnF -dGnH /InJ +DKnL MnN !$OnP &tQnR +DSnT  UnV dWnX $TYnZ +D[n\ !$]n^ "4_n` tanb #Dcnd denf !$gnh uinj #Dknl  mnn '
onp !$qnr (snt )$unv )$wnx tynz {n| T}n~ tn@ "4AnB #DCnD $UEnF !$GnH (InJ )$KnL #DMnN %)#!%#'  [nn@
r sn@
P <?:>? j47267 :<7;<  /
 PO=Qn@
P  B0!B 5aB <Q	B
 6qB 5aB ;AB <QB A!B 5aB /B >qB >qB )!B  Ea!B$ >q%B& 6q'B( 8)B* A!+B, A!-B. B1/B0 Ma1B2 @3B4 ?5B6 =a7B8 >q9B: :1;B> 1!?BB )!CBD *1EBF 5aGBH 6qIBJ >qKBL 5aMBN .qOBP ,QQBR 4QSBT 1!UBV 21WBX :1YBZ .q[B\ /]B^ 3A_B` 21aBd 3AeBf 8gBj 4QkBl :1mBn :1oBp B1qBr B1sBv 9!wBx 9:56=>+,CBDL^4a^ 9"^
 0^ 6s^ 9#^ 4S^ 23^ 4S^ 1#^ >r^ ?^ A"^ Eb^  <R!^" >r#^$ 5b%^( Nr)^* J2+^, STV-^. RSU/^0 ;B1^2 A"3^4 Eb5^6 H7^8 I"9^: B2;^< DQ=^> 9!?^@ <QA^B =aC^D B1E^F EaG^H ?I^J J1K^N CAO^P 8Q^R ;AS^T <QU^V =aW^X ?Y^Z DQ[^\ Ea]^^ DQ_^` A!a^b :1c^d <Re^f <Qg^h 4Qi^j :1k^l Mbm^n OPRo^p PQSq^r Ebs^t Mdu^v @w^x A"y^~ ,Q^@ +AA^B 5aC^F +AG^H ,QI^J 1!K^L 3AM^P 7Q^R 8S^T =aU^V A!W^X ?Y^Z A![^^ 4Q_^` 4Qa^b 5ac^d /e^f .rg^h *1i^j 5ak^l >qm^n /o^p /q^r 0s^v <Sw^x A#y^z B3{^| 9!}^~ 3A^@ 5aA^B =bC^D HE^F GG^H EbI^J FrK^L B2M^N J2O^P >qQ^R 8S^T CBU^V A!W^X 9"Y^Z DR[^\ 3B]^^ 9"_^` @a^b 6qc^f 4Qg^h ,Qi^j .qk^l 21m^n 4Qo^p 0q^r -as^v 5aw^z ;A{^~ Ea^@ 5aA^B ?C^D =aE^F <QG^H CAI^L LQM^N 8O^P ;AQ^R 8S^T ?U^V <QW^Z 4Q[^\ <Q]^^ 1!_^` 5aa^b 21c^f *1g^h 3Ai^j -ak^n 3Ao^p 21q^r 1!s^t J2u^x *+,-{^~H/H 7H 8	H
 ?H 3CH 1#H <RH =bH CCH ;CH ;BH HH McH  G!H" <R#H$ 9"%H& 5b'H( 5b)H* 9"+H, 9"-H0 G1H2 G3H4 Fr5H6 I"7H8 PQS9H: J2;H< Mc=H> ;A?H@ ;AAHB ?CHD <QEHF KAGHH GIHJ CAKHL HMHN DQOHP DQQHR FqSHT DQUHX :2YHZ ;B[H\ :2]H^ @_H` A"aHb @cHd >reHf CCgHh GiHj EckHl CCmHn McoHp CCqHt EbuHv ?wHx ?yHz <R{H@ *3AHB )!CHD *3EHF .rGHH 0IHJ /KHL 0MHN ;AOHR 3ASHT 6qUHV 4QWHX 21YHZ 5a[H\ 3A]H^ :1_H` 1!aHb 5acHd :1eHh 4QiHj 5akHl 5amHn 6qoHp 0qHr /sHv 8wHx <QyHz ;B{H| Ec}H~ ?H@ >qAHB 3BCHD 3BEHH 4RIHJ 1"KHL 4RMHN -bOHP 1"QHR -bSHT 1"UHX 7YHZ 5c[H^ ;A_H` <QaHb :3cHd ;CeHf <SgHj 23015678/0-.45<=BC7801<=?@/0OHAiMpQn@
r (sn@
x }j}Z} Z} Z	}
 \} \} \} 0} Z} Z} Z} M} J} Z} \}  0!}" 0#}$ -%}& .'}( 0)}* -+}, 0-}. -/}0 Z1}2 ]3}4 Z5}6 .7}8 -9}: -;}< -=}> -?}@ -A}B \C}D ZE}F ZG}H .I}J mK}L lM}N /O}P lQ}R /S}T /U}V lW}X lY}Z l[}\ l]}^ /_}` ja}b /c}d je}f lg}h li}j jk}l lm}n lo}p lq}r ls}t lu}v jw}x hy}z 2{}| h}}~ j}@ jA}B lC}D lE}F lG}H lI}J lK}L lM}N lO}P lQ}R lS}T lU}V lW}X lY}Z l[}\ j]}^ /_}` /a}b jc}d je}f jg}h ji}j jk}l /m}n /o}p /q}r ls}t lu}v lw}x ly}z l{}| l}}~ j}@ jA}B jC}D mE}F lG}H .I}J mK}L .M}N .O}P .Q}R lS}T mU}V lW}X mY}Z l[}\ l]}^ l_}` la}b /c}d le}f /g}h mi}j mk}l mm}n jo}p jq}r js}t ju}v mw}x jy}z m{}| j}}~ j}@ jA}B /C}D jE}F jG}H jI}J mK}L mM}N lO}P lQ}R jS}T mU}V 1W}X /Y}Z j[}\ j]}^ j_}` ma}b mc}d me}f mg}h ji}j jk}l jm}n mo}p mq}r ms}t mu}v lw}x /y}z l{}| /}}~ /}@ lA}B lC}D lE}F lG}H /I}J jK}L /M}N lO}P lQ}R lS}T jU}V lW}X lY}Z l[}\ l]}^ l_}` ja}b jc}d je}f jg}h li}j jk}l lm}n jo}p lq}r ls}t lu}v lw}x jy}z l{}| j}}~ j}@ lA}B lC}D lE}F jG}H /I}J /K}L jM}N jO}P jQ}R jS}T lU}V /W}X /Y}Z /[}\ l]}^ l_}` la}b lc}d le}f lg}h ji}j jk}l jm}n mo}p lq}r .s}t mu}v .w}x .y}z .{}| l}}~ m}@ lA}B nC}D lE}F lG}H lI}J mK}L mM}N /O}P /Q}R jS}T jU}V jW}X jY}Z l[}\ l]}^ l_}` la}b lc}d je}f /g}h li}j lk}l lm}n lo}p lq}r ls}t lu}v lw}x ly}z l{}| l}}~ l}@ lA}B lC}D lE}F lG}H mI}J mK}L lM}N lO}P lQ}R lS}T lU}V lW}X lY}Z l[}\ l]}^ l_}` la}b lc}d le}f lg}h .i}j lk}l lm}n lo}p lq}r ls}t mu}v lw}x ly}z j{}| /}}~ /}@	 .A	}B	 /C	}D	 mE	}F	 lG	}H	 lI	}J	 mK	}L	 5M	}N	 lO	}P	 lQ	}R	 lS	}T	 /U	}V	 lW	}X	 lY	}Z	 /[	}\	 l]	}^	 l_	}`	 la	}b	 .c	}d	 le	}f	 lg	}h	 li	}j	 lk	}l	 lm	}n	 lo	}p	 mq	}r	 js	}t	 ju	}v	 jw	}x	 jy	}z	 j{	}|	 j}	}~	 j	}@
 jA
}B
 jC
}D
 jE
}F
 jG
}H
 jI
}J
 jK
}L
 /M
}N
 jO
}P
 jQ
}R
 jS
}T
 jU
}V
 jW
}X
 jY
}Z
 j[
}\
 j]
}^
 j_
}`
 ja
}b
 jc
}d
 je
}f
 jg
}h
 ji
}j
 jk
}l
 jm
}n
 jo
}p
 .q
}r
 .s
}t
 .u
}v
 jw
}x
 jy
}z
 j{
}|
 j}
}~
 j
}@ lA}B lC}D lE}F lG}H jI}J ]K}L \M}N \O}P \Q}R \S}T \U}V \W}X \Y}Z \[}\ \]}^ \_}` \a}b \c}d \e}f \g}h \i}j \k}l \m}n \o}p \q}r Zs}t Zu}v Zw}x Zy}z Z{}| Z}}~ Z}@ \A}B \C}D \E}F \G}H \I}J ]K}L .M}N -O}P -Q}R -S}T \U}V \W}X ]Y}Z \[}\ \]}^ \_}` \a}b \c}d \e}f \g}h \i}j \k}l \m}n \o}p \q}r \s}t \u}v .w}x \y}z .{}| ]}}~ .}@ ]A}B \C}D ]E}F .G}H \I}J \K}L \M}N .O}P ]Q}R ]S}T ]U}V ]W}X ]Y}Z ][}\ .]}^ ]_}` \a}b \c}d ]e}h 0i}j ]k}l Zm}n Zo}p mq}r }s}t zu}v zw}x 0y}~ .7'5)6':0/2E	INyn@
V YWn@
X  H+UH#UH  GH &t	H
 'H &tH 4UH -eH vH !(H  H H hH !!H *5H  !%!H" %e#H$ #"$(&&".(%" *# #$ *&".("!LULUL UL 5	L
 5L 5L FL 7L $L fL WL WL FL 5L EL  5!L" 5#L$ 5%L& F'L( 5)L* F+L, 5-L. 5/L0 F1L2 F3L4 55L6 G7L8 F9L: 5;L< F=L> F?L@ 5ALB 5CLD 5ELF 5GLH FILJ 5KLL 5MLN 5OLT WULV FWLX FYLZ F[L\ 5]L^ U_L` VaLb FcLd 5eLf gLh FiLj FkLl 5mLn $oLp FqLr 5sLt WuLv 5wLx WyLz 6{L| 5}L~ 5L@ 5ALB 5CLD 5ELF 5GLH 5ILJ 5KLL hML\ #""" ! #*G$ !""AHYn@
n#  $&+(,$($(%)-
 -1)-+/ )-(,)-1
 &*7 $(#'"&#(	( #'/3$(#($)27+/? $D r% ',!$$+%&*/& ',#'$)*.	# ',!##'$)*/( $(&+!#$+,-%&#'$)*/	*  # r#QKZ  ),0,104%)7 37$ "9 "9 	 "9 "9 	CiX  %!%"&$# "'"' "!	&n@
 n n	    enablec                 z   | j                   rt        | j                  dz         |r9| j                  d   | j                  d<   | j                  d   | j                  d<   nMd| j                  v r?| j                  d   | j                  d<   | j	                  | j                  d      }|| _        || j
                  d<   y)z
        enables or disables demo trading mode
        https://bybit-exchange.github.io/docs/v5/demo
        :param boolean [enable]: True if demo trading should be enabled, False otherwise
        z5 demo trading does not support in sandbox environmentr   apiBackupDemoTradingr   r  N)isSandboxModeEnabledr;   rE   r   omitr  )r[  r_  newUrlss      r]  enable_demo_tradingzbybit.enable_demo_trading  s     $$tww)``aa04		%0@DII,-#yy7DIIe#tyy0#yy)?@DIIeii		+ABGDI,2()r^  c                 B    | j                         | j                  d   z
  S )Nr  )millisecondsr  )r[  s    r]  noncezbybit.nonce%  s       "T\\2B%CCCr^  c                     | j                  |di       }| j                  |g dg       }| j                  |dd      }t        |      }||dkD  r|d   }||d<   ||d<   |S )Nresult)listrowsdatadataListnextPageCursorcursorr   )	safe_dictsafe_list_nsafe_string_2len)r[  responserj  rm  paginationCursor
dataLengthfirsts          r]  add_pagination_cursor_to_resultz%bybit.add_pagination_cursor_to_result(  sv    (B7(LbQ--f6FQY
(zA~GE&6E"#DGr^  c                    | j                  | j                  d      }| j                  | j                  d      }||| j                  d   rKd| j                  d<   d| j                  d<   d| j                  d<   | j                  d   | j                  d   gS | j                  |      | j                  |      g}|}|d   }|d	   }| j	                  |d
i       }| j	                  |d
i       }	| j                  |d      d	k(  | j                  d<   | j                  |d      d	k(  | j                  d<   | j                  |	dd      | j                  d<   | j                  d   | j                  d   gS )a  

        https://bybit-exchange.github.io/docs/v5/user/apikey-info#http-request
        https://bybit-exchange.github.io/docs/v5/account/account-info

        returns [enableUnifiedMargin, enableUnifiedAccount] so the user can check if unified account is enabled
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns any: [enableUnifiedMargin, enableUnifiedAccount]
        r  r  r  FT   r  r   r   rj  r  uta)	safe_boolr  privateGetV5UserQueryApiprivateGetV5AccountInforq  safe_integer)
r[  paramsr  r  rawPromisespromisesru  accountInforj  accountResults
             r]  is_unified_enabledzbybit.is_unified_enabled3  sy    #nnT\\;PQ#~~dll<RS&*>*F||/0 7<237;346723%:;T\\J`=abb88@$B^B^_eBfgK"H{H"1+Kp ^^Hh;F NN;"EM262C2CFI2VZ[2[DLL./373D3DVU3SWX3XDLL/0262C2CMShjk2lDLL./23T\\BX5YZZr^  c                 $    | j                  |      S )a$  
        upgrades the account to unified trade account *warning* self is irreversible

        https://bybit-exchange.github.io/docs/v5/account/upgrade-unified-account

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns any: nothing
        ) privatePostV5AccountUpgradeToUta)r[  r  s     r]  upgrade_unified_trade_accountz#bybit.upgrade_unified_trade_account  s     44V<<r^  symbolc                    d }d }|j                  d      }|j                  d      }d }d }|j                  d      dkD  r^| j                  |d      }| j                  |d      }| j                  |d      }|j                  d      }	| j                  |	d      }
|
}|
}nM| j                  |d      }| j                  | j                  |d            }|j	                  d      rd}d}nd	}d	}| j                  |d
      }| j                  |d      }| j                  |      }| j                  |      }d }d }|dk(  r#| j                  d      }| j                  d      }nO|dk(  r#| j                  d      }| j                  d      }n'|dk(  r"| j                  d      }| j                  d      }i d|dz   | j                  |      z   dz   |z   dz   |z   d|dz   |z   dz   |z   dz   |z   dz   |z   dz   |z   d|d|d|d|d|d|dddddd d d d!dd"dd#ddd$d%dd$| j                  d      |||d&k(  rd'nd(| j                  |      ||d)d d d*d d d*d d d*d+d d,	S )-N-/r   r   :z-USDTr  USDC      r  z0.01r   r  z0.1r  r   rE   r  basequotesettlebaseIdquoteIdsettleIdactiveFtyperX   r  r  rT   rV   rW   TrU   Ccallputamountr1  minrD  )r  r1  cost)	r  contractSizeexpiryexpiryDatetime
optionTypestrike	precisionlimitsinfo)	splitfindsafe_stringconvert_market_id_expire_dateendswithconvert_expire_date	parse8601parse_number%convert_expire_date_to_market_id_date)r[  r  r  r  optionParts
symbolBaser  r  symbolQuoteAndSettle
splitQuotequoteAndSettler  r  datetime	timestampamountPrecisionpricePrecisions                    r]  create_expired_option_marketz"bybit.create_expired_option_market  s]   ll3'\\#&
;;sb ##J2D%%k15F#'#3#3J#B -33C8J!--j!<N"E#F##K3D778H8HVW8XYFw'!!+q1%%k15
++F3NN8,	5="//7O!..s3NU]"//6O!..u5NU]"//4O!..v6N+
$*tII&QQTWWZ``cffiss+
dSj5(3.7#=FLvUX[[^hh+
 D+
 U	+

 f+
 d+
 u+
 +
 e+
 H+
 d+
 t+
 E+
 E+
 e+
  d!+
" e#+
$  --c2&%/3%6&U''/)'  
  
   U+
 +	
r^  NmarketIdmarket	delimiter
marketTypec                     |d uxr* |j                  d      dkD  xs |j                  d      dkD  }|r|| j                  vr| j                  |      S t        t        |   ||||      S )Nz-Cr  z-P)r  markets_by_idr  rY  rB   safe_market)r[  r  r  r  r  isOptionr\  s         r]  r  zbybit.safe_market  sn    D(hd0Cb0H/ghmm\`NadfNfX););;44X>>UD-h	:VVr^  c                     d }| j                  |||      \  }}d }| j                  |||      \  }}|dk(  s|dk(  r||gS ||gS )NrX   rT   )handle_market_type_and_paramshandle_sub_type_and_params)r[  methodr  r  r  subTypes         r]  get_bybit_typezbybit.get_bybit_type  s_    99&&&Qf99&&&Q8tv~&>!  r^  r  c                     | j                  |      }|d   d   d u }| j                  |      }|s|dk7  r| j                  ||      S |S )Nr  r  0)r  number_to_stringamount_to_precision)r[  r  r  r  emptyPrecisionAmountamountStrings         r]  
get_amountzbybit.get_amount  sZ     V$ &{ 3H = E,,V4#)<++FF;;r^  r1  c                 l    ||S | j                  |      }|d   d   d u }|s| j                  ||      S |S Nr  r1  )r  price_to_precision)r[  r  r1  r  emptyPrecisionPrices        r]  	get_pricezbybit.get_price  sJ    =LV$%k27;tC"**6599r^  r  c                 d    | j                  |      }|d   d   d u }|s| j                  ||      S |S r  )r  cost_to_precision)r[  r  r  r  r  s        r]  get_costzbybit.get_cost  s@    V$%k27;tC"))&$77r^  c                 H    | j                  |      }| j                  |d      S )aQ  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://bybit-exchange.github.io/docs/v5/market/time

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        time)publicGetV5MarketTimer  )r[  r  ru  s      r]  
fetch_timezbybit.fetch_time  s)     --f5   622r^  c                    | j                  d      sy| j                  d   ry| j                  |      }| j                  |di       }| j	                  |dg       }i }t        dt        |            D ]^  }||   }| j                  |d      }| j                  |      }	| j                  |d      }
| j	                  |d	g       }i }t        dt        |            D ]  }||   }| j                  |d
      }| j                  |      }|||d| j                  |d      dk(  | j                  |d      dk(  | j                  |d      | j                  | j                  | j                  |d                  | j                  |d      dd| j                  |d      dddd	||<    | j                  ||	||
ddddddddddddddd|dd      ||	<   a |S )a  
        fetches all available currencies on an exchange

        https://bybit-exchange.github.io/docs/v5/asset/coin-info

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        FNr  rj  rl  r   coinrF   chainschainchainDepositr   chainWithdrawwithdrawFeeminAccuracywithdrawMinr  
depositMin)r   rU  )	r  rE   networkr  rU  r   feer  r  r  r   rU  crypto)r  r  rE   rF   r  rU  r   r  r  r  r(  r  )check_required_credentialsr  privateGetV5AssetCoinQueryInforq  	safe_listrangert  r  safe_currency_codenetwork_id_to_coder  safe_numberr  parse_precisionsafe_currency_structure)r[  r  ru  rm  rl  rj  icurrency
currencyIdr  rF   r  r(  jr  	networkIdnetworkCodes                    r]  fetch_currencieszbybit.fetch_currencies/  s8    ..u5<<+,66v>> ~~h"5~~dFB/q#d)$ 9	AAwH))(F;J**:6D##Hf5D^^Hh;FH1c&k* q	 ,,UG<	"55i@!#*"#00G1L $ 1 1% IQ N++E=A!%!2!243G3GHXHXY^`mHn3o!p $(#3#3E=#I#'%
 $(#3#3E<#H#'$	)%	0  77   !  $#
  $#!
  $#  % 39 F4L?9	t r^  c                 \   | j                   d   r| j                          g }| j                  | j                   dg d      }t        dt	        |            D ]  }||   }|dk(  r!|j                  | j                  |             /|dk(  r#|j                  | j                  ddi             W|dk(  r#|j                  | j                  ddi             |d	k(  rg|j                  | j                  d
di             |j                  | j                  d
di             |j                  | j                  d
di             t        | j                  dz   |z   dz          |}| j                  |dg       }| j                  |dg       }| j                  |dg       }	| j                  |dg       }
| j                  |dg       }| j                  |dg       }| j                  ||	      }| j                  |
|      }| j                  ||      }| j                  ||      }| j                  ||      S )a  
        retrieves data on all markets for bybit

        https://bybit-exchange.github.io/docs/v5/market/instrument

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r  r   )rT   r  r  r   rT   r  categoryr  rX   baseCoinr  r  r  z+ fetchMarkets() self.options fetchMarkets "z " is not a supported market typer   r  r     r   )r  load_time_differencer  r  rt  appendfetch_spot_marketsfetch_future_marketsfetch_option_marketsr.   rE   array_concat)r[  r  promisesUnresolvedr   r  r  r  spotMarketslinearMarketsinverseMarketsbtcOptionMarketsethOptionMarketssolOptionMarketsfutureMarketsoptionMarketsderivativeMarketss                   r]  fetch_marketszbybit.fetch_markets  s8    <<12%%'~~dllNDabq#l+, 	OA%aJV#"))$*A*A&*IJx'"))$*C*CZQYDZ*[\y("))$*C*CZQZD[*\]x'"))$*C*CZQVDW*XY"))$*C*CZQVDW*XY"))$*C*CZQVDW*XY#DGG.[$[^h$h  lN  %N  O  O	O &nnXq"5xB7!R8>>(Ar:>>(Ar:>>(Ar:))-H))*:<LM))-9IJ --m]K  .?@@r^  c                    ddi}| j                  | j                  dd      }d }|r"| j                  | j                  ||            }n!| j	                  | j                  ||            }| j                  |di       }| j                  |dg       }g }| j                  d      }| j                  d      }	t        dt        |            D ]  }
||
   }| j                  |d	      }| j                  |d
      }| j                  |d      }| j                  |      }| j                  |      }|dz   |z   }| j                  |d      }|dk(  }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |dd      }|dk7  }|j                  | 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 d d d d | j                  |d$      | j                  |d%|      d&| j                  d'      d d(| j                  |d)      | j                  |d*      d(d d d(| j                  |d+      | j                  |d,      d(d-d |d.              |S )/Nr  rT   r  Frj  rk  z0.001r   r  r  	quoteCoinr  statusTradinglotSizeFilterpriceFilterquotePrecisionmarginTradingnonerE   r  r  r  r  r  r  r  TrU   rV   rW   rX   r  r  r  basePrecisiontickSizer  r   r  minOrderQtymaxOrderQtyminOrderAmtmaxOrderAmtrA  r  r1  r  r  rS  rT  r  r  r  r  r  r  r  createdr  )r}  r  !privateGetV5MarketInstrumentsInfoextend publicGetV5MarketInstrumentsInforq  r  r  r  rt  r  r  r  r  safe_market_structure)r[  r  requestr  ru  responseResultmarketsrj  takerFeemakerFeer  r  rE   r  r  r  r  r  r  r  r  r  r  r  allowsMargins                            r]  r  zbybit.fetch_spot_markets  s`   
 %)NN4<<A\^c$d!$==dkk'SY>Z[H<<T[[RX=YZHB (B?..<$$W-$$W-q#g,' A	AQZF!!&(3B%%fj9F&&v{;G**62D++G4ECZ%'F%%fh7F	)F NN6?CM..?K!--m=MNN ,,V_fMM(F2LMM$44 26b26&26 26 	26
 $26 &26 726 D26 26 26 ,26 26 %26 %26 &26  E!26" $#26$  !! $"&""..}oN!--k:~V  $005#!
  $//}M#//}M
  $#
  $//}M#//}M$  c26 2 2A	D r^  c                 	   | j                  |      }d|d<   g }| j                  | j                  dd      }d }|r| j                  |      }n\| j	                  |      | j	                  | j                  |ddi            g}|}| j                  |di       }| j                  |di       }| j                  |d	i       }| j                  |d
g       }| j                  |d      }	|	|	|	|d<   d }
|r| j                  |      }
n| j	                  |      }
| j                  |
d	i       }| j                  |d
g       }t        |      }|dk(  rn'| j                  ||      }| j                  |d      }	|	| j                  |d	i       }| j                  |d
g       }| j                  ||      }g }| j                  |d      }t        dt        |            D ]  }||   }|| j                  |d      }|dk(  }|dk(  }| j                  |d      }|dk(  }|dk(  }|dk(  }|dk(  }| j                  |d      }| j                  |d      }| j                  |d      }|r|n|}| j                  |d|      }| j                  |      } | j                  |      }!d }"|r|dk(  rd}"n| j                  |      }"| dz   |!z   }#| j                  |di       }$| j                  |di       }%| j                  |di       }&| j                  |d      }'|xs |}(|xs |})d }*|(rd}*n|)rd }*d }+|(s.| j                  | j                  |d!            }+|+t        |+      }+| j                  |+      },|#d"z   |"z   }#|+|#d#z   | j                  |+      z   }#|r| j!                  |$d$d%      n| j#                  d&      }-|j%                  | j'                  i d'|d|#d(| d)|!d*|"d+|d,|d-|d.|*d/dd0d d|(d |)d1dd2|'d3k(  d4d5d||| j)                  |d6| j#                  d7            | j)                  |d8| j#                  d9            |-|+|,d d | j)                  |$d:      | j)                  |%d;      d<| j)                  |&d=      | j)                  |&d>      d?| j!                  |$d$d%      | j!                  |$d@dA      d?| j)                  |%dB      | j)                  |%dC      d?d d d?dD| j+                  |dE      |dF              |S )GNrM  rG  r  Fr  	PreLaunchr   r   rj  rk  ro  rp  r  r  r  contractTypeInverseFuturesLinearFuturesLinearPerpetualInversePerpetualr  r  r  
settleCoinUSDr  r  r  r  leverageFilterrV   rW   deliveryTimer  r  minTradingQtyr  r   rE   r  r  r  r  r  r  r  rT   rU   rX   r  r  r  Tr+  0.0006r,  0.0001qtyStepr  r  minLeveragemaxLeverager  maxTradingQtyr  minPricemaxPricer!  
launchTimer"  )r%  r}  r  r$  r&  rq  r  r  rt  r  r  r  	omit_zerointiso8601yymmddsafe_number_2r  r  r'  r  r  ).r[  r  preLaunchMarketsr  ru  linearPromisesr  rm  r*  rv  responseInnerdataNew
rawMarketsrawMarketsLengthpreLaunchDatapreLaunchMarketsListrj  r  r  r  r  r  r0  inverseFutureslinearFutureslinearPerpetualinversePerpetualrE   r  r  defaultSettledIdr  r  r  r  r  r  r  rA  r  rV   rW   r  r  r  r  s.                                                 r]  r  zbybit.fetch_future_markets5  s4   V$w$(NN4<<A\^c$d!$==fEH 55f=55dkk&8U`Ja6bcN &H~~h26H#~~h2>~~h"5..vr2++D2BC'".#3x &*,$($J$J6$RM$($I$I&$QM.."E!^^GVR@
#&z? #q(++J@#'#3#3G=M#N  #.t '72F#~~mVRH##G-AB##D*5q#g,' `	AQZF++FJ?(*F9,G++FNCL*.>>N)_<M+/@@O ,0B B!!&(3B%%fj9F&&v{;G*0wf''>NOH**62D++G4EFH$500:CZ%'F NN6?BGM..CK~~f.>CH%%fh7F"6&6D#4}FDF(8(8(PQ% [F!\\&1Nc\F*F!#F(;;`g4--m_m\mqm~m~  @C  nDLMM$44 26b26&26 26 	26
 &26 &26 726 H26 26 26 $26 26 &26 %26 6Y.26  D!26" &#26$ #))&*d>O>OPX>YZ))&*d>O>OPX>YZ , "0""..}iH!--k:F  $//-H#//-H!
  $11-R_`#11-R_`
  $//ZH#//ZH
  $#$  ,,V\Bc26 2 2]`	B r^  c                    ddi}| j                  | j                  dd      }d }|r"| j                  | j                  ||            }n!| j	                  | j                  ||            }| j                  |di       }| j                  |dg       }| j                  d   rd|d	<   | j                  |d
      }||||d<   d }|r"| j                  | j                  ||            }n!| j	                  | j                  ||            }| j                  |di       }	| j                  |	dg       }
t        |
      }|dk(  rn'| j                  |
|      }| j                  |	d
      }|g }t        dt        |            D ]  }||   }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }| j                  |      }| j                  |di       }| j                  |di       }| j                  |d      }| j                  |d      }|j                  d      }| j                  |d      }| j                  |d      }|dk(  }||k(  }|s | j                  d   s| j                  d   s/|j                  | j                  i d|d|dz   |z   dz   |z   dz   | j!                  |      z   dz   |z   dz   |z   d|d|d|d |d!|d"|d#dd$d d%dd&dd'dd(ddd)d*|d+d)| || j#                  |d,| j%                  d-            | j#                  |d.| j%                  d/            | j%                  d0      || j'                  |      | j%                  |      | j)                  |d1      | j#                  |d2      | j#                  |d3      d4d d d5| j#                  |d6      | j#                  |d7      d5| j#                  |d8      | j#                  |d9      d5d d d5d:| j                  |d;      |d<              |S )=Nr  rX   r  Frj  rk  r  rM  rG  ro  rp  r   r  r  r  r5  r  r  r  r8  r  r  r  r  r  rE   r  r  r  r  r  r  r  r  r  r  rT   rU   rV   rW   Tr  r  r+  r:  r,  r;  r   optionsTyper<  r  r  r  r  r  r@  rA  r!  rB  )r  r  rS  rT  r  r  r  r  r  r  r  r#  r  )r}  r  r$  r%  r&  rq  r  r  rt  r  r  r  r  r  r  r'  rF  r  r  rE  safe_string_lower)r[  r  r(  r  ru  rm  r*  rv  rJ  rK  rL  rM  rj  r  r  rE   r  r  r  r  r  r  r  r  r  r  splitIdr  optionLetterisActive	isInverses                                  r]  r  zbybit.fetch_option_markets  s   
 %)NN4<<A\^c$d!$==dkk'SY>Z[H<<T[[RX=YZH~~h"5..vr2<<()#GG#//6FG+&2(8GH%*.M0(,(N(Nt{{[bdjOk(l(,(M(MdkkZaciNj(k"nn]HbIG!%!DJ'*:$'1,"//
GDG'+'7'7AQ'R$ '2b q#g,' F	AQZF!!&(3B%%fj9F&&v{;G''=H**62D++G4E,,X6F NN6?BGM..CK%%fh7F&&v~>FhhsmG%%gq1F++GQ7L)+HIDLL)9:Ma@bd88 3:"3:dSj5036?#ETZH[[^aadjjmpps3: D3: U	3:
 f3: f3: w3: 3: H3: t3: E3: e3: E3: e3: d3:  h!3:" #3:$ #,m(!--fj$BSBST\B]^!--fj$BSBST\B]^$($5$5c$:$&*ll6&:"//7"&"8"8"O"&"2"2=)"L!%!1!1+z!J" $(#'%
 $(#3#3M=#Q#'#3#3M=#Q#
 $(#3#3K#L#'#3#3K#L"
 $(#'!$  $00F"e3: 3 3'F	N r^  tickerc           
      z   | j                  |d      d u }| j                  |d      }| j                  |d      }|rdnd}| j                  ||d |      }| j                  ||d |      }| j                  |d      }| j                  |d      }	| j                  |d      }
t	        j
                  |
d	      }
| j                  |d
      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  i d|d|d| j                  |      d|d|d|d| j                  |dd      d|d| j                  |dd      dd d|	d|d|d d d!d d"|
d#d ||| j                  |d$      | j                  |d%      |d&|      S )'NopenInterestValuer  r  rT   r  	lastPriceprevPrice24hprice24hPcnt100turnover24h	volume24h	bid1Price	ask1PricehighPrice24hlowPrice24hr  r  highlowbid	bidVolumebidSizebid1Sizeask	askVolumeaskSizeask1Sizevwapopencloser-  previousClosechangerR  average	markPrice
indexPrice)
baseVolumequoteVolumery  rz  r  )	r  r  r  safe_symbolr@   
string_mulsafe_tickerrE  rs  )r[  r\  r  isSpotr  r  r  r  r-  rt  rR  r|  r{  rk  ro  ri  rj  s                    r]  parse_tickerzbybit.parse_tickerv  sf   \ !!&*=>$F%%ff5	##FH5vZ!!(FD$?!!(FD$?47%%fn=
''
E:
&&v}=%%fk:
v{3v{37v}5 !
f!
!
 Y/!
 D	!

 3!
 3!
 ++FIzJ!
 3!
 ++FIzJ!
 D!
 D!
 T!
 D!
 T!
 d!
  *!!
" t#!
$ %&))&+>**6<@-!
. / 	r^  c                    |t        | j                  dz         | j                          | j                  |      }d|d   i}|d   rd|d<   n |d   rd|d<   n|d   rd|d<   n
|d   rd|d<   | j	                  | j                  ||            }| j                  |d	i       }| j                  |d
g       }| j                  |d      }| j                  ||      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://bybit-exchange.github.io/docs/v5/market/tickers

        :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>`
        z) fetchTicker() requires a symbol argumentr  rE   rT   r  rX   r  r  rj  rk  r   )	r2   rE   load_marketsr  publicGetV5MarketTickersr%  rq  r  r  )	r[  r  r  r  r(  ru  rj  tickers	rawTickers	            r]  fetch_tickerzbybit.fetch_ticker  s     >#DGG.Y$YZZV$fTl

 &>"(GJh&.
#!&.
#	"&/
#00Wf1MNN (B7..4NN7A.	  F33r^  symbolsc                    | j                          | j                  |g d      }d}d}|g }| j                  dd|      }|d   }d}t        dt	        |            D ]  }	||	   }
|
j                  d      dk(  }|r| j                  |
dd|      }n| j                  |
      }||d   }n |d   |k7  rt        | j                  dz         |d	   r=| ||d
   k7  rt        | j                  dz         ||d
   }| j                  |ddg      }|j                  |d           i }d}| j                  d||      \  }}| j                  |d      }d}| j                  d||d      \  }}|dk(  r|d|d<   n%|d	k(  rd	|d<   |d}||d<   n|dk(  s|dk(  s|||d<   | j                  | j                  ||            }| j!                  |di       }| j#                  |dg       }| j%                  ||      S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://bybit-exchange.github.io/docs/v5/market/tickers

        :param str[] 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.baseCoin]: *option only* base coin, default is 'BTC'
        :returns dict: an array of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        )r  r  r  Nr   r   r  r  r  z@ fetchTickers can only accept a list of symbols of the same typerX   r  z fetchTickers the base currency must be the same for all symbols, self endpoint only supports one base currency at a time. Read more about it here: https://bybit-exchange.github.io/docs/v5/market/tickersr  r  r  r  r  rT   r  r  r  rV   rW   rj  rk  )r  safe_string_nr  r  rt  r  r  r  r3   rE   rc  r  r  r  r  r%  rq  r  parse_tickers)r[  r  r  r  r  parsedSymbolsmarketTypeInfor  currentTyper  r  isExchangeSpecificSymbolr(  r  passedSubTyper  ru  rj  
tickerLists                      r]  fetch_tickerszbybit.fetch_tickers5	  sg    	!!&*JKM!??PTV\]N(+KK1c'l+ 7  -3KK,<,B(+!--fdD+NF![[0F&"(.KF^{2$TWW/q%qrr(#'DF6N,B(  4A  *A  B  B|%f~!YYv
/CDF$$VH%56'7(

 99.&RXYf ((;99.&RXZbc6>m3"(GJX"*GJ|"&GJV^tx/73F")GJ00Wf1MNN (B7^^FFB7
!!*m<<r^  c                 &    | j                  ||      S )at  
        fetches the bid and ask price and volume for multiple markets

        https://bybit-exchange.github.io/docs/v5/market/tickers

        :param str[]|None symbols: unified symbols of the markets to fetch the bids and asks for, all markets 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.baseCoin]: *option only* base coin, default is 'BTC'
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        )r  )r[  r  r  s      r]  fetch_bids_askszbybit.fetch_bids_asks	  s     !!'622r^  c           	          |d   rdnd}| j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  ||      gS )	Nr  r{  r   r   r   r  r  r   )r  r  )r[  ohlcvr  volumeIndexs       r]  parse_ohlcvzbybit.parse_ohlcv	  s|     #9-aAeQ'UA&UA&UA&UA&UK0
 	
r^  r   sincerG  c           	         |t        | j                  dz         | j                          d}| j                  |dd      \  }}|r| j	                  d|||||d      S | j                  |      }d|d   i}|d	}|||d
<   |||d<   | j                  d||      \  }}| j                  | j                  ||      |d<   d}	|d   r'd|d<   | j                  | j                  ||            }	n| j                  |d      }
| j                  |d      }|d   rd|d<   n#|d   rd|d<   nt        | j                  dz         |
dk(  r"| j                  | j                  ||            }	no|
dk(  r"| j                  | j                  ||            }	nH|
dk(  r"| j                  | j                  ||            }	n!| j                  | j                  ||            }	| j!                  |	di       }| j#                  |dg       }| j%                  |||||      S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://bybit-exchange.github.io/docs/v5/market/kline
        https://bybit-exchange.github.io/docs/v5/market/mark-kline
        https://bybit-exchange.github.io/docs/v5/market/index-kline
        https://bybit-exchange.github.io/docs/v5/market/preimum-index-kline

        :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]: the latest time in ms to fetch orders for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nz( fetchOHLCV() requires a symbol argumentFr   paginaterM  r  rE      startrG  endintervalrT   r  r1  r  r  z1 fetchOHLCV() is not supported for option marketsr.  r/  premiumIndexrj  rk  )r2   rE   r  handle_option_and_params"fetch_paginated_call_deterministicr  handle_until_optionr  r   publicGetV5MarketKliner%  rc  r;   publicGetV5MarketMarkPriceKline publicGetV5MarketIndexPriceKline'publicGetV5MarketPremiumIndexPriceKlinerq  r  parse_ohlcvs)r[  r  	timeframer  rG  r  r  r  r(  ru  r1  rj  ohlcvss                r]  fetch_ohlcvzbybit.fetch_ohlcv	  s?   $ >#DGG.X$XYY88zZ&::<QVX]_hjprvwwV$fTl
 =E$GG$GG225'6J"..t	9U
&>"(GJ224;;w3OPH$$VW5EYYvw/Fh&.
#	"&/
#"477-`#`aa??GU[@\]'!@@WV\A]^.(GGT[]cHde66t{{7F7STT (B73  E5IIr^  c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  ||d d      }| j	                  |d      }| j                  |d      }| j	                  |d      }| j	                  |d      }	| j                  | j                  ||d d      d      }
| j                  |
d	      }d }|"| j                  |d
z        }t        |      dz   }i d|d|d|d|	dd dd d|d| j                  |      d|d|d| j                  |      dd dd dd dd dd dd d|iS )Nr  r  rV   fundingRatenextFundingTimery  rz  r  fundingInterval<   hinterestRateestimatedSettlePricer  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer  )
r  rc  r  r}  r  rq  r  parse_to_intstrrE  )r[  r\  r  r  r  r  r  r  ry  rz  r  r  intervalStringr  s                 r]  parse_funding_ratezbybit.parse_funding_rate,
  s   4 %%fk:	6;/##FH5!!(FD&A&&v}=,,V5FG$$V[9	%%fl;
~~d..xvNPVW++D2CD&((2)=>H ]S0N
F
f
 
 *	

 D
 #D
 
 Y/
 ;
  0
 t||,<=
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 	
r^  c                 t   | j                          d}i }|=| j                  |      }| j                  |d         }t        |      }|dk(  r|d   |d<   d}| j	                  d||      \  }}|dk7  rt        | j                  dz   |z   d	z         d}| j                  d||d
      \  }}||d<   | j                  | j                  ||            }| j                  |di       }	| j                  |	dg       }
| j                  |d      }t        dt        |
            D ]
  }||
|   d<    | j                  |
|      S )a  
        fetches funding rates for multiple markets

        https://bybit-exchange.github.io/docs/v5/market/tickers

        :param str[] symbols: unified symbols of the markets to fetch the funding rates for, all market funding rates are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        Nr   r   rE   r  r   rV   z& fetchFundingRates() does not support z marketsr  r  rj  rk  r  r  )r  market_symbolsr  rt  r  r;   rE   r  r  r%  rq  r  r  r  parse_funding_rates)r[  r  r  r  r(  symbolsLengthr  r  ru  rm  r  r  r  s                r]  fetch_funding_rateszbybit.fetch_funding_ratesi
  sd    	))'2G[[,FLM!$*4L!99:MvW]^f6>tww)QQTXX[eeffG"==>QSY[acklOGV")GJ00Wf1MNJ ~~h"5^^D&"5
%%h7	q#j/* 	3A)2JqM+&	3''
G<<r^  c           
         |t        | j                  dz         | j                          d}| j                  |dd      \  }}|r| j	                  d|||d|d      S |d}d|i}| j                  |      }|d	   }|d
   |d	<   d}| j                  d||      \  }}|dk(  s|dk(  rt        | j                  dz         ||d<   |||d<   | j                  |d      }	| j                  |d|	      }
| j                  |ddg      }|
|
|d<   n|d}|||z  z   |d<   | j                  | j                  ||            }g }| j                  |d      }| j                  |d      }t        dt        |            D ]q  }||   }| j                  |d      }|j!                  || j#                  | j%                  |d	      ddd      | j'                  |d      || j)                  |      d       s | j+                  |d      }| j-                  ||||      S )a  
        fetches historical funding rate prices

        https://bybit-exchange.github.io/docs/v5/market/history-fund-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 <https://docs.ccxt.com/#/?id=funding-rate-history-structure>` to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest funding rate
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentFr   r  8hr  rG  r  rE   rT   rX   zA fetchFundingRateHistory() only support linear and inverse marketr  	startTimeuntilendTimei trj  rk  r   fundingRateTimestamprV   r  )r  r  r  r  r  r  )r2   rE   r  r  r  r  r  r;   r  rc  publicGetV5MarketFundingHistoryr%  rq  r  r  rt  r  r}  r  r  rE  sort_byfilter_by_symbol_since_limit)r[  r  r  rG  r  r  r(  r  r  r  r  r  ru  ratesrj  
resultListr  entryr  sorteds                       r]  fetch_funding_rate_historyz bybit.fetch_funding_rate_history
  sm    >#DGG.e$eff88AZ\fg&::;TV\^cejlprxz}~~=E U
 V$!"4L**+DffUf6>TX-tww)llmm"
#(GK !!&'2##FIu=6Iw#78!(GI "4%*U_-D%D	"77GV8TU& (3^^FF3
q#j/* 		AqME))%1GHILL**4+;+;E8+LdTXZ`a#//}E& LL3 		 e[100NNr^  tradec                 ,   | j                  |g d      }| j                  |d      }d|v rdnd}||d   }| j                  |d      }||dk(  rd}| j                  ||d |      }|d   }| j                  |g d      }| j                  |g d	      }	| j                  |d
      }
| j                  |g d      }| j	                  |d      }|| j                  |d      }||rdnd}| j                  |d      }d }||rdnd}n?| j                  |d      }|dk(  rd }|$|dk(  s|dk(  r|j                         }n	|dk(  rdnd}| j	                  |d      }|dk(  rd }| j                  |d      }d }|f| j                  |d      }d }|d   r8t        j                  |d      r|dk(  r|d   }n&|d   }n |dk(  r|d   }n|d   }n|d   r|d   n|d    }|||d!}| j                  |||| j                  |      || j                  |d"      ||||	||
|d#|      S )$N)execIdrE   tradeIdr  
createTyper  rT   r  r  )execQtyorderQtysize)	execPrice
orderPricer1  	execValue)r  execTime	tradeTimesideisBuyerbuysellisMakerrT  rS  lastLiquidityIndUNKNOWNTAKERMAKERAddedLiquidity	orderTypeunknownexecFeefeeRater  r  r  r  r  )r  r  rateorderId)rE   r  r  r  r  orderr  r  takerOrMakerr1  r  r  r  )r  r  r  safe_integer_nrW  r  r}  lowerr@   	string_gt
safe_traderE  )r[  r  r  rE   r  r  r  r  r  priceString
costStringr  r  r  r  r  r  r  feeCostStringr  feeRateStringfeeCurrencyCodes                         r]  parse_tradezbybit.parse_trade  s   | 'BC##E84$0E$9Z
J##E:66!#
!!(FD*E!))%1PQ((0TU%%e[9
''/PQ	%%eV4<''y9G" 'uV..	2&-77L#//7IJ9,#' +$/5E5P#3#9#9#;L/?CS/S7ZaL**5+>		!I((	:$ ,,UI>M"Of~$$]C8u}*0.*0/u}*0/*0.4:94E&.6RZK[%+%C
 "Y/%%eY7( " 
  	r^  c                    |t        | j                  dz         | j                          | j                  |      }d|d   i}|||d<   d}| j	                  d||      \  }}||d<   | j                  | j                  ||            }| j                  |di       }	| j                  |	d	g       }
| j                  |
|||      S )
a  
        get the list of most recent trades for a particular symbol

        https://bybit-exchange.github.io/docs/v5/market/recent-trade

        :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 str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        Nz) fetchTrades() requires a symbol argumentr  rE   rG  r   r  rj  rk  )
r2   rE   r  r  r  publicGetV5MarketRecentTrader%  rq  r  parse_trades)r[  r  r  rG  r  r  r(  r  ru  rj  tradess              r]  fetch_tradeszbybit.fetch_trades  s     >#DGG.Y$YZZV$fTl

   %GG**=&&If"
44T[[&5QR. (B73  >>r^  c                    |t        | j                  dz         | j                          | j                  |      }d|d   i}d}|d   rd}d|d<   n |d   rd|d<   n|d	   rd	|d<   n
|d
   rd
|d<   ||n||d<   | j	                  | j                  ||            }| j                  |di       }| j                  |d      }	| j                  |||	dd      S )a7  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://bybit-exchange.github.io/docs/v5/market/orderbook

        :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
        z, fetchOrderBook() requires a symbol argumentr  rE   r   rT   r   r  rX   r  r  rG  rj  tsba)	r2   rE   r  r  publicGetV5MarketOrderbookr%  rq  r  parse_order_book)
r[  r  rG  r  r  r(  defaultLimitru  rj  r  s
             r]  fetch_order_bookzbybit.fetch_order_book  s    >#DGG.\$\]]V$fTl
 &>L"(GJh&.
#!&.
#	"&/
#%*%65\224;;w3OP4 (B7%%fd3	$$VVYSIIr^  c                    | j                  |d      }||| j                  |      d}| j                  |di       }| j                  |g d      }|Cd}| j	                         }| j                  |d      |d<   | j                  |d      |d	<   |||<   nHt        d
t        |            D ]/  }||   }	| j                  |	d      }
|
dk(  s|
dk(  s|
dk(  rH| j                  |	d      }t        d
t        |            D ]  }| j	                         }||   }| j                  |d      }| j                  |d      }||t        j                  ||      |d<   | j                  |d      |d	<   | j                  |dd      }|||d<   nj| j                  |dd      }| j                  |dd      }| j                  |dd      }t        j                  ||      }t        j                  ||      }||d<   | j                  |d      }| j                  |      }|||<    s| j	                         }| j                  |	d      }| j                  |	d      }||t        j                  ||      |d<   | j                  |	d	d      |d	<   | j                  |	g d      |d<   | j                  |	d      |d<   | j                  |	g d      }| j                  |      }|||<   2 | j                  |      S )Nr  )r  r  r  rj  )loanAccountListrk  balancer  availableBalancefreewalletBalancetotalr   accountTyper  r  r  r  borrowAmountaccruedInterestdebtavailableToWithdrawlockedr  totalPositionIMtotalOrderIMusedloaninterest)r  availableBalanceWithoutConvertr  transferBalance)tokenIdr  currencyCoin)r  rE  rq  rr  accountr  r  rt  r  r@   
string_addrs  r  r  safe_balance)r[  ru  r  rj  r)  currencyListr  r  r  r  r  coinsr  	coinEntryr  r  r  r  totalPositionImtotalOrderIm	totalUsedr  s                         r]  parse_balancezbybit.parse_balance'  s(   N %%h7	"Y/

 (B?''8^_DllnG"..~?QRGFO#//PGG"F4L1c,/0 &+$Q"..umD)+{j/HK[aLa NN5&9E"1c%j1 /"&,,.$)!H	#//	>J#'#3#3I?P#Q ,83G.5.@.@x.PGFO+/+;+;I+W(#11)=RTZ[+.2GFO%)%5%5i3%OF.2.>.>yJ[]`.aO+/+;+;I~WZ+[L(/(:(:6?(SI(/(:(:9l(SI.7GFO%)%5%5i%H
#66zB'.t+/. #llnG++E6:D#//zBH(x/C*1*<*<T8*L'+'9'9%/'ZGG$&*&8&8  AR  'SGFO&*&6&6uh&GGFO!%!3!3E;^!_J22:>D#*F4LM&+N   ((r^  c                 6   | j                          i }| j                         \  }}|xs |}d}| j                  dd|      \  }}d}| j                  dd|      \  }}|dk(  s|dk(  r|}||j	                         nd}|dk(  }	|dk(  }
|dk(  }|dk(  xs |d	k(  }|r-| j                  | j                  d
d      }|dk  r|rd}nd}n	d}n|
s|rd}| j                  | j                  di       }| j                  |||      }d}| j                  d|      \  }}d}|	r$|"| j                  | j                  ||            }nO|r'd|d<   | j                  | j                  ||            }n&||d<   | j                  | j                  ||            }| j                  |      S )aJ  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://bybit-exchange.github.io/docs/v5/spot-margin-normal/account-info
        https://bybit-exchange.github.io/docs/v5/asset/all-balance
        https://bybit-exchange.github.io/docs/v5/account/wallet-balance

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: wallet type, ['spot', 'swap', 'funding']
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        Nrr   rV   rW   rT   r  r  r  r  r  r{  r   r  r  r&  r  r  )r  r  r  r  r  r  r  rq  safe_string_upperhandle_margin_mode_and_params'privateGetV5SpotCrossMarginTradeAccountr%  1privateGetV5AssetTransferQueryAccountCoinsBalance privateGetV5AccountWalletBalancer(  )r[  r  r(  r  r  isUnifiedAccountr  r  lowercaseRawTyper  isLinearr[  	isFundingr  accountTypesunifiedTyper6  ru  s                     r]  fetch_balancezbybit.fetch_balance  s    	484K4K4M11/G3G99.$PVWf99.$PVWFN 0D,0,<4::<4&.H$Y&	%/S5E5R	"&"3"3DLLBWYZ"["Q&%D$D 9!~~dll4DbI,,\4F
!??PVW
Fz-CCDKKPWY_D`aH &,GM"MMdkkZaciNjkH%0GM"<<T[[RX=YZHN !!(++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dddd}| j                  |||      S )NNEWrt  PARTIALLY_FILLEDFILLEDclosedCANCELEDcanceledPENDING_CANCELPENDING_NEWREJECTEDrejectedPARTIALLY_FILLED_CANCELLEDCreatedNewRejectedPartiallyFilledPartiallyFilledCanceledFilledPendingCancel	CancelledUntriggered)Deactivated	TriggeredActiver  r[  r  statusess      r]  parse_order_statuszbybit.parse_order_statusg  s    
6
 
 h	

 

 f
 6
 

 )(
 v
 6
 

 v
 &x
  h!
" V#
$ %
( 6)
* &/
2 &&99r^  r<  c                 6    ddddd}| j                  |||      S )NGTCr2  r3  r4  )GoodTillCancelImmediateOrCancel
FillOrKillPostOnlyrN  )r[  r<  timeInForcess      r]  parse_time_in_forcezbybit.parse_time_in_force  s,    #!&	
 k;GGr^  r  c                    | j                  |d      }|y|dk7  rt| j                  |d      }|dk(  rdnd}| j                  |d| j                  |d      | j                  |d      | j                  | j                  |d	      d d |      d
      S | j                  |d	      }d|v }d }||d   }n|rdnd}| j                  ||d |      }|d	   }	| j	                  |dd      }
| j                  |dd      }| j                  |d      }| j                  |d      }| j                  |d      }d }d }|dk(  r%| j                  |d      }| j                  |d      }n| j                  |d      }| j                  |d      }| j                  |d      }| j	                  |dd      }| j                  |d      }| j                  |      }| j                  |d      }d }| j                  |d      }|bd }|d   r8t        j                  |d      r|dk(  r|d   }n&|d   }n |dk(  r|d   }n|d   }n|d   r|d   n|d    }| j                  |      |d!}| j                  |d      }|t        |      d"k  rd }| j                  | j                  |d#            }| j                  |d$      }| j                  |      }| j                  | j                  |d%            }| j                  |d&      }| j                  | j                  |d'            } | j                  | j                  |d(            }!| j                  |d)      }"|"d*k(  }#|d uxr |}$|!|$r|#r|dk(  r|}!|#s|d+k(  r|}!| |$r|#r|d+k(  r|} |#s|dk(  r|} | j                  i d,|d-|d.|d/|
d0| j                  |
      d1|d2|d	|	d|d$|d3d d&| j                  |d&      d|d|d%|d4| d5|!|||||||d d6|      S )7Nr  r  r  rT   r  r@  r  orderLinkIdr  )r  r  rE   clientOrderIdr  tpslModer  createdTime	createdAt
marketUnitr  r  r1  qtycumExecValue
cumExecQty	leavesQtyupdatedTime	updatedAtorderStatusr  
cumExecFeer  r  r  r  r  r  r  r   avgPricer<  r7  
reduceOnly
takeProfitstopLossr8  r   r  r  rE   r\  r  r  lastTradeTimestamplastUpdateTimestamppostOnlyr:  r9  )r  r  rx  filled	remainingr  r  r  )r  
safe_orderr}  r  safe_integer_2rW  rQ  r@   r  r  rt  rC  rY  r}  rE  )%r[  r  r  r  r  inferredMarketTyper  
isContractr  r  r  r`  rE   r  r1  r  r  rq  rr  rn  	rawStatusr  r  r  r  r  r\  rj  rawTimeInForcer<  r7  rk  r:  r9  r8  isAscendingisStopOrderType2s%                                        r]  parse_orderzbybit.parse_order  s   | v.s{++E:>08F0BV"!(**5)<%)%5%5e]%K"..t/?/?x/PRVX\^pq(   ##E84 E)

J'1vJ!!(FD*E!''}kJ	%%e\:F
eY/%%e[9  0#%%eU3F##E>:D##E>:D!!%6$$UK8	!00{S$$UM:	((3%%eV4((=$"Of~$$]C8u}*0.*0/u}*0/*0.4:94E&.6RZK[))-8+C ((>%C,>,B M>>$"2"25*"EF))%?..~>~~d&6&6un&MN^^E<8
..)9)9%)NOt'7'7z'JK++E3EF'3.(4D*!'7 ,DFN ,#)9".DEM".  
E 
" 
 ] 
 	 

 Y/ 
 !"4 
 "#5 
 f 
 D 
 ; 
  
 $..= 
 D 
 U 
 L 
  ! 
" ]# 
$ "3 
4 5 	r^  c                     | j                          | j                  |      }|d   st        | j                  dz         | j	                  |dd|d|      S )a  
        create a market buy order by providing the symbol and cost

        https://bybit-exchange.github.io/docs/v5/order/create-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>`
        rT   z9 createMarketBuyOrderWithCost() supports spot orders onlyr  r  r   )r  r  r;   rE   create_order)r[  r  r  r  r  s        r]  !create_market_buy_order_with_costz'bybit.create_market_buy_order_with_cost_  sU     	V$f~tww)ddee  5$6JJr^  c                    | j                          | j                         }|d   }|st        | j                  dz         | j	                  |      }|d   st        | j                  dz         | j                  |dd|d|      S )a  
        create a market sell order by providing the symbol and cost

        https://bybit-exchange.github.io/docs/v5/order/create-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>`
        r   z; createMarketSellOrderWithCost() supports UTA accounts onlyrT   z: createMarketSellOrderWithCost() supports spot orders onlyr  r  )r  r  r;   rE   r  r}  )r[  r  r  r  typesr  r  s          r]  "create_market_sell_order_with_costz(bybit.create_market_sell_order_with_costp  s     	'')$Qx#tww)ffggV$f~tww)eeff  64FKKr^  r  r  c           	         | j                          | j                  |      }| j                         }|d   }	| j                  |dd      }
| j	                  |d      }| j	                  |d      }|
du}|du}|du}| j                  |||||||	      }d}|s|s|rd}nd}d}| j                  |d	d
|      \  }}d}|dk(  r| j                  |      }n| j                  |      }| j                  |di       }| j                  ||      S )a
  
        create a trade order

        https://bybit-exchange.github.io/docs/v5/order/create-order
        https://bybit-exchange.github.io/docs/v5/position/trading-stop

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.timeInForce]: "GTC", "IOC", "FOK"
        :param bool [params.postOnly]: True or False whether the order is post-only
        :param bool [params.reduceOnly]: True or False whether the order is reduce-only
        :param str [params.positionIdx]: *contracts only* 0 for one-way mode, 1 buy side of hedged mode, 2 sell side of hedged mode
        :param bool [params.hedged]: *contracts only* True for hedged mode, False for one way mode, default is False
        :param int [params.isLeverage]: *unified spot only* False then spot trading True then margin trading
        :param str [params.tpslMode]: *contract only* 'full' or 'partial'
        :param str [params.mmp]: *option only* market maker protection
        :param str [params.triggerDirection]: *contract only* the direction for trigger orders, 'above' or 'below'
        :param float [params.triggerPrice]: The price at which a trigger order is triggered at
        :param float [params.stopLossPrice]: The price at which a stop loss order is triggered at
        :param float [params.takeProfitPrice]: The price at which a take profit order is triggered at
        :param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered
        :param float [params.takeProfit.triggerPrice]: take profit trigger price
        :param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered
        :param float [params.stopLoss.triggerPrice]: stop loss trigger price
        :param str [params.trailingAmount]: the quote amount to trail away from the current market price
        :param str [params.trailingTriggerPrice]: the price to trigger a trailing order, default uses the price argument
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   trailingAmounttrailingStopr9  r:  N privatePostV5PositionTradingStopprivatePostV5OrderCreaterd   r  rj  )r  r  r  rs  r  create_order_requestr  r  r  rq  r{  )r[  r  r  r  r  r1  r  r  partsr  r  r9  r:  isTrailingAmountOrder
isStopLossisTakeProfitorderRequestdefaultMethodr  ru  r  s                        r]  r}  zbybit.create_order  s9   B 	V$'')$Qx++F4DnU((A**63DE .d :"$.
&d200tVUTZ\pq J,>M6M66v}hXef77<<\JH44\BH x26v..r^  Tc                    | j                  |      }|d   }|j                         }	||	dk(  rt        | j                  dz         d|d   i}
| j	                  |dd      }| j	                  |d      }| j                  |dd	      }| j                  |d
      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |dd| j                  |            }| j                  |dd      }|d u}|d u}|d u}|d u}|d u}|d u}|	dk(  }|	dk(  }|dk(  }d }|s|s|rd}nd}d }| j                  |dd|      \  }}|dk(  }| j                  ||      } |!| j                  || j                  |            nd }!|s|r|s	|s|s|d   rt        | j                  dz         |s|r-|r-| j                  ||      |
d<   |rd|
d<   d|
d<   |!|
d<   | |
d<   n|r| j                  ||      |
d<   |rd|
d<   d|
d <   |!|
d!<   | |
d"<   n| j                  |      |
d#<   | j                  |	      |
d$<   | j                  |d%      }"d }#| j                  ||"d&k(  |      \  }#}|#rd'|
d%<   n |"d(k(  rd)|
d%<   n|"d*k(  rd+|
d%<   n
|"d,k(  rd-|
d%<   |d   r|d.|
d/<   n|||s|rd0|
d/<   | j!                  |d1      }$|$|$|
d2<   n|d3   r| j#                         |
d2<   |r|!|
d4<   |d   rd|
d5<   n |d3   rd3|
d5<   n|d6   rd6|
d5<   n
|d7   rd7|
d5<   | j!                  |d8      }%| j%                  |d8      }|	dk(  xr |dk(  xr
 |d uxs |%d u}&|d   rR|dk(  rM|rK|&sI|%|:d9|
d:<   d }'|%|%}'nt'        j(                  | |!      }(|(}'| j+                  ||'      |
d;<   nd<|
d:<   | |
d;<   n|d   r|dk(  r|dk(  rd=})| j                  |dd>      \  })}|)rN||%t        | j                  d?z         t'        j(                  | |!      }(|%|%n|(}*| j+                  ||*      |
d;<   nb|%%| j+                  || j                  |%            |
d;<   n;|*| j+                  |t'        j(                  | |!            |
d;<   n| |
d;<   n	|s|s| |
d;<   |r|| j                  ||      |
d<   ||
d<   n|r|s| j!                  |d@      }+| j%                  |g dA      }|d   r|+Gt-        | j                  dBz         |+t        | j                  dCz         |+dDk(  xs |+dEk(  },|,rdFndG|
d@<   | j                  ||      |
d<   n;|s|r7|s5|r
|rdFndG|
d@<   n	|rdGndF|
d@<   |r|n|}| j                  ||      |
d<   d=|
d<   |s|r|s|r\| j                  |dd	|      }-| j                  ||-      |
d<   | j                  |d4      }.|.d|
d<   d|
d<   | j                  ||.      |
d<   |r\| j                  |dd	|      }/| j                  ||/      |
d<   | j                  |d4      }0|0d|
d<   d|
d <   | j                  ||0      |
d!<   |d   s+|r)|r| j%                  |d      }|dk(  rdHnd}|dk(  rdFndG|
dI<   | j%                  |g dJ      }| j/                  |
|      S )KNr  rG  z7 createOrder requires a price argument for limit ordersrE   r=  Frk  r7  	stopPricer9  r:  rm  rl  trailingTriggerPriceactivePricer  r  r  r  r  r  rd   r  rT   zf the API endpoint used only supports contract trailingAmount, stopLossPrice and takeProfitPrice ordersPartialr]  LimitslOrderTypeslLimitPriceslSizetpOrderTypetpLimitPricetpSizer  r  r<  postonlyrW  gtcrS  fokr3  iocr2  	StopOrderorderFilter	tpslOrderr\  r[  rX   r1  r  r  r  r  r  r`  ra  r  Tr  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 argumentr8  )r7  r  r8  zU createOrder() : trigger order does not support triggerDirection for spot markets yetz stop/trigger orders require a triggerDirection parameter, either "above" or "below" to determine the direction of the trigger.abover   r   r  r  positionIdx)r  r<  r9  r:  rp  r\  r7  rm  rl  r  r  r=  )r  r  r2   rE   r}  safe_value_2
safe_valuers  r  r  r  r  r9   
capitalizerW  handle_post_onlyr  uuid16rc  r@   r~  r  r;   r%  )1r[  r  r  r  r  r1  r  isUTAr  lowerCaseTyper(  r=  rk  r7  stopLossTriggerPricetakeProfitTriggerPricerm  rl  r  r  r  isTriggerOrderisStopLossTriggerOrderisTakeProfitTriggerOrderr  r  isMarketisLimitisBuyr  r  isAlternativeEndpointr  r  r<  rp  r\  r  isMarketBuyAndCostInferable	orderCostquoteAmountr  costRequestr8  
isAsendingslTriggerPricer  tpTriggerPricer  s1                                                    r]  r  zbybit.create_order_request  sY   V$!

M 8#DGG.g$ghhfTl
2 %8^^FL9
((M#vG!%9J!K??6:6__V\:
#11&:PR_aeavavw|a}~++F4DnU .d :%T1!5T!A#9#E T)
!- H,7* $:>V>M6M66v}hXef &*L Lvv6OTO`dnnVT-B-B5-IJgk $9\^vf~"477  .V  $V  W  W%)A)*...AU*VGJ'.7
+18.2=/,8)-,0NN6CY,ZGL).7
+18.2=/,8)"ood3GFO#'??=#AGK 00GKH#44X{j?XZ`aHf)3&%).&%).&%).&f~+-8GM*)59O9[_imy-8GM* ,,V_EM()6&!)-&#. &>"(GJH"*GJH"*GJI"+GJ/66*'4'@  'Ftu}  'F\aim\m  \Esw  @D  tD#&>tx/UC^ e&7(3% 	# $I")"4"4\;"OK +I!%vy!A(2%!-F^!1 15-8<8U8UV\^k  nQ  9R5-v0M&tww  2m  (m  n  n")"4"4\;"OK+/+;$+K%)]]6;%GGEN#%)]]64;P;PQU;V%WGEN&%)]]67;M;Ml\g;h%iGEN%1GEN(1F!- #/)-@T)U&&4GN#$9#//8JKYYv'XYFf~#/&tww  2I  (I  J  J#++DGG  7x  -x  y  y/7:X@PTW@W
3=a1*+&*nnV\&JGN#$(@J_3Iaq*+3Iaq*+3I/OeL&*nnV\&JGN#$(GL!,0E!%!2!28^[Zb!c&*nnV^&L
##xA+*3GJ'-4GM*.2nnV\.RGN+!%!2!2:~{\f!g(,v~(N%#z7C+*3GJ'-4GM*.2nnV\.RGN+f~&6<8"&%-ve+/5=QqGM"6  $_  `{{7F++r^  ordersc           
         | j                          | j                         }|d   }g }g }t        dt        |            D ]  }||   }| j	                  |d      }	|j                  |	       | j	                  |d      }
| j	                  |d      }| j                  |d      }| j                  |d      }| j                  |di       }| j                  |	|
|||||      }|d	= |j                  |        | j                  |d
ddd      }| j                  |d         }| j                  | j                  dd      }d
}| j                  d||      \  }}|dk(  r|dk  rt        | j                  dz         ||d}| j!                  | j#                  ||            }| j                  |di       }| j%                  |dg       }| j                  |di       }| j%                  |dg       }t        dt        |            D ]7  }||   }| j                  |d      }|dk7  s | j#                  ||   |      ||<   9 | j'                  |      S )a  
        create a list of trade orders

        https://bybit-exchange.github.io/docs/v5/order/batch-place

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   r   r  r  r  r  r1  r  r  NFTr  r{  re   r  r   zB createOrders does not allow inverse orders for non UTA2.0 accountr  r(  rj  rk  
retExtInfor  )r  r  r  rt  r  r  r  rq  r  r  r  r  r  r  r;   rE   privatePostV5OrderCreateBatchr%  r  parse_orders)r[  r  r  accountsisUtaordersRequestsorderSymbolsr  rawOrderr  r  r  r  r1  orderParamsr  r  r  r  r  r(  ru  rj  rm  retInfocodesr  retCodes                               r]  create_orderszbybit.create_orders  sc    	**,q#f+& 	0AayH''(;H)##Hf5D##Hf5D__Xx8FOOHg6E..8R@K44XtT6SXZeglmLZ(!!,/	0 %%lD%tLWQZ("//>SUVW..~vvN&	!(;a(?tww)mmnn %
 55dkk'66RS(B7~~ffb1..<<w3q#e*% 	5A8D''f5G!|++d1gt4Q		5T   &&r^  rE   c                    | j                  |      }|d   |d}	|d   rd|	d<   n |d   rd|	d<   n|d   rd|	d<   n
|d   rd|	d<   || j                  ||      |	d<   |$| j                  || j                  |            |	d	<   | j	                  |d
d      }
| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }|d u}|d u}|d u}|d u}|s|r|r|n|}
|
6|
dk(  r|
n| j                  ||
      }||	d
<   | j                  |dd      }||	d<   |s|r|rJ| j	                  |d
d|      }|dk(  r|n| j                  ||      }||	d<   | j                  |dd      }||	d<   |rJ| j	                  |d
d|      }|dk(  r|n| j                  ||      }||	d<   | j                  |dd      }||	d<   | j                  |d      }|||	d<   | j                  |g d      }|	S )NrE   r  r  rT   r  r  r  rX   ra  r1  r7  r  r9  r:  rm  rl  r  	triggerBy	LastPriceslTriggerBytpTriggerByr\  r[  )r  r9  r:  r7  r\  rm  rl  )r  r  r  r  rs  r  r  rc  )r[  rE   r  r  r  r  r1  r  r  r(  r7  r  r  rm  rl  r  r  r  r  triggerPriceRequestr  r  stopLossRequestr  r  takeProfitRequestr  r\  s                               r]  edit_order_requestzbybit.edit_order_request  s   V$Tl
 &>"(GJH"*GJI"+GJH"*GJ!__VV<GEN#~~fd6K6KE6RSGG))&.+N#//H!%!1!1&:K!L??6:6__V\:
!5T!A#9#E T)
!-!%=3I/OeL#3?33F,T^^\bdpMq&9GN#((kJI#,GK !%!3!3Hnk[c!d5Cs5J.QUQ_Q_`fhvQw&5
#"..v}kR)4&!%!3!3JP[]g!h7E7LNSWSaSabhjxSy!(9%"..v}kR)4&((A$%2GM"6  $P  Qr^  c           	      4   | j                          |t        | j                  dz         | j                  |||||||      }| j	                  | j                  ||            }	| j                  |	di       }
| j                  |	| j                  |
d      d      S )a#  
        edit a trade order

        https://bybit-exchange.github.io/docs/v5/order/amend-order
        https://bybit-exchange.github.io/docs/derivatives/unified/replace-order
        https://bybit-exchange.github.io/docs/api-explorer/derivatives/trade/contract/replace-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 of currency you want to trade in units of base currency
        :param float price: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: The price that a trigger order is triggered at
        :param float [params.stopLossPrice]: The price that a stop loss order is triggered at
        :param float [params.takeProfitPrice]: The price that a take profit order is triggered at
        :param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice that the attached take profit order will be triggered
        :param float [params.takeProfit.triggerPrice]: take profit trigger price
        :param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice that the attached stop loss order will be triggered
        :param float [params.stopLoss.triggerPrice]: stop loss trigger price
        :param str [params.triggerBy]: 'IndexPrice', 'MarkPrice' or 'LastPrice', default is 'LastPrice', required if no initial value for triggerPrice
        :param str [params.slTriggerBy]: 'IndexPrice', 'MarkPrice' or 'LastPrice', default is 'LastPrice', required if no initial value for stopLoss
        :param str [params.tpTriggerby]: 'IndexPrice', 'MarkPrice' or 'LastPrice', default is 'LastPrice', required if no initial value for takeProfit
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        z' editOrder() requires a symbol argumentrj  r  )r  rE   )	r  r2   rE   r  privatePostV5OrderAmendr%  rq  rs  r  )r[  rE   r  r  r  r  r1  r  r(  ru  rj  s              r]  
edit_orderzbybit.edit_order,  s    6 	>#DGG.W$WXX))"fdD&%QWX//GV0LM (B7""695 
  	r^  c           
         | j                          g }g }t        dt        |            D ]  }||   }| j                  |d      }|j	                  |       | j                  |d      }| j                  |d      }	| j                  |d      }
| j                  |d      }| j                  |d      }| j                  |di       }| j                  |||	|
|||      }|d	= |j	                  |        | j                  |d
ddd      }| j                  |d         }| j                  | j                  dd      }d
}| j                  d||      \  }}|dk(  r|dk  rt        | j                  dz         ||d}| j                  | j!                  ||            }| j                  |di       }| j#                  |dg       }| j                  |di       }| j#                  |dg       }t        dt        |            D ]7  }||   }| j                  |d      }|dk7  s | j!                  ||   |      ||<   9 | j%                  |      S )a  
        edit a list of trade orders

        https://bybit-exchange.github.io/docs/v5/order/batch-amend

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   r  rE   r  r  r  r1  r  r  NFTr  r{  rq   r  r   z@ editOrders does not allow inverse orders for non UTA2.0 accountr  rj  rk  r  r  )r  r  rt  r  r  r  rq  r  r  r  r  r  r  r;   rE   privatePostV5OrderAmendBatchr%  r  r  )r[  r  r  r  r  r  r  r  rE   r  r  r  r1  r  r  r  r  r  r(  ru  rj  rm  r  r  r  r  s                             r]  edit_orderszbybit.edit_orders^  s]    	q#f+& 	0AayH%%h9F'!!(D1B##Hf5D##Hf5D__Xx8FOOHg6E..8R@K222vtT6SXZefLZ(!!,/	0 **<udDQ\!_-"//>SUVW..|VVL&	!(;a(?tww)kkll %
 44T[[&5QR(B7~~ffb1..<<w3q#e*% 	5A8D''f5G!|++d1gt4Q		5P   &&r^  c                 &   | j                  |      }d|d   i}|d   r1| j                  |ddd      }| j                  |ddg      }|rdnd|d	<   |||d
<   |d   rd|d<   n |d   rd|d<   n|d   rd|d<   n
|d   rd|d<   | j                  ||      S )Nr  rE   rT   stoprK  Fr  r   r  r  r  r  r  rX   )r  safe_bool_2rc  r%  )r[  rE   r  r  r  r(  	isTriggers          r]  cancel_order_requestzbybit.cancel_order_request  s    V$fTl
 &>((EJIYYv	':;F4=[7GM">!#GI&>"(GJH"*GJI"+GJH"*GJ{{7F++r^  c                 
   |t        | j                  dz         | j                          | j                  |      }| j	                  |||      }| j                  |      }| j                  |di       }| j                  ||      S )aw  
        cancels an open order

        https://bybit-exchange.github.io/docs/v5/order/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 boolean [params.trigger]: *spot only* whether the order is a trigger order
        :param boolean [params.stop]: alias for trigger
        :param str [params.orderFilter]: *spot only* 'Order' or 'StopOrder' or 'tpslOrder'
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        z) cancelOrder() requires a symbol argumentrj  )r2   rE   r  r  r  privatePostV5OrderCancelrq  r{  )r[  rE   r  r  r  requestExtendedru  rj  s           r]  cancel_orderzbybit.cancel_order  s     >#DGG.Y$YZZV$33BG00A (B7//r^  c                 T   |t        | j                  dz         | j                          | j                  |      }| j	                         }|d   }|st        | j                  dz         d}| j                  d||      \  }}|dk(  rt        | j                  dz         g }| j                  |dd	g       }	| j                  |dd	g      }t        d
t        |	            D ])  }
|j                  |d   | j                  |	|
      d       + t        d
t        |            D ])  }
|j                  |d   | j                  ||
      d       + ||d}| j                  | j                  ||            }| j                  |di       }| j!                  |dg       }| j#                  ||      S )a  
        cancel multiple orders

        https://bybit-exchange.github.io/docs/v5/order/batch-cancel

        :param str[] ids: order ids
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str[] [params.clientOrderIds]: client order ids
        :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz* cancelOrders() requires a symbol argumentr   z* cancelOrders() supports UTA accounts onlyr]   r  z+ cancelOrders does not allow inverse ordersclientOrderIds
clientOidsr   rE   )r  r[  r  r  rj  rk  )r2   rE   r  r  r  r;   r  safe_list_2rc  r  rt  r  r  privatePostV5OrderCancelBatchr%  rq  r  r  )r[  idsr  r  r  r  r  r  r  r  r  r(  ru  rj  rows                  r]  cancel_orderszbybit.cancel_orders  s    >#DGG.Z$Z[[V$'')$Qx#tww)UUVV..~vvN&y tww)VVWW))&2BLRTU6$4l#CDq#n-. 	A!! ,#//B# 	
 q#c(# 	A!! ,++C3# 	 !%
 55dkk'66RSH (B7nnVVR0  f--r^  timeoutc                    | j                          d| j                  |dz        i}d}| j                  dd|d      \  }}dddd	}| j                  |||      }||d
<   | j	                  | j                  ||            }|S )a  
        dead man's switch, cancel all orders after the given timeout

        https://bybit-exchange.github.io/docs/v5/order/dcp

        :param number timeout: time in milliseconds
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.product]: OPTIONS, DERIVATIVES, SPOT, default is 'DERIVATIVES'
        :returns dict: the api result
        
timeWindowrM  Nr[   rV   r  DERIVATIVESOPTIONS)rT   rV   rX   product)r  r  r  r  'privatePostV5OrderDisconnectedCancelAllr%  )r[  r  r  r(  r  
productMapr  ru  s           r]  cancel_all_orders_afterzbybit.cancel_all_orders_afterA  s     	$++GdN;
 99:PRVX^`fgf!


 "":tT:$	??GU[@\] r^  c                    | j                          | j                         }|d   }|st        | j                  dz         g }d}t	        dt        |            D ]  }||   }| j                  |d      }	| j                  |	      }
d}| j                  d|
|      \  }}|dk(  rt        | j                  dz         |||k7  rt        | j                  d	z         |}| j                  |d
      }| j                  |d      }d}|d}d|
d
   i}|dk(  r|n|||<   |j                  |        ||d}| j                  | j                  ||            }| j                  |di       }| j                  |dg       }| j                  |d      S )a  
        cancel multiple orders for multiple symbols

        https://bybit-exchange.github.io/docs/v5/order/batch-cancel

        :param CancellationRequest[] orders: list of order ids with symbol, example [{"id": "a", "symbol": "BTC/USDT"}, {"id": "b", "symbol": "ETH/USDT"}]
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r   z4 cancelOrdersForSymbols() supports UTA accounts onlyNr   r  r]   r  z5 cancelOrdersForSymbols does not allow inverse ordersz_ cancelOrdersForSymbols requires all orders to be of the same category(linear, spot or option))rE   r\  r  r[  r  rj  rk  )r  r  r;   rE   r  rt  r  r  r  r.   r  r  r%  rq  r  r  )r[  r  r  r  r  r  r  r  r  r  r  currentCategoryrE   r\  idKey	orderItemr(  ru  rj  r  s                       r]  cancel_orders_for_symbolszbybit.cancel_orders_for_symbolsb  s    	'')$Qx#tww)__``q#f+& 	-A1IE%%eX6F[[(F"O&*&9&9.&RX&Y#OV)+"477-d#dee$8+F#DGG  /P  %P  Q  Q&H!!%.B ,,UODME(%&,I ',y&8r}Ie!!),)	-, !%
 55dkk'66RSH (B7nnVVR0  d++r^  c                    | j                          | j                         \  }}|xs |}d}i }|| j                  |      }|d   |d<   d}| j                  d||      \  }}||d<   |dk(  r |st	        | j
                  dz   |z   dz         |d	k(  s|d
k(  rI| j                  |d      }	|5|	3| j                  | j                  dd      }
| j                  |d|
      |d<   | j                  |ddd      }| j                  |ddg      }|rd|d<   | j                  | j                  ||            }| j                  |di       }| j                  |d      }t        |t              s|S | j!                  ||      S )a\  
        cancel all open orders

        https://bybit-exchange.github.io/docs/v5/order/cancel-all

        :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: True if trigger order
        :param boolean [params.stop]: alias for trigger
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :param str [params.baseCoin]: Base coin. Supports linear, inverse & option
        :param str [params.settleCoin]: Settle coin. Supports linear, inverse & option
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        NrE   r  rZ   r  rX   z. cancelAllOrders() Normal Account not support z marketr  r  r  r  r  r5  r  rK  Fr  r  rj  rk  )r  r  r  r  r;   rE   r  r  r  rc  privatePostV5OrderCancelAllr%  rq  r  
isinstancerk  r  )r[  r  r  r  r  r/  r  r(  r  r  r  r  ru  rj  r  s                  r]  cancel_all_orderszbybit.cancel_all_orders  s     	484K4K4M11/G3G[[(F &tGH**+<ffMf"
H&6tww)YY\``cllmmH$)"3''
;H~("2 $ 0 0PV W(,(8(8}(]%$$VVYF	6FI#67%0GM"33DKK4PQ: (B7/&$'O  00r^  c           	         |t        | j                  dz         | j                          | j                  |      }|d   rt	        | j                  dz         d|i}| j                  |dd| j                  ||            }t        |      }|dk(  r8| j                  |ddgd	      }|rd
nd}	t        dt        |      z   dz   |	z         |dkD  rt        | j                  dz         | j                  |d      S )a  
        fetches information on an order made by the user *classic accounts only*

        https://bybit-exchange.github.io/docs/v5/order/order-list

        :param str id: the order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz( fetchOrder() requires a symbol argumentrT   z/ fetchOrder() is not supported for spot marketsr  r   rK  r  F c If you are trying to fetch SL/TP conditional order, you might try setting params["trigger"] = TrueOrder  was not found.r    returned more than one order)r2   rE   r  r  r;   fetch_ordersr%  rt  safe_bool_nr:   r  r9   r  )
r[  rE   r  r  r  r(  rj  lengthr  extras
             r]  fetch_order_classiczbybit.fetch_order_classic  s    >#DGG.X$XYYV$&>tww)ZZ[[r
 ""64t{{7F7STVQ;(()V1DeLI#B  *OE3r7 25F F NOOA:tww)HHIIvq))r^  c                    | j                          | j                         \  }}|xs |}|s| j                  |||      S d}| j                  |dd      \  }}|st	        | j
                  dz         | j                  |      }d}	| j                  d||      \  }	}|d   ||	d}
d}| j                  |dd	d      \  }}|rd
|
d<   | j                  | j                  |
|            }| j                  |di       }| j                  |dg       }t        |      dk(  r#|rdnd}t        dt        |      z   dz   |z         | j                  |di       }| j!                  ||      S )a3  
classic accounts only/ spot not supported*  fetches information on an order made by the user *classic accounts only*

        https://bybit-exchange.github.io/docs/v5/order/order-list

        :param str id: the order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param dict [params.acknowledged]: to suppress the warning, set to True
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Fr   acknowledgedz fetchOrder() can only access an order if it is in last 500 orders(of any status) for your account. Set params["acknowledged"] = True to hide self warning. Alternatively, we suggest to use fetchOpenOrder or fetchClosedOrderNrE   )r  r  r  rK  r  r  r  rj  rk  r   r  r  r   r  )r  r  r  r  r2   rE   r  r  handle_param_bool_2privateGetV5OrderRealtimer%  rq  r  rt  r:   r  r{  )r[  rE   r  r  r  r  r/  acknowledger  r  r(  r  ru  rj  	innerListr  r  s                    r]  fetch_orderzbybit.fetch_order  s    	484K4K4M11/G3G++B??";;FLR`aV#DGG  /P  %P  Q  QV$
!00vvN
FTl"

 	 44VYPUV	6%0GM"11$++gv2NOd (B7NN6626	y>Q#B  *OE3r7 25F F NOOy!R0v..r^  c                     | j                         }	 | j                  |d      }|rt        | j                  dz         | j	                  ||||      S )Nr   z fetchOrders() is not supported after the 5/02 update for UTA accounts, please use fetchOpenOrders, fetchClosedOrders or fetchCanceledOrders)r  r}  r;   rE   fetch_orders_classic)r[  r  r  rG  r  resr  s          r]  r  zbybit.fetch_ordersv  sc    %%'	   $~~c15tww  *x   x  y  y((vFFr^  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||dddd	      S i }d}|| j                  |      }|d   |d	<   d}| j	                  d||      \  }}|d
k(  rt        | j                  dz         ||d<   | j                  |ddgd      }	| j                  |ddg      }|	rd|d<   |||d<   |||d<   | j                  |d      }
| j                  |d|
      }| j                  |ddg      }|||d<   | j                  | j                  ||            }| j                  |      }| j                  ||||      S )a  
        fetches information on multiple orders made by the user *classic accounts only*

        https://bybit-exchange.github.io/docs/v5/order/order-list

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: True if trigger order
        :param boolean [params.stop]: alias for trigger
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :param str [params.orderFilter]: 'Order' or 'StopOrder' or 'tpslOrder'
        :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 [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Fr   r  ro  rp  Nr   rE   r  rT   z0 fetchOrders() is not supported for spot marketsr  rK  r  r  r  rG  r  r  r  )r  r  fetch_paginated_call_cursorr  r  r;   rE   r  rc  r  privateGetV5OrderHistoryr%  ry  r  r[  r  r  rG  r  r  r(  r  r  r  r  r  ru  rm  s                 r]  r  zbybit.fetch_orders_classic  s   & 	88PZ[&33M65RWY_aqs{  ~B  DF  G  G[[(F &tGH**=&&If6>tww)[[\\"
$$Vi-@%H	6Iv#67%0GM"$GG#(GK !!&'2##FIu=6Iw#78!(GI00Wf1MNf 33H=  vue<<r^  c           	      `   | j                          d|i}| j                  |dd| j                  ||            }t        |      }|dk(  r8| j	                  |ddgd      }|rdnd}t        d	t        |      z   d
z   |z         |dkD  rt        | j                  dz         | j                  |d      S )a   
        fetches information on a closed order made by the user

        https://bybit-exchange.github.io/docs/v5/order/order-list

        :param str id: order id
        :param str [symbol]: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: set to True for fetching a closed trigger order
        :param boolean [params.stop]: alias for trigger
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :param str [params.orderFilter]: 'Order' or 'StopOrder' or 'tpslOrder'
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  Nr   rK  r  Fr  r  r   r  r   r  )
r  fetch_closed_ordersr%  rt  r  r:   r  r9   rE   r  	r[  rE   r  r  r(  rj  r  r  r  s	            r]  fetch_closed_orderzbybit.fetch_closed_order  s      	r
 ))&$dkk'SY>Z[VQ;(()V1DeLI#B  *OE3r7 25F F NOOA:tww)HHIIvq))r^  c           	      `   | j                          d|i}| j                  |dd| j                  ||            }t        |      }|dk(  r8| j	                  |ddgd      }|rdnd}t        d	t        |      z   d
z   |z         |dkD  rt        | j                  dz         | j                  |d      S )a  
        fetches information on an open order made by the user

        https://bybit-exchange.github.io/docs/v5/order/open-order

        :param str id: order id
        :param str [symbol]: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: set to True for fetching an open trigger order
        :param boolean [params.stop]: alias for trigger
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :param str [params.baseCoin]: Base coin. Supports linear, inverse & option
        :param str [params.settleCoin]: Settle coin. Supports linear, inverse & option
        :param str [params.orderFilter]: 'Order' or 'StopOrder' or 'tpslOrder'
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  Nr   rK  r  Fr  r  r   r  r   r  )
r  fetch_open_ordersr%  rt  r  r:   r  r9   rE   r  r  s	            r]  fetch_open_orderzbybit.fetch_open_order  s    $ 	r
 ''dDKKQW<XYVQ;(()V1DeLI#B  *OE3r7 25F F NOOA:tww)HHIIvq))r^  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||dddd	      S i }d}|| j                  |      }|d   |d	<   d}| j	                  d||      \  }}||d
<   | j                  |ddgd      }	| j                  |ddg      }|	rd|d<   |||d<   |||d<   | j                  |d      }
| j                  |d|
      }| j                  |ddg      }|||d<   | j                  | j                  ||            }| j                  |      }| j                  ||||      S )a  
        fetches information on multiple canceled and closed orders made by the user

        https://bybit-exchange.github.io/docs/v5/order/order-list

        :param str [symbol]: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: set to True for fetching trigger orders
        :param boolean [params.stop]: alias for trigger
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :param str [params.orderFilter]: 'Order' or 'StopOrder' or 'tpslOrder'
        :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)
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Frx   r  ro  rp  Nr   rE   r  r  rK  r  r  r  rG  r  r  r  )r  r  r  r  r  r  rc  r  r  r%  ry  r  r  s                 r]   fetch_canceled_and_closed_ordersz&bybit.fetch_canceled_and_closed_orders0  s   & 	88A_akl&334RTZ\achjp  sC  EM  OS  UW  X  X[[(F &tGH**+I6SYZf"
$$Vi-@%H	6Iv#67%0GM"$GG#(GK !!&'2##FIu=6Iw#78!(GI00Wf1MNf 33H=  vue<<r^  c           	      r    | j                          ddi}| j                  |||| j                  ||            S )a  
        fetches information on multiple closed orders made by the user

        https://bybit-exchange.github.io/docs/v5/order/order-list

        :param str [symbol]: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: set to True for fetching closed trigger orders
        :param boolean [params.stop]: alias for trigger
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :param str [params.orderFilter]: 'Order' or 'StopOrder' or 'tpslOrder'
        :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)
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        rg  rG  r  r  r%  r[  r  r  rG  r  r(  s         r]  r  zbybit.fetch_closed_orders  sB    & 	8
 44VUE4;;W^`fKghhr^  c           	      r    | j                          ddi}| j                  |||| j                  ||            S )a  
        fetches information on multiple canceled orders made by the user

        https://bybit-exchange.github.io/docs/v5/order/order-list

        :param str [symbol]: unified market symbol of the market orders were made in
        :param int [since]: timestamp in ms of the earliest order, default is None
        :param int [limit]: max number of orders to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: True if trigger order
        :param boolean [params.stop]: alias for trigger
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :param str [params.orderFilter]: 'Order' or 'StopOrder' or 'tpslOrder'
        :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)
        :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        rg  rI  r   r!  s         r]  fetch_canceled_orderszbybit.fetch_canceled_orders  sB    & 	;
 44VUE4;;W^`fKghhr^  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||dddd	      S i }d}|| j                  |      }|d   |d	<   d}| j	                  d||      \  }}|d
k(  s|dk(  rK| j                  |d      }	|7|	5| j                  | j                  dd      }
| j                  |d|
      }||d<   ||d<   | j                  |ddd      }| j                  |ddg      }|rd|d<   |||d<   | j                  | j                  ||            }| j                  |      }| j                  ||||      S )a  
        fetch all unfilled currently open orders

        https://bybit-exchange.github.io/docs/v5/order/open-order

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: set to True for fetching open trigger orders
        :param boolean [params.stop]: alias for trigger
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :param str [params.baseCoin]: Base coin. Supports linear, inverse & option
        :param str [params.settleCoin]: Settle coin. Supports linear, inverse & option
        :param str [params.orderFilter]: 'Order' or 'StopOrder' or 'tpslOrder'
        :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 Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Fr   r  ro  rp  Nr   rE   r  r  r  r  r  r  r5  r  r  rK  r  r  rG  )r  r  r  r  r  r  r  r  rc  r  r%  ry  r  )r[  r  r  rG  r  r  r(  r  r  r  r  r5  r  ru  rm  s                  r]  r  zbybit.fetch_open_orders  s   ( 	88ART^_&334EvuV[]ceuw  BF  HJ  K  K[[(F &tGH**+<ffMf8ty0''
;H~("2 $ 0 0PV W!--flMR
(2%"
$$VVYF	6FI#67%0GM"$GG11$++gv2NOd 33H=  vue<<r^  c           	          i }| j                  |dd      }|||d<   n||d<   | j                  |ddg      }| j                  |||| j                  ||            S )a  
        fetch all the trades made from a single order

        https://bybit-exchange.github.io/docs/v5/position/execution

        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        r\  r[  r  )rs  rc  fetch_my_tradesr%  )r[  rE   r  r  rG  r  r(  r\  s           r]  fetch_order_tradeszbybit.fetch_order_trades'  sn     **6?MR$%2GM"!#GI6O]#CD##FE5$++gv:VWWr^  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||dddd	      S dd	i}d}|| j                  |      }|d
   |d<   d}| j	                  d||      \  }}||d<   |||d<   |||d<   | j                  d||      \  }}| j                  | j                  ||            }	| j                  |	      }
| j                  |
|||      S )a  
        fetch all trades made by the user

        https://bybit-exchange.github.io/docs/api-explorer/v5/position/execution

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Fr   r  ro  rp  NrE  execTyper'   rE   r  r  rG  r  r  )
r  r  r  r  r  r  privateGetV5ExecutionListr%  ry  r  )r[  r  r  rG  r  r  r(  r  r  ru  r  s              r]  r&  zbybit.fetch_my_trades=  s@    	88R\]&33OVUTY[acsu}  @D  FI  J  J
 [[(F &tGH**?FFKf"
$GG#(GK 229gvN11$++gv2NOR 55h?  >>r^  r  c                     | j                  |d      }| j                  |d      }| j                  |d      }| j                  |       ||| j                  | j                  |d      |      ||dS )NaddressDeposit
tagDepositr  r  )r  r  r  addresstag)r  check_addressr  )r[  depositAddressr  r.  r/  r  s         r]  parse_deposit_addresszbybit.parse_deposit_address  s~     "">3CD~|<&17#"..t/?/?PW/XZ^_
 	
r^  r  c                    | j                          | j                  |      }d|d   i}d}| j                  |      \  }}|| j                  ||      |d<   | j	                  | j                  ||            }| j                  |di       }| j                  |dg       }| j                  |d      }	| j                  |	      }| j                  ||d   gdd	|d   i      }
| j                  |
d
      S )a  
        fetch a dictionary of addresses for a currency, indexed by network

        https://bybit-exchange.github.io/docs/v5/asset/master-deposit-addr

        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `address structures <https://docs.ccxt.com/#/?id=address-structure>` indexed by the network
        r  rE   N	chainTyperj  r  r  Fr  r  )r  r  handle_network_code_and_paramsnetwork_code_to_id$privateGetV5AssetDepositQueryAddressr%  rq  r  r  parse_deposit_addressesindex_by)r[  r  r  r  r(  r  ru  rj  r  r  parseds              r]  "fetch_deposit_addresses_by_networkz(bybit.fetch_deposit_addresses_by_network  s
    	==&HTN
 "AA&IV"#'#:#:;#MGK <<T[[RX=YZ( (B7"5/==&--fx7G6H%(R
  }}VY//r^  c                     | j                          | j                  |      }| j                  |      \  }}| j                  ||      }| j	                  |d   ||      }||   S )a  
        fetch the deposit address for a currency associated with self account

        https://bybit-exchange.github.io/docs/v5/asset/master-deposit-addr

        :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  r  r5  r;  )select_network_code_from_unified_networks)r[  r  r  r  r  paramsOmitedindexedAddressesselectedNetworkCodes           r]  fetch_deposit_addresszbybit.fetch_deposit_address  so     	==&$($G$G$O!\BB4V"LLXV\M]_jl|} 344r^  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||dddd	      S i }d}|| j                  |      }|d   |d	<   |||d
<   |||d<   | j	                  d||      \  }}| j                  | j                  ||            }| j                  |      }	| j                  |	|||      S )a  
        fetch all deposits made to an account

        https://bybit-exchange.github.io/docs/v5/asset/deposit-record

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for, default = 30 days before the current time
        :param int [limit]: the maximum number of deposits structures to retrieve, default = 50, max = 50
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch deposits for, default = 30 days after since
 EXCHANGE SPECIFIC PARAMETERS
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :param str [params.cursor]: used for pagination
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Fr   r  ro  rp  Nr   rE   r  r  rG  r  )	r  r  r  r  r  #privateGetV5AssetDepositQueryRecordr%  ry  parse_transactions
r[  r  r  rG  r  r  r(  r  ru  rm  s
             r]  fetch_depositszbybit.fetch_deposits  s     	88R\]&33OT5RWY_aqs{  ~B  DF  G  G

 }}T*H&tnGFO#(GK $GG229gvN;;DKKQW<XY8 33H=&&tXueDDr^  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||dddd	      S i }d}|| j                  |      }|d   |d	<   |||d
<   |||d<   | j	                  d||      \  }}| j                  | j                  ||            }| j                  |      }	| j                  |	|||      S )a[  
        fetch all withdrawals made from an account

        https://bybit-exchange.github.io/docs/v5/asset/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]: 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 [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Fr   r  ro  rp  Nr   rE   r  r  rG  r  )	r  r  r  r  r  $privateGetV5AssetWithdrawQueryRecordr%  ry  rD  rE  s
             r]  fetch_withdrawalszbybit.fetch_withdrawals$  s    	88ASU_`&334FeUZ\bdtv~  AE  GI  J  J

 }}T*H&tnGFO#(GK $GG229gvN<<T[[RX=YZT 33H=&&tXueDDr^  c                 F    ddddddddddddd	}| j                  |||      S )
Nr  pending
processingokfailr<  r@  failed)r  r   2r   4SecurityCheckPendingsuccessCancelByUserRejectFailBlockchainConfirmedrN  rO  s      r]  parse_transaction_statuszbybit.parse_transaction_statusr  sF     & & #'
  &&99r^  transactionc                    | j                  |d      }| j                  ||      }| j                  |dd      }| j                  |d      }| j	                  | j                  |d            }| j                  |dd      }d|v rdnd	}	d }
|||d
}
| j                  |d      }i d|d| j                  |dd      d| j                  |d      d|d| j                  |      d| j                  | j                  |d            dd d|dd d| j                  |d      dd dd d|	d| j                  |d      d|d|d||
d d dS ) Nr  
createTime	successAt
updateTimer  
depositFeer  rU  
withdrawalri  	toAddressr  rE   
withdrawIdtxidtxIDr  r  r  r  r.  	addressToaddressFromr/  tagTotagFromr  r  r  updated)r  internalcomment)
r  r  rt  r  rY  rG  rs  rE  r  r  )r[  rZ  r  r  r  r  ri  r  feeCostr  r  ra  s               r]  parse_transactionzbybit.parse_transaction  s   R %%k6:
&&z8<''\;O	##K>..t/?/?X/VW$$[,N)[8y| C $$[+>	
K
$$$[$E
 D$$[&9
 	

 Y/
 t..t/?/?W/UV
 t
 
 4
 4##K7
 T
 t
 D
 d&&{H=
 
  f!
" w#
$ )
 	
r^  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||dddd	      S i }| j                         }d}d}	|d	   r
d
}	|||d<   n|| j	                  |      |d<   || j                  |      }|d   ||	<   |||d<   d}
| j                  dd|      \  }
}d}|d	   rk| j                  | j                  dd      }|
dk(  r'|dk  r"| j                  | j                  ||            }nC| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |      }| j                  ||||      S )a  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

        https://bybit-exchange.github.io/docs/v5/account/transaction-log
        https://bybit-exchange.github.io/docs/v5/account/contract-transaction-log

        :param str [code]: unified currency code, default is None
        :param int [since]: timestamp in ms of the earliest ledger entry, default is None
        :param int [limit]: max number of ledger entries to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param 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.subType]: if inverse will use v5/account/contract-transaction-log
        :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
        Fr   r  ro  rp  Nr   r  r   r  r  
start_daterE   rG  r  r   r  )r  r  r  r  yyyymmddr  r  r  r  )privateGetV5AccountContractTransactionLogr%  !privateGetV5AccountTransactionLogry  parse_ledger)r[  r  r  rG  r  r  r(  enableUnifiedr  currencyKeyr  ru  r  rm  s                 r]  fetch_ledgerzbybit.fetch_ledger  s    	88PZ[&33M4PUW]_oqy{  BD  E  E
& //1$K ',$ (,e(<%}}T*H#+D>GK $GG99-vV"&"3"3DLLBWYZ"[)#)<q)@II$++V]_eJfgAA$++gW]B^_EEdkkRY[aFbcHP 33H=  x>>r^  itemc                    | j                  |dd      }| j                  ||      }| j                  ||      }| j                  |dd      }| j                  |dd      }t        j                  |d      rdnd	}d }d }	d }
|x|v|dk(  r|nt        j
                  |      }| j                  t        j                  ||            }| j                  |      }	| j                  t        j                  |            }
| j                  | j                  |d
            }|| j                  |d      }| j                  || j                  |d      || j                  |d      | j                  |d      d | j                  | j                  |d            ||
|| j                  |      ||	d|| j                  |d      dd|      S )Nr  r  r  rw  wallet_balancecashBalancer  outin	exec_timetransactionTimerE   	wallet_idtx_idr  rM  r  )r  r  )r  rE   	directionr  referenceIdreferenceAccountr  r  r  r  r  beforeafterr  r  )rs  r  safe_currencyr@   	string_lt
string_negparse_to_numericr   
string_absr  r  r  safe_ledger_entryparse_ledger_entry_typerE  r  )r[  rw  r  r  r  r  afterStringr  r  r  r  
differencer  s                r]  parse_ledger_entryzbybit.parse_ledger_entry~  s   J ''fjA
&&z8<%%j(;))$(C((/?O$..|SAEt	"|'?*3u*<7CUCUVbCcJ**7+=+=k:+VWF))+6E**7+=+=l+KLFNN4#3#3D+#FG	))$0ABI%%""4."''k:++D': $001A1A$1OP"Y/ ((u5'
& ' 	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ddd}| j                  |||      S )NDepositrZ  WithdrawRealisedPNLr  
Commissionr  RefundcashbackPrizeprizeExchangeOrderWithdrawExchangeOrderDepositTRANSFER_INTRANSFER_OUTTRADE
SETTLEMENTDELIVERYLIQUIDATIONBONUS
FEE_REFUNDINTEREST)CURRENCY_BUYCURRENCY_SELLrN  )r[  r  r  s      r]  r  zbybit.parse_ledger_entry_type  s    
}

 7
 %	

 j
 W
 $]
 #M
 =
 M
 W
 '
 
 7
  W!
" *#
$ %
& $$)
, tT22r^  r.  c                     | j                  ||      \  }}d}| j                  |ddd      \  }}| j                          | j                  |       | j	                  |      }|d   | j                  |      || j                         |d}|||d<   | j                  |      \  }	}
| j                  |	      }||j                         |d<   | j                  | j                  ||
            }| j                  |d	i       }| j                  ||      S )
a  
        make a withdrawal

        https://bybit-exchange.github.io/docs/v5/asset/withdraw

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr   r  r  rE   )r  r  r.  r  r  r/  r  rj  )handle_withdraw_tag_and_paramsr  r  r0  r  r  rg  r5  r6  upper privatePostV5AssetWithdrawCreater%  rq  rm  )r[  r  r  r.  r/  r  r  r  r(  r  queryr  ru  rj  s                 r]  r   zbybit.withdraw  s     99#vFV";;FJP]_efV7#==&TN++F3**,&
 ? GEN!@@HU++K8	 (0GG88We9TU (B7%%fh77r^  c                    |t        | j                  dz         | j                          | j                  |      }d|d   i}d}d}| j	                  d||      \  }}||d<   | j                  | j                  ||            }| j                  |di       }| j                  |dd	g       }| j                  |d
      }	| j                  |di       }
| j                  |
|      }|	|d<   | j                  |	      |d<   |S )a  
        fetch data on a single open contract trade position

        https://bybit-exchange.github.io/docs/v5/position

        :param str symbol: unified market symbol of the market the position is held in, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Nz+ fetchPosition() requires a symbol argumentr  rE   r   r  rj  rk  rn  r  r   r  r  )r2   rE   r  r  r  privateGetV5PositionListr%  rq  r  r  parse_positionrE  )r[  r  r  r  r(  ru  r  rj  	positionsr  rx  positions               r]  fetch_positionzbybit.fetch_position  s    >#DGG.[$[\\V$fTl
 **?FFKf"
00Wf1MNR (B7$$VVZD	%%h7	y!R0&&uf5 )#||I6r^  c                 D   | j                          d}| j                  |dd      \  }}|r| j                  d|dd|dddd	      S d}|Tt        |t              rDt        |      }|dkD  rt        | j                  d	z         |dk(  r|d
   }| j                  |      }n||}| j                  |      g}i }d}|| j                  |      }|d   }|d   |d<   d}| j                  d||      \  }}|dk(  s|dk(  rZ| j                  |d      }	|dk(  r:|A|	?| j                  | j                  dd      }
| j                  |d|
      }||d<   n	||	d|d<   | j                  |d      d|d<   | j                  |dg      }||d<   | j!                  | j#                  ||            }| j%                  |      }g }t'        d
t        |            D ]A  }||   }d|v rd|v r| j)                  |d      }|j+                  | j-                  |             C | j/                  |d|d      S )a'  
        fetch all open positions

        https://bybit-exchange.github.io/docs/v5/position

        :param str[] symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :param str [params.baseCoin]: Base coin. Supports linear, inverse & option
        :param str [params.settleCoin]: Settle coin. Supports linear, inverse & option
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Fr   r  Nro  rp  r  r   zD fetchPositions() does not accept an array with more than one symbolr   r  rE   r  r  r  r  r  r5  r  rG  r  rm  is_valid)r  r  r  r  rk  rt  r2   rE   r  r  r  r  r  r  r  rc  r  r%  ry  r  rq  r  r  filter_by_array_positions)r[  r  r  r  r  r  r(  r  r  r  r  r5  ru  r  resultsr  rawPositions                    r]  fetch_positionszbybit.fetch_positionsX  s    	88AQS]^&334DgtUY[acsu}  @D  FI  J  JZ%>LMq '2x(xyy!# ))'2G F{{6*+G[[(FH%F &tGH**+;VVLf8ty0''
;Hx>h&6$($4$4T\\?TZ$[M!%!1!1&,!VJ,6GL) >h&6*3GJ'VW-5"GG6F8,"
00Wf1MNH 88B	q#i.) 	=A#A,K+%J+,E"nn[&ANN4..{;<	= --gx%PPr^  r  c                 
   | j                  |d      }|d u}| j                  |d      }| j                  ||d d      }t        j                  | j	                  |dd            }| j                  |d      }||dk(  r|rdnd	}n|d
k(  r|rd	nd}nd }| j	                  |dd      }| j                  | j                  |d            }	| j                  |ddg      }
| j                  |d      }| j                  |ddg      }| j                  | j                  |d            }|| j                  |g d      }| j                  |dd      }d }| j                  d   r| j                  d   r|d   r|s	|dk(  rdnd}| j                  |d      }| j                  | j                  |g d            }| j                  | j                  |d            }| j                  |d      }||d    d!k(  rit        j                  t        j                  ||            }t        j                  t        j                  t        j                  ||      |      |	      }n| j                  |d"      }|d#   rlt        j                  t        j                  ||            }t        j                  ||      }|t        j                  t        j                  ||      |      }
nt        j                  t        j                  ||            }t        j                  ||      }t        j                  t        j                  ||      |      }|*t        j                  |t        j                  ||            }
t        j                  ||      }t        j                  ||d$      }| j                  |d%      }|d uxr |d&k7  }| j                  i d'|d(d d|d   d)|d*| j!                  |      d+|d,| j#                  |
      d-| j#                  t        j                  |
|            d.| j#                  |      d/| j#                  |      d0| j#                  |      d1| j#                  |      d| j#                  |      d2| j#                  |	      d3| j%                  |d4      d5| j#                  |      d6| j%                  |d6      | j#                  |      | j#                  |      | j%                  |d7      | j%                  |d8      | j#                  |      ||d | j'                  |d9d:      | j'                  |d;d<      |d=      S )>N
closedSizer  r  r  ra  r  BuyshortlongSellpositionValuecumExitValueunrealisedPnl
positionIMcumEntryValue
positionMMr^  r_  
updated_at)re  rf  re  	tradeModer   r  r  r   isolatedcrosspositionBalance)
entryPricerj  avgEntryPriceliqPricerA  r  r  	bustPricer  r   r  r  r  rE   r  r  ro  initialMargininitialMarginPercentagemaintenanceMarginmaintenanceMarginPercentager  notionalunrealizedPnlrealizedPnl	closedPnl	contractsr  ry  avgExitPrice	stop_lossrm  take_profitrl  )marginRatioliquidationPricery  r_  
collateralr6  r  rR  r9  r:  r=  )r  r  r@   r  rs  rC  r  r  r  r  r  
string_subr   r~  
string_divsafe_positionrE  r  r  rG  )r[  r  r  r  	isHistoryr  r  r  r  r  initialMarginStringmaintenanceMarginStringr  ro  r  r6  collateralStringr  r  rA  r  r   maintenanceMarginPriceDifferencemultiplyr  r  r  r=  s                               r]  r  zbybit.parse_position  s   P %%h=
t+	##Hh7!!(FD*E!!$"4"4Xvu"MN&1u}"+w!*v%%hPt'7'7/'RS"00L/;Z["&"2"28\"J''=+2NO	"nnT-=-=h-UV&"&"5"5h@k"l%%hQ?	
34$,,G]:^cijsct,5NZ
++H6GH^^D$6$6xAl$mn
>>$*:*:8Z*PQ##Hj9'h6)$//0B0B:O_0`a
#*#5#5g6H6HI[I[\fhlIm  pG  7H  JW  $X  ,,X{C	(#
 8?7I7I'J\J\]moxJy7z4.5.@.@Aacg.h+!-.5.@.@ASASTXZdAego.p+ ")!3!3G4F4FyRb4c!dJ&11)=MNH.5.@.@ASASTXZdAego.p+!-.5.@.@wGYGYZdfnGo.p+&-&8&89PRZ&[#(()@BRTUV&&x?T)Cs0B!! #
H#
$#
 fX&#
 	#

 Y/#
 "#6#
 T../BC#
 &t'8'89K9KL_ai9j'k#
  !2!23J!K#
 *4+<+<=X+Y#
 $++J7#
 ))(3#
 ))(3#
 T..}=#
 4++HkB#
  **40!#
" D,,V^D##
$  ,,[9 $ 1 12B C))(K@))(NC++,<=$!//+zR#11(M<X9#
  	r^  c                     | j                          | j                  |      }| j                  ||      }| j                  ||      S )aV  
        fetch the set leverage for a market

        https://bybit-exchange.github.io/docs/v5/position

        :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  r  r  parse_leverage)r[  r  r  r  r  s        r]  fetch_leveragezbybit.fetch_leverage  sC     	V$&&vv6""8V44r^  rA  c                     | j                  |d      }| j                  |d      }|| j                  ||      | j                  |d      ||dS )Nr  rA  r6  )r  r  r6  longLeverageshortLeverage)r  r  r}  rW  )r[  rA  r  r  leverageValues        r]  r  zbybit.parse_leverage  sY    ##Hh7))(J?&&x800<H)*
 	
r^  r6  c                    | j                          | j                         \  }}|xs |}d}d}|rW|dk(  rd}n(|dk(  rd}n |dk(  rd}nt        | j                  dz         d	|i}	| j	                  | j                  |	|            }|S |t        | j                  d
z         | j                  |      }|d   dk(  }
|
rO|dk(  rd}n |dk(  rd}nt        | j                  dz         d	|i}	| j	                  | j                  |	|            }|S d}| j                  d||      \  }}d}|dk(  rd}n |dk(  rd}nt        | j                  dz         d}d}| j                  |d      }|_| j                  |dd      }| j                  |dd      }||t        | j                  dz         ||}||}| j                  |g d      }n|}|}| j                  |d      }||d   |||d}	| j                  | j                  |	|            }|S )a  
        set margin mode(account) or trade mode(symbol)

        https://bybit-exchange.github.io/docs/v5/account/set-margin-mode
        https://bybit-exchange.github.io/docs/v5/position/cross-isolate

        :param str marginMode: account mode must be either [isolated, cross, portfolio], trade mode must be either [isolated, cross]
        :param str symbol: unified market symbol of the market the position is held in, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.leverage]: the rate of leverage, is required if setting trade mode(symbol)
        :returns dict: response from the exchange
        Nr  ISOLATED_MARGINr  REGULAR_MARGIN	portfolioPORTFOLIO_MARGINzG setMarginMode() marginMode must be either [isolated, cross, portfolio]r   zD setMarginMode() requires a symbol parameter for non unified accountr  r  zM setMarginMode() for usdc market marginMode must be either [cross, portfolio]r   r   r   zH setMarginMode() with symbol marginMode must be either [isolated, cross]rA  sell_leveragesellLeveragebuy_leveragebuyLeveragez[ setMarginMode() requires a leverage parameter or sell_leverage and buy_leverage parameters)r  r  r  r  rE   )r  r  r  r  r  )r  r  r;   rE   !privatePostV5AccountSetMarginModer%  r2   r  r  r  rs  rc  #privatePostV5PositionSwitchIsolated)r[  r6  r  r  r  r  r/  r  ru  r(  isUsdcSettledr  r  r  r  rA  s                   r]  set_margin_modezbybit.set_margin_mode  s    	484K4K4M11/G3GZ'.
w&-
{*/
"477-v#vwwG ==dkk'SY>Z[Hh e ~'2x(xyy[[(F"8,6M(!1J;.!3J&tww  2A  (A  B  B#Z!  AA$++gW]B^_H E #223DffUf 	( !I:- !I&tww1{'{||#"++FJ?##'#5#5fo~#^L"&"4"4V^]"[K#+0C/  ;X  1X  Y  Y"*&2#+'2!YYv/opF#+L"*K!YYvz:F $$Tl!*#.$0!  CCDKKPWY_D`ar^  c                 b   |t        | j                  dz         | j                          | j                  |      }| j	                  |      }|d   ||d}||d<   ||d<   |d   rd|d<   n#|d   rd|d<   nt        | j                  d	z         | j                  | j                  ||            }|S )
a  
        set the level of leverage for a market

        https://bybit-exchange.github.io/docs/v5/position/leverage

        :param float leverage: the rate of leverage
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.buyLeverage]: leverage for buy side
        :param str [params.sellLeverage]: leverage for sell side
        :returns dict: response from the exchange
        z) setLeverage() requires a symbol argumentrE   )r  r  r  r  r  r  r  r  z5 setLeverage() only support linear and inverse market)r2   rE   r  r  r  r;    privatePostV5PositionSetLeverager%  )r[  rA  r  r  r  leverageStringr(  ru  s           r]  set_leveragezbybit.set_leverage  s     >#DGG.Y$YZZV$
 ..x8Tl)*

 "0"0("*GJI"+GJtww)``aa88Wf9UVr^  r=  c                 H   | j                          d}|| j                  |      }d}|rd}nd}d|i}|d|d<   n|d   |d<   ||d	   rd	nd
|d<   nd}| j                  d||      \  }}||d<   | j                  |d      }| j	                  | j                  ||            }|S )ao  
        set hedged to True or False for a market

        https://bybit-exchange.github.io/docs/v5/position/position-mode

        :param bool hedged:
        :param str symbol: used for unified account with inverse market
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        Nr  r   moder  r  rE   r  r  r  r  r   r  )r  r  r  rc  privatePostV5PositionSwitchModer%  )	r[  r=  r  r  r  r  r(  r  ru  s	            r]  set_position_modezbybit.set_position_mode6  s     	[[(FDDD
 >$GFO &tGH.4X.>(IGJD../@&&QLD&"&GJ66*77GV8TU r^  r   c                    | j                          | j                  |      }|d   rdnd}| j                  |d|      }| j                  | j                  d      }	| j                  |	|      }
|
t        | j                  dz   |z   dz         |d   |
|d}|||d	<   | j                  |d
      }| j                  |d
g      }|||d<   |||d<   | j                  | j                  ||            }| j                  |di       }| j                  |      }| j                  |d      }| j                  ||d d      }| j                  ||||      S )Nr  r  r  r,  z+ fetchOpenInterestHistory() cannot use the 
 timeframerE   r  intervalTimer  r  r  r  rG  rj  r  r  )r  r  r  rq  r  r3   rE   r  rc  publicGetV5MarketOpenInterestr%  ry  r  parse_open_interests_history)r[  r  r  r  rG  r  r  r  r  r,  r  r(  r  ru  rj  rm  rE   s                    r]  'fetch_derivatives_open_interest_historyz-bybit.fetch_derivatives_open_interest_historyd  ss   V$$X.(I##FJ@NN4<<=	##Iy9TWW'TTW``cooppTl$ 

 #(GK !!&'26G9-!&GI$GG55dkk'66RS0 (B733H=fh/!!"fdJ?00vueLLr^  c                    | j                          | j                  |      }|d   st        | j                  dz         | j	                  |dd      }| j                  | j                  d      }| j	                  ||      }|t        | j                  dz   |z   dz         |d	   rd	nd
}| j	                  |d|      }|d   ||d}	| j                  | j                  |	|            }
| j                  |
di       }| j	                  |d      }| j                  ||dd      }| j                  |
      }| j                  |d   |      S )a  
        Retrieves the open interest of a derivative trading pair

        https://bybit-exchange.github.io/docs/v5/market/open-interest

        :param str symbol: Unified CCXT market symbol
        :param dict [params]: exchange specific parameters
        :param str [params.interval]: 5m, 15m, 30m, 1h, 4h, 1d
        :param str [params.category]: "linear" or "inverse"
        :returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
        r  z3 fetchOpenInterest() supports contract markets onlyr  r   r,  Nz$ fetchOpenInterest() cannot use the r  r  r  r  rE   r  rj  r  r   )r  r  r3   rE   r  rq  r  r  r%  r  ry  parse_open_interest)r[  r  r  r  r  r,  r  r  r  r(  ru  rj  rE   rm  s                 r]  fetch_open_interestzbybit.fetch_open_interest  sR    	V$j!TWW'\\]]$$VZ>	NN4<<=	##Iy9TWW'MMPYY\hhii$X.(I##FJ@Tl$ 

 55dkk'66RS0 (B7fh/!!"fdJ?33H=''Q88r^  c                    |dk(  rt        | j                  dz         | j                          | j                  |d      }|r0| j	                  |d      }||d<   | j                  d||||dddd		      S | j                  |      }|d
   s|d   rt        | j                  dz   |z         d|d   i}|||d<   | j                  |||||      S )a*  
        Gets the total amount of unsettled contracts. In other words, the total number of contracts held in open positions

        https://bybit-exchange.github.io/docs/v5/market/open-interest

        :param str symbol: Unified market symbol
        :param str timeframe: "5m", 15m, 30m, 1h, 4h, 1d
        :param int [since]: Not used by Bybit
        :param int [limit]: The number of open interest structures to return. Max 200, default 50
        :param dict [params]: Exchange specific parameters
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns: An array of open interest structures
        r   z5 fetchOpenInterestHistory cannot use the 1m timeframer  r  r   ro  rp  Nr  rT   rX   z; fetchOpenInterestHistory() symbol does not support market r  rE   rG  )r3   rE   r  r}  rc  r  r  r  )	r[  r  r  r  rG  r  r  r  r(  s	            r]  fetch_open_interest_historyz!bybit.fetch_open_interest_history  s
    TWW'^^__>>&*5YYvz2F"+F;334NPVX]_dfln~  AI  KO  QT  U  UV$&>VH-TWW'ddgmmnnfTl
 $GG;;FIuV[]cddr^  c           	          | j                  |d      }| j                  |dd      }|d   r|nd }|d   r|nd }| j                  |d   |||| j                  |      |d|      S )Nr  open_interestopenInterestr  r  r  )r  openInterestAmountr^  r  r  r  )r  rG  safe_open_interestrE  )r[  r  r  r  r  r  values          r]  r  zbybit.parse_open_interest  s     %%h<	))(O^T!'!1t &y 1t&&X&"(!&"Y/(
  	r^  c                    | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |d      }| j                  |di       }||d<   | j                  ||      S )a  
        fetch the rate of interest to borrow a currency for margin trading

        https://bybit-exchange.github.io/docs/zh-TW/v5/spot-margin-normal/interest-quota

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `borrow rate structure <https://docs.ccxt.com/#/?id=borrow-rate-structure>`
        r  rE   r  rj  r  )r  r  (privateGetV5SpotCrossMarginTradeLoanInfor%  r  rq  parse_borrow_rate)r[  r  r  r  r(  ru  r  rm  s           r]  fetch_cross_borrow_ratezbybit.fetch_cross_borrow_rate  s     	==&HTN
 @@WV\A]^ %%h7	~~h"5%[%%dH55r^  c                     | j                  |d      }| j                  |dd      }| j                  |d      }|dnd}| j                  ||      | j                  |d|      ||| j	                  |      |dS )	Nr  r  r  hourlyBorrowRatei6 i \&r  )r  r  periodr  r  r  )r  rs  r  r  rE  )r[  r  r  r  r  r  r  s          r]  r  zbybit.parse_borrow_rate*  s    $ %%dK8	''fjA
++D2DE-9//
HE$$T>;KL"Y/
 	
r^  c                     | j                          i }| j                  | j                  ||            }| j                  |di       }| j	                  |dg       }	| j                  |	d      }
| j                  |
|||      S )a  
        fetch the interest owed by the user for borrowing currency for margin trading

        https://bybit-exchange.github.io/docs/zh-TW/v5/spot-margin-normal/account-info

        :param str code: unified currency code
        :param str symbol: unified market symbol when fetch interest in isolated markets
        :param number [since]: the earliest time in ms to fetch borrrow interest for
        :param number [limit]: the maximum number of structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `borrow interest structures <https://docs.ccxt.com/#/?id=borrow-interest-structure>`
        rj  r
  N)r  r,  r%  rq  r  parse_borrow_interestsfilter_by_currency_since_limit)r[  r  r  r  rG  r  r(  ru  rm  rl  r  s              r]  fetch_borrow_interestzbybit.fetch_borrow_interestI  s     	??GU[@\]4 ~~h"5~~d$5r:..tT:228T5%PPr^  c                    | j                          | j                  |      }d|d   i}|| j                         dz
  }||d<   | j                  |dd      }| j	                  |dg      }||dz   }||d<   | j                  | j                  ||            }| j                  |d      }	| j                  |	dg       }
| j                  |
|||      S )	a  
        retrieves a history of a currencies borrow interest rate at specific time slots

        https://bybit-exchange.github.io/docs/v5/spot-margin-uta/historical-interest

        :param str code: unified currency code
        :param int [since]: timestamp for the earliest borrow rate
        :param int [limit]: the maximum number of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>` 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[]: an array of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>`
        r  rE   l    H4 r  r  r  rj  rk  )
r  r  rg  rt  rc  .privateGetV5SpotMarginTradeInterestRateHistoryr%  rq  r  parse_borrow_rate_history)r[  r  r  rG  r  r  r(  r  ru  rm  rl  s              r]  fetch_borrow_rate_historyzbybit.fetch_borrow_rate_historyw  s     	==&
 =%%'-7E$%%fgyA6G9-?m+G$	FFt{{SZ\bGcd& ~~h1~~dFB/--dD%GGr^  r  c           
          |d | j                  | j                  |d            | j                  |d      d | j                  |d      dd d d	S )Nr  r  r  r  )	r  r  r  r  r  amountBorrowedr6  r  r  )r  r  r  )r[  r  r  s      r]  parse_borrow_interestzbybit.parse_borrow_interest  s[     //0@0@y0QR((z: "..tV<!

 
	
r^  fromAccount	toAccountc           
         | j                          | j                  |d| j                               }| j                  | j                  di       }| j                  |||      }| j                  |||      }	| j                  |      }
| j                  ||      }|||	|
d   |d}| j                  | j                  ||            }| j                  |d      }| j                  |di       }| j                  |ddg      }| j                  |      }| j                  | j                  ||
      || j                  |      | j                  |      |||d	      S )
at  
        transfer currency internally between wallets on the same account

        https://bybit-exchange.github.io/docs/v5/asset/create-inter-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.transferId]: UUID, which is unique across the platform
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        
transferIdr&  rE   )r'  fromAccountTypetoAccountTyper  r  r  rj  r  retMsg)r  r  r  r$  r%  r  )r  r  uuidrq  r  r  currency_to_precision'privatePostV5AssetTransferInterTransferr%  r  r  parse_transfer_statusparse_transferrE  r  )r[  r  r  r$  r%  r  r'  r3  fromIdtoIdr  amountToPrecisionr(  ru  r  r   	statusRawr  s                     r]  r   zbybit.transfer  s\    	%%flDIIKH
~~dll4DbI!!,[IiC==& 66tVD$%!TN'
 ??GU[@\] %%h7	>>(Hb9&&x)X1FG	++I6{{4..xB"Y/''(9:&"E
  	r^  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||dddd	      S d}i }|| j                  |      }|d   |d	<   |||d
<   |||d<   | j	                  d||      \  }}| j                  | j                  ||            }| j                  |      }	| j                  |	|||      S )a~  
        fetch a history of internal transfers made on an account

        https://bybit-exchange.github.io/docs/v5/asset/inter-transfer-list

        :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 transfer 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
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
        Fr   r  ro  rp  Nr   rE   r  r  rG  r  )	r  r  r  r  r  /privateGetV5AssetTransferQueryInterTransferListr%  ry  parse_transfers)
r[  r  r  rG  r  r  r  r(  ru  rm  s
             r]  fetch_transferszbybit.fetch_transfers  s    	88AQS]^&334DdESXZ`brt|  C  EG  H  H))$/H&tnGFO#(GK $GG229gvNGGT[]cHde. 33H=##D(E5AAr^  c                 *   | j                          | j                  |      }|d   | j                  ||      d}| j                  | j	                  ||            }| j                  |di       }| j                  ||      }| j	                  |d|d      S )a  
        create a loan to borrow margin

        https://bybit-exchange.github.io/docs/v5/spot-margin-normal/borrow

        :param str code: unified currency code of the currency to borrow
        :param float amount: the amount to borrow
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        rE   r  ra  rj  Nr  r  )r  r  r,  %privatePostV5SpotCrossMarginTradeLoanr%  rq  parse_margin_loan	r[  r  r  r  r  r(  ru  rj  rZ  s	            r]  borrow_cross_marginzbybit.borrow_cross_margin+  s     	==&TN--dF;
 ==dkk'SY>Z[ (B7,,VX>{{;)
  	r^  c                 (   | j                          | j                  |      }|d   | j                  |      d}| j                  | j	                  ||            }| j                  |di       }| j                  ||      }| j	                  |d|d      S )a  
        repay borrowed margin and interest

        https://bybit-exchange.github.io/docs/v5/spot-margin-normal/repay

        :param str code: unified currency code of the currency to repay
        :param float amount: the amount to repay
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        rE   r9  rj  Nr:  )r  r  r  &privatePostV5SpotCrossMarginTradeRepayr%  rq  r<  r=  s	            r]  repay_cross_marginzbybit.repay_cross_marginO  s     	==&TN((0
 >>t{{7TZ?[\ (B7,,VX>{{;)
  	r^  c                 X    | j                  |dd      | j                  |d      d d d d |dS )N
transactIdrepayIdr  )rE   r  r  r  r  r  r  )rs  r  )r[  r  r  s      r]  r<  zbybit.parse_margin_loans  s?     $$T<C((6:
 	
r^  c                 4    dddd}| j                  |||      S )NrM  )r  OKSUCCESSrN  rO  s      r]  r.  zbybit.parse_transfer_status  s)    

 &&99r^  r   c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  | j                  di       }| j                  |||      }| j                  |||      }	|| j                  |d      || j	                  |      | j                  ||      | j                  |d      ||	| j                  | j                  |d            d		S )
Nr  r  r(  r)  r'  r'  r  r  )	r  rE   r  r  r  r  r$  r%  r  )r  r  rq  r  rE  r  r  r.  )
r[  r   r  r  r  fromAccountIdtoAccountId
accountIdsr$  r%  s
             r]  r/  zbybit.parse_transfer  s    ( %%h7
%%h<	((3DE&&xA^^DLL."E
&&z=-P$$ZkJ	""8\:"Y///
HE&&x:&"001A1A(H1UV

 
	
r^  c                 *   | j                          | j                  |      }d|d   i}|d   rd|d<   n
|d   rd|d<   | j                  | j                  ||            }| j	                  |d      }| j                  |d      }| j                  ||      S )Nr  rE   r  r  r  rj  rk  )r  r  publicGetV5MarketRiskLimitr%  rq  r  parse_market_leverage_tiers)r[  r  r  r  r(  ru  rj  tierss           r]  'fetch_derivatives_market_leverage_tiersz-bybit.fetch_derivatives_market_leverage_tiers  s    V$fTl
 ("*GJI"+GJ224;;w3OP0 (3vv.//v>>r^  c                     | j                          i }d}| j                  |      }|d   s|d   rt        | j                  dz   |z         |d   |d<   | j	                  ||      S )a  
        retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes for a single market

        https://bybit-exchange.github.io/docs/v5/market/risk-limit

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `leverage tiers structure <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`
        NrT   rX   z; fetchMarketLeverageTiers() symbol does not support market rE   r  )r  r  r3   rE   rP  )r[  r  r  r(  r  s        r]  fetch_market_leverage_tiersz!bybit.fetch_market_leverage_tiers  sr     	V$&>VH-TWW'ddgmmnn"4L;;FFKKr^  r  c                     | j                  |d      }||d   nd}| j                  ||d |      }||| j                  |d      | j                  |d      d d dS )Nr  r  r  makerFeeRatetakerFeeRate)r  r  rT  rS  rR  rQ  r  r}  r  )r[  r  r  r  r  r  s         r]  parse_trading_feezbybit.parse_trading_fee  sr     ##C2)/);fVn*!!(FD+F%%c>:%%c>:
 	
r^  c                 l   | j                          | j                  |      }d|d   i}d}|d   rd}n|d   rd}n
|d   rd}nd}||d<   | j                  | j                  ||            }| j	                  |d	i       }| j                  |d
g       }| j	                  |di       }	| j                  |	|      S )aT  
        fetch the trading fees for a market

        https://bybit-exchange.github.io/docs/v5/account/fee-rate

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        r  rE   Nr  r  rT   rX   r  rj  rk  r   )r  r  privateGetV5AccountFeeRater%  rq  r  rW  )
r[  r  r  r  r(  r  ru  rj  r   rx  s
             r]  fetch_trading_feezbybit.fetch_trading_fee  s     	V$fTl
 (HI HF^HH&
224;;w3OP$ (B7~~ffb1tQ+%%eV44r^  c                 t   | j                          d}| j                  |ddd      \  }}|dk(  rt        | j                  dz         | j	                  |      }| j                  |di       }| j                  |dg       }i }t        d	t        |            D ]   }| j                  ||         }|d
   }|||<   " |S )a  
        fetch the trading fees for multiple markets

        https://bybit-exchange.github.io/docs/v5/account/fee-rate

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        Nr   r  rW   rT   z4 fetchTradingFees() is not supported for spot marketrj  rk  r   r  )
r  r  r;   rE   rY  rq  r  r  rt  rW  )	r[  r  r  ru  r   rj  r  r  r  s	            r]  fetch_trading_feeszbybit.fetch_trading_fees7  s     	44V=OQWYabf6>tww)__``226:$ ~~h"5~~dFB/q#d)$ 	!A((a1C]F F6N	! r^  c                    | j                  |dg       }t        |      }|d d dd d di d}|dk7  rt        d|      D ]  }||   }| j                  |d      }| j                  |d      }	| j	                  ||	      }
d d d| j                  |d      ddd	|d
   |
<   |dk(  se| j                  |d      |d   d<   d|d   d<    |S )Nr  )r  rR  )r  r   rU  r(  r   r  r  r  F)rU  r   r(  r   r   r  rR  )r  rt  r  r  r  r  )r[  r  r  r  chainsLengthrj  r  r  r  currencyCoder  s              r]  parse_deposit_withdraw_feez bybit.parse_deposit_withdraw_feea  s   * Xr26{"
 " 
 11l+ =q	 ,,UG<	#//&A"55iN'+4@(,(8(8(N^c d3z";/  1$040@0@0VF:&u-7<F:&|4= r^  r  c                     | j                          | j                          | j                  |      }| j                  |di       }| j	                  |dg       }| j                  ||d      S )ab  
        fetch deposit and withdraw fees

        https://bybit-exchange.github.io/docs/v5/asset/coin-info

        :param str[] 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>`
        rj  rl  r  )r  r  r  rq  r  parse_deposit_withdraw_fees)r[  r  r  ru  rm  rl  s         r]  fetch_deposit_withdraw_feesz!bybit.fetch_deposit_withdraw_fees  sg     	'')66v>> ~~h"5~~dFB///eVDDr^  c                    | j                          i }d}|| j                  |      }|d   |d<   d}| j                  d||      \  }}|dk(  rt        | j                  dz         ||d<   |||d<   | j                  | j                  ||            }| j                  |d	i       }	| j                  |	d
g       }
| j                  |
|      }| j                  |d      }| j                  ||d   ||      S )a1  
        fetches historical settlement records

        https://bybit-exchange.github.io/docs/v5/market/delivery-price

        :param str symbol: unified market symbol of the settlement history
        :param int [since]: timestamp in ms
        :param int [limit]: number of records
        :param dict [params]: exchange specific params
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :returns dict[]: a list of [settlement history objects]
        NrE   r  r   rT   z: fetchSettlementHistory() is not supported for spot marketr  rG  rj  rk  r  )r  r  r  r;   rE   publicGetV5MarketDeliveryPricer%  rq  r  parse_settlementsr  r  r[  r  r  rG  r  r(  r  r  ru  rj  rm  settlementsr  s                r]  fetch_settlement_historyzbybit.fetch_settlement_history  s    	[[(F &tGH**+CVVTf6>tww)eeff"
$GG66t{{7F7ST( (B7~~ffb1,,T6:k;7009I5RWXXr^  c                    | j                          i }d}|| j                  |      }|d   |d<   d}| j                  d||      \  }}|dk(  s|dk(  rt        | j                  dz         d|d	<   |||d
<   | j                  | j                  ||            }| j                  |di       }	| j                  |	dg       }
| j                  |
|      }| j                  |d      }| j                  ||d   ||      S )a6  
        fetches historical settlement records of the user

        https://bybit-exchange.github.io/docs/v5/asset/delivery

        :param str symbol: unified market symbol of the settlement history
        :param int [since]: timestamp in ms
        :param int [limit]: number of records
        :param dict [params]: exchange specific params
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :returns dict[]: a list of [settlement history objects]
        NrE   r  r   rT   r  z< fetchMySettlementHistory() is not supported for spot marketr  r  rG  rj  rk  r  )r  r  r  r;   rE   privateGetV5AssetDeliveryRecordr%  rq  r  rf  r  r  rg  s                r]  fetch_my_settlement_historyz!bybit.fetch_my_settlement_history  s    	[[(F &tGH**+EvvVf6>TY.tww)gghh&
$GG77GV8TU2 (B7~~ffb1,,T6:k;7009I5RWXXr^  c                     | j                  |d      }| j                  |d      }|| j                  ||      | j                  |d      || j	                  |      dS )Nr8  r  deliveryPrice)r  r  r1  r  r  )r  r  r}  r  rE  )r[  
settlementr  r  r  s        r]  parse_settlementzbybit.parse_settlement1  sd    . %%j.A	##J9&&x8%%j/B"Y/
 	
r^  c                     g }t        dt        |            D ]&  }|j                  | j                  ||   |             ( |S )Nr   )r  rt  r  rp  )r[  rh  r  rj  r  s        r]  rf  zbybit.parse_settlementsR  sH    6 q#k*+ 	IAMM$//AGH	Ir^  c                     | j                          | j                  |      }d|d   d}| j                  | j                  ||            }| j	                  |dg       }| j                  |      S )a  
        fetch the historical volatility of an option market based on an underlying asset

        https://bybit-exchange.github.io/docs/v5/market/iv

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.period]: the period in days to fetch the volatility for: 7,14,21,30,60,90,180,270
        :returns dict[]: a list of `volatility history objects <https://docs.ccxt.com/#/?id=volatility-structure>`
        rX   rE   r  r  rj  )r  r  %publicGetV5MarketHistoricalVolatilityr%  r  parse_volatility_history)r[  r  r  r  r(  ru  
volatilitys          r]  fetch_volatility_historyzbybit.fetch_volatility_historyr  sr     	==&  
 ==dkk'SY>Z[ ^^Hh;
,,Z88r^  c           
          g }t        dt        |            D ]N  }||   }| j                  |d      }|j                  ||| j	                  |      | j                  |d      d       P |S )Nr   r  r  )r  r  r  rv  )r  rt  r  r  rE  r  )r[  rv  rj  r  r  r  s         r]  ru  zbybit.parse_volatility_history  sx     q#j/* 	AqME))%8IMM"& LL3"..ug>	 	 r^  c                 x   | j                          | j                  |      }|d   dd}| j                  | j                  ||            }| j	                  |d      }| j                  |di       }| j                  |dg       }| j                  |d   |      }	| j                  |	|| j                  |      d      S )	a  
        fetches an option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract

        https://bybit-exchange.github.io/docs/api-explorer/v5/market/tickers

        :param str symbol: unified symbol of the market to fetch greeks for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `greeks structure <https://docs.ccxt.com/#/?id=greeks-structure>`
        rE   rX   )r  r  r  rj  rk  r   )r  r  )	r  r  r  r%  r  rq  r  parse_greeksrE  )
r[  r  r  r  r(  ru  r  rj  rm  greekss
             r]  fetch_greekszbybit.fetch_greeks  s     	V$Tl 
 00Wf1MNR %%h7	(B7~~ffb1""47F3{{6"Y/$
  	r^  r{  c                 ~   | j                  |d      }| j                  ||      }i d|dd dd d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      dd d	| j                  |d
      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      | j                  |d      |dS )Nr  r  r  deltagammathetavegarhorm  rn  rq  rr  bidImpliedVolatilitybid1IvaskImpliedVolatilityask1IvmarkImpliedVolatilitymarkIvbidPricere  askPricerf  ry  r_  underlyingPrice)r  r  rV  )r[  r{  r  r  r  s        r]  rz  zbybit.parse_greeks  s   < ##FH5!!(F3
f

 
 T%%fg6	

 T%%fg6
 T%%fg6
 D$$VV4
 4
 t''
;
 t''
;
 #D$4$4VX$F
 #D$4$4VX$F
 $T%5%5fh%G
 ((=
 ((=
  ))&+>!
" ))&+>#
$  $//8IJ'
 	
r^  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||dddd	      S dd	i}d}|| j                  |      }|d
   |d<   d}| j	                  d||      \  }}||d<   |||d<   |||d<   | j                  d||      \  }}| j                  | j                  ||            }	| j                  |	      }
| j                  |
|||      S )a  
        retrieves the users liquidated positions

        https://bybit-exchange.github.io/docs/api-explorer/v5/position/execution

        :param str [symbol]: unified CCXT market symbol
        :param int [since]: the earliest time in ms to fetch liquidations for
        :param int [limit]: the maximum number of liquidation structures to retrieve
        :param dict [params]: exchange specific parameters for the exchange API endpoint
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :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  ro  rp  NrE  r)  	BustTraderE   r  r  rG  r  r  )
r  r  r  r  r  r  r*  r%  ry  parse_liquidations)r[  r  r  rG  r  r  r(  r  r  ru  liquidationss              r]  fetch_my_liquidationszbybit.fetch_my_liquidations!  sH    	88AVXbc&334I6SXZ_agiy  |D  FJ  LO  P  P
 [[(F &tGH**+@&&Qf"
$GG#(GK 229gvN11$++gv2NOR ;;HE&&|VUEJJr^  c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }t        j                  ||      }t        j                  ||      }	| j	                  || j                  ||d d      | j                  |      | j                  |      | j                  |      | j                  |      | j                  |	      || j                  |      d	      S )Nr  r  r  r  r  r  )	r  r  r  r  r1  	baseValue
quoteValuer  r  )r  r  r@   r~  safe_liquidationr}  r  rE  )
r[  liquidationr  r  r  contractsStringcontractSizeStringr  baseValueStringquoteValueStrings
             r]  parse_liquidationzbybit.parse_liquidationp  s   : ##K:%%k:>	**;	B!--fnE&&{K@!,,_>PQ"--o{K$$&&xzJ**?; --.@A&&{3**?;++,<="Y/
&
 
 
	r^  c                    | j                          d }|| j                  |      }d}| j                  |dd      \  }}|r| j                  d|d d |ddd d	      S d }| j	                  d||d      \  }}d|i}| j                  | j                  ||            }| j                  |      }| j                  |d	      }	t        |      }
|
d
z
  }| j                  ||      }| j                  |	d      }d|i|d<   |||<   |S )NFgetLeverageTiersPaginatedr  ro  rp  rE  r  r  r   r   r  )r  r  r  r  r  rM  r%  ry  rq  rt  r  )r[  r  r  r  r  r  r(  ru  rj  rx  r  	lastIndexr-  cursorValues                 r]  get_leverage_tiers_paginatedz"bybit.get_leverage_tiers_paginated  sH   [[(F88A\^hi&334OQWY]_cekm}  @H  JN  PS  T  T99:UW]_egop
 224;;w3OP55h?vq)FAI	~~fi0&&u.>?k
V !yr^  c                 ,   | j                          d}d}|6| j                  |d         }|d   rt        | j                  dz         |d   }| j	                  || j                  ddd|            }| j                  |      }| j                  ||d      S )	a  
        retrieve information on the maximum leverage, for different trade sizes

        https://bybit-exchange.github.io/docs/v5/market/risk-limit

        :param str[] [symbols]: a list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: market subType, ['linear', 'inverse'], default is 'linear'
        :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 dictionary of `leverage tiers structures <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`, indexed by market symbols
        Nr   rT   z6 fetchLeverageTiers() is not supported for spot marketr  Tr   )r  paginationCalls)r  r  r;   rE   r  r%  r  parse_leverage_tiers)r[  r  r  r  r  rm  s         r]  fetch_leverage_tierszbybit.fetch_leverage_tiers  s     	[[,Ff~"477-e#effH%F00RVkmEnpv9wx%%g.((wAAr^  c                    i }| j                  |      }| j                  |||d      }| j                  ||      }t        |j	                               }t        dt        |            D ]  }	||	   }
||
   }t        dt        |            D ]  }| j                  ||   d      }|||   d<   ! | j                  |
d d d      }|d   }| j                  | j                  |d      |      ||<    |S )NFr   rE   r  r  )
market_idsfilter_by_arraygroup_byrk  keysr  rt  r  r  rN  r  )r[  ru  r  marketIdKeyrO  	marketIdsfilteredResultsgroupedr  r  r  r  r  rE   r  r  s                   r]  r  zbybit.parse_leverage_tiers  s    OOG,	..xiQVW--=GLLN#q#d)$ 	`AAwHH%E1c%j) $&&uQx6!#a$ %%hdJGFH%F <<T\\%QU=VX^_E&M	` r^  c                    g }t        dt        |            D ]  }||   }| j                  |d      }| j                  |      }| j	                  d      }|dk7  r| j                  ||dz
     d      }|j                  | j                  |d      | j                  ||      |d   || j                  |d      | j                  |d      | j                  |d	      |d
        |S )Nr   r  r  r   riskLimitValuerE   r  r  r>  )tierr  r  minNotionalmaxNotionalmaintenanceMarginRater>  r  )	r  rt  r  r  r  r  r  r  r}  )r[  r  r  rO  r  r  r  r  s           r]  rN  z!bybit.parse_market_leverage_tiers  s     q#d)$ 	A7D''h7H%%h/F++C0KAv"..tAE{<LMLL))$5**8V<"8,*#//6FG)-)9)9$@S)T#//mD	 		" r^  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||dddd	      S dd	i}d}|| j                  |      }|d
   |d<   d}| j	                  d||      \  }}||d<   ||d
   |d<   |||d<   |||d<   nd|d<   | j                  d||      \  }}| j                  | j                  ||            }	| j                  |	      }
| j                  |
|||      S )a>  
        fetch the history of funding payments paid and received on self account

        https://bybit-exchange.github.io/docs/api-explorer/v5/position/execution

        :param str [symbol]: unified market symbol
        :param int [since]: the earliest time in ms to fetch funding history for
        :param int [limit]: the maximum number of funding history structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
        Fr   r  ro  rp  NrE  r)  FundingrE   r  r  r  r  r  )
r  r  r  r  r  r  r*  r%  ry  parse_incomes)r[  r  r  rG  r  r  r(  r  r  ru  fundingss              r]  fetch_funding_historyzbybit.fetch_funding_history  sa    	88AVXbc&334I6SXZ_agiy  |D  FJ  LO  P  P	
 [[(F &tGH**+@&&Qf"
 &tGH#(GK #GFO!GFO229gvN11$++gv2NO77A!!(FE5AAr^  c                 B   | j                  |d      }| j                  ||d d      }d}|d   r|d   }| j                  |d      }|| j                  ||dd      ||| j	                  |      | j                  |d	      | j                  |d
      | j                  |d      dS )Nr  r  r  r  r  r  r  rV   r  r  r  )r  r  r  r  r  rE   r  r  )r  r  r  r}  rE  r  )r[  incomer  r  r  r  s         r]  parse_incomezbybit.parse_income<  s    F ##FH5!!(FD*E)'?D%%fj9	&&xfE"Y/""684&&vy9$$VY7	
 		
r^  c                 .   | j                          | j                  |      }d|d   d}| j                  | j                  ||            }| j	                  |di       }| j                  |dg       }| j	                  |di       }| j                  |d|      S )a  
        fetches option data that is commonly found in an option chain

        https://bybit-exchange.github.io/docs/v5/market/tickers

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `option chain structure <https://docs.ccxt.com/#/?id=option-chain-structure>`
        rX   rE   )r  r  rj  rk  r   N)r  r  r  r%  rq  r  parse_option)	r[  r  r  r  r(  ru  rj  r  r  s	            r]  fetch_optionzbybit.fetch_optionp  s     	V$ Tl
 00Wf1MNR (B7^^FFB7
z1b1  f55r^  c                    | j                          | j                  |      }d|d   d}| j                  | j                  ||            }| j	                  |di       }| j                  |dg       }| j                  |dd      S )a  
        fetches data for an underlying asset that is commonly found in an option chain

        https://bybit-exchange.github.io/docs/v5/market/tickers

        :param str code: base currency to fetch an option chain for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `option chain structures <https://docs.ccxt.com/#/?id=option-chain-structure>`
        rX   rE   rs  rj  rk  Nr  )r  r  r  r%  rq  r  parse_option_chain)r[  r  r  r  r(  ru  rj  r  s           r]  fetch_option_chainzbybit.fetch_option_chain  s     	==&  
 00Wf1MNR (B7^^FFB7
&&z4BBr^  r  c                    | j                  |d      }| j                  ||      }i d|dd d|d   dd dd d| j                  |d      d| j                  |d      d	| j                  |d
      d| j                  |d      dd d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      dd d| j                  |d      dd S )Nr  r  r  r  r  impliedVolatilityr  r  r  re  r  rf  midPricery  r_  r  rw  	change24hrR  r{  totalVolumer|  )r  r  r  )r[  r  r  r  r  s        r]  r  zbybit.parse_option  su   < ##E84!!(F3
E

 fX&
 	

 
  !1!1%!B
 D,,UNC
 ((<
 ((<
 
 ))%=
 ))%=
 t//7HI
 d&&uk:
 $
  $**5-@!
" 4#
 	
r^  c                    | j                          d}d}d}|$t        |      }|dkD  r| j                  |d         }| j                  |d      }| j	                  d||d      \  }}| j                  |d      }d|i}	||dk(  r|d   |	d	<   |||	d
<   |||	d<   |||	d<   | j                  | j                  |	|            }
| j                  |
d      }| j                  |d      }| j                  |||      }| j                  |||      S )a  
        fetches historical positions

        https://bybit-exchange.github.io/docs/v5/position/close-pnl

        :param str[] symbols: a list of unified market symbols
        :param int [since]: timestamp in ms of the earliest position to fetch, params["until"] - since <= 7 days
        :param int [limit]: the maximum amount of records to fetch, default=50, max=100
        :param dict params: extra parameters specific to the exchange api endpoint
        :param int [params.until]: timestamp in ms of the latest position to fetch, params["until"] - since <= 7 days
        :param str [params.subType]: 'linear' or 'inverse'
        :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
        Nr   r  r   r  r  r   rE   r  r  rG  r  rj  rk  )r  rt  r  r  r  rc  privateGetV5PositionClosedPnlr%  rq  r  parse_positionsfilter_by_since_limit)r[  r  r  rG  r  r  r  r  r  r(  ru  rj  rawPositionsr  s                 r]  fetch_positions_historyzbybit.fetch_positions_history   sH    	LMq WQZ0!!&'299:QSY[ackl67+
 mq&8 &tGH#(GK $GG!&GI55dkk'66RSD (3~~ff5((wG	)))UEBBr^  c                    | j                          d}| j                         \  }}|xs |}|rdnd}| j                  |dd|      \  }}d|i}| j                  | j	                  ||            }i }	| j                  |di       }
| j                  |
dg       }t        dt        |            D ]  }||   }| j                  |d	      }| j                  |d
      }| j                  |d      }|xs |}| j                  |      }|||d| j                  |d      | j                  |d      | d| j                  |d      dd| j                  |d      | j                  |d      dddddddddd|	|<    |	S )a  
        fetches all available currencies that can be converted

        https://bybit-exchange.github.io/docs/v5/asset/convert/convert-coin-list

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.accountType]: eb_convert_uta, eb_convert_spot, eb_convert_funding, eb_convert_inverse, or eb_convert_contract
        :returns dict: an associative dictionary of currencies
        Neb_convert_utaeb_convert_spotr|   r  rj  r#  r   r  disableFrom	disableTocoinTypefullNamer  singleFromMinLimitsingleFromMaxLimitr  r  )r  rE   r  r(  r  rF   r  rU  r   r  r  r  r#  )r  r  r  &privateGetV5AssetExchangeQueryCoinListr%  rq  r  r  rt  r  r}  r  r  )r[  r  r  r  r  r/  accountTypeDefaultr(  ru  rj  rm  r#  r  r  rE   r  r  inactiver  s                      r]  fetch_convert_currencieszbybit.fetch_convert_currenciesj   s    	484K4K4M11/G3G1A-GX";;FD\^km  AV;
 >>t{{7TZ?[\D ~~h"5tWb1q#e*% "	A!HE!!%0B..>Kuk:I#0yH**2.D ((
;((
;&, ,,UI>!  $//7KL#//7KL
  $#!
  $#   5F4L"	F r^  fromCodetoCodec                    | j                          d}| j                         \  }}|xs |}|rdnd}	| j                  |dd|	      \  }}||| j                  |      ||d}
| j	                  | j                  |
|            }| j                  |di       }| j                  |d|      }| j                  |      }| j                  |d	|      }| j                  |      }| j                  |||      S )
a  
        fetch a quote for converting from one currency to another

        https://bybit-exchange.github.io/docs/v5/asset/convert/apply-quote

        :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.accountType]: eb_convert_uta, eb_convert_spot, eb_convert_funding, eb_convert_inverse, or eb_convert_contract
        :returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
        Nr  r  r}   r  )fromCointoCoinrequestAmountrequestCoinr  rj  r  r  )
r  r  r  r  $privatePostV5AssetExchangeQuoteApplyr%  rq  r  r  parse_conversion)r[  r  r  r  r  r  r  r  r/  r  r(  ru  rm  fromCurrencyIdfromCurrencytoCurrencyId
toCurrencys                    r]  fetch_convert_quotezbybit.fetch_convert_quote   s    	484K4K4M11/G3G1A-GX";;FDWYfhz{V !226:#&
 <<T[[RX=YZ* ~~h"5))$
HE}}^4''h?]]<0
$$T<DDr^  c                     | j                          d|i}| j                  | j                  ||            }| j                  |di       }| j	                  |      S )as  
        convert from one currency to another

        https://bybit-exchange.github.io/docs/v5/asset/convert/confirm-quote

        :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
        :returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
        	quoteTxIdrj  )r  (privatePostV5AssetExchangeConvertExecuter%  rq  r  )	r[  rE   r  r  r  r  r(  ru  rm  s	            r]  create_convert_tradezbybit.create_convert_trade   s_     	
 @@WV\A]^ ~~h"5$$T**r^  c                    | j                          d}| j                         \  }}|xs |}|rdnd}| j                  |dd|      \  }}||d}	| j                  | j	                  |	|            }
| j                  |
di       }| j                  |di       }| j                  |d      }| j                  |d	      }d}d}|| j                  |      }|| j                  |      }| j                  |||      S )
a[  
        fetch the data for a conversion trade

        https://bybit-exchange.github.io/docs/v5/asset/convert/get-convert-result

        :param str id: the id of the trade that you want to fetch
        :param str [code]: the unified currency code of the conversion trade
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.accountType]: eb_convert_uta, eb_convert_spot, eb_convert_funding, eb_convert_inverse, or eb_convert_contract
        :returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
        Nr  r  r}   r  )r  r  rj  r  r  )	r  r  r  +privateGetV5AssetExchangeConvertResultQueryr%  rq  r  r  r  )r[  rE   r  r  r  r  r  r/  r  r(  ru  rm  rj  r  r  r  r  s                    r]  fetch_convert_tradezbybit.fetch_convert_trade!  s    	484K4K4M11/G3G1A-GX";;FDWYfhz{V&
 CCDKKPWY_D`a4 ~~h"5h3))&*=''9
%==8L#|4J$$V\:FFr^  c                     | j                          i }|||d<   | j                  | j                  ||            }| j                  |di       }| j	                  |dg       }| j                  ||dd||      S )a  
        fetch the users history of conversion trades

        https://bybit-exchange.github.io/docs/v5/asset/convert/get-convert-history

        :param str [code]: the unified currency code
        :param int [since]: the earliest time in ms to fetch conversions for
        :param int [limit]: the maximum number of conversion structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.accountType]: eb_convert_uta, eb_convert_spot, eb_convert_funding, eb_convert_inverse, or eb_convert_contract
        :returns dict[]: a list of `conversion structures <https://docs.ccxt.com/#/?id=conversion-structure>`
        rG  rj  rk  r  r  )r  ,privateGetV5AssetExchangeQueryConvertHistoryr%  rq  r  parse_conversions)	r[  r  r  rG  r  r(  ru  rm  rn  s	            r]  fetch_convert_trade_historyz!bybit.fetch_convert_trade_historyZ!  s     	$GGDDT[[QXZ`Eab8 ~~h"5>>$3%%hj(ESXYYr^  
conversionr  r  c                 R   | j                  |dd      }| j                  |d      }| j                  ||      }| j                  |d      }| j                  ||      }||| j                  |      | j	                  |dd      || j                  |d      || j                  |d      d d d	
S )
NexpiredTimer_  r  r  r  exchangeTxId
fromAmounttoAmount)
r  r  r  rE   r  r  r  r  r1  r  )rt  r  r  rE  rs  r  )	r[  r  r  r  r  r  r  tor  s	            r]  r  zbybit.parse_conversion!  s    T ''
M;O	##J
;**8\Bj(3((Z8"Y/$$ZnM$**:|D ((Z@
 	
r^  r  c                    | j                          | j                  |      }d}| j                  d||      \  }}|dk(  s|dk(  rt        | j                  dz         |d}|d   ||d}|||d	<   | j                  | j                  ||            }	| j                  |	d
i       }
| j                  |
dg       }| j                  ||      S )a  
        fetches the long short ratio history for a unified market symbol

        https://bybit-exchange.github.io/docs/v5/market/long-short-ratio

        :param str symbol: unified symbol of the market to fetch the long short ratio for
        :param str [timeframe]: the period for the ratio, default is 24 hours
        :param int [since]: the earliest time in ms to fetch ratios for
        :param int [limit]: the maximum number of long short ratio structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of `long short ratio structures <https://docs.ccxt.com/#/?id=long-short-ratio-structure>`
        Nr   rT   rX   zE fetchLongShortRatioHistory() only support linear and inverse marketsr   rE   )r  r  r  rG  rj  rk  )
r  r  r  r;   rE   publicGetV5MarketAccountRatior%  rq  r  parse_long_short_ratio_history)r[  r  r  r  rG  r  r  r  r(  ru  rj  rm  s               r]  fetch_long_short_ratio_historyz$bybit.fetch_long_short_ratio_history!  s     	V$**+GQWXf6>TX-tww)ppqqITl

 $GG55dkk'66RS& (B7~~ffb1224@@r^  c                 ,   | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }|| j                  ||d d      || j                  |      d | j	                  t        j                  ||            dS )Nr  r  buyRatio	sellRatior  )r  r  r  r  r  longShortRatio)r  safe_integer_omit_zeror}  rE  r  r@   r  )r[  r  r  r  r  
longStringshortStrings          r]  parse_long_short_ratiozbybit.parse_long_short_ratio!  s     ##D(3//kB	%%dJ7
&&t[9&&xzJ"Y/"33G4F4FzS^4_`
 	
r^  r   GETc                 B   | j                  | j                  d   |         dz   |z   }|dk(  r|r|d| j                  |      z   z  }n|dk(  r| j                          |j	                  d      dk\  }|j	                  d      dk\  }	|j	                  d	      dk\  }
|j	                  d
      dk\  }t        | j                               }|r|r| j                  |      }nd}|| j                  z   |z   }| j                  | j                  |      | j                  | j                        t        j                  d      }d| j                  ||d}n|	s|
s|rLd| j                  |t        | j                  d         d}|	s|
rd|d<   | j                  i |      }| j                  |      }t        |      | j                  z   t        | j                  d         z   }d }|dk(  r| j                  |      }||z   }n||z   }|d| j                  |      z   z  }d }| j                  j	                  d      dkD  r| j!                  || j                  d      }nI| j                  | j                  |      | j                  | j                        t        j                        }||d<   nP| j                  || j                  | j                  d   |d      }| j#                  |      }| j                  |      }d }| j                  j	                  d      dkD  r| j!                  || j                  d      }nI| j                  | j                  |      | j                  | j                        t        j                        }|dk(  rV|j	                  d      dk\  }| j                  |d|i      }|r| j%                  |      }ddi}n5| j                  |      }ddi}n|d| j                  |      z   z  }|d|z   z  }|dk(  r#| j'                  | j                  d      }|||d<   ||||d S )!Nr   r  r   ?r   openapir   z
unified/v3zcontract/v3rK   z{}hexzapplication/json)Content-TypeX-BAPI-API-KEYX-BAPI-TIMESTAMPX-BAPI-SIGNr  )r
  r  r  zX-BAPI-RECV-WINDOWrP  zX-BAPI-SIGN-TYPEPOSTzPRIVATE KEYr  sha256r  )api_keyrecv_windowr  rT   signr
  z!application/x-www-form-urlencodedz&sign=r%  Referer)urlr  bodyheaders)implode_hostnamer   	rawencoder  r  r  rh  jsonapiKeyhmacencodesecrethashlibr  r  r%  rsakeysort	urlencoder  )r[  pathr   r  r  r  r  r  	isOpenapiisV3UnifiedMarginisV3ContractisV5UnifiedAccountr  payload	signaturer  queryEncoded	auth_baseauthFullsortedQueryauthr  extendedQueryr%  s                           r]  r  z
bybit.sign"  s   ##DIIe$4S$9:S@4G(?sT^^F333I++-+q0I # 6! ;88M2a7L!$$1!4DJJL)I99V,D  D#dkk1D8 IIdkk'&:DKK<TV]VdVdfkl	$6&*kk(1#,	 #l6H$6&*kk(1*-dll<.H*I	 %25G./B/#~~e4	NT[[83t||L?Y;ZZ	V#99U+D(4/H(<7H3!666C 	;;##M2R7 $4;; II $		$++h*?T[[AY[b[i[i jI)2&F#{{#'<<#=!*- 
 #ll51~~k2 	;;##M2R7 $t{{H EI $		$++d*;T[[=UW^WeWe fIV# XXf-2F$(KK	8 %M #~~m<*,O#  $yy7*,># 3!<<<C8i//CV''jAH#%-	"fdwOOr^  httpCodereasonr  r  r  r  c
                    |sy | j                  |dd      }
|
dk7  r|
dk(  ry d }|
dk(  r'|j                  d      dk  r| j                  dz   |z   }n| j                  d	z   |z   }|j                  d
      dkD  r|dz   }| j                  | j                  d   ||       | j                  | j                  d   |
|       t        |      y )Nret_coder  r  30084r   r  r   z private api uses /user/v3/private/query-api to check if you have a unified account. The API key of user id must own one of permissions: "Account Transfer", "Subaccount Transfer", "Withdrawal"  z7Withdraw address chain or destination tag are not equalr  z:; You might also need to ensure the address is whitelistedr  r  )rs  r  rE   throw_broadly_matched_exceptionr   throw_exactly_matched_exceptionr.   )r[  r/  r0  r  r  r  r  ru  requestHeadersrequestBody	errorCodefeedbacks               r]  handle_errorszbybit.handle_errorsi"  s    & &&xYG	G# HG#(9A(=77  &i  i  lp  p77S=4/yyRSVXX#&bb001I4QYZ001I9V^_))r^  )NNNN)N)NN)__name__
__module____qualname__r   rZ  boolre  rh  ry  r  r  r  r  r!   r   r+   r  r  floatr  r  r  r   r  r
   r  r-   r  r  r  r  dictr#   r  r  r"   r$   r  r  rk  r  r  r%   r  r&   r  r  r'   r  r   r   r  r   r(  r5  rQ  rY  r   r{  r~  r  r   r   r   r}  r  r   r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r#  r  r'  r&  r   r   r2  r;  rA  r*   rF  rI  rY  rm  r   rv  r  r  r   r    r  r  r  r   r  r  r  r  r  r  r	  r  r  r	   r  r  r   r  r   r#  r,   r   r7  r>  rA  r<  r.  r/  r   rP  rR  r(   rW  rZ  r)   r\  r`  rc  ri  rl  rp  rf  rw  ru  r   r|  rz  r   r  r  r  r   r  r  rN  r   r  objectr  r   r  r   r  r  r  r  r   r  r  r  r  r  r   r  r  r  rD  r;  __classcell__)r\  s   @r]  rB   rB       sX   o# ob'3$ 3$D	 )+ W[r 46 	=T
3 T
lWC W WRU Wjm W  zI W 57 ! e  C s #  !# 3s 30 ') iZ iV $& &A$v, &APqDL qftd6l tlId6l IVu4 u u6 un 02 F43 F4f F4P 04B j=W j=7 j=X 26b 3w 3W 3
 
4 
, 26DW[df eJ# eJc eJQT eJkoptku eJN;
 ;
; ;
z 6:" E=7 E= E=N 8<$]ajl SO SOC SOWZ SOjg gv g gR 6:UW 7?3 7?s 7?# 7?\`af\g 7?r :>b >Js >J3 >JY >J@^) ^)@ $& ^,( ^,@: :8Hs HQ Qv Q Qf RT K K5 KX] K" SU L LE LY^ L* gksu E/3 E/i E/y E/RW E/`c E/z E/N os{}  FJ H,3 H,i H,y H,Z_ H,hk H,T @B V'D$6 V'd5k V'p hlz~  HJ <S <# <Y <i <ad <tw <| `drv  @B 0S 0# 0Y 0i 0Y\ 0lo 0  GL 0d >@ S'$|"4 S'DK S'j ;?r ,s ,C ,4 37r !0s !0C !0e !0F 04B O. O.4; O.b <> s B SU P,5H0I P,d /32 G1 G1R :>b *c *3 *U *< 26b Y/c Y/3 Y/U Y/v *.Dt\^ G3 Gc G Gcghmcn G. 26DW[df c=3 c=c c=QT c=kopukv c=J 9=R *S *# *E *< 7;2 *3 * *% *@ >BPTcgpr a=s a=# a=]` a=w{  }B  xC a=F 154VZce i# iS iPS ijnotju i2 37TX\eg iC is iRU ilpqvlw i2 /3TXac `= `=3 `=c `=hlmrhs `=D 9=4^bkm XS X# XS XX[ Xrvw|r} X, -1tRV_a M?c M? M?C M?fjkpfq M?^
h 
R` 
* DF .0s .0$~J^ .0` 79 5# 5^ 5" *.Dt\^ @E3 @Ec @E @Ecghsct @ED -1tRV_a LEc LE LEC LEfjkvfw LE\:s :&L
T L
X L
Q\ L
\ (,$TZ\ i? i?C i?s i?aefqar i?VIt Ix I; IV32 DHPR -8S -8% -8# -8Wb -8^ 24 ES E EN 26b bQw bQT(^ bQHdt dV dx dL 24 5S 5 5	
t 	
V 	
x 	
 >B" R# Rs Rh 9=R $S $# $L =A , ,c ,\ NR`dsw  AC 2Mc 2MZ] 2Mmp 2Mh 79 89# 89t BFTXgktv e# ec ead e@F * 9; !6C !6 !6F
 
> 15DW[jnwy ,Q# ,Qc ,QQT ,Qdg ,Q  C  DR  S ,Q\ AESW`b /Hc /H# /HS /Hb
$ 
 
. 
. [] 3S 3% 3c 3c 3an 3j +/TPT]_ 5BC 5Bs 5B# 5Bdhivdw 5Bn DF " "U "H <> "s "H
 
D 
0:C :C :%
t %
x %
= %
N KM $?c $?QUVbQc $?L ?A L# LT,EW L&
T 
6 
EX 
( 57 .5 .5;N .5` )+ ({ (T0 0C 0d <@ -E -E^ 6:[_hj 3Ys 3Y# 3YUX 3Yj 9=4^bkm 8Y# 8YS 8YX[ 8Yt
B@ :< !9S !9F( 02 @3 @f @D4
4 4
 4
6 4
l 37TX\eg MKC MKs MKRU MKlpq|l} MK^.V .{ .` :>b 3 6 7;2 BG B- B0g [h <   $|J\  D 37TX\eg 'BC 'Bs 'BRU 'Blpq  mA 'BR2
6 2
V 2
h 02 <63 <6f <6| 46 ;Cs ;C+ ;Cz2
$ 2
( 2
6 2
]c 2
h :>D_cln ICw ICc ICY\ ICsw  yA  tB ICV /1 [Z [z MQY[ 4EC 4E 4Ec 4E`j 4El W[ce +s +c +3 +PS +jt +B 8<B :Gc :G :G: :Gx 7;\`ik /Z /Z3 /ZVY /Zptu  qA /Zb:
4 :
x :
\d :
pz :
x <@RVeix|  FH 1AS 1AC 1A_b 1Aru 1A  MQ  R`  Ma 1Af
4 
 
> 
, &eBSW WPr(c (3 (S (# (X\ (dg (r^  rB   )Gccxt.base.exchanger   ccxt.abstract.bybitr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   typingr-   ccxt.base.errorsr.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   ccxt.base.decimal_to_precisionr?   ccxt.base.preciser@   rB    r^  r]  <module>rL     s    ( +  r  r  r  r  r  r  r  r  r  r  r  * 0 - - . ' & % 1 4 . ) * ) . ) + 4 %qIHk qIr^  