
    ei                       d dl mZ d dlmZ d dlZd dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ 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/ d dl m0Z0 d dl m1Z1 d dl2m3Z3  G d dee          Z4dS )    )Exchange)ImplicitAPIN)AccountAnyBalancesBool
CurrenciesCurrencyDepositAddressIntMarketNumOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerOpenInterestTradeTransactionFundingRateHistoryTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)	BadSymbol)OperationRejected)MarketClosed)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)OrderNotFillable)DuplicateOrderId)NotSupported)RateLimitExceeded)InvalidNonce)	TICK_SIZEc                   H    e Zd Zdef fdZi fdefdZi fdefdZi fde	e
         fdZdede
fdZdhd	ed
edefdZ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de	e         fdZdddi fdedededede	e         f
dZdhdede
defdZi fdedefdZdhdede
defdZddddi fdede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dhde
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fd"Z#di d#d$fded!ed%ed&edef
d'Z$de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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!fd-Z*di fded	e+d.e,d/e-d0e.de!fd1Z/ddi fdeded	e+d.e,d/e.d0e.fd2Z0di fdedede!fd3Z1di fdede	e!         fd4Z2dhd5ede
de!fd6Z3d7efd8Z4d	efd9Z5dddi fd:ededede	e6         fd;Z7di fd:ed/e-d<ed=ede6f
d>Z8dhd?ed@e9de6fdAZ:dB Z;d7efdCZ<i fdDZ=i fde	e>         fdEZ?dFede>fdGZ@i fd:edeAfdHZBdhd@e9deAfdIZCi fdeDfdJZEd:edeDfdKZFdeDfdLZGdi fdMeHde	eI         fdNZJdhdOede
fdPZKd.efdQZLdddi fd:ededede	eM         fdRZNi fd:ed/e-dSedTedeMf
dUZOdhd@e9fdVZPdW ZQddi fd:ededefdXZRdhd@e9fdYZSdZ ZTi fdedeUfd[ZVdhde
fd\ZWd]d^i ddfd_ZXi fd`ZYi fdaZZdbe[dceddededeedfefdgZ\ xZ]S )ibullishreturnc           !      
   |                      t          t          |                                           dddgdddi dd ddd	d
dd
dd
dd
dd
dd
dddddd
dd
ddddddddddi dddddddddd
ddddd dd!d
d"d
d#d
d$dd%dd&dd'd
d(dd)d
i d*d
d+dd,d
d-dd.d
d/d
d0d
d1dd2d
d3d
d4d
d5d
d6dd7d
d8d
d9d
d:d
i d;d
d<d
d=d
d>d
d?d
d@ddAd
dBddCddDddEd
dFd
dGd
dHddIddJddKd
i dLddMddNd
dOd
dPd
dQddRd
dSd
dTd
dUd
dVd
dWddXd
dYddZdd[d
d\d
i d]d
d^d
d_d
d`d
daddbd
dcd
ddd
ded
dfd
dgd
dhd
did
djd
dkddlddmddndidodpdqdrdsdtdudvdwdxdxdydzdzdyd{d|d}gd~di ddddddddddddddddddddddddddddddddddddiii ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
ddydd
d|                     d          |                     d          dit
          dd
dddddddid ddd
dd d
d
d
d dddd
dd
d
d
d
d
d
d
dd d
ddd
ddd
d
d
d
dd
dddd
d
d
dd
dddd
d
d
dd
dddd
d
d
dd
ddddd
d
d
dd
dddd
d
d
dddidddiddid dddid dd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          d t          dt          dt*          dt*          dt(          dt          t          t          t(          t          t          t          t(          t(          t          d	t          t          t          t          ddd	          S (
  Nr0   BullishDEv3   TCORSspotmarginFswapfutureoption	addMarginborrowMargincancelAllOrderscancelOrdercancelOrderscreateDepositAddresscreateLimitBuyOrdercreateLimitOrdercreateLimitSellOrdercreateMarketBuyOrdercreateMarketOrdercreateMarketSellOrdercreateOrdercreatePostOnlyOrdercreateTriggerOrderdeposit	editOrderfetchAccountsfetchBalancefetchBidsAsksfetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledAndClosedOrdersfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL3OrderBookfetchLedgerfetchLeveragefetchLeverageTiersfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTradingLimitsfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransfersfetchWithdrawalfetchWithdrawalsfetchWithdrawalWhitelistreduceMarginrepayMarginsetLeverage	setMarginsetMarginModesetPositionModesignIntransferwithdrawws1m5m30m1h6h12h1d)r   r   r   r   r   r   r   zOhttps://github.com/user-attachments/assets/68f0686b-84f0-4da9-a751-f7089af3a9edz,https://api.exchange.bullish.com/trading-api)publicprivatez0https://api.simnext.bullish-test.com/trading-apizhttps://bullish.com/ z/https://api.exchange.bullish.com/docs/api/rest/)logoapitestwwwreferraldocgetzv1/nonce   zv1/timez	v1/assetszv1/assets/{symbol}z
v1/marketszv1/markets/{symbol}zv1/history/markets/{symbol}z$v1/markets/{symbol}/orderbook/hybridzv1/markets/{symbol}/tradeszv1/markets/{symbol}/tickzv1/markets/{symbol}/candlez"v1/history/markets/{symbol}/tradesz(v1/history/markets/{symbol}/funding-ratezv1/index-priceszv1/index-prices/{assetSymbol}zv1/expiry-prices/{symbol}zv1/option-ladderzv1/option-ladder/{symbol}	v2/orderszv2/history/orderszv2/orders/{orderId}v2/amm-instructionsz#v2/amm-instructions/{instructionId}zv1/wallets/transactionszv1/wallets/limits/{symbol}z/v1/wallets/deposit-instructions/crypto/{symbol}z2v1/wallets/withdrawal-instructions/crypto/{symbol}z-v1/wallets/deposit-instructions/fiat/{symbol}z0v1/wallets/withdrawal-instructions/fiat/{symbol}z,v1/wallets/self-hosted/verification-attemptsz	v1/trades   zv1/history/tradeszv1/trades/{tradeId}z)v1/trades/client-order-id/{clientOrderId}zv1/accounts/asset)zv1/accounts/asset/{symbol}zv1/users/logoutv1/users/hmac/loginzv1/accounts/trading-accountsz/v1/accounts/trading-accounts/{tradingAccountId}zv1/derivatives-positionsz!v1/history/derivatives-settlementzv1/history/transferzv1/history/borrow-interestv2/mmp-configurationv2/otc-tradeszv2/otc-trades/{otcTradeId}zv2/otc-trades/unconfirmed-trade)
r   z
v2/commandr   zv1/wallets/withdrawalzv2/users/loginzv1/simulate-portfolio-marginzv1/wallets/self-hosted/initiater   r   zv2/otc-command)r   posttradingz0.001)	tierBased
percentagetakermakerr   BTCEOSETH)r   r   ERC20r   USDC)timeDifferenceadjustForTimeDifferencenetworksdefaultNetworkdefaultNetworkstradingAccountId)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergd   Z   )r   limitdaysBacksymbolRequired	untilDays)r   triggerr   r   )r   r   r   r   r   r   r   )r   r   r   daysBackCanceledr   r   r   r   r     )sandboxrI   createOrdersrq   rx   r{   rw   rT   rW   rU   rr   extendsdefault)linearinverse)r   r8   r:   r;   15613151810022001200220032004200520062007200820092010201120122013201520162017201820202021202920353001300230033004300530063007303130323033303430353047304830493051305230633064306530663067600760116012601383018305830683078310831183138315831683178318831983208322)	832783298331833283338334833583368399)HttpInvalidParameterExceptionUNAUTHORIZED_COMMANDQUERY_FILTER_ERRORINVALID_SYMBOL)exactbroad)idname	countriesversion	rateLimitprohas
timeframesurlsr   feesprecisionModeoptionsfeatures
exceptions)deep_extendsuperr0   describeparse_numberr.   r!   r'   r*   r   r"   r   r#   r   r-   r%   r(   r,   r)   r$   r&   r+   )self	__class__s    X/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/bullish.pyrL  zbullish.describe"   sk   gt 4 4 = = ? ?hhh %h 	h
 %h %h Uh h "4h th h 'h &th #Dh 'h  '!h" $T#h h$ (%h& t'h( &t)h* %d+h, 5-h. T/h0  1h2 3h4  5h6 &u7h8 +E9h: )$;h< /=h> &t?h@ #EAhB $TChD 'Eh h hF (GhH "4IhJ KhL &tMhN (OhP 1%QhR  ShT +DUhV *5WhX +EYhZ &u[h\ #E]h^ *4_h` $Uahb "5chd *5ehf +Egh h hh #Eihj ukhl  mhn %eohp +Eqhr sht !%uhv  whx dyhz $T{h| +E}h~ %eh@ !%AhB "4ChD dEhF !$GhH "5Ih h hJ tKhL #DMhN  OhP 'QhR $UShT !$UhV *5WhX (YhZ %e[h\ )%]h^ u_h` tahb chd Tehf tghh "5ihj #Ekh h hl %emhn &uohp 'qhr $Usht !$uhv "5whx #Eyhz +E{h| }h~ uh@ uAhB UChD  EhF "5GhH $IhJ DKhL DMh hN dOh hT   jLM 
 QQ  .E $  "A!1 $Q -a	
 %a .q 6q ? 5a 3A 5a =a CA *1 8  4Q!" +A#$ 4Q% .#Q+Q .q .q	
 >q 21 5a J1 Ma H KA G $Q ,Q .q  DQ!" ,Q#$ 78+,/089KL45=>/06701)*67;<=  B &'&'/012*+89;<01)**+ C- -/E EN !&"&!..w77!..w77  ' #$+0  " 
 #*G$ %)    $&+(,,0,1).+06:#'#'"&#(	( ( #($)$)+027/4#()$ $, %)&+!$$&*/%'& & ',#($)*/	# # ',!$$&%'#($)*/$ $ ',!$$&%'#($)*/( ( ',!$$&%'#($)*/5 5 ',!$$%,-%&#($)*/	* 	* ',!$$%%&#($)*/, ,  #iW Wr y
 "9  $	  "9  $	 Eh hTNNN )N *	N
 *N *N JN JN JN JN JN MN JN JN JN  I!N" /#N N$ /%N& J'N( L)N* -+N, J-N. J/N0 J1N2 ,3N4 -5N6 L7N8 L9N: -;N< M=N> ,?N@ -ANB -CND -EN N NF ,GNH JINJ JKNL ,MNN -ONP -QNR -SNT -UNV -WNX -YNZ -[N\ J]N^ ,_N` LaNb McNd LeNf LgN N Nh LiNj LkNl LmNn MoNp MqNr MsNt MuNv NwNx JyNz J{N| -}N~ -N@ -ANB LCND LENF NGNH JIN NJ 0)*&&&**)[N N N` 6@,?*4&/	 aV Vc
