
    i]                         d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
mZmZmZ 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dS )    )Exchange)ImplicitAPI)		IndexTypeIntMarketNumOrder	OrderSide	OrderTypeStrTicker)List)ExchangeError)AuthenticationError)
BadRequest)InsufficientFunds)	TICK_SIZEc                   j    e Zd Z fdZi fdee         fdZi fdedefdZ	d&defdZ
di f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fdZd&defdZi fdZ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fdZdddi fdeded	efdZdi fdedefd Zd&dedefd!Zd"d#i ddfd$Zd% Z  xZ!S )(	tradeogrec                 4   |                      t          t          |                                           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d.dd/dd0dd1dd2dd3dd4dd5dd6dd7dd8di d9dd:dd;dd<dd=dd>dd?dd@ddAddBddCddDddEddFddGddHddIddddddddddddddddJdKdLdMdNidOdPdQdRdS|                     dT          |                     dT          dUidVdWdWdWdWdXidWdWdWdYdWdWdWdWdWdZd[d\i t
          d]t          t          t          t          d^ii d_          S )`Nr   d   v2FCORSspotTmarginswapfutureoption	addMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateDepositAddresscreateMarketOrdercreateOrdercreateOrderscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchAccountsfetchBalancefetchBorrowInterestfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLedgerEntryfetchLeverageTiersfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPermissionsfetchPositionfetchPositionsfetchPositionsForSymbolfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTradingLimitsfetchTransactionFee)fetchTransactionFeesfetchTransactionsfetchTransfersfetchWithdrawAddressesfetchWithdrawalfetchWithdrawalsreduceMarginsetLeverage	setMarginsetMarginModesetPositionModesignIntransferwithdraw zQhttps://github.com/ccxt/ccxt/assets/43336371/3aa748b7-ea44-45e9-a9e7-b1d207a2578arestzhttps://tradeogre.com/api/v1zhttps://tradeogre.comzhttps://tradeogre.com/help/apizhttps://tradeogre.com/help/fees)referrallogoapiwwwdocfeestradingz0.002)makertakerget   )marketszorders/{market}zticker/{market}zhistory/{market})zaccount/balancezaccount/balanceszaccount/order/{uuid})z	order/buyz
order/sellzorder/cancelorderszaccount/orders)rv   post)publicprivateexact)zMust be authorizedzMarket not foundzInsufficient fundszOrder not found)idname	countries	rateLimitversionprohasurlsrr   ro   commonCurrenciesprecisionMode
exceptionsoptions)	deep_extendsuperr   describeparse_numberr   r   r   r   )self	__class__s    b/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/async_support/tradeogre.pyr   ztradeogre.describe   si   i 6 6 ? ? A ASSS %S 	S
 %S %S US "4S tS S $US  S 'S $US tS  !S" &u#S S$ (%S& ''S( ()S* "5+S,  -S. /S0 &u1S2 )%3S4 $U5S6 '7S8 (9S: ;S< &u=S> (?S@ 1%ASB  CSD +EES S SF &uGSH #EISJ *5KSL $UMSN "5OSP *5QSR +ESST uUSV #EWSX %eYSZ +E[S\ ]S^ !%_S`  aSb ecSd $UeSf +EgS S Sh "4iSj dkSl !$mSn "5oSp uqSr #EsSt #EuSv  wSx !%ySz *5{S| %e}S~ )%S@ tASB CSD tESF %eGSH &uIS SJ ).%*"'*/#($) %$"!&#(!!eS S Sj k: /79	 	 !..w77!..w77  #$+,+,,-	  ,-,-01  &'&'()"#*+   0!&*=(2*;'1	 ]PD
 PD
 P P P	    returnc                   K   |                      |           d{V }g }t          dt          |                    D ]}||         }t          |                                          }|                     |d          }|                    d          }|                     |d          }	|                     |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| j	        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|d          }|                    |           |S ) a+  
        retrieves data on all markets for bigone
        :see: https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#markets
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Nr   -rw   r~   symbol/basequotesettlebaseIdquoteIdsettleIdtyper   Tr   Fr   r   r   activecontractlinearrs   ru   8)amountprice)minmax)leverager   r   cost)inversecontractSizeru   rt   expiryexpiryDatetimestrike
optionType	precisionlimitscreatedinfo)publicGetMarketsrangelenlistkeyssafe_stringsplitsafe_currency_codesafe_market_structurerr   r   parse_precisionappend)r   paramsresponseresulti	rawMarketr   r~   keyPartsr   r   r   r   markets                 r   fetch_marketsztradeogre.fetch_markets   s      ..v66666666  q#h--(( <	" <	"A I	(())D!!$**Bxx}}H%%h22F&&x33G**622D++G44E// 21b21$*u,21 21 	21
 $21 &21 721 D21 21 21 %21 21 %21 %21 $21  E!21" $#21$   $9-g69-g6"&""//0D0DS0I0IJJ!..t/C/CC/H/HII   $#! !
  $# 
  $# 
  $#  $  !c21 21 21 2 2Ff MM&!!!!r   r   c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :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~   )load_marketsr   publicGetTickerMarketextendparse_ticker)r   r   r   r   requestr   s         r   fetch_tickerztradeogre.fetch_ticker   s       !!!!!!!!!V$$fTl
 33DKK4P4PQQQQQQQQ   6222r   Nr   c                    |                      i d|                     |d          dd dd d|                     |d          d|                     |d          d|                     |d          dd d|                     |d          d	d d
