
    ei                       d dl mZ d dlmZ d dlZd dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl3m5Z5 d dl3m6Z6 d d	l3m7Z7 d d
l3m8Z8 d dl3m9Z9 d dl3m:Z: d dl3m;Z; d dl3m<Z< d dl3m=Z= d dl3m>Z> d dl3m?Z? d dl3m@Z@ d dl3mAZA d dl3mBZB d dl3mCZC d dl3mDZD d dl3mEZE d dlFmGZG d dlHmIZI  G d dee          ZJdS )    )Exchange)ImplicitAPIN)*AnyADLBalancesBorrowInterest
ConversionCrossBorrowRate
CurrenciesCurrencyDepositAddressFundingHistoryGreeksIntLedgerEntryLeverageLeverageTierLeverageTiersLiquidationLongShortRatio
MarginMode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)RestrictedLocation)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de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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.Z0dd/edede1fd0Z2ddi fd	ed)ed*edee1         fd1Z3di fd	ed*ede4fd2Z5de6fd3Z7i fde6fd4Z8d5efd6Z9d7efd8Z:dd9edede;fd:Z<i fd	edede;fd;Z=i fd	edede;fd<Z>di fd	ed=e?d>e@dedeAde;fd?ZBdi d@fd	ed=e?d>e@dedeAf
dAZCi fdBeeD         dee;         fdCZEddi fdDed	ed=e?d>e@deAdeAfdEZFddi fdDed	ed=e?d>e@deAdeAde;fdFZGi fdBeeD         dee;         fdGZHdi fdDed	efdHZIdi fdDed	ede;fdIZJdi fdJee         d	edee;         fdKZKi fdLefdMZLi fdBeeM         fdNZNdi fd	efdOZOdi fdDed	ede;fdPZPdi fdDed	ede;fdQZQdddi fd	ed)ed*edee;         fdRZRdddi fd	ed)ed*edee;         fdSZSdi fdDed	ede;fdTZTdi fdDed	ede;fdUZUdddi fd	ed)ed*edee;         fdVZVdddi fd	ed)ed*edee;         fdWZWdddi fd	ed)ed*edee;         fdXZXdddi fd	ed)ed*edee;         fdYZYdddi fdDed	ed)ed*edee1         f
dZZZdddi fd	ed)ed*edee1         fd[Z[ddede\fd\Z]i fd]edee\         fd^Z^i fd]ede\fd_Z_dddi fd]ed)ed*edee`         fd`Zadddi fd]ed)ed*edee`         fdaZbd5efdbZcddcedede`fddZddddi fd]ed)ed*edeee         fdeZfddfededeefdgZgdh Zhdi fd]edediedjede`f
dkZii fd	edejfdlZkdi fd#e%deej         fdmZlddnededejfdoZmi fd	edenfdpZoddqededenfdrZpdi fdsed	efdtZqdi fdqerd	efduZsdi fdved	efdwZtdxddi fd	ed)ed*efdyZui fd	efdzZvdxddi fd	ed)ed*efd{Zwddefd|Zxi fd]edeyfd}Zzddefd~Z{ddddi fd]ed	ed)ed*edee|         f
dZ}ddi fd]ed)ed*efdZ~ddedede|fdZi fd]ededededef
dZdddi fd]ed)ed*edee         fdZi fd]edefdZi fd]efdZddedefdZd5edefdZddededef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Zdded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d]efdZd Zi fd	edefdZdi fd#e%dee         f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d]edefdZddedededefdZdddi fd#e%d)ed*edeej         fdZi fdefdZdi fdededeAdefdZdi fdDedededeAdef
dZdi fdDed]edefdZdddi fd]ed)ed*edee         fdZddedededefdZddddi fd	ed(ed)ed*edee         f
dZddededefdZdi fd#e%dee         fdZddededefdZi fd	edefdZddsedefdZdsedefdZddi ddfdZderdededededefdȄZ xZS )bybitreturnc                 3   |                      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d3dd4d5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dHddId5dJddKddLd5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djddkddlddmd5dnddoddpddqddrddsddtdduddvddwddxddyddddd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ddddddddd̜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d0dd1dd2dΓd3dd4dؓd5dؓd6dd7dؓd8dؓd9d:d;dؓi d<dؓd=dd>dd?dd@ddAddBddCddDddEddFddGddHddIddJddKddLdi dMddNddOddPddQddRddSddTddUddVddWddXddYddZdd[dd\dd]di d^dd_dd`dؓdadؓdbdؓdcdؓdddؓdedؓdfdؓdgdؓdhdؓdidؓdjdؓdkdؓdlddmddnddddddddddddddddoi ddГdpdГdqdГdrdГdsdГdtdГdudؓdvdؓdwdxdydzd{dd|dxd}dxd~dؓddؓ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Г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dȐdx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dddddddt          idi 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          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          d0t
          d1t          i d2t          d3t
          d4t          d5t          d6t          d7t          d8t          d9t
          d:t          d;t          d<t          d=t
          d>t
          d?t          d@t          dAt          dBt          i dCt          dDt          dEt          dFt          dGt          dHt          dIt          dJt          dKt          dLt
          dMt          dNt          dOt
          dPt
          dQt
          dRt
          dSt
          i dTt          dUt          dVt          dWt          dXt          dYt          dZt          d[t          d\t          d]t
          d^t
          d_t
          d`t          dat          dbt          dct          ddt          i det          dft          dgt          dht          dit          djt          dkt          dlt          dmt          dnt          dot          dpt          dqt          drt          dst          dtt          dut
          i dvt
          dwt
          dxt
          dyt          dzt
          d{t          d|t
          d}t
          d~t
          dt          dt
          dt
          dt
          dt          dt          dt           dt           i dt
          dt          dt          dt          dt
          dt
          dt
          dt          dt          dt          dt          dt
          dt
          dt
          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt
          dt          dt          dt          dt          dt
          i dt          dt          dt          dt          dt          dt
          dt
          dt
          dt
          dt          dt
          dt          dt
          dt          dt          dt          dt          i dt
          dt          dt
          dt
          dt          dt          dt          dt
          dt          dt          dt
          dt
          dt
          dt
          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt
          dt
          dt
          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt"          dt          dt          dt          dt          dt          dt          dt          dt
          dt
          dt
          dt
          dt          dt          i dt          dt          dt          dt
          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          d t          dt          dt          dt          dt          dt          dt          dt          dt          d	t          d
t          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt$          dt          dt          dt          dt          dt
          dt          dt          dt          i d t          d!t          d"t          d#t          d$t          d%t&          d&t          d't          d(t          d)t          d*t          d+t          d,t          d-t          d.t          d/t          d0t          i d1t          d2t          d3t          d4t          d5t          d6t          d7t          d8t          d9t          d:t
          d;t
          d<t
          d=t
          d>t
          d?t
          d@t
          dAt
          i dBt
          dCt
          dDt
          dEt
          dFt
          dGt          dHt
          dIt
          dJt
          dKt
          dLt
          dMt
          dNt
          dOt
          dPt
          dQt
          dRt
          i dSt
          dTt
          dUt
          dVt
          dWt
          dXt
          dYt          dZt          d[t          d\t
          d]t
          d^t
          d_t
          d`t
          dat          dbt          dct          i ddt          det
          dft          dgt          dht          dit          djt          dkt          dlt          dmt          dnt          dot          dpt          dqt          drt          dst          dtt          i dut          dvt          dwt          dxt          dyt          dzt
          d{t
          d|t
          d}t
          d~t
          dt
          dt
          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt
          dt
          dt          t          t
          t
          t          dt(          t"          t          t          t          t          t          dddt*          di ddddd[g dg d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/d0d1d2d3d4ddddd5dd̐did6d7d8d9d:d;d<dd=	ddddddd>ddddddd>dd?ddddd@ddddddddAdBdiddCdDdEddFdddddGddddddHd dddDddEddddIdJdKidBdidL
dMdNdid dd dd?ddOdPdQdMidQdMidRdQdMidQdMidRdSddddTdUdVddi i dWdXdYdZ          S ([  NidrE   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fetchAllGreeks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fetchMarginModefetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionADLRankfetchPositionHistoryfetchPositionsfetchPositionsADLRank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})rW   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/360039261154z(https://www.bybit.com/invite?ref=XDK12WP)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-dataz#v5/crypto-loan-common/loanable-dataz%v5/crypto-loan-common/collateral-dataz'v5/crypto-loan-fixed/supply-order-quotez'v5/crypto-loan-fixed/borrow-order-quotev5/ins-loan/product-infos!v5/ins-loan/ensure-tokens-convert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/instruments-infozv5/account/collateral-infozv5/asset/coin-greekszv5/account/fee-ratezv5/account/infozv5/account/transaction-logg(\?z#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-addresszv5/asset/withdraw/query-recordz%v5/asset/withdraw/withdrawable-amountzv5/asset/withdraw/vasp/listz#v5/asset/convert/small-balance-listz&v5/asset/convert/small-balance-historyzv5/fiat/query-coin-listzv5/fiat/reference-pricezv5/fiat/trade-queryzv5/fiat/query-trade-historyzv5/fiat/balance-queryz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-margin-trade/max-borrowablez#v5/spot-margin-trade/position-tierszv5/spot-margin-trade/coinstatez/v5/spot-margin-trade/repayment-available-amountz(v5/spot-margin-trade/get-auto-repay-modez$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-historyz+v5/crypto-loan-common/max-collateral-amountz(v5/crypto-loan-common/adjustment-historyzv5/crypto-loan-common/positionz$v5/crypto-loan-flexible/ongoing-coinz&v5/crypto-loan-flexible/borrow-historyz)v5/crypto-loan-flexible/repayment-historyz)v5/crypto-loan-fixed/borrow-contract-infoz)v5/crypto-loan-fixed/supply-contract-infoz&v5/crypto-loan-fixed/borrow-order-infozv5/crypto-loan-fixed/renew-infoz&v5/crypto-loan-fixed/supply-order-infoz&v5/crypto-loan-fixed/repayment-historyr   r   zv5/ins-loan/loan-order)z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-recordr   zv5/earn/orderzv5/earn/positionzv5/earn/yieldzv5/earn/hourly-yieldz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/account/borrowzv5/account/repayzv5/account/no-convert-repayzv5/account/set-limit-px-actionz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/asset/covert/get-quotez%v5/asset/covert/small-balance-executezv5/fiat/quote-applyzv5/fiat/trade-executez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-margin-trade/set-auto-repay-modezv5/spot-cross-margin-trade/loanz v5/spot-cross-margin-trade/repayz!v5/spot-cross-margin-trade/switchzv5/crypto-loan/borrowzv5/crypto-loan/repayzv5/crypto-loan/adjust-ltvz v5/crypto-loan-common/adjust-ltvzv5/crypto-loan-common/max-loanzv5/crypto-loan-flexible/borrowzv5/crypto-loan-flexible/repayz(v5/crypto-loan-flexible/repay-collateralzv5/crypto-loan-fixed/borrowzv5/crypto-loan-fixed/renewzv5/crypto-loan-fixed/supplyz(v5/crypto-loan-fixed/borrow-order-cancelz(v5/crypto-loan-fixed/supply-order-cancelz v5/crypto-loan-fixed/fully-repayz%v5/crypto-loan-fixed/repay-collateralzv5/ins-loan/association-uidzv5/ins-loan/repay-loanz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-award)z#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170209170210170213170217170218170221170222170223170224170226170227170228170229170234170241170371170372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rW   linearinverser[   )BTCETHSOLXRPMNTDOGE)typesr  enableUnifiedMarginenableUnifiedAccountunifiedMarginStatus!createMarketBuyOrderRequiresPricecreateUnifiedMarginAccountdefaultTypedefaultSubTyper  defaultSettleUSDTcoder  
recvWindowi  timeDifferencer   adjustForTimeDifferenceloadAllOptionsloadExpiredOptionsCCXTSPOTCONTRACTOPTION
INVESTMENTUNIFIEDFUND)
rW   rX   rZ   rY   r[   
investmentunifiedfundingfundcontractr  r  r  r  )r  MARGINr  r  r  r  r  r  ERC20TRXTRC20BSCBEP20r  ACAADAALGOAPTAPTOSARARBONEARBIAVAXCCAVAXAVAXXXAVAXATOMBCHBEP2BNBCHZDCRDGBr  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OPOPTIMISMPOKTQTUMRVNSCSCRTSTXTHETATONWAVESWAXWAXPXDCXECXLMr  XTZXYMZENZILZKSYNC)r*  r+  r,  r-  r.  )r  r  r  r  5min15min30minr   r   r   )r   r   r   r   r   r   )	brokerIdaccountsByTypeaccountsByIdnetworksnetworksByIddefaultNetworkdefaultNetworks	intervals!useMarkPriceForPositionCollateral)lastmarkindex)triggerPriceTypeprice)IOCFOKPOGTD)
marginModetriggerPricer>  triggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedselfTradePreventiontrailingicebergleveragemarketBuyRequiresPricemarketBuyByCostmaxd   i     )rD  limitdaysBack	untilDayssymbolRequired)rD  triggerrM  rX  )rD  rU  rY  rM  rX  )rD  rU  rV  daysBackCanceledrW  rY  rM  rX  rU    )
r   rg   rh   r   r   r   r   r   r   rt   defaultr   )r>  rF  rI  rP  )extendsr   rg   r]  )r  r  )r\  rW   rY   rZ   g~jtH?g-C6?)feeSide	tierBased
percentagetakermaker)r_  r`  r   deposit)tradingr  g     @)featuresr   rollingWindowSize)deep_extendsuperrE   describer?   r5   r<   r1   r0   r@   r2   r3   r=   r;   r7   r8   r>   rA   r:   r9   r6   rB   )self	__class__s    V/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/bybit.pyri  zbybit.describe$   s@   eT 2 2 ; ; = = {@
'{@
G{@
 ${@
 t	{@

 {@
 {@
 {@
 4{@
 {@
  rrr $r 	r
 $r $r $Tr "4r 'r tr r )$r $Ur  r %dr  /!r" 0#r r$ t%r& 'r( 7)r* &t+r, (-r. '/r0 &t1r2 (3r4 "45r6 (7r8 ,T9r: %d;r< T=r> d?r@ !$ArB CrD  Er r rF &uGrH +EIrJ )%KrL /MrN &tOrP #DQrR $TSrT )$UrV $TWrX $TYrZ +D[r\ ']r^ (_r` "4arb crd &terf (gr r rh 1$irj  krl *:mrn +Dorp &tqrr #Jsrt *4urv $Twrx tyrz "4{r| *5}r~ +Er@ tArB  CrD %dErF &uGrH -dIr r rJ /KrL "4MrN +DOrP QrR !$SrT &tUrV +DWrX  YrZ d[r\ $T]r^ +D_r` !$arb "4crd terf #Dgrh dirj !$kr r rl umrn #Dorp  qrr 'srt '
urv !$wrx (yrz ({r| )$}r~ )$r@ tArB CrD TErF tGrH "4IrJ #DKrL $UMr rN #').*.$($(#!%#'  cr r r{@
z  {{@
X <?:>?  j47267  :<7;<    /  
 PF= Y{@
X  G0!G 5aG <Q	G
 6qG 5aG ;AG <QG A!G 5aG /G >qG >qG )!G  Ea!G$ >q%G& 6q'G( 8)G G* A!+G, A!-G. B1/G0 Ma1G2 @3G4 ?5G6 =a7G8 >q9G: :1;G> 1!?GB )!CGD *1EGF 5aGGH 6qIGJ >qKGL 5aMGN .qOG G GP ,QQGR 4QSGT 1!UGV 21WGX :1YGZ .q[G\ /]G^ 3A_G` 21aGd 3AeGf 8gGj 4QkGl :1mGn :1oGp B1qGr B1sGv 9!wG Gx 9:?@ABCDCD56=>+,MG G GIV|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 6qc|d 5ae|f /g|h .ri|j *1k|l 5dm|n >qo|p /q|r /s|t 0u|x <Sy|z A#{|| B3}|~ 9!| | |@ 3AA|B 5aC|D =bE|F HG|H GI|J EbK|L FrM|N B2O|P J2Q|R >qS|T 8U|V CBW|X A!Y|Z 9"[|\ DR]|^ 3B_|` :2a| | |b 9"c|d @e|f 6qg|h >qi|j A!k|l 21m|n 21o|p .qq|r 6qs|t 0u|x 4Qy|z ,Q{|| .q}|~ 21|@ 4QA|B 0C|D -aE| | |H 5aI|L ;AM|P EaQ|R 5aS|T >qU|V >qW|X 9!Y|Z J1[|\ CA]|^ ?_|` =aa|b <Qc|d CAe|h LQi|j 8k|l ;Am|n 8o| | |p ?q|r <Qs|v Frw|x CBy|z 9"{|| ?}|~ A"|@ DRA|B DRC|D DRE|F A"G|H :2I|J A"K|L A"M|P 4QQ|R <QS|T 1!U| |V 7834+,45./453423KM+,)*,-)*01w| | |z_/_ 7_ 8	_
 ?_ 3C_ 1#_ <R_ =b_ CC_ ;C_ ;B_ H_ Mc_  G!_" <R#_$ 9"%_& 5b'_ _( 5b)_* 9"+_, 9"-_0 G1_2 G3_4 Fr5_6 I"7_8 PQS9_: J2;_< Mc=_> ;A?_@ ;AA_B ?C_D <QE_F KAG_H GI_J CAK_ _ _L HM_N DQO_P DQQ_R FqS_T DQU_X :2Y_Z ;B[_\ :2]_^ @__` A"a_b @c_d >re_f CCg_h Gi_j Eck_l CCm_n Mco_ _ _p CCq_t Ebu_v ?w_x ?y_z <R{_@ *3A_B )!C_D *3E_F .rG_H 0I_J /K_L 0M_N ;AO_R 3AS_T 6qU_V 4QW_X 21Y_ _ _Z 5a[_\ 3A]_^ :1__` 1!a_b 5ac_d :1e_h 4Qi_j 5ak_l 5am_n 6qo_p 0q_r /s_t ,Qu_v +Aw_x 6qy_z 9!{_~ 8_ _ _@ <QA_B ;BC_D EcE_F ?G_H >qI_J 3BK_L 3BM_N 4RO_P @Q_R .rS_T 0U_X 4RY_Z 1"[_\ 4R]_^ -b__` 1"a_b -bc_ _ _d 1"e_h 7i_j 5ck_n ;Ao_p <Qq_r CAs_t :3u_v ;Cw_x <Sy_| 0}_~ /_@ 4QA_D ;BE_F 9"G_H 9"I_J 8K_L CBM_ _ _N 6rO_P 5bQ_R 6rS_T CBU_V CBW_X ;BY_Z @[_^ 6q__` 1!a_d .qe_f ,Qg_h 3Ai_j ;Ak_l A!m_p 6qq_t /u_v ;Aw_ _x @A/0}_ _ _}^ ^Wj jY{@
n (o{@
t @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 0s@t lu@v mw@x ly@z l{@| j}@~ /@@	 /A	@B	 .C	@ @ @D	 /E	@F	 mG	@H	 lI	@J	 lK	@L	 mM	@N	 5O	@P	 lQ	@R	 lS	@T	 lU	@V	 lW	@X	 lY	@Z	 /[	@\	 l]	@^	 l_	@`	 /a	@b	 lc	@d	 le	@ @ @f	 lg	@h	 .i	@j	 lk	@l	 lm	@n	 lo	@p	 lq	@r	 ls	@t	 lu	@v	 mw	@x	 jy	@z	 j{	@|	 j}	@~	 j	@@
 jA
@B
 jC
@D
 jE
@F
 jG
@ @ @H
 jI
@J
 jK
@L
 jM
@N
 jO
@P
 jQ
@R
 /S
@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
 jq
@r
 js
@t
 ju
@v
 .w
@x
 .y
@z
 .{
@|
 j}
@~
 j
@@ jA@B jC@D jE@F lG@H lI@J lK@ @ @L lM@N jO@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 Zy@z Z{@| Z}@~ Z@@ ZA@B ZC@D ZE@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@f \g@h \i@j ]k@n 0o@p ]q@r Zs@t Zu@v mw@ @x  -))0@ @ @D .7'5)6':0/2E	 	OQ Qu{@
X! YY!{@
Z!  P+UP#UP DDDJJJ! !P &tP 'P &tP 4UP -eP vP !(P  P P  h!P" !!#P$ *5%P& !%'P( %e)P* #"$(&&".(%" *# # #$ *&".("! !Q5Q5Q UQ 5	Q
 UQ 5Q UQ 5Q 5Q 5Q FQ 7Q $Q fQ WQ  W!Q" F#Q Q$ 5%Q& E'Q( 5)Q* 5+Q, 5-Q. F/Q0 51Q2 F3Q4 55Q6 57Q8 F9Q: F;Q< 5=Q> G?Q@ FAQB 5CQD FEQ Q QF FGQH 5IQJ 5KQL 5MQN 5OQP FQQR 5SQT 5UQV 5WQ\ W]Q^ F_Q` FaQb FcQd 5eQf UgQh ViQj FkQ Q Ql 5mQn $oQp qQr FsQt FuQv 5wQx $yQz F{Q| 5}Q~ WQ@ 5AQB WCQD 6EQF 5GQH 5IQJ 5KQL 5MQ QN !   &WQ Q Qf #""	! ! #*G$ !""  6;_P P P[!{@
@&  $&+(,$($(%)- -
 -1)-+/ )-(,)-1 1
 &*7 7 $(#'"&#(	( ( #'/3$(#($)27+/? $  $D r% ',!$$+%&*/& & ',#'$)*.	# # ',!##'$)*/( ( $(&+!#$+,-%&#'$)*/	* 	*  # r#QK KZ  )!4( -1,104%)7 7 37$ $ " "9 "9 	  "9 "9 	 Il l^  %!%"&$#  "'"' "!	   "(u){@
 {@
 {@
 { { {	    enablec                 0   | j         rt          | j        dz             |r+| j        d         | j        d<   | j        d         | j        d<   n@d| j        v r7| j        d         | j        d<   |                     | j        d          }|| _        || j        d<   dS )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>   rH   r   omitr  )rj  rn  newUrlss      rl  enable_demo_tradingzbybit.enable_demo_tradingb  s     $ 	btw)``aaa 	 04	%0@DI,-#y7DIe#ty00#y)?@DIeii	+ABBGDI,2()))rm  c                 F    |                                  | j        d         z
  S )Nr  )millisecondsr  )rj  s    rl  noncezbybit.noncev  s!      ""T\2B%CCCrm  c                     |                      |di           }|                     |g dg           }|                     |dd          }t          |          }||dk    r|d         }||d<   ||d<   |S )Nresult)listrowsdatadataListnextPageCursorcursorr   )	safe_dictsafe_list_nsafe_string_2len)rj  responsery  r|  paginationCursor
