
    iW                    0   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mZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlm Z  d dlm!Z! d dlm"Z" d dlm#Z# d dl$m%Z% d dl&m'Z'  G d dee          Z(dS )    )Exchange)ImplicitAPI)Balances
CurrenciesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeesTransaction)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)DDoSProtection)ExchangeNotAvailable)	TICK_SIZE)Precisec                   x    e Zd Z fdZi fdZi fdefdZi fdee         fdZ	defdZ
i fdefdZi fdZi fd	Zd:defdZd:dedefdZi fdedefdZd
i fdedefdZd
i fdede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:dedefdZ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:de#fdZ$i fdefdZ%i fdefd Z&d
d
d
i fde'dededee(         fd!Z)d
d
d
i fde'dededee(         fd"Z*d
i fded#e+fd$Z,d:de#de(fd%Z-d& Z.d:dede/fd'Z0d( Z1d
i fded)e2d*e3d#e+d+e4f
d,Z5d
i fd-ede'fd.Z6d
i fde'fd/Z7d
i fde'fd0Z8d
i fd-ede'fd1Z9d
d
d
i fde'dededee/         fd2Z:d
d
d
i fde'dededee/         fd3Z;d
d
d
i fd-ede'dedefd4Z<d
d
d
i fde'dedefd5Z=d6d7i d
d
fd8Z>d9 Z? xZ@S );
onetradingc                    |                      t          t          |                                           i d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d0di d1dd2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAdi dBddCddDddEddFddGddHddIddJddKddLddMddNddOddPddQddRddddddddddSdTdUdVdWdXdYdZd[d\d]d^	d_d`dadadbdcddgdedfdgdhg diig djg dkg dldmdbdndodd|                     dp          |                     dq          |                     dr          |                     dp          g|                     ds          |                     dt          g|                     du          |                     dt          g|                     dv          |                     dq          g|                     dw          |                     dx          g|                     dy          |                     dz          g|                     d{          |                     d|          gg|                     dr          |                     dq          g|                     ds          |                     dq          g|                     du          |                     dx          g|                     dv          |                     dz          g|                     dw          |                     d}          g|                     dy          |                     d~          g|                     d{          |                     d~          ggdgdidddddt
          di dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          t          t          t          t          t          t          t          t          t           dɜ	i dʜdddidddiddgdӜ          S )Nidr%   namezOne Trading	countriesAT	rateLimiti,  versionv1proThasCORSspotmarginFswapfutureoption	addMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateDepositAddresscreateOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchAccountsfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositsfetchDepositsWithdrawalsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionModefetchPositionsfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransferfetchTransfersfetchWithdrawal)fetchWithdrawalsreduceMarginsetLeverage	setMarginsetMarginModesetPositionModetransferwithdraw
timeframesz	1/MINUTESz	5/MINUTESz
15/MINUTESz
30/MINUTESz1/HOURSz4/HOURSz1/DAYSz1/WEEKSz1/MONTHS)	1m5m15m30m1h4h1d1w1MurlszQhttps://github.com/ccxt/ccxt/assets/43336371/bdbc26fd-02f2-4ca7-9f1e-17333690bb1cz!https://api.onetrading.com/public)publicprivatezhttps://onetrading.com/zhttps://docs.onetrading.comzhttps://onetrading.com/fees)logoapiwwwdocfeesr   get)	
currencieszcandlesticks/{instrument_code}r   instrumentszorder-book/{instrument_code}zmarket-tickerzmarket-ticker/{instrument_code}zprice-ticks/{instrument_code}time)zaccount/balancesz&account/deposit/crypto/{currency_code}zaccount/deposit/fiat/EURzaccount/depositszaccount/deposits/bitpandazaccount/withdrawalszaccount/withdrawals/bitpandaaccount/feesaccount/ordersaccount/orders/{order_id}z account/orders/{order_id}/tradeszaccount/tradeszaccount/trades/{trade_id}zaccount/trading-volume)zaccount/deposit/cryptozaccount/withdraw/cryptozaccount/withdraw/fiatr   r   )r   r   z!account/orders/client/{client_id})r   postdeleter   tradingz0.0015z0.0010100z0.001325010005000z0.000910000z0.0007520000z0.00065z0.0006z0.0005)takermaker)	tierBased
percentager   r   tiersrequiredCredentials)apiKeysecretprecisionMode
exceptionsINVALID_CLIENT_UUIDORDER_NOT_FOUNDONLY_ONE_ERC20_ADDRESS_ALLOWEDDEPOSIT_ADDRESS_NOT_USEDINVALID_CREDENTIALSMISSING_CREDENTIALSINVALID_APIKEYINVALID_SCOPESINVALID_SUBJECTINVALID_ISSUERINVALID_AUDIENCEINVALID_DEVICE_IDINVALID_IP_RESTRICTIONAPIKEY_REVOKEDAPIKEY_EXPIREDSYNCHRONIZER_TOKEN_MISMATCHSESSION_EXPIREDINTERNAL_ERRORCLIENT_IP_BLOCKEDMISSING_PERMISSIONILLEGAL_CHARSUNSUPPORTED_MEDIA_TYPE"ACCOUNT_HISTORY_TIME_RANGE_TOO_BIGCANDLESTICKS_TIME_RANGE_TOO_BIGINVALID_INSTRUMENT_CODEINVALID_ORDER_TYPEINVALID_UNITINVALID_PERIODINVALID_TIMEINVALID_DATEINVALID_CURRENCYINVALID_AMOUNTINVALID_PRICEINVALID_LIMITINVALID_QUERYINVALID_CURSORINVALID_ACCOUNT_IDINVALID_SIDE!INVALID_ACCOUNT_HISTORY_FROM_TIME%INVALID_ACCOUNT_HISTORY_MAX_PAGE_SIZE#INVALID_ACCOUNT_HISTORY_TIME_PERIODINVALID_ACCOUNT_HISTORY_TO_TIME INVALID_CANDLESTICKS_GRANULARITYINVALID_CANDLESTICKS_UNITINVALID_ORDER_BOOK_DEPTHINVALID_ORDER_BOOK_LEVELINVALID_PAGE_CURSORINVALID_TIME_RANGEINVALID_TRADE_IDINVALID_UI_ACCOUNT_SETTINGSNEGATIVE_AMOUNTNEGATIVE_PRICEMIN_SIZE_NOT_SATISFIEDBAD_AMOUNT_PRECISIONBAD_PRICE_PRECISIONBAD_TRIGGER_PRICE_PRECISIONMAX_OPEN_ORDERS_EXCEEDEDMISSING_PRICEMISSING_ORDER_TYPEMISSING_SIDE!MISSING_CANDLESTICKS_PERIOD_PARAMMISSING_CANDLESTICKS_UNIT_PARAMMISSING_FROM_PARAMMISSING_INSTRUMENT_CODEMISSING_ORDER_IDMISSING_TO_PARAMMISSING_TRADE_IDINVALID_ORDER_ID)		NOT_FOUNDINSUFFICIENT_LIQUIDITYINSUFFICIENT_FUNDS
NO_TRADINGSERVICE_UNAVAILABLEGATEWAY_TIMEOUT	RATELIMITCF_RATELIMITINTERNAL_SERVER_ERROR)exactbroadcommonCurrenciesMIOTAIOTAoptionsmethodfetchPrivateTradingFeesEURCHF)rm   fiat)deep_extendsuperr%   describeparse_numberr"   r   r   r   r   r   r   r   r   r!   r    r   )self	__class__s    U/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/onetrading.pyr  zonetrading.describe   s   j$ 7 7 @ @ B B [E
,[E
M[E
 $[E
 	[E

 t[E
 4[E
  MMM %M 	M
 %M %M UM "4M tM M $UM  M 'M tM (M  '!M" (#M M$ "4%M&  'M( )M* +E+M, )%-M. $T/M0 '1M2 (3M4 "45M6 7M8 &t9M: (;M<  =M> +E?M@ &uAMB #ECMD *5EM M MF $UGMH "5IMJ *5KML +EMMN uOMP  QMR "5SMT UMV !%WMX  YMZ d[M\ +E]M^ "4_M` daMb !$cMd ueMf #DgM M Mh  iMj $UkMl !%mMn %eoMp )%qMr tsMt uMv TwMx tyMz "5{M| #D}M~ &uM@ 'AMB $UCMD  EMF !%GMH "5IM MJ %) %$"!&#(! YM M M[E
