
    !: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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)  G d dee      Z*y)    )Exchange)ImplicitAPI)AnyBalances
CurrenciesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTradingFeesTransaction)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)InsufficientFunds)InvalidOrder)NotSupported)RateLimitExceeded)	TICK_SIZE)Precisec                       e Zd Zdef fdZ fdZd Zd Zi fdefdZ	de
fdZi fdee
   fdZi fdefd	Zi fd
ZdUde
defdZddi fdedededee   fdZdddi fdededefdZdi fdededefdZi fdefdZdUde
defdZdddi fdedededee   fdZdUd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#dUde
fdZ$di fde!fdZ%i fdefdZ&dUde'de
de(fd Z)di fde!de*fd!Z+i fdefd"Z,d# Z-d$ Z.d% Z/d& Z0dVd'Z1d( Z2d) Z3d* Z4d+ Z5d, Z6d-efd.Z7d/ Z8d0 Z9d1 Z:di fded2e;d3e<d4e=d5e>f
d6Z?ddi fd7eded2e;d3e<d4e>d5e>fd8Z@d9 ZAdUde
deBfd:ZCd; ZDdi fd7edefd<ZEdddi fdedededeeB   fd=ZFdddi fdedededeeB   fd>ZGdi fdefd?ZHdi fd7edefd@ZIdi fdAee   defdBZJi fdeKfdCZLdUde
fdDZMdi fde!deeN   fdEZOdF ZPdi fdGed4e=d-edeQfdHZRdUdIe'dJeSdeQfdKZTdLefdMZUdNedOe'fdPZVdQ ZWdRdSi ddfdTZX xZYS )Wvertexreturnc                 	   | j                  t        t        |          i dddddg 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d)dd*dd+dd,dd-dd.dd/dd0dd1di d2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBdi dCd dDddEddFddGddHddIddJddKddLddMddNddOddPddQddRddSdi dTddUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcdddddddddddedfdgdhdidjdkdldmdndndo	dpdqdrdsdtdudvdwdxdydzd{d|d}d~dwdddzd{dddddddddiiddddddddddddidwddddddidddddidzd{d| j	                  d      | j	                  d      d| j	                  d      | j	                  d      dddddddd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        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        t        t        t        t        t        di ddt        i dddddddddd ddd dddddddddddddd dddd dddddddddddddd d ddid	ddiddid d d d d dd      S (  Nidr'   nameVertex	countriesversionv1	rateLimit2   	certifiedFproTdexhasCORSspotmarginswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelAllOrdersAftercancelOrdercancelOrderscancelOrdersForSymbolscloseAllPositionsclosePositioncreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreateReduceOnlyOrdercreateStopOrdercreateTriggerOrder	editOrderfetchAccountsfetchBalancefetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledOrdersfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchLeverageTiersfetchLiquidationsfetchMarginModefetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyLiquidationsfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionModefetchPositionsfetchPositionsRiskfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransferfetchTransfersfetchWithdrawalfetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMargin)sandboxsetLeveragesetMarginModesetPositionModetransferwithdraw
timeframes<   i,  i  i  i   i@8  iQ i:	 )	1m5m15m1h2h4h1d1w1Mhostnamezvertexprotocol.comurlszQhttps://github.com/ccxt/ccxt/assets/43336371/bd04a0fa-3b48-47b6-9d8b-124954d520a8z"https://archive.prod.{hostname}/v1z"https://gateway.prod.{hostname}/v1z"https://trigger.prod.{hostname}/v1)archivegatewaytriggerz"https://archive.prod.{hostname}/v2z"https://gateway.prod.{hostname}/v2)r   r   )r/   v2z*https://archive.sepolia-test.{hostname}/v1z*https://gateway.sepolia-test.{hostname}/v1z*https://trigger.sepolia-test.{hostname}/v1z*https://archive.sepolia-test.{hostname}/v2z*https://gateway.sepolia-test.{hostname}/v2zhttps://vertexprotocol.com/z https://docs.vertexprotocol.com/z+https://docs.vertexprotocol.com/basics/feeszRhttps://app.vertexprotocol.com?referrer=0xCfC9BaB96a2eA3d3c3F031c005e82E1D9F295aC1)logoapitestwwwdocfeesreferralr   post    )querysymbolstime)r   execute)getr   )r   r   r   )tickers	contractstradesvrtxgK=U?)assetspairs	orderbookr   z0.0002)takermaker)r9   r7   requiredCredentials)apiKeysecretwalletAddress
privateKey
exceptions1000101510011002100320002001200220032004200520062007200820092010201120122013201420152016201720192020202120222023202420252026202720282029203020312033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207630003001300230034000)40014002400340045000)exactbroadprecisionModer      ,__E )defaultTypesandboxModetimeDifferencebrokerId)IOCFOKPOGTD)
marginModetriggerPricetriggerDirectiontriggerPriceTypestopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergi  i )r&  limitdaysBack	untilDayssymbolRequired)r&  r   r/  r8  )r&  r5  r   r/  r8  r5    )	r   rI   rJ   rn   rt   rs   rv   rU   ro   extendsdefault)linearinverse)r;  r7   r9   r:   )commonCurrenciesoptionsfeatures)deep_extendsuperr'   describeparse_numberr#   r   r!   r   r    r   r   r$   )self	__class__s    E/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/vertex.pyrC  zvertex.describe   sB   fd < > uA
(uA
HuA
 uA
 t	uA

 uA
 uA
 4uA
 4uA
  \\\ %\ 	\
 $\ %\ U\ $U\ '\ "4\ '\ t\ \ )%\ $U\   !\" /#\$ ,U%\& 0'\( t)\* +\, (-\. "4/\0 %d1\2 U3\4  5\6 7\8 &u9\: +E;\< )%=\> &u?\@ $UA\B 'C\D (E\F "4G\H &uI\J (K\L  M\N *5O\P +EQ\R &uS\T #DU\V *5W\X $TY\Z "5[\\ *5]\^ +E_\` ua\b  c\d %ee\f $Ug\h "4i\j +Ek\l m\n !%o\p &uq\r  s\t du\v $Tw\x +Ey\z %d{\| "4}\~ d\@ !$A\B tC\D #EE\F  G\H $UI\J !$K\L %eM\N )%O\P tQ\R uS\T U\V TW\X tY\Z "5[\\ #D]\^  _\` !%a\b "5c\d #Ee\f g\h #Ei\j &uk\l  $!&#(! w\uA
L 
MuA
b ,cuA
d k $H#G#G $H#G
 $P#O#O $P#O
 59Ep7euA
