
    !:h}                         d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ  G d dee      Zy)    )Exchange)ImplicitAPI)Any	IndexTypeIntMarketNumOrder	OrderSide	OrderTypeStrStringsTickerTickers)List)ExchangeError)AuthenticationError)ArgumentsRequired)
BadRequest)InsufficientFunds)	TICK_SIZEc                       e Zd Zdef fdZi fdee   fdZi fdede	fdZ
di fdedefdZd0d	efd
Zdddi fdedededee   fdZd0d	edefdZdi fdedefdZd1dededefdZddi fdededefdZd0de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$d0d$ed	ede%fd%Z&d&d'i ddfd(Z'd)e(d*ed+ed,ed-ed.efd/Z) xZ*S )2	tradeogrereturnc                    | j                  t        t        |          i dddddg ddddd	d
di dd dd
dddddddddddd
dd
dddddddddddd
ddddi ddddd dd!dd"dd#d
d$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.di d/dd0dd1dd2dd3dd4dd5dd6dd7dd8dd9dd:d
d;dd<dd=d
d>dd?di d@d
dAd
dBd
dCddDddEddFddGddHddIddJddKddLddMddNd
dOd
dPd
i dQddRddSddTddUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddadbdcdddeidfdgdhdidjdk| j	                  dl      | j	                  dl      dmidndodpdpdpdpdpdpdqidpdpdrdpdpdpdpdpdpdsdtdudvi dwt
        dxdyt        t        t        t        dzid{d|d}d~dddddi dddddd ddd dddddddddddddd d ddddddd ddddd d d d	d d dd d dd      S )Nidr   name	countries	rateLimitd   versionv2proThasCORSspotmarginF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fetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTradingLimitsfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransfersfetchWithdrawAddressesfetchWithdrawalfetchWithdrawalsreduceMarginsetLeverage	setMarginsetMarginModesetPositionModesignIntransferwithdrawurls 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feesr   tradingz0.002)makertakerr~   get   )marketszorders/{market}zticker/{market}zhistory/{market}z%chart/{interval}/{market}/{timestamp}zchart/{interval}/{market})zaccount/balanceszaccount/order/{uuid})z	order/buyz
order/sellzorder/cancelorderszaccount/orderszaccount/balance)r   post)publicprivatecommonCurrenciesprecisionMode
exceptionsexact)zMust be authorizedzMarket not foundzInsufficient fundszOrder not found
timeframes1m15m1h4h1d1w)r   r   r   r   r   r   optionsfeatures)IOCFOKPOGTD)
marginModetriggerPricetriggerDirectiontriggerPriceTypestopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventioniceberg)r   triggerr   symbolRequired)r   limitr   r   r   )	sandboxr3   r4   rT   rY   rX   r\   r>   rU   )linearinverse)r&   r(   r)   )	deep_extendsuperr   describeparse_numberr   r   r   r   )self	__class__s    H/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/tradeogre.pyr   ztradeogre.describe   s0   i ? A QD
+QD
KQD
 QD
 	QD

 tQD
 4QD
  UUU %U 	U
 %U %U UU "4U tU U $UU  U 'U $UU tU  !U" &u#U$ (%U& ''U( ()U* "5+U,  -U. /U0 &u1U2 )%3U4 $U5U6 '7U8 (9U: ;U< &u=U> (?U@ 1%AUB  CUD +EEUF &uGUH #EIUJ *5KUL $UMUN "5OUP *5QUR +ESUT uUUV #EWUX %eYUZ +E[U\ ]U^ !%_U`  aUb dcUd $UeUf +EgUh "4iUj dkUl !$mUn "5oUp uqUr #EsUt  uUv 'wUx $UyUz !%{U| *5}U~ (U@ %eAUB )%CUD tEUF GUH tIUJ %eKUL &uMUN 'OUP $UQUR !%SUT )%UUV "5WUX #EYUZ [U\ u]U^ U_U`  aUb "5cUd %eUf EgUh EiUQD
z k: /79	{QD
N !..w7!..w7OQD
Z #$+,+,,-AB56	 -.01
 &'&'()"#*++,[QD
N  !OQD
R YSQD
T *=(2*;'1	UQD
d eQD
t  uQD
x $&+(-,1,0).+06:#(#("'#(	( #($)$)+027/4#()$, %)%)&+#($)*/	# ',!%#($)*/( $()-"&S*X ##
 ##a4yQD
 Q Q	    c                 &   | j                  |      }g }t        dt        |            D ]d  }||   }t        |j	                               }| j                  |d      }|j                  d      }| j                  |d      }	| j                  |d      }