l !!## 
 
m[E
B kAB  11 6 C[E
Z  
 
 
       1 , ,[[E
t !%"&!..x88!..w77
 "&!2!23!7!79J9J89T9T U!%!2!25!9!94;L;LX;V;V W!%!2!25!9!94;L;LX;V;V W!%!2!26!:!:D<M<Mg<V<V W!%!2!26!:!:D<M<Mh<W<W X!%!2!27!;!;T=N=Ny=Y=Y Z!%!2!27!;!;T=N=Ny=Y=Y Z& "&!2!23!7!79J9J79S9S T!%!2!25!9!94;L;LW;U;U V!%!2!25!9!94;L;LX;V;V W!%!2!26!:!:D<M<Mi<X<X Y!%!2!26!:!:D<M<Mh<W<W X!%!2!27!;!;T=N=Nx=X=X Y!%!2!27!;!;T=N=Nx=X=X Y&  u[E
r "$ $s[E
z Y{[E
| N)<N%}N 5nN /	N
 *+>N *+>N %&9N %&9N &':N %&9N '(;N ()<N -.AN %&9N %&9N  23F!N" &':#N N$ %&9%N& ()9'N( )*:)N* $Z+N, -j-N. 9*/N0 6z1N2 .z3N4 )*5N6 #J7N8 %j9N: #J;N< #J=N> '
?N@ %jANB $ZCND $ZEN N NF $ZGNH %jINJ )*KNL #LMNN 8ONP <ZQNR ::SNT 6zUNV 7
WNX 0YNZ /
[N\ /
]N^ *:_N` )*aNb '
cNd 2:eNf &|gN N Nh %liNj -lkNl +LmNn *<oNp 2<qNr /
sNt $\uNv ),wNx #LyNz 89J{N| 67H}N~ )*;N@ ./@ANB 'CND '(9ENF '(9GNH 'IN NJ "/.?*;"6+?';!/$2-:[N N N^aR R}[E
b !c[E
j 7% 	 k[E
 [ [ [	    c                 X    |                      |          }|                     |d          S )a  
        fetches the current integer timestamp in milliseconds from the exchange server
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        epoch_millis)publicGetTimesafe_integerr  paramsresponses      r  
fetch_timezonetrading.fetch_time9  s/     %%f--   >:::r  returnc                    |                      |          }i }t          dt          |                    D ]}||         }|                     |d          }|                     |          }||d|dd|                     |                     |                     |d                              dddddddddi d||<   |S )z
        fetches all available currencies on an exchange
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r   codeN	precisionminmax)amountr{   )r'   r  r(   infoactivefeer  r{   depositlimitsnetworks)publicGetCurrenciesrangelensafe_stringsafe_currency_coder  parse_precision)r  r  r  resulticurrencyr'   r  s           r  fetch_currencieszonetrading.fetch_currenciesH  s     ++F33 q#h--(( 	 	A{H!!(F33B**2..D !..t/C/CDDTDTU]_jDkDk/l/lmm &*488(,T : :   F4LL  r  c                 V    |                      |          }|                     |          S )z
        retrieves data on all markets for onetrading
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        )publicGetInstrumentsparse_marketsr  s      r  fetch_marketszonetrading.fetch_marketsn  s-     ,,V44 !!(+++r  c                    |                      |di           }|                      |di           }|                     |d          }|                     |d          }|dz   |z   }|                     |          }|                     |          }|                     |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k    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basequoter  _stater'   symbol/settlebaseIdquoteIdsettleIdtyper1   Tr2   Fr3   r4   r5   r  ACTIVEcontractlinearamount_precisionmarket_precision)r  pricer  min_size)leverager  r>  cost)
inversecontractSizeexpiryexpiryDatetimestrike
optionTyper  r  createdr  )
safe_valuer"  r#  r  r$  safe_number)
r  market	baseAsset
quoteAssetr5  r6  r'   r.  r/  r1  s
             r  parse_marketzonetrading.parse_market  sy   OOFFB77	__VWb99
!!)V44"":v66c\G#&&v..''00  11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
 u(0
  !0
" d#0
$  "++D,@,@AQAQRXZlAmAm,n,noo**4+?+?@P@PQWYk@l@l+m+mnn    
   
   
  ++FJ??  $ _0
 0
 0
 0	
r  c                     |                      |d          }|                     |d          }|3|                     | j        di           }|                      |dd          } t	          | |          |          S )a  
        fetch the trading fees for multiple markets
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        r   Nrm   r   )r"  omitrI  r   getattr)r  r  r   r   s       r  fetch_trading_feeszonetrading.fetch_trading_fees  s{     !!&(3368,,>oodl4FKKG%%gx9RSSF$wtV$$V,,,r  c           	         |                                   |                     |          }|                     |di           }|                     |d          }|                     |          }|                     |di           }i }t	          dt          | j                            D ]D}| j        |         }	||	|                     |d          |                     |d          dd|d||	<   E|S )Nr   	fee_tiers	maker_fee	taker_feeTr  r2  r   r   r   r   r   )load_marketspublicGetFeesrI  parse_fee_tiersr   r!  symbolsrJ  )
r  r  r  firstfeeTiersr   	firstTierr%  r&  r2  s
             r  fetch_public_trading_feesz$onetrading.fetch_public_trading_fees  s    %%f--( !R00??5+66$$X..OOHa44	q#dl++,, 
	 
	A\!_F )))[AA)))[AA"! F6NN r  c           	      V   |                                   |                     |          }|                     |di           }|                     |d          }|                     |d          }t	          j        |d          }t	          j        |d          }|                     |d          }i }|                     |          }t          dt          | j	                            D ]B}	| j	        |	         }
||
| 
                    |          | 
                    |          dd|d||
<   C|S )	Nactive_fee_tierrU  rV  r   rT  r   TrW  )rX  privateGetAccountFeesrI  r"  r#   
string_divrZ  r   r!  r[  r  )r  r  r  activeFeeTiermakerFeetakerFeer]  r%  r   r&  r2  s              r  fetch_private_trading_feesz%onetrading.fetch_private_trading_fees  s0   --f55, 2CRHH##M;??##M;??%h66%h66??8[99$$X..q#dl++,, 
	 
	A\!_F  **844**844"! F6NN r  NrK  c                    g }g }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d          }	t	          j        |	d          }	t	          j        |d          }|                    ||                     |	          g           |                    ||                     |          g           ||dS )Nr   volumerV  rU  r   )r   r   )r   r!  rJ  r"  r#   rc  appendr  )
r  r]  rK  	takerFees	makerFeesr&  tierri  r   r   s
             r  rZ  zonetrading.parse_fee_tiers   s    		q#h--(( 	A 	AAA;D%%dH55F$$T;77E$$T;77E&ue44E&ue44Efd&7&7&>&>?@@@fd&7&7&>&>?@@@@
 
 	
r  c                    |                      |                     |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|          S )Nr   instrument_coder0  
last_priceprice_change_percentageprice_changebase_volumequote_volumer2  	timestampdatetimehighlowbidbest_bid	bidVolumeaskbest_ask	askVolumevwapopencloselastpreviousClosechanger   average)
baseVolumequoteVolumer  )	parse8601r"  safe_symbolsafe_tickeriso8601)r  tickerrK  ru  marketIdr2  r  r   r  r  r  s              r  parse_tickerzonetrading.parse_ticker1  s   * NN4#3#3FF#C#CDD	##F,=>>!!(FC8855%%f.GHH
!!&.99%%fm<<
&&v~>> !
f!
!
 Y//!
 D$$VV44	!

 4##FE22!
 4##FJ77!
 !
 4##FJ77!
 !
 D!
 D!
 T!
 D!
 T!
 f!
  *!!
" t#!
$ %&)!
 !
 !
* +  	r  r2  c                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     ||          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>`
        ro  r'   )rX  rK  #publicGetMarketTickerInstrumentCodeextendr  )r  r2  r  rK  requestr  s         r  fetch_tickerzonetrading.fetch_tickere  ss     	V$$vd|
 ;;DKKQW<X<XYY&   6222r  r[  c                 @   |                                   |                     |          }|                     |          }i }t          dt	          |                    D ]*}|                     ||                   }|d         }|||<   +|                     |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   r2  )rX  market_symbolspublicGetMarketTickerr   r!  r  filter_by_array_tickers)r  r[  r  r  r%  r&  r  r2  s           r  fetch_tickerszonetrading.fetch_tickers  s     	%%g..--f55* q#h--(( 	$ 	$A&&x{33FH%F#F6NN++FHgFFFr  limitc           	      \   |                                   |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |                     |d                    }|                     ||d         |dd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
        ro  r'   Ndepthr   r2  bidsasksr>  r  )rX  rK   publicGetOrderBookInstrumentCoder  r  r"  parse_order_book)r  r2  r  r  rK  r  r  ru  s           r  fetch_order_bookzonetrading.fetch_order_book  s     	V$$vd|
 $GG88Wf9U9UVVp NN4#3#3Hf#E#EFF	$$Xvh/?FTZ\cemnnnr  c           	         |                      |d          }|                     |d          }|                     |d          }dddddd	}|                     ||          }||z   }|                     |          }	|	d
z  }
|                     |                     |d                    }|
|                     ||
z            z  }|                      | j        di           }|                     |dd          }||                     |d          |                     |d          |                     |d          |                     |d          |                     ||          gS )NgranularityunitperiodmhdwM)MINUTESHOURSDAYSWEEKSMONTHS  r   r\   ri  total_amountr  rw  rx  r  )rI  r"  parse_timeframer  parse_to_intr   rJ  )r  ohlcvrK  r  r  r  unitslowercaseUnit	timeframedurationInSecondsdurationru  alignedTimestampr   volumeFields                  r  parse_ohlcvzonetrading.parse_ohlcv  st    ooe];;V44!!+x88
 
 ((55]*	 00;;$t+NN4#3#3E6#B#BCC	#d&7&7	H8L&M&MM//$,bAA&&w.IIUF++UF++UE**UG,,UK00
 	
r  r}   sincec                    |                                   |                     |          }|                     | j        |          }|                    d          \  }}	|                     |          }
|
dz  }|d}|d         ||	d}|K|                                 }|                     |          |d<   |                     |||z  z
            |d<   nG|                     |          |d<   |                     |                     |||z                      |d<   | 	                    | 
                    ||                    }|                     |||||          S )	aQ  
        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
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        r3  r  Ni  r'   )ro  r  r  tofrom)rX  rK  r"  r|   splitr  millisecondsr  sum#publicGetCandlesticksInstrumentCoder  parse_ohlcvs)r  r2  r  r  r  r  rK  
periodUnitr  r  r  r  r  nowr  s                  r  fetch_ohlcvzonetrading.fetch_ohlcv%  sc    	V$$%%doyAA
!'',, 00;;$t+=E%d| 
 
 =##%%C LL--GDM"ll31A+ABBGFOO"ll511GFO LL%9I)J)JKKGDM;;DKKQW<X<XYY   69eUKKKr  c                    |                      |di           }|                      |d|          }|                     |d          }|)|                     |                     |d                    }|                     |dd          }|                     |d          }|                     |d          }|                     |d	          }|                     |d
          }	|                     |	|d          }
