
    ei*~                    `   d dl mZ d dlm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 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l.m/Z/  G d dee          Z0dS )    )Exchange)ImplicitAPI)AnyBalancesBool
CurrenciesCurrencyDepositAddressIntMarket
MarketTypeNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateTradeTransaction)List)ExchangeError)AuthenticationError)ArgumentsRequired)
BadRequest)	BadSymbol)OperationRejected)InsufficientFunds)InvalidOrder)OperationFailed)NetworkError)RateLimitExceeded)ExchangeNotAvailable)RequestTimeout)	TICK_SIZE)Precisec                   z    e Zd Zdef fdZi fdefdZi fdee         fdZ	de
defdZd Zdi fd	edefd
Zi fdedefdZdQde
dedefdZdi fdededefdZdddi fdedededee         fdZdQdedefdZi fdedefdZdQdedefdZi fdefdZdQdefdZdddi fdededefdZ ddi fdedededee!         fdZ"dddi fdededefdZ#dQde
dede!fdZ$i fdZ%i fdefdZ&i fde'fd Z(de'fd!Z)dddi fd"edededee*         fd#Z+dddi fd"edededee*         fd$Z,di fd"ed%e-d&ed'ede*f
d(Z.dQd)e/de*fd*Z0d+efd,Z1i fd"ede2fd-Z3dQd)e/de2fd.Z4di fded/e5d0e6d%e-d1e7de8fd2Z9i fd3ee:         fd4Z;di fded/e5d0e6d%e-d1e7f
d5Z<d6 Z=dddi fdededefd7Z>di fd8edefd9Z?di fd8edefd:Z@di fdefd;ZAdddi fdedededee8         fd<ZBdQd=e
dede8fd>ZCd+efd?ZDd0efd@ZEdi fd	edeeF         fdAZGdQdBe
defdCZHdddi fdededefdDZIdQdefdEZJdF ZKdGdHi ddfdIZLdJ ZMd"eNdKedLedMedNe
dOefdPZO xZPS )Rbackpackreturnc                 0
   |                      t          t          |                                           i ddddddgddd	d
dddddi dd ddddddddddddddddddddddddddddddd di d!dd"dd#dd$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1di d2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBdi dCddDddEddFddGddHddIddJddKddLddMddNddOddPddQddRddSdi dTddUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcddddi deddfddgddhddiddjddkddlddmddnddoddpddqddrddsddtddudvdwdxdydzd{d|d}d~ddddddddddddddddddi dddddddddddddddddddddddddddddddddddddii ddddddddddddddddddddddddddddddddddddddddddddddddddddd
dddddiddddddd dddd ddddddddddddddddddddiddd d ddd ddddddddd d ddddd ddddÜ	ddid d dƜd d dƜdǜddddɜdt          di ddddΜdddidddidddidddidddidddidddidddidddidddidddidddidddidddidddidddddddddddiddiddiddiddiddiddiddiddtdd
ddd dddi ddddddddddd dddddd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d0d1d2d3d4dd5d6	d7i d8i d9t
          d:t          d;t
          d<t
          d=t
          d>t          d?t          d@t          dAt          dBt
          dCt          dDt
          dEt
          dFt
          dGt
          dHt          dIt
          i dJt          dKt
          dLt
          dMt
          dNt          dOt          dPt          dQt          dRt          dSt          dTt          dUt          dVt          dWt           dXt          dYt          i dZ          S ([  Nidr-   nameBackpack	countriesJP	rateLimit2   versionv1	certifiedFproThasCORSspotmarginswapfutureoption	addMargincancelAllOrderscancelAllOrdersAftercancelOrdercancelOrderscancelWithdrawclosePositioncreateConvertTradecreateDepositAddresscreateLimitBuyOrdercreateLimitOrdercreateLimitSellOrdercreateMarketBuyOrdercreateMarketBuyOrderWithCostcreateMarketOrdercreateMarketOrderWithCostcreateMarketSellOrdercreateMarketSellOrderWithCostcreateOrdercreateOrders$createOrderWithTakeProfitAndStopLosscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLossOrdercreateTakeProfitOrdercreateTrailingAmountOrdercreateTrailingPercentOrdercreateTriggerOrderfetchAccountsfetchAllGreeksfetchBalancefetchCanceledAndClosedOrdersfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchConvertCurrenciesfetchConvertQuotefetchConvertTradefetchConvertTradeHistoryfetchCurrenciesfetchDepositAddressfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchLedgerfetchLeveragefetchLeverageTiersfetchMarginAdjustmentHistoryfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsfetchTransfersfetchVolatilityHistoryfetchWithdrawalsreduceMarginsandboxsetLeverage	setMarginsetMarginModesetPositionModetransferwithdraw
timeframes1m3m5m15m30m1h2h4h6h8h12h1d3d1w1month)r   r   r   1530r   r   r   r   r   r   r   r   r   1MurlszOhttps://github.com/user-attachments/assets/cc04c278-679f-4554-9f72-930dd632b80fzhttps://api.backpack.exchange)publicprivatezhttps://backpack.exchange/zhttps://docs.backpack.exchange/z#https://backpack.exchange/join/ccxt)logoapiwwwdocreferralr   getzapi/v1/assets   zapi/v1/collateralzapi/v1/borrowLend/marketsz!api/v1/borrowLend/markets/historyzapi/v1/marketszapi/v1/marketzapi/v1/tickerzapi/v1/tickerszapi/v1/depthzapi/v1/klineszapi/v1/markPriceszapi/v1/openInterestzapi/v1/fundingRateszapi/v1/statuszapi/v1/pingzapi/v1/timezapi/v1/wallets)zapi/v1/tradeszapi/v1/trades/historyzapi/v1/accountzapi/v1/account/limits/borrowzapi/v1/account/limits/orderz api/v1/account/limits/withdrawalzapi/v1/borrowLend/positionszapi/v1/capitalzapi/v1/capital/collateralzwapi/v1/capital/depositszwapi/v1/capital/deposit/addresswapi/v1/capital/withdrawalsapi/v1/positionzwapi/v1/history/borrowLendzwapi/v1/history/interestz$wapi/v1/history/borrowLend/positionszwapi/v1/history/dustzwapi/v1/history/fillszwapi/v1/history/funding)wapi/v1/history/orderswapi/v1/history/rfqwapi/v1/history/quotewapi/v1/history/settlementwapi/v1/history/strategiesapi/v1/orderapi/v1/orders)
zapi/v1/account/convertDustapi/v1/borrowLendr   r   r   z
api/v1/rfqzapi/v1/rfq/acceptzapi/v1/rfq/refreshzapi/v1/rfq/cancelapi/v1/rfq/quote)r   r   )r   postdeletepatchfeatures)GTCIOCFOKPOGTD)EXPIRE_MAKEREXPIRE_TAKEREXPIRE_BOTHNONE)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergmax     )r   limitdaysBack	untilDayssymbolRequired)r   r   triggerr   r   )r   r   r   r   r   r   r   )paginater   )	r   rT   rU   r{   r   r   r   rd   r|   extendsdefault)linearinverse)r   r=   r?   r@   requiredCredentials)apiKeysecretprecisionModeoptionsaccountQueryaccountUpdate)GETPATCHr   balanceQuerymaxBorrowQuantitymaxOrderQuantitymaxWithdrawalQuantityborrowLendPositionQueryr   POSTborrowLendExecuteborrowPositionHistoryQueryAllborrowHistoryQueryAlldustHistoryQueryAllcollateralQuerydepositAddressQuerydepositQueryAllfillHistoryQueryAllfundingHistoryQueryAllinterestHistoryQueryAllr   
orderQueryorderExecuteorderCancel)r   r   DELETEorderQueryAllorderCancelAllorderHistoryQueryAllpnlHistoryQueryAllrfqHistoryQueryAllquoteHistoryQueryAllsettlementHistoryQueryAllpositionQueryquoteSubmitstrategyHistoryQueryAllwithdrawalQueryAll)r   r   )
r   r   zwapi/v1/history/pnlr   r   r   r   r   r   r   i   r   APTAptosARBArbitrumAVAX	AvalancheBASEBaseBERA	BerachainBTCBitcoinBCHBitcoinCashBSCBscADACardanoDOGEDogecoinECLIPSEEclipseEQUALSMONEYEqualsMoneyERC20EthereumHYPHyperliquidLTCLitecoinOPTIMISMOptimismMATICPolygonSeiSuiSolanaStoryTronXRP)SEISUISOLSTORYTRC20rB  aptosarbitrum	avalanchebase	berachainbitcoinbitcoincashbsccardanodogecoineclipseequalsmoneyethereumhyperliquidlitecoinoptimismpolygonrC  rD  rE  rF  rG  )seisuisolanastorytronxrp)	instructions
recvWindowbrokerIdcurrencyIdsListForParseMarketbrokertimeDifferenceadjustForTimeDifferencenetworksnetworksByIdcommonCurrencies
exceptionsINVALID_CLIENT_REQUESTINVALID_ORDERACCOUNT_LIQUIDATINGBORROW_LIMITBORROW_REQUIRES_LEND_REDEEM	FORBIDDENINSUFFICIENT_FUNDSINSUFFICIENT_MARGININSUFFICIENT_SUPPLYINVALID_ASSETINVALID_MARKETINVALID_PRICEINVALID_POSITION_IDINVALID_QUANTITYINVALID_RANGEINVALID_SIGNATUREINVALID_SOURCEINVALID_SYMBOLINVALID_TWO_FACTOR_CODE
LEND_LIMITLEND_REQUIRES_BORROW_REPAYMAINTENANCEMAX_LEVERAGE_REACHEDNOT_IMPLEMENTEDORDER_LIMITPOSITION_LIMITPRECONDITION_FAILEDRESOURCE_NOT_FOUNDSERVER_ERRORTIMEOUTTOO_MANY_REQUESTSTRADING_PAUSEDUNAUTHORIZED)exactbroad)deep_extendsuperr-   describer*   r    r$   r"   r#   r!   r   r   r%   r(   r&   r)   r'   )self	__class__s    Y/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/backpack.pyr  zbackpack.describe   s   h 5 5 > > @ @ _C
*_C
J_C
 $_C
 	_C

 t_C
 _C
 4_C
  fff $f 	f
 %f %f Uf "4f 'f tf f !%f  f %ef 'f  &t!f" #D#f f$ '%f& ''f( /)f* $T+f, ,T-f. (/f0 01f2 t3f4 5f6 77f8 &t9f: (;f< &u=f> (?f@ ,UAfB -eCfD %dEf f fF  GfH !%IfJ KfL /MfN &uOfP #EQfR $USfT )%UfV $UWfX $UYfZ +E[f\ "4]f^ &t_f`  afb +Ecfd +Eeff &tgf f fh #Difj *4kfl $Umfn uofp "4qfr usft  ufv %ewfx /yfz "5{f| }f~ !$f@  AfB dCfD $TEfF +DGfH !$If f fJ "4KfL uMfN #EOfP eQfR !$SfT tUfV #EWfX  YfZ '[f\ $U]f^ !$_f` *5afb (cfd )%eff tgfh tifj kf f fl Tmfn tofp "5qfr #Esft $Uufv !%wfx )%yfz #D{f| }f~ 5f@ uAfB UCfD  EfF "5GfH EIfJ DKf f_C
