
    !:h0                         d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZ 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      Z!y)    )Exchange)ImplicitAPIN)AnyBalancesCurrency	IndexTypeIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTransaction)List)ExchangeError)InsufficientFunds)InvalidOrder)	TICK_SIZE)Precisec                       e Zd Zdef fdZi fdee   fdZdedefdZ	di fde
defdZi fd	edefd
Zd=dededefdZdi fd	ededefdZd>dededefdZd=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e   fdZd=dededefdZdefdZd=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e#fd"Z$i fde#fd#Z%defd$Z&d=d%edede'fd&Z(di fd	ed'e)d(e*d)e+d*e,f
d+Z-di fd,ed	efd-Z.di fd,ed	efd.Z/dddi fd	edededee'   fd/Z0dddi fd	edededee'   fd0Z1dddi fd	edededee'   fd1Z2dddi fd	ededefd2Z3d3 Z4d4d5i ddfd6Z5de6d7ed8ed9ed:ed;efd<Z7 xZ8S )?btcalphareturnc                 R   | j                  t        t        |          dddgdi dd dddd	d
d	dd	dd	dd	dddd	dd	dd	dddd	dd	dd	dd	ddi dd	dd	dddd	dd	dd	dd	dd	d d	d!dd"d	d#d	d$d	d%d	d&d	d'd	d(d	i d)dd*d	d+d	d,dd-d	d.dd/dd0d	d1dd2dd3dd4dd5d	d6d	d7d	d8d	d9d	i d:d	d;d	d<d	d=dd>dd?dd@d	dAd	dBd	dCd	dDd	dEddFd	dGd	dHd	dId	dJd	dKd	idLdMdNdOdPdQdRdSdTdUidVdWdXdYdZd[g d\ig d]d^d_gd`da| j	                  db      | j	                  db      dcdKi idddedfid	d	d	d d	d	d	d d	d	d	d	dgd	d	d	d	d	d	d	dhd d	did d d	djd	d	d	d	dkd	dld	d	d	dmd	dld d d	d	d	dnd	dld d d d	d	d	dodpdqidr	d d dsd d dsdtt
        i dut        idvdw      S )xNr   z	BTC-AlphaUSv1CORSspotTmarginFswapfutureoption	addMargincancelOrdercloseAllPositionsclosePositioncreateDepositAddresscreateOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL2OrderBookfetchLeveragefetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTradingFeefetchTradingFeesfetchTransferfetchTransfersfetchWithdrawalfetchWithdrawalsreduceMarginsetLeveragesetMarginModesetPositionModetransferwithdraw5153060240D)5m15m30m1h4h1dzOhttps://github.com/user-attachments/assets/dce49f3a-61e5-4ba0-a2fe-41d192fd0e5drestzhttps://btc-alpha.com/apizhttps://btc-alpha.comz$https://btc-alpha.github.io/api-docszhttps://btc-alpha.com/fees/zhttps://btc-alpha.com/?r=123788)logoapiwwwdocfeesreferralget)zcurrencies/zpairs/zorderbook/{pair_name}z