| j                  |	      }| j                  |
      }| j                  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
| j                  | j                  d            | j                  | j                  d            dd
d
dd
d
dd
d
dd
d
ddd
|d       }|j                  |       g |S )!a'  
        retrieves data on all markets for bigone

        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
        r   -r   r   symbol/basequotesettleNbaseIdquoteIdsettleIdtyper&   Tr'   Fr(   r)   r*   activecontractr   r   r   r   8)amountprice)minmax)r   r   r   cost)r   contractSizer   r   expiryexpiryDatetimestrike
optionType	precisionlimitscreatedinfo)publicGetMarketsrangelenlistkeyssafe_stringsplitsafe_currency_codesafe_market_structurer   r   parse_precisionappend)r   paramsresponseresulti	rawMarketr   r   keyPartsr   r   r   r   markets                 r   fetch_marketsztradeogre.fetch_markets   sd    ((0  q#h-( <	"A I	()D!!$*Bxx}H%%h2F&&x3G**62D++G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"&""//0D0DS0IJ!..t/C/CC/HI  $#!
  $#
  $#
  $#$  !c21 2Ff MM&!y<	"z r   r   c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  ||      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>`
        r   r   )load_marketsr   publicGetTickerMarketextendparse_ticker)r   r   r   r   requestr   s         r   fetch_tickerztradeogre.fetch_tickerA  s`     	V$fTl
 --dkk'6.JK   622r   Nsymbolsc                    | j                          | j                  |      }i }| j                  | j                  ||            }i }t	        dt        |            D ]d  }||   }t        |j                               }| j                  |d      }	| j                  |	      }
||	   }| j                  ||
      }|d   }|||<   f | j                  |d|      S )a  
        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>`
        r   r   )r   market_symbolsr   r   r   r   r   r   r   safe_marketr   filter_by_array_tickers)r   r   r   r   r   r   r   entrymarketIdArraymarketIdr   datatickerr   s                 r   fetch_tickersztradeogre.fetch_tickers\  s     	%%g.((Wf)EF$ q#h-( 	$AQKE .M''q9H%%h/F?D&&tV4FH%F#F6N	$ ++FHgFFr   r   c                    | j                  i d| j                  |d      dd dd d| j                  |d      d| j                  |d      d| j                  |d      dd d| j                  |d      d	d d
d d| j                  |d      d| j                  |d      dd dd dd dd dd d | j                  |d      |d|      S )Nr   	timestampdatetimehighlowbid	bidVolumeask	askVolumevwapopeninitialpricecloser   lastpreviousClosechange
percentageaveragevolume)
baseVolumequoteVolumer   )safe_tickerr   )r   r   r   s      r   r   ztradeogre.parse_ticker  sa   6  !
d&&vx8!
!
 !
 D$$VV4	!

 4##FE2!
 4##FE2!
 !
 4##FE2!
 !
 D!
 D$$V^<!
 T%%fg6!
 D!
 T!
 d!
  $!!
" t#!
$ ++FH=)!
* + 	r   r   sincer   c                    | j                          | j                  |      }|d   | j                  | j                  ||      d}d}| j	                  |d      }	|	K| j                  |d      }| j                  |	dz        |d<   | j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |||||      S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :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
        :param int [params.until]: timestamp of the latest candle in ms
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        r   )r   intervalNuntil  r   )r   r   r   r   safe_integeromitparse_to_int%publicGetChartIntervalMarketTimestampr   publicGetChartIntervalMarketparse_ohlcvs)
r   r   	timeframer  r   r   r   r   r   r  s
             r   fetch_ohlcvztradeogre.fetch_ohlcv  s     	V$Tl(()YO
 !!&'2YYvw/F#'#4#4UT\#BGK AA$++gW]B^_H88Wf9UVH   69eUKKr   c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr   r               )safe_timestampsafe_number)r   ohlcvr   s      r   parse_ohlcvztradeogre.parse_ohlcv  sn     q)UA&UA&UA&UA&UA&
 	
r   c                 <   | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j	                  |di       }||d}	| j                  |	|      }
| j                  |d      |
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
        r   r   buysell)bidsaskssnonce)r   r   publicGetOrdersMarketr   	safe_dictparse_order_bookr  )r   r   r   r   r   r   r   rawBidsrawAsksrawOrderbook	orderbooks              r   fetch_order_bookztradeogre.fetch_order_book  s     	V$fTl
 --dkk'6.JK ..5"5..626
 )),?	!..x=	'r   priceKey	amountKeycountOrIdKeyc                    t        |j                               }g }t        dt        |            D ]K  }| j	                  ||      }| j                  ||      }	| j                  ||      }