|                     |d          }d }d }|]|                     |d          }|                     |          }|                     |d          }|||d}|                     |d          }|                     | 	                    |dd          |                     |d          || 
                    |          |
d |||||||d|          S )Nr  tradetrade_timestampr   side
taker_sider>  r  ri  ro  r0  
fee_amountfee_currencyfee_percentage)rA  r'  ratefee_typetrade_idsequenceorder_id)r'   orderru  rv  r2  r8  r  r>  r  rA  takerOrMakerr  r  )rI  r  r  r"  safe_string_lower_2r  r#  safe_string_lower
safe_tradesafe_string_2r  )r  r  rK  feeInforu  r  priceStringamountString
costStringr  r2  feeCostStringr  r  feeCurrencyIdfeeCurrencyCodefeeRateStrings                    r  parse_tradezonetrading.parse_tradeO  s   N //%33w66%%e->??	t'7'7v'F'FGGI''v|DD&&ug66''x88%%eX66
##E+<==!!(FC88((,??$ ,,WnEEM"55mDDO ,,W6FGGM%+% C
  11':FFL$$UJ
CC%%eZ88"Y// "( 
  
   	r  c                 v   |                                   |                     |          }d|d         i}|D|                     |          |d<   |                     |                     |d                    |d<   |                     |                     ||                    }|                     ||||          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 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>`
        ro  r'   Nr  i  r  )rX  rK  r  r  !publicGetPriceTicksInstrumentCoder  parse_trades)r  r2  r  r  r  rK  r  r  s           r  fetch_tradeszonetrading.fetch_trades  s     	V$$vd|

  #ll511GFO LL%)B)BCCGDM99$++gv:V:VWW   65%@@@r  c                    |                      |dg           }d|i}t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |||<   |                     |          S )	Nbalancesr  r   currency_code	availablefreelockedused)rI  r   r!  r"  r#  accountsafe_balance)	r  r  r  r%  r&  balance
currencyIdr  r  s	            r  parse_balancezonetrading.parse_balance  s    ??8Z<<(#q#h--(( 	# 	#AqkG))'?CCJ**:66DllnnG"..wDDGFO"..wAAGFO"F4LL  (((r  c                 ~    |                                   |                     |          }|                     |          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>`
        )rX  privateGetAccountBalancesr  r  s      r  fetch_balancezonetrading.fetch_balance  s?     	11&99" !!(+++r  r'  c                     d }||d         }|                      |d          }|                      |d          }|                     |           |||d |dS )Nr  addressdestination_tag)r'  r  tagnetworkr  )r"  check_address)r  depositAddressr'  r  r  r  s         r  parse_deposit_addressz onetrading.parse_deposit_address  st    F#D"">9==~/@AA7###"
 
 	