^  !  &''($%  &''(!
  '(%&! #4 '()*&'$%	   &,%&)*  3*_uA
t !..x8!..x8
 "..x8!..x8	uuA
H "!%"	$IuA
T [-[-[ ,[ ,	[
 ,[ L[ L[ L[ L[ L[ L[ L[ L[ L[ L[  L![" J#[$ J%[& L'[( ,)[* L+[, L-[. L/[0 L1[2 L3[4 L5[6 L7[8 L9[: -;[< -=[> J?[@ /A[B /C[D /E[F JG[H LI[J LK[L LM[N LO[P LQ[R LS[T LU[V LW[X LY[Z L[[\ L][^ L_[` La[b Lc[d Le[f Lg[h Li[j Mk[l ,m[n Lo[p Lq[r Ls[t Lu[v Lw[x Ly[z L{[| L}[~ L[@ LA[B LC[D LE[F LG[H LI[J LK[L LM[N LO[P LQ[R LS[T LU[V LW[X LY[Z L[[\ L][^ L_[` La[b Jc[d Je[f Jg[h Ji[j Jk[l *))()u[x{_UuA
T	 YU	uA
V	!  &$"#,	  $&+(,,1,0)-+/6:#(#("&#'	( #($)$)+/26/4#()$, %)&+!$$*%)*/& ',#($)*.	# ',!$#'$)*/( $()-#_2h y
 "9  $	 ##{Ag	uA
 u u	    c                 J    t         t        |   |       || j                  d<   y )Nr  )rB  r'   set_sandbox_moder?  )rE  enabledrF  s     rG  rJ  zvertex.set_sandbox_mode  s     fd,W5&-]#rH  c                     t        |t              rt        j                  |d      S | j	                  |      }t        j                  |d      S N1000000000000000000)
isinstancestrr%   
string_mulnumber_to_stringrE  numnumStrs      rG  convert_to_x18zvertex.convert_to_x18  D    c3%%c+@AA&&s+!!&*?@@rH  c                     t        |t              rt        j                  |d      S | j	                  |      }t        j                  |d      S rM  )rO  rP  r%   
string_divrR  rS  s      rG  convert_from_x18zvertex.convert_from_x18  rW  rH  c                    i }| j                  | j                  ||            }i }t        dt        |            D ]  }| j	                  ||i       }| j                  |d      }||j                  d      dkD  r?| j                  |d      }| j                  |d      }	| j                  |	      }
||	|
d|d| j                  |d      | j                  |d      ddddd	ddd	d
d||
<    |S )a!  
        fetches all available currencies on an exchange

        https://docs.vertexprotocol.com/developer-resources/api/v2/assets

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r   	ticker_idNPERP
product_idsymbolcan_depositcan_withdrawminmax)amountr   )r*   r+   code	precisioninfoactivedepositr   networksfeelimits)	v2GatewayGetAssetsextendrangelen	safe_dictsafe_stringfindsafe_currency_code	safe_bool)rE  paramsrequestresponseresultidatatickerIdr*   r+   rf  s              rG  fetch_currencieszvertex.fetch_currencies  s    **4;;w+GH6 q#h-( 	A>>(Ar2D''k:H$8==+@1+D!!$5B##D(3D**40D!>>$> NN4@   $#
  $#!	F4L	< rH  c                 0   | j                  |d      }d}| j                  |      }| j                  |d      }| j                  |      }|}| j                  |      }|dz   |z   }	|dk(  }
|
 }|
 }|r"|j                  d      }|d   dz   |z   dz   |z   }	| j                  |d	      }| j                  |d
      }| j                  |d      }| j                  |d      }| j                  |d      }|
rd nd}|
rd nd}|
rd n| j	                  d      }i d| j                  |d      d|	d|d|d|
rd n|d|d|d|
rd n|d|
rdndd|
dd d|ddddddd|d||| j	                  | j                  |            | j	                  | j                  |            |d d d d | j	                  | j                  |            | j	                  | j                  |            d d d d!| j	                  | j                  |            d d!d d d!d d d!d"d |d#S )$NtypeUSDCr_  /r7   -r   :price_increment_x18size_incrementmin_sizetaker_fee_rate_x18maker_fee_rate_x18FT1r*   r^  basequotesettlebaseIdquoteIdsettleIdr9   r8   r:   r;   ri  contractr<  )re  pricerb  )r0  re  r  cost)r=  r   r   contractSizeexpiryexpiryDatetimestrike
optionTyperg  rm  createdrh  )rs  ru  splitsafe_numberrD  rZ  )rE  market
marketTyper  r  r  r  r  r  r_  r7   r  r9   splitSymbolpriceIncrementX18sizeIncrementX18
minSizeX18takerX18makerX18	isInverseisLinearr  s                         rG  parse_marketzvertex.parse_market  s   " %%ff5
''0!!&(3&&v.((2e#V#8x**S/K ^c)E1C7&@F ,,V5JK++F4DE%%fj9
##F,@A##F,@A!D	 4t $t4+<+<S+A2
$""6<82
f2
 D2
 U	2

 td&2
 f2
 w2
 H2
 tF&2
 D2
 d2
 D2
 e2
 e2
 d2
  !2
" h#2
$ !&&t'<'<X'FG&&t'<'<X'FG("++D,A,ABR,ST**4+@+@AR+ST  
  ,,T-B-B:-NO
  
  $ c2
 2	
rH  c                 v   ddi}| j                  | j                  ||            }| j                  |di       }| j                  |di       }t        |j	                               }g }t        dt        |            D ]:  }||   }	| j                  ||	i       }
|j                  | j                  |
             < |S )a/  
        retrieves data on all markets for vertex

        https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/symbols

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r  r   r|  r   )	v1GatewayGetQueryro  rr  listkeysrp  rq  appendr  )rE  rw  rx  ry  r|  marketsr   rz  r{  r_  	rawMarkets              rG  fetch_marketszvertex.fetch_marketsB  s     I
 ))$++gv*FG2 ~~h3..y"5w||~&q#g,' 	8AQZFw;IMM$++I67	8 rH  c                 F    | j                  |      }| j                  |      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
        )v1GatewayGetTimeparse_to_int)rE  rw  ry  s      rG  
