
    i                     |   d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlm Z  d dl!m"Z" d dl!m#Z# d dl!m$Z$ d d	l!m%Z% d d
l!m&Z& d dl!m'Z' d dl!m(Z( d dl!m)Z) d dl!m*Z* d dl!m+Z+ d dl!m,Z, d dl!m-Z- d dl!m.Z. d dl!m/Z/ d dl0m1Z1 d dl2m3Z3  G d dee          Z4dS )    )Exchange)ImplicitAPIN)Balances
CurrenciesCurrencyGreeksIntLeverageMarketMarketInterfaceNumOptionOptionChainOrder	OrderBookOrderRequest	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeeInterfaceTradingFeesTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)NoChange)MarginModeAlreadySet)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)RateLimitExceeded)InvalidNonce)RequestTimeout)	TICK_SIZE)Precisec                   	    e Zd Z f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i fdZi fdefdZi fdee         fdZd Zd Zd ZddedefdZi fd	edefdZdi fdedefdZddede fdZ!dddi fd	ede"d e"dee          fd!Z#ddefd"Z$di fdefd#Z%dddi fd	ede"d e"fd$Z&ddede'fd%Z(ddi fd	ede"d e"dee'         fd&Z)di fd	ed e"de*fd'Z+de,fd(Z-i fde,fd)Z.d* Z/d+ Z0ddede1fd,Z2i fd	ed-e3fd.Z4i fd	ed-e3fd/Z5di fd	ed0e6d1e7d2e3d3e8f
d4Z9di d5fd	ed0e6d1e7d2e3d3e8f
d6Z:i fd7ee;         fd8Z<di fd	ed0e6d1e7d2e3d3e8f
d9Z=ddi fd:Z>ddi fd;ed	ed0e6d1e7d2e8d3e8fd<Z?di fd	efd=Z@di fd;ed	efd>ZAdi fd	efd?ZBdi fd	efd@ZCdi fd	efdAZDdddi fd	ede"d e"fdBZEdi fd;ed	efdCZFdi fd;ed	ede1fdDZGdddi fd	ede"d e"dee1         fdEZHdddi fd	ede"d e"dee1         fdFZIdi fd;ed	efdGZJdi fd;ed	efdHZKdddi fd	ede"d e"dee1         fdIZLdddi fd	ede"d e"dee1         fdJZMdddi fd	ede"d e"fdKZNdddi fd	ede"d e"fdLZOdddi fd	ede"d e"dee1         fdMZPdddi fd;ed	ede"d e"fdNZQdddi fd	ede"d e"fdOZRdddi fd	ede"d e"fdPZSddQeTfdRZUi fdSefdTZVi fdSefdUZWdddi fdSede"d e"deeX         fdVZYdddi fdSede"d e"deeX         fdWZZdX Z[ddQeTdeXfdYZ\dddi fdSede"d e"fdZZ]ddQeTfd[Z^d\ Z_di fdSed2e3fd]Z`i fd	efd^Zadi fdefd_Zbdi fdefd`ZcddefdaZdi fd	edeefdbZfddeefdcZgdi fdded	efdeZhdi fdfe"d	efdgZidi fdhed	efdiZjdjddi fd	ede"d e"fdkZki fd	efdlZldjddi fd	ede"d e"fdmZmddefdnZni fdSefdoZoddQeTfdpZpddddi fdSed	ede"d e"fdqZqddefdrZri fdSed2e3dsedtedesf
duZtdddi fdSede"d e"fdvZui fdSed2e3fdwZvi fdSefdxZwddQeTfdyZxdz ZyddQeTfd{Zzi fd	efd|Z{i fd	efd}Z|ddede}fd~Z~i fd	ede}fdZi fdefdZddQeTf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dSefdZd Zi fd	edefdZddefdZdddi fd	ede"d e"fdZddefdZdi fdefdZddefdZddefdZdddi fd	ede"d e"fdZddefdZi fd	edefdZi fdSedefdZddQeTdefdZddi ddfdZd Z xZS )bybitc                 ,   |                      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d4di d5dd6dd7dd8dd9dd:dd;dd<dd=d>d?dd@ddAddBddCddDddEddFdi dGddHddIddJddKddLddMddNddOddPddQddRddSddTddUddVddWdi dXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcdddddeddfddgddhdddddddddddi	djdkdldmdndodpdqdrdsdtdudvdwdxdydzdzdzdzdzd{d|d}d}d}d}d}d{d~d~d~d~d~d{dg 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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ddddddΓddΓddi ddΓddddƓddƓddddddddddddddd dddddddddddi ddddddd	dd
dƓddddddddddddddddΓddddΓddΓddΓi ddΓddddddƓddƓddddƓddƓdd d!dƓd"dd#dd$dd%dd&dd'dd(di d)dd*dd+dd,dd-dd.dd/dddddd0dd1dd2dd3dd4dd5dd6dd7dddƐd8i d9dd:dd;dd<dd=dd>dd?dd@ddAddBddCddDddEddddFddGddHdi dIddJddKdƓdLdƓdMdNdOdPdQdΓdRdNdSdNdTdƓdUdƓdVdƓdWdƓdXdƓdYdƓdZdƓ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ddddddΓddddddddddddddddddddddddi ddddddddddddddddddΓddNddƓddddΓddΓddƓddƓddƓi ddƓddƓddƓddƓddddddddddddddddddddddddddddiddddt          idi dt
          dt
          dt
          dt
          dt          dt          dt          dt          dt
          dt
          dt
          dt          dt
          dt
          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt
          dt          dt
          dt          dt          dt          dt          dt          dt          dt          dt
          i dt
          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt
          dt          dt
          dt          i dt          dt
          dt          dt          dt          dt          dt          dt
          dt          dt          dt          dt
          dt
          dt          dt          dt          dt          i dt          dt          dt          dt          dt          d t          dt          dt          dt          dt
          dt          dt          dt
          dt
          d	t
          d
t
          dt
          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt
          dt
          dt
          dt          dt          dt          dt          dt          i dt          dt          dt          d t          d!t          d"t          d#t          d$t          d%t          d&t          d't          d(t          d)t          d*t
          d+t
          d,t
          d-t
          i d.t          d/t
          d0t          d1t
          d2t
          d3t
          d4t          d5t
          d6t
          d7t
          d8t          d9t          d:t          d;t          d<t
          d=t          d>t          i d?t          d@t
          dAt
          dBt
          dCt          dDt          dEt          dFt          dGt
          dHt
          dIt
          dJt          dKt          dLt          dMt          dNt          dOt          i dPt          dQt          dRt          dSt          dTt          dUt          dVt          dWt          dXt
          dYt          dZt          d[t          d\t          d]t
          d^t          d_t          d`t          i dat          dbt          dct
          ddt
          det
          dft
          dgt          dht
          dit          djt
          dkt          dlt          dmt          dnt          dot
          dpt          dqt
          i drt
          dst          dtt          dut          dvt
          dwt          dxt          dyt
          dzt
          d{t
          d|t
          d}t          d~t          dt          dt          dt          dt          i dt          dt          dt          dt          dt
          dt
          dt
          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt           i dt          dt          dt          dt          dt          dt
          dt
          dt
          dt
          dt          dt          dt          dt          dt
          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt
          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt          dt
          i dt
          dt
          dt
          dt
          dt
          dt
          d t
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          dt
          d	t
          d
t          i dt          dt          dt
          dt
          dt
          dt
          dt
          dt          dt          dt          dt          dt
          dt          dt          dt          dt          dt          i dt          dt          dt          dt          d t          d!t          d"t          d#t          d$t          d%t          d&t          d't          d(t          d)t          d*t          d+t
          d,t
          i d-t
          d.t
          d/t
          d0t
          d1t
          d2t          d3t          d4t          d5t          d6t          d7t          d8t          d9t          d:t          d;t          d<t          d=t          i d>t          d?t          d@t          dAt          dBt          dCt          dDt          dEt          dFt          dGt          dHt          dIt          dJt          dKt          dLt          dMt          dNt          i dOt          dPt          dQt          dRt          dSt          dTt          dUt          dVt          dWt          dXt          dYt          dZt          d[t          d\t          d]t          d^t          d_t          t          t          t          t          t          t          t          t
          t
          t          t          t
          t
          t          d`t           t          t          t          t          t          dadbdct"          ddi deddfddMg dgd dhdiidjd dkd dlddmddnddodpdqdrdsdtdudvdwdxdyddzdd{dd|d}d}d~d~dddddd~d
ddddddddddddddddddddddrdidddddddddddddddddi i ddi          S (  Nidr0   nameBybit	countriesVGversionv5	userAgent	rateLimit   hostnamez	bybit.comproT	certifiedhasCORSspotmarginswapfutureoptionborrowCrossMargincancelAllOrderscancelOrdercloseAllPositionsFclosePositioncreateMarketBuyOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrders$createOrderWithTakeProfitAndStopLosscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopLossOrdercreateStopMarketOrdercreateStopOrdercreateTakeProfitOrdercreateTrailingAmountOrdercreateTriggerOrder	editOrderfetchBalancefetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledAndClosedOrdersfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchLeverageTiersfetchMarginAdjustmentHistoryfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionsfetchPremiumIndexOHLCVfetchSettlementHistoryfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsfetchTransfers)	fetchUnderlyingAssetsfetchVolatilityHistoryfetchWithdrawalsrepayCrossMargin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})rA   futuresv2publicprivatezdhttps://user-images.githubusercontent.com/51840849/76547799-daff5b80-649e-11ea-87fb-3be9bac08954.jpgzhttps://api.{hostname}zhttps://api-demo.{hostname}zhttps://www.bybit.com)z.https://bybit-exchange.github.io/docs/inverse/z-https://bybit-exchange.github.io/docs/linear/z!https://github.com/bybit-exchangez5https://help.bybit.com/hc/en-us/articles/360039261154z1https://www.bybit.com/register?affiliate_id=35953)testlogoapidemotradingwwwdocfeesreferralr   getzspot/v3/public/symbols   zspot/v3/public/quote/depthz!spot/v3/public/quote/depth/mergedzspot/v3/public/quote/tradeszspot/v3/public/quote/klinez spot/v3/public/quote/ticker/24hrz!spot/v3/public/quote/ticker/pricez&spot/v3/public/quote/ticker/bookTickerzspot/v3/public/server-timezspot/v3/public/infosz#spot/v3/public/margin-product-infosz#spot/v3/public/margin-ensure-tokenszv3/public/timez*contract/v3/public/copytrading/symbol/listz#derivatives/v3/public/order-book/L2zderivatives/v3/public/klinezderivatives/v3/public/tickersz&derivatives/v3/public/instruments-infoz&derivatives/v3/public/mark-price-klinez'derivatives/v3/public/index-price-klinez2derivatives/v3/public/funding/history-funding-ratez%derivatives/v3/public/risk-limit/listz$derivatives/v3/public/delivery-pricez"derivatives/v3/public/recent-tradez#derivatives/v3/public/open-interestzderivatives/v3/public/insurancezv5/announcements/index   zv5/market/timezv5/market/klinezv5/market/mark-price-klinezv5/market/index-price-klinez#v5/market/premium-index-price-klinezv5/market/instruments-infozv5/market/orderbookzv5/market/tickerszv5/market/funding/historyzv5/market/recent-tradezv5/market/open-interestzv5/market/historical-volatilityzv5/market/insurancezv5/market/risk-limitzv5/market/delivery-pricezv5/market/account-ratiozv5/spot-lever-token/infozv5/spot-lever-token/referencezv5/spot-margin-trade/datazv5/spot-cross-margin-trade/dataz'v5/spot-cross-margin-trade/pledge-tokenz'v5/spot-cross-margin-trade/borrow-tokenzv5/ins-loan/product-infosz!v5/ins-loan/ensure-tokens-convertzv2/private/wallet/fund/records   zspot/v3/private/orderg      @zspot/v3/private/open-orderszspot/v3/private/history-orderszspot/v3/private/my-tradeszspot/v3/private/accountzspot/v3/private/referencezspot/v3/private/recordz#spot/v3/private/cross-margin-orders
   z$spot/v3/private/cross-margin-accountz&spot/v3/private/cross-margin-loan-infoz*spot/v3/private/cross-margin-repay-historyz!spot/v3/private/margin-loan-infosz#spot/v3/private/margin-repaid-infoszspot/v3/private/margin-ltvz3asset/v3/private/transfer/inter-transfer/list/query2   z/asset/v3/private/transfer/sub-member/list/queryz8asset/v3/private/transfer/sub-member-transfer/list/queryz7asset/v3/private/transfer/universal-transfer/list/queryz asset/v3/private/coin-info/queryz&asset/v3/private/deposit/address/queryz*contract/v3/private/copytrading/order/list   z-contract/v3/private/copytrading/position/list(   z.contract/v3/private/copytrading/wallet/balancez'contract/v3/private/position/limit-infoz)contract/v3/private/order/unfilled-orderszcontract/v3/private/order/listz!contract/v3/private/position/listz"contract/v3/private/execution/listz'contract/v3/private/position/closed-pnlz*contract/v3/private/account/wallet/balancez$contract/v3/private/account/fee-ratez/contract/v3/private/account/wallet/fund-recordsz(unified/v3/private/order/unfilled-orderszunified/v3/private/order/listz unified/v3/private/position/listz!unified/v3/private/execution/listz"unified/v3/private/delivery-recordz$unified/v3/private/settlement-recordz)unified/v3/private/account/wallet/balancez*unified/v3/private/account/transaction-logz)unified/v3/private/account/borrow-historyz&unified/v3/private/account/borrow-ratezunified/v3/private/account/infoz!user/v3/private/frozen-sub-memberz!user/v3/private/query-sub-memberszuser/v3/private/query-apizuser/v3/private/get-member-typez2asset/v3/private/transfer/transfer-coin/list/queryz4asset/v3/private/transfer/account-coin/balance/queryz5asset/v3/private/transfer/account-coins/balance/queryz*asset/v3/private/transfer/asset-info/queryz2asset/v3/public/deposit/allowed-deposit-list/queryg(\?z%asset/v3/private/deposit/record/queryz&asset/v3/private/withdraw/record/queryzv5/order/realtimezv5/order/historyzv5/order/spot-borrow-checkzv5/position/listzv5/execution/listzv5/position/closed-pnlzv5/position/move-historyzv5/pre-upgrade/order/historyzv5/pre-upgrade/execution/listz"v5/pre-upgrade/position/closed-pnlz&v5/pre-upgrade/account/transaction-logz$v5/pre-upgrade/asset/delivery-recordz&v5/pre-upgrade/asset/settlement-recordzv5/account/wallet-balancezv5/account/borrow-historyzv5/account/collateral-infozv5/asset/coin-greekszv5/account/fee-ratezv5/account/infozv5/account/transaction-logzv5/account/smp-groupzv5/account/mmp-statezv5/asset/exchange/order-recordzv5/asset/delivery-recordzv5/asset/settlement-recordz"v5/asset/transfer/query-asset-infoz-v5/asset/transfer/query-account-coins-balancez,v5/asset/transfer/query-account-coin-balancez*v5/asset/transfer/query-transfer-coin-listz+v5/asset/transfer/query-inter-transfer-listz'v5/asset/transfer/query-sub-member-listz/v5/asset/transfer/query-universal-transfer-listz#v5/asset/deposit/query-allowed-listzv5/asset/deposit/query-recordz(v5/asset/deposit/query-sub-member-recordz&v5/asset/deposit/query-internal-recordzv5/asset/deposit/query-addressz)v5/asset/deposit/query-sub-member-addresszv5/asset/coin/query-info   zv5/asset/withdraw/query-recordz%v5/asset/withdraw/withdrawable-amountzv5/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/spot-lever-token/order-recordzv5/spot-margin-trade/statez$v5/spot-cross-margin-trade/loan-infoz"v5/spot-cross-margin-trade/accountz!v5/spot-cross-margin-trade/ordersz(v5/spot-cross-margin-trade/repay-historyzv5/ins-loan/loan-orderzv5/ins-loan/repaid-historyzv5/ins-loan/ltv-convertzv5/lending/infozv5/lending/history-orderzv5/lending/accountzv5/broker/earning-recordzv5/broker/earnings-info)zv5/broker/account-infoz/v5/broker/asset/query-sub-member-deposit-recordz*option/usdc/openapi/private/v1/place-orderz,option/usdc/openapi/private/v1/replace-orderz+option/usdc/openapi/private/v1/cancel-orderz)option/usdc/openapi/private/v1/cancel-allz2option/usdc/openapi/private/v1/query-active-ordersz2option/usdc/openapi/private/v1/query-order-historyz-option/usdc/openapi/private/v1/execution-listz-option/usdc/openapi/private/v1/query-positionz-perpetual/usdc/openapi/private/v1/place-orderz/perpetual/usdc/openapi/private/v1/replace-orderz.perpetual/usdc/openapi/private/v1/cancel-orderz,perpetual/usdc/openapi/private/v1/cancel-allz8perpetual/usdc/openapi/private/v1/position/leverage/savezspot/v3/private/cancel-orderzspot/v3/private/cancel-ordersz$spot/v3/private/cancel-orders-by-idszspot/v3/private/purchasezspot/v3/private/redeemz!spot/v3/private/cross-margin-loanz"spot/v3/private/cross-margin-repayz(asset/v3/private/transfer/inter-transfer   z asset/v3/private/withdraw/createi,  z asset/v3/private/withdraw/cancelz-asset/v3/private/transfer/sub-member-transferz2asset/v3/private/transfer/transfer-sub-member-savez,asset/v3/private/transfer/universal-transferz!user/v3/private/create-sub-memberzuser/v3/private/create-sub-apizuser/v3/private/update-apizuser/v3/private/delete-apizuser/v3/private/update-sub-apizuser/v3/private/delete-sub-apiz,contract/v3/private/copytrading/order/createz,contract/v3/private/copytrading/order/cancelz+contract/v3/private/copytrading/order/closez.contract/v3/private/copytrading/position/closez5contract/v3/private/copytrading/position/set-leveragez/contract/v3/private/copytrading/wallet/transferz2contract/v3/private/copytrading/order/trading-stopz contract/v3/private/order/createz contract/v3/private/order/cancelz$contract/v3/private/order/cancel-allz!contract/v3/private/order/replacez0contract/v3/private/position/set-auto-add-marginz,contract/v3/private/position/switch-isolatedz(contract/v3/private/position/switch-modez-contract/v3/private/position/switch-tpsl-modez)contract/v3/private/position/set-leveragez)contract/v3/private/position/trading-stopz+contract/v3/private/position/set-risk-limitz)contract/v3/private/account/setMarginModezunified/v3/private/order/createz unified/v3/private/order/replacezunified/v3/private/order/cancelz%unified/v3/private/order/create-batchz&unified/v3/private/order/replace-batchz%unified/v3/private/order/cancel-batchz#unified/v3/private/order/cancel-allz(unified/v3/private/position/set-leveragez,unified/v3/private/position/tpsl/switch-modez*unified/v3/private/position/set-risk-limitz(unified/v3/private/position/trading-stopz2unified/v3/private/account/upgrade-unified-accountz(unified/v3/private/account/setMarginModez*fht/compliance/tax/v3/private/registertimez$fht/compliance/tax/v3/private/createz$fht/compliance/tax/v3/private/statusz!fht/compliance/tax/v3/private/urlzv5/order/createzv5/order/amendzv5/order/cancelzv5/order/cancel-allzv5/order/create-batchzv5/order/amend-batchzv5/order/cancel-batchz v5/order/disconnected-cancel-allzv5/position/set-leveragezv5/position/switch-isolatedzv5/position/set-tpsl-modezv5/position/switch-modezv5/position/set-risk-limitzv5/position/trading-stopzv5/position/set-auto-add-marginzv5/position/add-marginzv5/position/move-positionszv5/position/confirm-pending-mmrzv5/account/upgrade-to-utazv5/account/quick-repaymentzv5/account/set-margin-modezv5/account/set-hedging-modezv5/account/mmp-modifyzv5/account/mmp-resetz v5/asset/transfer/inter-transferz*v5/asset/transfer/save-transfer-sub-memberz$v5/asset/transfer/universal-transferz#v5/asset/deposit/deposit-to-accountzv5/asset/withdraw/createzv5/asset/withdraw/cancelzv5/user/create-sub-memberzv5/user/create-sub-apizv5/user/frozen-sub-memberzv5/user/update-apizv5/user/update-sub-apizv5/user/delete-apizv5/user/delete-sub-apizv5/spot-lever-token/purchasezv5/spot-lever-token/redeemz v5/spot-margin-trade/switch-modez!v5/spot-margin-trade/set-leveragezv5/spot-cross-margin-trade/loanz v5/spot-cross-margin-trade/repayz!v5/spot-cross-margin-trade/switchzv5/ins-loan/association-uidzv5/lending/purchasezv5/lending/redeemzv5/lending/redeem-cancelz v5/account/set-collateral-switchz&v5/account/set-collateral-switch-batchzv5/account/demo-apply-money)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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170007170005170031170032170033170034170035170036170037170105170115170116170117170121170130170131170132170133170134170135170136170137170139170140170124170141170142170143170144170145170146170147170148170149170150170151170157170159170190170191170192170193170194170195170196170197170198170199170200170221170222170223170224170226170227170228170229170234170210170213170217170218170010170011170019170201170202170203170204170206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Request timeoutzunknown orderInfozinvalid api_keyoc_diffnew_oczopenapi sign params error!)exactbroadprecisionModeoptionssandboxModeenableDemoTrading)rA   linearinverserE   methodprivatePostV5OrderCreateenableUnifiedMarginenableUnifiedAccount!createMarketBuyOrderRequiresPricecreateUnifiedMarginAccountdefaultTypedefaultSubTyper  defaultSettleUSDTcodeBTC