d d|                     |d          dd dd dd dd dd dd |                     |d          d |d|          S )Nr   	timestampdatetimehighlowbid	bidVolumeask	askVolumevwapopencloselastpreviousClosechange
percentageaveragevolume)
baseVolumequoteVolumer   )safe_tickerr   )r   tickerr   s      r   r   ztradeogre.parse_ticker  sx     !
d&&vx88!
!
 !
 D$$VV44	!

 4##FE22!
 4##FE22!
 !
 4##FE22!
 !
 D!
 D$$VV44!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **68<<)!
 !
 !
* +  	r   limitc                 l  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     |di           }||d}	|                     |	|          }
|
S )a  
        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
        Nr   r~   buysell)bidsasks)r   r   publicGetOrdersMarketr   	safe_dictparse_order_book)r   r   r   r   r   r   r   rawBidsrawAsksrawOrderbook	orderbooks              r   fetch_order_bookztradeogre.fetch_order_book<  s       !!!!!!!!!V$$fTl
 33DKK4P4PQQQQQQQQ ..5"55..6266
 
 )),??	r   r   rw      priceKey	amountKeycountOrIdKeyc                 >   t          |                                          }g }t          dt          |                    D ][}|                     ||          }|                     ||          }	|                     ||          }
|                    |	|
g           \|S )Nr   )r   r   r   r   r   safe_numberr   )r   bidasksr   r   r   pricesr   r   priceStringr   r   s              r   parse_bids_asksztradeogre.parse_bids_asks]  s    gllnn%%q#f++&& 	+ 	+A**6155K$$VQ//E%%g{;;FMM5&/****r   sincec                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||||          S )a  
        get the list of most recent trades for a particular symbol
        :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 number of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int params['lastId']: order id
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        Nr   r~   )r   r   publicGetHistoryMarketr   parse_tradesr   r   r   r   r   r   r   r   s           r   fetch_tradesztradeogre.fetch_tradesg  s       !!!!!!!!!V$$fTl
 44T[[&5Q5QRRRRRRRR  65%@@@r   c                 D   |                      |dd          }|                     |d ||                     |          |                     |d          d d |                     |d          d |                     |d          |                     |d          d d d dd|          S )	Ndate  r   r   r   quantitycurrencyr   )r   r~   r   r   r   orderr   sidetakerOrMakerr   r   r   fee)safe_integer_product
safe_tradeiso8601r   )r   trader   r   s       r   parse_tradeztradeogre.parse_tradey  s     --eVTBB	"Y//&&vx88$$UF33 %%eW55&&uj99   
  