r  r  c                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     ||          S )a=  
        create a currency deposit address
        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r'  r'   )rX  r'  privatePostAccountDepositCryptor  r  r  r  r  r'  r  r  s         r  create_deposit_addressz!onetrading.create_deposit_address  sr     	==&&
 77GV8T8TUU ))(H===r  c                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     ||          S )a9  
        fetch the deposit address for a currency associated with self account
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r  r'   )rX  r'  *privateGetAccountDepositCryptoCurrencyCoder  r  r  s         r  fetch_deposit_addressz onetrading.fetch_deposit_address  ss     	==&&Xd^
 BB4;;wX^C_C_`` ))(H===r  c                    |                                   i }d}| |                     |          }|d         |d<   |||d<   |G|                     |d          }|t          | j        dz             |                     |          |d<   |                     |                     ||                    }|                     |dg           }	| 	                    |	|||d	d
i          S )a  
        fetch all deposits made to an account
        :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'   r  max_page_sizer  zZ fetchDeposits() requires a "to" iso8601 string param with the since argument is specifiedr  deposit_historyr8  r  )
rX  r'  r"  r   r'   r  privateGetAccountDepositsr  	safe_listparse_transactions)
r  r  r  r  r  r  r'  r  r  depositHistorys
             r  fetch_depositszonetrading.fetch_deposits)  s    	
 }}T**H'/~GO$',GO$!!&$//Bz'  3O  )O  P  P  P"ll511GFO11$++gv2N2NOO> 2CRHH&&~xPVXaObcccr  c                    |                                   i }d}| |                     |          }|d         |d<   |||d<   |G|                     |d          }|t          | j        dz             |                     |          |d<   |                     |                     ||                    }|                     |dg           }	| 	                    |	|||d	d