hB
 hB
 h h h	    c                 h   K   |                      |           d{V }|                     |d          S )ae  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#tag--time

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        N	timestamp)publicGetV1Timesafe_integerrN  paramsresponses      rP  
fetch_timezbullish.fetch_time  sE       --f55555555   ;777rQ  c                   K   |                      |           d{V }i }t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                     |d          }|                     |d          }	|||ddd|                     |d          |                     |                     |	                    dddddddi d	|d
||<   |S )a-  
        fetches all available currencies on an exchange

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/assets

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        Nr   symbolr=  	precisionminFeeminmax)amountr   crypto)r<  coder=  activerL   r   feer\  limitsr   typeinfo)publicGetV1Assetsrangelensafe_stringsafe_currency_codesafe_numberrM  parse_precision)
rN  rW  rX  resulticurrencyr<  rc  r=  r\  s
             rP  fetch_currencieszbullish.fetch_currencies  s7      //77777777Z q#h--(( 	 	A{H!!(H55B**2..D##Hf55D((;??I ''(;;!..t/C/CI/N/NOO&*488(,T : :     F4LL" rQ  c                    K   | j         d         r|                                  d{V  |                     |           d{V }|                     |          S )a+  
        retrieves data on all markets for ace

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/markets

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r   N)rG  load_time_differencepublicGetV1Marketsparse_marketsrV  s      rP  fetch_marketszbullish.fetch_markets/  su       <12 	.++---------0088888888!!(+++rQ  marketc                 	   |                      |d          }|                      |d          }|                      |d          }|                     |          }|                     |          }|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}d}|                     |d          }!n|                     |d          }|d|z   z  }||k    }| }|dk    rd}n|                      |d          }|                    d          }"|                      |"d          }#|d|#z   z  }|dk    rd}n||dk    rvd}|                     |d          }|                     |                      |d                    } |d|                     |           z   dz   |                      |"d           z   z  }| 	                    i d!|d|d"|d#|d$|d%|d&|d'|d(|d|d)|!d|d|d|d*|d+|d,|| j
        d-         d.         | j
        d-         d/         ||                     |          || ||                     |          |                     |          d0|                     |          |                     |          d0|                     |          |                     |          d0d d d0d1|                     |                     |
                    |                     |                     |                    |                     |                     |                    |                     |                     |                    |                     |                     |	                    d2|                     |d3          d |d4          S )5Nr[  
baseSymbolquoteSymbol/basePrecisionquotePrecisionquantityPrecisionpricePrecisioncostPrecisionminQuantityLimitmaxQuantityLimitminPriceLimitmaxPriceLimitminCostLimitmaxCostLimitsettlementAssetSymbol
marketTyper8   FTmarginTradingEnabledcontractMultiplier:r:   expiryDatetime-   r;   r<   
optionTypeoptionStrikePrice   r<  basebaseIdquotequoteIdsettlesettleIdrg  r9   contractr   r   r   r   r   r^  )ra  pricecostr   )ra  r  r  r  r  marketEnabled)r   r   contractSizeexpiryr  striker  rf  r\  rd  createdrh  )rl  rm  parse_market_type	safe_boolrn  splitsafe_string_lowerparse_to_numericnumber_to_stringsafe_market_structurerE  	parse8601rM  ro  )$rN  ry  r<  r  r  r  r  r[  r~  r  amountPrecisionr  r  r  r  r  r  r  r  r  r  rg  r8   r:   r;   r<   r  r   r   r  r  r  r  r9   idPartsdateParts$                                       rP  parse_marketzbullish.parse_market=  s   p fh//!!&,77""6=99&&v..''00e#((AA))&2BCC**63FGG))&2BCC((AA++F4FGG++F4FGG((AA((AA''??''??##F,CDD((22%%d&6&6v|&L&LfUU" 
6>>DH^^F,BCCFF++F4HIILcFl"Fu_F jGv~~!%!1!1&:J!K!K((3--++GQ77#.(8##!FFX%%!F!%!7!7!M!MJ!2243C3CFL_3`3`aaFcD$9$9&$A$AACG$JZJZ[bdeJfJfffF)) 5+
"5+
f5+
 D5+
 f	5+

 U5+
 w5+
 f5+
 5+
 D5+
 D5+
 f5+
 D5+
 f5+
 f5+
 5+
  f!5+
" w#5+
$ Yy)'2Yy)'2(nn^44,$  ,,-=>>,,-=>> 
  ,,];;,,];; 
  ,,\::,,\:: 
    & ++D,@,@,Q,QRR**4+?+?+O+OPP))$*>*>}*M*MNN))$*>*>}*M*MNN**4+?+?+O+OPP  nnV_==i5+
 5+
 5+
 5 5 5	rQ  Nrg  defaultTypec                 >    ddddd}|                      |||          S )Nr8   r:   r;   r<   )SPOT	PERPETUALDATED_FUTUREOPTIONrl  )rN  rg  r  typess       rP  r  zbullish.parse_market_type  s4    $	
 
 t[999rQ  r[  r   c           	      8  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |d          }|                     |||dddd          S )	ay  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/markets/-symbol-/orderbook/hybrid

        :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(not used by bullish)
        :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
        Nr[  r<  rS  bidsasksr  priceLevelQuantity)load_marketsry  'publicGetV1MarketsSymbolOrderbookHybridextendrU  parse_order_book)rN  r[  r   rW  ry  requestrX  rS  s           rP  fetch_order_bookzbullish.fetch_order_book  s       !!!!!!!!!V$$fTl
 EEdkkRY[aFbFbcccccccc( %%h<<	$$Xvy&&RY[oppprQ  sincec                   K   |                                   d{V  d}d}|                     |dd          \  }}|r7|                     d||          }|                     d|||||           d{V S |                     |          }d|d         i}|                     ||          }||                     |          |d	<   |                     |                     ||                     d{V }	| 	                    |	|||          S )