^  __C
@ i=>  48A	 	A_C
T  '+Q 4Q <Q	
 )! ( ( )! ' ( ,Q .q .q ( &q  &q!" )!#$ *+12'  0(!6 6q ;A	
 6q )! 4Q 3A :1 6q *1 5a 3A ? /  0!" 21#$ 34/0126767())*1  6 78-.78())*&'-../-.,-  )*)* 
 )!W. .1G GU_C
d $&+(,,0,1)-+/6:#'#'#'"&#(( ( #($)$)+/26,0,0+/$)	0 0 $)5$ $: r% ',!%$(%)*/& & #'&+!%#'$)*/( ( ',!%$(%)#'$)*.$ $ *.$)!%# #u> >@ y ## 
 ## OK Ke_C
| "$ $}_C
D	 YE	_C
F	 X!$-!0' 'X!
 %~'X! 325X! 214X! 769X!" 284#X!( ( 3*)X!. ;>=/X!4 1635X!: +4-;X!@ 002AX!F 648GX!L /01MX!R ,4.SX!X .70YX!^ /81_X!d #+ ."/% %eX!p  / ."2& & 5/ 3, 3, 5. :3 ( ) 83  4 *4 4iX! X! X!r #15"#+07: K F	
 K 9 = 5 9 J y "= Z = :  
!" Y#$ ! #$# /  2!U!!  ! F	!
  ! u! "5! 5! u! ! y! "=! ! "5! !  
!!" w#!$ ! #$# /! ! !sR RG	_C
l m_C
n ",j"#\" *:" #J	"
 2:"  !2" )*;" *+<" *+<" $Z" %i" $Z" *:" '
" $Z"  ()<!"" %j#" "$ %i%"& .z'"( !*)"* 1*+", "=-". +,=/"0 &1"2 "#43"4 %&75"6 *?7"8 )*>9": #L;"< ~="> ():?"@ %&:A"B #$7C" "J M' 'o_C
 _ _ _	    c                 (  K   |                      |           d{V }i }t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                     |dg           }i }	t          dt          |                    D ]}
||
         }|                     |d          }|                     |d          }|                     |          }|||                     |d          | 	                    | 
                    |                     |d                              d|                     |d	          ddd