fetch_timezvertex.fetch_timeq  s%     ((0  **rH  c                     ddi}| j                  | j                  ||            }| j                  |d      }|dk(  rd}nd}|ddd|dS )	ah  
        the latest known information on the availability of the exchange API

        https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/status

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
        r  statusr|  ri  okerrorN)r  updatedetaurlrh  )r  ro  rs  )rE  rw  rx  ry  r  s        rG  fetch_statuszvertex.fetch_status{  sl     H
 ))$++gv*FG !!(F3XFF
 	
rH  Nr  c                 `   d }d }d }d }| j                  | j                  |d            }||d d}| j                  |dd      }| j                  |d      }	| j                  |d      }
|
| j	                  | j	                  |di       di       }d }d	|v r$| j                  | j	                  |d	i       d
      }n#| j                  | j	                  |di       d
      }| j                  |      }| j	                  |di       }| j                  | j                  |d            }| j                  | j                  |d            }t        j                  |d      rd}nd}n| j                  |d      }|j                  d      }|d   j                  d      }|d   |d   z   }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |d      }t        j                  |      }|d   }| j                  ||
| j                  |
      ||||d |	d d ||d|      S )Nrl  )r  currencytrade_idsubmission_idxdigest	timestamppre_balancer  perpr^  r7   orderpriceX18base_filled0sellbuyr\  _r   r  r   r  
trade_typer_  )r*   r  datetimer_  sider  re  r  r  takerOrMakerr  rl  rh  )rZ  rs  safe_string_2safe_timestamprr  safe_marketr%   	string_ltr  safe_string_lower
string_abs
safe_tradeiso8601)rE  trader  r  re  r  rl  feeCostr*   r  r  baseBalancemarketIdsubOrderr}  splitTickerIdr  r_  s                     rG  parse_tradezvertex.parse_trade  se   @ ''(8(8(FG C z3CD  1''{;	..}b)QSY[]^KH$++DNN;PR,SUab++DNN;PR,SUab%%h/F~~eWb9H))$*:*:8Z*PQE**4+;+;E=+QRF  -''{;H$NN3/M'*005K"1~a(88H%%h7F$$UG4E%%e];F))%>D##F+!"Y/  
  	rH  r_  sincer5  c                     | j                          | j                  |      }|d   dz   }d|i}|||d<   | j                  | j                  ||            }| j	                  ||||      S )a)  
        get the list of most recent trades for a particular symbol

        https://docs.vertexprotocol.com/developer-resources/api/v2/trades

        :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>`
        r  _USDCr\  r5  )load_marketsr  v2ArchiveGetTradesro  parse_trades)	rE  r_  r  r5  rw  r  r  rx  ry  s	            rG  fetch_tradeszvertex.fetch_trades  s     	V$(#g-
 $GG**4;;w+GH.   65%@@rH  c                    | j                          d}| j                  d|      \  }}d}d| j                  |      i}|)| j                  |      }| j	                  |d         g|d<   | j                  |d      }|| j                  |d      }||d<   |||d<   d	|i}	| j                  | j                  |	|            }
| j                  |
d	g       }| j                  |||||      S )
as  
        fetch all trades made by the user

        https://docs.vertexprotocol.com/developer-resources/api/archive-indexer/matches

        :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
        :param str [params.user]: user address, will default to self.walletAddress if not provided
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nrn   
subaccountr*   product_idsuntilmax_timer5  matches)r  handle_public_addressconvert_address_to_senderr  parse_to_numericsafe_integeromitv1ArchivePostro  	safe_listr  )rE  r_  r  r5  rw  userAddressr  matchesRequestr  rx  ry  r   s               rG  fetch_my_tradeszvertex.fetch_my_tradesA  s    	"88&QV$88E
 [[(F-1-B-B6$<-P,QN=)!!&'2YYvw/F).N:&&+N7#~
 %%dkk'6&BCX )R8  vFFrH  c                     | j                          | j                  |      }|d   dz   }|d}||d}| j                  | j                  ||            }| j	                  |d      }| j                  |||dd      S )aB  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://docs.vertexprotocol.com/developer-resources/api/v2/orderbook

        :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  d   )r\  depthr  bidsasks)r  r  v2GatewayGetOrderbookro  r  parse_order_book)	rE  r_  r5  rw  r  r  rx  ry  r  s	            rG  fetch_order_bookzvertex.fetch_order_book  s     	V$(#g-=E!
 --dkk'6.JKN %%h<	$$Xvy&&QQrH  c           
      Z   | j                          d}| j                  d|      \  }}d| j                  |      d}| j                  | j	                  ||            }| j                  |di       }| j                  |dg       }| j                  |dg       }i }t        dt        |            D ]{  }	| j                  | j                  |	            }
|
d	   )|
d
   }||| j                  | j                  ||	               | j                  | j                  ||	               ddd||<   } |S )a  
        fetch the trading fees for multiple markets

        https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/fee-rates

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.user]: user address, will default to self.walletAddress if not provided
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        Nr   	fee_rates)r  senderr|  maker_fee_rates_x18taker_fee_rates_x18r   r*   r_  TF)rh  r_  r   r   
percentage	tierBased)r  r  r  r  ro  rr  r  rp  rq  r  rR  rD  rZ  )rE  rw  r  rx  ry  r|  r   r   rz  r{  r  r_  s               rG  fetch_trading_feeszvertex.fetch_trading_feesN  sF    	"889KVTV44[A
 ))$++gv*FGB ~~h3t%:B?t%:B?q#e*% 	A%%d&;&;A&>?Fd|#H%F  **4+@+@q+JK**4+@+@q+JK""F6N	 rH  c                    | j                  |d      | j                  | j                  | j                  |d                  | j                  | j                  | j                  |d                  | j                  | j                  | j                  |d                  | j                  | j                  | j                  |d                  | j                  | j                  | j                  |d                  gS )Nr  open_x18high_x18low_x18	close_x18volume)r  rD  rZ  rs  )rE  ohlcvr  s      rG  parse_ohlcvzvertex.parse_ohlcv  s     {3d33D4D4DUJ4WXYd33D4D4DUJ4WXYd33D4D4DUI4VWXd33D4D4DUK4XYZd33D4D4DUH4UVW
 	
rH  r   c                    | j                          | j                  |      }| j                  |d         | j                  | j                  |      d}| j                  |d      }|| j                  |d      }||d<   |t        |d      |d<   d|i}	| j                  | j                  |	|            }
| j                  |
dg       }| j                  |||||      S )a  

        https://docs.vertexprotocol.com/developer-resources/api/archive-indexer/candlesticks

        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]: max=1000, max=100 when since is defined and is less than(now - (999 * (timeframe in ms)))
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        r*   )r^  granularityr  r  r9  r5  candlesticks)r  r  r  r  r   r  rc  r  ro  r  parse_ohlcvs)rE  r_  	timeframer  r5  rw  r  ohlcvRequestr  rx  ry  rowss               rG  fetch_ohlcvzvertex.fetch_ohlcv  s     	V$++F4L9,,T__iH
 !!&'2YYvw/F',L$$'t$4L!L
 %%dkk'6&BC: ~~h;  vy%GGrH  c                    | j                  |d      }|2| j                  |d      }| j                  | j                  |            }| j	                  |dd      }| j                  |d      }| j                  |d      }i d|d|d   d	|d
|dd dd dd dd d|d|d| j                  |      dd dd dd dd dd dd dd iS )Nfunding_ratefunding_rate_x18update_timenext_funding_rate_timestamp
mark_priceindex_pricerh  r_  	markPrice
indexPriceinterestRateestimatedSettlePricer  r  fundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r  rs  rD  rZ  safe_timestamp_2r  )rE  tickerr  r  fundingRateX18r   r  r  s           rG  parse_funding_ratezvertex.parse_funding_rate  sr   : &&v~>!--f6HIN++D,A,A.,QRK00Hef$$V\:	%%fm<

F
fX&
 
 *	

 D
 #D
 
 
 ;
  0
 t||,<=
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 	
rH  c                     | j                          | j                  |      }dd| j                  |d         ii}| j                  | j	                  ||            }| j                  ||      S )a|  
        fetch the current funding rate

        https://docs.vertexprotocol.com/developer-resources/api/archive-indexer/funding-rate

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        r  r^  r*   )r  r  r  r  ro  r,  )rE  r_  rw  r  rx  ry  s         rG  fetch_funding_ratezvertex.fetch_funding_rate  ss     	V$d//t=

 %%dkk'6&BC &&x88rH  r   c                    | j                          i }|| j                  |      }| j                  | j                  ||            }t	        |j                               }i }t        dt        |            D ]R  }||   }|j                  d      }	||   }