a  
        get the list of most recent trades for a particular symbol

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/markets/-symbol-/trades
        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/history/markets/-symbol-/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(max 100)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest trade to fetch
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=public-trades>`
        Nr   Fre   paginater   r[  r<  	_pageSize)
r  handle_option_and_paramshandle_pagination_paramsfetch_paginated_call_dynamicry  handle_since_and_untilget_closest_limit%publicGetV1HistoryMarketsSymbolTradesr  parse_trades)
rN  r[  r  r   rW  maxLimitr  ry  r  rX  s
             rP  fetch_tradeszbullish.fetch_trades  sO      !!!!!!!!!88AZ\fgg& 	r22=%PPF::=&RWY^`fhpqqqqqqqqqV$$fTl
 ,,UF;;#'#9#9%#@#@GK CCDKKPWY_D`D`aaaaaaaa    65%@@@rQ  c                 ,  K   t          j        |                                 |                                 g  d{V  |                     |           d{V }d|i}d}| |                     |          }|d         |d<   |                     |d          }d}	|0|                     |                     ||                     d{V }	nd}
| 	                    |dd          \  }
}|
r7| 
                    d||          }|                     d||||d	           d{V S |                     ||          }||                     |          |d
<   |                     |                     ||                     d{V }	|                     |	|||          S )aU  
        fetch all trades made by the user

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/history/trades

        :param str [symbol]: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch trades for
        :param str [params.orderId]: the order id to fetch trades for
        :param str [params.clientOrderId]: the client order id to fetch trades for
        :param str [params.tradingAccountId]: the trading account id to fetch trades for
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Nr   r<  r[  clientOrderIdFrq   r  r   r  )asynciogatherr  handle_tokenload_accountry  rl  ,privateGetV1TradesClientOrderIdClientOrderIdr  r  r  r  r  r  privateGetV1HistoryTradesr  )rN  r[  r  r   rW  r   r  ry  r  rX  r  s              rP  fetch_my_tradeszbullish.fetch_my_trades  s       nt0022D4E4E4G4GHIIIIIIII!%!2!26!:!::::::: 0
 [[((F &tGH((AA$!NNt{{[bdjOkOkllllllllHHH#<<V_V`aaHf s66vVV!>>PVX]_dflnqrrrrrrrrr00??F '+'='=e'D'D$* ";;DKKQW<X<XYYYYYYYYH  65%@@@rQ  r<  c                    K   |                                   d{V  |                     |d          }||                     d|i|          }|                     ||||           d{V S )a  
        fetch all the trades made from a single order

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/history/trades

        :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
        :param str [params.clientOrderId]: the client order id to fetch trades for
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Nr  orderId)r  rl  r  r  )rN  r<  r[  r  r   rW  r  s          rP  fetch_order_tradeszbullish.fetch_order_trades  s       !!!!!!!!!((AA [[)R&99F))&%GGGGGGGGGrQ  tradec                    |                      |d          }|                     ||          }|d         }|                     |d          }|                      |d          }|                      |d          }|                     |d          }|                     |d          }	|d         }
|                     |
          }|                     |d          }d }|||d	}d }|	rd
}nd}|                      |d          }|                     |||                     |          ||                      |d          |d ||||d |d|          S )Nr[  createdAtTimestampr  quantitysideisTakerr  quoteFee)rr  r  r   r   r  tradeId)rh  rS  datetimer[  r<  orderrg  takerOrMakerr  r  ra  r  re  )	rl  safe_marketrU  r  r  rm  rn  
safe_tradeiso8601)rN  r  ry  marketIdr[  rS  r  ra  r  r  rr  rc  feeCostre  r  r  s                   rP  parse_tradezbullish.parse_trade3  s   d ##E844!!(F33!%%e-ABB	  00!!%44%%eV44..	22'?&&x00""5*55#W55C 	#"LL"L""5)44"Y//""5)44( 
  
   	rQ  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://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/markets/-symbol-/tick

        :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[  r<  )r  ry  publicGetV1MarketsSymbolTickr  parse_tickerrN  r[  rW  ry  r  rX  s         rP  fetch_tickerzbullish.fetch_ticker  s       !!!!!!!!!V$$fTl
 ::4;;wPV;W;WXXXXXXXXN   6222rQ  tickerc           	         |                      |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|          S )Nr[  r  rS  r  highlowbidbestBid	bidVolumeaskbestAsk	askVolumevwapopencloselastpreviousClosechanger   average
baseVolumequoteVolume	markPrice)r   r  r  rh  )rl  r  rU  safe_tickerr  safe_string_2)rN  r  ry  r  rS  s        rP  r  zbullish.parse_ticker  sa   N ##FH55!!(F33%%f.BCC	 !
fX&!
!
 Y//!
 D$$VV44	!

 4##FE22!
 4%%feY??!
 ))&+>>!
 4%%feY??!
 ))&+>>!
 D$$VV44!
 D$$VV44!
 T%%fg66!
 D$$VV44!
 T!
 d&&vx88!
  $**6<@@!!
" t''	::#!
$ **6<@@++FMBB))&+>>+!
 !
 !
, -  	rQ  method	timeframec                   K   d }|                      ||dd          \  }}d}|                     |d          }||k    r	 |r)|dk    r# t          | |          |||||           d {V S  t          | |          ||||           d {V S # t          $ r.}	t	          |	t
                    r|	|dz  }||k    r|	Y d }	~	nd }	~	ww xY w||k    g S )N
maxRetries   r   untilre   r   )r  omitgetattr	Exception
isinstancer,   )
rN  r  r[  r  r   r  rW  r  errorses
             rP  safe_deterministic_callzbullish.safe_deterministic_call  sE     
!::66<YZ[[
F67++ 
""
 U+D!D!D!6v!6!6vy%QVX^!_!________!6v!6!6vueV!T!TTTTTTTT   a!233 G!J&&G '&&&&	 
"" 	s   *B *!B 
C$B??Cr   c           	      <  K   |                                   d{V  |                     |          }d}d}|                     |dd          \  }}|r!|                     d||||||           d{V S |d         |                     | j        ||          |d}	|                     d|	|          \  }	}|                     |	d          }
|                     |          }d	|z  |z  }|}||
| 	                                }
|
|z
  }n ||
|z
  }n|
| 
                    ||          }
|                     |          |	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://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/markets/-symbol-/candle

        :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(max 100)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest entry
        :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
        Nr   Frr   r  r<  )r[  
timeBucketr  createdAtDatetime[lte]r   createdAtDatetime[gte])r  ry  r  "fetch_paginated_call_deterministicrl  rC  handle_until_optionrU  parse_timeframemillisecondssumr  publicGetV1MarketsSymbolCandler  parse_ohlcvs)rN  r[  r  r  r   rW  ry  r  r  r  r
  durationmaxDelta	startTimerX  s                  rP  fetch_ohlcvzbullish.fetch_ohlcv  s      !!!!!!!!!V$$88zZZ& 	B@@vW\^cenpv  yA  B  B  B  B  B  B  B  B  BTl**4?IyQQ!
 

 223KWV\]]!!'+CDD''	22(?X-	%%''E(II(II]HHY11E,0LL,C,C(),0LL,?,?()<<T[[RX=Y=YZZZZZZZZ   69eUKKKrQ  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr  r  r  r  r  volume)rU  rn  )rN  ohlcvry  s      rP  parse_ohlcvzbullish.parse_ohlcvS  s    e%9::UF++UF++UE**UG,,UH--
 	
rQ  c           	        K   |t          | j        dz             |                                  d{V  d}d}|                     |dd          \  }}|r7|                     d||          }|                     d|||||           d{V S |                     |          }|d         st          | j        dz             d	|d
         i}||                     |          |d<   | 	                    ||dd          }| 
                    |                     ||                     d{V }	g }
|                     |	          }t          dt          |                    D ]b}||         }|                     |d          }|
                    |||                     |d          |                     |          |d           c|                     |