d|                     |d          |                     |d          |                     |d          d|d	|	|<   d}d}d}|                     |	          rd}d}d}|                     ||dd|                     |d          |||dddddddd|	|d          ||<   |S )a
  
        fetches all available currencies on an exchange

        https://docs.backpack.exchange/#tag/Assets

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        Nr   symboltokens
blockchainminimumWithdrawalmaximumWithdrawalminr   minimumDeposit)r   depositdepositEnabledwithdrawEnabledwithdrawalFee)	r0   networklimitsactiver  r   fee	precisioninfoFcryptodisplayName)r  r   )r0   coder  typer1   r  r  r   r  r  rf  r  )publicGetApiV1Assetsrangelensafe_stringsafe_currency_code	safe_listsafe_string_lowernetwork_id_to_codesafe_numberparse_number	omit_zero	safe_boolis_emptysafe_currency_structure)r  paramsresponseresulticurrecy
currencyIdr  rf  parsedNetworksjr  	networkIdnetworkIdLowerCasenetworkCoder  r  r   s                     r  fetch_currencieszbackpack.fetch_currencies  s      226::::::::0 q#h--(( <	 <	AqkG))'8<<J**:66D~~gx<<H#%N1c(mm,,  "1+ ,,WlCC	%)%;%;G\%R%R""556HII#* $(#3#3G=P#Q#Q#'#4#4T^^DDTDTU\^qDrDr5s5s#t#t% %
 $(#3#3G=M#N#N#'$ $	 	 ##~~g7GHH $w8I J J++G_EE!%#%/ /{++( FGH}}^,, ! 77 ! ((-@@ "$  $#   
  $#! !	 	 ++9 9  F4LL. r  c                    K   | j         d         r|                                  d{V  |                     |           d{V }|                     |          S )a"  
        retrieves data on all markets for bitbank

        https://docs.backpack.exchange/#tag/Markets/operation/get_markets

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        re  N)r   load_time_differencepublicGetApiV1Marketsparse_marketsr  r  r  s      r  fetch_marketszbackpack.fetch_markets`  su       <12 	.++---------33F;;;;;;;;!!(+++r  marketc                    |                      |d          }|                      |d          }|                      |d          }|                     |          }|                     |          }|dz   |z   }|                     |di           }|                     |di           }	|                     |	d          }
|                     |	d          }|                     |	d	          }|                     |d
i           }|                     |d          }|                     |d          }|                     |d          }|                     |                      |d                    }d }d }d }d }d }|dk    rd}nA|dk    r;d}d}d}|                      |d          }|                     |          }|d|z   z  }d}|                      |d          }|                     i d|d|d|d|d|d|d|d|d|d|dk    d|dk    d|dk    ddd dd!|d"k    d#|dk    d$||d d |d d d d ||d%d d d&||d&||
d&d d d&d'|                     |                      |d(                    |d)          S )*Nr  
baseSymbolquoteSymbol/filterspricemaxPriceminPricetickSizequantitymaxQuantityminQuantitystepSize
marketTyper=   r?   TF:r   orderBookStater0   rK  quotesettlebaseIdquoteIdsettleIdr  r>   r@   rA   r  Opencontractr   )amountr  r  )r   r  r  cost	createdAt)r   takermakercontractSizeexpiryexpiryDatetimestrike
optionTyper  r  createdr  )r  r  	safe_dictr  parse_market_typesafe_market_structure	parse8601)r  r  r0   r  r  rK  r  r  r  priceFilterr  r  pricePrecisionquantityFilterr  r  amountPrecisiontypeOfMarketr   r   r  r  r  r  r  s                            r  parse_marketzbackpack.parse_marketn  s   r fh//!!&,77""6=99&&v..''00e#..B77nnWgr::##K<<##K<<))+zBBR@@&&~}EE&&~}EE**>:FF--d.>.>v|.T.TUU 6!!DDV##DFG''>>H,,X66FcFl"FL))&2BCC)) 2+
"2+
f2+
 D2+
 U	2+

 f2+
 f2+
 w2+
 2+
 D2+
 DFN2+
 dfn2+
 DFN2+
 e2+
 e2+
 n.2+
  !2+
" f#2+
$ (")'    
 '& 
 $# 
    $ ~~d&6&6v{&K&KLLc2+
 2+
 2+
 2 2 2	r  c                 :    ddd}|                      |||          S )Nr=   r?   )SPOTPERPr  )r  r  typess      r  r  zbackpack.parse_market_type  s.    
 
 tT222r  Nsymbolsc                    K   |                                   d{V  i }|                     |                     ||                     d{V }|                     |          }|                     |d|          S )a  

        https://docs.backpack.exchange/#tag/Markets/operation/get_tickers

        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/?id=ticker-structure>`
        Nr  )load_marketspublicGetApiV1Tickersextendparse_tickersfilter_by_array_tickers)r  r  r  requestr  tickerss         r  fetch_tickerszbackpack.fetch_tickers(  s       !!!!!!!!!33DKK4P4PQQQQQQQQ$$X..++GXwGGGr  r  c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://docs.backpack.exchange/#tag/Markets/operation/get_ticker

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/?id=ticker-structure>`
        Nr  r0   )r  r  publicGetApiV1Tickerr  parse_tickerr  r  r  r  r  r  s         r  fetch_tickerzbackpack.fetch_ticker8  s       !!!!!!!!!V$$fTl
 224;;w3O3OPPPPPPPP  6222r  tickerc           	         |                      |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|          S )Nr  
firstPrice	lastPricehighlowvolumequoteVolumepriceChangePercentpriceChange	timestampdatetimebid	bidVolumeask	askVolumevwapopencloselastpreviousClosechange
percentageaverage)
baseVolumer  	markPrice
indexPricer  )r  safe_marketsafe_symbolsafe_ticker)r  r  r  marketIdr  r  r  r  r  r$  r  r"  r!  s                r  r	  zbackpack.parse_tickerJ  s   " ##FH55!!(F33!!(F335544//vu--%%fh77
&&v}==%%f.BCC
!!&-88 !
f!
!
 !
 D	!

 3!
 4!
 !
 4!
 !
 D!
 D!
 T!
 D!
 T!
 f!
  *!!
" t#!
$ %&-!
 !
 !
. /  	r  r   c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |d          }|                     |dz            }|                     |||          }	|                     |d          |	d<   |	S )a_  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://docs.backpack.exchange/#tag/Markets/operation/get_depth

        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return(default 100, max 200)
        :param dict [params]: extra parameters specific to the bitteam api endpoint
        :returns dict: A dictionary of `order book structures <https://github.com/ccxt/ccxt/wiki/Manual#order-book-structure>` indexed by market symbols
        Nr  r0   r  r   lastUpdateIdnonce)r  r  publicGetApiV1Depthr  safe_integerparse_to_intparse_order_book)