exchanges/charts/{pair}/{type}/chart/zticker/)zwallets/zorders/own/zorder/{id}/zexchanges/own/z	deposits/z
withdraws/zorder/zorder-cancel/)rz   post)publicprivatez0.002)makertaker)tradingfundingCBCCashbery)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedleveragemarketBuyRequiresPricemarketBuyByCostselfTradePreventiontrailingicebergd   )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   i  )r   r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   daysBackCanceledr   r   r   r   r   i  )	sandboxr-   createOrdersrI   rM   rL   rO   r5   rJ   )linearinverse)r#   r%   r&   zOut of balance)exactbroad)idname	countriesversionhas
timeframesurlsru   rx   commonCurrenciesfeaturesprecisionMode
exceptions)deep_extendsuperr   describeparse_numberr   r   )self	__class__s    U/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/async_support/btcalpha.pyr   zbtcalpha.describe   s   h > @FFF %F 	F
 %F %F UF tF $UF  F 'F tF (F 'F (F  "5!F" #F$ +E%F& )%'F( $T)F* '+F, (-F. /F0 &u1F2 (3F4 1%5F6  7F8 &u9F: #E;F< *5=F> $U?F@ "5AFB *5CFD +EEFF #DGFH  IFJ "5KFL MFN !%OFP  QFR dSFT +EUFV "4WFX dYFZ !$[F\ t]F^  _F` 'aFb $UcFd !%eFf *5gFh (iFj %ekFl )%mFn toFp qFr tsFt "5uFv #EwFx  yFz !%{F| "5}F~ #DF@ AFB uCFD  EFF "5GFH EIFJ EKFP  j7 /=5=	  	 !'8 "..w7!..w7
  z!
  %&+(-,0,1).+06:#(#("'#(	( #($)27+0/4$)#()$, %)&+!$$(%)*/& ',#($)*/	# ',!%#($)*/( ',!%$(%)#($)*/$ ',!%$(,0%)#($)*/	*  #ACJ ##
 ##SM\ '$&7gYC
 Y Y	    c                 b   K   | j                  |       d{   }| j                  |      S 7 w)a  
        retrieves data on all markets for btcalpha

        https://btc-alpha.github.io/api-docs/#list-all-currencies

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        N)publicGetPairsparse_marketsr   paramsresponses      r   fetch_marketszbtcalpha.fetch_markets   s3      ,,V44  !!(++! 5s   /-/marketc                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }| j                  |d      }| j                  |      }| j                  |d      }	i 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 d d d d d | j                  | j                  | j                  |d                  | j                  | j                  |            dd d d| j                  |	      | j	                  |d      d| j                  |      d d| j                  t        j                  ||	            d ddd |d
S ) Nr   	currency1	currency2price_precisionminimum_order_sizer   symbol/basequotesettlebaseIdquoteIdsettleIdtyper#   Tr$   Fr%   r&   r'   activecontractr   amount_precision)amountprice)minmaxmaximum_order_size)r   r   r   cost)
r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedinfo)safe_stringsafe_currency_codeparse_precisionr   safe_numberr   
string_mul)
r   r   r   r   r   r   r   pricePrecision
priceLimitamountLimits
             r   parse_marketzbtcalpha.parse_market  sF   ff-!!&+6""6;7&&v.''0))&2CD)).9
&&v/CD0
"0
dSj5(0
 D0
 U	0

 d0
 f0
 w0
 0
 F0
 D0
 e0
 E0
 e0
 e0
 d0
  !0
" d#0
$  "++D,@,@AQAQRXZlAm,no**4+?+?+QR  
  ,,[9++F4HI
  ,,Z8
  ,,W-?-?
K-XY$ _0
 0	
r   Nsymbolsc                    K   | j                          d{    | j                  |       d{   }| j                  ||      S 7 /7 w)a	  

        https://btc-alpha.github.io/api-docs/#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>`
        N)load_marketspublicGetTickerparse_tickers)r   r   r   r   s       r   fetch_tickerszbtcalpha.fetch_tickersF  sK      !!!--f55" !!(G44% 	"5s   A