d          }|                     ||d	         ||          S )a  
        fetches historical funding rate prices

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/history/markets/-symbol-/funding-rate

        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: not sent to exchange api, exchange api always returns the most recent data, only used to filter exchange response
        :param int [limit]: the maximum amount of funding rate structures to fetch
        :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   Fre   r  r:   z5 fetchFundingRateHistory() supports swap markets onlyr[  r<  r  zupdatedAtDatetime[gte]zupdatedAtDatetime[lte]r   updatedAtDatetimefundingRate)rh  r[  r'  rS  r  rS  )r    r<  r  r  r  r  ry  r!   r  r  *publicGetV1HistoryMarketsSymbolFundingRater  to_arrayrj  rk  rl  appendrn  r  sort_byfilter_by_symbol_since_limit)rN  r[  r  r   rW  r  r  ry  r  rX  ratesrp  rq  entryr  sorteds                   rP  fetch_funding_rate_historyz"bullish.fetch_funding_rate_history]  sV      >#DG.e$efff!!!!!!!!!88AZ\fgg& 	~223LeU[\\F::;TV\^cejlrt|}}}}}}}}}V$$f~ 	`TW'^^___fTl
 #'#9#9%#@#@GK ,,UF<TVnooHHU\^dIeIeffffffff x((q#f++&& 		 		A1IE''/BCCHLL #//}EE!^^H55$      e[11009I5RWXXXrQ  c                 t  K   t          j        |                                 |                                 g  d{V  |                     |           d{V }|                     |dd          }|r7|                     d||          }|                     d||||d           d{V S d}d|i}| |                     |          }|d         |d<   | 	                    ||          }|| 
                    |          |d	<   d
}	|                     |dd|	          \  }	}d}
|	dk    r0|                     |                     ||                     d{V }
nM|	d
k    r0|                     |                     ||                     d{V }
nt          | j        dz             |                     |
|||          S )aK  
        fetches information on multiple orders made by the user

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#tag--orders
        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#tag--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 order structures to retrieve(5, 25, 50, 100, default is 25)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest order to fetch
        :param str [params.tradingAccountId]: the trading account id(mandatory parameter)
        :param str [params.orderId]: the id of the order to fetch for
        :param str [params.clientOrderId]: the client id of the order to fetch for
        :param str [params.status]: filter by order status, 'OPEN', 'CANCELLED', 'CLOSED', 'REJECTED'
        :param bool [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>`
        Nr  Fr{   r   r   r<  r[  r  privateGetV2HistoryOrdersr  privateGetV2Orderszb fetchOrders() method parameter must be either "privateGetV2Orders" or "privateGetV2HistoryOrders")r  r  r  r  r  r  r  r  ry  r  r  r  r3  r  r2  r!   r<  parse_orders)rN  r[  r  r   rW  r   r  ry  r  r  rX  s              rP  fetch_orderszbullish.fetch_orders  s+     & nt0022D4E4E4G4GHIIIIIIII!%!2!26!:!:::::::>>&*e<< 	m22=%PPF::=&RWY^`fhklllllllll 0
 [[((F &tGH,,UF;;#'#9#9%#@#@GK ,66v}hX^__)))< "44T[[&5Q5QRRRRRRRRHH222!;;DKKQW<X<XYYYYYYYYHHTW  (L  L  M  M  M  65%@@@rQ  rW  c                 B   d}|                                  }||z
  }|#||k     rt          | j        dz   |z   dz             |                     |d          }|                     |ddi          }|                     |d          }||                     |d|i          }|S )N    X  z9() only allows fetching entries up to 90 days in the pastr  paginationDirectionbackwardr
  )r  r!   r<  r  r  rU  )rN  r  r  rW  
ninetyDaysnowallowedSincer
  s           rP  r  z bullish.handle_pagination_params  s    -
!!Z'EL$8$8TWs]V36qqrrr6:..V&;Z%HII!!&'22=[['388FrQ  r  r  sinceKeyuntilKeyc                 J   |                      |d          }||d}|||z
  }|                     |d          }n4|2|                     ||          }|                                 }||k    r|}|                     |          }|                     |          }	|||<   |	||<   |S )Nr
  i $)rU  r  r  r  r  )
rN  r  rW  r>  r?  r
  	timeDeltar<  	sinceDate	untilDates
             rP  r  zbullish.handle_since_and_until  s    !!&'225#4/I}	)6733	22''))3;;EU++IU++I(F8(F8rQ  c                 V    d}|dk    r	|dk     rd}n|dk    r	|dk     rd}n|dk    rd}|S )Nr         3   2   r    )rN  r   pageSizes      rP  r  zbullish.get_closest_limit  sJ    AIIEBJJHHbjjurzzHHRZZHrQ  c           	      r   K   ddi}|                      ||||                     ||                     d{V S )a  
        fetch all unfilled currently open orders

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#tag--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 order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str params['tradingAccountId']: the trading account id(mandatory parameter)
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        statusOPENNr5  r  rN  r[  r  r   rW  r  s         rP  fetch_open_orderszbullish.fetch_open_orders  sQ       f
 &&vueT[[RX=Y=YZZZZZZZZZrQ  c           	      t   K   ddd}|                      ||||                     ||                     d{V S )a  
        fetches information on multiple canceled orders made by the user

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#tag--orders

        :param str symbol: unified market symbol of the canceled orders
        :param int [since]: timestamp in ms of the earliest order
        :param int [limit]: the max number of canceled orders to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.tradingAccountId]: the trading account id(mandatory parameter)
        :returns dict: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        	CANCELLEDr3  rL  r  NrN  rO  s         rP  fetch_canceled_orderszbullish.fetch_canceled_orders  sW       "*
 
 &&vueT[[RX=Y=YZZZZZZZZZrQ  c           	      t   K   ddd}|                      ||||                     ||                     d{V S )a  
        fetches information on multiple closed orders made by the user

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#tag--orders

        :param str symbol: unified market symbol of the closed orders
        :param int [since]: timestamp in ms of the earliest order
        :param int [limit]: the max number of closed orders to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str params['tradingAccountId']: the trading account id(mandatory parameter)
        :returns dict: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        CLOSEDr3  rS  NrN  rO  s         rP  fetch_closed_orderszbullish.fetch_closed_orders0  sW       *
 
 &&vueT[[RX=Y=YZZZZZZZZZrQ  c           	      t   K   ddd}|                      ||||                     ||                     d{V S )a  
        fetches information on multiple canceled orders made by the user

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#tag--history

        :param str symbol: unified market symbol of the closed orders
        :param int [since]: timestamp in ms of the earliest order
        :param int [limit]: the max number of closed orders to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.tradingAccountId]: the trading account id(mandatory parameter)
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        rV  r2  rS  NrN  rO  s         rP   fetch_canceled_and_closed_ordersz(bullish.fetch_canceled_and_closed_ordersC  sW       1
 
 &&vueT[[RX=Y=YZZZZZZZZZrQ  c                 v  K   t          j        |                                 |                                 g  d{V  |                     |           d{V }d}||                     |          }||d}|                     |                     ||                     d{V }|                     ||          S )a   
        fetches information on an order made by the user

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v2/orders/-orderId-

        :param str id: the order id
        :param str [symbol]: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.traidingAccountId]: the trading account id(mandatory parameter)
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        N)r  r   )	r  r  r  r  r  ry  privateGetV2OrdersOrderIdr  parse_orderrN  r<  r[  rW  r   ry  r  rX  s           rP  fetch_orderzbullish.fetch_orderV  s       nt0022D4E4E4G4GHIIIIIIII!%!2!26!:!:::::::[[((F 0
 
 77GV8T8TUUUUUUUU8 &111rQ  r  ra  r  c                   K   t          j        |                                 |                                 g  d{V  |                     |           d{V }|                     |          }d|d         |                                |                     ||          |d}	|dk    p|dk    }
d}|                     |
|dk    |          \  }}|rd}d	}| 	                    |d
d|          \  }}|                                |d<   |
s| 
                    ||          |	d<   |                     |d          }|J|
