
    !:h                         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    G/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/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                 F    | j                  |      }| j                  |      S )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
        )publicGetPairsparse_marketsr   paramsresponses      r   fetch_marketszbtcalpha.fetch_markets   s'     &&v.  !!(++r   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                 h    | j                          | j                  |      }| j                  ||      S )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>`
        )load_marketspublicGetTickerparse_tickers)r   r   r   r   s       r   fetch_tickerszbtcalpha.fetch_tickersF  s5     	''/" !!(G44r   r   c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  ||      S )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>`
        pairr   )r   r   r   extendparse_ticker)r   r   r   r   requestr   s         r   fetch_tickerzbtcalpha.fetch_tickerd  s`     	V$F4L
 ''GV(DE   622r   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           	          | j                          | j                  |      }d|d   i}|r
||d<   ||d<   | j                  | j                  ||            }| j	                  ||d   dddd	d
      S )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
        	pair_namer   
limit_sell	limit_buyr   Nr   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 224;;w3OP$$Xvh/?ufV]_ghhr   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                     | j                          d}i }|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||            }| j	                  ||||      S )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((Wf)EF  >>r   codec                     | j                          d}|| j                  |      }| j                  |      }| j                  ||||ddi      S )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   r@  r   s          r   fetch_depositszbtcalpha.fetch_deposits  sZ     	}}T*H**62 &&x5%&R[I\]]r   c                     | j                          d}i }|| j                  |      }|d   |d<   | j                  | j                  ||            }| j	                  ||||ddi      S )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   r@  privateGetWithdrawsr   rB  )r   r=  r7  r   r   r@  r   r   s           r   fetch_withdrawalszbtcalpha.fetch_withdrawals0  sx     	}}T*H%-d^GM"++DKK,HI &&x5%&R^I_``r   transactionr@  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   r@  statusr   r   r   networkaddress	addressToaddressFromtagtagTotagFromr   txidr   comment)internalr/  updated)safe_timestampr   r  r   r   parse_transaction_status)r   rI  r@  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   rK  c                 8    dddddd}| j                  |||      S )Npendingokfailedcanceled)1020ri   4050r   r   rK  statusess      r   rX  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)rW  r   )r   ohlcvr   s      r   parse_ohlcvzbtcalpha.parse_ohlcv  sn     v.UF+UF+UE*UG,UH-
 	
r   rm   c                 6   | j                          | j                  |      }|d   | j                  | j                  ||      d}|||d<   || j	                  |dz        |d<   | j                  | j                  ||            }| j                  |||||      S )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
        r   )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4T[[&5QR   69eUKKr   c                 .   d|i}t        dt        |            D ]i  }||   }| j                  |d      }| j                  |      }| j	                         }| j                  |d      |d<   | j                  |d      |d<   |||<   k | j                  |      S )Nr   r   r@  reserveusedbalancetotal)r   r!  r   r   accountsafe_balance)r   r   r%  r&  ru  rY  r=  rw  s           r   parse_balancezbtcalpha.parse_balance  s    )q#h-( 	#AqkG))':>J**:6DllnG"..w	BGFO#//CGG"F4L	#   ((r   c                 f    | j                          | j                  |      }| j                  |      S )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>`
        )r   privateGetWalletsry  r   s      r   fetch_balancezbtcalpha.fetch_balance  s1     	))&1!!(++r   c                 4    dddd}| j                  |||      S )Nr  r`  closed)123re  rf  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_originalrK  )oidr   r,  r;  r+  r   r   clientOrderIdr   r   r   r   postOnlyr-  r   r   filled	remaining)r/  r   lastTradeTimestampr  )r   r  	safe_boolrW  safe_integerr  safe_string_n
safe_valuer1  
safe_orderr  )r   r,  r   r  r   r  r   r   r  r  r   rK  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                    |dk(  rt        | j                  dz         | j                          | j                  |      }|d   ||| j	                  ||      d}| j                  | j                  ||            }	|	d   s*t        | j                  dz   | j                  |	      z         | j                  |	|      }
t        |
d         }t        j                  |d      r|
d   n|}| j                  |      |
d<   |
S )	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 supportedr   )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;	
 ((Wf)EF	"tww}tyy/BBCC  62%/*$+$5$5k3$GxV++F3hr   r   c                 n    d|i}| j                  | j                  ||            }| j                  |      S )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,  )privatePostOrderCancelr   r  )r   r   r   r   r   r   s         r   cancel_orderzbtcalpha.cancel_orderD  s@     R
 ..t{{7F/KL ))r   c                     | j                          d|i}| j                  | j                  ||            }| j                  |      S )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>`
        r   )r   privateGetOrderIdr   r  )r   r   r   r   r   r,  s         r   fetch_orderzbtcalpha.fetch_orderZ  sJ     	"
 &&t{{7F'CD&&r   c                     | j                          i }d}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||            }| j	                  ||||      S )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))$++gv*FG  >>r   c           	      R    ddi}| j                  |||| j                  ||            S )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>`
        rK  r  r  r   r   r   r7  r   r   r   s         r   fetch_open_orderszbtcalpha.fetch_open_orders  4     c
   t{{7F7STTr   c           	      R    ddi}| j                  |||| j                  ||            S )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>`
        rK  r  r  r  s         r   fetch_closed_orderszbtcalpha.fetch_closed_orders  r  r   c                     | j                          i }|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||            }| j	                  |d||      S )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  sx     	[[(F$TlGFO$GG,,T[[&-IJ  ue<<r   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   rC  rH  r   r[  rX  listrl  rq  r   ry  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 04B 5W 57 5< 02 33 3f 3>(4 ( (6 (T :>b is i3 iY i, 9 hq / /v / /b 6:UW ?3 ?s ?# ?\`af\g ?. *.Dt\^ ^3 ^c ^ ^cghsct ^: -1tRV_a ac a aC afjkvfw a@+
T +
X +
Q\ +
Z:s :
 
4 
( 26DW[df L# Lc LQT Lkoptku LB
) 
) $& ,( ,: :D Dv D DL gksu 3 i y RW `c B 37r *s *C *, 26b 'c '3 '$ *.Dt\^ ?3 ?c ? ?cghmcn ?. /3TXac U U3 Uc Uhlmrhs U" 154VZce U# US UPS Ujnotju U" -1tRV_a =c = =C =,# &eBSW P0# s  c TX `c r   r   )"ccxt.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    ( .  l  l  l  l  l  * . ) 4 %Px Pr   