i          S )a  
        fetch all withdrawals made from an account
        :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'   r  r  r  z] fetchWithdrawals() requires a "to" iso8601 string param with the since argument is specifiedr  withdrawal_historyr8  
withdrawal)
rX  r'  r"  r   r'   r  privateGetAccountWithdrawalsr  r
  r  )
r  r  r  r  r  r  r'  r  r  withdrawalHistorys
             r  fetch_withdrawalszonetrading.fetch_withdrawalsc  s    	
 }}T**H'/~GO$',GO$!!&$//Bz'  3R  )R  S  S  S"ll511GFO44T[[&5Q5QRR@ !NN85I2NN&&'8(E5SY[gRhiiir  r  c                 h   |                      ||          \  }}|                     |           |                                  |                     |          }||                     ||          d}|                     | j        dg           }|                     ||          }	|	rdnd}
|	r6|                     |d          }|t          | j
        dz   |z   dz             nd	|i}|||d
<   ||d<    t          | |
          |                     ||                    }|                     ||          S )a  
        make a withdrawal
        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        )r'  r  r   privatePostAccountWithdrawFiat privatePostAccountWithdrawCryptopayout_account_idNz8 withdraw() requires a payout_account_id param for fiat z withdrawalsr  r  	recipient)handle_withdraw_tag_and_paramsr  rX  r'  currency_to_precisionrI  r   in_arrayr"  r   r'   rQ  r  parse_transaction)r  r  r  r  r  r  r'  r  r   isFiatr   payoutAccountIdr  r  s                 r  r{   zonetrading.withdraw  ss    99#vFFV7###==&&00v>>
 
 //$,;;tW--5;c11Ac 	-"..v7JKKO&'2l(los(s  wE  )E  F  F  F ' #G,I/2	+,#,GK (74((Wf)E)EFF$ %%h999r  c                    |                      |d          }|                     |d          }|                     |                      |d                    }|                      |d          }|                     ||          }d}|                     |dd          }d }	|                      |d          }