dataLengthfirsts          rl  add_pagination_cursor_to_resultz%bybit.add_pagination_cursor_to_resulty  s    (B77(L(L(LbQQ--f6FQQYY
(zA~~GE&6E"#DGrm  c                   K   |                      | j        d          }|                      | j        d          }||$| j        d         r8d| j        d<   d| j        d<   d| j        d<   | j        d         | j        d         gS |                     |          |                     |          g}t	          j        |  d{V }|d	         }|d
         }|                     |di           }|                     |di           }	|                     |d          d
k    | j        d<   |                     |d          d
k    | j        d<   |                     |	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  Nr  FT   r  r   r   ry  r  uta)	safe_boolr  privateGetV5UserQueryApiprivateGetV5AccountInfoasynciogatherr  safe_integer)
rj  paramsr  r  rawPromisespromisesr  accountInfory  accountResults
             rl  is_unified_enabledzbybit.is_unified_enabled  s      #nnT\;PQQ#~~dl<RSS&*>*F|/0 c 7<237;346723%:;T\J`=abb88@@$B^B^_eBfBfgK$^[9999999H{H"1+Kp ^^Hh;;F NN;"EEM262C2CFI2V2VZ[2[DL./373D3DVU3S3SWX3XDL/0262C2CMShjk2l2lDL./23T\BX5YZZrm  c                 <   K   |                      |           d{V 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
        N) privatePostV5AccountUpgradeToUta)rj  r  s     rl  upgrade_unified_trade_accountz#bybit.upgrade_unified_trade_account  s.       ::6BBBBBBBBBrm  symbolc                    d }d }|                     d          }|                     d          }d }d }|                    d          dk    rr|                     |d          }|                     |d          }|                     |d          }|                     d          }	|                     |	d          }
|
}|
}n]|                     |d          }|                     |                     |d                    }|                    d          rd}d}nd	}d	}|                     |d
          }|                     |d          }|                     |          }|                     |          }d }d }|dk    r+|                     d          }|                     d          }na|dk    r+|                     d          }|                     d          }n0|dk    r*|                     d          }|                     d          }i d|dz   |                     |          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$|                     d          |||d&k    rd'nd(|                     |          ||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   rH   r  basequotesettlebaseIdquoteIdsettleIdactiveFtyper[   r  r  rW   rY   rZ   TrX   Ccallputamountr?  minrR  )r  r?  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)rj  r  r  r  optionParts
symbolBaser  r  symbolQuoteAndSettle
splitQuotequoteAndSettler  r  datetime	timestampamountPrecisionpricePrecisions                    rl  create_expired_option_marketz"bybit.create_expired_option_market  s   ll3''\\#&&
;;sb  ##J22D%%k155F#'#3#3J#B#B -33C88J!--j!<<N"E#FF##K33D778H8HVW8X8XYYFw''  !!+q11%%k155
++F33NN8,,	5=="//77O!..s33NNU]]"//66O!..u55NNU]]"//44O!..v66N+
$*tII&Q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2&%/3%6%6&&U''//)'    
   
     U+
 +
 +
 +	
rm  NmarketIdmarket	delimiter
marketTypec                    |d uo1|                     d          dk    p|                     d          dk    }|r|| j        vr|                     |          S t          t          |                               ||||          S )Nz-Cr  z-P)r  markets_by_idr  rh  rE   safe_market)rj  r  r  r  r  isOptionrk  s         rl  r  zbybit.safe_market>  s    D(hd0C0Cb0H/ghmm\`NaNadfNf 	?X);;;44X>>>UD!!--h	:VVVrm  c                     d }|                      |||          \  }}d }|                     |||          \  }}|dk    s|dk    r||gS ||gS )Nr[   rW   )handle_market_type_and_paramshandle_sub_type_and_params)rj  methodr  r  r  subTypes         rl  get_bybit_typezbybit.get_bybit_typeE  sj    99&&&QQf99&&&QQ8tv~~&>!  rm  r  c                     |                      |          }|d         d         d u }|                     |          }|s|dk    r|                     ||          S |S )Nr  r  0)r  number_to_stringamount_to_precision)rj  r  r  r  emptyPrecisionAmountamountStrings         rl  
get_amountzbybit.get_amountN  sk     V$$ &{ 3H = E,,V44# 	<)<)<++FF;;;rm  r?  c                     ||S |                      |          }|d         d         d u }|s|                     ||          S |S Nr  r?  )r  price_to_precision)rj  r  r?  r  emptyPrecisionPrices        rl  	get_pricezbybit.get_priceX  sU    =LV$$%k27;tC" 	:**65999rm  r  c                     |                      |          }|d         d         d u }|s|                     ||          S |S r  )r  cost_to_precision)rj  r  r  r  r  s        rl  get_costzbybit.get_costa  sK    V$$%k27;tC" 	8))&$777rm  c                 h   K   |                      |           d{V }|                     |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
        Ntime)publicGetV5MarketTimer  )rj  r  r  s      rl  
fetch_timezbybit.fetch_timeh  sE       33F;;;;;;;;   6222rm  c                   K   |                      d          si S | j        d         ri S |                     |           d{V }|                     |di           }|                     |dg           }|                     |          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
        Fr  Nry  r{  )check_required_credentialsr  privateGetV5AssetCoinQueryInfor  	safe_listparse_currencies)rj  r  r  r|  r{  s        rl  fetch_currencieszbybit.fetch_currencies  s       ..u55 	I<+, 	I<<VDDDDDDDD> ~~h"55~~dFB//$$T***rm  currencyc                 8   |                      |d          }|                     |          }|                      |d          }|                     |dg           }i }t          dt	          |                    D ]}||         }|                      |d          }	|                     |	|          }
||	|
d |                     |d          dk    |                     |d          dk    |                     |d	          |                     | 	                    |                      |d
                              |                     |d          d d|                     |d          d ddd	||
<   | 
                    ||||d d d d d d d dd d dd d dd|dd          S )NcoinrI   chainsr   chainchainDepositr   chainWithdrawwithdrawFeeminAccuracywithdrawMinr  
depositMin)r   rc  )	r  rH   networkr  rc  r   feer  r  r  r   rc  crypto)r  r  rH   rI   r  rc  r   r  r  r  r5  r  )r  safe_currency_coder  ranger  network_id_to_coder  safe_numberr  parse_precisionsafe_currency_structure)rj  r  
currencyIdr  rI   r  r5  jr  	networkIdnetworkCodes              rl  parse_currencyzbybit.parse_currency  s   %%h77
&&z22&11(B77q#f++&& 	 	A1IE((88I11)TBBK&,,UNCCqH --e_EEJ''}==!..t/C/CDDTDTUZ\iDjDj/k/kll  $//}EE#! !
  $//|DD#   	 	% %H[!!( ++   
   
     !3-
 -
   	rm  c                 D  K   | j         d         r|                                  d{V  g }d}g d}|                     | j         d          }||                     |d|          }n|                     | j         d|          }t	          dt          |                    D ]*}||         }|dk    r)|                    |                     |                     :|dk    r+|                    |                     d	di                     k|d
k    r+|                    |                     d	d
i                     |dk    rm|                     |dg d          }t	          dt          |                    D ]4}	||	         }
|                    | 	                    d|
i                     5t          | j        dz   |z   dz             t          j        |  d{V }g }t	          dt          |                    D ] }||         }|                     ||          }!|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  Nr  r   r  r   rW   r  categoryr  r[   r  )r  r  r  baseCoinz+ fetchMarkets() self.options fetchMarkets "z " is not a supported market type)r  load_time_differencer  r  r  r  appendfetch_spot_marketsfetch_future_marketsfetch_option_marketsr0   rH   r  r  array_concat)rj  r  promisesUnresolvedr  defaultTypesfetchMarketsOptionsir  optionsCurrenciesr  r  r  ry  parsedMarkets                 rl  fetch_marketszbybit.fetch_markets  s      <12 	.++--------->>>"nnT\>JJ*NN#6NNEE NN4<NNEq#e**%% 	O 	OAqJV##"))$*A*A&*I*IJJJJx''"))$*C*CZQYDZ*[*[\\\\y(("))$*C*CZQZD[*\*\]]]]x''$(NN3F	ShShSh$i$i!q#&7"8"899 a aA03H&--d.G.GU]H^._._````a $DG.[$[^h$h  lN  %N  O  O  O );<<<<<<<q#h--(( 	= 	=A#A;L&&v|<<FF rm  c                 
  K   ddi}|                      | j        dd          }d }|r0|                     |                     ||                     d {V }n/|                     |                     ||                     d {V }|                     |di           }|                     |dg           }g }|                     d          }|                     d          }	t          dt          |                    D ]}
||
         }| 
                    |d	          }| 
                    |d
          }| 
                    |d          }|                     |          }|                     |          }|dz   |z   }| 
                    |d          }|dk    }|                     |d          }|                     |d          }|                     |d          }| 
                    |dd          }|dk    }|                    |                     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 d d(|                     |d+          |                     |d,          d(d-d |d.                     |S )/Nr  rW   r  Fry  rz  z0.001r   r  r  	quoteCoinr  statusTradinglotSizeFilterpriceFilterquotePrecisionmarginTradingnonerH   r  r  r  r  r  r  r  TrX   rY   rZ   r[   r  r  r  basePrecisiontickSizer  r   r  minOrderQtymaxOrderQtyminOrderAmtmaxOrderAmtrO  r  r?  r  r  ra  rb  r  r  r  r  r  r  r  createdr  )r  r  !privateGetV5MarketInstrumentsInfoextend publicGetV5MarketInstrumentsInfor  r  r  r  r  r  r  r  r  safe_market_structure)rj  r  requestr  r  responseResultmarketsry  takerFeemakerFeer  r  rH   r  r  r  r  r  r"  r  r$  r%  r&  r'  allowsMargins                            rl  r  zbybit.fetch_spot_markets  s     
 %)NN4<A\^c$d$d!$ 	a!CCDKKPWY_D`D`aaaaaaaaHH!BB4;;wX^C_C_````````HB (B??..<<$$W--$$W--q#g,,'' A	 A	AQZF!!&(33B%%fj99F&&v{;;G**622D++G44ECZ%'F%%fh77F	)F NN6?CCM..??K!--m=MNNN ,,V_fM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N!--k:~VV   $0055#! !
  $//}MM#//}MM 
  $# 
  $//}MM#//}MM  $  c26 26 26 2 2 2 2 2 2f rm  c                    K   |                      |          }d|d<   g }|                     | j        dd          }d }|r|                     |           d {V }n|                     |          |                     |                      |ddi                    g}t          j        |  d {V }|                     |di           }|                     |di           }|                     |d	i           }|                     |d
g           }| 	                    |d          }	|	|	|	|d<   d }
|r|                     |           d {V }
n|                     |           d {V }
|                     |
d	i           }|                     |d
g           }t          |          }|dk    rn.|                     ||          }| 	                    |d          }	|	|                     |d	i           }|                     |d
g           }|                     ||          }g }| 	                    |d          }t          dt          |                    D ]}||         }|| 	                    |d          }|dk    }|dk    }| 	                    |d          }|dk    }|dk    }|dk    }|dk    }| 	                    |d          }| 	                    |d          }| 	                    |d          }|r|n|}| 	                    |d|          }|                     |          } |                     |          }!d }"|r	|dk    rd}"n|                     |          }"| dz   |!z   }#|                     |di           }$|                     |di           }%|                     |di           }&| 	                    |d          }'|p|}(|p|})d }*|(rd}*n|)rd }*d }+|(s:|                     | 	                    |d!                    }+|+t          |+          }+|                     |+          },|#d"z   |"z   }#|+|#d#z   |                     |+          z   }#|r|                     |$d$d%          n|                     d&          }-|                    |                     i d'|d|#d(| d)|!d*|"d+|d,|d-|d.|*d/dd0d d|(d |)d1dd2|'d3k    d4d5d|||                     |d6|                     d7                    |                     |d8|                     d9                    |-|+|,d d |                     |$d:          |                     |%d;          d<|                     |&d=          |                     |&d>          d?|                     |$d$d%          |                     |$d@dA          d?|                     |%dB          |                     |%dC          d?d d d?dD|                     |dE          |dF                     |S )GNr[  rU  r  Fr"  	PreLaunchr   r   ry  rz  r~  r  r  r  r  contractTypeInverseFuturesLinearFuturesLinearPerpetualInversePerpetualr  r  r!  
settleCoinUSDr  r  r$  r%  leverageFilterrY   rZ   deliveryTimer  r  minTradingQtyr+  r   rH   r  r  r  r  r  r  r  rW   rX   r[   r  r#  r  Tr9  0.0006r:  0.0001qtyStepr*  r  minLeveragemaxLeverager  maxTradingQtyr,  minPricemaxPricer/  
launchTimer0  )r3  r  r  r2  r4  r  r  r  r  r  r  r  r  r  	omit_zerointiso8601yymmddsafe_number_2r  r  r5  r  r  ).rj  r  preLaunchMarketsr  r  linearPromisesr  r|  r8  r  responseInnerdataNew
rawMarketsrawMarketsLengthpreLaunchDatapreLaunchMarketsListry  r  r  r  r  r  r>  inverseFutureslinearFutureslinearPerpetualinversePerpetualrH   r  r  defaultSettledIdr  r  r  r  r  r$  r%  rO  r"  rY   rZ   r  r  r  r  s.                                                 rl  r  zbybit.fetch_future_markets  s     V$$w$(NN4<A\^c$d$d!$ 		?!CCFKKKKKKKKHH 55f==55dkk&8U`Ja6b6bccN %^^<<<<<<<H~~h266H#~~h2>>~~h"55..vr22++D2BCC'".#3x &*, X*.*P*PQW*X*X$X$X$X$X$X$XMM*.*O*OPV*W*W$W$W$W$W$W$WM.."EE!^^GVR@@
#&z?? #q((++J@@#'#3#3G=M#N#N  #.t '72FF#~~mVRHH##G-ABB##D*55q#g,,'' `	 `	AQZF++FJ??(*F9,G++FNCCL*.>>N)_<M+/@@O ,0B B!!&(33B%%fj99F&&v{;;G*0<wwf''>NOOH**622D++G44EF ;H$5$500::CZ%'F NN6?BGGM..CCK~~f.>CCH%%fh77F"6&6D#4}FD    F )(8(8(P(PQQ% [[F!\\&11Nc\F*F!#F(;(;;`g  D4--m_m\\\mqm~m~  @C  nD  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>YZZ))&*d>O>OPX>Y>YZZ , "0""..}iHH!--k:FF   $//-HH#//-HH! !
  $11-R_``#11-R_`` 
  $//ZHH#//ZHH 
  $#  $  ,,V\BBc26 26 26 2 2 2 2 2 2f rm  c                 :
  K   ddi}|                      | j        dd          }d }|r0|                     |                     ||                     d {V }n/|                     |                     ||                     d {V }|                     |di           }|                     |dg           }| j        d         rd|d	<   |                     |d
          }||||d<   d }|r0|                     |                     ||                     d {V }n/|                     |                     ||                     d {V }|                     |di           }	|                     |	dg           }
t          |
          }|dk    rn.| 	                    |
|          }|                     |	d
          }|g }t          dt          |                    D ]@}||         }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |          }|                     |          }|                     |          }|                     |di           }|                     |di           }|                     |d          }|                     |d          }|                    d          }|                     |d          }|                     |d          }|dk    }||k    }|s| j        d         s| j        d         r|                    |                     i d|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-                    |                     |d.|                     d/                    |                     d0          ||                     |          |                     |          |                     |d1          |                     |d2          |                     |d3          d4d d d5|                     |d6          |                     |d7          d5|                     |d8          |                     |d9          d5d d d5d:|                     |d;          |d<                     B|S )=Nr  r[   r  Fry  rz  r  r[  rU  r~  r  r   r  r  r!  rC  r$  r%  r"  rF  r  r  r  r#  r  rH   r  r  r  r  r  r  r  r  r  r  rW   rX   rY   rZ   Tr  r  r9  rH  r:  rI  r   optionsTyperJ  r*  r  r  r+  r,  rN  rO  r/  rP  )r  r  ra  rb  r  r  r  r  r  r  r  r1  r  )r  r  r2  r3  r4  r  r  r  r  r  r  r  r  r  r  r5  rT  r  r  rS  safe_string_lower)rj  r  r6  r  r  r|  r8  r  rX  rY  rZ  r[  ry  r  r  rH   r  r  r  r  r  r  r$  r%  r"  r  splitIdr  optionLetterisActive	isInverses                                  rl  r  zbybit.fetch_option_marketsH  sY     
 %)NN4<A\^c$d$d!$ 	a!CCDKKPWY_D`D`aaaaaaaaHH!BB4;;wX^C_C_````````H~~h"55..vr22<() 	S#GG#//6FGG+&2(8GH%*.M0 r.2.T.TUYU`U`ahjpUqUq.r.r(r(r(r(r(r(r.2.S.STXT_T_`gioTpTp.q.q(q(q(q(q(q(q"nn]HbIIG!%!D!DJ'*:$'1,,"//
GDDG'+'7'7AQ'R'R$ '2b q#g,,'' F	 F	AQZF!!&(33B%%fj99F&&v{;;G''==H**622D++G44E,,X66F NN6?BGGM..CCK%%fh77F&&v~>>FhhsmmG%%gq11F++GQ77L)+HI 4DL)9: 4Ma@b 4d88 3:"3:dSj5036?#ETZH[H[[^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]B]^^!--fj$BSBST\B]B]^^$($5$5c$:$:$&*ll6&:&:"//77"&"8"8"O"O"&"2"2=)"L"L!%!1!1+z!J!J" " $(#'% %
 $(#3#3M=#Q#Q#'#3#3M=#Q#Q# #
 $(#3#3K#L#L#'#3#3K#L#L" "
 $(#'! ! $  $00FF"e3: 3: 3: 3 3 3 3 3h rm  tickerc           
         |                      |d          d u }|                     |d          }|                      |d          }|rdnd}|                     ||d |          }|                     ||d |          }|                      |d          }|                      |d          }	|                      |d          }
t	          j        |
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&|          S )'NopenInterestValuer  r  rW   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changer`  average	markPrice
indexPrice)
baseVolumequoteVolumer  r  r  )	r  r  r  safe_symbolrC   
string_mulsafe_tickerrS  r  )rj  rj  r  isSpotr  r  r  r  r;  r  r`  r  r  ry  r}  rw  rx  s                    rl  parse_tickerzbybit.parse_ticker  s   \ !!&*=>>$F%%ff55	##FH55/vvZ!!(FD$??!!(FD$??4477%%fn==
'
E::
&&v}==%%fk::
v{33v{3377v}55 !
f!
!
 Y//!
 D	!

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

        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>`
        Nz) fetchTicker() requires a symbol argumentr  rH   r   r  ry  rz  r   )
r4   rH   load_marketsr  r  publicGetV5MarketTickersr3  r  r  r  )
rj  r  r  r  r6  r  r  ry  tickers	rawTickers
             rl  fetch_tickerzbybit.fetch_tickerJ	  s      >#DG.Y$YZZZ!!!!!!!!!V$$fTl

 ..}ffMM&&