rt          | j        dz             | 
                    ||          |	d<   d}|                     |d          }|                                |	d<   |                     |                     |	|                     d{V }|                     ||          S )a  
        create a trade order

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#post-/v2/orders

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit' or 'STOP_LIMIT' or 'POST_ONLY'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.clientOrderId]: a custom client order id
        :param float [params.triggerPrice]: the price at which a stop order is triggered at
        :param str [params.timeInForce]: the time in force for the order, either 'GTC'(Good Till Cancelled) or 'IOC'(Immediate or Cancel), default is 'GTC'
        :param bool [params.allowBorrow]: if True, the order will be allowed to borrow assets to fulfill the order(default is False)
        :param bool [params.postOnly]: if True, the order will only be posted to the order book and not executed immediately(default is False)
        :param str params['traidingAccountId']: the trading account id(mandatory parameter)
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        NV3CreateOrderr<  )commandTyper[  r  r  r   ry  MARKETF	POST_ONLYGTCrI   r   r  r   z5 createOrder() does not support market trigger orders	stopPrice
STOP_LIMITrg  )r  r  r  r  r  ry  upperamount_to_precisionhandle_post_onlyr  price_to_precisionrl  r+   r<  r  privatePostV2Ordersr  r\  )rN  r[  rg  r  ra  r  rW  r   ry  r  isMarketOrderpostOnlyr   r   rX  s                  rP  create_orderzbullish.create_order  s"     ( nt0022D4E4E4G4GHIIIIIIII!%!2!26!:!:::::::V$$*TlJJLL00@@ 0
 
 (*?tx/?00@SU[\\& 	D";;FMS`bmnnV + 1 1 3 3} 	F#66vuEEGG''??# f"47-d#deee#'#:#:6<#P#PGK DYYv~66F**,,11$++gv2N2NOOOOOOOO &111rQ  c                   K   t          j        |                                 |                                 g  d{V  |                     |           d{V }|                     |          }	d|	d         |d}
|                     |d          }|||
d<   ||                                |
d<   |                     |dd	          }|r| 	                    |d          }d
|
d<   || 
                    ||          |
d<   ||                     ||          |
d<   |                     |                     |
|                     d{V }|                     ||	          S )aF  
        edit a trade limit order

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#post-/v2/command-amend

        :param str id: order id
        :param str [symbol]: unified symbol of the market to create an order in
        :param str [type]: 'limit' or 'POST_ONLY'
        :param str [side]: not used by bullish editOrder
        :param float [amount]: how much of the currency you want to trade in units of the base currency
        :param float [price]: the price for the order, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.traidingAccountId]: the trading account id(mandatory parameter)
        :param bool [params.postOnly]: if True, the order will only be posted to the order book and not executed immediately(default is False)
        :param str [params.clientOrderId]: a unique identifier for the order, automatically generated if not sent
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        NV1AmendOrderr<  )ra  r[  r   r  r  rg  rm  Frc  r  r  )r  r  r  r  r  ry  rl  rg  r  r  rh  rj  privatePostV2Commandr  r\  )rN  r<  r[  rg  r  ra  r  rW  r   ry  r  r  rm  rX  s                 rP  
edit_orderzbullish.edit_order  s     $ nt0022D4E4E4G4GHIIIIIIII!%!2!26!:!:::::::V$$)Tl 0
 

 ((AA !#GI"jjllGFO>>&*e<< 	*YYvz22F)GFO"&":":66"J"JGJ#66vuEEGG224;;w3O3OPPPPPPPP&111rQ  c                   K   t          j        |                                 |                                 g  d{V  |                     |           d{V }|t          | j        dz             |                     |          }|d         ||                     |dd          |d}| 	                    | 
                    ||                     d{V }|                     ||          S )as  
        cancels an open order

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#post-/v2/command-cancellations

        :param str [id]: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str params['commandType']: the command type, default is 'V3CancelOrder'(mandatory parameter)
        :param str [params.traidingAccountId]: the trading account id(mandatory parameter)
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nz) cancelOrder() requires a symbol argumentr<  ra  V3CancelOrder)r[  r   ra  r  )r  r  r  r  r  r    r<  ry  rl  rq  r  r\  r]  s           rP  cancel_orderzbullish.cancel_order  s      nt0022D4E4E4G4GHIIIIIIII!%!2!26!:!:::::::>#DG.Y$YZZZV$$Tl 0++FM?SS	
 
 224;;w3O3OPPPPPPPP &111rQ  c                   K   t          j        |                                 |                                 g  d{V  |                     |           d{V }d|i}d}|&|                     |          }|d         |d<   d|d<   nd|d<   |                     |                     ||                     d{V }|g}|                     ||          S )a  
        cancel all open orders in a market

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#post-/v2/command-cancellations

        :param str [symbol]: alpaca cancelAllOrders cannot setting symbol, it will cancel all open orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str params['traidingAccountId']: the trading account id(mandatory parameter)
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nr   r<  r[  V1CancelAllOrdersByMarketra  V1CancelAllOrders)	r  r  r  r  r  ry  rq  r  r4  )rN  r[  rW  r   r  ry  rX  orderss           rP  cancel_all_orderszbullish.cancel_all_orders  s      nt0022D4E4E4G4GHIIIIIIII!%!2!26!:!::::::: 0
 [[((F &tGH%@GM""%8GM"224;;w3O3OPPPPPPPP   000rQ  r  c                 v   |                      |d          }||                     |          }|                     ||          }|                      |d          }|                     |d          }|                      |d          }|                     |d          }|                      |d          }	|                      |d          }
|                      |d          }|                     |                      |d	                    }|d
k    r|                      |d          }|dk    rd}|                      |d          }|                      |d          }|                      |d          }i }|                     |d          }|||d<   |d         |d<   |                      |d          }|                     i d|d|                      |d          d|d|                     |          dd d	|d|d| 	                    |          d|d|dk    d|d|	d|d|
d|d d d|d |||d!|          S )"Nr[  r  r  rg  r  r  r  quantityFilledrL  closedstatusReasonzUser cancelledcanceledr   re  quoteAmountr  r  r  rr  averageFillPricer<  r  rS  r  lastTradeTimestamprm  rc  r   ra  filled	remaining)tradesre  rh  r  )
rl  r  safe_symbolrU  r  parse_order_statusrn  
safe_orderr  parse_order_type)rN  r  ry  r  r[  r<  rS  rg  r  r  ra  r  rL  r~  r   re  r  re  r  r  s                       rP  r\  zbullish.parse_order2  s   d ##E844>%%h//F!!(F33eY//%%e-ABB	v..%%eV44  00!!%44!!%)9::(()9)9%)J)JKKX++E>BBL///#&&um<<$$UK88	}55##E:66"CK$WoC
O""5*<==  
" 
T--e_EE 
  
 Y//	 

 !$ 
 f 
 f 
 D))$// 
 ; 
 + 
 D 
 U 
 I 
 f 
 f 
  ! 
" D# 
$ + 
  
  
, -  	rQ  rL  c                 >    ddddd}|                      |||          S )Nr  r}  r  rejected)rM  rV  rR  REJECTEDr  rN  rL  statusess      rP  r  zbullish.parse_order_status  s4    #"	
 
 &&999rQ  c                 >    ddddd}|                      |||          S )Nr   ry  )LMTMKTrc  rf  r  rN  rg  r  s      rP  r  zbullish.parse_order_type  s4     !	
 
 tT222rQ  rc  c                 4  K   t          j        |                                 |                                 g  d{V  i }|                     d||          \  }}|                     |d          }||                     |          |d<   ||                     |          |d<   |                     |                     ||                     d{V }| 	                    |dg           }d}	|| 
                    |          }	|                     ||	||          S )a  
        fetch history of deposits and withdrawals

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/wallets/transactions

        :param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
        :param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
        :param int [limit]: max number of deposit/withdrawals to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `transaction structure <https://docs.ccxt.com/?id=transaction-structure>`
        Nr  r  data)r  r  r  r  r  rU  r  privateGetV1WalletsTransactionsr  	safe_listrr  parse_transactions)