AA
AA
A
r   c                    K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  ||      S 7 W7 w)a  

        https://btc-alpha.github.io/api-docs/#tickers

        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :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>`
        Npairr   )r   r   r   extendparse_ticker)r   r   r   r   requestr   s         r   fetch_tickerzbtcalpha.fetch_tickerd  sy      !!!V$F4L
 --dkk'6.JKK   622' 	"
 Ls"   A2A.A A2A0A20A2tickerc           	      L   | j                  |d      }t        t        j                  |d            }| j                  |d      }| j	                  ||d      }| j                  |d      }| j                  i d|d|d   d|d| j                  |      d	| j                  |d	      d
| j                  |d
      d| j                  |d      dd d| j                  |d      dd dd dd d|d|dd d| j                  |d      dd d d | j                  |d      d|      S )N	timestamp1000000r   _lastr   r   datetimehighlowbidbuy	bidVolumeasksell	askVolumevwapopenclosepreviousClosechangediff
percentagevol)average
baseVolumequoteVolume)r   intr   r   safe_marketsafe_tickeriso8601)r   r   r   timestampStrr   marketIdr   s          r   r   zbtcalpha.parse_ticker  s    ''<**<CD	##FF3!!(FC8/ !
F!
fX&!
 !
 Y/	!

 D$$VV4!
 4##FE2!
 4##FE2!
 !
 4##FF3!
 !
 D!
 D!
 T!
 D!
 T!
  d&&vv6!!
" $#!
$ ++FE:)!
* + 	r   r   c           	        K   | j                          d{    | j                  |      }d|d   i}|r
||d<   ||d<   | j                  | j                  ||             d{   }| j	                  ||d   dddd	d
      S 7 k7  w)a1  

        https://btc-alpha.github.io/api-docs/#get-orderbook

        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        N	pair_namer   
limit_sell	limit_buyr   r   r  r   r   )r   r   publicGetOrderbookPairNamer   parse_order_book)r   r   r   r   r   r   r   s          r   fetch_order_bookzbtcalpha.fetch_order_book  s      !!!V$
 $)GL!#(GK 88Wf9UVV$$Xvh/?ufV]_ghh 	" Ws"   BBAB#B$BBpriceKey	amountKeycountOrIdKeyc                     g }t        dt        |            D ],  }||   }|s|j                  | j                  |||             . |S )Nr   )rangelenappendparse_bid_ask)r   bidasksr  r  r  resultibidasks           r   parse_bids_askszbtcalpha.parse_bids_asks  sQ    q#g,' 	OAQZFd009MN	O r   tradec                    | j                  |d      }| j                  ||d      }| j                  |d      }| j                  t        j                  |d            }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |dd	      }	| j                  |||| j                  |      |d
   |d|	d ||d d d|      S )Nr   r   r   r   r   r   r   my_sider   r   r   )r   r   r   r   r   orderr   sidetakerOrMakerr   r   r   fee)r   r  parse_to_intr   r   safe_string_2
safe_trader  )
r   r)  r   r  timestampRawr   priceStringamountStringr   r-  s
             r   parse_tradezbtcalpha.parse_trade  s    2 ##E62!!(FC8''{;%%g&8&8y&QR	&&ug6''x8eT*!!%F;"Y/X&  " 
  	r   sincec                   K   | j                          d{    d}i }|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||             d{   }| j	                  ||||      S 7 g7 w)a   
        get the list of most recent trades for a particular symbol

        https://btc-alpha.github.io/api-docs/#list-all-exchanges

        :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
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        Nr   r   r   )r   r   publicGetExchangesr   parse_trades)r   r   r7  r   r   r   r   tradess           r   fetch_tradeszbtcalpha.fetch_trades  s      !!![[(F$TlGFO$GG..t{{7F/KLL  >> 	" M"   BA>AB%B &B Bcodec                    K   | j                          d{    d}|| j                  |      }| j                  |       d{   }| j                  ||||ddi      S 7 I7 w)a	  
        fetch all deposits made to an account

        https://btc-alpha.github.io/api-docs/#list-own-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
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr   deposit)r   currencyprivateGetDepositsparse_transactions)r   r>  r7  r   r   rA  r   s          r   fetch_depositszbtcalpha.fetch_deposits  sr      !!!}}T*H0088 &&x5%&R[I\]] 	" 9s!   A$A -A$A"A$"A$c                    K   | j                          d{    d}i }|| j                  |      }|d   |d<   | j                  | j                  ||             d{   }| j	                  ||||ddi      S 7 c7 w)a  
        fetch all withdrawals made from an account

        https://btc-alpha.github.io/api-docs/#list-own-made-withdraws

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr   currency_idr   
withdrawal)r   rA  privateGetWithdrawsr   rC  )r   r>  r7  r   r   rA  r   r   s           r   fetch_withdrawalszbtcalpha.fetch_withdrawals0  s      !!!}}T*H%-d^GM"11$++gv2NOO &&x5%&R^I_``% 	" Ps"   A>A:AA>A<A><A>transactionrA  c                    | j                  |d      }| j                  |d      }| j                  |d      }i d| j                  |d      d|d|d| j                  |      dd dd d	d d
d dd dd dd d| j                  ||      d| j	                  |d      dd dd d| j                  |      dd d d d dS )Nr   rA  statusr   r   r   networkaddress	addressToaddressFromtagtagTotagFromr   txidr   comment)internalr/  updated)safe_timestampr   r  r   r   parse_transaction_status)r   rJ  rA  r   
currencyIdstatusIds         r   parse_transactionzbtcalpha.parse_transactionP  sW   & ''[A	%%k:>
##K:
$"";5
K
 
 Y/	

 t
 t
 
 4
 4
 T
 t
 //
HE
 d&&{H=
 D
 D
  d33H=!
" t#
$ )
 	
r   rL  c                 8    dddddd}| j                  |||      S )Npendingokfailedcanceled)1020ri   4050r   r   rL  statusess      r   rY  z!btcalpha.parse_transaction_status}  s/    
 &&99r   c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Ntimer  r   r   r  volume)rX  r   )r   ohlcvr   s      r   parse_ohlcvzbtcalpha.parse_ohlcv  sn     v.UF+UF+UE*UG,UH-
 	
r   rm   c                 f  K   | j                          d{    | j                  |      }|d   | j                  | j                  ||      d}|||d<   || j	                  |dz        |d<   | j                  | j                  ||             d{   }| j                  |||||      S 7 7 w)a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://btc-alpha.github.io/api-docs/#charts

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nr   )r   r   r   i  r7  )r   r   r   r   r0  publicGetChartsPairTypeChartr   parse_ohlcvs)	r   r   	timeframer7  r   r   r   r   r   s	            r   fetch_ohlcvzbtcalpha.fetch_ohlcv  s      !!!V$4L$$T__iK
 $GG#00>GG::4;;wPV;WXX   69eUKK% 	" Ys"   B1B-A<B1B/B1/B1c                 .   d|i}t        dt        |            D ]i  }||   }| j                  |d      }| j                  |      }| j	                         }| j                  |d      |d<   | j                  |d      |d<   |||<   k | j                  |      S )Nr   r   rA  reserveusedbalancetotal)r   r!  r   r   accountsafe_balance)r   r   r%  r&  rv  rZ  r>  rx  s           r   parse_balancezbtcalpha.parse_balance  s    )q#h-( 	#AqkG))':>J**:6DllnG"..w	BGFO#//CGG"F4L	#   ((r   c                    K   | j                          d{    | j                  |       d{   }| j                  |      S 7 .7 w)ab  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://btc-alpha.github.io/api-docs/#list-own-wallets

        :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   privateGetWalletsrz  r   s      r   fetch_balancezbtcalpha.fetch_balance  sG      !!!//77!!(++ 	"7s   A	AA	AA	A	c                 4    dddd}| j                  |||      S )Nr  ra  closed)123rf  rg  s      r   parse_order_statuszbtcalpha.parse_order_status  s)    

 &&99r   r,  c                    | j                  |d      }| j                  ||d      }|d   }| j                  |dd      }d }|r| j                  |d      }n| j	                  |d      }| j                  |d      }| j                  |d      }| j                  |d	      }	| j                  |d
      }
| j                  | j                  |d            }| j                  |g d      }| j                  |d      }| j                  |dd      }| j                  i d|dd d| j                  |      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   successFdater   r   amount_filledamount_originalrL  )oidr   r,  r;  r+  r   r   clientOrderIdr   r   r   r   postOnlyr-  r   r   filled	remaining)r/  r   lastTradeTimestampr  )r   r  	safe_boolrX  safe_integerr  safe_string_n
safe_valuer1  
safe_orderr  )r   r,  r   r  r   r  r   r   r  r  r   rL  r   r;  r-  s                  r   parse_orderzbtcalpha.parse_order  s   : ##E62!!(FC8!..	59	++E6:I))%8I  0$$UH5	!!%9!!%):;(()9)9%)JK'=>1!!%F;  
" 
T 
 Y/ 
 	 

 f 
 f 
 G 
 4 
  
 D 
 U 
 D 
 D 
 f 
 f 
  ! 
" f# 
$ "&+ 
, - 	r   r   r-  r   r   c                 (  K   |dk(  rt        | j                  dz         | j                          d{    | j                  |      }|d   ||| j	                  ||      d}| j                  | j                  ||             d{   }	|	d   s*t        | j                  dz   | j                  |	      z         | j                  |	|      }
t        |
d         }t        j                  |d	      r|
d   n|}| j                  |      |
d<   |
S 7 7 w)
a  

        https://btc-alpha.github.io/api-docs/#create-order

        create a trade order
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   z! only limits orders are supportedNr   )r   r   r   r   r   r   0)r   r   r   r   price_to_precisionprivatePostOrderr   jsonr  strr   	string_gtr   )r   r   r   r-  r   r   r   r   r   r   r,  orderAmounts               r   create_orderzbtcalpha.create_order#  s     8tww)LLMM!!!V$4L,,VU;	
 ..t{{7F/KLL	"tww}tyy/BBCC  62%/*$+$5$5k3$GxV++F3h 	" Ms#   1DDADDBDDr   c                    K   d|i}| j                  | j                  ||             d{   }| j                  |      S 7 w)a  

        https://btc-alpha.github.io/api-docs/#cancel-order

        cancels an open order
        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r,  N)privatePostOrderCancelr   r  )r   r   r   r   r   r   s         r   cancel_orderzbtcalpha.cancel_orderD  sM      R
 44T[[&5QRR )) Ss   )AAAc                    K   | j                          d{    d|i}| j                  | j                  ||             d{   }| j                  |      S 7 B7 w)a  

        https://btc-alpha.github.io/api-docs/#retrieve-single-order

        fetches information on an order made by the user
        :param str id: the order id
        :param str symbol: not used by btcalpha fetchOrder
        :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   privateGetOrderIdr   r  )r   r   r   r   r   r,  s         r   fetch_orderzbtcalpha.fetch_orderZ  sc      !!!"
 ,,T[[&-IJJ&& 	" Ks!   AA,AAAAc                   K   | j                          d{    i }d}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||             d{   }| j	                  ||||      S 7 g7 w)a-  

        https://btc-alpha.github.io/api-docs/#list-own-orders

        fetches information on multiple orders made by the user
        :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
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   r   r   )r   r   privateGetOrdersOwnr   parse_orders)r   r   r7  r   r   r   r   orderss           r   fetch_orderszbtcalpha.fetch_ordersl  s      !!![[(F$TlGFO$GG//GV0LMM  >> 	" Nr=  c           	      n   K   ddi}| j                  |||| j                  ||             d{   S 7 w)a  
        fetch all unfilled currently open orders

        https://btc-alpha.github.io/api-docs/#list-own-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>`
        rL  r  Nr  r   r   r   r7  r   r   r   s         r   fetch_open_orderszbtcalpha.fetch_open_orders  ?      c
 &&vueT[[RX=YZZZZ   ,535c           	      n   K   ddi}| j                  |||| j                  ||             d{   S 7 w)a4  
        fetches information on multiple closed orders made by the user

        https://btc-alpha.github.io/api-docs/#list-own-orders

        :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
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        rL  r  Nr  r  s         r   fetch_closed_orderszbtcalpha.fetch_closed_orders  r  r  c                   K   | j                          d{    i }|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||             d{   }| j	                  |d||      S 7 e7 w)a  
        fetch all trades made by the user

        https://btc-alpha.github.io/api-docs/#list-own-exchanges

        :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
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nr   r   r   )r   r   privateGetExchangesOwnr   r:  )r   r   r7  r   r   r   r   r;  s           r   fetch_my_tradeszbtcalpha.fetch_my_trades  s      !!![[(F$TlGFO$GG224;;w3OPP  ue<< 	" Qs"   B A<AB #A>$B >B c                 "    | j                         S N)milliseconds)r   s    r   noncezbtcalpha.nonce  s      ""r   r}   GETc           
         | j                  | j                  | j                  || j                  |                        }| j                  d   d   dz   }|dk7  r|dz  }|| j                  ||      z  }ddi}|dk(  rt        |      r|d	|z   z  }n| j                          | j                  }	|d