66t{{7F7S7STTTTTTTTN (B77..44NN7A..	  F333rm  symbolsc                 $  K   |                                   d{V  |                     |g d          }d}d}|,g }|                     dd|          }|d         }d}t          dt	          |                    D ]}	||	         }
|
                    d          dk    }|r|                     |
dd|          }n|                     |
          }|	|d         }n#|d         |k    rt          | j	        dz             |d	         rG|#||d
         k    rt          | j	        dz             ||d
         }| 
                    |ddg          }|                    |d                    i }d}|                     d||          \  }}||d<   |d	k    rd	|d<   |d}||d<   |                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     ||          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>`
        N)r  r  r  r   r   r  r  r  z@ fetchTickers can only accept a list of symbols of the same typer[   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  r  ry  rz  )r  safe_string_nr  r  r  r  r  r  r5   rH   rr  r  r  r  r3  r  r  parse_tickers)rj  r  r  r  r  parsedSymbolsmarketTypeInfor  currentTyper  r  isExchangeSpecificSymbolr6  r  r  ry  
tickerLists                    rl  fetch_tickerszbybit.fetch_tickers	  s      !!!!!!!!!!!&*J*J*JKKM!??PTV\]]N(+KK1c'll++ 7 7  -3KK,<,<,B(+ 1!--fdD+NNFF![[00F&"(.KKF^{22$TW/q%qrrr(# E'DF6N,B,B(  4A  *A  B  B  B|%f~!YYv
/CDDF$$VH%56666

 ..~vvNN&&
x"*GJ|"&GJ66t{{7F7S7STTTTTTTTN (B77^^FFB77
!!*m<<<rm  c                 >   K   |                      ||           d{V S )ar  
        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>`
        N)r  )rj  r  r  s      rl  fetch_bids_askszbybit.fetch_bids_asks	  s0       ''888888888rm  c           	         |d         rdnd}|                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     ||          gS )	Nr  r  r   r   r   r  r     )r  r  )rj  ohlcvr  volumeIndexs       rl  parse_ohlcvzbybit.parse_ohlcv	  s     #9-5aaAeQ''UA&&UA&&UA&&UA&&UK00
 	
rm  r   	timeframesincerU  c           	      ,  K   |t          | j        dz             |                                  d{V  d}|                     |dd          \  }}|r!|                     d|||||d           d{V S |                     |          }d|d         i}|d	}|||d
<   |||d<   |                     d||          \  }}|                     | j        ||          |d<   d}	|d         r6d|d<   | 	                    | 
                    ||                     d{V }	n0|                     |d          }
|                     |d          }|d         rd|d<   n%|d         rd|d<   nt          | j        dz             |
dk    r0|                     | 
                    ||                     d{V }	n|
dk    r0|                     | 
                    ||                     d{V }	ne|
dk    r0|                     | 
                    ||                     d{V }	n/| 	                    | 
                    ||                     d{V }	|                     |	di           }|                     |dg           }|                     |||||          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   paginater[  r  rH      startrU  endintervalrW   r  r?  r  r  z1 fetchOHLCV() is not supported for option marketsr<  r=  premiumIndexry  rz  )r4   rH   r  handle_option_and_params"fetch_paginated_call_deterministicr  handle_until_optionr  r   publicGetV5MarketKliner3  rr  r>   publicGetV5MarketMarkPriceKline publicGetV5MarketIndexPriceKline'publicGetV5MarketPremiumIndexPriceKliner  r  parse_ohlcvs)rj  r  r  r  rU  r  r  r  r6  r  r?  ry  ohlcvss                rl  fetch_ohlcvzbybit.fetch_ohlcv
  s4     $ >#DG.X$XYYY!!!!!!!!!88zZZ& 	~@@vW\^cenpvx|}}}}}}}}}V$$fTl
 =E$GG$GG225'6JJ"..t	9UU
&> 	["(GJ!88Wf9U9UVVVVVVVVHH$$VW55EYYvw//Fh b&.
##	" b&/
##"47-`#`aaa!%!E!EdkkRY[aFbFb!c!ccccccc'!!!%!F!Ft{{SZ\bGcGc!d!ddddddd.((!%!M!MdkkZaciNjNj!k!kkkkkkk!%!<!<T[[RX=Y=Y!Z!ZZZZZZZT (B7733  E5IIIrm  c                    |                      |d          }|                     |d          }|                     |d          }|                     ||d d          }|                     |d          }|                      |d          }|                     |d          }|                     |d          }	|                     |                     ||d d          d          }
|                      |
d	          }d }|*|                     |d
z            }t          |          dz   }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|iS )Nr  r  rY   fundingRatenextFundingTimer  r  r  fundingInterval<   hinterestRateestimatedSettlePricer  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer  )
r  rr  r  r  r  r  r  parse_to_intstrrS  )rj  rj  r  r  r  r  r  r  r  r  r  r  intervalStringr  s                 rl  parse_funding_ratezbybit.parse_funding_ratey
  s   4 %%fk::	6;//##FH55!!(FD&AA&&v}==,,V5FGG$$V[99	%%fl;;
~~d..xvNNPVWW++D2CDD&((2)=>>H ]]S0N
F
f
 
 *	

 D
 #D
 
 Y//
 ;
  0
 t||,<==
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 
 	
rm  c                   K   |                                   d{V  d}i }|P|                     |          }|                     |d                   }t          |          }|dk    r|d         |d<   d}|                     d||          \  }}|dk    rt          | j        dz   |z   d	z             d}|                     d||d
          \  }}||d<   |                     | 	                    ||                     d{V }| 
                    |di           }	|                     |	dg           }
|                     |d          }t          dt          |
                    D ]}||
|         d<   |                     |
|          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   rH   r  r   rY   z& fetchFundingRates() does not support z marketsr  r  ry  rz  r  r  )r  market_symbolsr  r  r  r>   rH   r  r  r3  r  r  r  r  parse_funding_rates)rj  r  r  r  r6  symbolsLengthr  r  r  r|  r  r  r  s                rl  fetch_funding_rateszbybit.fetch_funding_rates
  s      !!!!!!!!!))'22G[[,,FLLM!!$*4L!99:MvW]^^f6>>tw)QQTXX[eefffG"==>QSY[ackllOGV")GJ66t{{7F7S7STTTTTTTTJ ~~h"55^^D&"55
%%h77	q#j//** 	3 	3A)2JqM+&&''
G<<<rm  c           
      n  K   |t          | j        dz             |                                  d{V  d}|                     |dd          \  }}|r |                     d||||d           d{V S |d}d|i}|                     |          }|                     |d         d	          }|d
         }|d         |d
<   d}	|                     d||          \  }	}|	dk    s|	dk    rt          | j        dz             |	|d<   |||d<   |                     |d          }
|                     |d|
          }| 	                    |ddg          }|||d<   n*|(d}||dz  dz  }| 
                    |||z            |d<   |                     |                     ||                     d{V }g }|                     |d          }|                     |d          }t          dt!          |                    D ]}||         }|                     |d          }|                    ||                     |                     |d
          ddd          |                     |d          ||                     |          d           |                     |d          }|                     ||||          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  r  rU  r  r  r  rH   rW   r[   zA fetchFundingRateHistory() only support linear and inverse marketr  	startTimeuntilendTimei tr  r[  ry  rz  r   fundingRateTimestamprY   r  )r  r  r  r  r  r  )r4   rH   r  r  fetch_paginated_call_dynamicr  r  r  r>   rr  sumpublicGetV5MarketFundingHistoryr3  r  r  r  r  r  r  r  r  rS  sort_byfilter_by_symbol_since_limit)rj  r  r  rU  r  r  r6  r  fundingTimeFrameMinsr  r  r  r  r  ratesry  
resultListr  entryr  sorteds                        rl  fetch_funding_rate_historyz bybit.fetch_funding_rate_history
  sC      >#DG.e$efff!!!!!!!!!88AZ\fgg& 	y::;TV\^cejlrtwxxxxxxxxx=E U
 V$$#00ARSS!"4L**+DffUUf6>>TX--tw)llmmm"
#(GK !!&'22##FIu==6Iw#788!(GI "4'3&:R&?$&FO%)XXeU_5L%M%M	"==dkk'SY>Z>Z[[[[[[[[& (33^^FF33
q#j//** 		 		AqME))%1GHHILL**4+;+;E8+L+LdTXZ`aa#//}EE& LL33      e[1100NNNrm  tradec                 <   |                      |g d          }|                     |d          }d|v rdnd}|                     |d          }|
|dk    rdnd}||d         }|                     ||d |          }|d         }|                      |g d          }|                      |g d	          }	|                     |d
          }
|                     |g d          }|                     |d          }||                     |d          }||rdnd}|                     |d          }d }||rdnd}nK|                     |d          }|dk    rd }|+|dk    s|dk    r|                                }n
|dk    rdnd}|                     |d          }|dk    rd }|                     |d          }d }||                     |d          }d }|d         rEt          j	        |d          r|dk    r	|d         }n9|d         }n0|dk    r	|d         }n!|d         }n|d         r|d         n|d          }||                     |d!|          |d"}| 
                    ||||                     |          ||                     |d#          ||||	||