|	d   dz   }| j                  |      }| j                  |
|      }|d   }|||<   T | j                  |d|      S )a  
        fetches funding rates for multiple markets

        https://docs.vertexprotocol.com/developer-resources/api/v2/contracts

        :param str[] symbols: unified symbols of the markets to fetch the funding rates for, all market funding rates are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        r   r  
/USDC:USDCr_  )r  market_symbolsv2ArchiveGetContractsro  r  r  rp  rq  r  r  r,  filter_by_array)rE  r   rw  rx  ry  r  fundingRatesr{  r}  parsedTickerIdr|  r  r  r*  r_  s                  rG  fetch_funding_rateszvertex.fetch_funding_rates.  s     	))'2G--dkk'6.JK. HMMO$q#d)$ 	*AAwH%^^C0NH%D%a(<7H[[*F,,T6:FH%F#)L 	* ##L(GDDrH  c           	          | j                  |d      }| j                  | j                  ||      | j                  |d      | j                  |d      d d |d|      S )Nr\  open_interestopen_interest_usd)r_  openInterestAmountopenInterestValuer  r  rh  )rs  safe_open_interestsafe_symbolr  )rE  interestr  r  s       rG  parse_open_interestzvertex.parse_open_interest`  sm    . ##Hk:&&&&x8"&"2"28_"M!%!1!1(<O!P(
  	rH  c                    | j                          | j                  |      }| j                  |      }g }g }t        |j	                               }|^g }t        dt        |            D ]D  }||   }|j                  d      }	|	d   dz   }
| j                  |
|      r4|j                  |
       F t        dt        |            D ]  }||   }| j                  |      }| j                  ||i       }t        dt        |            D ]\  }| j                  ||         }|d   dz   }|d   |k(  s(|j                  |d          |j                  | j                  ||             ^  | j                  |d|      S )a  
        Retrieves the open interest for a list of symbols

        https://docs.vertexprotocol.com/developer-resources/api/v2/contracts

        :param str[] [symbols]: a list of unified CCXT market symbols
        :param dict [params]: exchange specific parameters
        :returns dict[]: a list of `open interest structures <https://docs.ccxt.com/#/?id=open-interest-structure>`
        r   r  r0  r  r  r  r_  )r  r1  r2  r  r  rp  rq  r  in_arrayr  r  rr  r  r?  r3  )rE  r   rw  ry  parsedSymbolsresultsr  yr}  r5  currentSymbolr{  r  marketInneropenInterestjr  s                    rG  fetch_open_interestszvertex.fetch_open_interests  s    	%%g.--f5. x}}'?G1c'l+ 2"1:!)!4 .q 1L @}}]G<NN=12 q#g,' 		SAqzH**84K>>(HbAL1c'l+ SWQZ0!&>G3z*h6!(()9:NN4#;#;L&#QRS			S ##GX}EErH  c                    | j                          | j                  |      }|d   st        | j                  dz         i }| j	                  | j                  ||            }|d   dz   }| j                  ||i       }| j                  ||      S )aw  
        Retrieves the open interest of a derivative trading pair

        https://docs.vertexprotocol.com/developer-resources/api/v2/contracts

        :param str symbol: Unified CCXT market symbol
        :param dict [params]: exchange specific parameters
        :returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
        r  z3 fetchOpenInterest() supports contract markets onlyr  r  )r  r  r   r*   r2  ro  rr  r?  )rE  r_  rw  r  rx  ry  r}  rG  s           rG  fetch_open_interestzvertex.fetch_open_interest  s     	V$j!TWW'\\]]--dkk'6.JK. &>G+~~h"=''f==rH  r*  c                    | j                  |d      }| j                  |d      }|dz   |z   }|j                  d      dkD  r|j                  dd      dz   }| j                  ||      }| j                  |d	      }| j	                  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| j                  |d      dd | j                  |d      | j                  |d      |d|      S )Nbase_currencyquote_currencyr  r]  r   z-PERPr   z:USDC
last_pricer_  r  r  highlowbid	bidVolumeask	askVolumevwapopencloselastpreviousClosechanger  price_change_percent_24haveragebase_volumequote_volume)
baseVolumequoteVolumerh  )rs  rt  replacer  safe_ticker)rE  r*  r  r  r  r  rY  s          rG  parse_tickerzvertex.parse_ticker  s    8  )9:#:%99Vq ''4w>H!!(F35 !
fX&!
!
 !
 D	!

 4!
 4!
 !
 4!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $**63MN!!