|                      |d	          }|1|                      |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S )Ntransaction_idr  r   r'  okr  r  r  r  r  )rA  r'  r  r'   r  r  r  addressFrom	addressTor  tagFromtagTostatusr8  updatedtxidblockchain_transaction_idcommentinternal)ru  rv  r  )r"  rJ  r  safe_currencysafe_number_2r#  r  )r  transactionr'  r'   r  ru  r  r&  feeCostr  r#  r%  r  r  s                 r  r  zonetrading.parse_transaction  s   J k+;<<!!+x88NN4#3#3K#H#HII	%%k:>>
%%j(;;$$[,FF$$[+>>	  .?@@ ,,[.*UUM"55mDDO+ C
K
"
 (
 f	

 t
 y
 4
 
 5
 t
 U
 f
 D
 t
 D$$[2MNN
  t!
" #
$ #Y//)
 
 
 	
r  c           
      H    dddddddddd	}|                      |||          S )Nr  closedcanceledrejectedfailed	triggered)	FILLEDFILLED_FULLYFILLED_CLOSEDFILLED_REJECTEDOPENREJECTEDCLOSEDFAILEDSTOP_TRIGGEREDr"  )r  r&  statusess      r  parse_order_statuszonetrading.parse_order_status"  sC    $')" )

 

 &&999r  c                 *   |                      |d|          }|                     |d          }|                     |d          }|                     |                     |d                    }|                     |                     |d                    }|                     |          }|                     |d          }	|                     |	|d          }
|                     |d          }|                     |d	          }|                     |d
          }|                     |d          }|                     |d          }|                     |                     |d                    }|                     |d          }|                      |d          }|                      |dg           }|                     i 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  	client_idr   r&  ro  r0  r>  r  filled_amountr  r8  time_in_forcetrigger_priceis_post_onlytradesr'   clientOrderIdr  ru  rv  lastTradeTimestampr2  timeInForcepostOnly	stopPricetriggerPricerA  r  )filled	remainingr&  rH  )
rI  r"  r  rA  r  r  parse_time_in_forcerJ  
safe_orderr  )r  r  rK  rawOrderr'   rI  ru  	rawStatusr&  r  r2  r>  r  rO  r  r8  rK  rM  rL  	rawTradess                       r  parse_orderzonetrading.parse_order0  s   F ??5'599h
33((;??NN4#3#3Hf#E#EFF	++D,<,<Xx,P,PQQ	((33##H.?@@!!(FC88  733!!(H55!!(O<<%%h77%%h77..t/?/?//Z/Z[[$$X??	??8^<<OOE8R88	  
" 
] 
 E 
 	 

 Y// 
 !$ 
 f 
 D 
 ; 
  
 D 
 U 
  
 I 
 f 
  D! 
" t# 
$ - 
  
  
. /  	r  c                 >    ddddd}|                      |||          S )NGTCGTTIOCFOK)GOOD_TILL_CANCELLEDGOOD_TILL_TIMEIMMEDIATE_OR_CANCELLEDFILL_OR_KILLr?  )r  rK  timeInForcess      r  rQ  zonetrading.parse_time_in_force  s4    #(#&+!	
 
 k;GGGr  r8  r  r>  c                 D   |                                   |                     |          }|                                }|d         ||                                |                     ||          d}	d}