|d$|          S )%N)execIdrH   tradeIdr  
createTyper  rW   r  r  )execQtyorderQtysize)	execPrice
orderPricer?  	execValue)r  execTime	tradeTimesideisBuyerbuysellisMakerrb  ra  lastLiquidityIndUNKNOWNTAKERMAKERAddedLiquidity	orderTypeunknownexecFeefeeRater  r  r  r  r  feeCoin)r  r  rateorderId)rH   r  r  r  r  orderr  r  takerOrMakerr?  r  r  r  )r  r  r  safe_integer_nre  r  r  lowerrC   	string_gt
safe_traderS  )rj  r  r  rH   r  r  r  r  r  priceString
costStringr  r  r  r  r  r  r  feeCostStringr  feeRateStringfeeCurrencyCodes                         rl  parse_tradezbybit.parse_tradeU  s\   h 'B'B'BCC##E844$0E$9$9ZZ
##E:66$,$6$6ZJJ!!(FD*EE!))%1P1P1PQQ((0T0T0TUU%%e[99
''/P/P/PQQ	%%eV44<''y99G" '3uuV..	22&-:777LL#//7IJJ9,,#' +$//5E5P5P#3#9#9#;#;LL/?CS/S/S77ZaL**5+>>		!!I((	::$ ,,UI>>M"Of~ \$]C88 	9u}}*0.*0/u}}*0/*0.4:94E"[&..6RZK[% ,,UIOO% C
 "Y//%%eY77( " 
  
   	rm  c                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|||d<   d}|                     d||          \  }}||d<   |                     |                     ||                     d{V }|                     |di           }	|                     |	d	g           }
| 	                    |
|||          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  rH   rU  r   r  ry  rz  )
r4   rH   r  r  r  publicGetV5MarketRecentTrader3  r  r  parse_trades)rj  r  r  rU  r  r  r6  r  r  ry  tradess              rl  fetch_tradeszbybit.fetch_trades3  s       >#DG.Y$YZZZ!!!!!!!!!V$$fTl

   %GG**=&&IIf"
::4;;wPV;W;WXXXXXXXX. (B7733  >>>rm  c                   K   |t          | j        dz             |                                  d{V  |                     |          }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<   |                     |                     ||                     d{V }|                     |di           }|                     |d          }	|                     |||	dd          S )a5  
        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
        Nz, fetchOrderBook() requires a symbol argumentr  rH   r   rW   r   r  r[   r  r  rU  ry  tsba)	r4   rH   r  r  publicGetV5MarketOrderbookr3  r  r  parse_order_book)
rj  r  rU  r  r  r6  defaultLimitr  ry  r  s
             rl  fetch_order_bookzbybit.fetch_order_bookl  sf      >#DG.\$\]]]!!!!!!!!!V$$fTl
 &> 	0L"(GJh 0&.
##! 0&.
##	" 0&/
#%*%655\88Wf9U9UVVVVVVVV4 (B77%%fd33	$$VVYSIIIrm  c                    |                      |d          }|||                     |          d}|                     |di           }|                     |g d          }|Od}|                                 }|                     |d          |d<   |                     |d          |d	<   |||<   nt          d
t          |                    D ]}||         }	|                     |	d          }
|
dk    s|
dk    s|
dk    rz|                     |	d          }t          d
t          |                    D ]C}|                                 }||         }|                     |d          }|                     |d          }||t          j
        ||          |d<   |                     |d          |d	<   |                     |dd          }|||d<   nt|                     |dd          }|                     |dd          }|                     |dd          }t          j
        ||          }t          j
        ||          }||d<   |                     |d          }|                     |          }|||<   E|                                 }|                     |	d          }|                     |	d          }||t          j
        ||          |d<   |                     |	d	d          |d	<   |                     |	g d          |d<   |                     |	d          |d<   |                     |	g d          }|                     |          }|||<   |                     |          S )Nr  )r  r  r  ry  )loanAccountListrz  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  rS  r  r  accountr  r  r  r  rC   
string_addr  r  r  safe_balance)rj  r  r  ry  r7  currencyListr  r0  r  r  r!  coinsr  	coinEntryr*  r+  r  r&  totalPositionImtotalOrderIm	totalUsedr  s                         rl  parse_balancezbybit.parse_balance  s   N %%h77	"Y//
 

 (B??''8^8^8^__DllnnG"..~?QRRGFO#//PPGG"F4LL1c,//00 &+ &+$Q"..umDD)++{j/H/HK[aLaLa NN5&99E"1c%jj11 / /"&,,..$)!H	#//	>JJ#'#3#3I?P#Q#Q ,83G.5.@x.P.PGFO+/+;+;I+W+W(#11)=RTZ[[+.2GFOO%)%5%5i3%O%OF.2.>.>yJ[]`.a.aO+/+;+;I~WZ+[+[L(/(:6?(S(SI(/(:9l(S(SI.7GFO%)%5%5i%H%H
#66zBB'.t+/. #llnnG++E6::D#//zBBH(x/C*1*<T8*L*L'+'9'9%/'Z'ZGG$&*&8&8  AR  AR  AR  'S  'SGFO&*&6&6uh&G&GGFO!%!3!3E;^;^;^!_!_J22:>>D#*F4LL  (((rm  c                   K   |                                   d{V  i }|                                  d{V \  }}|p|}d}|                     dd|          \  }}d}|                     dd|          \  }}|dk    s|dk    r|}||                                nd}|dk    }	|dk    }
|dk    }|dk    p|d	k    }|r-|                     | j        d
d          }|dk     r|rd}nd}n	d}n|
s|rd}|                     | j        di           }|                     |||          }d}| 	                    d|          \  }}d}|	r2|0| 
                    |                     ||                     d{V }nk|r5d|d<   |                     |                     ||                     d{V }n4||d<   |                     |                     ||                     d{V }|                     |          S )aH  
        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>`
        Nrv   rY   rZ   rW   r  r  r  r  r  r  r   r  r  r3  r  r!  )r  r  r  r  r  r  r  r  safe_string_upperhandle_margin_mode_and_params'privateGetV5SpotCrossMarginTradeAccountr3  1privateGetV5AssetTransferQueryAccountCoinsBalance privateGetV5AccountWalletBalancer9  )rj  r  r6  r  r  isUnifiedAccountr  r  lowercaseRawTyper  isLinearri  	isFundingr  accountTypesunifiedTyperD  r  s                     rl  fetch_balancezbybit.fetch_balanceL  s      !!!!!!!!!:>:Q:Q:S:S4S4S4S4S4S4S11/G3G99.$PVWWf99.$PVWWFNN 0 0D,0,<4::<<<4&.H$Y&	%/S5E5R	 	""&"3"3DLBWYZ"["["Q&& %%DD$DD  "9 "!~~dl4DbII,,\4FF
!??PVWW
F 		az-!II$++V]_eJfJfggggggggHH 	a &,GM"!SSTXT_T_`gioTpTpqqqqqqqqHH%0GM"!BB4;;wX^C_C_````````HN !!(+++rm  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}|                      |||          S )NNEWr  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  rj  r"  statusess      rl  parse_order_statuszbybit.parse_order_status  s   
6
 
 h	

 

 f
 6
 

 )(
 v
 6
 

 v
 &x
  h!
" V#
$ %
( 6)
* &/
 
 
2 &&999rm  rJ  c                 >    ddddd}|                      |||          S )NGTCr@  rA  rB  )GoodTillCancelImmediateOrCancel
FillOrKillPostOnlyr_  )rj  rJ  timeInForcess      rl  parse_time_in_forcezbybit.parse_time_in_force  s4    #!&	
 
 k;GGGrm  r  c                 	   |                      |d          }||dk    r|                      |d          }|dk    rdnd}|                     |d|                      |d          |                      |d          |                     |                      |d	          d d |          d
          S |                      |d	          }d|v }d }|	|d         }n|rdnd}|                     ||d |          }|d	         }	|                     |dd          }
|                      |dd          }|                      |d          }|                     |d          }|                      |d          }d }d }|dk    r-|                      |d          }|                      |d          }n|                      |d          }|                      |d          }|                      |d          }|                     |dd          }|                      |d          }|                     |          }|                     |d          }d }|                     |di           }t          |	                                          }|                      |d          }|| 
                    ||          |d}|                      |d          }|t          |          dk     rd }|                     |                      |d                    }|                      |d           }|                     |          }|                     |                      |d!                    }|                     |d"          } |                     |                      |d#                    }!|                     |                      |d$                    }"|                      |d%          }#|#d&k    }$|d uo| }%|"|%r|$r|d'k    r|}"|$s|d(k    r|}"|!|%r|$r|d(k    r|}!|$s|d'k    r|}!|                     i d)|d*|d+|d,|
d-|                     |
          d.|d/|d	|	d|d |d0d d"|                     |d"          d|d|d!|d1|!d2|"|||||||d d3|          S )4Nr  r  r  rW   r  rQ  r   orderLinkIdr  )r  r"  rH   clientOrderIdr  tpslModer  createdTime	createdAt
marketUnitr  r  r?  qtycumExecValue
cumExecQty	leavesQtyupdatedTime	updatedAtorderStatusr  cumFeeDetailr   r  r  r   avgPricerJ  rE  
reduceOnly
takeProfitstopLossrF  r   r  r  r  rH   rm  r  r  lastTradeTimestamplastUpdateTimestamppostOnlyrH  rG  )r  r  r  filled	remainingr"  r  r  )r  
safe_orderr  r  safe_integer_2re  rb  r  rz  keysr  r  rQ  rj  r  rS  )&rj  r  r  r  r  inferredMarketTyper  
isContractr  r  r  rq  rH   r  r?  r  r  r  r  r  	rawStatusr"  r  r  ry  feeCoins	feeCoinIdrm  r{  rawTimeInForcerJ  rE  r|  rH  rG  rF  isAscendingisStopOrderType2s&                                         rl  parse_orderzbybit.parse_order  s   L v..s{{++E:>>08F0B0BVV"!(**5)<<%)%5%5e]%K%K"..t/?/?x/P/PRVX\^pqq( (    ##E844 E)

JJ'1=vJ!!(FD*EE!''}kJJ	%%e\:FF
eY//%%e[99  00##%%eU33F##E>::DD##E>::D!!%66$$UK88	!00{SS$$UM::	((33%%eV44~~e^R@@))++,,$$Xq11	 ((yAA% C ((>>%C,>,>,B,B M>>$"2"25*"E"EFF))%??..~>>~~d&6&6un&M&MNN^^E<88
..)9)9%)N)NOOt'7'7z'J'JKK++E3EFF'3.(4D*!'7! - , -DFNN ,#)9# /". /DEMM".  
E 
" 
 ] 
 	 

 Y// 
 !"4 
 "#5 
 f 
 D 
 ; 
  
 $..== 
 D 
 U 
 L 
  ! 
" ]# 
$ "3 
  
  
4 5  	rm  c                   K   |                                   d{V  |                     |          }|d         st          | j        dz             d|i}|                     |dddd|                     ||                     d{V 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>`
        NrW   z9 createMarketBuyOrderWithCost() supports spot orders onlyr  r  r  r  )r  r  r>   rH   create_orderr3  )rj  r  r  r  r  reqs         rl  !create_market_buy_order_with_costz'bybit.create_market_buy_order_with_cost  s       !!!!!!!!!V$$f~ 	ftw)ddeeeD
 &&vxD$++VY[aJbJbcccccccccrm  c                   K   |                                   d{V  |                                  d{V }|d         }|st          | j        dz             |                     |          }|d         st          | j        dz             d|i}|                     |ddd	d|                     ||                     d{V 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>`
        Nr   z; createMarketSellOrderWithCost() supports UTA accounts onlyrW   z: createMarketSellOrderWithCost() supports spot orders onlyr  r  r  r  )r  r  r>   rH   r  r  r3  )rj  r  r  r  r  r  r  r  s           rl  "create_market_sell_order_with_costz(bybit.create_market_sell_order_with_cost  s       !!!!!!!!!--////////$Qx# 	htw)ffgggV$$f~ 	gtw)eefffD
 &&vxT4;;WZ\bKcKcdddddddddrm  r  r  c           	        K   |                                   d{V  |                     |          }|                                  d{V }|d         }	|                     |dd          du}
|                     |d          du}|                     |d          du}|                     |||||||	          }|r|p|                     |dd          }d}|
s|r|d	         sd
}nd}d}|                     |dd|          \  }}d}|d
k    r|                     |           d{V }n| 	                    |           d{V }| 
                    |di           }|                     ||          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, 'ascending' or 'descending'
        :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.stopLossLimitPrice]: The limit price for a stoploss order(only when used in OCO with takeProfitPrice)
        :param float [params.takeProfitPrice]: The price at which a take profit order is triggered at
        :param float [params.takeProfitLimitPrice]: The limit price for a takeprofit order(only when used in OCO combination with stopLossPrice)
        :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
        :param boolean [params.tradingStopEndpoint]: whether to enforce using the tradingStop(https://bybit-exchange.github.io/docs/v5/position/trading-stop) endpoint, makes difference when submitting single tp/sl order
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr   trailingAmounttrailingStoprG  rH  tradingStopEndpointFrW    privatePostV5PositionTradingStopprivatePostV5OrderCreaterg   r  ry  )r  r  r  r  r  create_order_requestr  r  r  r  r  r  )rj  r  r  r  r  r?  r  r  partsr  isTrailingOrderisStopLossOrderisTakeProfitOrderorderRequestswitchToOcodefaultMethodr  r  r  s                      rl  r  zbybit.create_order  s     H !!!!!!!!!V$$--////////$Qx,,V5E~VV^bb**6?CC4O ,,V5FGGtS00tVUTZ\pqq&<+<uPVXmotAuAu 	7{ 	7F6N 	7>MM6M66v}hXeff777!BB<PPPPPPPPHH!::<HHHHHHHHH x266v...rm  Tc                 >   |                      |          }|d         }|                                }	d|d         i}
|                     |dd          }|                     |d          }|                     |dd          }|                     |d          }|                     |d	          }|                     |d
          }|                     |d          }|                     |dd|                     |                    }|                     |dd          }|d u}|d u}|d u}|d u}|d u}|d u}|	dk    }|	dk    }|dk    }|r|p|                     |dd          }d }|s|rd}nd}d }|                     |dd|          \  }}|dk    } ||	dk    r| st          | j	        dz             t          j        |                     |          d          sd }||                     ||          nd }!|)|                     ||                     |                    nd }"| r"|s|s
|s|d         rt          | j	        dz             |s|rd }#d }$|rU|                     ||          |
d
<   |                     |dd          }%|%d}#d|
d <   |%|
d<   |!|
d!<   nd"|
d <   |!|!|
d!<   d}#nd#}#|rU|                     ||          |
d<   |                     |d$d%          }&|&d}$d|
d&<   |&|
d%<   |!|
d'<   nd"|
d&<   |!|!|
d'<   d}$nd#}$|r|r|#|$k    rt          | j	        d(z             |#|#|
d)<   n|$|
d)<   |                     |g d*          }n|                     |          |
d+<   |                     |	          |
d,<   |                     |d-          }'d }(|                     ||'d.k    |          \  }(}|(rd/|
d-<   n#|'d0k    rd1|
d-<   n|'d2k    rd3|
d-<   n|'d4k    rd5|
d-<   |d         r|d6|
d7<   n	|s|rd8|
d7<   |                     |d9          })|)|)|
d:<   n|d;         r|                                 |
d:<   |r|"|
d<<   d }*|                     d=||          \  }*}|*|
d><   |                     |d?          }+|                     |d?          }|	dk    o|dk    o|d up|+d u},|	dk    }-|d         rS|-rQ|rO|,sM|+|>d@|
dA<   d }.|+|+}.nt          j        |!|"          }/|/}.|                     ||.          |
dB<   n	dC|
dA<   |!|
dB<   n|d         r|-r|dk    rdD}0|                     |ddE          \  }0}|0rc||+t          | j	        dFz             t          j        |                     |          |"          }/|+|+n|/}1|                     ||1          |
dB<   nm|+-|                     ||                     |+                    |
dB<   n>|-|                     |t          j        |!|"                    |
dB<   n|!|
dB<   n	|s| s|!|
dB<   |r!||                     ||          |
d<   ||
d<   n|r| s|                     |dG          }2|                     |g dH          }|d         r|2t1          | j	        dIz             n4|2t          | j	        dJz             |2dKk    p|2dLk    p|2dMk    }3|3rdNndO|
dG<   |                     ||          |
d<   n?|s|r;| s9|r
|rdNndO|
dG<   n	|rdOndN|
dG<   |r|n|}|                     ||          |
d<   dD|
d<   |s|r=| s:|r|                     |dd|          }4|                     ||4          |
d
<   |                     |d<          }5|5$d|
d)<   d|
d <   |                     ||5          |
d<   n|d         rd"|
d <   |d         r|-rt          | j	        dPz             |r|                     |dd|          }6|                     ||6          |
d<   |                     |d<          }7|7$d|
d)<   d|
d&<   |                     ||7          |
d%<   n|d         rd"|
d&<   |d         r|-rt          | j	        dQz             |d         s1|r/|r |                     |d          }|dk    rdRnd}|dk    rdNndO|
dS<   |                     |g dT          }|                     |
|          S )UNr  rH   rK  Fr|  rE  	stopPricerG  rH  r~  r}  trailingTriggerPriceactivePricer  r  r  rU  r  r  r  r  rg   r  z7 createOrder requires a price argument for limit ordersr  rW   zf the API endpoint used only supports contract trailingAmount, stopLossPrice and takeProfitPrice ordersstopLossLimitPriceslLimitPricePartialLimitslOrderTypeslSizer   FulltakeProfitLimitPricetpLimitPricetpOrderTypetpSizeza createOrder() requires both stopLoss and takeProfit to be full or partial when using combinationrn  )r  r  r  r  r  rJ  postonlyrh  gtcrd  fokrA  iocr@  	StopOrderorderFilter	tpslOrderrm  rl  r[   r?  createOrderRequestr  r  r!  rq  rr  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 argumentrF  )rE  r  rF  zU createOrder() : trigger order does not support triggerDirection for spot markets yetz stop/trigger orders require a triggerDirection parameter, either "ascending" or "descending" to determine the direction of the trigger.	ascendingabover   r   r  zI createOrder(): attached stopLoss is not supported for spot market orderszK createOrder(): attached takeProfit is not supported for spot market ordersr  positionIdx)r  rJ  rG  rH  r  rm  rE  r~  r}  r  r  rK  )r  r  r  safe_value_2
safe_valuer  r  r  r4   rH   rC   r  r  r  r<   rr  
capitalizere  handle_post_onlyr  uuid16r  r  r  r>   r3  )8rj  r  r  r  r  r?  r  isUTAr  lowerCaseTyper6  rK  r|  rE  stopLossTriggerPricetakeProfitTriggerPricer~  r}  r  r  r  isTriggerOrderr  r  hasStopLosshasTakeProfitisMarketisLimitisBuyr  r  r  endpointIsTradingStopr  r  
tpslModeSl
tpslModeTpr  r  rJ  r  rm  r  r  isMarketBuyAndCostInferableisMarketOrder	orderCostquoteAmountr  costRequestrF  
isAsendingslTriggerPricer  tpTriggerPricer  s8                                                           rl  r  zbybit.create_order_requestT  s(   V$$!

fTl
2 %88^^FL99
((MM#vGG!%9J!K!K??6:66__V\::
#11&:PR_aeavavw|a}a}~~++F4DnUU(4%T1.d:2$>d*"$. H,7*&<+<uPVXmotAuAu 	7k 	7>MM6M66v}hXeff &*L LM 8 8BW 8#DG.g$ghhh !6!6v!>!>DD 	F;A;Mtvv666TXOTO`dnnVT-B-B5-I-IJJJgk  F	/ Wm W~ W W"47  .V  $V  W  W  W 'r"3 'r"&
"&
" 0*...AU*V*VGJ')-););FDXZh)i)i&)5%.
18.2D/,8))19.'30<GH-)2JJ)/J$ 0,0NN6CY,Z,ZGL)+/+=+=fF\^l+m+m(+7%.
18.2F/,8))19.'30<GH-)2JJ)/J$ V VZ:=U=U&tw  2U  (U  V  V  V)*4GJ''*4GJ'6+p+p+pqq"ood33GFO#'??=#A#AGK 00GGKH#44X{j?XZ`aaHf /)3&&%%).&&%%).&&%%).&f~ 9+-8GM**$ 9(9 9-8GM* ,,V_EEM()6&&! 7)-& /#. ../CVVTT&&
//66**'4'@  'Ftu}  'F\aim\m  \Esw  @D  tD#%1&> #	.m #	. #	.>Y #	. e&7(3% 	# $II")"4\;"O"OK +I!%vy!A!A(2%!-F^ 	. 	.45== 15-8<8U8UV\^k  nQ  9R  9R5-v0 2M&tw  2m  (m  n  n  n")"4T5J5J65R5RT_"`"`K+/+;$$+K%)]]6;%G%GGENN#%)]]64;P;PQU;V;V%W%WGENN&%)]]67;Ml\g;h;h%i%iGENN%1GENN" .+@ .!- 	)#/)-@T)U)U&&4GN## 	)$9 	)#//8JKKYYv'X'X'XYYFf~ E#/&tw  2I  (I  J  J  J 0 $++DG  7A  -A  B  B  B/;>}DTX_D_}euy|e|
3=.Daa1*+&*nnV\&J&JGN## 	)!2 	)<Q 	) J3B.Iaa*++3B.Iaa*+3B^//H^L&*nnV\&J&JGN#$(GL! 	@= 	@2G 	@ ~!%!2!28^[Zb!c!c&*nnV^&L&L
##xAA+*3GJ'-4GM*.2nnV\.R.RGN++ f~ :19.&> ~m ~&tw1|'|}}} @!%!2!2:~{\f!g!g(,v~(N(N%#z7CC+*3GJ'-4GM*.2nnV\.R.RGN++ f~ :19.&> @m @&tw1~'~f~ 	A& 	A <6<88"&%--vve+/5==QQqGM"6  $_  $_  $_  `  `{{7F+++rm  ordersc           
        K   |                                   d{V  |                                  d{V }|d         }g }g }t          dt          |                    D ]}||         }|                     |d          }	|                    |	           |                     |d          }
|                     |d          }|                     |d          }|                     |d          }|                     |d	i           }|                     |	|
|||||          }|d
= |                    |           | 	                    |dddd          }| 
                    |d                   }|                     | j        dd          }d}|                     d||          \  }}|dk    r|dk     rt          | j        dz             ||d}|                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     |di           }|                     |dg           }t          dt          |                    D ]E}||         }|                     |d          }|dk    r|                     ||         |          ||<   F|                     |          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>`
        Nr   r   r  r  r  r  r?  r  r  FTr  r  rh   r  r   zB createOrders does not allow inverse orders for non UTA2.0 accountr  r6  ry  rz  
retExtInfor  )r  r  r  r  r  r  r  r  r  r  r  r  r  r  r>   rH   privatePostV5OrderCreateBatchr3  r  parse_orders)rj  r  r  accountsisUtaordersRequestsorderSymbolsr  rawOrderr  r  r  r  r?  orderParamsr  r  r  r  r  r6  r  ry  r|  retInfocodesr  retCodes                               rl  create_orderszbybit.create_ordersE  s      !!!!!!!!!0022222222q#f++&& 	0 	0AayH''(;;H)))##Hf55D##Hf55D__Xx88FOOHg66E..8R@@K44XtT6SXZeglmmLZ(!!,////%%lD%tLLWQZ(("//>SUVWW..~vvNN&	!!(;a(?(?tw)mmnnn %
 
 ;;DKKQW<X<XYYYYYYYY(B77~~ffb11..<<<w33q#e**%% 	5 	5A8D''f55G!||++d1gt44QL   &&&rm  rH   c                    |                      |          }d|d         i}	|                     |dd          }
|
||	d<   n|
|	d<   d }|                     d||          \  }}||	d<   ||                     ||          |	d<   |,|                     ||                     |                    |	d	<   |                     |d
d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|d u}|d u}|d u}|d u}|s|r|r|n|}|?|dk    r|n|                     ||          }||	d
<   |                     |dd          }||	d<   |s|r|rW|                     |d
d|          }|dk    r|n|                     ||          }||	d<   |                     |dd          }||	d<   |rW|                     |d
d|          }|dk    r|n|                     ||          }||	d<   |                     |dd          }||	d<   |                     |g d          }|	S )Nr  rH   rl  rm  r   editOrderRequestr  rr  r?  rE  r  rG  rH  r~  r}  r  	triggerBy	LastPriceslTriggerBytpTriggerBy)r  rG  rH  rE  rm  r~  r}  )	r  r  r  r  r  r  r  r  rr  )rj  rH   r  r  r  r  r?  r  r  r6  rm  r  rE  r  r  r~  r}  r  r  r  r  triggerPriceRequestr  r  stopLossRequestr  r  takeProfitRequestr  s                                rl  edit_order_requestzbybit.edit_order_request  s   V$$fTl
 **6=/RR !#GI%2GM"../A66RR&&
!__VV<<GEN#~~fd6K6KE6R6RSSGG))&.+NN#//HH!%!1!1&:K!L!L??6:66__V\::
.d:2$>d*"$. 	_/ 	_3B^//H^L#3?33F3F,,T^^\bdpMqMq&9GN#((kJJI#,GK  	5- 	5 5!%!3!3Hnk[c!d!d5Cs5J5J..QUQ_Q_`fhvQwQw&5
#"..v}kRR)4& 5!%!3!3JP[]g!h!h7E7L7LNNSWSaSabhjxSySy!(9%"..v}kRR)4&6  $P  $P  $P  Q  Qrm  c           	        K   |                                   d{V  |t          | j        dz             |                     |          }|                     |||||||          }	|                     |                     |	|                     d{V }
|                     |
di           }|                     |
| 	                    |d          | 	                    |d          d|          S )ac  
        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 str [params.clientOrderId]: unique client order id
        :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>`
        Nz' editOrder() requires a symbol argumentry  r   rl  )r  rH   rm  )
r  r4   rH   r  r  privatePostV5OrderAmendr3  r  r  r  )rj  rH   r  r  r  r  r?  r  r  r6  r  ry  s               rl  
edit_orderzbybit.edit_order  s     8 !!!!!!!!!>#DG.W$WXXXV$$))"fdD&%QWXX55dkk'66R6RSSSSSSSS (B77""6955!--fmDD 
  
 	  	rm  c           
        K   |                                   d{V  g }g }t          dt          |                    D ]}||         }|                     |d          }|                    |           |                     |d          }|                     |d          }	|                     |d          }
|                     |d          }|                     |d          }|                     |d	i           }|                     |||	|
|||          }|d
= |                    |           |                     |dddd          }| 	                    |d                   }| 
                    | j        dd          }d}|                     d||          \  }}|dk    r|dk     rt          | j        dz             ||d}|                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     |di           }|                     |dg           }t          dt          |                    D ]E}||         }| 
                    |d          }|dk    r|                     ||         |          ||<   F|                     |          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>`
        Nr   r  rH   r  r  r  r?  r  r  FTr  r  rt   r  r   z@ editOrders does not allow inverse orders for non UTA2.0 accountr  ry  rz  r  r  )r  r  r  r  r  r  r  r  r  r  r  r  r  r>   rH   privatePostV5OrderAmendBatchr3  r  r  )rj  r  r  r  r  r  r  r  rH   r  r  r  r?  r  r  r  r  r  r6  r  ry  r|  r  r  r  r  s                             rl  edit_orderszbybit.edit_orders  s      !!!!!!!!!q#f++&& 	0 	0AayH%%h99F'''!!(D11B##Hf55D##Hf55D__Xx88FOOHg66E..8R@@K222vtT6SXZeffLZ(!!,////**<udDQQ\!_--"//>SUVWW..|VVLL&	!!(;a(?(?tw)kklll %
 
 ::4;;wPV;W;WXXXXXXXX(B77~~ffb11..<<<w33q#e**%% 	5 	5A8D''f55G!||++d1gt44QH   &&&rm  c                 >   |                      |          }d|d         i}|d         r9|                     |ddd          }|                     |ddg          }|rdnd|d	<   |||d
<   d }|                     d||          \  }}||d<   |                     ||          S )Nr  rH   rW   stoprY  Fr  r   r  r   cancelOrderRequestr  )r  safe_bool_2rr  r  r3  )rj  rH   r  r  r  r6  	isTriggerr  s           rl  cancel_order_requestzbybit.cancel_order_requestb  s    V$$fTl
 &> 	K((EJJIYYv	':;;F4=%J[[7GM">!#GI../CVVTT&&
{{7F+++rm  c                 T  K   |t          | j        dz             |                                  d{V  |                     |          }|                     |||          }|                     |           d{V }|                     |di           }|                     ||          S )au  
        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>`
        Nz) cancelOrder() requires a symbol argumentry  )r4   rH   r  r  r  privatePostV5OrderCancelr  r  )rj  rH   r  r  r  requestExtendedr  ry  s           rl  cancel_orderzbybit.cancel_orderw  s       >#DG.Y$YZZZ!!!!!!!!!V$$33BGG66GGGGGGGG (B77///rm  idsc                   K   |t          | j        dz             |                                  d{V  |                     |          }|                                  d{V }|d         }|st          | j        dz             d}|                     d||          \  }}|dk    rt          | j        dz             g }|                     |dd	g           }	|                     |dd	g          }t          d
t          |	                    D ]4}
|                    |d         |                     |	|
          d           5t          d
t          |                    D ]4}
|                    |d         |                     ||
          d           5||d}|                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     ||          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   rH   )r  rl  )r  r   r  ry  rz  )r4   rH   r  r  r  r>   r  safe_list_2rr  r  r  r  r  privatePostV5OrderCancelBatchr3  r  r  r  )rj  r  r  r  r  r  r  r  r  r  r  r6  r  ry  rows                  rl  cancel_orderszbybit.cancel_orders  sp      >#DG.Z$Z[[[!!!!!!!!!V$$--////////$Qx# 	Wtw)UUVVV..~vvNN&y  tw)VVWWW))&2BLRTUU6$4l#CDDq#n--.. 	 	A!! ,#//BB# #     q#c((## 	 	A!! ,++C33# #    
 !%
 
 ;;DKKQW<X<XYYYYYYYYH (B77nnVVR00  f---rm  timeoutc                 N  K   |                                   d{V  d|                     |dz            i}d}|                     dd|d          \  }}dddd	}|                     |||          }||d
<   |                     |                     ||                     d{V }|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
        N
timeWindowr[  r^   rY   r  DERIVATIVESOPTIONS)rW   rY   r[   product)r  r  r  r  'privatePostV5OrderDisconnectedCancelAllr3  )rj  r
  r  r6  r  
productMapr  r  s           rl  cancel_all_orders_afterzbybit.cancel_all_orders_after  s       !!!!!!!!!$++GdN;;
 99:PRVX^`fggf!
 


 "":tT::$	EEdkkRY[aFbFbcccccccc rm  c                   K   |                                   d{V  |                                  d{V }|d         }|st          | j        dz             g }d}t	          dt          |                    D ]}||         }|                     |d          }	|                     |	          }
d}|                     d|
|          \  }}|dk    rt          | j        dz             |||k    rt          | j        d	z             |}|                     |d
          }|                     |d          }d}|d}d|
d
         i}|dk    r|n|||<   |
                    |           ||d}|                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     |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>`
        Nr   z4 cancelOrdersForSymbols() supports UTA accounts onlyr   r  r`   r  z5 cancelOrdersForSymbols does not allow inverse ordersz_ cancelOrdersForSymbols requires all orders to be of the same category(linear, spot or option))rH   rm  r   rl  r  ry  rz  )r  r  r>   rH   r  r  r  r  r  r0   r  r  r3  r  r  r  )rj  r  r  r  r  r  r  r  r  r  r  currentCategoryrH   rm  idKey	orderItemr6  r  ry  r  s                       rl  cancel_orders_for_symbolszbybit.cancel_orders_for_symbols  sS      !!!!!!!!!--////////$Qx# 	atw)__```q#f++&& 	- 	-A1IE%%eX66F[[((F"O&*&9&9.&RX&Y&Y#OV)++"47-d#deee$8+F+F#DG  /P  %P  Q  Q  Q&H!!%..B ,,UODDME(%&,I ',y&8&8rr}Ie!!),,,, %
 
 ;;DKKQW<X<XYYYYYYYYH (B77nnVVR00  d+++rm  c                   K   |                                   d{V  |                                  d{V \  }}|p|}d}i }| |                     |          }|d         |d<   d}|                     d||          \  }}||d<   |dk    r|st	          | j        dz   |z   dz             |d	k    s|d
k    rP|                     |d          }	|8|	6|                     | j        dd          }
|                     |d|
          |d<   |                     |ddd          }| 	                    |ddg          }|rd|d<   | 
                    |                     ||                     d{V }|                     |di           }|                     |d          }t          |t                    s|                     d|i          gS |                     ||          S )aZ  
        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>`
        NrH   r  r]   r  r[   z. cancelAllOrders() Normal Account not support z marketr  r  r  r  r  rC  r  rY  Fr  r  ry  rz  r  )r  r  r  r  r>   rH   r  r  r  rr  privatePostV5OrderCancelAllr3  r  r  
isinstancerz  r  r  )rj  r  r  r  r  r@  r  r6  r  r  r  r  r  ry  r  s                  rl  cancel_all_orderszbybit.cancel_all_orders^  s;       !!!!!!!!!:>:Q:Q:S:S4S4S4S4S4S4S11/G3G[[((F &tGH**+<ffMMf"
H&6tw)YY\``cllmmmH$)"3"3''
;;H~("2 $ 0 0PV W W(,(8(8}(](]%$$VVYFF	6FI#677 	1%0GM"99$++gv:V:VWWWWWWWW: (B77//&$'' 	9OOVX$67788  000rm  c           	      X  K   |t          | j        dz             |                                  d{V  |                     |          }|d         rt	          | j        dz             d|i}|                     |dd|                     ||                     d{V }t          |          }|dk    rD|                     |ddgd	          }|rd
nd}	t          dt          |          z   dz   |	z             |dk    rt          | j        dz             |                     |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 argumentrW   z/ fetchOrder() is not supported for spot marketsr   r   rY  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)r4   rH   r  r  r>   fetch_ordersr3  r  safe_bool_nr=   r  r<   r  )
rj  rH   r  r  r  r6  ry  lengthr  extras
             rl  fetch_order_classiczbybit.fetch_order_classic  s_      >#DG.X$XYYY!!!!!!!!!V$$&> 	\tw)ZZ[[[r
 ((tT[[RX=Y=YZZZZZZZZVQ;;(()V1DeLLI#  OBB  *OE3r77 25F F NOOOA::tw)HHIIIvq)))rm  c                 v  K   |                                   d{V  |                                  d{V \  }}|p|}|s|                     |||           d{V S d}|                     |dd          \  }}|st	          | j        dz             |                     |          }d}	|                     d||          \  }	}|d         ||	d}
d}|                     |dd	d          \  }}|rd
|
d<   | 	                    | 
                    |
|                     d{V }|                     |di           }|                     |dg           }t          |          dk    r+|rdnd}t          dt          |          z   dz   |z             |                     |di           }|                     ||          S )a1  
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>`
        NFr   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 fetchClosedOrderrH   )r  r   r  rY  r  r  r  ry  rz  r   r  r  r  r   )r  r  r&  r  r4   rH   r  r  handle_param_bool_2privateGetV5OrderRealtimer3  r  r  r  r=   r  r  )rj  rH   r  r  r  r  r@  acknowledger  r  r6  r  r  ry  	innerListr%  r  s                    rl  fetch_orderzbybit.fetch_order  s=      !!!!!!!!!:>:Q:Q:S:S4S4S4S4S4S4S11/G3G 	F11"ffEEEEEEEEE";;FLR`aaV 	Q#DG  /P  %P  Q  Q  QV$$
!00vvNN
FTl"
 

 	 44VYPUVV	6 	1%0GM"77GV8T8TUUUUUUUUd (B77NN66266	y>>Q#  OBB  *OE3r77 25F F NOOOy!R00v...rm  c                    K   |                                   d {V }	 |                     |d          }|rt          | j        dz             |                     ||||           d {V S )Nr   z fetchOrders() is not supported after the 5/02 update for UTA accounts, please use fetchOpenOrders, fetchClosedOrders or fetchCanceledOrders)r  r  r>   rH   fetch_orders_classic)rj  r  r  rU  r  resr  s          rl  r"  zbybit.fetch_orders   s      ++--------	   $~~c155 	ytw  *x   x  y  y  y..vueVLLLLLLLLLrm  c                 `  K   |                                   d{V  d}|                     |dd          \  }}|r#|                     d||||dddd	  	         d{V S i }d}| |                     |          }|d         |d	<   d}|                     d||          \  }}|d
k    rt          | j        dz             ||d<   |                     |ddgd          }	|                     |ddg          }|	rd|d<   |||d<   |||d<   | 	                    |d          }
| 	                    |d|
          }|                     |ddg          }|||d<   | 
                    |                     ||                     d{V }|                     |          }|                     ||||          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>`
        NFr   r  r~  r  r   rH   r  rW   z0 fetchOrders() is not supported for spot marketsr  rY  r  r  r  rU  r  r  r  )r  r  fetch_paginated_call_cursorr  r  r>   rH   r#  rr  r  privateGetV5OrderHistoryr3  r  r  rj  r  r  rU  r  r  r6  r  r  r  r  r  r  r|  s                 rl  r/  zbybit.fetch_orders_classic7  sP     & !!!!!!!!!88PZ[[& 	M99-QVX]_egw  zB  DH  JL  M  M  M  M  M  M  M  M  M[[((F &tGH**=&&IIf6>>tw)[[\\\"
$$Vi-@%HH	6Iv#677 	1%0GM"$GG#(GK !!&'22##FIu==6Iw#788!(GI66t{{7F7S7STTTTTTTTf 33H==  vue<<<rm  c           	        K   |                                   d{V  d|i}|                     |dd|                     ||                     d{V }t          |          }|dk    rD|                     |ddgd          }|rdnd}t          d	t          |          z   d
z   |z             |dk    rt          | j        dz             | 	                    |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>`
        Nr   r   rY  r  Fr  r  r  r   r   r!  )
r  fetch_closed_ordersr3  r  r#  r=   r  r<   rH   r  	rj  rH   r  r  r6  ry  r$  r  r%  s	            rl  fetch_closed_orderzbybit.fetch_closed_order  s       !!!!!!!!!r
 //dDKKPWY_D`D`aaaaaaaaVQ;;(()V1DeLLI#  OBB  *OE3r77 25F F NOOOA::tw)HHIIIvq)))rm  c           	        K   |                                   d{V  d|i}|                     |dd|                     ||                     d{V }t          |          }|dk    rD|                     |ddgd          }|rdnd}t          d	t          |          z   d
z   |z             |dk    rt          | j        dz             | 	                    |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>`
        Nr   r   rY  r  Fr  r  r  r   r   r!  )
r  fetch_open_ordersr3  r  r#  r=   r  r<   rH   r  r7  s	            rl  fetch_open_orderzbybit.fetch_open_order  s     $ !!!!!!!!!r
 --fdD$++gW]B^B^________VQ;;(()V1DeLLI#  OBB  *OE3r77 25F F NOOOA::tw)HHIIIvq)))rm  c                 &  K   |                                   d{V  d}|                     |dd          \  }}|r#|                     d||||dddd	  	         d{V S i }d}| |                     |          }|d         |d	<   d}|                     d||          \  }}||d
<   |                     |ddgd          }	|                     |ddg          }|	rd|d<   |||d<   |||d<   |                     |d          }
|                     |d|
          }|                     |ddg          }|||d<   |                     | 	                    ||                     d{V }| 
                    |          }|                     ||||          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>`
        NFr|   r  r~  r  r   rH   r  r  rY  r  r  r  rU  r  r  r  )r  r  r2  r  r  r#  rr  r  r3  r3  r  r  r4  s                 rl   fetch_canceled_and_closed_ordersz&bybit.fetch_canceled_and_closed_orders  s:     & !!!!!!!!!88A_akll& 	^99:XZ`bginpv  yI  KS  UY  []  ^  ^  ^  ^  ^  ^  ^  ^  ^[[((F &tGH**+I6SYZZf"
$$Vi-@%HH	6Iv#677 	1%0GM"$GG#(GK !!&'22##FIu==6Iw#788!(GI66t{{7F7S7STTTTTTTTB 33H==  vue<<<rm  c           	         K   |                                   d{V  ddi}|                     ||||                     ||                     d{V 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>`
        Nrx  rX  r  r=  r3  rj  r  r  rU  r  r6  s         rl  r6  zbybit.fetch_closed_ordersK  sy      & !!!!!!!!!8
 ::65%QUQ\Q\]dflQmQmnnnnnnnnnrm  c           	         K   |                                   d{V  ddi}|                     ||||                     ||                     d{V 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>`
        Nrx  rZ  r?  r@  s         rl  fetch_canceled_orderszbybit.fetch_canceled_ordersd  sy      & !!!!!!!!!;
 ::65%QUQ\Q\]dflQmQmnnnnnnnnnrm  c                 :  K   |                                   d{V  d}|                     |dd          \  }}|r#|                     d||||dddd	  	         d{V S i }d}| |                     |          }|d         |d	<   d}|                     d||          \  }}|d
k    s|dk    rR|                     |d          }	|:|	8|                     | j        dd          }
|                     |d|
          }||d<   ||d<   |                     |ddd          }|                     |ddg          }|rd|d<   |||d<   | 	                    | 
                    ||                     d{V }|                     |          }|                     ||||          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>`
        NFr   r  r~  r  r   rH   r  r  r  r  r  r  rC  r  r  rY  r  r  rU  )r  r  r2  r  r  r  r  r  rr  r*  r3  r  r  )rj  r  r  rU  r  r  r6  r  r  r  r  rC  r  r  r|  s                  rl  r:  zbybit.fetch_open_orders}  s<     ( !!!!!!!!!88ART^__& 	Q99:KVUZ\acik{  ~F  HL  NP  Q  Q  Q  Q  Q  Q  Q  Q  Q[[((F &tGH**+<ffMMf8ty00''
;;H~("2 $ 0 0PV W W!--flMRR
(2%"
$$VVYFF	6FI#677 	1%0GM"$GG77GV8T8TUUUUUUUUB 33H==  vue<<<rm  c           	         K   i }|                      |dd          }|||d<   n||d<   |                     |ddg          }|                     ||||                     ||                     d{V 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>`
        rm  rl  Nr   )r  rr  fetch_my_tradesr3  )rj  rH   r  r  rU  r  r6  rm  s           rl  fetch_order_tradeszbybit.fetch_order_trades  s       **6?MRR$%2GM""!#GI6O]#CDD))&%GU[@\@\]]]]]]]]]rm  c                 V  K   |                                   d{V  d}|                     |dd          \  }}|r#|                     d||||dddd	  	         d{V S dd	i}d}| |                     |          }|d
         |d<   d}|                     d||          \  }}||d<   |||d<   |||d<   |                     d||          \  }}|                     |                     ||                     d{V }	|                     |	          }
| 	                    |
|||          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>`
        NFr   r  r~  r  rS  execTyper)   rH   r  r  rU  r  r  )
r  r  r2  r  r  r  privateGetV5ExecutionListr3  r  r  )rj  r  r  rU  r  r  r6  r  r  r  r  s              rl  rE  zbybit.fetch_my_trades  s      !!!!!!!!!88R\]]& 	P99/6SXZ_agiy  |D  FJ  LO  P  P  P  P  P  P  P  P  P
 [[((F &tGH**?FFKKf"
$GG#(GK 229gvNN77GV8T8TUUUUUUUUR 55h??  >>>rm  c                    |                      |d          }|                      |d          }|                      |d          }|                     |           |||                     |                      |d          |          ||dS )NaddressDeposit
tagDepositr  r  )r  r  r  addresstag)r  check_addressr  )rj  depositAddressr  rM  rN  r  s         rl  parse_deposit_addresszbybit.parse_deposit_addressS  s     "">3CDD~|<<&117###"..t/?/?PW/X/XZ^__
 
 	
rm  r  c                 l  K   |                                   d{V  |                     |          }d|d         i}d}|                     |          \  }}||                     ||          |d<   |                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     |d          }	|                     |	          }| 	                    ||d         gdd	|d         i          }
| 
                    |
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
        Nr  rH   	chainTypery  r  r  Fr  r  )r  r  handle_network_code_and_paramsnetwork_code_to_id$privateGetV5AssetDepositQueryAddressr3  r  r  r  parse_deposit_addressesindex_by)rj  r  r  r  r6  r  r  ry  r  r  parseds              rl  "fetch_deposit_addresses_by_networkz(bybit.fetch_deposit_addresses_by_networkh  s[      !!!!!!!!!==&&HTN
 "AA&IIV"#'#:#:;#M#MGK BB4;;wX^C_C_````````( (B77"55//==&&--fx7G6H%(R
   }}VY///rm  c                   K   |                                   d{V  |                     |          }|                     |          \  }}|                     ||           d{V }|                     |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>`
        Nr  )r  r  rT  rZ  )select_network_code_from_unified_networks)rj  r  r  r  r  paramsOmitedindexedAddressesselectedNetworkCodes           rl  fetch_deposit_addresszbybit.fetch_deposit_address  s       !!!!!!!!!==&&$($G$G$O$O!\!%!H!H|!\!\\\\\\\"LLXV\M]_jl|}} 344rm  c                   K   |                                   d{V  d}|                     |dd          \  }}|r#|                     d||||dddd	  	         d{V S i }d}| |                     |          }|d         |d	<   |||d
<   |||d<   |                     d||          \  }}|                     |                     ||                     d{V }|                     |          }	|                     |	|||          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>`
        NFr   r  r~  r  r   rH   r  r  rU  r  )	r  r  r2  r  r  #privateGetV5AssetDepositQueryRecordr3  r  parse_transactions
rj  r  r  rU  r  r  r6  r  r  r|  s
             rl  fetch_depositszbybit.fetch_deposits  s       !!!!!!!!!88R\]]& 	M99/4QVX]_egw  zB  DH  JL  M  M  M  M  M  M  M  M  M

 }}T**H&tnGFO#(GK $GG229gvNNAA$++gW]B^B^________8 33H==&&tXueDDDrm  c                   K   |                                   d{V  d}|                     |dd          \  }}|r#|                     d||||dddd	  	         d{V S i }d}| |                     |          }|d         |d	<   |||d
<   |||d<   |                     d||          \  }}|                     |                     ||                     d{V }|                     |          }	|                     |	|||          S )aY  
        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>`
        NFr   r  r~  r  r   rH   r  r  rU  r  )	r  r  r2  r  r  $privateGetV5AssetWithdrawQueryRecordr3  r  rc  rd  s
             rl  fetch_withdrawalszbybit.fetch_withdrawals  s      !!!!!!!!!88ASU_``& 	P99:LdTY[`bhjz  }E  GK  MO  P  P  P  P  P  P  P  P  P

 }}T**H&tnGFO#(GK $GG229gvNNBB4;;wX^C_C_````````T 33H==&&tXueDDDrm  c                 N    ddddddddddddd	}|                      |||          S )
Nr  pending
processingokfailrM  rQ  failed)r  r   2r   4SecurityCheckPendingsuccessCancelByUserRejectFailBlockchainConfirmedr_  r`  s      rl  parse_transaction_statuszbybit.parse_transaction_status9  sN     & & #'
 
  &&999rm  transactionc                    |                      |d          }|                     ||          }|                     |dd          }|                     |d          }|                     |                      |d                    }|                     |dd          }d|v rdn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S ) Nr  
createTime	successAt
updateTimer"  
depositFeer  rc  
withdrawalrz  	toAddressr  rH   
withdrawIdtxidtxIDr  r  r  r  rM  	addressToaddressFromrN  tagTotagFromr  r  r  updated)r  internalcomment)
r  r  r  r  rx  rU  r  rS  r  r  )rj  ry  r  r  r  r  r  r"  feeCostr  r  r  s               rl  parse_transactionzbybit.parse_transactionL  s7   R %%k6::
&&z8<<''\;OO	##K>>..t/?/?X/V/VWW$$[,NN)[88yy|  C $$[+>>	
K
$$$[$EE
 D$$[&99
 	

 Y//
 t..t/?/?W/U/UW[\\
 t
 
 4
 4##K77
 T
 t
 D
 d&&{H==
 
  f!
" w#
$ )
 
 
 	
rm  c                   K   |                                   d{V  d}|                     |dd          \  }}|r#|                     d||||dddd	  	         d{V S i }|                                  d{V }d}d}	|d	         r
d
}	|||d<   n||                     |          |d<   | |                     |          }|d         ||	<   |||d<   d}
|                     dd|          \  }
}d}|d	         r|                     | j        dd          }|
dk    r6|dk     r0| 	                    | 
                    ||                     d{V }n_|                     | 
                    ||                     d{V }n/| 	                    | 
                    ||                     d{V }|                     |          }|                     ||||          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-entry-structure>`
        NFr   r  r~  r  r   r  r   r  r  
start_daterH   rU  r  r   r  )r  r  r2  r  yyyymmddr  r  r  r  )privateGetV5AccountContractTransactionLogr3  !privateGetV5AccountTransactionLogr  parse_ledger)rj  r  r  rU  r  r  r6  enableUnifiedr  currencyKeyr  r  r  r|  s                 rl  fetch_ledgerzbybit.fetch_ledger  s      !!!!!!!!!88PZ[[& 	K99-uV[]ceuw  BF  HJ  K  K  K  K  K  K  K  K  K
& #5577777777 	=$K ',$ (,e(<(<%}}T**H#+D>GK $GG99-vVV 	j"&"3"3DLBWYZ"["[)##)<q)@)@!%!O!OPTP[P[\cekPlPl!m!mmmmmmm!%!G!GT[]cHdHd!e!eeeeeee!KKDKKX_agLhLhiiiiiiiiHP 33H==  x>>>rm  itemc                    |                      |dd          }|                     ||          }|                     ||          }|                      |dd          }|                      |dd          }t          j        |d          rdnd	}d }d }	d }
|||dk    r|nt          j        |          }|                     t          j        ||                    }|                     |          }	|                     t          j        |                    }
| 	                    | 
                    |d
                    }||                     |d          }|                     || 
                    |d          || 
                    |d          | 
                    |d          d |                     | 
                    |d                    ||
||                     |          ||	d||                     |d          dd|          S )Nr  r  r  r  wallet_balancecashBalancer  outin	exec_timetransactionTimerH   	wallet_idtx_idr  rl  r  )r  r  )r  rH   	directionr0  referenceIdreferenceAccountr  r  r  r  r  beforeafterr"  r  )r  r  safe_currencyrC   	string_lt
string_negparse_to_numericr1  
string_absr  r  r  safe_ledger_entryparse_ledger_entry_typerS  r  )rj  r  r  r  r  r  afterStringr  r  r  r  
differencer  s                rl  parse_ledger_entryzbybit.parse_ledger_entryE  s"   J ''fjAA
&&z8<<%%j(;;))$(CC((/?OO$.|SAAKEEt	"|'?*3u*<*<7CUVbCcCcJ**7+=k:+V+VWWF))+66E**7+=l+K+KLLFNN4#3#3D+#F#FGG	))$0ABBI%%""4.."''k::++D':: $001A1A$1O1OPP"Y// ((u55 '
 '
& '  	rm  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}|                      |||          S )NDepositry  WithdrawRealisedPNLr  
Commissionr  RefundcashbackPrizeprizeExchangeOrderWithdrawExchangeOrderDepositTRANSFER_INTRANSFER_OUTTRADE
SETTLEMENTDELIVERYLIQUIDATIONBONUS
FEE_REFUNDINTEREST)CURRENCY_BUYCURRENCY_SELLr_  )rj  r  r  s      rl  r  zbybit.parse_ledger_entry_type  s   
}

 7
 %	

 j
 W
 $]
 #M
 =
 M
 W
 '
 
 7
  W!
" *#
$ %
& $$)
 
 
, tT222rm  rM  rN  c                   K   |                      ||          \  }}d}|                                  d{V }|d         }|                     |dd          \  }}||rdnd}|                                  d{V  |                     |           |                     |          }	|	d         |                     |          ||                                 |d}
|||
d	<   |                     |          \  }}| 	                    ||          }||
                                |
d
<   |                     |                     |
|                     d{V }|                     |di           }|                     ||	          S )a8  
        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
        :param str [params.accountType]: 'UTA', 'FUND', 'FUND,UTA', and 'SPOT(for classic accounts only)
        :returns dict: a `transaction structure <https://docs.ccxt.com/?id=transaction-structure>`
        Nr   r   r!  UTAr  rH   )r  r  rM  r  r!  rN  r  ry  )handle_withdraw_tag_and_paramsr  r  r  rO  r  r  rv  rT  rU  upper privatePostV5AssetWithdrawCreater3  r  r  )rj  r  r  rM  rN  r  r!  r  r  r  r6  r  queryr  r  ry  s                   rl  r   zbybit.withdraw  s      99#vFFV0022222222";;FJP]^^V#(4%%fK!!!!!!!!!7###==&&TN++F33**,,&
 
 ? GEN!@@HHU++K>>	 (00GG>>t{{7TY?Z?Z[[[[[[[[ (B77%%fh777rm  c                 p  K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}d}d}|                     d||          \  }}||d<   |                     |                     ||                     d{V }|                     |di           }|                     |dd	g           }| 	                    |d
          }	|                     |di           }
| 
                    |
|          }|	|d<   |                     |	          |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  rH   r   r  ry  rz  r}  r  r   r  r  )r4   rH   r  r  r  privateGetV5PositionListr3  r  r  r  parse_positionrS  )rj  r  r  r  r6  r  r  ry  	positionsr  r  positions               rl  fetch_positionzbybit.fetch_position  sa      >#DG.[$[\\\!!!!!!!!!V$$fTl
 **?FFKKf"
66t{{7F7S7STTTTTTTTR (B77$$VVZDD	%%h77	y!R00&&uf55 )#||I66rm  c                 8  K   |                                   d{V  d}|                     |dd          \  }}|r#|                     d|dd|dddd	  	         d{V S d}|et          |t                    rPt          |          }|dk    rt          | j        d	z             |dk    r|d
         }|                     |          }n||}| 	                    |          g}i }d}|(| 
                    |          }|d         }|d         |d<   d}|                     d||          \  }}|dk    s|dk    rb|                     |d          }	|dk    r=|:|	8|                     | j        dd          }
|                     |d|
          }||d<   n	||	d|d<   |                     |d          d|d<   |                     |dg          }||d<   |                     |                     ||                     d{V }|                     |          }g }t'          d
t          |                    D ]P}||         }d|v rd|v r|                     |d          }|                    |                     |                     Q|                     |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>`
        NFr   r  r~  r  r  r   zD fetchPositions() does not accept an array with more than one symbolr   r  rH   r  r  r  r  r  rC  r  rU  r  r|  is_valid)r  r  r2  r  rz  r  r4   rH   r  r  r  r  r  r  r  rr  r  r3  r  r  r  r  r  filter_by_array_positions)rj  r  r  r  r  r  r6  r  r  r  r  rC  r  r  resultsr  rawPositions                    rl  fetch_positionszbybit.fetch_positions$  sP      !!!!!!!!!88AQS]^^& 	P99:JGUY[_agiy  |D  FJ  LO  P  P  P  P  P  P  P  P  PZ%>%>LLMq  '2x(xyyy!## ))'22GG F{{6**+G[[((FH%F &tGH**+;VVLLf8ty00''
;;Hx>h&6$($4$4T\?TZ$[$[M!%!1!1&,!V!VJ,6GL) >h&6*3GJ'VW--5"GG6F8,,"
66t{{7F7S7STTTTTTTTH 88BB	q#i..)) 	= 	=A#A,K+%%J+,E,E"nn[&AANN4..{;;<<<<--gx%PPPrm  r  c                 b   |                      |d          }|d u}|                      |d          }|                     ||d d          }t          j        |                     |dd                    }|                      |d          }|                      |d          }d }	||dk    }	|	|	r|d	k    rd
nd}n||dk    r|rdnd
}n|dk    r|rd
nd}nd }d }
|                      |d          }|                      |d          }|d         r)t          j        t          j        ||          |          }
n|                     |dd          }
|                     |                      |d                    }|                     |dd          }|                      |d          }|                     |ddg          }| 	                    |                      |d                    }||                     |g d          }|                      |d          }|                     | 
                    |g d                    }|                     |                      |d                    }|                      |d          }||d         d k    r|                     | j        d!d"          r|n|}t          j        t          j        ||                    }t          j        t          j        t          j        ||          |          |          }n|                      |d#          }|d$         rit          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%          }|                     i d&|d'd d|d         d(|d)|                     |          d*|d+|                     |          d,|                     t          j        ||
                    d-|                     |          d.|                     |          d/|                     |          d0|                     |
          d|                     |          d1|                     |          d2|                     |d3d4          d5|                     |          d|                     |d          |                     |          |                     |          |                     |          |                     |d6          |                     |          d |d |                     |d7d8          |                     |d9d:          |	d;          S )<N
closedSizer  r  r  rr  r  r  r  r   longshortBuySellr  r  r  positionValuecumExitValueunrealisedPnl
positionIMcumEntryValue
positionMMro  rp  
updated_at)rv  rw  rv  positionBalance)
entryPricer{  avgEntryPriceliqPricerO  r  r  r:  F	bustPricer  r  r  rH   r  r  r  initialMargininitialMarginPercentagemaintenanceMarginmaintenanceMarginPercentager  notionalunrealizedPnlrealizedPnlcurRealisedPnl	closedPnl	contractsavgExitPrice	stop_lossr~  take_profitr}  )marginRatioliquidationPricer  rm  
collateralrD  r  r`  rG  rH  rK  )r  r  rC   r  r  
string_divr  rQ  r  r  r  r  r  
string_subr1  safe_positionrS  r  rU  r  )rj  r  r  r  	isHistoryr  r  r  r  rK  r  r  r  r  initialMarginStringmaintenanceMarginStringr  r  collateralStringr  r  rO  r?  r  r   maintenanceMarginPriceDifferencemultiplyr  r  s                                rl  r  zbybit.parse_position  s   P %%h==
t+	##Hh77!!(FD*EE!$"4"4Xvu"M"MNN&11&&x??"!S(FF)S0066wDDu}}"+7ww!*7vv''??$$X{;;	) 	U)'*<T<*P*PR[\\HH))(O^TTHt'7'7/'R'RSS"00<YY"&"2"28\"J"J''=+2NOO	"nnT-=-=h-U-UVV&"&"5"5h@k@k@k"l"l++H6GHH^^D$6$6xAlAlAl$m$mnn
>>$*:*:8Z*P*PQQ##Hj99'h6))%)^^DLBegl%m%m}		s}$/0B5JZ0[0[\\
#*#5g6HI[\fhlImIm  pG  7H  7H  JW  $X  $X   ,,X{CC	(# q
 8?7I'J\]moxJyJy7z7z4.5.@Aacg.h.h+".5H5P.5.@ASTXZdAeAego.p.p+ ")!3G4FyRb4c4c!d!dJ&1)=MNNH.5.@ASTXZdAeAego.p.p+".5H5P.5.@wGYZdfnGoGo.p.p+&-&89PRZ&[&[#()@BRTUVV!! #
H#
$#
 fX&#
 	#

 Y//#
 "#6#
 T../BCC#
 &t'8'89KL_ai9j9j'k'k#
  !2!23J!K!K#
 *4+<+<=X+Y+Y#
 $++J77#
 ))(33#
 ))(33#
 T..}==#
 4--h8H+VV#
  **400!#
" D,,V^DD##
$  ,,[99 $ 1 12B C C**955))(NCC++,<==!//+zRR#11(M<XX9#
 #
 #
   	rm  c                    K   |                                   d{V  |                     |          }|                     ||           d{V }|                     ||          S )aT  
        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>`
        N)r  r  r  parse_leverage)rj  r  r  r  r  s        rl  fetch_leveragezbybit.fetch_leverages  sz       !!!!!!!!!V$$,,VV<<<<<<<<""8V444rm  rO  c                     |                      |d          }|                     |d          }||                     ||          |                     |d          ||dS )Nr  rO  rD  )r  r  rD  longLeverageshortLeverage)r  r  r  re  )rj  rO  r  r  leverageValues        rl  r  zbybit.parse_leverage  sj    ##Hh77))(J??&&x8800<HH)*
 
 	
rm  rD  c                   K   |                                   d{V  |                                  d{V \  }}|p|}d}d}|rg|dk    rd}n)|dk    rd}n |dk    rd}nt          | j        dz             d	|i}	|                     |                     |	|                     d{V }n|t          | j        d
z             |                     |          }|d         dk    }
|
r^|dk    rd}n |dk    rd}nt          | j        dz             d	|i}	|                     |                     |	|                     d{V }n$d}|                     d||          \  }}d}|dk    rd}n |dk    rd}nt          | j        dz             d}d}| 	                    |d          }|j| 
                    |dd          }| 
                    |dd          }||t          | j        dz             ||}||}|                     |g d          }n|}|}|                     |d          }||d         |||d}	|                     |                     |	|                     d{V }|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
        NisolatedISOLATED_MARGINcross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]rO  sell_leveragesellLeveragebuy_leveragebuyLeveragez[ setMarginMode() requires a leverage parameter or sell_leverage and buy_leverage parameters)r  r  r  r  rH   )r  r  	tradeModer  r  )r  r  r>   rH   !privatePostV5AccountSetMarginModer3  r4   r  r  r  r  rr  #privatePostV5PositionSwitchIsolated)rj  rD  r  r  r  r  r@  r  r  r6  isUsdcSettledr  r  r  r  rO  s                   rl  set_margin_modezbybit.set_margin_mode  se      !!!!!!!!!:>:Q:Q:S:S4S4S4S4S4S4S11/G3G ?	hZ''.

w&&-

{**/