r  r  r   r  r  r  r  microsecondsr  	orderbooks
             r  fetch_order_bookzbackpack.fetch_order_book  s       !!!!!!!!!V$$fTl
 11$++gv2N2NOOOOOOOO ((;??%%lT&9::	))(FIFF	!..xHH	'r  r   sincec                 (  K   |                                   d{V  |                     |          }|                     | j        ||          }|d         |d}d}	|                     |dd          \  }	}|	|                     |	dz            |d<   d}
|U||
}|                     |          }|	r|                     |	dz            n|                                 }|||z  z
  }||d	<   n|                     |dz            |d	<   |                     |d
          }|.|                     |          |d<   | 	                    |d
          }| 
                    |                     ||                     d{V }|                     |||||          S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://docs.backpack.exchange/#tag/Markets/operation/get_klines

        :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 seconds of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch(default 100)
        :param dict [params]: extra parameters specific to the bitteam api endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nr0   )r  intervalr|   untilr   endTimed   	startTimer  	priceType)r  r  r  r   handle_option_and_paramsr0  parse_timeframeseconds
capitalizeomitpublicGetApiV1Klinesr  parse_ohlcvs)r  r  	timeframer5  r   r  r  r7  r  r8  defaultLimitdurationr9  r;  r  r  s                   r  fetch_ohlcvzbackpack.fetch_ohlcv  s      !!!!!!!!!V$$##DOY	JJTl 
 
 55flGTTv!%!2!254<!@!@GI=}$++I66H9>Rd''555DLLNNG58#34I#,GK  #'#4#4UT\#B#BGK   11#'??5#9#9GK YYvw//F224;;w3O3OPPPPPPPP  69eUKKKr  c           	      (   |                      |                     |d                    |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nstartr  r  r  r  r  )r  r  r  )r  ohlcvr  s      r  parse_ohlcvzbackpack.parse_ohlcv  s    $ NN4++E7;;<<UF++UF++UE**UG,,UH--
 	
r  c                 t  K   |                                   d{V  |                     |          }|d         rt          | j        dz   |z             d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )ak  
        fetch the current funding rate

        https://docs.backpack.exchange/#tag/Markets/operation/get_mark_prices

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/?id=funding-rate-structure>`
        Nr=   z3 fetchFundingRate() symbol does not support market r  r0   r   )r  r  r    r0   publicGetApiV1MarkPricesr  r  parse_funding_rate)r  r  r  r  r  r  datas          r  fetch_funding_ratezbackpack.fetch_funding_rate  s       !!!!!!!!!V$$&> 	gTW'\\_eeffffTl
 66t{{7F7S7STTTTTTTT~~h2..&&tV444r  c                    |                      |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iS )Nr  nextFundingTimestampr  r%  r&  interestRateestimatedSettlePricer  r  fundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer7  r   )r  r'  r(  r/  r  iso8601)r  r  r  r*  r  rR  s         r  rN  zbackpack.parse_funding_rate  s{    ##Hh77!!(F33!!(F33#00;QRR
H
f
 ))(K@@
 $**8\BB	

 D
 #D
 
 
 4++HmDD
 
 t
 t
 #$8
 "4<<0D#E#E
 "4
  '!
" &t#
$ %
 
 	
r  c                 t  K   |                                   d{V  |                     |          }|d         rt          | j        dz   |z             d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )a{  
        Retrieves the open interest of a derivative trading pair

        https://docs.backpack.exchange/#tag/Markets/operation/get_open_interest

        :param str symbol: Unified CCXT market symbol
        :param dict [params]: exchange specific parameters
        :returns dict} an open interest structure{@link https://docs.ccxt.com/?id=interest-history-structure:
        Nr=   z4 fetchOpenInterest() symbol does not support market r  r0   r   )r  r  r    r0   publicGetApiV1OpenInterestr  r  parse_open_interest)r  r  r  r  r  r  interests          r  fetch_open_interestzbackpack.fetch_open_interest  s       !!!!!!!!!V$$&> 	hTW']]`ffgggfTl
 88Wf9U9UVVVVVVVV>>(Ar22''&999r  c           	          |                      |d          }|                     |d          }|                     |d         d |||                     |          |d|          S )Nr  openInterestr  )r  openInterestAmountopenInterestValuer  r  r  )r/  r  safe_open_interestr]  )r  ra  r  r  rd  s        r  r`  zbackpack.parse_open_interest4  sx     %%h<<	''.AA&&X&"&!-"Y//(
 (
   	r  c           	        K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|t	          |d          |d<   |                     |                     ||                     d{V }g }t          dt          |                    D ]j}	||	         }
| 	                    |
d          }| 
                    |          }|                    |
|d         |                     |
d	          ||d
           k|                     |d          }|                     ||d         ||          S )aZ  
        fetches historical funding rate prices

        https://docs.backpack.exchange/#tag/Markets/operation/get_funding_interval_rates

        :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
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/?id=funding-rate-history-structure>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentr  r0   r   r   r   intervalEndTimestamprU  )r  r  rU  r  r  r  )r   r0   r  r  r  publicGetApiV1FundingRatesr  r  r  r  r  appendr  sort_byfilter_by_symbol_since_limit)r  r  r5  r   r  r  r  r  ratesr  rater  r  sorteds                 r  fetch_funding_rate_historyz#backpack.fetch_funding_rate_historyI  s      >#DG.e$efff!!!!!!!!!V$$fTl
 "5$//GG88Wf9U9UVVVVVVVV q#h--(( 
	 
	AA;D''.DEEHx00ILL *#//mDD&$      e[11009I5RWXXXr  c                   K   |                                   d{V  |                     |          }d|d         i}|t          |d          |d<   d}|                     |d          }|0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     ||||          S )a  
        get the list of most recent trades for a particular symbol

        https://docs.backpack.exchange/#tag/Trades/operation/get_recent_trades
        https://docs.backpack.exchange/#tag/Trades/operation/get_historical_trades

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.offset]: the number of trades to skip, default is 0
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=public-trades>`
        Nr  r0   r   r   offset)r  r  r  r/  publicGetApiV1TradesHistoryr  publicGetApiV1Tradesparse_trades)	r  r  r5  r   r  r  r  r  rs  s	            r  fetch_tradeszbackpack.fetch_tradesw  s      !!!!!!!!!V$$fTl
 "5$//GG""6844!==dkk'SY>Z>Z[[[[[[[[HH!66t{{7F7S7STTTTTTTTH  65%@@@r  c                   K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |||d<   |                     |d          }||                     |dg          }||d<   |                     |d          }|d	|d<   |                     |                     ||                     d{V }	|                     |	|||          S )