" #  	r   c                    K   |                                   d{V  |                     |           d{V }|                     |di           }|                     |          S )a!  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        Nbalances)r   privateGetAccountBalancesr   parse_balance)r   r   r   r   s       r   fetch_balanceztradeogre.fetch_balance  sz       !!!!!!!!!77????????*b99!!&)))r   c                    d|i}t          |                                          }t          dt          |                    D ]0}||         }||         }|                     |          }d|i}|||<   1|                     |          S )Nr   r   total)r   r   r   r   r   safe_balance)	r   r   r   r   r   
currencyIdbalancecodeaccounts	            r   r  ztradeogre.parse_balance  s     H
 HMMOO$$q#d))$$ 	# 	#AaJz*G**:66DG #F4LL  (((r   r   r  r   r   c                 L  K   |                                   d{V  |                     |          }|d         |                     |                     ||                    |                     |                     ||                    d}|dk    rt          | j        dz             d}	|dk    r0|                     |                     ||                     d{V }	n/| 	                    |                     ||                     d{V }	| 
                    |	|          S )aF  
        create a trade order
        :param str symbol: unified symbol of the market to create an order in
        :param str type: not used by tradeogre
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float price: the price at which the order is to be fullfilled, in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr~   )r   r  r   r   z+ createOrder does not support market ordersr   )r   r   parse_to_numericamount_to_precisionprice_to_precisionr   r~   privatePostOrderBuyr   privatePostOrderSellparse_order)
r   r   r   r  r   r   r   r   r   r   s
             r   create_orderztradeogre.create_order  sA      !!!!!!!!!V$$Tl--d.F.Fvv.V.VWW**4+B+B65+Q+QRR
 

 8TW'TTUUU5==!55dkk'66R6RSSSSSSSSHH!66t{{7F7S7STTTTTTTTH&111r   r~   c                    K   |                                   d{V  d|i}|                     |                     ||                     d{V }|                     |          S )aD  
        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>`
        Nuuid)r   privatePostOrderCancelr   r!  r   r~   r   r   r   r   s         r   cancel_orderztradeogre.cancel_order  s       !!!!!!!!!B
 44T[[&5Q5QRRRRRRRR)))r   c                 t   K   |                                   d{V  |                     d||           d{V S )aI  
        cancel all open orders
        :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
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nall)r   r'  )r   r   r   s      r   cancel_all_ordersztradeogre.cancel_all_orders  sV       !!!!!!!!!&&uff=========r   c                   K   |                                   d{V  d}||                     |          }i }||d         |d<   |                     |                     ||                     d{V }|                     ||||          S )a  
        fetch all unfilled currently open 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>`
        Nr~   r   )r   r   privatePostAccountOrdersr   parse_ordersr   s           r   fetch_open_ordersztradeogre.fetch_open_orders  s       !!!!!!!!![[((F &tGH66t{{7F7S7STTTTTTTT  65%@@@r   c                    K   |                                   d{V  d|i}|                     |                     ||                     d{V }|                     |d          S )a  
        fetches information on an order made by the user
        :see: https://github.com/ace-exchange/ace-official-api-docs/blob/master/api_v2.md#open-api---order-status
        :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>`
        Nr$  )r   privateGetAccountOrderUuidr   r!  r&  s         r   fetch_orderztradeogre.fetch_order  s       !!!!!!!!!B
 88Wf9U9UVVVVVVVV$///r   c                 (   |                      |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|          S )Nr  r  r   r   r~   r$  clientOrderIdr   r   lastTradeTimestampr   r   timeInForcepostOnlyr  r   	stopPricer   r  r   r   filled	fulfilledr  )	remainingstatusr	  trades)r
  r   safe_market
safe_orderr  )r   r  r   r   marketIds        r   r!  ztradeogre.parse_order  s    --eVTBB	##E844!!(F33  
E 
$""5&11 
 T 
 	 

 Y// 
 !$ 
 fX& 
 D 
 4 
  
 D$$UF33 
 T%%eW55 
  
 d&&uj99 
 D 
  t! 
" d&&uk::# 
$    1 
  
  
2 3  	r   r{   GETc                    | j         d         d         dz   |                     ||          z   }|                     ||                     |                    }|dk    r|r|d|                     |          z   z  }|dk    rGddd	|                     | j        d
z   | j        z             z   d}|dk    r|                     |          }||||dS )Nro   rl   r   r@  ?r|   z!application/x-www-form-urlencodedCCXTzBasic :)zContent-TypeRefererauthorization)urlmethodbodyheaders)r   implode_paramsomitextract_params	urlencodestring_to_base64apiKeysecret)r   pathro   rH  r   rJ  rI  rG  s           r   signztradeogre.sign5  s    iv&,t/B/B4/P/PP64#6#6t#<#<==U?? 4sT^^F3333) C!!)D,A,A$+PSBSVZVaBa,b,b!b G
 ~~f--fdwOOOr   c
                    |d S d|vrd S |                      |d          }
|
rd S |                     |d          }|dk    rd S |                     |d          }|                     |d          }| j        dz   |                     |          z   }|                     | j        d         ||           t          |          )Nsuccesstrueerrorr   r}   )	safe_boolr   
safe_valuer~   jsonthrow_exactly_matched_exceptionr   r   )r   r  reasonrG  rH  rJ  rI  r   requestHeadersrequestBodyrU  successStringrW  	errorCodefeedbacks                  r   handle_errorsztradeogre.handle_errorsE  s    4X%%4 ..955 	4((9==F""4'22$$UF33	7S=499X#6#66,,T_W-EyRZ[[[H%%%r   )N)r   rw   r   )"__name__
__module____qualname__r   r   r   r   strr   r   r   r   r   r   r   r   r  r  r  r   r
   floatr   r"  r   r'  r*  r.  r1  r	   r!  rS  rc  __classcell__)r   s   @r   r   r      s       Q Q Q Q Qf *, U UV U U U Un 68 3 3 3F 3 3 3 36" "6 " " " "H @DB  S     B  9 hq     <@d[] A A AS A A A A A$     : *, 	* 	* 	* 	*) ) )( mqy{ 2 2 2I 2Y 2X] 2fi 2 2 2 26 9=R * *S *# * * * * 59 > >c > > > > 59tZ^gi A Ac A ATW A A A A& 8<B 0 0C 0 0 0 0 0( ( (5 ( ( ( (T &eBSW P P P P & & & & & & &r   r   N) ccxt.async_support.base.exchanger   ccxt.abstract.tradeogrer   ccxt.base.typesr   r   r   r   r	   r
   r   r   r   typingr   ccxt.base.errorsr   r   r   r   ccxt.base.decimal_to_precisionr   r    r   r   <module>rq     s   6 5 5 5 5 5 / / / / / / a a a a a a a a a a a a a a a a a a a a a a       * * * * * * 0 0 0 0 0 0 ' ' ' ' ' ' . . . . . . 4 4 4 4 4 4F	& F	& F	& F	& F	&+ F	& F	& F	& F	& F	&r   