"47-v#vwwwG "CCDKKPWY_D`D`aaaaaaaaHH~'2x(xyyy[[((F"8,6M -h((!1JJ;..!3JJ&tw  2A  (A  B  B  B#Z! "&!G!GT[]cHdHd!e!eeeeeee#223DffUUf 	(( !II:-- !II&tw1{'{|||#"++FJ??##'#5#5fo~#^#^L"&"4"4V^]"["[K#+0C/  ;X  1X  Y  Y  Y"*&2#+'2!YYv/o/o/oppFF#+L"*K!YYvz::F $$Tl!*#.$0! ! "&!I!I$++V]_eJfJf!g!gggggggrm  c                   K   |t          | j        dz             |                                  d{V  |                     |          }|                     |          }|d         ||d}||d<   ||d<   |d         rd|d<   n%|d	         rd	|d<   nt          | j        d
z             |                     |                     ||                     d{V }|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
        Nz) setLeverage() requires a symbol argumentrH   )r  r  r  r  r  r  r  r  z5 setLeverage() only support linear and inverse market)r4   rH   r  r  r  r>    privatePostV5PositionSetLeverager3  )rj  rO  r  r  r  leverageStringr6  r  s           rl  set_leveragezbybit.set_leverage  s!      >#DG.Y$YZZZ!!!!!!!!!V$$
 ..x88Tl)*
 

 "0"0( 	b"*GJI 	b"+GJtw)``aaa>>t{{7TZ?[?[\\\\\\\\rm  rK  c                   K   |                                   d{V  d}||                     |          }d}|rd}nd}d|i}|d|d<   n|d         |d<   ||d	         rd	nd