rN  rc  r  r   rW  r  r
  rX  r  rr  s
             rP  fetch_deposits_withdrawalsz"bullish.fetch_deposits_withdrawals  s8      nt0022D4E4E4G4GHIIIIIIII223KWV\]]!!'+CDD04U0C0CG,-04U0C0CG,-==dkk'SY>Z>Z[[[[[[[[F ~~h33}}T**H&&tXueDDDrQ  addresstagc                   K   t          j        |                                 |                                 g  d{V  |                     |          }dd||d         |                     ||          di}d}|                     |          \  }}||                     |          |d<   nt          | j	        dz             | 
                    |                     ||                     d{V }	|                     |	|          S )a  
        make a withdrawal

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#post-/v1/wallets/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['timestamp']: the timestamp of the withdrawal request(mandatory)
        :param str params['nonce']: the nonce of the withdrawal request(mandatory)
        :param str params['network']: network for withdraw(mandatory)
        :returns dict: a `transaction structure <https://docs.ccxt.com/?id=transaction-structure>`
        Ncommand
V1Withdrawr<  )ra  destinationIdr[  r  networkz( withdraw() requires a network parameter)r  r  r  r  rr  currency_to_precisionhandle_network_code_and_paramsnetwork_code_to_idr    r<  privatePostV1WalletsWithdrawalr  parse_transaction)
rN  rc  ra  r  r  rW  rr  r  networkCoderX  s
             rP  r   zbullish.withdraw  s+       nt0022D4E4E4G4GHIIIIIIII==&&+!("4. 66tVDD	 
  "AA&IIV"!%!8!8!E!EGI#DG.X$XYYY<<T[[RX=Y=YZZZZZZZZ %%h999rQ  transactionrr  c                 D   |                      |d          }|                      |d          }|                     |                      |d                    }|                     |                      |d                    }|                      |d          }|                     |d          }|                      |d          }	|                      |d          }
|                     |d	          }|                      |d
          }|                     ||          }|                      |d          }|                     |dg           }|                     |di           }|                      |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 ) NcustodyTransactionId	directioncreatedAtDateTimeupdatedAtDateTimer  transactionDetailsblockchainTxIdr  r  r[  rL  sourcesr   )rr  r  ratere  r  rr  r<  txidrS  r  addressFrom	addressTora  rg  updatedtagFromr  tagTocomment)internalre  rh  )
rl  r  	safe_dictrn  rm  r  r  network_id_to_codeparse_transaction_typeparse_transaction_status)rN  r  rr  r<  rg  rS  r  r  r  r  r  ra  
currencyIdrc  rL  r  sourcesourceAddressre  r  s                       rP  r  zbullish.parse_transaction  s   4 k+ABB[99NN4#3#3KAT#U#UVV	..!1!1+?R!S!STT"";	::!^^K9MNN 24DEE""#5yAA!!+z::%%k8<<
&&z8<<!!+x88..!3YCCB//((;;
 

 "";66!CK"C
O
"
D
 
 Y//	

 t..w77
 =
 w
 
 f
 D//55
 
 d33F;;
 w
 t
 4
  T!
" t#
$ )
 
 
 	
rQ  c                 :    ddd}|                      |||          S )NrL   
withdrawal)DEPOSITWITHDRAWr  r  s      rP  r  zbullish.parse_transaction_type[  s.     $
 
 tT222rQ  c                 >    ddddd}|                      |||          S )Nokfailedpendingr  )COMPLETEFAILEDPENDINGrR  r  r  s      rP  r  z bullish.parse_transaction_statusb  s4     #	
 
 &&999rQ  c                 z  K   d }|                      |dd          \  }}|w|                     |           d {V }t          dt          |                    D ]>}||         }|                     |d          }|dk    r|                     |d          } n?|t          | j        dz             || j        d<   |S )Nrq   r   r   tradingAccountNamezPrimary Accountz loadAccount() requires a tradingAccountId parameter in options["tradingAccountId"] or params["tradingAccountId"], fetchAccounts() was not able to find the Primary account)r  #privateGetV1AccountsTradingAccountsrj  rk  rl  r    r<  rG  )rN  rW  r   rX  rq  accountr=  s          rP  r  zbullish.load_accountk  s       $#'#@#@Zl#m#m &#!EEfMMMMMMMMH1c(mm,,  "1+''1EFF,,,'+'7'7AS'T'T$E - ##DG  /\  %\  ]  ]  ]+;'(rQ  c                    K   t          j        |                                 |                                 g  d{V  |                     |           d{V }|                     ||          S )a|  
        fetch all the accounts associated with a profile

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#tag--trading-accounts

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `account structures <https://docs.ccxt.com/?id=account-structure>` indexed by the account type
        N)r  r  r  r  r  parse_accountsrV  s      rP  fetch_accountszbullish.fetch_accounts{  s       nt0022D4E4E4G4GHIIIIIIIIAA&IIIIIIII` ""8V444rQ  r  c                 8    |                      |d          d d |dS )Nr   )r<  rg  rc  rh  r  )rN  r  s     rP  parse_accountzbullish.parse_account  s.    ""7,>??	
 
 	
rQ  c                   K   t          j        |                                 |                                 g  d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |          }t          |          }| 	                    |di           }d}	| 
                    |          \  }	}|	du}
|dk    s|
r|	|                     |          }	|	pt          dt          |                    D ]N}| 	                    ||i           }|                     |d          }|                     |          }|	|k    r|} nO|
ri }|                     ||          S )a  
        fetch the deposit address for a currency associated with self account

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/wallets/deposit-instructions/crypto/-symbol-

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network]: network for deposit address
        :returns dict: an `address structure <https://docs.ccxt.com/?id=address-structure>`
        Nr[  r<  r   r   r  )r  r  r  r  rr  2privateGetV1WalletsDepositInstructionsCryptoSymbolr  r)  rk  r  r  default_network_coderj  rl  r  parse_deposit_address)rN  rc  rW  rr  r  rX  safeResponselengthr  r  networkDefinedByUserrq  r.  	networkIdr  s                  rP  fetch_deposit_addresszbullish.fetch_deposit_address  s      nt0022D4E4E4G4GHIIIIIIII==&&htn
 PPQUQ\Q\]dflQmQmnnnnnnnn }}X..\""~~lAr22==fEE&d2QJJ0J33D99"q#l"3"344  A NN<B??E $ 0 0	 B BI"&"9"9)"D"DK+--$ . ( D))$999rQ  c                     |                      |d          }|                      |d          }||                     ||          |                     |          |                      |d          d dS )Nr[  r  r  )rh  rr  r  r  r  )rl  rm  r  )rN  depositAddressrr  r<  r  s        rP  r  zbullish.parse_deposit_address	  sx    nh77"">9=="//H==..w77''	BB
 
 	