recvWindowi  timeDifferencer   adjustForTimeDifferenceloadAllOptionsloadExpiredOptionsCCXTSPOTCONTRACTOPTION
INVESTMENTUNIFIEDFUND)
rA   rB   rD   rC   rE   
investmentunifiedfundingfundcontractr  r  r  r  )r  MARGINr  r  r  r  r  ETHTRXBSCOMNISOL)ERC20TRC20BEP20r  SPLr  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	intervalsr   g~jtH?g-C6?)feeSide	tierBased
percentagetakermaker)r  r  r   deposit)tradingr  )deep_extendsuperr0   describer*   r#   r'   r    r   r+   r!   r(   r&   r$   r%   r)   r,   r-   )self	__class__s    P/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/bybit.pyr  zbybit.describe   s5   eT 2 2 ; ; = = U@
'U@
GU@
 $U@
 t	U@

 U@
 U@
 U@
 4U@
 U@
  ___ $_ 	_
 $_ $_ $T_ "4_ t_ $U_  _ /_ 0_ t_ _  7!_" &t#_ _$ (%_& ''_( &t)_* (+_, "4-_. (/_0 ,T1_2 %d3_4 T5_6 7_8 &u9_: +E;_< )%=_> /?_@ &tA_B #DC_D $TE_ _ _F 'G_H (I_J "4K_L M_N &tO_P (Q_R 1$S_T  U_V *:W_X +DY_Z &t[_\ #D]_^ *4__` $Ta_b tc_d "4e_f *5g_ _ _h +Ei_j tk_l  m_n %do_p /q_r +Ds_t u_v !$w_x &ty_z +D{_|  }_~ d_@ $TA_B +DC_D !$E_F "4G_H tI_ _ _J #DK_L eM_N !$O_P uQ_R #DS_T  U_V !$W_X )$Y_Z )$[_\ t]_^ __` Ta_b tc_d "4e_f #Dg_h $Ui_j !$k_ _l */*.$($(#!%#'  }_ _ _U@
T  UU@
r <?:>?  47267  :<7;<    /  
 PO= sU@
r  <0!< 5a< <Q	<
 6q< 5a< ;A< <Q< A!< 5a< /< >q< >q< )!<  Ea!<$ >q%<& 6q'<( 8)< <* A!+<, A!-<. B1/<0 Ma1<2 @3<4 ?5<6 =a7<8 >q9<: :1;<> 1!?<B )!C<D *1E<F 5aG<H 6qI<J >qK<L 5aM<N .qO< < <P ,QQ<R 4QS<T 1!U<V 21W<X :1Y<Z .q[<\ /]<^ 3A_<` 21a<d 3Ae<f 8g<j 4Qk<l :1m<n B1o<p B1q<t 4Qu<v <Qw< <>@J8"J 0	J
 6sJ 9#J 4SJ 23J 4SJ 1#J >rJ ?J A"J EbJ <RJ  >r!J" 5b#J& Nr'J( J2)J J* STV+J, RSU-J. ;B/J0 A"1J2 Eb3J4 H5J6 I"7J8 B29J: DQ;J< 9!=J> <Q?J@ =aAJB B1CJD EaEJF ?GJH J1IJL CAMJ J JN 8OJP ;AQJR <QSJT =aUJV ?WJX DQYJZ Ea[J\ DQ]J^ A!_J` :1aJb <RcJd <QeJf 4QgJh :1iJj MbkJl OPRmJn PQSoJ J Jp EbqJr MdsJt @uJv A"wJ| ,Q}J~ +AJ@ 5aAJD +AEJF ,QGJH 1!IJJ 3AKJN 7OJP 8QJR =aSJT A!UJV ?WJX A!YJ J J\ 4Q]J^ 4Q_J` 5aaJb /cJd .reJf *1gJh 5aiJj /kJl /mJp 9!qJr 3AsJt 5auJv =bwJx HyJz G{J| Eb}J~ FrJ J J@ B2AJB J2CJD >qEJF 8GJH CBIJJ A!KJL 9"MJN DROJP 3BQJR 9"SJT @UJX 4QYJZ ,Q[J\ .q]J^ 21_J` 4QaJb 0cJ J Jd -aeJh ;AiJl 5amJn ?oJp =aqJr <QsJt CAuJx 4QyJz <Q{J| 1!}J~ 5aJ@ 21AJD *1EJF 3AGJH -aIJL 3AMJN 21OJ JP 34KMSJ J JVKDcK GK Fs	K
 DSK McK McK HK HK HK J3K I#K GK STWK" 0#K$ 7%K& 8'K( ?)K K* 3C+K, 1#-K. <R/K0 =b1K4 CC5K6 ;C7K8 ;B9K: H;K< Mc=K> G?K@ <RAKB 9"CKD 5bEKF 5bGKH 9"IKJ 9"KKN GOK K KP GQKR FrSKT I"UKV PQSWKX J2YKZ Mc[K\ ;A]K^ ;A_K` ?aKb <QcKd KAeKf GgKh CAiKj HkKl DQmKn DQoKp FqqK K Kr DQsKv :2wKx ;ByKz :2{K| @}K~ A"K@ @AKB >rCKD CCEKF GGKH EcIKJ CCKKL McMKN CCOKR EbSKT ?UKV ?WK K KX <RYK^ *3_K` )!aKb *3cKd .reKf 0gKh /iKj 0kKl ;AmKp 3AqKr 6qsKt 4QuKv 21wKx 5ayKz 3A{K| :1}K~ 1!K K K@ 5aAKB :1CKF 4QGKH 5aIKJ 5aKKL 6qMKN 0OKP /QKT ;BUKV EcWKX ?YKZ >q[K\ 3B]K^ 3B_Kb 4RcKd 1"eKf 4RgK K Kh -biKj 1"kKl -bmKn 1"oKr 7sKt 5cuKx ;AyKz <Q{K| :3}K~ ;CK@ <SAKD 6qEKH .qIKJ ,QKKL 3AMKN ;AOKP A!QK KT 6qUK KYX XAY YsU@
f (gU@
l yjyZy Zy Z	y
 \y \y \y 0y Zy Zy Zy My Jy Zy \y  0!y" 0#y y$ -%y& .'y( 0)y* 0+y, 0-y. -/y0 Z1y2 ]3y4 Z5y6 .7y8 -9y: -;y< -=y> -?y@ -AyB \CyD ZEy y yF ZGyH .IyJ mKyL lMyN /OyP lQyR /SyT /UyV lWyX lYyZ l[y\ l]y^ /_y` jayb /cyd jeyf lgy y yh liyj jkyl lmyn loyp lqyr lsyt luyv jwyx hyyz 2{y| h}y~ jy@ jAyB lCyD lEyF lGyH lIy y yJ lKyL lMyN lOyP lQyR lSyT lUyV lWyX lYyZ l[y\ j]y^ /_y` /ayb jcyd jeyf jgyh jiyj jky y yl /myn /oyp /qyr lsyt luyv lwyx lyyz l{y| l}y~ jy@ jAyB jCyD mEyF lGyH .IyJ mKyL .My y yN .OyP .QyR lSyT mUyV lWyX mYyZ l[y\ /]y^ l_y` /ayb mcyd meyf mgyh jiyj jkyl jmyn joy y yp mqyr jsyt muyv jwyx jyyz j{y| /}y~ jy@ jAyB jCyD mEyF mGyH lIyJ lKyL jMyN mOyP 1Qy y yR /SyT jUyV jWyX jYyZ m[y\ m]y^ m_y` mayb jcyd jeyf jgyh miyj mkyl mmyn moyp lqyr /sy y yt luyv /wyx /yyz l{y| l}y~ ly@ lAyB /CyD jEyF /GyH lIyJ lKyL lMyN jOyP lQyR lSyT lUy y yV lWyX lYyZ j[y\ j]y^ j_y` jayb lcyd jeyf lgyh jiyj lkyl lmyn loyp lqyr jsyt luyv jwy y yx jyyz l{y| l}y~ ly@ jAyB /CyD /EyF jGyH jIyJ jKyL jMyN lOyP /QyR /SyT /UyV lWyX lYy y yZ l[y\ l]y^ l_y` layb jcyd jeyf jgyh miyj lkyl .myn moyp .qyr .syt .uyv lwyx myyz n{y y y| l}y~ my@ mAyB /CyD /EyF jGyH jIyJ jKyL jMyN lOyP lQyR lSyT lUyV jWyX /YyZ l[y\ l]y y y^ l_y` layb lcyd leyf lgyh liyj lkyl lmyn loyp lqyr lsyt luyv lwyx lyyz l{y| m}y~ my y y@ lAyB lCyD lEyF lGyH lIyJ lKyL lMyN lOyP lQyR lSyT lUyV lWyX lYyZ l[y\ j]y^ /_y` /ay y yb .cyd /eyf mgyh liyj lkyl mmyn loyp mqyr lsyt luyv lwyx lyyz l{y| .}y~ ly@	 lA	yB	 lC	y y yD	 lE	yF	 lG	yH	 lI	yJ	 lK	yL	 /M	yN	 lO	yP	 lQ	yR	 /S	yT	 lU	yV	 lW	yX	 lY	yZ	 .[	y\	 l]	y^	 l_	y`	 la	yb	 lc	yd	 le	y y yf	 lg	yh	 mi	yj	 jk	yl	 jm	yn	 jo	yp	 jq	yr	 js	yt	 ju	yv	 jw	yx	 jy	yz	 j{	y|	 j}	y~	 j	y@
 jA
yB
 jC
yD
 /E
yF
 jG
y y yH
 jI
yJ
 jK
yL
 jM
yN
 jO
yP
 jQ
yR
 jS
yT
 jU
yV
 jW
yX
 jY
yZ
 j[
y\
 j]
y^
 j_
y`
 ja
yb
 jc
yd
 je
yf
 jg
yh
 .i
y y yj
 .k
yl
 .m
yn
 jo
yp
 jq
yr
 js
yt
 ju
yv
 jw
yx
 ly
yz
 l{
y|
 l}
y~
 l
y@ jAyB ]CyD \EyF \GyH \IyJ \Ky y yL \MyN \OyP \QyR \SyT \UyV \WyX \YyZ \[y\ \]y^ \_y` \ayb \cyd \eyf \gyh \iyj Zkyl Zmy y yn Zoyp Zqyr Zsyt Zuyv Zwyx \yyz \{y| \}y~ \y@ \AyB ]CyD .EyF -GyH -IyJ -KyL \MyN \Oy y yP ]QyR \SyT \UyV \WyX \YyZ \[y\ \]y^ \_y` \ayb \cyd \eyf \gyh \iyj \kyl \myn .oyp \qy y yr .syt ]uyv .wyx ]yyz \{y| ]}y~ .y@ \AyB \CyD \EyF .GyH ]IyJ ]KyL ]MyN ]OyP ]QyR ]Sy yT /*))*0*''+,))0qy y yv (6)6':0/2E AI ImU@
@ YAU@
B  DuD#UD  G G GD 8 	D &tD 'D 4TD -eD vD !(D  D D hD  !!!D" *5#D$ !%%D& %e'D( #"$(&&".(%" *# # #$ *&".("! ! #"""   #""" ! ! #*G$ !"" yD D DCU@
L  $!%"&$#  "'"' "!	  M U@
 U@
 U U U	    enablec                 l    t          t          |                               |           || j        d<   dS )z
        enables or disables sandbox mode
        :param boolean [enable]: True if demo trading should be enabled, False otherwise
        r  N)r  r0   set_sandbox_moder  )r  r  r  s     r  r  zbybit.set_sandbox_mode7  s5    
 	eT++F333&,]###r  c                 <   | j         d         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
        :see: https://bybit-exchange.github.io/docs/v5/demo
        :param boolean [enable]: True if demo trading should be enabled, False otherwise
        r  z5 demo trading does not support in sandbox environmentr   apiBackupDemoTradingr   r  N)r  r)   r2   r   omit)r  r  newUrlss      r  enable_demo_tradingzbybit.enable_demo_trading?  s     <& 	btw)``aaa 	 04	%0@DI,-#y7DIe#ty00#y)?@DIeii	+ABBGDI,2()))r  c                 F    |                                  | j        d         z
  S )Nr  )millisecondsr  )r  s    r  noncezbybit.nonceQ  s!      ""T\2B%CCCr  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_valuesafe_value_nsafe_string_2len)r  responser  r  paginationCursor
dataLengthfirsts          r  add_pagination_cursor_to_resultz%bybit.add_pagination_cursor_to_resultT  s    8R88  )M)M)MrRR--f6FQQYY
(zA~~GE&6E"#DGr  c                     |                      | j        d          }|                      | j        d          }||| j        d         r.d| j        d<   d| j        d<   | j        d         | j        d         gS |                     |          }|                      |di           }|                     |d          d	k    | j        d<   |                     |d
          d	k    | j        d<   | j        d         | j        d         gS )zy
        returns [enableUnifiedMargin, enableUnifiedAccount] so the user can check if unified account is enabled
        r  r  Nr  FTr  r  r   uta)r  r  privateGetV5UserQueryApisafe_integer)r  paramsr  r  r  r  s         r  is_unified_enabledzbybit.is_unified_enabled_  s    #oodl<QRR#t|=STT&*>*F|/0 c 7<237;34%:;T\J`=abb44V<<HR __Xx<<F262C2CFI2V2VZ[2[DL./373D3DVU3S3SWX3XDL/023T\BX5YZZr  c                 ,    |                      |          S N) privatePostV5AccountUpgradeToUta)r  r  s     r  upgrade_unified_trade_accountz#bybit.upgrade_unified_trade_account  s    44V<<<r  symbolc                 z   d}d}|                     d          }|                     d          }d }d }|                    d          dk    r-|                     |d          }|                     |d          }n?|                     |d          }|                     |                     |d                    }|                     |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#d d$	S )%NUSDUSDC-/r   r         r2   r  :basequotesettlebaseIdquoteIdsettleIdactiveFtyperE   r  r  rA   rC   rD   TrB   Ccallputamountpriceminmax)r  r  cost)	r  contractSizeexpiryexpiryDatetime
optionTypestrike	precisionlimitsinfo)splitfindsafe_stringconvert_market_id_expire_dateconvert_expire_date	parse8601%convert_expire_date_to_market_id_dateparse_number)r  r  r  r  optionParts
symbolBaser  r  r  r  datetime	timestamps               r  create_expired_option_marketz"bybit.create_expired_option_market  s   ll3''\\#&&
;;sb  ##J22D%%k155FF##K33D778H8HVW8X8XYYF!!+q11%%k155
++F33NN8,,	+
$*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#+
$  &%/3%6%6&&U''//    
   
     U+
 +
 +
 +	
r  NmarketIdmarket	delimiter
marketTypereturnc                    |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!  r  r0   safe_market)r  r"  r#  r$  r%  isOptionr  s         r  r)  zbybit.safe_market  s    D(hd0C0Cb0H/ghmm\`NaNadfNf 	?X);;;44X>>>UD!!--h	:VVVr  c                     d }|                      |||          \  }}d }|                     |||          \  }}|dk    s|dk    r||gS ||gS )NrE   rA   )handle_market_type_and_paramshandle_sub_type_and_params)r  r  r#  r  r  subTypes         r  get_bybit_typezbybit.get_bybit_type  sj    99&&&QQf99&&&QQ8tv~~&>!  r  c                 X    |                      |          }|                     |d          S )aU  
        fetches the current integer timestamp in milliseconds from the exchange server
        :see: https://bybit-exchange.github.io/docs/v5/market/time
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        time)publicGetV5MarketTimer  )r  r  r  s      r  
fetch_timezbybit.fetch_time  s/     --f55   6222r  c                 D   |                      d          sdS | j        d         rdS |                     |          }|                     |dg           }|                     |dg           }i }t	          dt          |                    D ]}||         }|                     |d          }|                     |          }	|                     |d          }
|                     |d	g           }i }d}d}d}d}d}d}t	          dt          |                    D ]}||         }|                     |d
          }|                     |          }| 	                    | 
                    |                     |d                              }||nt          ||          }|                     |d          dk    }|r|n|}|                     |d          dk    }|r|n|}|                     |d          }|||nt          j        ||          }|                     |d          }|||nt          j        ||          }|                     |d          }|||nt          j        ||          }||||o|||| 	                    |          || 	                    |          dd| 	                    |          dddd	||<   ||	||