a,  
        fetch all trades made by the user

        https://docs.backpack.exchange/#tag/History/operation/get_fills

        :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(default 100, max 1000)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch trades for
        :param str [params.fillType]: 'User'(default) 'BookLiquidation' or 'Adl' or 'Backstop' or 'Liquidation' or 'AllLiquidation' or 'CollateralConversion' or 'CollateralConversionAndSpotLiquidation'
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Nr0   r  fromr   r8  tofillTypeUser)r  r  r/  rA  r  privateGetWapiV1HistoryFillsr  rv  )
r  r  r5  r   r  r  r  r8  r{  r  s
             r  fetch_my_tradeszbackpack.fetch_my_trades  s&      !!!!!!!!![[((F &tGH#GFO$GG!!&'22YYvy11F!GDM##FJ77"(GJ::4;;wPV;W;WXXXXXXXX  65%@@@r  tradec                 (   |                      |dd          }|                     |d          }|                     ||          }|                     |d          }|                     |d          }|                     |d          }|rdnd}|                     |d	          }	|                     |                     |d
                    }
d }|                     |d          }|                     |d          }|+|                     |d          }|                     |          }|                     |                     |d                    }|||d d}|                     ||| 	                    |          |d         ||	d |
|||d |d|          S )Nr0   tradeIdr  r  r  isMakerr  r  orderIdsider  r  	feeSymbol)r  currencyro  )r  r  r  r  r0   orderr  r  takerOrMakerr  r  r  r  )
safe_string_2r  r'  r  parse_order_sider/  r  r  
safe_trader]  )r  r  r  r0   r*  r  r  r  r  r  r  r  	feeAmountr  r  r  s                   r  parse_tradezbackpack.parse_trade  s   8 tY77##E844!!(F33  00!!%44..	22")6www""5)44$$T%5%5eV%D%DEE$$UE22	%%e[99	 ''{;;Hx00I++D,<,<UK,P,PQQ	 !% C
 "Y//X&( 
  
   	r  c                    K   |                      |           d{V }|                     |d          }|                                ddd|dS )aW  
        the latest known information on the availability of the exchange API

        https://docs.backpack.exchange/#tag/System/operation/get_status

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `status structure <https://docs.ccxt.com/?id=exchange-status-structure>`
        Nstatus)r  updatedetaurlr  )publicGetApiV1Statusr  lower)r  r  r  r  s       r  fetch_statuszbackpack.fetch_status  sj       226:::::::: !!(H55llnn
 
 	
r  c                    K   |                      |           d{V }|                     |d|                                           S )aW  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://developer-pro.bitmart.com/en/spot/#get-system-time

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        Nr   )publicGetApiV1Timer/  millisecondsr  s      r  
fetch_timezbackpack.fetch_time  sS       0088888888   1d.?.?.A.ABBBr  c                    K   |                                   d{V  |                     |           d{V }|                     |          S )al  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://docs.backpack.exchange/#tag/Capital/operation/get_balances

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
        N)r  privateGetApiV1Capitalparse_balancer  s      r  fetch_balancezbackpack.fetch_balance!  se       !!!!!!!!!44V<<<<<<<<!!(+++r  c                    t          |                                          }i }t          dt          |                    D ]}||         }|                     |          }||         }|                                 }|                     |d          }	|                     |d          }
t          j        |	|
          }|                     |d          |d<   ||d<   |||<   | 	                    |          S )Nr   lockedstaked	availablefreeused)
listkeysr  r  r  accountr  r+   
string_addsafe_balance)r  r  balanceKeysr  r  r0   r  balancer  r  r  r  s               r  r  zbackpack.parse_balance.  s     8==??++q#k**++ 
	# 
	#AQB**2..DrlGllnnG%%gx88F%%gx88F%ff55D"..wDDGFO"GFO"F4LL  (((r  r  c                 `  K   |                                   d{V  i }d}||                     |          }|||d<   |||d<   d}|                     |dd          \  }}|||d<   |                     |                     ||                     d{V }|                     ||||          S )a`  
        fetch all deposits made to an account

        https://docs.backpack.exchange/#tag/Capital/operation/get_deposits

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        Nry  r   rk   r8  r9  )r  r  r=  privateGetWapiV1CapitalDepositsr  parse_transactions	r  r  r5  r   r  r  r  r8  r  s	            r  fetch_depositszbackpack.fetch_depositsG  s       !!!!!!!!!
!}}T**H#GFO$GG55fowWWv!&GI==dkk'SY>Z>Z[[[[[[[[&&x5%HHHr  c                 `  K   |                                   d{V  i }d}||                     |          }|||d<   |||d<   d}|                     |dd          \  }}|||d<   |                     |                     ||                     d{V }|                     ||||          S )a  
        fetch all withdrawals made from an account

        https://docs.backpack.exchange/#tag/Capital/operation/get_withdrawals

        :param str code: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for(default 24 hours ago)
        :param int [limit]: the maximum number of transfer structures to retrieve(default 50, max 200)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch transfers for(default time now)
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        Nry  r   r   r8  rz  )r  r  r=  "privateGetWapiV1CapitalWithdrawalsr  r  r  s	            r  fetch_withdrawalszbackpack.fetch_withdrawalse  s       !!!!!!!!!!}}T**H#GFO$GG55f>PRYZZv!GDM@@WV\A]A]^^^^^^^^&&x5%HHHr  r  addresstagc                   K   |                                   d{V  |                     |          }|d         |                     |          |d}|||d<   |                     |          \  }}	|                     |          }
|
t          | j        dz             |
|d<   |                     |                     ||	                     d{V }| 	                    ||          S )a,  
        make a withdrawal

        https://docs.backpack.exchange/#tag/Capital/operation/request_withdrawal

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str params['network']: the network to withdraw on(mandatory)
        :returns dict: a `transaction structure <https://docs.ccxt.com/?id=transaction-structure>`
        Nr0   )r  r  r  clientIdz( withdraw() requires a network parameterr  )
r  r  number_to_stringhandle_network_code_and_paramsnetwork_code_to_idr    r0   #privatePostWapiV1CapitalWithdrawalsr  parse_transaction)r  r  r  r  r  r  r  r  r  queryr  r  s               r  r   zbackpack.withdraw  s      !!!!!!!!!==&&tn--f55
 

 ?"%GJ!@@HHU++K88	TW'QQRRR )AA$++gW\B]B]^^^^^^^^%%h999r  r  c                 f   |                      |                     |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S ) Nr  r0   transactionHashr  r  r  sourcer  	toAddressfromAddressplatformMemor  
isInternalF)r  r  r  txidr  r  r  r  	addressToaddressFromr  tagTotagFromr  r  r  r  )internalcommentr  )	parse_transaction_statusr  r  r  r  safe_string_lower_2r  r  r]  )r  transactionr  r  r0   r  coinr  r  r  r  r  r  r  r  feeCostr  r  s                     r  r  zbackpack.parse_transaction  s[   R ..t/?/?X/V/VWWk400->??X66&&tX66NN4#3#3K#M#MNN	!!+z::,,[(LQQ	)))44$$[+>>	&&{MBB{N;;"";66>>+|UCC  C
K
"
 D
 	

 Y//
 w
 t
 
 ;
 3
 T
 t
 D
 f
 
  f!
" t#
$ !)
 
 
 	