rQ  c                 :  K   t          j        |                                 |                                 g  d{V  |                     |           d{V }d|i}d}|                     |d          }|c|                     |          d         |d<   |                     |                     ||                     d{V }| 	                    ||          S | 
                    |                     ||                     d{V }|                     |          S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/accounts/asset
        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/accounts/asset/-symbol-

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str params['tradingAccountId']: the trading account id(mandatory parameter)
        :param str [params.code]: unified currency code, default is None
        :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
        Nr   rc  r<  r[  )r  r  r  r  r  rl  rr  privateGetV1AccountsAssetSymbolr  !parse_balance_for_single_currencyprivateGetV1AccountsAssetparse_balance)rN  rW  r   r  rX  rc  s         rP  fetch_balancezbullish.fetch_balance	  sH      nt0022D4E4E4G4GHIIIIIIII!%!2!26!:!::::::: 0
 // $d 3 3D 9GH!AA$++gW]B^B^________H99(DIII!;;DKKQW<X<XYYYYYYYYH" %%h///rQ  c                     d|i}|                                  }|                     |d          |d<   |                     |d          |d<   |||<   |                     |          S )Nrh  availableQuantityfreelockedQuantityused)r  rl  safe_balance)rN  rX  rc  rp  r  s        rP  r  z)bullish.parse_balance_for_single_currencyG	  sj    ),,..**85HII**85EFFt  (((rQ  c                 p   d|i}t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |||<   |                     |          S )Nrh  r   assetSymbolr  totalr  r  )rj  rk  rl  rm  r  r  )rN  rX  rp  rq  balancer[  rc  r  s           rP  r  zbullish.parse_balanceO	  s    H
 q#h--(( 	# 	#AqkG%%g}==F**622DllnnG#//9LMMGG"..w8HIIGFO"F4LL  (((rQ  symbolsc                 r  K   t          j        |                                 |                                 g  d{V  |                     |           d{V }d|i}|                     |                     ||                     d{V }|                     ||          }|                     |d|d          S )a  
        fetch all open positions

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/derivatives-positions

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str params['tradingAccountId']: the trading account id
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/?id=position-structure>`
        Nr   r[  F)	r  r  r  r  r   privateGetV1DerivativesPositionsr  parse_positionsfilter_by_array_positions)rN  r  rW  r   r  rX  resultss          rP  fetch_positionszbullish.fetch_positions]	  s       nt0022D4E4E4G4GHIIIIIIII!%!2!26!:!::::::: 0
 >>t{{7TZ?[?[\\\\\\\\, &&x99--gx%PPPrQ  positionc                 ,   |                      |                     |d          |          }|d         }|                     |d          }|                     |d          }|                     i d|dd d|d|d|                     |          d|                     |d	          d
d d|                     |          d|                     |d          dd dd dd dd d|                     |d          dd dd dd d d d d d d d d d d d
          S )Nr[  r  r  rh  r<  rS  r  lastUpdateTimestampupdatedAtTimestampr   	contractsr  r  
entryPricer  	lastPricenotionalr   
collateralinitialMargin)
initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentageunrealizedPnlliquidationPricer   marginRatior   r   r   )r  rl  rU  safe_positionr  parse_position_sidern  )rN  r  ry  r[  rS  r  s         rP  parse_positionzbullish.parse_position	  s   , !!$"2"28X"F"FOO!%%h0DEE	&11!! #
H#
$#
 f#
 	#

 Y//#
 "4#4#4X?S#T#T#
 d#
 D,,T22#
 ))(J??#
 D#
 $#
 #
 #
 ((:>>#
 #
  $!#
" T##
$ (,!%+/! $!#7#
 #
 #
   	rQ  c                 :    ddd}|                      |||          S )Nlongshort)BUYSELLr  )rN  r  sidess      rP  r  zbullish.parse_position_side	  s.    
 
 tT222rQ  c                 (  K   t          j        |                                 |                                 g  d{V  |                     |           d{V }d}d}|                     |dd          \  }}|r7|                     d||          }|                     d|||||           d{V S d|i}d}	| |                     |          }	|	d         |d<   | 	                    |d	          }
|.|
,| 
                                }|                     |d	|i          }|                     ||          }||                     |          |d
<   |                     |                     ||                     d{V }|                     ||	||          S )a  
        fetch a history of internal transfers made on an account

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/history/transfer

        :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 transfers for(default time now)
        :param str params['tradingAccountId']: the trading account id
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/?id=transfer-structure>`
        Nr   Fr   r  r   r<  r  r
  r  )r  r  r  r  r  r  r  r  rr  rU  r  r  r  r  privateGetV1HistoryTransferparse_transfers)rN  rc  r  r   rW  r   r  r  r  rr  r
  r<  rX  s                rP  fetch_transferszbullish.fetch_transfers	  s      nt0022D4E4E4G4GHIIIIIIII!%!2!26!:!:::::::88AQS]^^& 	s223CUFSSF::;KTSXZ_agiqrrrrrrrrr 0
 "}}T**H%-d^GM"!!&'22M##%%C[['388F,,UF;;#'#9#9%#@#@GK 99$++gv:V:VWWWWWWWW" ##HhuEEErQ  fromAccount	toAccountc                   K   t          j        |                                 |                                 g  d{V  |                     |          }d|d         |                     ||          ||d}|                     |                     ||                     d{V }|                     | j	        di           }	| 
                    |	dd          }
|                     ||          }|
r||d<   ||d	<   ||d
<   ||d<   |S )uQ  
        transfer currency internally between wallets on the same account

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#post-/v1/command-commandType-V1TransferAsset

        :param str code: unified currency codeåå
        :param float amount: amount to transfer
        :param str fromAccount: account ID to transfer from
        :param str toAccount: account ID to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/?id=transfer-structure>`
        NV2TransferAssetr<  )ra  r  r  fromTradingAccountIdtoTradingAccountIdr   fillResponseFromRequestTr  r  ra  rr  )r  r  r  r  rr  r  rq  r  r  rG  r  parse_transfer)rN  rc  ra  r  r  rW  rr  r  rX  transferOptionsr  r   s               rP  r   zbullish.transfer	  s4      nt0022D4E4E4G4GHIIIIIIII==&&,#D>224@@$/"+
 
 224;;w3O3OPPPPPPPP ..z2FF"&..B[]a"b"b&&x::" 	(&1H]#$-H[!!'HX#'HZ rQ  c           
         |                      |d          }|                     |d          }|                     |d          }||                     |d          }|                     |d          ||                     |          |                     ||          |                     |d          |                     |d          |                     |d          |                     |          |d		S )
Nr  r  rL  message	requestIdr  r  r  )	r<  rS  r  rr  ra  r  r  rL  rh  )rU  rl  r  rm  rn  parse_transfer_status)rN  r   rr  rS  r  rL  s         rP  r  zbullish.parse_transfer%
  s    , %%h0DEE	%%h>>
!!(H55>%%h	::F""8[99"Y////
HEE&&x<<++H6LMM))(4HII0088

 

 
	
rQ  c                 >    ddddd}|                      |||          S )Nr  r  r  )rV  rM  r  z$Command acknowledged - TransferAssetr  r  s      rP  r  zbullish.parse_transfer_statusL
  s4     48	
 
 &&999rQ  c                   K   t          j        |                                 |                                 g  d{V  |                     |           d{V }|                     |          }|d         |d}|                                 }|}	|                     d||          \  }}|                     |d          }
|	|dz
  }	|
|}
| 	                    |	          |d<   | 	                    |
          |d<   | 
                    |                     ||                     d{V }|                     ||||          S )a  
        retrieves a history of a currencies borrow interest rate at specific time slots

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/history/borrow-interest

        :param str code: unified currency code
        :param int [since]: timestamp for the earliest borrow rate
        :param int [limit]: the maximum number of `borrow rate structures <https://docs.ccxt.com/?id=borrow-rate-structure>` to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int params['until']: the latest time in ms to fetch entries for
        :param str params['tradingAccountId']: the trading account id
        :returns dict[]: an array of `borrow rate structures <https://docs.ccxt.com/?id=borrow-rate-structure>`
        Nr<  )r  r   r  r7  r  )r  r  r  r  r  rr  r  r  rU  r  !privateGetV1HistoryBorrowInterestr  parse_borrow_rate_history)rN  rc  r  r   rW  r   rr  r  r<  startTimestampr
  rX  s               rP  fetch_borrow_rate_historyz!bullish.fetch_borrow_rate_historyU
  su      nt0022D4E4E4G4GHIIIIIIII!%!2!26!:!:::::::==&&#D> 0
 
 !!223KWV\]]!!'+CDD! #;;N=E,0LL,H,H(),0LL,?,?()??GU[@\@\]]]]]]]] --heUKKKrQ  c                     |                      |d          }|                     |d          }|                     ||          |                     |d          d||                     |          |dS )Nr  r  borrowedQuantity \&)rr  r  periodrS  r  rh  )rU  rl  rm  rn  r  )rN  rh  rr  rS  r  s        rP  parse_borrow_ratezbullish.parse_borrow_rate
  s}     %%d,@AA	%%dM::
//
HEE$$T+=>>"Y//
 
 	
rQ  c                 F    |                                  | j        d         z
  S )Nr   )r  rG  )rN  s    rP  get_timestampzbullish.get_timestamp
  s!      ""T\2B%CCCrQ  c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||          S )a  
        fetches the open interest of a specific market

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/markets/-symbol-/tick

        :param str symbol: unified symbol of the market to fetch the open interest for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `open interest structure <https://docs.ccxt.com/?id=ticker-structure>`
        Nr[  r<  )r  ry  r  r  parse_open_interestr  s         rP  fetch_open_interestzbullish.fetch_open_interest
  s       !!!!!!!!!V$$fTl
 ::4;;wPV;W;WXXXXXXXXN ''&999rQ  c                     |                      |d          }|                     ||                      |d          |d |                      |d          |                      |d          |d d|          S )NopenInterestr[  r  createdAtDatetime)rh  r[  openInterestAmountopenInterestValuerS  r  r   r  )rl  safe_open_interest)rN  interestry  r0  s       rP  r-  zbullish.parse_open_interest
  s    N ''.AA&&&&vx88".!%))(4HII((3FGG&	(
 	(
 	 	 		rQ  r   GETc                    |                      ||                     |                    }d|                     ||          z   }| j        d         |         |z   }	|dk    r|                                  t          |                                           }