|o|||| 	                    |          |ddd| 	                    |          dd| 	                    |          ddd|d||	<   |S )a  
        fetches all available currencies on an exchange
        :see: https://bybit-exchange.github.io/docs/v5/asset/coin-info
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        FNr  r  r  r   coinr3   chainschainminAccuracychainDepositr   chainWithdrawwithdrawFeewithdrawMin
depositMinr	  )r   r  )	r  r2   networkr  r  r   feer  r  )r  r   r  )r  r  r2   r3   r  r  r   r?  r  r  r  )check_required_credentialsr  privateGetV5AssetCoinQueryInfor  ranger  r  safe_currency_codenetwork_id_to_coder  parse_precisionr
  r  r.   
string_min)r  r  r  r  r  r  icurrency
currencyIdr  r3   r6  r  minPrecisionminWithdrawFeeStringminWithdrawStringminDepositStringr  r   jr7  	networkIdnetworkCoder  depositAllowedwithdrawAllowedwithdrawFeeStringminNetworkWithdrawStringminNetworkDepositStrings                                r  fetch_currencieszbybit.fetch_currencies  s&    ..u55 	4<+, 	466v>>> x266tVR00q#d))$$ M	 M	AAwH))(F;;J**:66D##Hf55D__Xx<<FHL#'  $#GH1c&kk** & &q	 ,,UG<<	"55i@@ --d.B.B4CSCSTY[hCiCi.j.jkk	-9-AyyLZcHdHd!%!2!25.!I!IQ!N-;I..'"&"3"3E?"K"Kq"P/>M??X$($4$4UM$J$J!$0AUA]+<+<dkdv  xI  K_  e`  e`(+/+;+;E=+Q+Q(+7EVE^(@(@elew  yQ  Sd  fe  fe%*.*:*:5,*O*O'*6CSC['>'>bibt  vM  O_  c`  c`$!#*,@- /,,->??!* $(#4#45M#N#N#'% %
 $(#4#45L#M#M#'$ $	 	) )%%* ! !.h"$(()=>>)  $# 
  $001BCC#! !
  $001ABB#     %1 F4LL4 r  c                 0   | j         d         r|                                  g }|                     | j         dg d          }t          dt	          |                    D ]=}||         }|dk    r)|                    |                     |                     :|dk    r+|                    |                     ddi                     k|dk    r+|                    |                     ddi                     |d	k    r|                    |                     d
di                     |                    |                     d
di                     |                    |                     d
di                     "t          | j
        dz   |z   dz             |}|                     |dg           }|                     |dg           }|                     |dg           }	|                     |dg           }