k(  rd|d<   |}|	|z  }	nt        |      r|d	|z   z  }| j                  |d<   | j                  | j                  |	      | j                  | j                        t        j                        |d<   t        | j                               |d<   ||||dS )Nru   rs   r   r{   zv1/Acceptzapplication/jsonr}   ?POSTz!application/x-www-form-urlencodedzContent-TypezX-KEYzX-SIGNzX-NONCE)urlmethodbodyheaders)	urlencodekeysortomitextract_paramsr   implode_paramsr!  check_required_credentialsapiKeyhmacencodesecrethashlibsha256r  r  )
r   pathru   r  r   r  r  queryr  payloads
             r   signzbtcalpha.sign  sH   t||DIIfd>Q>QRV>W,XYZiiv&,005LCt""400/0(?5zsU{"++-kkG*M'4UsU{"#{{GG $		$++g*>DKK@XZaZhZh iGH!$TZZ\!2GIfdwOOr   reasonr  r  r  r  c
                     |y | j                  |d      }
|
]| j                  dz   |z   }| j                  | j                  d   |
|       | j	                  | j                  d   |
|       t        |      y )Nerrorr  r   r   )r   r   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r   r>  r  r  r  r  r  r   requestHeadersrequestBodyr  feedbacks               r   handle_errorszbtcalpha.handle_errors  s}       73ww}t+H001I5RZ[001I5RZ[))r   r  )r         )9__name__
__module____qualname__r   r   r   r
   r   dictr   r   r   r   r  r   r   r   r	   r   r  r   r(  r   r6  r<  r   r   rD  rI  r   r\  rY  listrm  rr  r   rz  r}  r  r   r  r   r   floatr   r  r  r  r  r  r  r  r  r  r  r  __classcell__)r   s   @r   r   r      s   Z# Zx *, ,V ,69
4 9
F 9
v 6:" 57 5 5< 68 3 3F 3>(4 ( (6 (T @DB iS i iS\ i, 9 hq / /v / /b <@d[] ? ?S ? ?bfglbm ?. 04$UYbd ^ ^C ^s ^imnyiz ^: 37TX\eg aC as aRU alpq|l} a@+
T +
X +
Q\ +
Z:s :
 
4 
( 8<$]ajl L LC LWZ Lquvzq{ LB
) 
) *, , ,: :D Dv D DL mqy{  I Y X] fi B 9=R *S *# *, 8<B 'C ' '$ 04$UYbd ? ?C ?s ?imnsit ?. 59tZ^gi [c [ [TW [nrsxny [" 7;\`ik [ [3 [VY [ptuzp{ [" 37TX\eg =C =s =RU =,# &eBSW P0# s  c TX `c r   r   )" ccxt.async_support.base.exchanger   ccxt.abstract.btcalphar   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r    r   r   <module>r     sP    6 .  l  l  l  l  l  * . ) 4 %Px Pr   