" t#!
$ **6=A++FNC)!
* + 	rH  c                     | j                          | j                  |dddd      }i }| j                  | j                  ||            }t	        |j                               }| j                  ||      S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://docs.vertexprotocol.com/developer-resources/api/v2/tickers

        :param str[] [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>`
        NT)r  r1  v2ArchiveGetTickersro  r  valuesparse_tickers)rE  r   rw  rx  ry  r   s         rG  fetch_tickerszvertex.fetch_tickers  sn     	%%gtT4F++DKK,HI. x()!!'733rH  c                     | j                  | j                  d      }||S ddi}| j                  | j                  ||            }| j                  |di       }|| j                  d<   |S )Nv1contractsr  r   r|  )rr  r?  r  ro  )rE  rw  cachedContractsrx  ry  r|  s         rG  query_contractszvertex.query_contracts6  sp    ..}E&""K
 ))$++gv*FG~~h3&*]#rH  c                 B    | j                         | j                  d   z
  S )Nr   )millisecondsr?  )rE  s    rG  noncezvertex.nonceC  s       "T\\2B%CCCrH  c                 .    d| j                  |dd      z   S )N0xkeccakhex)hash)rE  messages     rG  hash_messagezvertex.hash_messageF  s    dii5999rH  c                     | j                  |dd  |dd  dd       }|d   }|d   }| j                  | j                  d|d               }d|j                  dd	      z   |j                  dd	      z   |z   S )
N	secp256k1rs   vrr  @   r  )ecdsaint_to_base16sumrjust)rE  ru  r   	signaturer{  r|  r~  s          rG  	sign_hashzvertex.sign_hashI  s    JJtCDz:cd+;[$O	cNcNtxxIcN;<aggb#&&S)99A==rH  c                 J    | j                  | j                  |      |dd        S )Nry  )r  rw  )rE  rv  r   s      rG  sign_messagezvertex.sign_messageP  s%    ~~d//8*ST:JKKrH  c                 r    |d|dd}| j                  |||      }| j                  || j                        }|S )Nr,   z0.0.1)chainIdr+   verifyingContractr.   )eth_encode_structured_datar  r   )rE  r  messageTypesrv  verifyingContractAddressdomainmsgr  s           rG  	build_sigzvertex.build_sigS  sG    !9	
 --flGL%%c4??;	rH  c                 Z    dddddddddddd	dd
d	dgi}| j                  ||||      S )Nr   r  bytes32r+   r  r  int128re  
expirationuint64rp  r  rE  rv  r  r  r  s        rG  build_create_order_sigzvertex.build_create_order_sig^  sQ    !95#X6!84%x8 (3
 ~~g|W>VWWrH  c                 B    dddddddgi}| j                  ||||      S )NListTriggerOrdersr  r  r  recvTimer  r  r  s        rG  build_list_trigger_tx_sigz vertex.build_list_trigger_tx_sigj  s9    !95#X6"
 ~~g|W>VWWrH  c                 J    ddddddddddgi}| j                  ||||      S )	NCancellationProductsr  r  r  
productIdsuint32[]rp  r  r  r  s        rG  build_cancel_all_orders_sigz"vertex.build_cancel_all_orders_sigs  sA    "!95%z: (3%
 ~~g|W>VWWrH  c                 R    ddddddddddd	d
dgi}| j                  ||||      S )NCancellationr  r  r  r  r  digestsz	bytes32[]rp  r  r  r  s        rG  build_cancel_orders_sigzvertex.build_cancel_orders_sig}  sI    !95%z:"K8 (3	
 ~~g|W>VWWrH  c                 R    ddddddddddd	d
dgi}| j                  ||||      S )NWithdrawCollateralr  r  r  	productIduint32re  uint128rp  r  r  r  s        rG  build_withdraw_sigzvertex.build_withdraw_sig  sI     !95$h7!95 (3	#
 ~~g|W>VWWrH  addressc                 0    |dz   }|j                  dd      S )N64656661756c74B   r  )ljust)rE  r  r  s      rG  r  z vertex.convert_address_to_sender  s    ++||B$$rH  c           
          || j                         }t        j                  t        j                  t        j                  | j	                  |      | j	                  |            d      d      S )N1048576r   )rp  r%   
string_addrQ  rR  )rE  nowr  s      rG  	get_noncezvertex.get_nonce  sx    ;**,C !!'"4"4W5G5GH]H]^aHbdhdydy  {E  eF  6G  IR  #S  U[  \  	\rH  c                     t        j                  | j                  |      d      }|dk(  rt        j                  |d      }n4|dk(  rt        j                  |d      }n|rt        j                  |d      }|rt        j                  |d      }|S )N86400ioc4611686018427387904fok9223372036854775808138350580552821637122305843009213693952)r%   r  rR  	string_or)rE  r  r-  postOnly
reduceOnlyr  s         rG  get_expirationzvertex.get_expiration  s    ''(=(=c(BGL
% **:7LMJE! **:7LMJ **:7MNJ **:7LMJrH  c                     | j                  |      }|dk(  r|dkD  rt        j                  |d      }|S |dk  rt        j                  |d      }|S )Nr  r   z-1)rR  r%   rQ  )rE  re  r  amountStrings       rG  
get_amountzvertex.get_amount  s[    ,,V46>z&11,E
  z&11,ErH  r  r  re  r  c           	      n   | j                          |j                         }|dk(  }|r|t        | j                  dz         | j	                          | j                  |      }	| j                  |	d         }
| j                         }| j                  |d      }| j                  |dg       }| j                  ||
      }|rdnd}| j                  |d|      }| j                  |d	d
      }| j                  |dd
      }| j                  |dd      }| j                  |d|      }| j                  |d      }|xs |}| j                         }| j                  |d      }|r|rt        | j                  dz         | j!                  ||||      }|rt#        j$                  |d      }| j'                  ||      }| j)                  | j*                        | j-                  | j/                  ||            | j-                  | j1                  ||            ||d}d|
|d   |d   |d   | j3                  |d         |d   d| j5                  |||      | j7                  | j8                  dd      di}| j;                  |g d      }d}|rYi }|| j-                  |      |d<   n|| j-                  |      |d<   ||d   d <   | j=                  | j?                  ||            }n!| jA                  | j?                  ||            }| jC                  |d!i       }| jE                  d| j                  |d"      i      S )#az  
        create a trade order

        https://docs.vertexprotocol.com/developer-resources/api/gateway/executes/place-order
        https://docs.vertexprotocol.com/developer-resources/api/trigger/executes/place-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 fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.timeInForce]: ioc, fok
        :param bool [params.postOnly]: True or False whether the order is post-only
        :param bool [params.reduceOnly]: True or False whether the order is reduce-only, only works for ioc and fok order
        :param float [params.triggerPrice]: The price at which a trigger order is triggered at
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  Nz9 createOrder() requires a price argument for market orderr*   chain_id
book_addrsr  r-  r  Fr  r'  	stopPricer*  r+  _ 2 reduceOnly not supported when postOnly is enabledr  r  r  re  r  rp  place_orderr  r  re  r  rp  r!  r  r^  r  r  r*   r-  r  r  r'  r  r*  r+  last_price_belowlast_price_abover   r|  r  )#check_required_credentialslowerr   r*   r  r  r  rm  rs  r  r  rv  r  rp  r  r"   r  r%   r  r  r  r   rV  price_to_precisionamount_to_precisionrR  r  r  r?  r  v1TriggerPostExecutero  v1GatewayPostExecuterr  
safe_order) rE  r_  r  r  re  r  rw  r  isMarketOrderr  r  r   r  bookAddressesr  defaultTimeInForcer-  r  r  r'  r*  r+  	isTriggerr  rp  r  r  r  rx  ry  r   r|  s                                    rG  create_orderzvertex.create_order  sX   & 	'')ZZ\
"h.U]#DGG.i$ijjV$$$VD\2((*	""9j9y,C#'#3#3M8#L '4U4,,V]DVW>>&*e<^^FL%@
))&.+N((,O**63DE"5o	jjlsE*
tww)]]^^((k8ZP
%%e-BCEvt444T5G5GH++D,C,CFE,RS))$*B*B6<*XY$
 &#Ho %j 1#Ho"&"7"7l8K"L"7^ "88Iab''jBRS
 6  $N  OG(.2.A.A-.P*+ ,.2.A.A/.R*+07GM"9-00Wf1MNH00Wf1MNH ~~h3$""42 
  	rH  r*   c                 \   | j                          |j                         }|dk(  }	|	r|t        | j                  dz         | j	                          | j                  |      }
| j                  |
d         }|	rdnd}| j                  |d|      }| j                  |dd      }| j                  |d	d      }| j                  |d
d      }| j                  |d|      }| j                  |d      }|xs |}| j                         }| j                  |d      }| j                  |dg       }| j                  ||      }| j                  |d      }| j                         }| j                  |d      }| j                  | j                         }|r|rt#        | j                  dz         |rt#        | j                  dz         | j%                  ||||      }| j'                  ||      }|| j)                  | j+                  ||            | j)                  | j-                  ||            ||d}||g|g|d}d|d   |d   |d   | j/                  |d         d| j1                  |||      ||d   |d   |d   | j/                  |d         |d   d| j3                  |||      | j5                  | j6                  dd      d d!i} | j9                  |g d"      }| j;                  | j=                  | |            }!| j?                  |!d#i       }"| jA                  d| j                  |"d$      i      S )%aG  
        edit a trade order

        https://docs.vertexprotocol.com/developer-resources/api/gateway/executes/cancel-and-place

        :param str id: cancel order id
        :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 fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.timeInForce]: ioc, fok
        :param bool [params.postOnly]: True or False whether the order is post-only
        :param bool [params.reduceOnly]: True or False whether the order is reduce-only, only works for ioc and fok order
        :param float [params.triggerPrice]: The price at which a trigger order is triggered at
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  Nz7 editOrder() requires a price argument for market orderr*   r  r-  r  Fr  r'  r  r*  r+  r  r  endpoint_addrr  r  z, editOrder() not supported for trigger orderr  r  r  r  rp  cancel_and_placer  r  r  rp  r  re  r  r!  r  r  )	cancel_txcancel_signaturer  r  r|  r  )!r  r  r   r*   r  r  r  r  rv  r  rs  rm  r  rp  r  r  r   r"   r  r  rV  r  r  rR  r  r  r  r?  r  r  ro  rr  r  )#rE  r*   r_  r  r  re  r  rw  r  r  r  r  r  r-  r  r  r'  r*  r+  r  r   r  r  verifyingContractAddressOrderverifyingContractAddressCancelr  rp  r  r  r  r  cancelsrx  ry  r|  s#                                      rG  
edit_orderzvertex.edit_order  sf   & 	'')ZZ\
"h.U]#DGG.g$ghhV$$$VD\2'4U4,,V]DVW>>&*e<^^FL%@
))&.+N((,O**63DE"5o	((*	""9j9y,C(,(8(8(Q%)-)9)9)_)U&jjlsE*//0B0BC
tww)]]^^tww)WWXX((k8ZP
vt4++D,C,CFE,RS))$*B*B6<*XY$
 #*t	
 %h/"),"7&y1!22773CD	 %)$@$@'Sq$r"*"'/$)*$5"'/&*&;&;E,<O&P!&w "&!<!<UGMj!k++DLL*FVW !
. 6  $N  O,,T[[&-IJ ~~h3$""42 
  	rH  c                     |iddi}t        |t              r| j                  |||      S | j                  |d      }|y| j                  |di       }| j                  |dd      }|dk(  ry	y|S )
NpendingrW  	cancelledcanceled	triggeredr  failuresuccessclosed)rO  rP  rs  rr  )rE  r  statusesstatusCancelledstatusTriggeredtriggeredStatuss         rG  parse_order_statuszvertex.parse_order_status  s    6H &#&''&&AA"nnV[AO*!"nnV["EO"..)TO)+rH  c           
         | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }d }| j                  |d      }	|	| j                  |di       }
| j                  |
di       }| j                  |
d      }| j                  |d      }| j                  |d      }| j                  |d	      }| j                  |
d
i       }| j	                  |g d      }| | j                  | j                  |            }| j                  ||      }|d   }d }| | j                  | j                  |            }d }| | j                  | j                  |            }d }| | j                  | j                  |            }d }|||dk  s|dk  rdnd}| j                  | j                  |d            }|dk(  }| j                  i d|d| j                  |d      dd d|d| j                  |      dd dd d|dd d|d|dd d|d|d |d|d!d d d || j                  |	      d d d"|      S )#Nr^  	placed_atre  	price_x18unfilled_amountr  r  r  
updated_atr   )price_aboveprice_belowr  r  r_  r   r  r  
order_typer$  rh  r*   r  clientOrderIdr  r  lastTradeTimestamplastUpdateTimestampr  r-  r  r  r  r  r'  r  )r]  filled	remainingr  rl  r   )rs  r  
safe_valuerr  safe_string_nr  rZ  r  parse_time_in_forcer  r  r  )rE  r  r  r  r  re  r  r  triggerPriceNumr  
outerOrder
innerOrderr   r'  r_  priceNum	amountNumremainingNumr  tif
isPostOnlys                        rG  parse_orderzvertex.parse_order  s"   H ##E<8''{;	!!%2  4$$U,=>	1w;J
GR@J''
LAH%%j(;F$$Z<E++E<@InnZB?G--g7}~L'"&"7"78M8Ml8["\!!(F3!,,T-B-B5-IJH	--d.C.CF.KLI 001F1Fy1QRL \%='!m|a/?6eD&&t'7'7|'LMTk
  
E 
$""5(3 
 T 
 	 

 Y/ 
 !$ 
 "4 
 f 
 D 
 3 
 
 
 $ 
 D 
 X 
 O 
  i! 
" D# 
$ %--f5/ 
0 1 	rH  c                 0    ddi}| j                  |||      S )N	POST_ONLYr$  )safe_string_upper)rE  r-  timeInForcess      rG  r  zvertex.parse_time_in_force  s%    
 %%lKMMrH  c                     | j                          | j                  |      }d| j                  |d         |d}| j                  | j	                  ||            }| j                  |d      }| j                  ||      S )a  
        fetches information on an order made by the user

        https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/order

        :param str id: the order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  r*   )r  r^  r  r|  )r  r  r  r  ro  rr  r  )rE  r*   r_  rw  r  rx  ry  r|  s           rG  fetch_orderzvertex.fetch_order  s     	V$++F4L9

 ))$++gv*FG& ~~h/f--rH  c                    | j                          | j                          d}| j                  d|      \  }}i }d}| j                  |dd      }| j	                  |ddg      }|(| j                  |      }| j                  |d         |d<   d}	|r| j                         }
| j                  |
d      }| j                  |
d      }| j                  |      | j                         d	z   d
}| j                  |||      |d<   |d   | j                  |d         d
|d<   d|d<   d|d<   | j                  |d      }| j	                  |d      }|||d<   |||d<   | j                  | j                  ||            }	nM| j!                  d|d       d|d<   | j                  |      |d<   | j#                  | j                  ||            }	| j%                  |	di       }| j'                  |d      }| j)                  ||||      S )a:  
        fetch all unfilled currently open orders

        https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/orders
        https://docs.vertexprotocol.com/developer-resources/api/trigger/queries/list-trigger-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
        :param boolean [params.trigger]: whether the order is a trigger/algo order
        :param str [params.user]: user address, will default to self.walletAddress if not provided
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nrs   stopr   r*   r^  r  r  r  r  r  r  r  r  txlist_trigger_ordersr  Tr  r  max_update_timer5  r_  subaccount_ordersr|  orders)r  r  r  safe_bool_2r  r  r  rm  rs  r  rp  r  rR  r  v1TriggerPostQueryro  check_required_argumentv1GatewayPostQueryrr  r  parse_orders)rE  r_  r  r5  rw  r  rx  r  r   ry  r   r  r  r  r  r|  r  s                    rG  fetch_open_orderszvertex.fetch_open_orders!  s4    	'')"889JFSV""669=6FI#67[[(F$($9$9&,$GGL!,,.I&&y*=G'+'7'7	?'S$88E JJL50B $(#A#A"gOg#hGK X, 11"Z.AGDM 4GFO!%GI%%fg6EYYvw/F -2)* #( ..t{{7F/KLH@ (():FHM1GFO $ > >{ KGH..t{{7F/KLH4 ~~h3h/  >>rH  c                    | j                          | j                  |dd      }| j                  |ddg      }|st        | j                  dz         d}| j                  d|      \  }}| j                          d}ddd}|(| j                  |      }| j                  |d	         |d
<   | j                         }	| j                  |	d      }
| j                  |	d      }| j                  |      | j                         dz   d}| j                  ||
|      |d<   |d   | j                  |d         d|d<   | j                  |d      }| j                  |d      }|||d<   |||d<   | j!                  | j#                  ||            }| j%                  |di       }| j'                  |d      }| j)                  ||||      S )a  
        fetches information on multiple orders made by the user

        https://docs.vertexprotocol.com/developer-resources/api/trigger/queries/list-trigger-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
        :param boolean [params.trigger]: whether the order is a trigger/algo order
        :param str [params.user]: user address, will default to self.walletAddress if not provided
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  r   z( fetchOrders only support trigger ordersNrv   r  F)r  r  r*   r^  r  r  r  r  r  r  r  r  r  r  r5  r|  r  )r  r  r  r"   r*   r  r  r  r  rm  rs  r  rp  r  rR  r  r  ro  rr  r  r   )rE  r_  r  r5  rw  r   r  r  rx  r   r  r  r  r  ry  r|  r  s                    rG  fetch_orderszvertex.fetch_orders  s    	'')""669=6FI#67tww)SSTT"88OV)
 [[(F$($9$9&,$GGL!((*	""9j9#'#3#3I#O 44[A

u,
  $==b'Kcdl--bn=
 !!&'267+).G%&$GG**4;;w+GH> ~~h3h/  >>rH  c                    | j                          | j                          |t        | j                  dz         | j	                  |      }|d   }| j                         }| j                  |d      }| j                  |d      }| j                         }| j                  |d      }	| j                  | j                        | j                  |      g|	d}
d|
d	   |
d
   | j                  |
d         d| j                  |
||      di}| j                  |dd      }| j                  |ddg      }d}|r#| j!                  | j#                  ||            }|S | j%                  | j#                  ||            }|S )a@  

        https://docs.vertexprotocol.com/developer-resources/api/gateway/executes/cancel-product-orders
        https://docs.vertexprotocol.com/developer-resources/api/trigger/executes/cancel-product-orders

        cancel all open orders in a market
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: whether the order is a trigger/algo order
        :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz- cancelAllOrders() requires a symbol argumentr*   r  r  r  )r  r  rp  cancel_product_ordersr  r  rp  r  r  r  r   )r  r  r   r*   r  rm  rs  rp  r  r  r   r  rR  r  r  r  r  ro  r  )rE  r_  rw  r  r  r   r  r  r  rp  r  rx  r   ry  s                 rG  cancel_all_orderszvertex.cancel_all_orders  s    	'')>#DGG.]$]^^V$$<((*	""9j9#'#3#3I#O jjlsE*44T5G5GH%%h/ 
 $%h/"),"7!22773CD
 "==gwPhi&	
 ""669=6FI#6700Wf1MNHD 3 00Wf1MNH2 rH  c                 *    | j                  |g||      S )a  
        cancels an open order

        https://docs.vertexprotocol.com/developer-resources/api/gateway/executes/cancel-orders
        https://docs.vertexprotocol.com/developer-resources/api/trigger/executes/cancel-orders

        :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>`
        )cancel_orders)rE  r*   r_  rw  s       rG  cancel_orderzvertex.cancel_order5	  s     !!2$77rH  idsc                 \   | j                          |t        | j                  dz         | j                          | j	                  |      }|d   }| j                         }| j                  |d      }| j                  |d      }| j                         }	| j                  |	d      }