|d<   n!d}|                     d||          \  }}||d<   |                     |d          }|                     |                     ||                     d{V }|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  rH   r  r  r  r  r   r  )r  r  r  rr  privatePostV5PositionSwitchModer3  )	rj  rK  r  r  r  r  r6  r  r  s	            rl  set_position_modezbybit.set_position_mode  s'      !!!!!!!!![[((F 	DDDD
 >$GFOO &tGH.4X.>"M((IGJD../@&&QQLD&"&GJ66**==dkk'SY>Z>Z[[[[[[[[ rm  r   c                 (  K   |                                   d {V  |                     |          }|d         rdnd}|                     |d|          }|                     | j        d          }	|                     |	|          }
|
t          | j        dz   |z   dz             |d         |
|d}|||d	<   |                     |d
          }|                     |d
g          }|||d<   |||d<   | 	                    | 
                    ||                     d {V }|                     |di           }|                     |          }|                     |d          }|                     ||d d          }|                     ||||          S )Nr  r  r  r9  z+ fetchOpenInterestHistory() cannot use the 
 timeframerH   r  intervalTimer  r  r  r  rU  ry  r  r  )r  r  r  r  r  r5   rH   r  rr  publicGetV5MarketOpenInterestr3  r  r  parse_open_interests_history)rj  r  r  r  rU  r  r  r  r  r9  r  r6  r  r  ry  r|  rH   s                    rl  'fetch_derivatives_open_interest_historyz-bybit.fetch_derivatives_open_interest_history5  s     !!!!!!!!!V$$$X.=((I##FJ@@NN4<==	##Iy99TW'TTW``coopppTl$ 
 

 #(GK !!&'226G9--!&GI$GG;;DKKQW<X<XYYYYYYYY0 (B7733H==fh//!!"fdJ??00vueLLLrm  c                   K   |                                   d{V  |                     |          }|d         st          | j        dz             |                     |dd          }|                     | j        d          }|                     ||          }|t          | j        dz   |z   dz             |d	         rd	nd
}|                     |d|          }|d         ||d}	|                     |                     |	|                     d{V }
|                     |
di           }|                     |d          }| 	                    ||dd          }| 
                    |
          }|                     |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:
        Nr  z3 fetchOpenInterest() supports contract markets onlyr  r   r9  z$ fetchOpenInterest() cannot use the r"  r  r  r  rH   r#  ry  r  r   )r  r  r5   rH   r  r  r  r%  r3  r  r  parse_open_interest)rj  r  r  r  r  r9  r  r  r  r6  r  ry  rH   r|  s                 rl  fetch_open_interestzbybit.fetch_open_interesti  s      !!!!!!!!!V$$j! 	^TW'\\]]]$$VZ>>	NN4<==	##Iy99TW'MMPYY\hhiii$X.=((I##FJ@@Tl$ 
 

 ;;DKKQW<X<XYYYYYYYY0 (B77fh//!!"fdJ??33H==''Q888rm  c                   K   |dk    rt          | j        dz             |                                  d{V  |                     |d          }|r>|                     |d          }||d<   |                     d||||dddd		  	         d{V S |                     |          }|d
         s|d         rt          | j        dz   |z             d|d         i}|||d<   |                     |||||           d{V 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 timeframeNr  r  r   r~  r  r  rW   r[   z; fetchOpenInterestHistory() symbol does not support market r  rH   rU  )r5   rH   r  r  rr  r2  r  r'  )	rj  r  r  r  rU  r  r  r  r6  s	            rl  fetch_open_interest_historyz!bybit.fetch_open_interest_history  s      TW'^^___!!!!!!!!!>>&*55 	[YYvz22F"+F;99:TV\^cejlr  uE  GO  QU  WZ  [  [  [  [  [  [  [  [  [V$$&> 	oVH- 	oTW'ddgmmnnnfTl
 $GGAA&)UZ\acijjjjjjjjjrm  c           	          |                      |d          }|                     |dd          }|d         r|nd }|d         r|nd }|                     |d         ||||                     |          |d|          S )Nr  open_interestopenInterestr  r  r  )r  openInterestAmountrl  r  r  r  )r  rU  safe_open_interestrS  )rj  r+  r  r  r/  r  values          rl  r)  zbybit.parse_open_interest  s     %%h<<	))(O^TT!'!1;t &y 1;t&&X&"(!&"Y//(
 (
   	rm  c                 f  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |d          }|                     |di           }||d<   |                     ||          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>`
        Nr  rH   r  ry  r  )r  r  (privateGetV5SpotCrossMarginTradeLoanInfor3  r  r  parse_borrow_rate)rj  r  r  r  r6  r  r  r|  s           rl  fetch_cross_borrow_ratezbybit.fetch_cross_borrow_rate  s       !!!!!!!!!==&&HTN
 FFt{{SZ\bGcGcdddddddd %%h77	~~h"55%[%%dH555rm  c                    |                      |d          }|                     |dd          }|                     |d          }|dnd}|                     ||          |                     |d|          |||                     |          |dS )	Nr  r  r  hourlyBorrowRatei6 i \&r  )r  r  periodr  r  r  )r  r  r  r  rS  )rj  r  r  r  r  r8  r9  s          rl  r5  zbybit.parse_borrow_rate  s    $ %%dK88	''fjAA
++D2DEE-9//
HEE$$T>;KLL"Y//
 
 	
rm  c                 T  K   |                                   d{V  i }|                     |                     ||                     d{V }|                     |di           }|                     |dg           }	|                     |	d          }
|                     |
|||          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>`
        Nry  r  )r  r=  r3  r  r  parse_borrow_interestsfilter_by_currency_since_limit)rj  r  r  r  rU  r  r6  r  r|  r{  r+  s              rl  fetch_borrow_interestzbybit.fetch_borrow_interest  s       !!!!!!!!!EEdkkRY[aFbFbcccccccc4 ~~h"55~~d$5r::..tT::228T5%PPPrm  c                   K   |                                   d{V  |                     |          }d|d         i}||                                 dz
  }||d<   |                     |dd          }|                     |dg          }||dz   }||d<   |                     |                     ||                     d{V }|                     |d          }	|                     |	d	g           }
| 	                    |
|||          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>`
        Nr  rH   l    H4 r  r  r  ry  rz  )
r  r  rv  r  rr  .privateGetV5SpotMarginTradeInterestRateHistoryr3  r  r  parse_borrow_rate_history)rj  r  r  rU  r  r  r6  r  r  r|  r{  s              rl  fetch_borrow_rate_historyzbybit.fetch_borrow_rate_historyH  s2      !!!!!!!!!==&&
 =%%''-7E$%%fgyAA6G9--?m+G$	LLT[[Y`bhMiMijjjjjjjj& ~~h11~~dFB//--dD%GGGrm  r  c           
          |d |                      |                     |d                    |                     |d          d |                     |d          dd d d	S )Nr.  r+  r*  r  )	r  r  r  r+  r  amountBorrowedrD  r  r  )r  r  r  )rj  r  r  s      rl  parse_borrow_interestzbybit.parse_borrow_interesty  sl     //0@0@y0Q0QRR((z:: "..tV<<!

 

 
	
rm  fromAccount	toAccountc           
      R  K   |                                   d{V  |                     |d|                                           }|                     | j        di           }|                     |||          }|                     |||          }	|                     |          }
|                     ||          }|||	|
d         |d}|                     |                     ||                     d{V }| 	                    |d          }|                     |di           }| 
                    |dd	g          }|                     |          }|                     |                     ||
          ||                     |          |                     |          |||d
          S )ar  
        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>`
        N
transferIdr3  rH   )rH  fromAccountTypetoAccountTyper  r  r  ry  r  retMsg)r  r  r  rE  rF  r"  )r  r  uuidr  r  r  currency_to_precision'privatePostV5AssetTransferInterTransferr3  r  r  parse_transfer_statusparse_transferrS  r  )rj  r  r  rE  rF  r  rH  rD  fromIdtoIdr  amountToPrecisionr6  r  r  r   	statusRawr"  s                     rl  r   zbybit.transfer  s      !!!!!!!!!%%flDIIKKHH
~~dl4DbII!!,[IIiCC==&& 66tVDD$%!TN'
 
 EEdkkRY[aFbFbcccccccc %%h77	>>(Hb99&&x)X1FGG	++I66{{4..xBB"Y//''(9::&"E
 E
   	rm  c                   K   |                                   d{V  d}|                     |dd          \  }}|r#|                     d||||dddd	  	         d{V S d}i }| |                     |          }|d         |d	<   |||d
<   |||d<   |                     d||          \  }}|                     |                     ||                     d{V }|                     |          }	|                     |	|||          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>`
        NFr   r  r~  r  r   rH   r  r  rU  r  )	r  r  r2  r  r  /privateGetV5AssetTransferQueryInterTransferListr3  r  parse_transfers)
rj  r  r  rU  r  r  r  r6  r  r|  s
             rl  fetch_transferszbybit.fetch_transfers  s      !!!!!!!!!88AQS]^^& 	N99:JDRWY^`fhx  {C  EI  KM  N  N  N  N  N  N  N  N  N))$//H&tnGFO#(GK $GG229gvNNMMdkkZaciNjNjkkkkkkkk. 33H==##D(E5AAArm  c                 Z  K   |                                   d{V  |                     |          }|d         |                     ||          d}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  
        create a loan to borrow margin

        https://bybit-exchange.github.io/docs/v5/account/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>`
        NrH   r  r  ry  )r  r  rM  privatePostV5AccountBorrowr3  r  parse_margin_loan)rj  r  r  r  r  r6  r  ry  s           rl  borrow_cross_marginzbybit.borrow_cross_margin  s       !!!!!!!!!==&&TN00v>>
 
 88Wf9U9UVVVVVVVV (B77%%fh777rm  c                   K   |                                   d{V  |                     |          }|d         |                     |          d}|                     |                     ||                     d{V }|                     |di           }|                     ||          }|                     |d|i          S )a  
        repay borrowed margin and interest

        https://bybit-exchange.github.io/docs/v5/account/no-convert-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>`
        NrH   rZ  ry  r  )r  r  r  "privatePostV5AccountNoConvertRepayr3  r  r\  )	rj  r  r  r  r  r6  r  ry  ry  s	            rl  repay_cross_marginzbybit.repay_cross_margin  s       !!!!!!!!!==&&TN++F33
 
 @@WV\A]A]^^^^^^^^ (B77,,VX>>{{;f)
   	rm  c                     |                      |d          }d |                     ||          |                      |d          d d d |dS )Nr  r  )rH   r  r  r  r  r  r  )r  r  )rj  r  r  r  s       rl  r\  zbybit.parse_margin_loan@  s]     %%dF33