|                     |dg           }|                     |dg           }|                     ||	          }|                     |
|          }|                     ||          }|                     ||          }|                     ||          S )a  
        retrieves data on all markets for bybit
        :see: 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  rz   )rA   r  r  r   rA   r  categoryr  rE   baseCoinr  r  r  z+ fetchMarkets() self.options fetchMarkets "z " is not a supported market typer   r  r     r   )r  load_time_differencer  rB  r  appendfetch_spot_marketsfetch_future_marketsfetch_option_marketsr   r2   array_concat)r  r  promisesUnresolvedrz   rG  r%  promisesspotMarketslinearMarketsinverseMarketsbtcOptionMarketsethOptionMarketssolOptionMarketsfutureMarketsoptionMarketsderivativeMarketss                   r  fetch_marketszbybit.fetch_markets  s    <12 	(%%'''t|^EbEbEbccq#l++,, 	O 	OA%aJV##"))$*A*A&*I*IJJJJx''"))$*C*CZQYDZ*[*[\\\\y(("))$*C*CZQZD[*\*\]]]]x''"))$*C*CZQVDW*X*XYYY"))$*C*CZQVDW*X*XYYY"))$*C*CZQVDW*X*XYYYY#DG.[$[^h$h  lN  %N  O  O  O%ooh266!R881b99??8Q;;??8Q;;??8Q;;))-HH))*:<LMM))-9IJJ --m]KK  .?@@@r  c                    ddi}|                      |                     ||                    }|                     |di           }|                     |dg           }g }|                     d          }|                     d          }t	          dt          |                    D ]}	||	         }
|                     |
d          }|                     |
d          }|                     |
d	          }|                     |          }|                     |          }|d
z   |z   }|                     |
d          }|dk    }|                     |
d          }|                     |
d          }|                     |d          }|	                    i d|d|d|d|dd d|d|dd dddddd ddddddd|ddd d d ||d d d d d |                     |d!          |                     |d"|          d#|                     d$          d d%|                     |d&          |                     |d'          d%d d d%|                     |d(          |                     |d)          d%d*d |
d+           |S ),NrX  rA   r  r  z0.001r   r  rY  	quoteCoinr  statusTradinglotSizeFilterpriceFilterquotePrecisionr2   r  r  r  r  r  r   r  TrB   rC   FrD   rE   r  r  r  basePrecisiontickSizer  r   r	  minOrderQtymaxOrderQtyminOrderAmtmaxOrderAmtleverager  r  r  r  r  r  r  r  r  r  r  r  r  createdr  )
 publicGetV5MarketInstrumentsInfoextendr  r  rB  r  r  rC  safe_numberr\  )r  r  requestr  responseResultmarketsr  takerFeemakerFeerG  r#  r2   r  r  r  r  r  ro  r  rq  rr  rs  s                         r  r]  zbybit.fetch_spot_markets  ss   
 88Wf9U9UVV@ 8R@@//.&"==$$W--$$W--q#g,,'' ?	 ?	AQZF!!&(33B%%fj99F&&v{;;G**622D++G44ECZ%'F%%fh77F	)F OOFODDM//&-@@K!--m=MNNNMM 2b2&2 2 	2
 $2 &2 72 D2 2 2 $2 2 %2 %2 &2  E!2" $#2$  !! $"&""..}oNN!--k:~VV   $0055#! !
  $//}MM#//}MM 
  $# 
  $//}MM#//}MM  $  c2 2 2 2 2 2 2f r  c                 	   |                      |          }d|d<   |                     |          }|                     |di           }|                     |dg           }|                     |d          }||||d<   |                     |          }|                     |di           }|                     |dg           }t	          |          }	|	dk    rn.|                     ||          }|                     |d          }|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,d-d d|"d|#d.d,d/|!d0k    d1d2d	|||                     |d3|                     d4                    |                     |d5|                     d6                    |'|%|&d d |                     |d7          |                     |d8          d9|                     | d:          |                     | d;          d<|                     |d d!          |                     |d=d>          d<|                     |d?          |                     |d@          d<d d d<dA|                     |dB          |dC           |
S )DN  limitr  r  r  r  r   rX  r  r  contractTypeInverseFuturesLinearFuturesLinearPerpetualInversePerpetualr  rY  rn  
settleCoinr  r  r  rq  rr  leverageFilterro  rC   rD   deliveryTimer  r  minTradingQtyrv  r   r2   r  r  r  r  r  r   r  rA   FrB   rE   r  rp  r  Tr  0.0006r  0.0001qtyStepru  r  minLeveragemaxLeverager	  maxTradingQtyrw  minPricemaxPricerz  
launchTimer|  )r  r~  r  r  r  r`  rB  rC  	omit_zerointiso8601yymmddsafe_number_2r  r\  r  r  )(r  r  r  r  r  r  responseInnerdataNew
rawMarketsrawMarketsLengthr  rX  rG  r#  r  r  r  inverseFutureslinearFutureslinearPerpetualinversePerpetualr2   r  r  defaultSettledIdr   r  r  r  r  rq  rr  r{  ro  rC   rD   r  r  r  r  s(                                           r  r^  zbybit.fetch_future_markets  s=   V$$w88@@x266//$33++D2BCC'".#3x  $ E Ef M M//-2FF!__WfbAA
#&z?? #q((++J@@#'#3#3G=M#N#N  #.l ##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 OOFORHHM//&-DDKv/?DDH%%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 2b2&2 2 	2
 &2 &2 72 H2 2 2 $2 2 &2 %2 6Y.2  D!2" &#2$ #))&*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2 2 2 2 2 2 2f r  c                    ddi}|                      |                     ||                    }|                     |di           }|                     |dg           }| j        d         rd|d<   |                     |d          }||||d	<   |                      |                     ||                    }|                     |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    }|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-|                     d.                    |                     |d/          ||                     |          |                     |          |                     |d0          |                     |d1          |                     |d2          d3d d d4|                     |d/          |                     |d5          d4|                     |d6          |                     |d7          d4d d d4d8| 	                    |d9          |d:           (|S );NrX  rE   r  r  r  r  r  r  r  r   r  rY  rn  r  rq  rr  ro  r  r  r  r  rp  r  r2   r  r  r  r  r  r  r  r   r  rA   FrB   rC   rD   Tr  r  r  r  r  r  r  rv  optionsTyper  ru  r  r	  rw  r  r  rz  r  r|  )r~  r  r  r  r  r  r`  rB  rC  r  r  r\  r  r  r  r  safe_string_lower)r  r  r  r  r  r  r  r  r  r  r  r  rG  r#  r2   r  r  r   r  r  r  rq  rr  ro  r  splitIdr  optionLetterisActives                                r  r_  zbybit.fetch_option_markets  sh   
 88Wf9U9UVVx266//$33<() 	S#GG#//6FGG+&2(8GH%$($I$I$++V]_eJfJf$g$gM"oomXrJJG!%&"!E!EJ'*:$'1,,"//
GDDG'+'7'7AQ'R'R$ '2Z q#g,,'' D	 D	AQZF!!&(33B%%fj99F&&v{;;G''==H**622D++G44E,,X66F OOFORHHM//&-DDK%%fh77F&&v~>>FhhsmmG%%gq11F++GQ77L)+H 3DL)9: 3Ma@b 3 2"2dSj5036?#ETZH[H[[^aadjjmpps2 D2 U	2
 f2 f2 w2 2 H2 E2 e2 E2 e2 d2 h2  !2" d#2$  $!--fj$BSBST\B]B]^^!--fj$BSBST\B]B]^^$($4$4]M$R$R$&*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"c2 2 2 2 2 2f r  c           	         |                      |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$|          S )%NopenInterestValuer1  r  rA   r  	lastPriceprevPrice24hprice24hPcnt100turnover24h	volume24h	bid1Price	ask1PricehighPrice24hlowPrice24hr   r  highlowbid	bidVolumebidSizebid1Sizeask	askVolumeaskSizeask1SizevwapopencloselastpreviousClosechanger  average)
baseVolumequoteVolumer  )	r  r  r)  safe_symbolr.   
string_mulsafe_tickerr  r  )r  tickerr#  isSpotr   r"  r  r  r  r  r  r  r  r  r  r  r  s                    r  parse_tickerzbybit.parse_ticker6  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#!
$ %&)!
 !
 !
* +  	r  c                    |t          | j        dz             |                                  |                     |          }d|d         i}|d         rd|d<   n)|d         rd|d<   n|d         rd|d<   n|d	         rd	|d<   |                     |                     ||                    }|                     |d
g           }|                     |dg           }|                     |d          }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: https://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  r2   rA   rX  rE   r  r  r  r  r   )	r"   r2   load_marketsr#  publicGetV5MarketTickersr  r  	safe_dictr  )	r  r  r  r#  r  r  r  tickers	rawTickers	            r  fetch_tickerzbybit.fetch_ticker  s/    >#DG.Y$YZZZV$$fTl

 &> 	0"(GJh 0&.
##! 0&.
##	" 0&/
#00Wf1M1MNNN 8R88//&&"55NN7A..	  F333r  symbolsc                    |                                   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                    i }d}|                     d||          \  }}| 
                    |d	          }d}|                     d||d
          \  }}|dk    r|d|d<   n|dk    s|dk    s|||d<   n|dk    rd|d<   |                     |                     ||                    }|                     |di           }|                     |dg           }|                     ||          S )aW  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: 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'
        :returns dict: an array of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nr   r   r  r  r  z@ fetchTickers can only accept a list of symbols of the same typer  r.  r  rA   rX  rC   rD   rE   r  r  )r  r,  rB  r  r  r)  r#  r#   r2   r\  r  r-  r  r  r  	safe_listparse_tickers)r  r  r  r#  parsedSymbolsmarketTypeInfor  currentTyperG  r  isExchangeSpecificSymbolr  r  passedSubTyper.  r  r  
tickerLists                     r  fetch_tickerszbybit.fetch_tickers  s8    	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$$VH%56666

 99.&RXYYf ((;;99.&RXZbcc6>>m3"(GJV^^tx//73F")GJX"*GJ00Wf1M1MNNN 8R88^^FFB77
!!*m<<<r  c           	         |d         rdnd}|                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     ||          gS )	Nr     r   r   r   r  r  rZ  )r  r  )r  ohlcvr#  volumeIndexs       r  parse_ohlcvzbybit.parse_ohlcvP  s     #9-5aaAeQ''UA&&UA&&UA&&UA&&UK00
 	
r  r   sincer  c           	         |t          | j        dz             |                                  d}|                     |dd          \  }}|r|                     d|||||d          S |                     |          }d|d         i}|d	}|||d
<   |||d<   |                     d||          \  }}|                     | j        ||          |d<   d}	|d         r0d|d<   | 	                    | 
                    ||                    }	n|                     |d          }
|                     |d          }|d         rd|d<   n%|d         rd|d<   nt          | j        dz             |
dk    r*|                     | 
                    ||                    }	n|
dk    r*|                     | 
                    ||                    }	nY|
dk    r*|                     | 
                    ||                    }	n)| 	                    | 
                    ||                    }	|                     |	di           }|                     |dg           }|                     |||||          S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :see: https://bybit-exchange.github.io/docs/v5/market/kline
        :see: https://bybit-exchange.github.io/docs/v5/market/mark-kline
        :see: https://bybit-exchange.github.io/docs/v5/market/index-kline
        :see: 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  r2      startr  endintervalrA   rX  r  r  r  z1 fetchOHLCV() is not supported for option marketsmarkindexpremiumIndexr  r  )r"   r2   r  handle_option_and_params"fetch_paginated_call_deterministicr#  handle_until_optionr  r   publicGetV5MarketKliner  r  r)   publicGetV5MarketMarkPriceKline publicGetV5MarketIndexPriceKline'publicGetV5MarketPremiumIndexPriceKliner  r  parse_ohlcvs)r  r  	timeframer  r  r  r  r#  r  r  r  r  ohlcvss                r  fetch_ohlcvzbybit.fetch_ohlcvf  s     >#DG.X$XYYY88zZZ& 	x::<QVX]_hjprvwwwV$$fTl
 =E$GG$GG225'6JJ"..t	9UU
&> 	U"(GJ224;;w3O3OPPHH$$VW55EYYvw//Fh b&.
##	" b&/
##"47-`#`aaa??GU[@\@\]]'!!@@WV\A]A]^^.((GGT[]cHdHdee66t{{7F7S7STTT 8R8833  E5IIIr  c                    |                      |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 S )Nr   r  rC   fundingRatenextFundingTime	markPrice
indexPricer  interestRateestimatedSettlePricer  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetime)r  r  r  r  r  r  )
r  r  r#  r   r"  r  r  r  r  r  s
             r  parse_funding_ratezbybit.parse_funding_rate  s   2 %%fk::	6;//##FH55!!(FD&AA&&v}==,,V5FGG$$V[99	%%fl;;

F
f
 
 *	

 D
 #D
 
 Y//
 ;
  0
 t||,<==
 t
 #D
 "4
 "4
  '!
" &t#
 	
r  c                 N   |                                   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g           }	|                     |d          }
| 
                    |	d          }	i }t          dt          |	                    D ]8}|	|         }|
|d<   |                     |	|         d          }|d         }|||<   9|                     |d|          S )a  
        fetches funding rates for multiple markets
        :see: 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: an array of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        Nr   r   r2   r  rp   rC   z& fetchFundingRates() does not support  marketsr  rX  r  r1  r  r   )r  market_symbolsr#  r  r,  r)   r2   r-  r  r  r  r  rB  r  filter_by_array)r  r  r  r#  r  symbolsLengthr  r.  r  r  r   fundingRatesrG  r  r  r  s                   r  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00Wf1M1MNNJ __Xx<<
%%h77	__Z88
q#j//** 	* 	*A"1I%.Ik",,Z]DAAFH%F#)L  ##L(GDDDr  c           
         |t          | j        dz             |                                  |d}d}|                     |dd          \  }}|r|                     d|||d|d          S d|i}|                     |          }|d	         }|d
         |d	<   d}|                     d||          \  }}|dk    s|dk    rt          | j        dz             ||d<   |||d<   |                     |dd          }	| 	                    |d|	          }
| 
                    |g d          }|
|
|d<   n|d}|||z  z   |d<   |                     |                     ||                    }g }|                     |d          }|                     |d          }t          dt          |                    D ]}||         }| 	                    |d          }|                    ||                     |                     |d	          ddd          |                     |d          ||                     |          d           |                     |d          }|                     ||||          S )a  
        fetches historical funding rate prices
        :see: 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 argumentr  Fro   r  8hr  r  r2   rA   rE   zA fetchFundingRateHistory() only support linear and inverse marketrX  	startTimeuntiltillendTimer  r  r  i tr  r  r   fundingRateTimestamprC   r  )r  r  r  r   r  r   )r"   r2   r  r  r  r#  r/  r)   safe_integer_2r  r  publicGetV5MarketFundingHistoryr  r  rB  r  r\  r  r  r  r  sort_byfilter_by_symbol_since_limit)r  r  r  r  r  r  r  r#  r  r  r  fundingIntervalr  ratesr  
resultListrG  entryr   sorteds                       r  fetch_funding_rate_historyz bybit.fetch_funding_rate_historyJ	  s    >#DG.e$efff=E88AZ\fgg& 	::;TV\^cejlprxz}~~~ U
 V$$!"4L**+DffUUf6>>TX--tw)llmmm"
#(GK ##FGV<<##FIu==6#?#?#?@@!(GI "4%*U_-D%D	"77GV8T8TUU& 844__VV44
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Nr  c                    |                      |g d          }|                     |d          }d|v rdnd}||d         }|                     |d          }||dk    r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#|          S )$N)execIdr2   tradeIdr  
createTyper  rA   r  rX  )execQtyorderQtysize)	execPrice
orderPricer  	execValue)r1  execTime	tradeTimesideisBuyerbuysellisMakerr  r  lastLiquidityIndUNKNOWNTAKERMAKERAddedLiquidity	orderTypeunknownexecFeefeeRate0r  r  r  r  )r  rH  rateorderId)r2   r  r   r  r  orderr  r5  takerOrMakerr  r  r  r?  )safe_string_nr  r)  safe_integer_nr  r  r  lowerr.   	string_gt
safe_trader  )r  trader#  r2   r"  r%  rX  r  amountStringpriceString
costStringr   r5  r6  r9  rG  r:  r?  feeCostStringr?  feeRateStringfeeCurrencyCodes                         r  parse_tradezbybit.parse_trade	  sG   | 'B'B'BCC##E844$0E$9$9ZZ
J##E:666!!#
!!(FD*EE!))%1P1P1PQQ((0T0T0TUU%%e[99
''/P/P/PQQ	%%eV44<''y99G" '3uuV//%33&-: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[%+% C
 "Y//%%eY77( " 
  
   	r  c                    |t          | j        dz             |                                  |                     |          }d|d         i}|||d<   d}|                     d||          \  }}||d<   |                     |                     ||                    }|                     |di           }	|                     |	d	g           }
| 	                    |
|||          S )
a  
        get the list of most recent trades for a particular symbol
        :see: 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  r2   r  r   rX  r  r  )
r"   r2   r  r#  r/  publicGetV5MarketRecentTrader  r  r  parse_trades)r  r  r  r  r  r#  r  r  r  r  tradess              r  fetch_tradeszbybit.fetch_tradesF
  s     >#DG.Y$YZZZV$$fTl

   %GG**=&&IIf"
44T[[&5Q5QRR. 8R8833  >>>r  c                     |t          | j        dz             |                                  |                     |          }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g           }|                     |d          }	|                     |||	dd          S )a;  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: 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  r2   r   rA   r   rX  rE   r  r  r  r  tsba)	r"   r2   r  r#  publicGetV5MarketOrderbookr  r  r  parse_order_book)
r  r  r  r  r#  r  defaultLimitr  r  r   s
             r  fetch_order_bookzbybit.fetch_order_book}
  s>    >#DG.\$\]]]V$$fTl
 &> 	0L"(GJh 0&.
##! 0&.
##	" 0&/
#%*%655\224;;w3O3OPP4 8R88%%fd33	$$VVYSIIIr  c                    |                      |d          }|||                     |          d}|                     |di           }|                     |g d          }|Od}|                                 }|                     |d          |d<   |                     |d          |d	<   |||<   n-t          d
t          |                    D ]}||         }	|                     |	d          }
|
dk    s|
dk    s|
dk    r|                     |	d          }t          d
t          |                    D ]}|                                 }||         }|                     |d          }|                     |d          }||t          j	        ||          |d<   |                     |d          |d	<   | 
                    |dd          |d<   |                     |d          }|                     |          }|||<   ʐ2|                                 }|                     |	d          }|                     |	d          }||t          j	        ||          |d<   | 
                    |	d	d          |d	<   |                     |	g d          |d<   |                     |	d          |d<   |                     |	g d          }|                     |          }|||<   |                     |          S )Nr1  )r  r   r  r  )loanAccountListr  balancer  availableBalancefreewalletBalancetotalr   accountTyper  r  r  r5  borrowAmountaccruedInterestdebtavailableToWithdrawloaninterest)rf  availableBalanceWithoutConvertre  transferBalancelockedused)tokenIdr5  currencyCoin)r  r  r  r  accountr  rB  r  r.   
string_addr  rC  rH  safe_balance)r  r  r   r  r  currencyListr  rv  rG  r&  ri  coinsrN  	coinEntryrn  ro  rI  s                    r  parse_balancezbybit.parse_balance
  s6   N %%h77	"Y//
 

 8R@@((9_9_9_``DllnnG"..~?QRRGFO#//PPGG"F4LL1c,//00 + +$Q"..umDD)++{j/H/HK[aLaLa OOE6::E"1c%jj11 / /"&,,..$)!H	#//	>JJ#'#3#3I?P#Q#Q ,83G.5.@x.P.PGFO+/+;+;I+W+W(*.*<*<YH]_e*f*f%)%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  (((r  c                    |                                   i }|                                 \  }}|p|}d}|                     dd|          \  }}|dk    }|dk    }|r|s|rd}n|rd}|                     | j        di           }	|                     |	||          }
d}|                     d|          \  }}d}|r,|*|                     |                     ||                    }nc|
dk    r/|
|d	<   | 	                    |                     ||                    }n.|
|d	<   | 
                    |                     ||                    }|                     |          S )
aW  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://bybit-exchange.github.io/docs/v5/spot-margin-normal/account-info
        :see: https://bybit-exchange.github.io/docs/v5/asset/all-balance
        :see: 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', 'fund']
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        NrZ   rA   rC   r  r  r  r  ri  )r  r  r,  r  r  safe_string_upperhandle_margin_mode_and_params'privateGetV5SpotCrossMarginTradeAccountr  1privateGetV5AssetTransferQueryAccountCoinsBalance privateGetV5AccountWalletBalancer|  )r  r  r  r  r  isUnifiedAccountr  r  isSwapaccountTypesunifiedType
marginModer  s                r  fetch_balancezbybit.fetch_balanceR  s    	484K4K4M4M11/G3G99.$PVWWf&.&. 	" ! !  "!t|5ErJJ,,\4FF
!??PVWW
F 		[z-CCDKKPWY_D`D`aaHHF"" &1GM"MMdkkZaciNjNjkkHH%0GM"<<T[[RX=Y=YZZHN !!(+++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  r  ro  statusess      r  parse_order_statuszbybit.parse_order_status  s   
6
 
 h	

 

 f
 6
 

 )(
 v
 6
 

 v
 &x
  h!
" V#
$ %
( 6)
* &/
 
 
2 &&999r  c                 >    ddddd}|                      |||          S )NGTCIOCFOKPO)GoodTillCancelImmediateOrCancel
FillOrKillPostOnlyr  )r  timeInForcetimeInForcess      r  parse_time_in_forcezbybit.parse_time_in_force  s4    #!&	
 
 k;GGGr  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d          }|                      |d          }|                     |          }|                     |d          }d }|                      |d          }|ld }|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          }|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/|d0|d	|	d|d"|d1d d$|                     |d$          d|d|d2|d#|d3|| |||||||d d4	|          S )5Nr  rC  rX  rA   r  r  rE  orderLinkIdr  )r  ro  r2   clientOrderIdr  tpslModer  createdTime	createdAtr?  r  qtycumExecValue
cumExecQty	leavesQtyupdatedTime	updatedAtorderStatusr5  
cumExecFeer7  r  r  r  r  r  rH  r   avgPricer  triggerPrice
reduceOnly
takeProfitstopLosstriggerDirectionr   r8  r  r2   r  r   r  lastTradeTimestamplastUpdateTimestamppostOnly	stopPricetakeProfitPrice)	stopLossPricer  r  r  filled	remainingro  r?  rX  )r  
safe_orderr  r)  r  r  r  r.   rK  r  r  r  r  r  )$r  rF  r#  r  rX  inferedMarketTyper"  
isContractr%  r  r   r2   r  r  r  r  r  r  r  	rawStatusro  r5  r?  rQ  rS  r  r  rawTimeInForcer  r  r  r  r  r  isAscendingisStopOrderType2s$                                       r  parse_orderzbybit.parse_order  s   | v..s{{++E:>>/76/A/AFF
!!(**5)<<%)%5%5e]%K%K"..t/?/?x/P/PRVX\^opp( (    ##E844 E)

JJ'1=vJ!!(FD*EE!''}kJJ	eY//%%e[99  00!!%//~66!!%66$$UK88	!00{SS$$UM::	((33%%eV44((==$"Of~ \$]C88 	9u}}*0.*0/u}}*0/*0.4:94E"[&..6RZK[%+ C ((>>%C,>,>,B,B M>>$"2"25*"E"EFF))%??..~>>NN4#3#3E>#J#JKK	__UL99
..)9)9%)N)NOOt'7'7z'J'JKK++E3EFF'3.%T1Az!'7! * ) *DFNN )#)9# ,"+ ,DEMM"+  
E 
" 
 ] 
 	 

 Y// 
 !"4 
 "#5 
 f 
 D 
 ; 
  
 $//%>> 
 D 
 U 
  
  I! 
" # 
$ +"5 
  
  
6 7  	r  r  c                     |                                   |                     |          }|d         st          | j        dz             |                     |dd|d|          S )a  
        :see: https://bybit-exchange.github.io/docs/v5/order/create-order
        create a market buy order by providing the symbol and cost
        :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>`
        rA   z9 createMarketBuyOrderWithCost() supports spot orders onlyr#  r7  r   )r  r#  r)   r2   create_order)r  r  r  r  r#  s        r  !create_market_buy_order_with_costz'bybit.create_market_buy_order_with_cost  sh     	V$$f~ 	ftw)ddeee  5$6JJJr  c                 0   |                                   |                                 }|d         }|st          | j        dz             |                     |          }|d         st          | j        dz             |                     |dd|d|          S )a  
        :see: https://bybit-exchange.github.io/docs/v5/order/create-order
        create a market sell order by providing the symbol and cost
        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   z; createMarketSellOrderWithCost() supports UTA accounts onlyrA   z: createMarketSellOrderWithCost() supports spot orders onlyr#  r8  )r  r  r)   r2   r#  r  )r  r  r  r  typesr  r#  s          r  "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  64FKKKr  r  r5  r  r  c           	      t   |                                   |                     |          }|                                 \  }}	|p|	}
|d         dk    }|r|
s|                     ||||||          S |                     |dd          }|du}|                     |||||||	          }|                     | j        di           }|                     |dd          }d}|s|d	k    r| 	                    |          }n| 
                    |          }|                     |d
i           }|                     ||          S )a	  
        create a trade order
        :see: https://bybit-exchange.github.io/docs/v5/order/create-order
        :see: 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 fullfilled, 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 boolean [params.isLeverage]: *unified spot only* False then spot trading True then margin trading
        :param str [params.tpslMode]: *contract only* 'full' or 'partial'
        :param str [params.mmp]: *option only* market maker protection
        :param str [params.triggerDirection]: *contract only* the direction for trigger orders, 'above' or 'below'
        :param float [params.triggerPrice]: The price at which a trigger order is triggered at
        :param float [params.stopLossPrice]: The price at which a stop loss order is triggered at
        :param float [params.takeProfitPrice]: The price at which a take profit order is triggered at
        :param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered
        :param float [params.takeProfit.triggerPrice]: take profit trigger price
        :param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered
        :param float [params.stopLoss.triggerPrice]: stop loss trigger price
        :param str [params.trailingAmount]: the quote amount to trail away from the current market price
        :param str [params.trailingTriggerPrice]: the price to trigger a trailing order, default uses the price argument
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  trailingAmounttrailingStopNrM   r  r   privatePostV5PositionTradingStopr  )r  r#  r  create_usdc_orderr  create_order_requestr  r  r  r  r  r  r  )r  r  r  r5  r  r  r  r#  r  r  r  isUsdcSettledr  isTrailingAmountOrderorderRequestr  defaultMethodr  rF  s                      r  r  zbybit.create_order  sk   < 	V$$484K4K4M4M11/G3Gx(F2 	U!1 	U))&$feVTTT++F4DnUU .d :00tVUTZ\pqq//$,rBB(((<VWW  	C]6X%X%X<<\JJHH44\BBH x266v...r  Tc                    |                      |          }|d         }|                                }	||	dk    rt          | j        dz             d }
|                     |ddd          \  }
}d|d         i}|                     |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    }|
dk    }|s|r|s|s
|s|d         rt          | j        dz             |s|r|rY| 
                    ||          |d<   |r<d|d<   d|d<   | 
                    ||          |d<   |                     ||          |d<   na|rW| 
                    ||          |d<   |r<d|d<   d|d<   | 
                    ||          |d<   |                     ||          |d<   n|                     |          |d <   |                     |	          |d!<   |                     |d"          }d }|                     ||d#k    |          \  }}|rd$|d"<   n#|d%k    rd&|d"<   n|d'k    rd(|d"<   n|d)k    rd*|d"<   |d         r|d+|d,<   n|||s|rd-|d,<   |                     |d.          }|||d/<   n|d0         r|                                 |d/<   |r| 
                    ||          |d1<   |d         rd|d2<   n)|d3         rd3|d2<   n|d4         rd4|d2<   n|d0         rd0|d2<   |                     |d5          } |                     |d5          }|	dk    o|dk    o|d up| d u}!|d         r|dk    r|r|!s| |hd6|d7<   d }"| | }"nA|                     |          }#|                     |          }$t%          j        |#|$          }%|%}"|                     ||"          |d8<   nd9|d7<   |                     ||          |d8<   n|d         r|dk    r|dk    rd:}&|                     |dd;d:          \  }&}|&rz|| t          | j        d<z             |                     |          }#|                     |          }$t%          j        |#|$          }%| | n|%}'|                     ||'          |d8<   n7|                     ||          |d8<   n|s|s|                     ||          |d8<   |r!|| 
                    ||          |d<   ||d<   n|r|s|                     |d=          }(|                     |g d>          }|d         r|(t+          | j        d?z             n.|(t          | j        d@z             |(dAk    p|(dBk    })|)rdCndD|d=<   | 
                    ||          |d<   n?|s|r;|s9|r
|rdCndD|d=<   n	|rdDndC|d=<   |r|n|}| 
                    ||          |d<   d:|dE<   |s|r|s|rl|                     |dd	|          }*| 
                    ||*          |d<   |                     |d1          }+|+#d|d<   d|d<   | 
                    ||+          |d<   |rl|                     |dd	|          },| 
                    ||,          |d<   |                     |d1          }-|-#d|d<   d|d<   | 
                    ||-          |d<   |                     |g dF          }|                     ||          S )GNr  r  7 createOrder requires a price argument for limit ordersrM   r  r  r2   r  r  r  r  r  r  trailingTriggerPriceactivePricer  r  r#  r7  r  rA   zf the API endpoint used only supports contract trailingAmount, stopLossPrice and takeProfitPrice ordersPartialr  LimitslOrderTypeslLimitPriceslSizetpOrderTypetpLimitPricetpSizer5  r?  r  postonlyr  gtcr  fokr  iocr  	StopOrderorderFilter	tpslOrderr  r  rE   r  rX  r  r  r  rn  
marketUnitr  rY  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 argumentr  )r  r  r  zU createOrder() : trigger order does not support triggerDirection for spot markets yetz stop/trigger orders require a triggerDirection parameter, either "above" or "below" to determine the direction of the trigger.abover   r   r  r  )r  r  r  r  r  r  r  r  r  r  r  )r#  rJ  r"   r2   r  safe_value_2r  r  number_to_stringr'   price_to_precisionamount_to_precision
capitalizer  handle_post_onlyr  uuid16r  r.   r  cost_to_precisionr)   r  ).r  r  r  r5  r  r  r  isUTAr#  lowerCaseTyper  r  r  stopLossTriggerPricetakeProfitTriggerPricer  r  r  r  r  isTriggerOrderisStopLossTriggerOrderisTakeProfitTriggerOrder
isStopLossisTakeProfitisMarketisLimitisBuyisAlternativeEndpointr  r  r  r  isMarketBuyAndCostInferable	orderCostrN  rO  quoteAmountr  costRequestr  
isAsendingslTriggerPricer  tpTriggerPricer  s.                                                 r  r  zbybit.create_order_request4  s.
   V$$!

M 8 8#DG.g$ghhh $ = =fmU]_y z zvfTl
2 ((MM#vGG!%9J!K!K??6:66__V\::
#11&:PR_aeavavw|a}a}~~++F4DnUU .d :%T1!5T!A#9#E T)
!- H,7* -1S S  -	J$9 -	J W\ W^ Wvf~ W"47  .V  $V  W  W  W% U)A U) U*.*A*A&J^*_*_GJ' U.7
+18.262I2I&RW2X2X/,0,D,DVV,T,T)- U,0,C,CFLb,c,cGL) U.7
+18.262I2I&RW2X2X/,0,D,DVV,T,T)"ood33GFO#'??=#A#AGK 00GGKH#44X{j?XZ`aaHf /)3&&%%).&&%%).&&%%).&f~ 9+-8GM**)59O9[_i9[my9[-8GM* ,,V_EEM()6&&! 7)-& J#'#:#:65#I#I &> 	+"(GJH 	+"*GJI 	+"+GJH 	+"*GJ//66**'4'@  'Ftu}  'F\aim\m  \Esw  @D  tD#&> "	Jtx//U/C^/ e&7(3% 	# $II#'#8#8#@#@L"&"7"7">">K")"4\;"O"OK +I!%!7!7	!J!J(2%!%!9!9&&!I!IF^ 	J!1!1 15-8<8U8UV\^k  nQ  SW  9X  9X5-v0 
HM&tw  2m  (m  n  n  n#'#8#8#@#@L"&"7"7">">K")"4\;"O"OK+/+;$$+K%)%;%;FK%P%PGENN!%!7!7!G!G( J1F J!%!9!9&&!I!I  	)#/)-)@)@I])^)^&&4GN## 	)$9 	)#//8JKKYYv'X'X'XYYFf~ E#/&tw  2I  (I  J  J  J 0 $++DG  7x  -x  y  y  y/7:X@PTW@W
3=.Daa1*+&*&=&=fl&S&SGN##$ 	)(@ 	)J_ 	) Q3I.Paaq*++3I.Paaq*+3Ie//OeL&*&=&=fl&S&SGN#$(GL! 	\, 	\0E 	\ \!%!2!28^[Zb!c!c&*&=&=fn&U&U
##xAA+*3GJ'-4GM*.2.E.Efl.[.[GN+ \!%!2!2:~{\f!g!g(,(?(?(W(W%#z7CC+*3GJ'-4GM*.2.E.Efl.[.[GN+6  $U  $U  $U  V  V{{7F+++r  ordersc           
      ,   |                                   |                                 }|d         }g }g }t          dt          |                    D ]}||         }|                     |d          }	|                    |	           |                     |d          }
|                     |d          }|                     |d          }|                     |d          }|                     |di           }|                     |	|
|||||          }|                    |           |                     |d	d
dd          }| 	                    |d                   }d	}| 
                    d||          \  }}|dk    rt          | j        dz             ||d}|                     |                     ||                    }|                     |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
        :see: 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
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   r   r  r  r5  r  r  r  NFTrN   r  z+ createOrders does not allow inverse ordersrX  r  r  r  
retExtInfor  )r  r  rB  r  r  r\  r  r  r  r#  r/  r)   r2   privatePostV5OrderCreateBatchr  r  parse_orders)r  r  r  accountsisUtaordersRequestsorderSymbolsrG  rawOrderr"  r  r5  r  r  orderParamsr  r  r#  rX  r  r  r  r  retInfocodesr  retCodes                              r  create_orderszbybit.create_orders  s    	**,,q#f++&& 
	0 
	0AayH''(;;H)))##Hf55D##Hf55D__Xx88FOOHg66E//(HbAAK44XtT6SXZeglmmL!!,////%%lD%tLLWQZ((..~vvNN&y  tw)VVWWW %
 
 55dkk'66R6RSS8R88vvr22//(L"==44q#e**%% 	5 	5A8D''f55G!||++d1gt44QL   &&&r  c                 v   |                                   |                     |          }|dk    rt          | j        dz   |z   dz             |                                }||dk    rt          | j        dz             |d         |                     |          |                     |          d|                     ||          d}	|dk    }
|dk    }||                     ||          |	d	<   | 	                    |d
          }| 
                    |d          }|                     |
|dk    |          }|rd|	d
<   n#|dk    rd|	d
<   n|dk    rd|	d
<   n|dk    rd|	d
<   |d         rr|                     |dd          }|                     |d|          }|                     |d          }|                     |d          }|                     |d          }|d u}|d u}|d u}|d u}|p|}|r|d|	d<   d|	d<   |r|n|}|                     ||          }||	d<   |                     |d         d                   }|rt          j        ||          nt          j        ||          |	d<   np|s|rg|r1|                     |dd|          }|                     ||          |	d<   |r1|                     |dd|          }|                     ||          |	d<   nd |	d<   | 	                    |d!          }|||	d"<   n|d#         r|                                 |	d"<   |                     |g d$          }d }|d#         r*|                     |                     |	|                    }n)|                     |                     |	|                    }|                     |d%i           } |                     | |          S )&Nr#  z. createOrder does not allow market orders for r  r  r  r2   r  )r  r5  r?  r  r.  r1  time_in_forcer  r  r  r  r  r  r  rC   r  r  r  r  r  r  r  r  	LastPrice
trigger_byr  r  	basePricer   r  r  rE   )r  r  r  r  r  r  r  r  )r  r#  r)   r2   rJ  r"   r  r  r  r  r  is_post_onlyr  r  r  r.   
string_subrw  r  r  /privatePostOptionUsdcOpenapiPrivateV1PlaceOrderr  2privatePostPerpetualUsdcOpenapiPrivateV1PlaceOrderr  r  )!r  r  r  r5  r  r  r  r#  r  r  r  r  exchangeSpecificParamr  r  r  r  r  r  r  r  r	  r
  r  isStopOrderstopPxpreciseStopPricedeltar  r  r  r  rF  s!                                    r  r  zbybit.create_usdc_orderB  s   V$$8tw)YY\bbeooppp

M 8 8#DG.g$ghhhTlOOD))77+00@@
 
( !H,7*$($;$;FE$J$JGL! $ 0 0 I I,,V]CC$$X/D
/RTZ[[ 	;'1GO$$E!!'7GO$$E!!'3GO$$E!!':GO$&> 	1,,V[.QQL#'??6?L#Y#Y %)__V=N%O%O"vz::H>>J%9%E"'=T'I$!-J%T1L0L4LK 1)4&(3%1Gc--Mc#'#:#:66#J#J *:'--f[.A'.JKKVl  (^w'9:JE'R'R'Rry  sE  FV  X]  s^  s^$$ 1| 1 Z%)%6%6xQ\^f%g%gN*.*A*A&.*Y*YGJ' \%)%6%6z>S^`j%k%kN,0,C,CFN,[,[GL))0&((AA$%2GM""H 	3%)[[]]GM"6  $Q  $Q  $Q  R  R( 	mKKDKKX_agLhLhiiHHNNt{{[bdjOkOkllH4 x266v...r  c                    |                                   |                     |          }|d         |d}	||                     ||          |	d<   ||                     ||          |	d<   d }
|d         r+|                     |                     |	|                    }
n|                     |ddd          }|                     |d	d
          }|                     |d          }|d u}|                     |d          }|d u}|p|p|}|rZ|rdnd|	d<   ||                     ||          |	d
<   ||                     ||          |	d<   ||                     ||          |	d<   |                     |g d          }| 	                    |                     |	|                    }
| 
                    |
di           }|                     ||          S )Nr2   r  rE  r.  r1  rE   stoptriggerFr  r  r  r  r  r   r  r  r  )r7  r  r  r  r  r  )r  r#  r  r  1privatePostOptionUsdcOpenapiPrivateV1ReplaceOrderr  r  r  r  4privatePostPerpetualUsdcOpenapiPrivateV1ReplaceOrderr  r  )r  r2   r  r  r5  r  r  r  r#  r  r  isStopr  r  isStopLossOrderr  isTakeProfitOrderr1  r  s                      r  edit_usdc_orderzbybit.edit_usdc_order  s   V$$Tl
 
 "&":":66"J"JGJ$($;$;FE$J$JGL!( 	oMMdkkZaciNjNjkkHH&&vvy%HHF,,V[.QQL OOFODDM+47O"oof6GHHO /t ;)H->H&K ]8>)KG&+.2.E.Efl.[.[GN+ ,*.*A*A&-*X*XGJ'".,0,C,CFO,\,\GL)YYv'p'p'pqqFPPQUQ\Q\]dflQmQmnnH (B77///r  r2   c           	      z   |t          | j        dz             |                                  |                     |          }|                                 \  }	}
|	p|
}|d         dk    }|r|s|                     |||||||          S |d         |d}|d         rd|d<   n)|d	         rd	|d<   n|d
         rd
|d<   n|d         r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<   | 	                    |d          }|||d<   |                     |g d          }|                     |                     ||                    } | 
                    | di           }!|                     | | 	                    |!d          d          S )a3  
        edit a trade order
        :see: https://bybit-exchange.github.io/docs/v5/order/amend-order
        :see: https://bybit-exchange.github.io/docs/derivatives/unified/replace-order
        :see: 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 fullfilled, in units of the base currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: The price that a trigger order is triggered at
        :param float [params.stopLossPrice]: 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 argumentr  r  r2   r6  rA   rX  r  r  rE   r  r  r  r  r  r  r  r  rC  	triggerByr)  slTriggerBytpTriggerByr  r  )r  r  r  r  r  r  r  r  rE  )r  r2   )r"   r2   r  r#  r  r>  r  r  r  r  r  r  privatePostV5OrderAmendr  r  )"r  r2   r  r  r5  r  r  r  r#  r  r  r  r  r  r  r  r  r  r  r  r	  r
  r  triggerPriceRequestr@  r  stopLossRequestrA  r  takeProfitRequestrB  r  r  r  s"                                     r  
edit_orderzbybit.edit_order  sV   2 >#DG.W$WXXXV$$484K4K4M4M11/G3Gx(F2 	W!1 	W''FD$vVVVTl
 
 &> 	+"(GJH 	+"*GJI 	+"+GJH 	+"*GJ!55ffEEGEN#66vuEEGG!55ffEEGEN))&.+NN#//HH!%!1!1&:K!L!L??6:66__V\::
!5T!A#9#E T)
!-! 	f%= 	f3Ie//OeL#3?33F3F,,TMdMdekmyMzMz&9GN#((kJJI#,GK  	5 	5 5!%!3!3Hnk[c!d!d5Cs5J5J..QUQhQhioq  RA  RA&5
#"..v}kRR)4& 5!%!3!3JP[]g!h!h7E7L7LNNSWSjSjkq  tB  TC  TC!(9%"..v}kRR)4&((AA$%2GM"6  $P  $P  $P  Q  Q//GV0L0LMM 8R88""6955 
  
   	r  c                 .   |t          | j        dz             |                                  |                     |          }d|d         i}|                     |ddd          }|                     |ddg          }|||d<   d }|d         r*|                     |                     ||                    }n2|rd	nd
|d<   |                     |                     ||                    }| 	                    |di           }| 
                    ||          S )Nz- cancelUsdcOrder() requires a symbol argumentr  r2   r7  r8  FrE  rE   r  r   r  r  )r"   r2   r  r#  r  r  0privatePostOptionUsdcOpenapiPrivateV1CancelOrderr  3privatePostPerpetualUsdcOpenapiPrivateV1CancelOrderr  r  )	r  r2   r  r  r#  r  r;  r  r  s	            r  cancel_usdc_orderzbybit.cancel_usdc_orderR  s0   >#DG.]$]^^^V$$fTl

 ""669eDD6FI#677>!#GI( 	nLLT[[Y`bhMiMijjHH4:%G[[GM"OOPTP[P[\cekPlPlmmH (B77///r  c                    |t          | j        dz             |                                  |                     |          }|                                 \  }}|p|}|d         dk    }|r|s|                     |||          S d|d         i}	|d         r9|                     |dd	d
          }
|                     |dd	g          }|
rdnd|	d<   |||	d<   |d         rd|	d<   n)|d         rd|	d<   n|d         rd|	d<   n|d         rd|	d<   |                     | 	                    |	|                    }| 
                    |di           }|                     ||          S )a=  
        cancels an open order
        :see: 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.stop]: *spot only* whether the order is a stop order
        :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 argumentr  r  r  r2   rA   r7  r8  Fr  r   r  rE  rX  r  r  rE   r  )r"   r2   r  r#  r  rK  r  r  privatePostV5OrderCancelr  r  r  )r  r2   r  r  r#  r  r  r  r  r  r;  r  r  s                r  cancel_orderzbybit.cancel_orderv  s    >#DG.Y$YZZZV$$484K4K4M4M11/G3Gx(F2 	>!1 	>))"ff===fTl
 &> 	H&&vvy%HHFYYv	':;;F4:%G[[GM">!#GI&> 	+"(GJH 	+"*GJI 	+"+GJH 	+"*GJ00Wf1M1MNN (B77///r  c                    |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i           }|                     |dg           }|                     ||          S )a  
        cancel multiple orders
        :see: 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 argumentcancelOrdersr  z+ cancelOrders does not allow inverse ordersclientOrderIds
clientOidsr   r2   )r  r  r6  r  r  r  )r"   r2   r  r#  r/  r)   safe_list_2r  rB  r  r\  r  privatePostV5OrderCancelBatchr  r  r  r  )r  idsr  r  r#  rX  r  rQ  rG  r  r  r  rows                r  cancel_orderszbybit.cancel_orders  s    >#DG.Z$Z[[[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# #    
 !%
 
 55dkk'66R6RSSH (B77nnVVR00  f---r  c                 V   |t          | j        dz             |                                  |                     |          }d|d         i}d }|d         r*|                     |                     ||                    }nf|                     |ddd          }|rd|d	<   nd
|d	<   |                     |ddg          }|                     |                     ||                    }| 	                    |dg           }t          |t                    s|S |                     ||          S )Nz1 cancelAllUsdcOrders() requires a symbol argumentr  r2   rE   r7  r8  Fr  r  r   r  )r"   r2   r  r#  .privatePostOptionUsdcOpenapiPrivateV1CancelAllr  r  r  1privatePostPerpetualUsdcOpenapiPrivateV1CancelAllr  
isinstancer  r  )r  r  r  r#  r  r  r;  r  s           r  cancel_all_usdc_orderszbybit.cancel_all_usdc_orders  sA   >#DG.a$abbbV$$fTl
 ( 		lJJ4;;W^`fKgKghhHH&&vvy%HHF 1)4&&)0&YYv	':;;FMMdkkZaciNjNjkkH$ 8R88&$'' 	O  000r  c                    |                                   |                                 \  }}|p|}d}i }|F|                     |          }|d         dk    }|r|s|                     ||          S |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g           }|                     |d          }t          |t                    s|S |                     ||          S )a"  
        cancel all open orders
        :see: 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.stop]: True if stop order
        :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>`
        Nr  r  r2   r  rG   rX  rE   z. cancelAllOrders() Normal Account not support z marketr  r  rY  r  r  r  r7  r8  Fr  r  r  r  )r  r  r#  r\  r/  r)   r2   r  r  r  r  privatePostV5OrderCancelAllr  r  r[  r  r  )r  r  r  r  r  r  r#  r  r  r  rY  r  r;  r  r  r  s                   r  cancel_all_orderszbybit.cancel_all_orders$  s#    	484K4K4M4M11/G3G[[((F"8,6M C%5 C2266BBB &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}(](]%""669eDD6FI#677 	1%0GM"33DKK4P4PQQ: 8R8800&$'' 	O  000r  c                 *   |                                   d }i }| |                     |          }|d         |d<   d }|                     d||          \  }}|dk    rd|d<   nd|d<   |                     |dd	d
          }|                     |dd	g          }|rd|d<   |||d<   |                     |                     ||                    }	|                     |	di           }
|                     |
dg           }| 	                    ||||          S )Nr2   r  r   rC   	PERPETUALrX  r  r7  r8  Fr  r  r  r  r  )
r  r#  r,  r  r  6privatePostOptionUsdcOpenapiPrivateV1QueryOrderHistoryr  r  r  r  )r  r  r  r  r  r#  r  r  r;  r  r  r  s               r  fetch_usdc_orderszbybit.fetch_usdc_ordersm  sE   
 [[((F &tGH99-QWXXf6>>"-GJ"*GJ""669eDD6FI#677 	1%0GM"$GGNNt{{[bdjOkOkll` 8R88~~fj"55  vue<<<r  c           	      <   |t          | j        dz             |                                  |                     |          }|d         rt	          | j        dz             d|i}|                     |dd|                     ||                    }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*
        :see: https://bybit-exchange.github.io/docs/v5/order/order-list
        :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 argumentrA   z/ fetchOrder() is not supported for spot marketsrE  r   r8  r7  F bIf 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)r"   r2   r  r#  r)   fetch_ordersr  r  safe_bool_nr(   strr'   r  )
r  r2   r  r  r#  r  r  length	isTriggerextras
             r  fetch_order_classiczbybit.fetch_order_classic  s6    >#DG.X$XYYYV$$&> 	\tw)ZZ[[[r
 ""64t{{7F7S7STTVQ;;(()V1DeLLI#  NBB  *NE3r77 25F F NOOOA::tw)HHIIIvq)))r  c                     |                                  }|                     |d          }|rt          | j        dz             |                     |||          S )a  
         *classic accounts only/ spot not supported*  fetches information on an order made by the user *classic accounts only*
        :see: https://bybit-exchange.github.io/docs/v5/order/order-list
        :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>`
        r   zt fetchOrder() is not supported after the 5/02 update for UTA accounts, please use fetchOpenOrder or fetchClosedOrder)r  	safe_boolr)   r2   rp  )r  r2   r  r  resr  s         r  fetch_orderzbybit.fetch_order  so     %%''#~~c155 	atw  *`   `  a  a  a''FF;;;r  c                     |                                  }	 |                     |d          }|rt          | j        dz             |                     ||||          S )Nr   z fetchOrders() is not supported after the 5/02 update for UTA accounts, please use fetchOpenOrders, fetchClosedOrders or fetchCanceledOrders)r  rr  r)   r2   fetch_orders_classic)r  r  r  r  r  rs  r  s          r  rj  zbybit.fetch_orders  sv    %%''	  $~~c155 	ytw  *x   x  y  y  y((vFFFr  c                    |                                   d}|                     |dd          \  }}|r|                     d||||dddd	  	        S |                                 \  }}|p|}i }	d}
d}|,|                     |          }
|
d         d	k    }|
d
         |	d<   d}|                     d|
|          \  }}|dk    s|r|s|                     ||||          S |dk    rt          | j        dz             ||	d<   | 	                    |ddgd          }| 
                    |ddg          }|rd|	d<   |||	d<   |||	d<   |                     |dd          }|                     |d|          }| 
                    |g d          }|||	d<   |                     |                     |	|                    }|                     |          }|                     ||
||          S )a  
        fetches information on multiple orders made by the user *classic accounts only*
        :see: 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.stop]: True if stop order
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :param str [params.orderFilter]: 'Order' or 'StopOrder' or 'tpslOrder'
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Fr   r  r  r  Nr   r  r  r2   r  rE   rA   z0 fetchOrders() is not supported for spot marketsrX  r8  r7  r  r  r  r  r  r  r  r  )r  r  fetch_paginated_call_cursorr  r#  r/  rc  r)   r2   rk  r  r  r  privateGetV5OrderHistoryr  r  r  r  r  r  r  r  r  r  r  r  r  r#  r  r  r;  r  r  r  r  s                     r  rv  zbybit.fetch_orders_classic  sk     	88PZ[[& 	G33M65RWY_aqs{  ~B  DF  G  G  G484K4K4M4M11/G3G[[((F"8,6M &tGH**=&&IIfX-9I))&%GGG6>>tw)[[\\\"
!!&9f*=uEE6Iv#677 	1%0GM"$GG#(GK ##FGV<<##FIu==6#?#?#?@@!(GI00Wf1M1MNNf 33H==  vue<<<r  c           	         |                                   d|i}|                     |dd|                     ||                    }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
        :see: 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.stop]: set to True for fetching a closed stop order
        :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>`
        rE  Nr   r8  r7  Fre  rf  rg  rh  r   ri  )
r  fetch_closed_ordersr  r  rk  r(   rl  r'   r2   r  	r  r2   r  r  r  r  rm  rn  ro  s	            r  fetch_closed_orderzbybit.fetch_closed_orderf  s     	r
 ))&$dkk'SY>Z>Z[[VQ;;(()V1DeLLI#  NBB  *NE3r77 25F F NOOOA::tw)HHIIIvq)))r  c           	         |                                   d|i}|                     |dd|                     ||                    }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
        :see: 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.stop]: set to True for fetching an open stop order
        :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>`
        rE  Nr   r8  r7  Fre  rf  rg  rh  r   ri  )
r  fetch_open_ordersr  r  rk  r(   rl  r'   r2   r  r}  s	            r  fetch_open_orderzbybit.fetch_open_order  s     	r
 ''dDKKQW<X<XYYVQ;;(()V1DeLLI#  NBB  *NE3r77 25F F NOOOA::tw)HHIIIvq)))r  c                    |                                   d}|                     |dd          \  }}|r|                     d||||dddd	  	        S |                                 \  }}|p|}i }	d}
d}|,|                     |          }
|
d         d	k    }|
d
         |	d<   d}|                     d|
|          \  }}|dk    s|r|s|                     ||||          S ||	d<   |                     |ddgd          }|                     |ddg          }|rd|	d<   |||	d<   |||	d<   | 	                    |dd          }| 
                    |d|          }|                     |g d          }|||	d<   |                     |                     |	|                    }|                     |          }|                     ||
||          S )a  
        fetches information on multiple canceled and closed orders made by the user
        :see: 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.stop]: set to True for fetching stop orders
        :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>`
        Fr^   r  r  r  Nr   r  r  r2   r  rE   rX  r8  r7  r  r  r  r  r  r  r  r  )r  r  rx  r  r#  r/  rc  rk  r  r  r  ry  r  r  r  rz  s                     r   fetch_canceled_and_closed_ordersz&bybit.fetch_canceled_and_closed_orders  sZ     	88A_akll& 	X334RTZ\achjp  sC  EM  OS  UW  X  X  X484K4K4M4M11/G3G[[((F"8,6M &tGH**+I6SYZZfX-9I))&%GGG"
!!&9f*=uEE6Iv#677 	1%0GM"$GG#(GK ##FGV<<##FIu==6#?#?#?@@!(GI00Wf1M1MNNf 33H==  vue<<<r  c           	          |                                   ddi}|                     ||||                     ||                    S )a  
        fetches information on multiple closed orders made by the user
        :see: 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.stop]: set to True for fetching closed stop orders
        :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>`
        r  r  r  r  r  r  r  r  r  r  r  s         r  r|  zbybit.fetch_closed_orders  sN      	8
 44VUE4;;W^`fKgKghhhr  c           	          |                                   ddi}|                     ||||                     ||                    S )a  
        fetches information on multiple canceled orders made by the user
        :see: 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.stop]: True if stop order
        :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>`
        r  r  r  r  s         r  fetch_canceled_orderszbybit.fetch_canceled_orders  sN      	;
 44VUE4;;W^`fKgKghhhr  c                    |                                   i }d }| |                     |          }|d         |d<   d }|                     d||          \  }}|dk    rdnd|d<   |                     |                     ||                    }|                     |di           }	|                     |	d	g           }
|                     |
|||          S )
Nr2   r  fetchUsdcOpenOrdersrC   	perpetualrE   rX  r  r  )r  r#  r,  6privatePostOptionUsdcOpenapiPrivateV1QueryActiveOrdersr  r  r  )r  r  r  r  r  r  r#  r  r  r  r  s              r  fetch_usdc_open_orderszbybit.fetch_usdc_open_orders0  s    [[((F &tGH99:OQWY_``f.2fnnkk8
NNt{{[bdjOkOkll8R88R886   >>>r  c                 >   |                                   |                                 \  }}|p|}i }d}	d}
|,|                     |          }	|	d         dk    }
|	d         |d<   d}|                     d|	|          \  }}|dk    s|d	k    rX|                     |d
          }|@|>|                     | j        dd          }|                     |d|          }||d<   |dk    }
|dk    s|
r|s|                     ||||          S ||d<   |                     |ddd          }|                     |ddg          }|rd|d<   |||d<   | 	                    | 
                    ||                    }|                     |          }|                     ||	||          S )a  
        fetch all unfilled currently open orders
        :see: 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.stop]: set to True for fetching open stop orders
        :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 Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        NFr  r  r2   r  r   r  r  rY  r  r  r  rE   rX  r7  r8  r  r  r  )r  r  r#  r/  r  r  r  r  r  privateGetV5OrderRealtimer  r  r  )r  r  r  r  r  r  r  r  r  r#  r  r  rY  r  r  r;  r  r  s                     r  r  zbybit.fetch_open_ordersY  s     	484K4K4M4M11/G3G[[((F"8,6M &tGH**+<ffMMf8ty00''
;;H~("2 $ 0 0PV W W!--flMRR
(2%!+v!5X-9I..vueVLLL"
""669eDD6FI#677 	1%0GM"$GG11$++gv2N2NOOd 33H==  vue<<<r  c           	          i }|                      |dd          }|||d<   n||d<   |                     |ddg          }|                     ||||                     ||                    S )a   
        fetch all the trades made from a single order
        :see: https://bybit-exchange.github.io/docs/v5/position/execution
        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        r  r  NrE  )r  r  fetch_my_tradesr  )r  r2   r  r  r  r  r  r  s           r  fetch_order_tradeszbybit.fetch_order_trades  s}     **6?MRR$%2GM""!#GI6O]#CDD##FE5$++gv:V:VWWWr  c                 ~   |                                   d }i }|0|                     |          }|d         |d<   |d         rdnd|d<   nd|d<   |                     |                     ||                    }|                     |di           }|                     |dg           }	|                     |	|||          S )	Nr2   r  rE   r  ra  rX  r  r  )r  r#  2privatePostOptionUsdcOpenapiPrivateV1ExecutionListr  r  r  rW  )
r  r  r  r  r  r#  r  r  r  r  s
             r  fetch_my_usdc_tradeszbybit.fetch_my_usdc_trades  s    [[((F &tGH.4X.>"O((KGJ"-GJJJ4;;W^`fKgKghh: 8R88>>&*b99  65%@@@r  c                    |                                   d}|                     |dd          \  }}|r|                     d||||dddd	  	        S |                                 \  }}|p|}dd	i}	d}
d}|,|                     |          }
|
d
         dk    }|
d         |	d<   d}|                     d|
|          \  }}|dk    s|r|s|                     ||||          S ||	d<   |||	d<   |||	d<   |                     d|	|          \  }	}|                     | 	                    |	|                    }| 
                    |          }|                     ||
||          S )a  
        fetch all trades made by the user
        :see: https://bybit-exchange.github.io/docs/api-explorer/v5/position/execution
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Fr~   r  r  r  Nd   execTyper   r  r  r2   r  rE   rX  r  r  r  )r  r  rx  r  r#  r/  r  r  privateGetV5ExecutionListr  r  rW  )r  r  r  r  r  r  r  r  r  r  r#  r  r  r  rX  s                  r  r  zbybit.fetch_my_trades  s    	88R\]]& 	J33OVUTY[acsu}  @D  FI  J  J  J484K4K4M4M11/G3G
 [[((F"8,6M &tGH**?FFKKfX-9I,,VUE6JJJ"
$GG#(GK 229gvNN11$++gv2N2NOOR 55h??  >>>r  rH  c                     |                      |d          }|                      |d          }|                      |d          }|                      |d          }|                     |           |||||dS )NaddressDeposit
tagDepositr  r7  )rH  addresstagr>  r  )r  check_address)r  depositAddressrH  r  r  r  r7  s          r  parse_deposit_addresszbybit.parse_deposit_addressL  s     "">3CDD~|<<&11  997###"
 
 	
r  r  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     |dg           }|                     |d          }|                     |          }|                     ||d         gdd|d         i          }	|                     |	d          S )	a  
        fetch a dictionary of addresses for a currency, indexed by network
        :see: 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
        r5  r2   r  r6  r  FrH  r>  )r  rH  $privateGetV5AssetDepositQueryAddressr  r  r  parse_deposit_addressesindex_by)
r  r  r  rH  r  r  r  r6  r5  parseds
             r  "fetch_deposit_addresses_by_networkz(bybit.fetch_deposit_addresses_by_networkb  s     	==&&HTN
 <<T[[RX=Y=YZZ( 8R88266//==&&--fx7G6H%(R
   }}VY///r  c                 2   |                                   |                     |          \  }}|                     |          }|                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |di           }	|                     |	dg           }
|                     |
d          }|                     |||          }| 	                    ||i           }| 
                    ||          S )a  
        fetch the deposit address for a currency associated with self account
        :see: 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>`
        r5  r2   N	chainTyper  r6  r7  )r  handle_network_code_and_paramsnetwork_code_to_idrH  r  r  r  r  #select_network_id_from_raw_networksr  r  )r  r  r  rP  queryrO  rH  r  r  r  r6  chainsIndexedByIdselectedNetworkIdaddressObjects                 r  fetch_deposit_addresszbybit.fetch_deposit_address  s    	!@@HHU++K88	==&&HTN
  #,GK <<T[[RW=X=XYY( 8R88266 MM&':: DDT;Xijj'8:KRPP))-BBBr  c                    |                                   d}|                     |dd          \  }}|r|                     d||||dddd	  	        S i }d}| |                     |          }|d         |d	<   |||d
<   |||d<   |                     d||          \  }}|                     |                     ||                    }|                     |          }	|                     |	|||          S )a  
        fetch all deposits made to an account
        :see: 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>`
        Fri   r  r  r  Nr   r2   r5  r  r  r  )	r  r  rx  rH  r  #privateGetV5AssetDepositQueryRecordr  r  parse_transactions
r  r  r  r  r  r  r  rH  r  r  s
             r  fetch_depositszbybit.fetch_deposits  s:    	88R\]]& 	G33OT5RWY_aqs{  ~B  DF  G  G  G

 }}T**H&tnGFO#(GK $GG229gvNN;;DKKQW<X<XYY8 33H==&&tXueDDDr  c                    |                                   d}|                     |dd          \  }}|r|                     d||||dddd	  	        S i }d}| |                     |          }|d         |d	<   |||d
<   |||d<   |                     d||          \  }}|                     |                     ||                    }|                     |          }	|                     |	|||          S )a_  
        fetch all withdrawals made from an account
        :see: https://bybit-exchange.github.io/docs/v5/asset/withdraw-record
        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Fr   r  r  r  Nr   r2   r5  r  r  r  )	r  r  rx  rH  r  $privateGetV5AssetWithdrawQueryRecordr  r  r  r  s
             r  fetch_withdrawalszbybit.fetch_withdrawals  s=    	88ASU_``& 	J334FeUZ\bdtv~  AE  GI  J  J  J

 }}T**H&tnGFO#(GK $GG229gvNN<<T[[RX=Y=YZZT 33H==&&tXueDDDr  c                 N    ddddddddddddd	}|                      |||          S )
Nr@  pending
processingokfailr  r  failed)rC  r   2r   4SecurityCheckPendingsuccessCancelByUserRejectFailBlockchainConfirmedr  r  s      r  parse_transaction_statuszbybit.parse_transaction_statusD  sN     & & #'
 
  &&999r  c                    |                      |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 ) Nr5  
createTime	successAt
updateTimero  
depositFeer;  r  
withdrawalr  	toAddressr  r2   
withdrawIdtxidtxIDr   r  r>  r7  r  	addressToaddressFromr  tagTotagFromr  r  rH  updated)r?  internalcomment)
r  rC  r  r  r  r  r  r  rD  r  )r  transactionrH  rI  r  r   r  ro  feeCostr  r?  r  s               r  parse_transactionzbybit.parse_transactionW  s4   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/UVV
 t
 
 4
 4##K77
 T
 t
 D
 d&&{H==
 
  f!
" w#
$ )
 
 
 	
r  c                    |                                   i }|                                 }d}d}|d         r
d}|||d<   n||                     |          |d<   | |                     |          }|d         ||<   |||d<   d}	|d         r*|                     |                     ||                    }	n)|                     |                     ||                    }	|                     |	          }
|                     |
|||          S )	ac  
        fetch the history of changes, actions done by the user or operations that altered balance of the user
        :see: https://bybit-exchange.github.io/docs/v5/account/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 entrys to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger-structure>`
        Nr5  r   rH  r  
start_dater2   r  )	r  r  yyyymmddrH  !privateGetV5AccountTransactionLogr  $privateGetV2PrivateWalletFundRecordsr  parse_ledger)r  r  r  r  r  r  enableUnifiedrH  currencyKeyr  r  s              r  fetch_ledgerzbybit.fetch_ledger  s7    	
& //11 	=$K ',$ (,e(<(<%}}T**H#+D>GK $GG 	_==dkk'SY>Z>Z[[HH@@WV\A]A]^^HP 33H==  x>>>r  c                    |                      |dd          }|                     ||          }|                      |dd          }|                      |dd          }t          j        |d          rdnd	}d }|3|1|dk    r|nt          j        |          }	t          j        ||	          }|                     |                     |d
                    }
|
|                     |d          }
| 	                    |                     |d                    }|                     |d          }|                     |d          }|||                     |d          d |d | 
                    t          j        |                    | 
                    |          | 
                    |          | 
                    |                     |d                    ||
|                     |
          ||dS )Nr5  rH  r  r  wallet_balancecashBalancerC  outin	exec_timetransactionTimer  r2   tx_id	wallet_idr?  )r2   rH  rv  referenceAccountreferenceIdro  r  beforeafterr?  	directionr   r  r  r  )r  rC  r.   	string_lt
string_negrw  r  r  r  parse_ledger_entry_typer  
string_absr  )r  itemrH  rI  r  r  r  r  r  
differencer   r  r2   r  s                 r  parse_ledger_entryzbybit.parse_ledger_entryA  s   J ''fjAA
&&z8<<##D(H==""4)9=II$.vs;;EEE	!3$-$6$6W=OPV=W=WJ'z::FNN4#3#3D+#F#FGG	))$0ABBI++D,<,<T6,J,JKKdD))&&tW55''k:: $&''(:6(B(BCC''//&&u--$$T%5%5dE%B%BCC""Y//
 
 	
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}|                      |||          S )NDepositr  WithdrawRealisedPNLrM  
Commissionr?  RefundcashbackPrizeprizeExchangeOrderWithdrawExchangeOrderDepositTRANSFER_INTRANSFER_OUTTRADE
SETTLEMENTDELIVERYLIQUIDATIONBONUS
FEE_REFUNDINTEREST)CURRENCY_BUYCURRENCY_SELLr  )r  r  r  s      r  r  zbybit.parse_ledger_entry_type  s   
}

 7
 %	

 j
 W
 $]
 #M
 =
 M
 W
 '
 
 7
  W!
" *#
$ %
& $$)
 
 
, tT222r  c                 Z   |                      ||          \  }}|                                  |                     |           |                     |          }|d         |                     |          ||                                 d}|||d<   |                     |          \  }}	|                     |          }
|
|
                                |d<   | 	                    | 
                    ||	                    }|                     |di           }|                     ||          S )a  
        make a withdrawal
        :see: https://bybit-exchange.github.io/docs/v5/asset/withdraw
        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r2   )r5  r  r  r   Nr  r7  r  )handle_withdraw_tag_and_paramsr  r  rH  r  r  r  r  upper privatePostV5AssetWithdrawCreater  r  r  )r  r  r  r  r  r  rH  r  rP  r  rO  r  r  s                r  r   zbybit.withdraw  s-    99#vFFV7###==&&TN++F33**,,	
 
 ? GEN!@@HHU++K88	 (00GG88We9T9TUU (B77%%fh777r  c                 $   |t          | j        dz             |                                  |                     |          }d|d         i}|                                 \  }}|p|}|d         dk    }d}	d}
|                     d||          \  }
}|
dk    s|r9|s7|
dk    rd	nd
|d<   |                     |                     ||                    }	n.|
|d<   |                     |                     ||                    }	| 	                    |	di           }| 
                    |ddg           }|                     |	d          }| 	                    |di           }|                     ||          }||d<   |                     |          |d<   |S )a  
        fetch data on a single open contract trade position
        :see: 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  r2   r  r  r   rE   r  ra  rX  r  r  r  r1  r   r   r  )r"   r2   r  r#  r  r/  2privatePostOptionUsdcOpenapiPrivateV1QueryPositionr  privateGetV5PositionListr  rS  r  parse_positionr  )r  r  r  r#  r  r  r  r  r  r  r  r  	positionsr   r  positions                   r  fetch_positionzbybit.fetch_position  s    >#DG.[$[\\\V$$fTl
 594K4K4M4M11/G3Gx(F2**?FFKKfH7G/3x/?/?((kGJNNt{{[bdjOkOkllHH"&GJ44T[[&5Q5QRRHR (B77$$VVZDD	%%h77	y!R00&&uf55 )#||I66r  c                 x   |                                   i }d }t          |t                    rct          |          }|dk    rt	          | j        dz             |                     |d          }|                     |          }|d         |d<   n"| |                     |          }|d         |d<   d }|                     d||          \  }}|dk    rdnd	|d
<   | 	                    | 
                    ||                    }|                     |di           }	|                     |	dg           }
g }t          dt          |
                    D ]Q}|
|         }d|v rd|v r|                     |d          }|                    |                     ||                     R|                     |d|d          S )Nr   z< fetchUsdcPositions() takes an array with exactly one symbolr   r2   r  fetchUsdcPositionsrE   r  ra  rX  r  r  r  is_validF)r  r[  r  r  r"   r2   r  r#  r/  r  r  r  rB  r\  r  filter_by_array_positions)r  r  r  r  r#  rm  r  r  r  r  r  resultsrG  rawPositions                 r  fetch_usdc_positionszbybit.fetch_usdc_positions  s   gt$$ 		-\\F{{'2p(pqqq%%gq11F[[((F &tGH [[))F &tGH**+?PPf+/8+;+;hh+
JJ4;;W^`fKgKghhT 8R88OOFJ;;	q#i..)) 	E 	EA#A,K+%%J+,E,E"ook6BBNN4..{FCCDDDD--gx%PPPr  c                    d}|et          |t                    rPt          |          }|dk    rt          | j        dz             |dk    r|d         }|                     |          }n||}|                     |          g}|                                  |                                 \  }}|p|}i }d}	d}
|4| 	                    |          }	|	d         }|	d         |d<   |	d         d	k    }
d}| 
                    d
|	|          \  }}|dk    s|dk    rh|                     |d          }|dk    rC|@|>|                     | j        dd          }|                     |d|          }||d<   |d	k    }
n	||d|d<   |dk    s|
r|s|                     ||          S |                     |dg          }||d<   |                     |                     ||                    }|                     |          }g }t%          dt          |                    D ]P}||         }d|v rd|v r|                     |d          }|                    |                     |                     Q|                     |d|d          S )a  
        fetch all open positions
        :see: 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
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Nr   zD fetchPositions() does not accept an array with more than one symbolr   Fr  r2   r  r  r   r  r  rY  r  r  r  rX  rE   r  r  r  )r[  r  r  r"   r2   r  r  r  r  r#  r/  r  r  r#  r  r  r  r  rB  r  r\  r  r   )r  r  r  r  r  r  r  r  r  r#  r  r  rY  r  r  r  r  r!  rG  r"  s                       r  fetch_positionszbybit.fetch_positions\  s    Z%>%>LLMq  '2x(xyyy!## ))'22GG F{{6**+G484K4K4M4M11/G3G[[((FH%F &tGH"8,6M**+;VVLLf8ty00''
;;Hx>h&6$($4$4T\?TZ$[$[M!%!1!1&,!V!VJ,6GL)%/6%9M >h&6*3GJ'X-9I,,Wf===6F8,,"
00Wf1M1MNNH 88BB	q#i..)) 	= 	=A#A,K+%%J+,E,E"ook6BBNN4..{;;<<<<--gx%PPPr  c                 
   |                      |d          }|                     ||d d          }t          j        |                      |d                    }|                      |d          }||dk    rd}n|dk    rd}nd }|                      |d	          }|                     |                      |d
                    }|                      |d          }|                      |d          }	|                     |                      |d                    }
|
|                     |ddg          }
|                     |dd          }d }| j        d         r| j        d         r|d         r
|dk    rdnd}|                      |d          }|                     | 	                    |dd                    }|                     |                      |d                    }|                      |d          }||d         dk    rdt          j        t          j
        ||                    }t          j        t          j        t          j        ||          |	          |          }n|                      |d          }|d         rgt          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&|                     |          d'|                     t          j        ||                    d(|                     |	          d)|                     |          d|                     |          d*|                     |          d|                     |          d+|                     |          d,|                     |          d-|                     |d-          d.|                     |          |                     |          |                     |d/          d |                     |          ||d |                     |d0d1          |                     |d2d3          d4	          S )5Nr  r  r/  r5  BuylongSellshortpositionValueunrealisedPnl
positionIM
positionMM
updated_atr  r  	tradeModer   r  r  r   isolatedcrosspositionBalance
entryPricer  liqPricer{  r  r  	bustPricer  rZ  r  r2   r   r  r  initialMargininitialMarginPercentagemaintenanceMarginmaintenanceMarginPercentagenotionalunrealizedPnl	contractsr  marginRatior  	stop_lossr  take_profitr  )	liquidationPricer  r  
collateralr  r5  r  r  r  )r  r)  r.   r  r  r  rI  r  r  r  r-  rw  r  
string_divsafe_positionr  r  r  r  )r  r  r#  r  r/  r5  r;  r,  initialMarginStringmaintenanceMarginStringr   r0  r  collateralStringr4  rA  r{  r  r6   maintenanceMarginPriceDifferencemultiplyr:  r>  s                          r  r  zbybit.parse_position  s   d ##Hh77!!(FD*EE!$"2"28V"D"DEE&11u}}##Ho>>t'7'7/'R'RSS"..xFF"&"2"28\"J"JNN4#3#3Hl#K#KLL	++H}k6RSSI%%hQ??	
34 	E$,G]:^ 	Ecijsct 	E(1QWJ++H6GHH^^D$6$6xz$Z$Z[[
>>$*:*:8Z*P*PQQ##Hj99'h6))$/0B:O_0`0`aa
#*#5g6HI[\fhlImIm  pG  7H  7H  JW  $X  $X   ,,X{CC	(# q
 8?7I'J\]moxJyJy7z7z4.5.@Aacg.h.h+!-.5.@ASTXZdAeAego.p.p+ ")!3G4FyRb4c4c!d!dJ&1)=MNNH.5.@ASTXZdAeAego.p.p+!-.5.@wGYZdfnGoGo.p.p+&-&89PRZ&[&[#()@BRTUVV!! #
H#
$#
 fX&#
 	#

 Y//#
 "4#
 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00#
  D,,V^DD!#
" 4,,[99##
$ !% 1 12B C C))(K@@++,<==$!//+zRR#11(M<XX5#
 #
 #
   	r  c                     |                                   |                     |          }|                     ||          }|                     ||          S )aZ  
        fetch the set leverage for a market
        :see: https://bybit-exchange.github.io/docs/v5/position
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `leverage structure <https://docs.ccxt.com/#/?id=leverage-structure>`
        )r  r#  r  parse_leverage)r  r  r  r#  r  s        r  fetch_leveragezbybit.fetch_leverage  sR     	V$$&&vv66""8V444r  c                     |                      |d          }|                     |d          }||                     ||          |                     |d          ||dS )Nr  r{  r  )r  r  r  longLeverageshortLeverage)r  r  r  r  )r  r{  r#  r"  leverageValues        r  rK  zbybit.parse_leverage  sj    ##Hh77))(J??&&x8800<HH)*
 
 	
r  r  c                    |                                   |                                 \  }}|p|}d}d}|ra|dk    rd}n)|dk    rd}n |dk    rd}nt          | j        dz             d	|i}	|                     |                     |	|                    }n|t          | j        d
z             |                     |          }|d         dk    }
|
rX|dk    rd}n |dk    rd}nt          | j        dz             d	|i}	|                     |                     |	|                    }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}	|                     |                     |	|                    }|S )a  
        set margin mode(account) or trade mode(symbol)
        :see: https://bybit-exchange.github.io/docs/v5/account/set-margin-mode
        :see: 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
        Nr1  ISOLATED_MARGINr2  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]r{  sell_leveragesellLeveragebuy_leveragebuyLeveragez[ setMarginMode() requires a leverage parameter or sell_leverage and buy_leverage parameters)rX  rV  rW  rY  r2   )rX  r  r0  rY  rW  )r  r  r)   r2   !privatePostV5AccountSetMarginModer  r"   r#  r/  r  r  r  #privatePostV5PositionSwitchIsolated)r  r  r  r  r  r  r  r#  r  r  r  r  r0  rW  rY  r{  s                   r  set_margin_modezbybit.set_margin_mode  s    	484K4K4M4M11/G3G ?	bZ''.

w&&-

{**/

"47-v#vwwwG ==dkk'SY>Z>Z[[HH~'2x(xyyy[[((F"8,6M -b((!1JJ;..!3JJ&tw  2A  (A  B  B  B#Z  AA$++gW]B^B^__#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   CCDKKPWY_D`D`aar  r{  c                 P   |t          | j        dz             |                                  |                     |          }|                                 \  }}|p|}|d         dk    }|                     |          }|d         ||d}	d}
|r1|s/||	d<   |                     |                     |	|                    }
nf||	d<   ||	d	<   |d
         rd
|	d<   n%|d         rd|	d<   nt          | j        dz             | 	                    |                     |	|                    }
|
S )a  
        set the level of leverage for a market
        :see: 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 argumentr  r  r2   )r  rY  rW  r{  rY  rW  r  rX  r  z5 setLeverage() only support linear and inverse market)
r"   r2   r  r#  r  r  <privatePostPerpetualUsdcOpenapiPrivateV1PositionLeverageSaver  r)    privatePostV5PositionSetLeverage)r  r{  r  r  r#  r  r  r  r  r  r  s              r  set_leveragezbybit.set_leverage  sw    >#DG.Y$YZZZV$$ 594K4K4M4M11/G3Gx(F2 ((22Tl#$
 

  	[!1 	["*GJXXY]YdYdelntYuYuvvHH%-GM"&.GN#h f&.
##	" f&/
##"47-d#deee<<T[[RX=Y=YZZHr  hedgedc                    |                                   d}||                     |          }d}|rd}nd}d|i}|d|d<   n|d         |d<   ||d	         rd	nd
|d<   n!d}|                     d||          \  }}||d<   |                     |d          }|                     |                     ||                    }|S )as  
        set hedged to True or False for a market
        :see: 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  r5  r2   r  r  r  rX  r   r  )r  r#  r/  r  privatePostV5PositionSwitchModer  )	r  ra  r  r  r#  rc  r  r  r  s	            r  set_position_modezbybit.set_position_mode  s     	[[((F 	DDDD
 >$GFOO &tGH.4X.>"M((IGJD../@&&QQLD&"&GJ66**77GV8T8TUU r  r   c                    |                                   |                     |          }|d         rdnd}|                     |d|          }|                     | j        d          }	|                     |	|          }
|
t          | j        dz   |z   dz             |d         |
|d}|||d	<   |                     |d
d          }|                     |dd
g          }|||d<   |||d<   | 	                    | 
                    ||                    }|                     |di           }|                     |          }|                     |d          }|                     ||d d          }|                     ||||          S )Nr  r  rX  r  z+ fetchOpenInterestHistory() cannot use the 
 timeframer2   r  intervalTimerX  r  r  r  r  r  r  r  r  )r  r#  r  r  r  r#   r2   r  r  publicGetV5MarketOpenInterestr  r  r)  parse_open_interests)r  r  r  r  r  r  r#  r.  rX  r  r  r  r  r  r  r  r2   s                    r  'fetch_derivatives_open_interest_historyz-bybit.fetch_derivatives_open_interest_historyH  s   V$$$X.=((I##FJ@@OODL+>>	##Iy99TW'TTW``coopppTl$ 
 

 #(GK ##FGV<<6FG#455!&GI$GG55dkk'66R6RSS0 8R8833H==fh//!!"fdJ??((vueDDDr  c                    |                                   |                     |          }|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i           }|                     |d          }| 	                    ||dd          }| 
                    |
          }|                     |d         |          S )a  
        Retrieves the open interest of a derivative trading pair
        :see: https://bybit-exchange.github.io/docs/v5/market/open-interest
        :param str symbol: Unified CCXT market symbol
        :param dict [params]: exchange specific parameters
        :param str [params.interval]: 5m, 15m, 30m, 1h, 4h, 1d
        :param str [params.category]: "linear" or "inverse"
        :returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
        r  z3 fetchOpenInterest() supports contract markets onlyr  r   r  Nz$ fetchOpenInterest() cannot use the rg  r  r  rX  r2   rh  r  r  r   )r  r#  r#   r2   r  r  r  rj  r  r)  r  parse_open_interest)r  r  r  r#  r  r  r  r.  rX  r  r  r  r2   r  s                 r  fetch_open_interestzbybit.fetch_open_interest|  s    	V$$j! 	^TW'\\]]]$$VZ>>	OODL+>>	##Iy99TW'MMPYY\hhiii$X.=((I##FJ@@Tl$ 
 

 55dkk'66R6RSS0 8R88fh//!!"fdJ??33H==''Q888r  c           	         |dk    rt          | j        dz             |                                  |                     |d          }|r1|                     |d          }|                     d|||||d          S |                     |          }|d         s|d         rt          | j        dz   |z             d	|d
         i}|||d<   |                     |||||          S )a.  
        Gets the total amount of unsettled contracts. In other words, the total number of contracts held in open positions
        :see: 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   z4fetchOpenInterestHistory cannot use the 1m timeframer  r   i  rA   rE   z; fetchOpenInterestHistory() symbol does not support market r  r2   Nr  )r#   r2   r  rr  r  r  r#  rl  )	r  r  r  r  r  r  r  r#  r  s	            r  fetch_open_interest_historyz!bybit.fetch_open_interest_history  s!    TW']]^^^>>&*55 	EYYvz22F::;UW]_dfkmvx~  AD  E  E  EV$$&> 	oVH- 	oTW'ddgmmnnnfTl
 $GG;;FIuV[]cdddr  c           	          |                      |d          }|                     |dd          }|                     |d         d |||                     |          |d|          S )Nr   open_interestopenInterestr  )r  openInterestAmountr  r   r  r  )r  r  safe_open_interestr  )r  ro  r#  r   values        r  rn  zbybit.parse_open_interest  sz     %%h<<	""8_nMM&&X&"&!&"Y//(
 (
   	r  c                 J   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d          }|                     |di           }||d<   |                     ||          S )a  
        fetch the rate of interest to borrow a currency for margin trading
        :see: 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>`
        r5  r2   r1  r  r   )r  rH  (privateGetV5SpotCrossMarginTradeLoanInfor  r  r  parse_borrow_rate)r  r  r  rH  r  r  r   r  s           r  fetch_cross_borrow_ratezbybit.fetch_cross_borrow_rate  s     	==&&HTN
 @@WV\A]A]^^ %%h77	x266%[%%dH555r  c                     |                      |d          }|                     |d          }|                     ||          |                     |d          d||                     |          |dS )Nr   r5  r  i \&)rH  rD  periodr   r  r  )r  r  rC  r  r  )r  r  rH  r   rI  s        r  rz  zbybit.parse_borrow_rate  s{     %%dK88	%%dF33
//
HEE$$T>::"Y//
 
 	
r  c                 8   |                                   i }|                     |                     ||                    }|                     |di           }|                     |dg           }	|                     |	d          }
|                     |
|||          S )a  
        fetch the interest owed by the user for borrowing currency for margin trading
        :see: 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>`
        r  rc  N)r  r  r  r  parse_borrow_interestsfilter_by_currency_since_limit)r  r  r  r  r  r  r  r  r  r  ro  s              r  fetch_borrow_interestzbybit.fetch_borrow_interest  s     	??GU[@\@\]]4 x266t%6;;..tT::228T5%PPPr  c           
          d d|                      |                     |d                    |                     |d          d |                     |d          d d |d	S )Nr2  rt  ro  rn  )	r  r  rH  ro  r  amountBorrowedr   r  r  )rC  r  r  )r  r  r#  s      r  parse_borrow_interestzbybit.parse_borrow_interestE  sl     !//0@0@y0Q0QRR((z:: "..tV<<

 

 
	
r  fromAccount	toAccountc           
      6   |                                   |                     |d|                                           }|                     | j        di           }|                     |||          }|                     |||          }	|                     |          }
|                     ||          }|||	|
d         |d}|                     |                     ||                    }| 	                    |d          }|                     |di           }| 
                    |ddg          }|                     |          }|                     |                     ||
          ||                     |          |                     |          |||d	          S )
ax  
        transfer currency internally between wallets on the same account
        :see: https://bybit-exchange.github.io/docs/v5/asset/create-inter-transfer
        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.transferId]: UUID, which is unique across the platform
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        
transferIdr  r2   )r  fromAccountTypetoAccountTyper5  r  r1  r  r%  retMsg)r   r  r  r  r  ro  )r  r  uuidr  r  rH  currency_to_precision'privatePostV5AssetTransferInterTransferr  r  rH  parse_transfer_statusparse_transferr  r  )r  r  r  r  r  r  r  r  fromIdtoIdrH  amountToPrecisionr  r  r   r   	statusRawro  s                     r  r   zbybit.transfer\  s    	%%flDIIKKHH
t|5ErJJ!!,[IIiCC==&& 66tVDD$%!TN'
 
 ??GU[@\@\]] %%h77	??8Xr::&&x)X1FGG	++I66{{4..xBB"Y//''(9::&"E
 E
   	r  c                    |                                   d}|                     |dd          \  }}|r|                     d||||dddd	  	        S d}i }||                     |          }||d<   |||d	<   |||d
<   |                     d||          \  }}|                     |                     ||                    }|                     |          }	|                     |	|||          S )a  
        fetch a history of internal transfers made on an account
        :see: https://bybit-exchange.github.io/docs/v5/asset/inter-transfer-list
        :param str code: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for
        :param int [limit]: the maximum number of transfer structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
        Fr   r  r  r  Nr   r5  r  r  r  )	r  r  rx  rC  r  /privateGetV5AssetTransferQueryInterTransferListr  r  parse_transfers)
r  r  r  r  r  r  rH  r  r  r  s
             r  fetch_transferszbybit.fetch_transfers  s7    	88AQS]^^& 	H334DdESXZ`brt|  C  EG  H  H  H..t44H&GFO#(GK $GG229gvNNGGT[]cHdHdee. 33H==##D(E5AAAr  c                 p   |                                   |                     |          }|d         |                     ||          d}|                     |                     ||                    }|                     |di           }|                     ||          }|                     |d|d          S )a  
        create a loan to borrow margin
        :see: https://bybit-exchange.github.io/docs/v5/spot-margin-normal/borrow
        :param str code: unified currency code of the currency to borrow
        :param float amount: the amount to borrow
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        r2   r5  r  r  Nr  r  )r  rH  r  %privatePostV5SpotCrossMarginTradeLoanr  r  parse_margin_loan	r  r  r  r  rH  r  r  r  r  s	            r  borrow_cross_marginzbybit.borrow_cross_margin  s     	==&&TN--dF;;
 
 ==dkk'SY>Z>Z[[ 8R88,,VX>>{{;)
 )
   	r  c                 n   |                                   |                     |          }|d         |                     |          d}|                     |                     ||                    }|                     |di           }|                     ||          }|                     |d|d          S )a  
        repay borrowed margin and interest
        :see: https://bybit-exchange.github.io/docs/v5/spot-margin-normal/repay
        :param str code: unified currency code of the currency to repay
        :param float amount: the amount to repay
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        r2   r  r  Nr  )r  rH  r  &privatePostV5SpotCrossMarginTradeRepayr  r  r  r  s	            r  repay_cross_marginzbybit.repay_cross_margin  s     	==&&TN((00
 
 >>t{{7TZ?[?[\\ 8R88,,VX>>{{;)
 )
   	r  c                 h    |                      |dd          |                     |d          d d d d |dS )N
transactIdrepayIdr  )r2   rH  r  r  r   r  r  )r  r  )r  r  rH  s      r  r  zbybit.parse_margin_loan  sJ     $$T<CC((6::
 
 	
r  c                 <    dddd}|                      |||          S )Nr  )rC  OKSUCCESSr  r  s      r  r  zbybit.parse_transfer_status   s1    
 

 &&999r  c                 J   |                      |d          }|                     |d          }|                      |d          }|                      |d          }|                     | j        di           }|                      |||          }|                      |||          }	||                      |d          ||                     |          |                     ||          |                     |d          ||	|                     |                      |d                    d		S )
Nr5  r   r  r  r  r  r  ro  )	r  r2   r   r  rH  r  r  r  ro  )r  r  r  r  r  rC  r  r  )
r  r   rH  rI  r   fromAccountIdtoAccountId
accountIdsr  r  s
             r  r  zbybit.parse_transfer(  s"   ( %%h77
%%h<<	((3DEE&&xAA__T\>2FF
&&z=-PP$$ZkJJ	""8\::"Y////
HEE&&x::&"001A1A(H1U1UVV

 

 
	
r  c                 t   |                                   |                     |          }d|d         i}|d         rd|d<   n|d         rd|d<   |                     |                     ||                    }|                     |d          }|                     |d          }|                     ||          S )Nr  r2   r  rX  r  r  r  )r  r#  publicGetV5MarketRiskLimitr  r  parse_market_leverage_tiers)r  r  r  r#  r  r  r  tierss           r  'fetch_derivatives_market_leverage_tiersz-bybit.fetch_derivatives_market_leverage_tiersO  s    V$$fTl
 ( 	,"*GJI 	,"+GJ224;;w3O3OPP0 844////v>>>r  c                     |                                   i }d}|                     |          }|d         s|d         rt          | j        dz   |z             |d         |d<   |                     ||          S )a  
        retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes for a single market
        :see: 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>`
        NrA   rE   z; fetchMarketLeverageTiers() symbol does not support market r2   r  )r  r#  r#   r2   r  )r  r  r  r  r#  s        r  fetch_market_leverage_tiersz!bybit.fetch_market_leverage_tiersu  s     	V$$&> 	oVH- 	oTW'ddgmmnnn"4L;;FFKKKr  c                     |                      |d          }||d         nd}|                     ||d |          }|||                     |d          |                     |d          d d dS )Nr  r  r  makerFeeRatetakerFeeRate)r  r  r  r  r  r  r  r  r  )r  r?  r#  r"  r  r  s         r  parse_trading_feezbybit.parse_trading_fee  s     ##C22)/);fVnn*!!(FD+FF%%c>::%%c>::
 
 	
r  c                    |                                   |                     |          }d|d         i}d}|d         rd}n|d         rd}n|d         rd}nd}||d<   |                     |                     ||                    }|                     |d	i           }|                     |d
g           }|                     |di           }	|                     |	|          S )aX  
        fetch the trading fees for a market
        :see: https://bybit-exchange.github.io/docs/v5/account/fee-rate
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        r  r2   Nr  r  rA   rE   rX  r  r  r   )r  r#  privateGetV5AccountFeeRater  r  r  )
r  r  r  r#  r  rX  r  r  r   r  s
             r  fetch_trading_feezbybit.fetch_trading_fee  s     	V$$fTl
 ( 	 HHI 	  HHF^ 	 HHH&
224;;w3O3OPP$ 8R88vvr22a,,%%eV444r  c                    |                                   d}|                     |ddd          \  }}|dk    rt          | j        dz             |                     |          }|                     |di           }|                     |dg           }i }t          d	t          |                    D ]*}|                     ||                   }|d
         }|||<   +|S )a  
        fetch the trading fees for multiple markets
        :see: 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  rD   rA   z4 fetchTradingFees() is not supported for spot marketr  r  r   r  )	r  r  r)   r2   r  r  rB  r  r  )	r  r  r  r  r   r  rG  r?  r  s	            r  fetch_trading_feeszbybit.fetch_trading_fees  s     	44V=OQWYabbf6>>tw)__```226::$ x266tVR00q#d))$$ 	! 	!A((a11C]F F6NNr  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 )Nr6  )r?  r  )r  r   r  r  r   r7  r  r;  F)r  r   r  r   r   r?  r  )r  r  rB  r  rD  r  )r  r?  rH  r6  chainsLengthr  rG  r7  rO  currencyCoderP  s              r  parse_deposit_withdraw_feez bybit.parse_deposit_withdraw_fee  sF   * h33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r  r$  c                    |                                   |                                  |                     |          }|                     |di           }|                     |dg           }|                     ||d          S )af  
        fetch deposit and withdraw fees
        :see: 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>`
        r  r  r5  )r@  r  rA  r  r  parse_deposit_withdraw_fees)r  r$  r  r  r  r  s         r  fetch_deposit_withdraw_feesz!bybit.fetch_deposit_withdraw_fees"  s     	'')))66v>>> x266~~dFB////eVDDDr  c                 B   |                                   i }d}| |                     |          }|d         |d<   d}|                     d||          \  }}|dk    rt          | j        dz             ||d<   |||d<   |                     |                     ||                    }|                     |d	i           }	|                     |	d
g           }
|                     |
|          }| 	                    |d          }| 
                    ||d         ||          S )a5  
        fetches historical settlement records
        :see: 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]
        Nr2   r  r   rA   z: fetchSettlementHistory() is not supported for spot marketrX  r  r  r  r   )r  r#  r/  r)   r2   publicGetV5MarketDeliveryPricer  r  parse_settlementsr!  r"  r  r  r  r  r  r  r#  r  r  r  r  settlementsr'  s                r  fetch_settlement_historyzbybit.fetch_settlement_historyO  s4    	[[((F &tGH**+CVVTTf6>>tw)eefff"
$GG66t{{7F7S7STT( 8R88vvr22,,T6::k;77009I5RWXXXr  c                 N   |                                   i }d}| |                     |          }|d         |d<   d}|                     d||          \  }}|dk    s|dk    rt          | j        dz             d|d	<   |||d
<   |                     |                     ||                    }|                     |di           }	|                     |	dg           }
|                     |
|          }| 	                    |d          }| 
                    ||d         ||          S )a:  
        fetches historical settlement records of the user
        :see: 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]
        Nr2   r  r}   rA   r  z< fetchMySettlementHistory() is not supported for spot marketr  rX  r  r  r  r   )r  r#  r/  r)   r2   privateGetV5AssetDeliveryRecordr  r  r  r!  r"  r  s                r  fetch_my_settlement_historyz!bybit.fetch_my_settlement_history  s>    	[[((F &tGH**+EvvVVf6>>TY..tw)gghhh&
$GG77GV8T8TUU2 8R88vvr22,,T6::k;77009I5RWXXXr  c                     |                      |d          }|                     |d          }||                     ||          |                     |d          ||                     |          dS )Nr  r  deliveryPrice)r  r  r  r   r  )r  r  r  r  r  )r  
settlementr#  r   r"  s        r  parse_settlementzbybit.parse_settlement  sx    . %%j.AA	##J99&&x88%%j/BB"Y//
 
 	
r  c                     g }t          dt          |                    D ]1}|                    |                     ||         |                     2|S )Nr   )rB  r  r\  r  )r  r  r#  r  rG  s        r  r  zbybit.parse_settlements  sZ    6 q#k**++ 	I 	IAMM$//AGGHHHHr  c                    |                                   |                     |          }d|d         d}|                     |                     ||                    }|                     |dg           }|                     |          S )a  
        fetch the historical volatility of an option market based on an underlying asset
        :see: 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>`
        rE   r2   rX  rY  r  )r  rH  %publicGetV5MarketHistoricalVolatilityr  r  parse_volatility_history)r  r  r  rH  r  r  
volatilitys          r  fetch_volatility_historyzbybit.fetch_volatility_history  s     	==&&  
 
 ==dkk'SY>Z>Z[[ __Xx<<
,,Z888r  c           
         g }t          dt          |                    D ]a}||         }|                     |d          }|                    |||                     |          |                     |d          d           b|S )Nr   r1  rw  )r  r   r  r  )rB  r  r  r\  r  r  )r  r  r  rG  r&  r   s         r  r  zbybit.parse_volatility_history  s     q#j//** 	 	AqME))%88IMM"& LL33"..ug>>	      r  c                    |                                   |                     |          }|d         dd}|                     |                     ||                    }|                     |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
        :see: 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>`
        r2   rE   )r  rX  r1  r  r  r   )r   r  )r  r#  r  r  r  r  parse_greeksr  )
r  r  r  r#  r  r  r   r  r  greekss
             r  fetch_greekszbybit.fetch_greeks0  s     	V$$Tl 
 
 00Wf1M1MNNR %%h77	8R88vvr22""47F33{{6"Y//$
 $
   	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  r4  gammathetavegarhor  r  r  r  bidImpliedVolatilitybid1IvaskImpliedVolatilityask1IvmarkImpliedVolatilitymarkIvbidPricer  askPricer  r  r  underlyingPrice)r  r  r  )r  r  r#  r"  r  s        r  r  zbybit.parse_greeksp  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'
 
 
 	
r  c                 .   |                                   d}|                     |dd          \  }}|r|                     d||||dddd	  	        S dd	i}d}| |                     |          }|d
         |d<   d}|                     d||          \  }}||d<   |||d<   |||d<   |                     d||          \  }}|                     |                     ||                    }	|                     |	          }
| 	                    |
|||          S )a  
        retrieves the users liquidated positions
        :see: https://bybit-exchange.github.io/docs/api-explorer/v5/position/execution
        :param str [symbol]: unified CCXT market symbol
        :param int [since]: the earliest time in ms to fetch liquidations for
        :param int [limit]: the maximum number of liquidation structures to retrieve
        :param dict [params]: exchange specific parameters for the exchange API endpoint
        :param str [params.type]: market type, ['swap', 'option', 'spot']
        :param str [params.subType]: market subType, ['linear', 'inverse']
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict: an array of `liquidation structures <https://docs.ccxt.com/#/?id=liquidation-structure>`
        Fr|   r  r  r  Nr  r  	BustTrader2   r  rX  r  r  r  )
r  r  rx  r#  r/  r  r  r  r  parse_liquidations)r  r  r  r  r  r  r  r#  r  r  liquidationss              r  fetch_my_liquidationszbybit.fetch_my_liquidations  sr    	88AVXbcc& 	P334I6SXZ_agiy  |D  FJ  LO  P  P  P
 [[((F &tGH**+@&&QQf"
$GG#(GK 229gvNN11$++gv2N2NOOR ;;HEE&&|VUEJJJr  c                 |   |                      |d          }|                     |d          }|                      |d          }|                      |d          }|                      |d          }t          j        ||          }t          j        ||          }	|                     ||                     ||          |                     |          |                     |          |                     |          |                     |          |                     |	          ||                     |          d	          S )Nr  r3  r-  r  r0  )	r  r  r=  r  r  	baseValue
quoteValuer   r  )r  r  r.   r  safe_liquidationr  r  r  )
r  liquidationr#  r"  r   contractsStringcontractSizeStringrO  baseValueStringquoteValueStrings
             r  parse_liquidationzbybit.parse_liquidation  s5   : ##K::%%k:>>	**;	BB!--fnEE&&{K@@!,_>PQQ"-o{KK$$&&x88**?;; --.@AA&&{33**?;;++,<=="Y//
&
 
&
 
 
 
	r  c                    |                                   d}|:|                     |d                   }|d         rt          | j        dz             d}|                     d||d          \  }}d|i}|                     |                     ||                    }|                     |di           }|                     |d	g           }| 	                    |          }| 
                    ||d
          S )a-  
        :see: https://bybit-exchange.github.io/docs/v5/market/risk-limit
        retrieve information on the maximum leverage, for different trade sizes
        :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'
        :returns dict: a dictionary of `leverage tiers structures <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`, indexed by market symbols
        Nr   rA   z6 fetchLeverageTiers() is not supported for spot marketr   r  rX  r  r  r  )r  r#  r)   r2   r-  r  r  r  r  r  parse_leverage_tiers)	r  r  r  r#  r.  r  r  r  r  s	            r  fetch_leverage_tierszbybit.fetch_leverage_tiers#  s    	[[,,Ff~ g"47-e#efff99.&RXZbcc
 224;;w3O3OPP(B77~~ffb11%%g..((wAAAr  c                    i }|                      |          }|                     |||d          }|                     ||          }t          |                                          }t          dt          |                    D ]K}	||	         }
||
         }|                     |
d d d          }|d         }|                     ||          ||<   L|S )NFr   r  r  )	
market_idsr  group_byr  keysrB  r  r)  r  )r  r  r  marketIdKeyr  	marketIdsfilteredResultsgroupedr  rG  r"  r&  r#  r  s                 r  r  zbybit.parse_leverage_tiers=  s     OOG,,	..xiQVWW--==GLLNN##q#d))$$ 	L 	LAAwHH%E%%hdJGGFH%F <<UFKKE&MMr  c                 
   g }t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                     d          }|dk    r|                     ||dz
           d          }|                    |                     |d          |d         ||                     |d          |                     |d          |                     |d	          |d
           |S )Nr   r  rC  r   riskLimitValuer2   r  r9  r  )tierrH  minNotionalmaxNotionalmaintenanceMarginRater  r  )rB  r  r  r)  r  r  r\  r  )r  r  r#  r  rG  r  r"  r	  s           r  r  z!bybit.parse_market_leverage_tiersX  s    q#d))$$ 	 	A7D''h77H%%h//F++C00KAvv"..tAE{<LMMLL))$55"8,*#//6FGG)-)9)9$@S)T)T#//mDD      r  c                 T   |                                   d}|                     |dd          \  }}|r|                     d||||dddd	  	        S dd	i}d}| |                     |          }|d
         |d<   d}|                     d||          \  }}||d<   ||d
         |d<   |||d<   |||d<   nd|d<   |                     d||          \  }}|                     |                     ||                    }	|                     |	          }
| 	                    |
|||          S )aB  
        fetch the history of funding payments paid and received on self account
        :see: 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>`
        Frm   r  r  r  Nr  r  Fundingr2   r  rX  r  r/  r  )
r  r  rx  r#  r/  r  r  r  r  parse_incomes)r  r  r  r  r  r  r  r#  r  r  fundingss              r  fetch_funding_historyzbybit.fetch_funding_historyy  s    	88AVXbcc& 	P334I6SXZ_agiy  |D  FJ  LO  P  P  P	
 [[((F &tGH**+@&&QQf"
 &tGH#(GK #GFOO!GFO229gvNN11$++gv2N2NOO77AA!!(FE5AAAr  c                    |                      |d          }|                     ||d d          }d}|d         r|d         }|                     |d          }||                     ||dd          |||                     |          |                      |d	          |                     |d
          |                     |d          dS )Nr  r  r  r  r  r3  r  rC   r*  r-  rB  )r  r  r  r   r  r2   r  rD  )r  r)  r  r  r  r  )r  incomer#  r"  r  r   s         r  parse_incomezbybit.parse_income  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	
 	
 		
r  c                 t   |                                   |                     |          }d|d         d}|                     |                     ||                    }|                     |di           }|                     |dg           }|                     |di           }|                     |d|          S )a  
        fetches option data that is commonly found in an option chain
        :see: 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>`
        rE   r2   )rX  r  r  r  r   N)r  r#  r  r  r  r  parse_option)	r  r  r  r#  r  r  r  r%  r7  s	            r  fetch_optionzbybit.fetch_option  s     	V$$ Tl
 
 00Wf1M1MNNR (B77^^FFB77
z1b11  f555r  c                 F   |                                   |                     |          }d|d         d}|                     |                     ||                    }|                     |di           }|                     |dg           }|                     |dd          S )a  
        fetches data for an underlying asset that is commonly found in an option chain
        :see: https://bybit-exchange.github.io/docs/v5/market/tickers
        :param str currency: 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>`
        rE   r2   r  r  r  Nr  )r  rH  r  r  r  r  parse_option_chain)r  r  r  rH  r  r  r  r%  s           r  fetch_option_chainzbybit.fetch_option_chain  s     	==&&  
 
 00Wf1M1MNNR (B77^^FFB77
&&z4BBBr  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  rH  r   r  impliedVolatilityr  rt  r  r  r  r  midPricer  r  r  r  	change24hr  r  totalVolumer  )r  r)  r  )r  r7  rH  r#  r"  s        r  r  zbybit.parse_optionK  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#
 	
r  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|r]d| 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<   nm|                     || j        | j        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|                     |          z   z  }|d|z   z  }|dk    r"|                     | j        d          }|||d<   ||||d S )!Nr   r  r   ?r   openapir   z
unified/v3zcontract/v3r8   z{}hexzapplication/json)Content-TypeX-BAPI-API-KEYX-BAPI-TIMESTAMPX-BAPI-SIGNr  )r$  r%  r&  zX-BAPI-RECV-WINDOWr  zX-BAPI-SIGN-TYPEPOSTzPRIVATE KEYr  sha256r'  )api_keyrecv_windowr   rA   signr$  z!application/x-www-form-urlencodedz&sign=r  Referer)urlr  bodyheaders)implode_hostnamer   	rawencoder@  r  rl  r  jsonapiKeyhmacencodesecrethashlibr)  r  r  rsakeysort	urlencoder  )r  pathr   r  r  r0  r/  r.  	isOpenapiisV3UnifiedMarginisV3ContractisV5UnifiedAccountr   payload	signaturer  queryEncoded	auth_baseauthFullsortedQueryauthr  extendedQueryr  s                           r  r,  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!6!666C 	;##M22R77 $4; I III $		$++h*?*?T[AYAY[b[i j jI)2&&F#{#'<#=!*- -  
 #ll511~~k22 	;##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!<!<<<C8i//CV''jAAH#%-	"fdwOOOr  c
                 v   |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   }|                     | j        d
         ||           |                     | j        d         |
|           t          |          d S )Nret_coder%  rC  30084r   rF  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"  r  r  )r  r  r2   throw_broadly_matched_exceptionr   throw_exactly_matched_exceptionr   )r  httpCodereasonr.  r  r0  r/  r  requestHeadersrequestBody	errorCodefeedbacks               r  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/001I4QYZZZ001I9V^___)))tr  )NNNNr  )NN)__name__
__module____qualname__r  boolr  r  r  r  r  r  rl  r!  r   r   r   r)  r/  r3  r   rV  r   rl  r]  r^  r_  r   r  r  r   r   r  r  r  r	   r  r  r  r(  r   rT  rY  r   ra  r   r|  r  r  r  r   r  floatr  r  r   r   r   r  r  r   r&  r  r>  rG  rK  rN  rW  r\  r_  rc  rp  rt  rj  rv  r~  r  r  r|  r  r  r  r  r  r  r   r  r  r  r   r  r  r  r  r  r  r  r   r  r#  r%  r  r
   rL  rK  r\  r`  re  rl  ro  rq  rn  r{  rz  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,  rU  __classcell__)r  s   @r  r0   r0      s       V V V V Vp -t - - - - - -3$ 3 3 3 3$D D D	 	 	 )+ <[ <[ <[ <[| 46 = = = ==
3 =
 =
 =
 =
~W WC W WRU Wjm W  zI W W W W W W 57 ! ! ! ! !# 3 3 3 3, ') { {Z { { { {z $& $A $A$v, $A $A $A $ALi i iVa a aF~ ~ ~@s s6 sV s s s sj 02 D4 D43 D4f D4 D4 D4 D4L 04B ]= ]=W ]=7 ]= ]= ]= ]=~
 
 
4 
 
 
 
, 26DW[df cJ cJ# cJc cJQT cJkoptku cJ cJ cJ cJJ3
 3
 3
 3
 3
 3
j 6:" HE HE7 HE HE HE HET 8<$]ajl QO QO QOC QOWZ QO QO QO QOfg g g5 g g g gR 6:UW 5? 5?3 5?s 5?# 5?\`af\g 5? 5? 5? 5?n :>b <J <Js <J3 <JY <J <J <J <J|U) U) U) U) U)n $& M, M,( M, M, M, M,^: : :8H H HL L L5 L L L L\ RT K K K5 K K K K SU L L LE L L L L& gksu </ </3 </i </y </RW </`c </ </ </ </| os{}  FJ y, y,3 y,i y,y y,Z_ y,hk y, y, y, y,v @B Q' Q'D$6 Q' Q' Q' Q'f lpxz m/ m/ m/9 m/I m/W\ m/eh m/ m/ m/ m/^ >BVX .0 .0 .0 .0` `drv  @B o oS o# oY oi oY\ olo o o o ob 37r "0 "0C "0 "0 "0 "0H 37r 80 80s 80C 80 80 80 80t 04B I. I. I. I. I. I.V 48 '1 '1S '1 '1 '1 '1R /32 G1 G1 G1 G1 G1 G1R /3TXac P= P= P=3 P=c P= P= P= P=d :>b * *c *3 * * * *6 26b < <c <3 <U < < < < *.Dt\^ G G3 Gc G Gcghmcn G G G G, 26DW[df f= f=3 f=c f=QT f=kopukv f= f= f= f=P 9=R * *S *# * * * *6 7;2 * *3 * * * * *: >BPTcgpr d= d=s d=# d=]` d=w{  }B  xC d= d= d= d=L 154VZce i i# iS iPS ijnotju i i i i, 37TX\eg i iC is iRU i i i i, 48dY]fh '? '?S '? '?SV '? '? '? '?R /3TXac _= _= _=3 _=c _=hlmrhs _= _= _= _=B 9=4^bkm X XS X# XS XX[ X X X X( 26DW[df )A )A3 )Ac )AQT )A )A )A )AV -1tRV_a Q? Q?c Q? Q?C Q? Q? Q? Q?f
 
h 
 
 
 
, DF (0 (0s (0 (0 (0 (0T 79 *C *C# *C *C *C *CX *.Dt\^ >E >E3 >Ec >E >Ecghsct >E >E >E >E@ -1tRV_a JE JEc JE JEC JEfjkvfw JE JE JE JEX: : :&L
 L
x L
; L
 L
 L
 L
\ (,$TZ\ Z? Z? Z?C Z?s Z? Z? Z? Z?xD
 D
 D
 D
 D
 D
L3 3 32 ?C2 (8 (8S (8% (8 (8 (8 (8T 24 J JS J J J JX 7;2 DQ DQG DQ DQ DQ DQL 26b `Q `Qw `Q `Q `Q `QDF Fv F F F FP 24 5 5S 5 5 5 5 5	
 	
x 	
 	
 	
 	
 >B" P P# Ps P P P Pd 9=R * *S *# * * * *X =A * * *c * * * *X NR`dsw  AC 2E 2Ec 2EZ] 2Emp 2E 2E 2E 2Eh 79 69 69# 69 69 69 69p BFTXgktv e e# ec ead e e e e: F    $ 9; 6 6C 6 6 6 6B
 
 
 
 
 
* 15DW[jnwy *Q *Q# *Qc *QQT *Qdg *Q *Q *Q *QX
 
& 
 
 
 
. [] 1 1S 1% 1c 1c 1an 1 1 1 1f +/TPT]_ 3B 3BC 3Bs 3B# 3B 3B 3B 3Bj DF      U        D <>    s        D
 
 
 
 
 
0: : :%
 %
 %
 %
 %
 %
N KM $? $?c $? $? $? $?L ?A L L# L L L L"
 
V 
?R 
 
 
 
( 57 ,5 ,5 ,5;N ,5 ,5 ,5 ,5\ )+ & &{ & & & &P0 0 0 0 0 0d <@ +E +E +E +E +E +EZ 6:[_hj 1Y 1Ys 1Y# 1YUX 1Y 1Y 1Y 1Yf 9=4^bkm 6Y 6Y# 6YS 6YX[ 6Y 6Y 6Y 6Yp
 
 
B  @ :< 9 9S 9 9 9 9B  ( 02 > >3 >f > > > >@4
 4
6 4
 4
 4
 4
l 37TX\eg KK KKC KKs KKRU KK KK KK KKZ. .V . . . .` 7;2 B BG B B B B4 g    6     B 37TX\eg %B %BC %Bs %BRU %B %B %B %BN2
 2
6 2
 2
 2
 2
h 02 :6 :63 :6f :6 :6 :6 :6x 46 9C 9Cs 9C+ 9C 9C 9C 9Cv2
 2
H 2
V 2
 2
 2
 2
h &eBSW WP WP WP WPr& & & & & & &r  r0   )5ccxt.base.exchanger   ccxt.abstract.bybitr   r8  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   typingr   ccxt.base.errorsr   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   ccxt.base.decimal_to_precisionr-   ccxt.base.preciser.   r0    r  r  <module>rd     s   ( ' ' ' ' ' + + + + + +  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . ' ' ' ' ' ' % % % % % % 1 1 1 1 1 1 . . . . . . ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) . . . . . . ) ) ) ) ) ) + + + + + + 4 4 4 4 4 4 % % % % % %a{ a{ a{ a{ a{Hk a{ a{ a{ a{ a{r  