| j                  | j                        g ||
d}|d   }| j                  |      }t        d	t        |            D ]  }|j                  |        d
|d   ||d   | j                  |d         d| j!                  |||      di}| j#                  |dd      }| j%                  |ddg      }d}|r#| j'                  | j)                  ||            }|S | j+                  | j)                  ||            }|S )a  
        cancel multiple orders

        https://docs.vertexprotocol.com/developer-resources/api/gateway/executes/cancel-orders
        https://docs.vertexprotocol.com/developer-resources/api/trigger/executes/cancel-orders

        :param str[] ids: order ids
        :param str [symbol]: unified market symbol
        :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>`
        Nz* cancelOrders() requires a symbol argumentr*   r  r  r  r  r  r   r)  r  r  rp  r&  r  r   )r  r   r*   r  r  rm  rs  rp  r  r  r   r  rp  rq  r  rR  r  r  r  r  ro  r  )rE  r+  r_  rw  r  r  r   r  r  r  rp  r  r  marketIdNumr{  rx  r   ry  s                     rG  r)  zvertex.cancel_ordersC	  s    	'')>#DGG.Z$Z[[V$$<((*	""9j9#'#3#3I#O jjlsE*44T5G5GH	
 \*
++H5q#c(# 	+Ak*	+ %h/",&y1!22773CD	 "99'7Lde

 ""669=6FI#6700Wf1MNHD 3 00Wf1MNH2 rH  c                    d}| j                  d|      \  }}d| j                  |      d}| j                  | j                  ||            }| j	                  |di       }| j                  |dg       }d|i}t        dt        |            D ]  }||   }	| j                  |	d	      }
| j                  |
      }|
d
k(  }|d   |s8|rdn| j                  |d      }| j                  |      }| j                         }| j	                  |	di       }| j                  | j                  |d            }||d<   |||<    | j                  |      S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/subaccount-info

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.user]: user address, will default to self.walletAddress if not provided
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        NrP   subaccount_infor  r  r|  spot_balancesrh  r   r^  r  r*   r  r  balancere  total)r  r  r  ro  rr  r  rp  rq  rs  r  ru  accountrZ  safe_balance)rE  rw  r  rx  ry  r|  balancesrz  r{  r2  r  r  isUsdcMarketIdr  rf  r4  tokenBalancer3  s                     rG  fetch_balancezvertex.fetch_balance	  si    "88PV%88E
 ))$++gv*FGf	 ~~h3>>$<(#q#h-( 	#AqkG''>H%%h/F%_Nd|#N .VT5E5Efh5WF**62DllnG>>'9bAL))$*:*:<*RSE$GG"F4L	#   ((rH  c                    | j                  |d      }| j                  |      }| j                  |di       }| j                  | j                  |d            }d}t	        j
                  |d      rd}| j                  i d|dd d	| j                  |d	      d
d dd dd dd dd dd dd dd dd dd dd dd d| j                  |      dd d d d d dd |d d d d d      S )Nr^  r2  re  r  r  r  rh  r*   r_  r  r  r  initialMargininitialMarginPercentagemaintenanceMarginmaintenanceMarginPercentage
entryPricenotionalr0  unrealizedPnlr   r  marginRatiocross)liquidationPricer  	lastPrice
collateralr&  
marginTyper  r  r.  r*  r+  )rs  r  rr  rZ  r%   r  safe_positionr  )rE  positionr  r  r2  r  r  s          rG  parse_positionzvertex.parse_position
  s   6 ##Hl;!!(+..9b9,,T-=-=gx-PQ\3/D!! #
H#
$#
 d&&vx8#
 	#

 #
 "4#
 T#
 &t#
  #
 *4#
 $#
 #
 #
 T#
 #
  D11,?!#
" 4##
$ !%!!#9#
  	rH  c                    d}| j                  d|      \  }}d| j                  |      d}| j                  | j                  ||            }| j	                  |di       }| j                  |dg       }| j                  |      }g }t        dt        |            D ]A  }	| j                  | j                  ||	   d      |      }
|
d   dk(  r1|j                  |
       C | j                  |d	|d
      S )a  
        fetch all open positions

        https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/subaccount-info

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.user]: user address, will default to self.walletAddress if not provided
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Nrz   r/  r0  r|  perp_balancesr   r  r_  F)r  r  r  ro  rr  r  r1  rp  rq  rJ  r  filter_by_array_positions)rE  r   rw  r  rx  ry  r|  	positionsrz  r{  rI  s              rG  fetch_positionszvertex.fetch_positions.  s     "889I6RV%88E
 ))$++gv*FG~~h3NN4"=	%%g.q#i.) 	$A{{4#6#6y|T#JFSH'1,MM(#		$
 --fhOOrH  c                 h    d| j                   d}| j                  |      }| j                  |di       S )Nnonces)r  r  r|  )r   r  rr  )rE  rx  ry  s      rG  query_nonceszvertex.query_noncesL  s<    ))
 ))'2 ~~h33rH  rf  c                    | j                          | j                          | j                  |      }| j                         }| j	                  |d      }| j	                  |d      }	| j                         }
| j                  |
d      }| j                  | j                        | j                  |d         t        |      |d}d|d   |d   |d	   | j                  |d
         d| j                  |||	      di}| j                  | j                  ||            }| j                  ||      }| j                  |||d      S )a  
        make a withdrawal

        https://docs.vertexprotocol.com/developer-resources/api/withdrawing-on-chain

        :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  tx_noncer*   )r  r  re  rp  withdraw_collateralr  r  re  rp  r&  )re  r  )r  r  r  rm  rs  rR  r  r  r   r  rP  rR  r  r  ro  parse_transaction)rE  rf  re  r  tagrw  r  r   r  r  rQ  rp  r   rx  ry  transactions                   rG  r   zvertex.withdraw^  sY    	'')==&((*	""9j9#'#3#3I#O ""$  444T5G5GH..x~>&k	
 "&x0!)+!6&x0!228G3DE	 "44XwH`a$

 ,,T[[&-IJ ,,Xx@{{;)
  	rH  rX  r  c                     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| j                  | j                  |d            dd dd d d d dS )Nrf  rh  r*   txidr  r  addressFromr  	addressTotagFromrW  tagTor  
withdrawalre  r  r  r  network)commentinternalrl  )parse_transaction_statusrs  )rE  rX  r  rf  s       rG  rV  zvertex.parse_transaction  s    F#D
K
$
 D
 	

 
 4
 t
 
 t
 4
 T
 L
 d
 
 d33D4D4D[RZ4[\
  t!
" t#
$ )
 	
rH  r  c                 0    ddi}| j                  |||      S )Nr  r  )rs  )rE  r  r  s      rG  rc  zvertex.parse_transaction_status  s%    t
 &&99rH  