r  r  c           	      F    ddddddddd}|                      |||          S )	N	cancelledokdeclinedexpired	initiatedpendingrefunded)r  	confirmedr  r  r  r  r  zinformation requiredr  r  r  statusess      r  r  z!backpack.parse_transaction_status  s@    $" $ "$-	
 	
 &&999r  c                   K   |                                   d{V  d}|                     |          \  }}|t          | j        dz             |                     |          }d|                     |          i}|                     |                     ||                     d{V }|                     ||          S )a  
        fetch the deposit address for a currency associated with self account

        https://docs.backpack.exchange/#tag/Capital/operation/get_deposit_address

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.networkCode]: the network to fetch the deposit address(mandatory)
        :returns dict: an `address structure <https://docs.ccxt.com/?id=address-structure>`
        Nz` fetchDepositAddress() requires a network parameter, see https://docs.ccxt.com/?id=network-codesr  )	r  r  r   r0   r  r  %privateGetWapiV1CapitalDepositAddressr  parse_deposit_address)r  r  r  r  r  r  r  s          r  fetch_deposit_addresszbackpack.fetch_deposit_address"  s       !!!!!!!!!"AA&IIV#DG  /Q  %Q  R  R  R==&&$11+>>
 CCDKKPWY_D`D`aaaaaaaa))(H===r  c                     |                      |d          }|                      |d          }|                     ||          }||d         d |d dS )Nr  r  r  )r  r  r  r  r  )r  safe_currency)r  depositAddressr  r  r  s        r  r  zbackpack.parse_deposit_address9  sf     "">9==%%njAA
%%j(;;" (
 
 	
r  r  r  r  c                    K   |                                   d{V  |                     |          }|                     ||||||          }|                     |           d{V }	|                     |	|          S )a	  
        create a trade order

        https://docs.backpack.exchange/#tag/Order/operation/execute_order

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much 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 float [params.cost]: *market orders only* the cost of the order in units of the quote currency(could be used instead of amount)
        :param int [params.clientOrderId]: a unique id for the order
        :param boolean [params.postOnly]: True to place a post only order
        :param str [params.timeInForce]: 'GTC', 'IOC', 'FOK' or 'PO'
        :param bool [params.reduceOnly]: *contract only* Indicates if self order is to reduce the size of a position
        :param str [params.selfTradePrevention]: one of EXPIRE_MAKER, EXPIRE_TAKER or EXPIRE_BOTH
        :param bool [params.autoLend]: *spot margin only* if True then the order can lend
        :param bool [params.autoLendRedeem]: *spot margin only* if True then the order can redeem a lend if required
        :param bool [params.autoBorrow]: *spot margin only* if True then the order can borrow
        :param bool [params.autoBorrowRepay]: *spot margin only* if True then the order can repay a borrow
        :param float [params.triggerPrice]: the price that a trigger order is triggered at
        :param dict [params.takeProfit]: *swap markets only - 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 float [params.takeProfit.price]: take profit order price(if not provided the order will be a market order)
        :param dict [params.stopLoss]: *swap markets only - 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 float [params.stopLoss.price]: stop loss order price(if not provided the order will be a market order)
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        N)r  r  create_order_requestprivatePostApiV1Orderparse_order)
r  r  r  r  r  r  r  r  orderRequestr  s
             r  create_orderzbackpack.create_orderJ  s      > !!!!!!!!!V$$00tVUTZ[[33LAAAAAAAA&111r  ordersc           	        K   |                                   d{V  g }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d          }|                     |d          }	|                     |d          }
|                     |di           }|                     ||          }|                     ||||	|
|          }|                    |           | 	                    |           d{V }| 
                    |          S )	a  
        create a list of trade orders

        https://docs.backpack.exchange/#tag/Order/operation/execute_order_batch

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr   r  r  r  r  r  r  )r  r  r  r  r  r  r  r  rk  privatePostApiV1Ordersparse_orders)r  r  r  ordersRequestsr  rawOrderr*  r  r  r  r  orderParamsextendedParamsr  r  s                  r  create_orderszbackpack.create_orderso  sY      !!!!!!!!!q#f++&& 
	0 
	0AayH''(;;H##Hf55D##Hf55D%%h99F$$Xw77E..8R@@K![[f==N44XtT6SXZhiiL!!,////44^DDDDDDDD  ***r  c                    |                      |          }|d         |                     |          |                     |          d}|                     |d          }	|	d u}
|
rdnd}|dk    r3|                     ||          |d<   |                     ||          ||<   nj|dk    rd|                     |d	d
          }|2|                     ||          |d
<   |                     |d	d
g          }n|                     ||          ||<   |
r/|                     ||	          |d<   |                     |d          }| 	                    |d          }|||d<   |                     |d          }d}| 
                    |dk    d|          \  }}|rd|d<   |                     |d          }|x|                     |d          }||                     ||          |d<   |                     |d          }||                     ||          |d<   |                     |d          }|                     |d          }|x|                     |d          }||                     ||          |d<   |                     |d          }||                     ||          |d<   |                     |d          }d }|                     |dd          \  }}|#|dk    rd|d<   n|dk    rd|d<   n|dk    rd|d<   |                     ||          S )Nr0   )r  r  	orderTyper   triggerQuantityr  r   r  r  r  quoteQuantityclientOrderIdr  FTpostOnly
takeProfittakeProfitTriggerPricetakeProfitLimitPricestopLossstopLossTriggerPricestopLossLimitPricerT   r   r   RejectMakerr   RejectTakerr   
RejectBoth)r  encode_order_sider@  r  price_to_precisionamount_to_precisionr  cost_to_precisionrA  r/  handle_post_onlyr  r=  r  )r  r  r  r  r  r  r  r  r  r   isTriggerOrderquantityKeyr  r  r  r  r  r   r  r  r   r   s                         r  r  zbackpack.create_order_request  s   V$$Tl**400..
 

 ''??%T1+9I''z7??#66vuEEGG#'#;#;FF#K#KGK  X%%ffoFFD+/+A+A&$+O+O(6FO+DEE'+'?'?'O'O$ 	7&*&=&=fl&S&SGN#YYv~66F))&/BB$"/GJYYv77F001A5&QQ& 	&!%F:^^FL99
!%)%5%5j.%Q%Q"%1484K4KFTj4k4k01"..z7CCO*262I2I&Ra2b2b./YYv|44F>>&*55#'#3#3Hn#M#M #/262I2I&Rf2g2g./ ,,Xw??M(040G0GP]0^0^,-YYvz22F"&*&C&CFM[p&q&q#V*"n441>-..$661>-..$551=-.{{7F+++r  c                 :    ddd}|                      |||          S )NBidAsk)buysellr  r  r  sidess      r  r   zbackpack.encode_order_side  s.    
 
 tT222r  c                   K   |                                   d{V  i }d}| |                     |          }|d         |d<   |                     |                     ||                     d{V }|                     ||||          S )a  
        fetch all unfilled currently open orders

        https://docs.backpack.exchange/#tag/Order/operation/get_open_orders

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nr0   r  )r  r  privateGetApiV1Ordersr  r  r  r  r5  r   r  r  r  r  s           r  fetch_open_orderszbackpack.fetch_open_orders  s       !!!!!!!!![[((F &tGH33DKK4P4PQQQQQQQQ  65%@@@r  r0   c                 4  K   |                                   d{V  |t          | j        dz             |                     |          }|d         |d}|                     |                     ||                     d{V }|                     |          S )a  
        fetch an open order by it's id

        https://docs.backpack.exchange/#tag/Order/operation/get_order

        :param str id: order id
        :param str symbol: not used by hollaex fetchOpenOrder()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nz, fetchOpenOrder() requires a symbol argumentr0   )r  r  )r  r   r0   r  privateGetApiV1Orderr  r  r  r0   r  r  r  r  r  s          r  fetch_open_orderzbackpack.fetch_open_order  s       !!!!!!!!!>#DG.\$\]]]V$$Tl
 
 224;;w3O3OPPPPPPPP)))r  c                 4  K   |                                   d{V  |t          | j        dz             |                     |          }||d         d}|                     |                     ||                     d{V }|                     |          S )a  
        cancels an open order

        https://docs.backpack.exchange/#tag/Order/operation/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
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        N) cancelOrder() requires a symbol argumentr0   )r  r  )r  r   r0   r  privateDeleteApiV1Orderr  r  r  s          r  cancel_orderzbackpack.cancel_order  s       !!!!!!!!!>#DG.Y$YZZZV$$Tl
 
 55dkk'66R6RSSSSSSSS)))r  c                 4  K   |                                   d{V  |t          | j        dz             |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||          S )a  
        cancel all open orders

        https://docs.backpack.exchange/#tag/Order/operation/cancel_open_orders

        :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
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nr  r  r0   )r  r   r0   r  privateDeleteApiV1Ordersr  r  r
  s         r  cancel_all_orderszbackpack.cancel_all_orders  s       !!!!!!!!!>#DG.Y$YZZZV$$fTl
 66t{{7F7S7STTTTTTTT  6222r  c                 "  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |                     |                     ||                     d{V }|                     ||||          S )ab  
        fetches information on multiple orders made by the user

        https://docs.backpack.exchange/#tag/History/operation/get_order_history

        :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  orde structures to retrieve(default 100, max 1000)
        :param dict [params]: extra parameters specific to the bitteam api endpoint
        :returns Order[]: a list of `order structures <https://github.com/ccxt/ccxt/wiki/Manual#order-structure>`
        Nr0   r  r   )r  r  privateGetWapiV1HistoryOrdersr  r  r  s           r  fetch_orderszbackpack.fetch_orders#  s       !!!!!!!!![[((F &tGH$GG;;DKKQW<X<XYYYYYYYY  65%@@@r  r  c                    |                      |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|          S )Nr  r0   r  r  r  r   r  r  r  r  executedQuoteQuantityr  r   executedQuantity