|dk    s|dk    rd}
|                     |g d          }|T|d	k    rt          | j        d
z             |                     ||          |	d<   d|	d<   |                     |g d          }n#|dk    rt          | j        dz   |z   dz             |
r|                     ||          |	d<   | 
                    |dd          }|||	d<   |                     |ddg          }|                     |                     |	|                    }|                     ||          S )a  
        create a trade order
        :see: https://docs.onetrading.com/#create-order
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or '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 fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: onetrading only does stop limit orders and does not do stop market
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r'   )ro  r8  r  r  FLIMITSTOPT)rN  rF  rM  NMARKETz? createOrder() cannot place stop market orders, only stop limitrF  r8  z1 createOrder() requires a triggerPrice param for z ordersr>  rI  rC  )rX  rK  upperamount_to_precisionsafe_number_nr   r'   price_to_precisionrP  r   r  privatePostAccountOrdersr  rV  )r  r2  r8  r  r  r>  r  rK  uppercaseTyper  priceIsRequiredrN  rI  r  s                 r  create_orderzonetrading.create_order  s    	V$$

%d|!JJLL..vv>>	
 
  G##}'>'>"O))&2`2`2`aa#(( +l!lmmm'+'>'>v|'T'TGO$$GFOYYv'U'U'UVVFFf$$#DG.a$adh$hkt$tuuu 	F#66vuEEGG**6?KPP$#0GK YYv'EFFF00Wf1M1MNN  &111r  r'   c                    |                                   |                     |dd          }|                     |ddg          }d}i }|d}||d<   n||d<    t          | |          |                     ||                    }|S )a2  
        cancels an open order
        :param str id: order id
        :param str symbol: not used by bitmex cancelOrder()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rI  rC  !privateDeleteAccountOrdersOrderIdN(privateDeleteAccountOrdersClientClientIdr  )rX  r  rP  rQ  r  )r  r'   r2  r  rI  r   r  r  s           r  cancel_orderzonetrading.cancel_order  s     	**6?KPP6O[#ABB4$?F#0GK  "$GJ(74((Wf)E)EFF r  c                     |                                   i }| |                     |          }|d         |d<   |                     |                     ||                    }|S )ab  
        cancel all open orders
        :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
        :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>`
        Nr'   ro  )rX  rK  privateDeleteAccountOrdersr  )r  r2  r  r  rK  r  s         r  cancel_all_orderszonetrading.cancel_all_orders  si     	[[((F)/G%&224;;w3O3OPP r  c                     |                                   dd                    |          i}|                     |                     ||                    }|S )aF  
        cancel multiple orders
        :param str[] ids: order ids
        :param str symbol: unified market symbol, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        ids,)rX  joinrr  r  )r  ru  r2  r  r  r  s         r  cancel_orderszonetrading.cancel_orders  sV     	388C==
 224;;w3O3OPP r  c                     |                                   d|i}|                     |                     ||                    }|                     |          S )a.  
        fetches information on an order made by the user
        :param str symbol: not used by onetrading 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  )rX  privateGetAccountOrdersOrderIdr  rV  )r  r'   r2  r  r  r  s         r  fetch_orderzonetrading.fetch_order&  s\     	
 66t{{7F7S7STTT )))r  c                    |                                   i }d}| |                     |          }|d         |d<   |G|                     |d          }|t          | j        dz             |                     |          |d<   |||d<   |                     |                     ||                    }|                     |dg           }	| 	                    |	|||          S )	a  
        fetch all unfilled currently open 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>`
        Nr'   ro  r  zs fetchOpenOrders() requires a "to" iso8601 string param with the since argument is specified, max range is 100 daysr  r  order_history)
rX  rK  r"  r   r'   r  privateGetAccountOrdersr  r
  parse_orders)