methodNamerw  c                    d }| j                  ||d      \  }}|}| j                  ||d|      \  }}|	|dk7  r||gS | j                  | j                  dk7  r| j                  |gS t        | j                  dz   |z   dz         )Nuserr  r    zF() requires a user parameter inside 'params' or the wallet address set)handle_option_and_paramsr   r   r*   )rE  re  rw  userAuxrg  s        rG  r  zvertex.handle_public_address  s    77
FS44VZT[\f42:&>!*1C1Cr1I&&//#
 :  >H  !H  I  	IrH  c
                 <   |sy | j                  |dd      }
|
dk(  r| j                  |d      }| j                  dz   |z   }| j                  |d      }| j                  | j                  d   ||       | j	                  | j                  d   ||       t        |      y )	Nr  r   r  r  rh  
error_coder  r  )rs  r*   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )rE  rf  reasonr  methodheadersbodyry  requestHeadersrequestBodyr  rv  feedback	errorCodes                 rG  handle_errorszvertex.handle_errors  s     !!(Hb9Y&&x9Gww}t+H((<@I001I9V^_001I7T\]))rH  publicGETc                 N   | j                  |d      }| j                  |d      }| j                  | j                  d   |   |         }	|dk7  s|dk7  r|	dz   |z   }	|dk(  rdd	i}| j                  |      }n|r|	d
| j	                  |      z   z  }	|dk7  r|d|d<   nddi}|	|||dS )Nr   r   r   r/   r   r  POSTzContent-Typezapplication/json?r   gzipzAccept-Encoding)r  rp  rr  rq  )rs  implode_hostnamer   json	urlencode)
rE  pathr   rp  rw  rq  rr  r.   r  r  s
             rG  signzvertex.sign  s    ""3*Q'##DIIe$4W$=d$CDd?di/)d"CV 2G 99V$DsT^^F3339"-3)* &v fdwOOrH  )N)r   )Z__name__