reduceOnlyr  r  r  r  r  r  r  r  r  lastTradeTimestampr  r   r   r  )r  r#  filled	remainingr  r  trades)r/  r  r  r(  r  r  r  parse_order_statusr  
safe_orderr]  )r  r  r  r  
timestamp2r0   r  r  r  r   r  r  r  r  r  r   r%  r#  r  r   r   s                        r  r  zbackpack.parse_order:  s   z %%e[99	^^D$4$4UK$H$HII
!"IeT**((
;;!!$"2"25("C"CVLL%%e[99&&um<<$$T%5%5eV%D%DEE##E:7HII  00'>??(()9)9%)J)JKK''~>>!!%);<<^^E<88
>>%44**52FH^__,,U4JLdee  
E 
" 
 ] 
 	 

 Y// 
 !$ 
 f 
 D 
 ; 
  
 * 
 D 
 U 
 L 
 ] 
  ! 
" f# 
$ 1 
  
  
2 3  	r  c                 D    dddddddd}|                      |||          S )Nr  closedcanceledrejected)NewFilled	CancelledExpiredPartiallyFilledTriggerPendingTriggerFailedr  r  s      r  r(  zbackpack.parse_order_status  s=    #!%$'
 
 &&999r  c                 :    ddd}|                      |||          S )Nr
  r  )r  r	  r  r  s      r  r  zbackpack.parse_order_side  s.    
 
 tT222r  c                 "  K   |                                   d{V  |                     |           d{V }|                     |          }|                     |          r|S |                     |          }|                     |d|d          S )av  
        fetch all open positions

        https://docs.backpack.exchange/#tag/Futures/operation/get_positions

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/?id=position-structure>`
        Nr  F)r  privateGetApiV1Positionparse_positionsr  market_symbolsfilter_by_array_positions)r  r  r  r  	positionss        r  fetch_positionszbackpack.fetch_positions  s       !!!!!!!!!55f========((22	==!! 	%%g..--i7ERRRr  positionc                    |                      |d          }|                      |d          }|                     ||          }|d         }|                      |d          }|                      |d          }|                      |d          }d}	d}
t          j        |d          r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t          j        |          dd dd dd |                      |d          d |                      |d          |||d d d d d d          S )N
positionIdr  
entryPricer%  netCostFlong0shortpnlUnrealizedpnlRealizedestLiquidationPricer  r0   r  r  lastUpdateTimestampr   r  	contractsnetExposureQuantityr  r  notionalr   
collateralinitialMarginimfmmf)initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentagerealizedPnlunrealizedPnlliquidationPricer   marginRatior"  r   r   )r  r'  r+   	string_ltsafe_positionr  r]  
string_abs)r  r>  r  r0   r*  r  rA  r%  rB  r   r  rU  rT  rV  s                 r  parse_positionzbackpack.parse_position  s   F h55##Hh77!!(F33!%%h==
$$X{;;	""8Y77Wc** 	D?FD((?CC&&x??++H6KLL!! #
H#
"#
 f#
 (8(8;(O(OPP	#

 T^^D4D4DX{4[4[%\%\]]#
 "4#
 f#
 D#
 ))(4IJJ#
 D#
 *#
 #
 #
 *733#
 #
  $!#
" T##
$ (,'7'7%'H'H!%+/+;+;He+L+L&* 0!#9#
 #
 #
   	r  c                 "  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |                     |                     ||                     d{V }|                     ||||          S )a  
        fetches the history of funding payments

        https://docs.backpack.exchange/#tag/History/operation/get_funding_payments

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch(default 24 hours ago)
        :param int [limit]: the maximum amount of trades to fetch(default 200, max 500)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest trade to fetch(default now)
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=public-trades>`
        Nr0   r  r   )r  r  privateGetWapiV1HistoryFundingr  parse_incomesr  s           r  fetch_funding_historyzbackpack.fetch_funding_history>  s       !!!!!!!!![[((F &tGH$GG<<T[[RX=Y=YZZZZZZZZ!!(FE5AAAr  c           	      l   |                      |d          }|                     ||          }|                     |d          }|                      |d          }|                     |                      |d                    }|                     |d          }||d ||                     |          |||dS )Nr  r  userIdri  rU  )r  r  r  r  r  r0   r  ro  )r  r(  r  r  r]  )	r  incomer  r*  r  r  r0   r  ro  s	            r  parse_incomezbackpack.parse_incomeV  s     ##FH55!!(F33!!&*55fh//NN4#3#3F<R#S#STT	66"Y//	
 	
 		