//
HEE&&tX66
 
 	
rm  c                 <    dddd}|                      |||          S )Nrl  )r  OKSUCCESSr_  r`  s      rl  rO  zbybit.parse_transfer_statusZ  s1    
 

 &&999rm  r   c                 J   |                      |d          }|                     |d          }|                      |d          }|                      |d          }|                     | j        di           }|                      |||          }|                      |||          }	||                      |d          ||                     |          |                     ||          |                     |d          ||	|                     |                      |d                    d		S )
Nr  r  rI  rJ  r4  rH  r  r"  )	r  rH   r  r  r  r  rE  rF  r"  )r  r  r  r  rS  r  r  rO  )
rj  r   r  r  r  fromAccountIdtoAccountId
accountIdsrE  rF  s
             rl  rP  zbybit.parse_transferb  s"   ( %%h77
%%h<<	((3DEE&&xAA^^DL."EE
&&z=-PP$$ZkJJ	""8\::"Y////
HEE&&x::&"001A1A(H1U1UVV

 

 
	
rm  c                   K   |                                   d {V  |                     |          }d|d         i}|d         rd|d<   n|d         rd|d<   |                     |                     ||                     d {V }|                     |d          }|                     |d          }|                     ||          S )Nr  rH   r  r  r  ry  rz  )r  r  publicGetV5MarketRiskLimitr3  r  r  parse_market_leverage_tiers)rj  r  r  r  r6  r  ry  tierss           rl  'fetch_derivatives_market_leverage_tiersz-bybit.fetch_derivatives_market_leverage_tiers  s      !!!!!!!!!V$$fTl
 ( 	,"*GJI 	,"+GJ88Wf9U9UVVVVVVVV0 (33vv..//v>>>rm  c                   K   |                                   d{V  i }d}|                     |          }|d         s|d         rt          | j        dz   |z             |d         |d<   |                     ||           d{V 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>`
        NrW   r[   z; fetchMarketLeverageTiers() symbol does not support market rH   r  )r  r  r5   rH   rm  )rj  r  r  r6  r  s        rl  fetch_market_leverage_tiersz!bybit.fetch_market_leverage_tiers  s       !!!!!!!!!V$$&> 	oVH- 	oTW'ddgmmnnn"4LAA&&QQQQQQQQQrm  r  c                     |                      |d          }||d         nd}|                     ||d |          }|||                     |d          |                     |d          d d dS )Nr  r  r  makerFeeRatetakerFeeRate)r  r  rb  ra  r`  r_  r  r  r  )rj  r  r  r  r  r  s         rl  parse_trading_feezbybit.parse_trading_fee  s     ##C22)/);fVnn*!!(FD+FF%%c>::%%c>::
 
 	
rm  c                   K   |                                   d{V  |                     |          }d|d         i}d}|                     d||          \  }}||d<   |                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     |di           }	|                     |	|          S )	aR  
        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>`
        Nr  rH   r   r  ry  rz  r   )r  r  r  privateGetV5AccountFeeRater3  r  r  rt  )
rj  r  r  r  r6  r  r  ry  r   r  s
             rl  fetch_trading_feezbybit.fetch_trading_fee  s      !!!!!!!!!V$$fTl
 ../@&&QQ&&
88Wf9U9UVVVVVVVV$ (B77~~ffb11tQ++%%eV444rm  c                   K   |                                   d{V  d}|                     |ddd          \  }}|dk    rt          | j        dz             |                     |           d{V }|                     |di           }|                     |dg           }i }t          d	t          |                    D ]*}| 	                    ||                   }|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  rZ   rW   z4 fetchTradingFees() is not supported for spot marketry  rz  r   r  )
r  r  r>   rH   rv  r  r  r  r  rt  )	rj  r  r  r  r   ry  r  r  r  s	            rl  fetch_trading_feeszbybit.fetch_trading_fees  s      !!!!!!!!!44V=OQWYabbf6>>tw)__```88@@@@@@@@$ ~~h"55~~dFB//q#d))$$ 	! 	!A((a11C]F F6NNrm  c                    |                      |dg           }t          |          }|d d dd d di d}|dk    rt          d|          D ]}||         }|                     |d          }|                     |d          }	|                     ||	          }
d d d|                     |d          ddd	|d
         |
<   |dk    r*|                     |d          |d         d<   d|d         d<   |S )Nr  )r  r`  )r  r   rc  r5  r   r  r  r  F)rc  r   r5  r   r   r  r`  )r  r  r  r  r  r  )rj  r  r  r  chainsLengthry  r  r  r  currencyCoder  s              rl  parse_deposit_withdraw_feez bybit.parse_deposit_withdraw_fee)  sF   * Xr226{{" 
 "  
 
 11l++ = =q	 ,,UG<<	#//&AA"55iNN'+4@@(,(8(8(N(N^c d d3 3z";/  1$$040@0@0V0VF:&u-7<F:&|4rm  r  c                 "  K   |                                   |                                  d{V  |                     |           d{V }|                     |di           }|                     |dg           }|                     ||d          S )a`  
        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>`
        Nry  r{  r  )r  r  r  r  r  parse_deposit_withdraw_fees)rj  r  r  r  r|  r{  s         rl  fetch_deposit_withdraw_feesz!bybit.fetch_deposit_withdraw_fees[  s       	'')))!!!!!!!!!<<VDDDDDDDD> ~~h"55~~dFB////eVDDDrm  c                 ^  K   |                                   d{V  i }d}| |                     |          }|d         |d<   d}|                     d||          \  }}|dk    rt          | j        dz             ||d<   |||d<   |                     |                     ||                     d{V }|                     |d	i           }	|                     |	d
g           }
| 	                    |
|          }| 
                    |d          }|                     ||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]
        NrH   r  r   rW   z: fetchSettlementHistory() is not supported for spot marketr  rU  ry  rz  r  )r  r  r  r>   rH   publicGetV5MarketDeliveryPricer3  r  r  parse_settlementsr  r  rj  r  r  rU  r  r6  r  r  r  ry  r|  settlementsr  s                rl  fetch_settlement_historyzbybit.fetch_settlement_history  s]      !!!!!!!!![[((F &tGH**+CVVTTf6>>tw)eefff"
$GG<<T[[RX=Y=YZZZZZZZZ( (B77~~ffb11,,T6::k;77009I5RWXXXrm  c                 ^  K   |                                   d{V  i }d}| |                     |          }|d         |d<   d}|                     d||          \  }}|dk    rt          | j        dz             ||d<   |||d<   |                     |                     ||                     d{V }|                     |d	i           }	|                     |	d
g           }
| 	                    |
|          }| 
                    |d          }|                     ||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]
        NrH   r  r   rW   z< fetchMySettlementHistory() is not supported for spot marketr  rU  ry  rz  r  )r  r  r  r>   rH   privateGetV5AssetDeliveryRecordr3  r  r  r  r  r  r  s                rl  fetch_my_settlement_historyz!bybit.fetch_my_settlement_history  s]      !!!!!!!!![[((F &tGH**+EvvVVf6>>tw)gghhh"
$GG==dkk'SY>Z>Z[[[[[[[[2 (B77~~ffb11,,T6::k;77009I5RWXXXrm  c                     |                      |d          }|                     |d          }||                     ||          |                     |d          ||                     |          dS )NrF  r  deliveryPrice)r  r  r?  r  r  )r  r  r  r  rS  )rj  
settlementr  r  r  s        rl  parse_settlementzbybit.parse_settlement  sx    . %%j.AA	##J99&&x88%%j/BB"Y//
 
 	
rm  c                     g }t          dt          |                    D ]1}|                    |                     ||         |                     2|S )Nr   )r  r  r  r  )rj  r  r  ry  r  s        rl  r  zbybit.parse_settlements  sZ    6 q#k**++ 	I 	IAMM$//AGGHHHHrm  c                 0  K   |                                   d{V  |                     |          }d|d         d}|                     |                     ||                     d{V }|                     |dg           }|                     |          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>`
        Nr[   rH   r  r  ry  )r  r  %publicGetV5MarketHistoricalVolatilityr3  r  parse_volatility_history)rj  r  r  r  r6  r  
volatilitys          rl  fetch_volatility_historyzbybit.fetch_volatility_history:  s       !!!!!!!!!==&&  
 
 CCDKKPWY_D`D`aaaaaaaa ^^Hh;;
,,Z888rm  c           
         g }t          dt          |                    D ]a}||         }|                     |d          }|                    |||                     |          |                     |d          d           b|S )Nr   r  r2  )r  r  r  r  )r  r  r  r  rS  r  )rj  r  ry  r  r  r  s         rl  r  zbybit.parse_volatility_history]  s     q#j//** 	 	AqME))%88IMM"& LL33"..ug>>	      rm  c                   K   |                                   d{V  |                     |          }|d         dd}|                     |                     ||                     d{V }|                     |d          }|                     |di           }|                     |dg           }|                     |d         |          }	|                     |	||                     |          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>`
        NrH   r[   )r  r  r  ry  rz  r   )r  r  )	r  r  r  r3  r  r  r  parse_greeksrS  )
rj  r  r  r  r6  r  r  ry  r|  greekss
             rl  fetch_greekszbybit.fetch_greeksq  s      !!!!!!!!!V$$Tl 
 
 66t{{7F7S7STTTTTTTTR %%h77	(B77~~ffb11""47F33{{6"Y//$
 $
   	rm  c                   K   |                                   d{V  |                     |dddd          }|                     |dd          }d|d}d}|;t          |          }|dk    r&|                     |d                   }|d	         |d
<   |                     |                     ||                     d{V }|                     |di           }|                     |dg           }	| 	                    |	|          S )a\  
        fetches all 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[] [symbols]: unified symbols of the markets to fetch greeks for, all markets are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.baseCoin]: the baseCoin of the symbol, default is BTC
        :returns dict: a `greeks structure <https://docs.ccxt.com/?id=greeks-structure>`
        NTr  r  r[   r  r   r   rH   r  ry  rz  )
r  r  r  r  r  r  r3  r  r  parse_all_greeks)
rj  r  r  r  r6  r  r  r  ry  r|  s
             rl  fetch_all_greekszbybit.fetch_all_greeks  s,      !!!!!!!!!%%gtT4FF##FJ>>  
 
 LLM!!WQZ00$*4L!66t{{7F7S7STTTTTTTTR (B77~~ffb11$$T7333rm  r  c                    |                      |d          }|                     ||          }i d|dd dd d|                     |d          d|                     |d          d|                     |d          d|                     |d          dd d	|                     |d
          d|                     |d          d|                     |d          d|                     |d          d|                     |d          d|                     |d          d|                     |d          d|                     |d          d|                     |d          |                     |d          |dS )Nr  r  r  deltagammathetavegarhor{  r|  r  r  bidImpliedVolatilitybid1IvaskImpliedVolatilityask1IvmarkImpliedVolatilitymarkIvbidPricers  askPricert  r  rm  underlyingPrice)r  r  rs  )rj  r  r  r  r  s        rl  r  zbybit.parse_greeks  s   < ##FH55!!(F33
f

 
 T%%fg66	

 T%%fg66
 T%%fg66
 D$$VV44
 4
 t''
;;
 t''
;;
 #D$4$4VX$F$F
 #D$4$4VX$F$F
 $T%5%5fh%G%G
 ((==
 ((==
  ))&+>>!
" ))&+>>#
$  $//8IJJ'
 
 
 	
rm  c                 V  K   |                                   d{V  d}|                     |dd          \  }}|r#|                     d||||dddd	  	         d{V S dd	i}d}| |                     |          }|d
         |d<   d}|                     d||          \  }}||d<   |||d<   |||d<   |                     d||          \  }}|                     |                     ||                     d{V }	|                     |	          }
| 	                    |
|||          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>`
        NFr   r  r~  r  rS  rH  	BustTraderH   r  r  rU  r  r  )
r  r  r2  r  r  r  rI  r3  r  parse_liquidations)rj  r  r  rU  r  r  r6  r  r  r  liquidationss              rl  fetch_my_liquidationszbybit.fetch_my_liquidations.  s      !!!!!!!!!88AVXbcc& 	V99:OQWY^`egmo  BJ  LP  RU  V  V  V  V  V  V  V  V  V
 [[((F &tGH**+@&&QQf"
$GG#(GK 229gvNN77GV8T8TUUUUUUUUR ;;HEE&&|VUEJJJrm  c                    |                      |d          }|                     |d          }|                      |d          }|                      |d          }|                      |d          }t          j        ||          }t          j        ||          }	|                     ||                     ||d d          |                     |          |                     |          |                     |          |                     |          |                     |	          ||                     |          d	          S )Nr  r  r  r  r  r  )	r  r  r  r  r?  	baseValue
quoteValuer  r  )r  r  rC   r  safe_liquidationr  r  rS  )
rj  liquidationr  r  r  contractsStringcontractSizeStringr  baseValueStringquoteValueStrings
             rl  parse_liquidationzbybit.parse_liquidation}  s9   : ##K::%%k:>>	**;	BB!--fnEE&&{K@@!,_>PQQ"-o{KK$$&&xzJJ**?;; --.@AA&&{33**?;;++,<=="Y//
&
 
&
 
 
 
	rm  c                   K   |                                   d {V  d }||                     |          }d}|                     |dd          \  }}|r#|                     d|d d |ddd d	  	         d {V S d }|                     d||d          \  }}d|i}|                     |                     ||                     d {V }|                     |          }|                     |d	          }	t          |          }
|
d
z
  }|                     ||          }| 
                    |	d          }d|i|d<   |||<   |S )NFgetLeverageTiersPaginatedr  r~  r  rS  r  r  r   r   r  )r  r  r  r2  r  rj  r3  r  r  r  r  )rj  r  r  r  r  r  r6  r  ry  r  r   	lastIndexr;  cursorValues                 rl  get_leverage_tiers_paginatedz"bybit.get_leverage_tiers_paginated  s     !!!!!!!!![[((F88A\^hii& 	Z99:UW]_ceikq  tD  FN  PT  VY  Z  Z  Z  Z  Z  Z  Z  Z  Z99:UW]_egopp
 88Wf9U9UVVVVVVVV55h??vq))FAI	~~fi00&&u.>??k
V !yrm  c                   K   |                                   d{V  d}d}|B|                     |d                   }|d         rt          | j        dz             |d         }|                     ||                     ddd|                     d{V }|                     |          }|                     ||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   rW   z6 fetchLeverageTiers() is not supported for spot marketr  Tr   )r  paginationCalls)r  r  r>   rH   r  r3  r  parse_leverage_tiers)rj  r  r  r  r  r|  s         rl  fetch_leverage_tierszbybit.fetch_leverage_tiers  s       !!!!!!!!![[,,Ff~ g"47-e#efffH%F66vt{{X\qsKtKtv|?}?}~~~~~~~~%%g..((wAAArm  c                 Z   i }|                      |          }|                     |||d          }|                     ||          }t          |                                          }t          dt          |                    D ]}	||	         }
||
         }t          dt          |                    D ])}|                     ||         d          }|||         d<   *|                     |
d d d          }|d         }| 	                    | 
                    |d          |          ||<   |S )NFr   rH   r  r  )
market_idsfilter_by_arraygroup_byrz  r  r  r  r  r  rk  r  )rj  r  r  marketIdKeyrl  	marketIdsfilteredResultsgroupedr  r  r  r  r  rH   r  r  s                   rl  r  zbybit.parse_leverage_tiers  s*    OOG,,	..xiQVWW--==GLLNN##q#d))$$ 	` 	`AAwHH%E1c%jj)) $ $&&uQx66!#a%%hdJGGFH%F <<T\\%QU=V=VX^__E&MMrm  c                 4   g }t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                     d          }|dk    r|                     ||dz
           d          }|                    |                     |d          |                     ||          |d         ||                     |d          |                     |d          |                     |d	          |d
           |S )Nr   r  r  r   riskLimitValuerH   r  r  rL  )tierr  r  minNotionalmaxNotionalmaintenanceMarginRaterL  r  )	r  r  r  r  r  r  r  r  r  )rj  r  r  rl  r  r  r  r  s           rl  rk  z!bybit.parse_market_leverage_tiers  s.    q#d))$$ 	 	A7D''h77H%%h//F++C00KAvv"..tAE{<LMMLL))$55**8V<<"8,*#//6FGG)-)9)9$@S)T)T#//mDD	 	 	 	 	 	 rm  c                 |  K   |                                   d{V  d}|                     |dd          \  }}|r#|                     d||||dddd	  	         d{V S dd	i}d}| |                     |          }|d
         |d<   d}|                     d||          \  }}||d<   ||d
         |d<   |||d<   |||d<   nd|d<   |                     d||          \  }}|                     |                     ||                     d{V }	|                     |	          }
| 	                    |
|||          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>`
        NFr   r  r~  r  rS  rH  FundingrH   r  r  r  r  r  )
r  r  r2  r  r  r  rI  r3  r  parse_incomes)rj  r  r  rU  r  r  r6  r  r  r  fundingss              rl  fetch_funding_historyzbybit.fetch_funding_history    s      !!!!!!!!!88AVXbcc& 	V99:OQWY^`egmo  BJ  LP  RU  V  V  V  V  V  V  V  V  V	
 [[((F &tGH**+@&&QQf"
 &tGH#(GK #GFOO!GFO229gvNN77GV8T8TUUUUUUUU77AA!!(FE5AAArm  c                    |                      |d          }|                     ||d d          }d}|d         r|d         }|                     |d          }||                     ||dd          |||                     |          |                      |d	          |                     |d
          |                     |d          dS )Nr  r  r  r  r  r  r  rY   r  r  r  )r  r  r  r  r  rH   r  r  )r  r  r  r  rS  r  )rj  incomer  r  r  r  s         rl  parse_incomezbybit.parse_incomeI   s    F ##FH55!!(FD*EE) 	#'?D%%fj99	&&xfEE"Y//""6844&&vy99$$VY77	
 	
 		
rm  c                   K   |                                   d{V  |                     |          }d|d         d}|                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     |di           }|                     |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>`
        Nr[   rH   )r  r  ry  rz  r   )r  r  r  r3  r  r  parse_option)	rj  r  r  r  r6  r  ry  r  r  s	            rl  fetch_optionzbybit.fetch_option}   s       !!!!!!!!!V$$ Tl
 
 66t{{7F7S7STTTTTTTTR (B77^^FFB77
z1b11  f555rm  c                 b  K   |                                   d{V  |                     |          }d|d         d}|                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     |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>`
        Nr[   rH   r  ry  rz  r  )r  r  r  r3  r  r  parse_option_chain)rj  r  r  r  r6  r  ry  r  s           rl  fetch_option_chainzbybit.fetch_option_chain   s       !!!!!!!!!==&&  
 
 66t{{7F7S7STTTTTTTTR (B77^^FFB77
&&z4BBBrm  r  c                 8   |                      |d          }|                     ||          }i d|dd d|d         dd dd d|                     |d          d|                     |d          d	|                     |d
          d|                     |d          dd d|                     |d          d|                     |d          d|                     |d          d|                     |d          dd d|                     |d          dd S )Nr  r  r  r  r  impliedVolatilityr  r/  r  rs  r  rt  midPricer  rm  r  r  	change24hr`  r  totalVolumer  )r  r  r  )rj  r  r  r  r  s        rl  r  zbybit.parse_option   s   < ##E844!!(F33
E

 fX&
 	

 
  !1!1%!B!B
 D,,UNCC
 ((<<
 ((<<
 
 ))%==
 ))%==
 t//7HII
 d&&uk::
 $
  $**5-@@!
" 4#
 	
rm  c                   K   |                                   d{V  d}d}d}|0t          |          }|dk    r|                     |d                   }|                     |d          }|                     d||d          \  }}|                     |d          }d|i}	||dk    r|d         |	d	<   |||	d
<   |||	d<   |||	d<   |                     |                     |	|                     d{V }
|                     |
d          }| 	                    |d          }| 
                    |||          }|                     |||          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   rH   r  r  rU  r  ry  rz  )r  r  r  r  r  rr  privateGetV5PositionClosedPnlr3  r  r  parse_positionsfilter_by_since_limit)rj  r  r  rU  r  r  r  r  r  r6  r  ry  rawPositionsr  s                 rl  fetch_positions_historyzbybit.fetch_positions_history,!  s      !!!!!!!!!LLMq  WQZ00!!&'2299:QSY[ackll67++
 mq&8&8 &tGH#(GK $GG!&GI;;DKKQW<X<XYYYYYYYYD (33~~ff55((wGG	)))UEBBBrm  c                   K   |                                   d{V  d}|                                  d{V \  }}|p|}|rdnd}|                     |dd|          \  }}d|i}|                     |                     ||                     d{V }i }	|                     |di           }
|                     |
dg           }t          dt          |                    D ]}||         }| 	                    |d	          }| 
                    |d
          }| 
                    |d          }|p|}|                     |          }|||d| 	                    |d          | 	                    |d          | d|                     |d          dd|                     |d          |                     |d          dddddddddd|	|<   |	S )a  
        fetches all available currencies that can be converted

        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!  ry  r4  r   r  disableFrom	disableTocoinTypefullNamer  singleFromMinLimitsingleFromMaxLimitr  r  )r  rH   r  r5  r  rI   r  rc  r   r  r  r  r1  )r  r  r  &privateGetV5AssetExchangeQueryCoinListr3  r  r  r  r  r  r  r  r  )rj  r  r!  r  r  r@  accountTypeDefaultr6  r  ry  r|  r4  r  r  rH   r  r  inactiver  s                      rl  fetch_convert_currencieszbybit.fetch_convert_currenciesw!  sh      !!!!!!!!!:>:Q:Q:S:S4S4S4S4S4S4S11/G3G1AX--GX";;FD\^km  A  AV;
 DDT[[QXZ`EaEabbbbbbbbD ~~h"55tWb11q#e**%% "	 "	A!HE!!%00B..>>Kuk::I#0yH**2..D ((