|j                  |	|
g       M |S )Nr   )r   r   r   r   r   r$  r   )r   bidasksr6  r7  r8  pricesr   r   priceStringr   r  s              r   parse_bids_asksztradeogre.parse_bids_asks  s~    glln%q#f+& 	+A**615K$$VQ/E%%g{;FMM5&/*		+
 r   c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  ||||      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>`
        r   r   )r   r   publicGetHistoryMarketr   parse_tradesr   r   r  r   r   r   r   r   s           r   fetch_tradesztradeogre.fetch_trades  sb     	V$fTl
 ..t{{7F/KL  65%@@r   tradec                    | j                  |dd      }| j                  |d || j                  |      | j                  |d      d d | j                  |d      d | j                  |d      | j                  |d      d d d dd|      S )	Ndater  r   r   r   quantitycurrencyr   )r   r   r   r   r   orderr   sidetakerOrMakerr   r   r   fee)safe_integer_product
safe_tradeiso8601r   )r   rC  r   r   s       r   parse_tradeztradeogre.parse_trade/  s     --eVTB	"Y/&&vx8$$UF3 %%eW5&&uj9  
" # 	r   c                 z   | j                          d}| j                  |d      }|a| j                  |      }d|i}| j                  |      }| j	                  |d      | j	                  |d      d}|||<   | j                  |      S | j                  |      }| j                  |di       }| j                  |      S )ai  
        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
        :param str [params.currency]: currency to fetch the balance for
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        NrH  r   balance	available)totalfreebalances)	r   r   privatePostAccountBalancer   r$  safe_balanceprivateGetAccountBalancesr/  parse_balance)r   r   r   rH  singleCurrencyresultcodeaccountr   s           r   fetch_balanceztradeogre.fetch_balanceL  s     	##FJ755f=H*  **84D))(I>((;?G *1 &$$%9::55f=H*b9!!&))r   c                     d|i}t        |j                               }t        dt        |            D ]&  }||   }||   }| j	                  |      }d|i}|||<   ( | j                  |      S )Nr   r   rT  )r   r   r   r   r   rX  )	r   r   r   r   r   
currencyIdrR  r\  r]  s	            r   rZ  ztradeogre.parse_balanceg  s     H
 HMMO$q#d)$ 	#AaJz*G**:6DG #F4L	#   ((r   r   rJ  r   r   c                    | j                          | j                  |      }|dk(  rt        | j                  dz         |t	        | j                  dz         |d   | j                  ||      | j                  ||      d}d}	|dk(  r"| j                  | j                  ||            }	n!| j                  | j                  ||            }	| j                  |	|      S )a  
        create a trade order

        https://tradeogre.com/help/api#:~:text=u%20%27%7Bpublic%7D%3A%7Bprivate%7D%27-,Submit%20Buy%20Order

        :param str symbol: unified symbol of the market to create an order in
        :param str type: must be '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
        :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+ createOrder does not support market ordersNz' createOrder requires a price parameterr   )r   rF  r   r(  )r   r   r   r   r   amount_to_precisionprice_to_precisionprivatePostOrderBuyr   privatePostOrderSellparse_order)
r   r   r   rJ  r   r   r   r   r   r   s
             r   create_orderztradeogre.create_order{  s     	V$8TWW'TTUU=#DGG.W$WXXTl00@,,VU;

 5=//GV0LMH00Wf1MNH&11r   r   c                     | j                          d|i}| j                  | j                  ||            }| j                  |      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>`
        uuid)r   privatePostOrderCancelr   rf  r   r   r   r   r   r   s         r   cancel_orderztradeogre.cancel_order  sJ     	B
 ..t{{7F/KL))r   c                 N    | j                          | j                  d||      }|g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>`
        all)r   rl  )r   r   r   r   s       r   cancel_all_ordersztradeogre.cancel_all_orders  s1     	$$UFF;
 	
r   c                     | j                          d}|| j                  |      }i }||d   |d<   | j                  | j                  ||            }| j	                  ||||      S )aI  
        fetch all unfilled currently open orders

        https://tradeogre.com/help/api#:~:text=%7B%22success%22%3Atrue%7D-,Get%20Orders,-Method%20(POST)

        :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_ordersrA  s           r   fetch_open_ordersztradeogre.fetch_open_orders  st     	[[(F &tGH00Wf1MN  65%@@r   c                     | j                          d|i}| j                  | j                  ||            }| j                  |d      S )a  
        fetches information on an order made by the user

        https://tradeogre.com/help/api#:~:text=market%22%3A%22XMR%2DBTC%22%7D%5D-,Get%20Order,-Method%20(GET)

        :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>`
        ri  N)r   privateGetAccountOrderUuidr   rf  rk  s         r   fetch_orderztradeogre.fetch_order  sL     	B
 224;;w3OP$//r   rI  c                    | j                  |dd      }| j                  |d      }| j                  ||      }| j                  i d|d| j                  |d      dd d|d	| j	                  |      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| j                  |d      | j                  |d      d d d dd d|      S )NrE  r  r   r   r   ri  clientOrderIdr   r   lastTradeTimestampr   r   r   postOnlyrJ  r   r   r   r   r  filled	fulfilledrF  rG  )	remainingstatusrL  trades)rM  r   r   