r  c                 F    |                                  | j        d         z
  S )Nrd  )r  r   )r  s    r  r-  zbackpack.noncer  s!      ""T\2B%CCCr  r   r   c                 :   d|z   }| j         d         |         }t          |t                    r|n|                     |          }	|dk    r|                                  t          |                                           }
|                     | j        ddd          }| 	                    | j        di           }| 	                    ||i           }| 
                    ||d          }d}|d	k    r|d
k    r|                     |	|
||          }nD|                     |	          }t          |          dk    r|dz  }d|z   dz   |z   dz   |
z   dz   |z   }|                     | j                  }|                     |dd          }|                     |                     |          |d          }|
|| j        |dd}|dk    r|                     |	          }d|d<   |dk    r0|                     |	          }t          |          dk    r|d|z   z  }||z  }||||dS )Nr  r   r   r`  X-Window5000r_  r  r   r   r   &instruction=
timestamp=&window=    ed255191400)zX-Timestamprf  z	X-API-KeyzX-SignaturezX-Broker-Idr   zapplication/jsonzContent-Type?)r  methodbodyheaders)r   
isinstancer  keysortcheck_required_credentialsstrr-  r  r   r  r  generate_batch_payload	urlencoder  base64_to_binaryr   array_sliceeddsaencoder   json)r  pathr   rp  r  rr  rq  endpointr  sortedParamstsr`  optionInstructionsoptionPathInstructionsinstructionpayloadqueryStringsecretBytesseed	signaturer  s                        r  signzbackpack.signu  sF   :is#!+FD!9!9Svvt||F?S?S)++---TZZ\\""B++DL,
TZ[[J!%nb!Q!Q%)^^4Fb%Q%Q"**+A62NNKG''f.>.>55lB
T_``"nn\::{##a''3&K(;6<{J\Y\^^akknxx//<<K##KB77D

4;;w#7#7yIII!&![(% G yy..*<'U??NN<00E5zzQC%K'xfdwOOOr  c                 6   d}t          dt          |                    D ]x}|                     ||i           }|                     |          }|                     |          }	|d|z   dz   |	z   dz   z  }|t          |          dz
  k    r|d|z   dz   |z   z  }y|S )Nr  r   ri  rh  r   rj  rk  )r  r  r  rt  rx  )
r  r  r  r`  r  r  r  r  sortedOrderr  s
             r  rw  zbackpack.generate_batch_payload  s    q#f++&& 	G 	GANN61b11E,,u--K44J~3c9JFLLGS[[1_%%<",z9JFFr  reasonr  rp  rr  rq  c
                 n   |d S |                      |d          }
|                      |d          }|
| j        dz   |z   }|                     | j        d         |
|           |                     | j        d         ||           |                     | j        d         ||           t          |          d S )Nr  message r  r  )r  r0   throw_exactly_matched_exceptionri  throw_broadly_matched_exceptionr   )r  r  r  r  rp  rr  rq  r  requestHeadersrequestBody	errorCoder  feedbacks                r  handle_errorszbackpack.handle_errors  s    4
 $$Xv66	""8Y77 w}t+H001I9V^___001I7T\]]]001I7T\]]])))tr  )N)Q__name__
__module____qualname__r   r  r   r  r   r   r  dictr  r  r   r   r  rv  r   r  r	  r   r   r4  r  rG  rK  r   rP  rN  rb  r`  r   rq  r   rw  r~  r  r  r  r   r  r  r   r  r  floatr   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_  rc  r-  r  rw  intr  __classcell__)r  s   @r  r-   r-      s	       `# ` ` ` ` ` `D -/ _ _: _ _ _ _B *, , ,V , , , ,l4 lF l l l l\
3 
3 
3 6:" H H7 H H H H H  68 3 3 3F 3 3 3 3$3 34 3 36 3 3 3 3j @DB # #S # #S\ # # # #J 8<$]ajl 'L 'L 'LC 'LWZ 'Lquvzq{ 'L 'L 'L 'LR
 
 
4 
 
 
 
4 <> 5 5s 5+ 5 5 5 5*!
 !
6 !
[ !
 !
 !
 !
F =? : : : : : :* F    * >BPTcgpr ,Y ,Ys ,Y# ,Y]` ,Y ,Y ,Y ,Y\ <@d[] A A AS A Abfglbm A A A A: 37TX\eg  A  AC  As  ARU  A  A  A  ADA A Av A A A A AF )+ 
 
 
 
2 ') C CS C C C C *, , , , , , ,) ) ) ) )2 04$UYbd I I IC Is Iimnyiz I I I I< 37TX\eg I IC Is IRU Ilpq|l} I I I I: QU]_ : :3 : : :# :do : : : :>r
 r
x r
; r
 r
 r
 r
h:s : : : : =? > > >> > > > >.
 
h 
R` 
 
 
 
" mqy{ #2 #2 #2I #2Y #2X] #2fi #2  AF #2 #2 #2 #2J FH + +$|*< + + + +4 os{} <, <,3 <,i <,y <,Z_ <,hk <, <, <, <,|3 3 3 59tZ^gi A Ac A ATW A A A A* =A * * *c * * * *, 9=R * *S *# * * * *, 59 3 3c 3 3 3 3( 04$UYbd A A AC As Aimnsit A A A A.J J Jv J J J J JX
: 
: 
: 
: 
:3S 3 3 3 3 8<B S SW S4PX> S S S S$Q Qt QV Q Q Q Qf 9=4^bkm B B# BS BX[ B B B B0
 
6 
 
 
 
8D D D &eBSW %P %P %P %PN	 	 	# s  c TX `c        r  r-   N)1 ccxt.async_support.base.exchanger   ccxt.abstract.backpackr   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   typingr   ccxt.base.errorsr   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   ccxt.base.decimal_to_precisionr*   ccxt.base.preciser+   r-    r  r  <module>r     s   6 5 5 5 5 5 . . . . . . t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t       * * * * * * 0 0 0 0 0 0 . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . . . . . . . ) ) ) ) ) ) , , , , , , ) ) ) ) ) ) . . . . . . 1 1 1 1 1 1 + + + + + + 4 4 4 4 4 4 % % % % % %[" [" [" [" ["x [" [" [" [" ["r  