;;((
;;&, ,,UI>>!  $//7KLL#//7KLL 
  $#! !
  $#      5 F4LL8 rm  fromCodetoCodec                 b  K   |                                   d{V  d}|                                  d{V \  }}|p|}|rdnd}	|                     |dd|	          \  }}|||                     |          ||d}
|                     |                     |
|                     d{V }|                     |di           }|                     |d|          }|                     |          }|                     |d	|          }|                     |          }| 	                    |||          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!  ry  r  r  )
r  r  r  r  $privatePostV5AssetExchangeQuoteApplyr3  r  r  r  parse_conversion)rj  r  r  r  r  r!  r  r  r@  r  r6  r  r|  fromCurrencyIdfromCurrencytoCurrencyId
toCurrencys                    rl  fetch_convert_quotezbybit.fetch_convert_quote!  sx      !!!!!!!!!:>:Q:Q:S:S4S4S4S4S4S4S11/G3G1AX--GX";;FDWYfhz{{V !226::#&
 
 BB4;;wX^C_C_````````* ~~h"55))$
HEE}}^44''h??]]<00
$$T<DDDrm  c                    K   |                                   d{V  d|i}|                     |                     ||                     d{V }|                     |di           }|                     |          S )aq  
        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>`
        N	quoteTxIdry  )r  (privatePostV5AssetExchangeConvertExecuter3  r  r   )	rj  rH   r  r  r  r  r6  r  r|  s	            rl  create_convert_tradezbybit.create_convert_trade
"  s       !!!!!!!!!
 FFt{{SZ\bGcGcdddddddd ~~h"55$$T***rm  c                 p  K   |                                   d{V  d}|                                  d{V \  }}|p|}|rdnd}|                     |dd|          \  }}||d}	|                     |                     |	|                     d{V }
|                     |
di           }|                     |di           }|                     |d          }|                     |d	          }d}d}||                     |          }||                     |          }|                     |||          S )
aY  
        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!  ry  r  r  )	r  r  r  +privateGetV5AssetExchangeConvertResultQueryr3  r  r  r  r   )rj  rH   r  r  r!  r  r  r@  r  r6  r  r|  ry  r  r  r  r  s                    rl  fetch_convert_tradezbybit.fetch_convert_trade+"  s      !!!!!!!!!:>:Q:Q:S:S4S4S4S4S4S4S11/G3G1AX--GX";;FDWYfhz{{V&
 
 II$++V]_eJfJfgggggggg4 ~~h"55h33))&*==''99
%==88L#|44J$$V\:FFFrm  c                 :  K   |                                   d{V  i }|||d<   |                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     ||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>`
        NrU  ry  rz  r  r  )r  ,privateGetV5AssetExchangeQueryConvertHistoryr3  r  r  parse_conversions)	rj  r  r  rU  r  r6  r  r|  r}  s	            rl  fetch_convert_trade_historyz!bybit.fetch_convert_trade_historyg"  s       !!!!!!!!!$GGJJ4;;W^`fKgKghhhhhhhh8 ~~h"55>>$33%%hj(ESXYYYrm  
conversionr  r  c                    |                      |dd          }|                     |d          }|                     ||          }|                     |d          }|                     ||          }|||                     |          |                     |dd          ||                     |d          ||                     |d          d d d	
S )
NexpiredTimerp  r  r  r  exchangeTxId
fromAmounttoAmount)
r  r  r  rH   r  r  r  r  r?  r  )r  r  r  rS  r  r  )	rj  r  r  r  r  r  r  tor  s	            rl  r   zbybit.parse_conversion"  s    T ''
M;OO	##J
;;**8\BBj(33((Z88"Y//$$ZnMM$**:|DD ((Z@@
 
 	
rm  c                   K   |                                   d{V  |                     |          }d}|                     d||          \  }}|dk    s|dk    rt          | j        dz             |d}|d         ||d}|||d	<   |                     |                     ||                     d{V }	|                     |	d
i           }
|                     |
dg           }| 	                    ||          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   rW   r[   zE fetchLongShortRatioHistory() only support linear and inverse marketsr   rH   )r  r9  r  rU  ry  rz  )
r  r  r  r>   rH   publicGetV5MarketAccountRatior3  r  r  parse_long_short_ratio_history)rj  r  r  r  rU  r  r  r  r6  r  ry  r|  s               rl  fetch_long_short_ratio_historyz$bybit.fetch_long_short_ratio_history"  s4      !!!!!!!!!V$$**+GQWXXf6>>TX--tw)ppqqqITl
 

 $GG;;DKKQW<X<XYYYYYYYY& (B77~~ffb11224@@@rm  c                 b   |                      |d          }|                     |d          }|                      |d          }|                      |d          }||                     ||d d          ||                     |          d |                     t          j        ||                    dS )Nr  r  buyRatio	sellRatior  )r  r  r  r  r  longShortRatio)r  safe_integer_omit_zeror  rS  r  rC   r  )rj  r  r  r  r  
longStringshortStrings          rl  parse_long_short_ratiozbybit.parse_long_short_ratio#  s     ##D(33//kBB	%%dJ77
&&t[99&&xzJJ"Y//"33G4FzS^4_4_``
 
 	
rm  c                   K   |t          | j        dz             |                                  d{V  |                     |dddd          }|                     |          }i }||d         |d<   d}|                     d||          \  }}||d<   |                     |                     ||                     d{V }|                     |di           }| 	                    |d	g           }| 
                    ||          S )
a  
        fetches the auto deleveraging rank and risk percentage for a list of symbols

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

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of `auto de leverage structures <https://docs.ccxt.com/?id=auto-de-leverage-structure>`
        Nz4 fetchPositionsADLRank() requires a symbols argumentTrH   r  r   r  ry  rz  )r4   rH   r  r  get_market_from_symbolsr  r  r3  r  r  parse_adl_ranks)	rj  r  r  r  r6  r  r  ry  rankss	            rl  fetch_positions_adl_rankzbybit.fetch_positions_adl_rank#  s/      ?#DG.d$deee!!!!!!!!!%%gtT4FF--g66 &tGH**+BFFSSf"
66t{{7F7S7STTTTTTTTh (B77vvr22##E7333rm  c           	          |                      |d          }|                     |d          }||                     ||d d          |                     |d          d d ||                     |          dS )Nr  rv  r  adlRankIndicator)r  r  rankratingr`  r  r  )r  r  r  rS  )rj  r  r  r  r  s        rl  parse_adl_rankzbybit.parse_adl_rankj#  s    T ##D(33%%dM::	&&xzJJ%%d,>??"Y//
 
 	
rm  c                    K   |                                   d{V  |                     |          }|                     |           d{V }|                     |di           }|                     ||          S )a  
        fetches the margin mode of the trading pair

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

        :param str [symbol]: unified symbol of the market to fetch the margin mode for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin mode structure <https://docs.ccxt.com/?id=margin-mode-structure>`
        Nry  )r  r  r  r  parse_margin_mode)rj  r  r  r  r  ry  s         rl  fetch_margin_modezbybit.fetch_margin_mode#  s       !!!!!!!!!V$$55f========" (B77%%ff555rm  c                     |                      |d          }||                     d |          |                     |          dS )NrD  )r  r  rD  )r  r  parse_margin_mode_type)rj  rD  r  
marginTypes       rl  r/  zbybit.parse_margin_mode#  sM    %%j,??
&&tV4455jAA
 
 	
rm  c                 <    dddd}|                      |||          S )Nr
  r  r  )r  r  r  r_  )rj  rD  marginModess      rl  r2  zbybit.parse_margin_mode_type#  s1    )% +
 

 ZDDDrm  r   GETc                    |                      | j        d         |                   dz   |z   }|dk    r|r|d|                     |          z   z  }n|dk    r|                                  |                    d          dk    }|                    d          dk    }	|                    d	          dk    }
|                    d
          dk    }t          |                                           }|r|r|                     |          }nd}|| j        z   |z   }| 	                    | 
                    |          | 
                    | j                  t          j        d          }d| j        ||d}n|	s|
s|rJd| j        |t          | j        d                   d}|	s|
rd|d<   |                     i |          }|                     |          }t          |          | j        z   t          | j        d                   z   }d }|dk    r|                     |          }||z   }n||z   }|d|z   z  }d }| j                            d          dk    r|                     || j        d          }nL| 	                    | 
                    |          | 
                    | j                  t          j                  }||d<   no|                     || j        | j        d         |d          }|                     |          }|                     |d          }d }| j                            d          dk    r|                     || j        d          }nL| 	                    | 
                    |          | 
                    | j                  t          j                  }|dk    rg|                    d          dk    }|                     |d|i          }|r|                     |          }ddi}n>|                     |          }ddi}n$|d|                     |d          z   z  }|d|z   z  }|dk    r"|                     | j        d          }|||d <   ||||d!S )"Nr   r  r   ?r   openapir   z
unified/v3zcontract/v3rN   z{}hexzapplication/json)Content-TypeX-BAPI-API-KEYX-BAPI-TIMESTAMPX-BAPI-SIGNr  )r;  r<  r=  zX-BAPI-RECV-WINDOWro  zX-BAPI-SIGN-TYPEPOSTzPRIVATE KEYr  sha256r>  )api_keyrecv_windowr  TrW   signr;  z!application/x-www-form-urlencodedz&sign=r2  Referer)urlr  bodyheaders)implode_hostnamer   	rawencoder  r  r  rw  jsonapiKeyhmacencodesecrethashlibr@  r  r3  rsakeysort	urlencoder  )rj  pathr   r  r  rG  rF  rE  	isOpenapiisV3UnifiedMarginisV3ContractisV5UnifiedAccountr  payload	signaturer  queryEncoded	auth_baseauthFullsortedQueryauthr  extendedQueryr2  s                           rl  rC  z
bybit.sign#  s   ##DIe$4S$9::S@4G(?? 4sT^^F3333I++---++q0I # 6 6! ;88M22a7L!$$1!4DJJLL))I F0  99V,,DD  D#dk1D8 IIdkk'&:&:DKK<T<TV]Vdfkll	$6&*k(1#,	  # 70l 706H 70$6&*k(1*-dl<.H*I*I	  % 6 625G./B//#~~e44	NNT[83t|L?Y;Z;ZZ	V##99U++D(4/HH(<7H3--C 	;##M22R77 $4; I III $		$++h*?*?T[AYAY[b[i j jI)2&&F#{#'<#=!*- -  
 #ll511~~k488 	;##M22R77 $t{H E EII $		$++d*;*;T[[=U=UW^We f fIV## XXf--2F$(KK	8 % %M  	#~~m<<*,O#  $yy77*,># 3T!B!BBBC8i//CV''jAAH#%-	"fdwOOOrm  httpCodereasonrE  r  rG  rF  c
                    |sd S |                      |dd          }
|
dk    r|
dk    rd S d }|
dk    r'|                    d          dk     r| j        dz   |z   }n| j        d	z   |z   }|                    d
          dk    r|dz   }|                     | j        d         ||           |                     | j        d         |
|           t          |          d S )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  )r  r  rH   throw_broadly_matched_exceptionr   throw_exactly_matched_exceptionr0   )rj  r`  ra  rE  r  rG  rF  r  requestHeadersrequestBody	errorCodefeedbacks               rl  handle_errorszbybit.handle_errors)$  s    	4& &&xYGG	G## tHG##(9(9A(=(=7  &i  i  lp  p7S=4/yyRSSVXXX#&bb001I4QYZZZ001I9V^___)))trm  )NNNN)N)NN)__name__
__module____qualname__r   ri  boolrt  rw  r  r  r  r  r  r#   r   r-   r  r  floatr  r  r  r   r  r   r  dictr   r  r/   r  r  r  r  r%   r  r  r$   r&   r  r  rz  r  r  r'   r  r(   r  r  r)   r  r  r   r  r   r9  rF  rb  rj  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/  r8  r;  r=  r6  rB  r:  rF  rE  r   rQ  rZ  r`  r,   re  rh  rx  r  r   r  r  r  r   r"   r  r  r  r   r  r  r  rR  r  r   r'  r*  r,  r)  r
   r6  r5  r   r=  rA  rD  r.   r   rX  r]  r`  r\  rO  rP  r   rm  ro  r*   rt  rw  r+   ry  r}  r  r  r  r  r  r  r  r   r  r  r  r   r  r  r  r   r  r  rk  r   r  objectr  r   r  r   r  r  r  r  r	   r  r	  r  r  r   r   r  r#  r   r(  r-  r   r0  r/  r2  rC  rl  __classcell__)rk  s   @rl  rE   rE   "   sQ       |# | | | | | ||)3$ 3 3 3 3(D D D	 	 	 /1 W[ W[ W[ W[r :< 	C 	C 	C 	CT
3 T
 T
 T
 T
lW WC W WRU Wjm W  zI W W W W W W 57 ! ! ! ! e     C    s #     ') 3 3S 3 3 3 30 -/ .+ .+: .+ .+ .+ .+`8t 8 8 8 8 8t *, 3 3V 3 3 3 3jq$v, q q q qftDL t t t tlIDL I I I IVu u4 u u6 u u u un 68 @4 @4 @4F @4 @4 @4 @4D 6:" `= `=7 `= `= `= `= `=D 8<B 9 9W 97 9 9 9 9
 
 
4 
 
 
 
, ?CQUdhqs eJ eJ eJ eJ3 eJ^a eJx|  ~B  yC eJ eJ eJ eJN;
 ;
 ;
; ;
 ;
 ;
 ;
z <@ E= E= E=| E= E= E= E=N >BPTcgpr VO VOs VO# VO]` VO VO VO VOp\ \ \v \ \ \ \ \| <@d[] 7? 7? 7?S 7? 7?bfglbm 7? 7? 7? 7?r @DB >J >JS >J >JS\ >J >J >J >J@^) ^) ^) ^) ^)@ *, ^, ^, ^, ^, ^, ^,@: : : : :8Hs H H H HM M Mv M M M M M^ XZ d dc d d^c d d d d( Y[ e es e% e_d e e e e0 mqy{ F/ F/ F/I F/Y F/X] F/fi F/  AF F/ F/ F/ F/P os{}  FJ o, o,3 o,i o,y o,Z_ o,hk o, o, o, o,b FH V' V'$|*< V'DQVK V' V' V' V'p hlz~  HJ 9 9S 9# 9Y 9i 9ad 9tw 9 9 9 9v fjx|  FH 3 33 3 39 3I 3_b 3ru 3  MR 3 3 3 3j DF S' S'\(: S'$u+ S' S' S' S'j ;?r , ,s ,C , , , ,* 9=R !0 !0S !0# !0E !0 !0 !0 !0F AER O. O.tCy O.# O.TXY^T_ O. O. O. O.b BD  S    B Y[ P, P,d;N6O P, P, P, P,d 59 G1 G1c G1 G1 G1 G1R @DB * *C * *SX * * * *< 8<B Y/ Y/C Y/ Y/5 Y/ Y/ Y/ Y/v 04$UYbd M M MC Ms Mimnsit M M M M. 8<$]ajl c= c= c=C c=WZ c=quv{q| c= c= c= c=J ?C2 * *3 * *RW * * * *< =A * * *c *PU * * * *@ DHVZimvx o= o=S o=PS o=cf o=  ~B  CH  ~I o= o= o= o=b 7;\`ik o o o3 oVY optuzp{ o o o o2 9=4^bkm o o# oS oX[ orvw|r} o o o o2 59tZ^gi o= o=c o= o=TW o=nrsxny o= o= o= o=b ?CQUdhqs ^ ^3 ^ ^3 ^^a ^x|  ~C  yD ^ ^ ^ ^, 37TX\eg M? M?C M?s M?RU M?lpqvlw M? M? M? M?^
 
h 
R` 
 
 
 
* JL .0 .0S .0PTUcPd .0 .0 .0 .0` =? 5 5 5> 5 5 5 5" 04$UYbd @E @E @EC @Es @Eimnyiz @E @E @E @ED 37TX\eg LE LEC LEs LERU LElpq|l} LE LE LE LE\:s : : : :&L
 L
T L
X L
Q\ L
 L
 L
 L
\ .2SW`b i? i?s i?# i?S i?gklwgx i? i? i? i?VI It Ix I; I I I IV3 3 32 QU]_ 28 283 28 28 28# 28do 28 28 28 28h 8: E E3 Eh E E E EN 8<B bQ bQW bQ4PX> bQ bQ bQ bQHi it iV ix i i i iV 8: 5 53 5h 5 5 5 5	
 	
t 	
V 	
x 	
 	
 	
 	
 DHPR R R RS R R R Rh ?C2 $ $3 $ $ $ $ $L CGr , ,d ,C , , , ,\ TXfjy}  GI 2M 2MC 2M`c 2Msv 2M 2M 2M 2Mh =? 89 89 89 89 89 89t HLZ^mqz| k k kTW kgj k k k k@ F    * ?A !6 !6# !6_ !6 !6 !6 !6F
 
 
 
 
 
> 7;$]apt} ,Q ,Q ,QC ,QWZ ,Qjm ,Q  EI  JX  EY ,Q ,Q ,Q ,Q\ GKY]fh /H /HC /H /HSV /H /H /H /Hb
 
$ 
 
. 
 
 
 
. ac 3 33 3 3C 3TW 3gt 3 3 3 3j 154VZce 5B 5B# 5BS 5BPS 5Bjno|j} 5B 5B 5B 5Bn JL 8 8c 85 8 8 8 8B BD ! !S ! ! ! !F
 
 
D 
 
 
 
4:C :C : : : :%
 %
t %
x %
= %
 %
 %
 %
N QS $? $?C $?W[\hWi $? $? $? $?L EG R R R4P\K] R R R R&
 
T 
6 
EX 
 
 
 
( ;= '5 '5c '5AT '5 '5 '5 '5R /1 ( ([ ( ( ( (T0 0 0C 0 0 0 0d BFb -E -Ew -E -E -E -E^ <@daenp 3Y 3YS 3Y 3Y[^ 3Y 3Y 3Y 3Yj ?CQUdhqs 8Y 8Y 8Y3 8Y^a 8Y 8Y 8Y 8Yt
 
 
B  @ @B !9 !93 !9 !9 !9 !9F  ( 68 @ @ @F @ @ @ @D 9=R C4 C4g C4DQWL C4 C4 C4 C4J4
 4
4 4
 4
6 4
 4
 4
 4
l 9=4^bkm MK MK# MKS MKX[ MKrv  xC  sD MK MK MK MK^. .V .{ . . . .` @DB      6 =A B B' BP] B B B B0 g [h    <     $|J\        D 9=4^bkm 'B 'B# 'BS 'BX[ 'Brv  xF  sG 'B 'B 'B 'BR2
 2
6 2
V 2
 2
 2
 2
h 68 <6 <6 <6F <6 <6 <6 <6| :< ;C ;CS ;C ;C ;C ;C ;Cz2
 2
$ 2
( 2
6 2
]c 2
 2
 2
 2
h @DRVeirt IC ICW ICC IC_b ICy}  G  zH IC IC IC ICV 57 [ [: [ [ [ [z SW_a 4E 4E# 4Es 4EC 4Efp 4E 4E 4E 4El ]aik + +S +C + +VY +pz + + + +B >B" :G :GC :Gs :GQ[ :G :G :G :Gx =Atbfoq /Z /Zc /Z /Z\_ /Zvz  |F  wG /Z /Z /Z /Zb:
 :
4 :
x :
\d :
pz :
 :
 :
 :
x BFX\ko  C  LN 1A 1A3 1ARU 1Aeh 1Ax{ 1A  SW  Xf  Sg 1A 1A 1A 1Af
 
4 
 
> 
 
 
 
, AER K4 K4g K4TXY\T] K4 K4 K4 K4Z4
 4
4 4
 4
3 4
 4
 4
 4
l ;= 6 6c 6 6 6 6 6@
 
D 
* 
 
 
 
E E E E E E &eBSW WP WP WP WPr(c (3 (S (# (X\ (dg ( ( ( ( ( ( ( (rm  rE   )K ccxt.async_support.base.exchanger   ccxt.abstract.bybitr   r  rO  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,   r-   r.   typingr/   ccxt.base.errorsr0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   ccxt.base.decimal_to_precisionrB   ccxt.base.preciserC   rE    rm  rl  <module>r}     s   6 5 5 5 5 5 + + + + + +   C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C       * * * * * * 0 0 0 0 0 0 - - - - - - - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & % % % % % % 1 1 1 1 1 1 4 4 4 4 4 4 / / / / / / . . . . . . ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) . . . . . . ) ) ) ) ) ) + + + + + + 4 4 4 4 4 4 % % % % % %oP oP oP oP oPHk oP oP oP oP oPrm  