t          |                                           }|dk    rb||
z   |z   dz   |z   }|                     | 	                    |          | 	                    | j
                  t          j        d          }||
|d}n|dk    r|                     |          }||
z   |z   dz   |z   |z   }|                     | 	                    |          d	d          }|                     | 	                    |          | 	                    | j
                  t          j        d          }||
|d
d}d
|d<   |                     |d          }|||d<   |dk    r| j        |d<   n(| j        }|t%          | j        dz             d|z   |d<   |dk    r,|                     |          }t+          |          r|	d|z   z  }	|	|||dS )Nr}  r   r   r6  z/trading-api/hex)BX-TIMESTAMPBX-NONCEBX-SIGNATUREPOSTsha256zapplication/json)r9  r:  r;  Content-Typer>  rateLimitTokenzBX-RATE-LIMIT-TOKENr   zBX-PUBLIC-KEYz- requires a token, please call signIn() firstzBearer Authorization?)urlr  bodyheaders)r  extract_paramsimplode_paramsrD  check_required_credentialsstrmicrosecondsr+  hmacencodesecrethashlibr=  jsonhashrl  apiKeytokenr   r<  	urlencoderk  )rN  pathr   r  rW  rD  rC  r  endpointrB  noncerS  payload	signaturedigestr?  rQ  querys                     rP  signzbullish.sign  s   ))FD$7$7$=$=>>,,T6:::is#h.)++---))++,,ED..0011I#e+f4FM IIdkk'&:&:DKK<T<TV]Vdfkll	$- %$- 
 6!!yy((#e+f4FMPTT4;;w#7#75II IIdkk&&9&94;;t{;S;SU\Ucejkk	$- %$-$6	  +='!%!1!1';K!L!L!-5CG12,,,+/;((
M-dg8g.ghhh+4u+<(U??NN7++E5zz #sU{"fdwOOOrQ  c                   K   |                      |           d{V }|                     |d          }|                     |d          }|| j        d<   || _        |                     |                                 d          | j        d<   |S )aF  
        sign in, must be called prior to using other authenticated methods

        https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#overview--add-authenticated-request-header

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns: response from exchange
        NrQ  
authorizerr'  tokenExpires)privateGetV1UsersHmacLoginrl  rG  rQ  r  r  )rN  rW  rX  rQ  r\  s        rP  sign_inzbullish.sign_in5  s       88@@@@@@@@   733%%h==
%/\"
'+xx0A0A0C0CEX'Y'Y^$rQ  c                    K   |                                  }| j        }|                     | j        d          }||||k    r|                                  d {V S | j        S )Nr]  )r  rQ  rU  rG  r_  )rN  rW  r<  rQ  r]  s        rP  r  zbullish.handle_tokenM  sq      !!
((~FFM|3|9K9K''''''':rQ  httpCodereasonrB  rD  rC  c
                    |d S |                      |d          }
|                      |d          }|
|
dk    r|
dk    s||dk    rd}|                      |d          }||}n|}| j        dz   |z   }|                     | j        d	         ||           |                     | j        d
         ||           |                     | j        d	         |
|           t          |          d S )N	errorCoderg  01001r6  r   errorCodeNamer8  r:  r;  )rl  r<  throw_exactly_matched_exceptionrI  throw_broadly_matched_exceptionr   )rN  ra  rb  rB  r  rD  rC  rX  requestHeadersrequestBodyrc  rg  r  rg  feedbacks                  rP  handle_errorszbullish.handle_errorsV  s   4 +66&11TEUZ^  cB  [B  [BG ,,XGGM('w}t+H001I7T\]]]001I7T\]]]001I4QYZZZ)))trQ  )N)^__name__
__module____qualname__r   rL  r   rY  r	   rs  r   r   rx  dictr  rH  r   r  r   r  r   r  r  r  r  r   r  r  r  listr   r$  r   r0  r   r5  r  r  r  rP  rT  rW  rY  r^  r   r   floatr   rn  rr  ru  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-  rZ  r_  r  intrm  __classcell__)rO  s   @rP  r0   r0       s4       i# i i i i i iV ') 8 8S 8 8 8 8$ -/ N N: N N N N` *, , ,V , , , ,D4 DF D D D DL
: :c : :s : : : : @DB %q %qS %q %qS\ %q %q %q %qN <@d[] -A -A -AS -A -Abfglbm -A -A -A -A^ 37TX\eg ;A ;AC ;As ;ARU ;Alpqvlw ;A ;A ;A ;Az ?CQUdhqs H H3 H H3 H^a Hx|  ~C  yD H H H H(T T Tv T T T T Tl 68 63 63 63F 63 63 63 63p@ @4 @ @6 @ @ @ @D HLZ^mq  EI  RT  C  TW gj   B    * 8<$]ajl 9L 9L 9LC 9LWZ 9Lquvzq{ 9L 9L 9L 9Lv
 
 
4 
 
 
 
 >BPTcgpr 8Y 8Ys 8Y# 8Y]` 8Yw{  }O  xP 8Y 8Y 8Y 8Yt 04$UYbd IA IA IAC IAs IAimnsit IA IA IA IAV BFVX  s 3 t ]a     37r[s  F^  C  UX   @C   cg    $s s     59tZ^gi [ [c [ [TW [nrsxny [ [ [ [$ 9=4^bkm [ [# [S [X[ [rvw|r} [ [ [ [& 7;\`ik [ [ [3 [VY [ptuzp{ [ [ [ [& DHVZimvx [ [S [PS [cf [  ~B  CH  ~I [ [ [ [& 8<B 12 12C 12 125 12 12 12 12f mqy{ 92 92 92I 92Y 92X] 92fi 92  AF 92 92 92 92v fjx|  FH (2 (23 (2 (29 (2I (2_b (2ru (2 (2 (2 (2T 9=R !2 !2S !2# !2E !2 !2 !2 !2F 59 1 1c 1U 1 1 1 1Ba a av a a a a aF: : : : :3S 3 3 3 3 <@daenp ;E ;ES ;E ;E[^ ;Euy  {F  vG ;E ;E ;E ;Ez QU]_ ,: ,:3 ,: ,: ,:# ,:do ,: ,: ,: ,:\G
 G
T G
X G
Q\ G
 G
 G
 G
R3 3 3:s : : : : )+          +- Z5 Z5g Z5 Z5 Z5 Z5x
T 
g 
 
 
 
 =? 0: 0: 0:> 0: 0: 0: 0:d	
 	
h 	
R` 	
 	
 	
 	
 *, )0 )0 )0 )0 )0 )0V) ) ) ) ) )) ) ) ) ) 8<B 'Q 'QW 'Q4PX> 'Q 'Q 'Q 'QR6 6t 6V 6 6 6 6p3 3 3 3 3 154VZce 6F 6F# 6FS 6FPS 6Fjno|j} 6F 6F 6F 6Fp ac & &3 & &C &TW &gt & & & &P%
 %
 %
 %
 %
 %
N: : : GKY]fh -L -LC -L -LSV -L -L -L -L^
 
 
 
 
 
,D D D =? 6: 6: 6:< 6: 6: 6: 6:p1 1F 1 1 1 1f &eBSW +P +P +P +PZ $&    0 )+    c 3 S # X\ dg        rQ  r0   )5 ccxt.async_support.base.exchanger   ccxt.abstract.bullishr   r  rM  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)   r*   r+   r,   r-   ccxt.base.decimal_to_precisionr.   r0   rI  rQ  rP  <module>r|     s   6 5 5 5 5 5 - - - - - -   ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . ) ) ) ) ) ) . . . . . . + + + + + + ) ) ) ) ) ) * * * * * * - - - - - - - - - - - - ) ) ) ) ) ) . . . . . . ) ) ) ) ) ) 4 4 4 4 4 4T- T- T- T- T-h T- T- T- T- T-rQ  