safe_orderrO  )r   rI  r   r   r   s        r   rf  ztradeogre.parse_order  s    --eVTB	##E84!!(F3  
E 
$""5&1 
 T 
 	 

 Y/ 
 !$ 
 fX& 
 D 
 4 
  
 D$$UF3 
 T%%eW5 
 D 
 d 
 D 
  t! 
" d&&uk:# 
$ ))%<  1 
2 3 	r   r   GETc                 x   | j                   d   d   dz   | j                  ||      z   }| j                  || j                  |            }|dk(  r|r|d| j	                  |      z   z  }|dk(  rHddd	| j                  | j                  d
z   | j                  z         z   d}|dk7  r| j	                  |      }||||dS )Nr~   r{   r   r  ?r   z!application/x-www-form-urlencodedCCXTzBasic :)zContent-TypeRefererauthorization)urlmethodbodyheaders)ry   implode_paramsr  extract_params	urlencodestring_to_base64apiKeysecret)r   pathr~   r  r   r  r  r  s           r   signztradeogre.sign	  s    iiv&,t/B/B4/PP64#6#6t#<=U?sT^^F333) C!!)D,A,A$++PSBSVZVaVaBa,b!bG
 ~~f-fdwOOr   r\  reasonr  r  r  r  c
                 L   |y d|vry | j                  |d      }
|
ry | j                  |d      }|dk(  ry | j                  |d      }| j                  |d      }| j                  dz   | j	                  |      z   }| j                  | j                  d   ||       t        |      )Nsuccesstrueerrorr\   r   )	safe_boolr   
safe_valuer   jsonthrow_exactly_matched_exceptionr   r   )r   r\  r  r  r  r  r  r   requestHeadersrequestBodyr  successStringr  	errorCodefeedbacks                  r   handle_errorsztradeogre.handle_errors  s    X% ..95((9=F"'2$$UF3	77S=499X#66,,T__W-EyRZ[H%%r   )N)r   r   r  )+__name__
__module____qualname__r   r   r   r   r   strr   r   r   r   r   r   r   r   r  r&  r5  r   r=  rB  dictrP  r^  rZ  r   r   floatr	   rg  r   rl  ro  rs  rv  r
   rf  r  intr  __classcell__)r   s   @r   r   r      sC   R# Rh $& W$v, Wr 02 33 3f 36 04B &GW &G7 &GP06 0d 26DW[df %L# %Lc %LQT %Lkoptku %LN
 
4 
( :>b  s  3  D 9 hq  6:UW A3 As A# A$ v : $& *6)( gksu 23 2i 2y 2RW 2`c 2@ 37r *s *C * /32 
 
 /3TXac A A3 Ac A, 26b 0c 03 0$( (v ( (T &eBSW P &# &s & &c &TX &`c &r   r   N)ccxt.base.exchanger   ccxt.abstract.tradeogrer   ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   ccxt.base.decimal_to_precisionr   r    r   r   <module>r     s>    ( / x x x x  * 0 . ' . 4Y&+ Y&r   