r  r2  r  r  r  r  rK  r  r  orderHistorys
             r  fetch_open_orderszonetrading.fetch_open_orders]  s    		
 [[((F)/G%&!!&$//Bz'  3h  )h  i  i  i"ll511GFO',GO$//GV0L0LMM` ~~hDD  vueDDDr  c           	      b    ddi}|                      ||||                     ||                    S )a  
        fetches information on multiple closed 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>`
        with_cancelled_and_rejectedT)r  r  )r  r2  r  r  r  r  s         r  fetch_closed_orderszonetrading.fetch_closed_orders  s;     *4
 %%feUDKKQW<X<XYYYr  c                 "   |                                   d|i}|||d<   |                     |                     ||                    }|                     |dg           }d}	||                     |          }	|                     ||	||          S )a  
        fetch all the trades made from a single order
        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        r  Nr  trade_history)rX  $privateGetAccountOrdersOrderIdTradesr  rI  rK  r  )
r  r'   r2  r  r  r  r  r  tradeHistoryrK  s
             r  fetch_order_tradeszonetrading.fetch_order_trades  s     	

 ',GO$<<T[[RX=Y=YZZ> x"EE[[((F  vueDDDr  c                    |                                   i }d}| |                     |          }|d         |d<   |G|                     |d          }|t          | j        dz             |                     |          |d<   |||d<   |                     |                     ||                    }|                     |dg           }	| 	                    |	|||          S )	a  
        fetch all trades made by the user
        :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'   ro  r  zq fetchMyTrades() requires a "to" iso8601 string param with the since argument is specified, max range is 100 daysr  r  r  )
rX  rK  r"  r   r'   r  privateGetAccountTradesr  r
  r  )
r  r2  r  r  r  r  rK  r  r  r  s
             r  fetch_my_tradeszonetrading.fetch_my_trades  s    	
 [[((F)/G%&!!&$//Bz'  3f  )f  g  g  g"ll511GFO',GO$//GV0L0LMM> ~~hDD  vueDDDr  r   GETc                    | j         d         |         dz   | j        z   dz   |                     ||          z   }|                     ||                     |                    }|dk    r|r|d|                     |          z   z  }ne|dk    r_|                                  dd| j        z   d}|d	k    r|                     |          }d|d
<   n|r|d|                     |          z   z  }||||dS )Nr   r3  r   ?r   zapplication/jsonzBearer )AcceptAuthorizationPOSTzContent-Type)urlr   bodyheaders)	r   r,   implode_paramsrP  extract_params	urlencodecheck_required_credentialsr   json)	r  pathr   r   r  r  r  r  querys	            r  signzonetrading.signR  s   is#c)DL83>ATATUY[aAbAbb		&$"5"5d";";<<(?? 3sT^^E2222I++---,!*T[!8 G yy''*<'' 73!6!666CfdwOOOr  c
                     |d S |                      |d          }
|
`| j        dz   |z   }|                     | j        d         |
|           |                     | j        d         |
|           t          |          d S )Nerror r   r   )r"  r'   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r  r  reasonr  r   r  r  r  requestHeadersrequestBodymessagefeedbacks               r  handle_errorszonetrading.handle_errorsf  s    4 ""8W55w}t+H001I7T\]]]001I7T\]]])))tr  )N)A__name__
__module____qualname__r  r  r   r(  r   r	   r,  rN  r   rR  r_  rg  rZ  r   r  strr  r   r   r  r   r   r  listr  r  r   r  r  r   r  r  r   r  r  r  r   r   r  r  floatr{   r  rA  r   rV  rQ  r   r   r
   rl  rp  rs  rx  r{  r  r  r  r  r  r  __classcell__)r  s   @r  r%   r%      sn       \ \ \ \ \| !# ; ; ; ; ') $ $Z $ $ $ $L $& , ,$v, , , , ,*9
f 9
 9
 9
 9
v )+ - -{ - - - - 02 & & & &P 13 + + + +Z
 
 
 
 
 
"2 26 2V 2 2 2 2h 02 3 33 3f 3 3 3 3B 04B #G #GW #G7 #G #G #G #GJ :>b No Nos No3 NoY No No No No`(
 (
 (
4 (
 (
 (
 (
T 26DW[df (L (L# (Lc (LQT (Lkoptku (L (L (L (LTM M M5 M M M M^ 6:UW $A $A3 $As $A# $A\`af\g $A $A $A $AL) ) ) ) ) $& , ,( , , , ,4
 
h 
 
 
 
 8: > >3 > > > >. 79 > ># > > > >0 *.Dt\^ 8d 8d3 8dc 8d 8dcghsct 8d 8d 8d 8dt -1tRV_a 9j 9jc 9j 9jC 9jfjkvfw 9j 9j 9j 9jv ?C2 5: 5:S 5:% 5: 5: 5: 5:nK
 K
x K
; K
 K
 K
 K
Z: : :k k k5 k k k kZH H H gksu >2 >23 >2i >2y >2RW >2`c >2 >2 >2 >2@ 37r  s C    0 /32      ( 04B      ( 26b 5* 5*c 5*3 5* 5* 5* 5*n /3TXac pE pE pE3 pEc pEhlmrhs pE pE pE pEd 154VZce Z Z# ZS ZPS Zjnotju Z Z Z Z 9=4^bkm 5E 5ES 5E# 5ES 5EX[ 5E 5E 5E 5En -1tRV_a <E <Ec <E <EC <E <E <E <E| &eBSW P P P P(      r  r%   N))ccxt.base.exchanger   ccxt.abstract.onetradingr   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   r   r   r   r   r   r   r    r!   ccxt.base.decimal_to_precisionr"   ccxt.base.preciser#   r%    r  r  <module>r     sK   ( ' ' ' ' ' 0 0 0 0 0 0 u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u  u       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . ' ' ' ' ' ' . . . . . . + + + + + + ) ) ) ) ) ) * * * * * * + + + + + + 1 1 1 1 1 1 4 4 4 4 4 4 % % % % % %[ [ [ [ [; [ [ [ [ [r  