__module____qualname__r   rC  rJ  rV  rZ  r   r~  r
   r  r   r  r	   r  r  r   r  rP  r  r   r  r   r  r   r  r  r  r  r   r,  r.  r   r   r6  r?  rI  rK  dictr   rd  r   ri  rm  rp  rw  r  r  r  r  r  r  r  r  r  r  r  r  r   r   floatr   r  r  r  r   r  r  r  r!  r#  r'  r*  r)  r   r9  rJ  r   rO  rR  r   r   r   rV  rc  r  rw  r  __classcell__)rF  s   @rG  r'   r'      s   v# vp.AA ') DZ DLY
f Y
v $& -$v, -^ !# +s + #% 
Bv v5 vp 6:UW +A3 +As +A# +A\`af\g +AZ -1tRV_a MGc MG MGC MG^ :>b <Rs <R3 <RY <R| )+ C{ CJ	
 	
4 	
 26DW[df :H# :Hc :HQT :Hkoptku :Hx7
 7
; 7
r 68 9 9K 96 6:" 0E7 0E 0EdF B 7;2 8FG 8Ft 79 (># (>T(4 ( (6 (T 04B %4W %47 %4N &( J D:>L	
XXX	X	X% %\ 
 gksu _3 _i _y _RW _`c _B `drv  @B dS d# dY di dY\ dlo dL"_ _5 _BN 26b &.c &.3 &.P /3TXac o? o?3 o?c o?hlmrhs o?b *.Dt\^ Q?3 Q?c Q? Q?cghmcn Q?f /32 N N` 37r 8s 8C 8 ;?r Rc RC Rh $& T)( T)l
?v ?B 26b Pw PT(^ P<4$ DHPR 2S 2% 2# 2Wb 2h 
T  
X  
Q\  
D:s :	I 	IT 	I &eBSW PrH  r'   N)+ccxt.base.exchanger   ccxt.abstract.vertexr   ccxt.base.typesr   r   r   r   r	   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#   ccxt.base.decimal_to_precisionr$   ccxt.base.preciser%   r'    rH  rG  <module>r     sg    ( , _  _  _  _  _  _  * 0 - . ' . ) ) . 4 %S/PX{ S/PrH  