
    eiJ                    X   d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZ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, d dl-m.Z.  G d dee          Z/dS )    )Exchange)ImplicitAPIN)AnyBalances
CurrenciesCurrencyIntLeverage	Leverages
MarginModeMarginModesMarketNumOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerTradeTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)	BadSymbol)OperationRejected)InsufficientFunds)InvalidOrder)OperationFailed)RateLimitExceeded)InvalidNonce)	TICK_SIZE)Precisec                   Z    e Zd Zdef fdZd Zd Zi fdZi fdZi fdZ	i fdZ
i fdee         fd	Zdefd
Zi fdefdZdedefdZi fdedefdZdodededefdZdi fdededefdZddi fdedededee         fdZdodededefdZdddi fdedededee         fdZdodedefdZ dddi fde!dedefdZ"dodefdZ#d Z$i fde%fd Z&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*dpd%ededefd&Z+dod'ed%ede(fd(Z,dddi fd"e!dededee-         fd)Z.dqd+ed,edefd-Z/i fd"ed.e0d/ed0ede-f
d1Z1dod2ed%ede-fd3Z2d4 Z3di fd"ed.e0d5ed6e!de(f
d7Z4di fded8e5d9e6d.e0d:e7f
d;Z8d< Z9d= Z:dddi fde!dedefd>Z;di fd?e<dee=         fd@Z>dodAedefdBZ?di fd?e<de@fdCZAdi fdDeBde!fdEZCdodDededeDfdFZEdi fd?ee!         deFfdGZGdodHedeHfdIZIdddi fde!dedefdJZJdodefdKZKdddi fde!dededeeL         fdLZMdddi fde!dededeeL         fdMZNdi fdNede!fdOZOdodPededeLfdQZPd8e!de!fdRZQdSe!defdTZRdUe!fdVZSdi fde!fdWZTdi fdNede!fdXZUdY ZVdZ ZWdrd[ed\ed]e!defd^ZXd_efd`ZYda ZZdsdcefddZ[de Z\dfdgi ddfdhZ]d"eBdiedjedkedledmefdnZ^ xZ_S )tgrvtreturnc                 
   d}d}|                      t          t          |                                           i d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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/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIidJdKdLdMdNdOdPdQdRdOdSdTdUgdVdWdXdYdZdZd[idYd\d\d\d]d]d\d\d]d]d]d]d]d^idYi d_d`dad`dbdZdcddde|df|dg|dh|di|dj|dk|dl|dm|dn|do|dpdZdqdZi drdZdsdZdtdZdu|dv|dw|dx|dy|dz|d{|d||d}|d~|d|d|d|d|||diddd ddddddddddddddidddddt          ddddddddddddd dddddddddddddd ddddddddddddd ddddddd d ddddd ddid	d ddid dd d ddddddddd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          i dt          dt          d t          dt          dt          dt          dt          dt          dt          dt          dt          d	t          d
t          dt          dt          dt          dt          t          t          t          t          t          di di          S (  N(      idr+   nameGRVT	countriesSG	rateLimit
   	certifiedFversionv1dexTprohasCORSspotmarginswapfutureoptioncancelAllOrderscancelOrdercreateOrderfetchBalancefetchCurrenciesfetchDepositsfetchFundingHistoryfetchFundingRateHistoryfetchLeveragesfetchMarginModesfetchMarkets)fetchMyTrades
fetchOHLCVfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionsfetchTickerfetchTradesfetchTransfersfetchWithdrawalssetLeveragesignIntransferwithdraw
timeframes1mCI_1_M3mCI_3_M5mCI_5_M15mCI_15_M30mCI_30_M1hCI_1_H2hCI_2_H4hCI_4_H6hCI_6_H8hCI_8_H12hCI_12_H1dCI_1_D3dCI_3_D5dCI_5_D1wCI_1_W2wCI_2_W3wCI_3_W4wCI_4_WurlszOhttps://github.com/user-attachments/assets/7a2e8108-29f6-45d1-822d-48eb1c8cbbe6zhttps://edge.grvt.io/zhttps://trades.grvt.io/zhttps://market-data.grvt.io/)privateEdgeprivateTradingpublicMarketzhttps://edge.testnet.grvt.io/zhttps://trades.testnet.grvt.io/z$https://market-data.testnet.grvt.io/zhttps://grvt.iozhttps://grvt.io/?ref=WBLS9D1zhttps://api-docs.grvt.io/zGhttps://help.grvt.io/en/articles/9614699-how-does-grvt-s-fee-model-work)logoapitestwwwreferraldocfeesr   postd   )auth/api_key/loginauth/wallet/login      )zfull/v1/instrumentzfull/v1/all_instrumentszfull/v1/instrumentszfull/v1/currencyzfull/v1/margin_ruleszfull/v1/minizfull/v1/tickerzfull/v1/bookzfull/v1/tradezfull/v1/trade_historyzfull/v1/klinezfull/v1/fundingzfull/v1/create_order   zfull/v1/cancel_orderzfull/v1/cancel_on_disconnectzfull/v1/cancel_all_orders2   zfull/v1/orderzfull/v1/order_historyzfull/v1/open_orderszfull/v1/fill_historyzfull/v1/positionszfull/v1/funding_payment_historyzfull/v1/get_sub_accountszfull/v1/account_summaryzfull/v1/account_historyz"full/v1/aggregated_account_summaryzfull/v1/funding_account_summaryzfull/v1/transferzfull/v1/deposit_historyzfull/v1/transfer_historyzfull/v1/withdrawalzfull/v1/withdrawal_historyzfull/v1/add_position_marginz"full/v1/get_position_margin_limitszfull/v1/set_position_configzfull/v1/set_initial_leveragez full/v1/get_all_initial_leveragezfull/v1/set_derisk_mm_ratiozfull/v1/vault_burn_tokenszfull/v1/vault_investzfull/v1/vault_investor_summaryzfull/v1/vault_redeemzfull/v1/vault_redeem_cancelz#full/v1/vault_view_redemption_queuez&full/v1/vault_manager_investor_historyzfull/v1/authorize_builder)zfull/v1/get_authorized_builderszfull/v1/builder_fill_history)r   r   r   options4216143114845356110900	7281264283248217)ARBONEAVAXCBASEBSCETHERC20OPSOLTRX	ZKSYNCERAKAIAr   *0x21d2a053495994b1132a38cd1171acec40c6741eg{Gz?)	accountIdnetworksnetworksById
builderFeebuilderbuilderRateprecisionModefeatures)lastmarkindexmedian)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedleveragemarketBuyRequiresPricemarketBuyByCostselfTradePreventiontrailingiceberg  )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   )r   r   r   r   r   r   r   r   )	sandboxrE   createOrdersrN   rQ   rP   rS   fetchClosedOrdersrO   extendsdefault)linearinverse)r   r>   r@   rA   requiredCredentials)
privateKeyapiKeysecretquoteJsonNumbers
exceptions100010011002100310041005100610081009101214002000200120022003200420052006200720082010201120122020202120302031203220402041204220502051206020612062206320642065207020802081208220832090210021012102210321042105210721082110211121122113211421152116211723002301240024012402300030043005300630213031400040024010500050015002500350045005600061007000700170027003700470057006700771007101710271037201745074517452745374547455)75007501750275037504)exactbroad)deep_extendsuperr+   describer(   r   r   r%   r    r"   r&   r'   r$   r!   r#   )selfrlOthersrlOrders	__class__s      G/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/grvt.pyrM  zgrvt.describe   s   dD 1 1 : : < < o?
&o?
Fo?
 $o?
 	o?

 o?
 to?
 4o?
 4o?
  !!! %! 	!
 %! %! "4! t! t! ! "4!  ! &t! *4! !$!  #D!!" #!$ "&"#'""&#"&##"&$(#  A! ! !o?
V  hh h y	
 y h h h h h y h h h h  h!" h#$ h% Wo?
~ i#:&?$B  $C&G$J 
 ):/ b# o?
d  .1-0   ./34/0,.02()*+(*)+13)++- !"  %.%.% 7% 4R	%
 (% 0% .x% /% ,X% :8% 3H% 28% 28% =h% :8%  +C!%" 23#% %$ 3C%%& -c'%( 5c)%* 6x+%, =h-%. 6x/%0 71%2 ;H3%4 6x5%6 4X7%8 /9%: 9(;%< /=%> 6x?%@ >xA%B A(C%D 4XE% %F <D8@I% % %'#1@ @eo?
h ! &$"  &!&"  ! #G#+ io?
V YWo?
X #&+(,$($(%)&*	- - -1)-+/6:#'#'"&#(	( ( #($)27+0/4$)#(3$ $6 %)&+!%$(%)*/& & ',#($)*/	# # ',!%#($)*/( ( ',!%$(%)#($)*/$ $ *.#y? ?@  "9  $	  ## QL LYo?
r ""$ $so?
| }o?
~ l/l,l Ol J	l
 -l Ol -l ,l -l Jl ,l ,l Ll Jl ,l  L!l" J#l l$ J%l& J'l( J)l* L+l, L-l. L/l0 L1l2 L3l4 L5l6 L7l8 L9l: L;l< L=l> L?l@ LAlB LClD IEl l lF IGlH LIlJ LKlL LMlN LOlP LQlR -SlT -UlV LWlX -YlZ -[l\ J]l^ J_l` -alb -cld Jelf Jgl l lh Jilj Jkll Lmln Lolp Lqlr Lslt Lulv Lwlx Lylz L{l| -}l~ -l@ -AlB -ClD -ElF IGlH -Il l lJ -KlL -MlN JOlP JQlR -SlT OUlV -WlX -YlZ -[l\ -]l^ -_l` -alb -cld -elf -glh -ilj -kl l ll Omln -olp -qlr -slt Oulv ,wlx Oylz -{l| -}l~ -l@ -AlB -ClD -ElF -GlH -IlJ -KlL -Ml lN .&---Wl l lZ ]o oo?
 o?
 o o o	    c                    ddddddddddddd	ddd
ddddddddgddddddddddddg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g
ddddddddddddg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gid!dd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gid(d)ddddddddgid*S )+NsubAccountIDuint64)r1   typeisMarketboolr   uint8postOnly
reduceOnlylegsz
OrderLeg[]nonceuint32
expirationint64assetIDuint256contractSize
limitPriceisBuyingContract)r   OrderLegr   addressr   )OrderWithBuilderFeerg  TransferfromAccountfromSubAccount	toAccounttoSubAccounttokenCurrency	numTokens
WithdrawaltoEthAddressAuthorizeBuildermainAccountIDbuilderAccountIDmaxFutureFeeRatemaxSpotFeeRateWalletLoginsigner)EIP712_ORDER_TYPEEIP712_ORDER_WITH_BUILDER_TYPEEIP712_TRANSFER_TYPEEIP712_WITHDRAWAL_TYPEEIP712_BUILDER_APPROVAL_TYPEEIP712_WALLETLOGIN_TYPE rN  s    rR  eip_definitionszgrvt.eip_definitions  s    ,X>>'88*G<<'88)6::#\::$h77)7;;	 '	::+X>>)8<</@@	" "( ,X>>'88*G<<'88)6::#\::&	::)8<<$h77)7;;( '	::+X>>)8<</@@	/ /* *I>>-x@@()<<+X>>,g>>((;;$h77)7;;	% *I>>+Y??,g>>((;;$h77)7;;	' #,i@@/CC/BB-x@@$h77)7;;%	- %y99$h77)7;; (ON
 N
 N	
rS  c                 |    | j         d uo
| j         dk    }| j        d uo
| j        dk    }|r|rt          d          |S )N z;You should provide either "privateKey" or "apikey & secret")r   r   r   )rN  privateKeyDefinedapiKeyDefineds      rR  uses_private_keyzgrvt.uses_private_key  sY     O47QDOr<Q4/EDK24E 	_ 	_ ]^^^  rS  c                     |                                  r+|                     |           |                     |           n|                     |           |                                  dS )a  
        sign in, must be called prior to using other authenticated methods

        https://api-docs.grvt.io/#authentication

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns: response from exchange
        T)r  sign_in_with_private_keyinitialize_clientsign_in_with_api_keyload_account_infos)rN  paramss     rR  sign_inzgrvt.sign_in  sn       "" 	.))&111""6****%%f---!!!trS  c                     |                                  }|                     | j        dd          }|||dz   k    ri S d| j        i}|                     |                     ||                    }|dz   | j        d<   |S )NsignInExpirationr   '  api_key \&)millisecondssafe_integerr   r   privateEdgePostAuthApiKeyLoginextend)rN  r  nowexpiresrequestresponses         rR  r  zgrvt.sign_in_with_api_key  s    !!##DL2DaHH7S5[#8#8It{
 66t{{7F7S7STT ,/>'(rS  c                    |                                   |                                 }|                     | j        dd          }|||dz   k    ri S |                     | j                  }||                                 d}|                     |d          }|                     | 	                    ||                    }|dz   | j        d<   |S )Nr  r   r  )rh  	signaturer  r  )
check_required_credentialsr  r  r    eth_get_address_from_private_keyr   default_signaturecreate_signed_requestprivateEdgePostAuthWalletLoginr  )rN  r  r  r  walletAddressr  r  s          rR  r  zgrvt.sign_in_with_private_key  s    '')))!!##DL2DaHH7S5[#8#8I==doNN$//11
 
 ,,W6OPP66t{{7F7S7STT ,/>'(rS  c           	         |                      |d|                      | j        dd                    }|sdS |                      | j        dd          }|rdS |                                 |                                 g}|d         }|                     |dg           }t          |          }d}t          d|          D ]R}	|                     ||	i           }
|                     |
d          }||                     | j        d          k    rd} nS|rd| j        d<   n?	 |                     | j        d	          }||                     | j        d          |                     | j        d
          |                     | j        d
          | 	                                d}| 
                    |d          }|                     |                     ||                    }|                     |d          }|                      |d          }|s%t          d|                     |          z             d| j        d<   n!# t          $ r}d| j        d<   Y d }~nd }~ww xY wd S )Nr   TFapprovedBuilderFeer   resultsbuilder_account_idr   userMainAccountIdr   )main_account_idr  max_futures_fee_ratemax_spot_fee_rater  r~  resultackzBuilder authorization failed, )	safe_boolr   -privateTradingPostFullV1GetAuthorizedBuildersr  	safe_listlenrange	safe_dictsafe_stringr  r  (privateTradingPostFullV1AuthorizeBuilderr  r   json	Exception)rN  r  r   r  r  currentBuildersapprovedBuilderlengthfoundibuilderInfobuilderAccountIddefaultFromAccountIdr  authResponse
authResultr  es                     rR  r  zgrvt.initialize_client&  s   ^^FL$..Wcei:j:jkk
 	5!^^DL:NPUVV 	4EEGGI`I`IbIbc "!*..)RHH_%%q&!! 	 	A..!R@@K#//=QRR4#3#3DL)#L#LLL M  	315DL-..3'+'7'7FY'Z'Z$';*.*:*:4<*S*S,0,<,<T\=,Y,Y)-)9)9$,)V)V!%!7!7!9!9! ! 44W>\]]#LLT[[Y`bhMiMijj "^^L(CC
nnZ77 d'(H499UaKbKb(bccc59122 3 3 3-2\******3ts    DH= =
I
IIc                 T   |                      |          }|g}|                     | j                  r|                     | j                  s'|                    |                                            |}|d         }|                     |dg           }|                     |          S )a  
        retrieves data on all markets

        https://api-docs.grvt.io/market_data_api/#get-instrument-prod

        :param dict [params]: extra parameters specific to the exchange api endpoint
        :returns dict[]: an array of objects representing market data
        r   r  )$publicMarketPostFullV1AllInstrumentsis_empty_stringr   r   appendr  r  parse_markets)rN  r  marketsPromisepromisesr  r  r  s          rR  fetch_marketszgrvt.fetch_markets`  s     BB6JJ6 ####DK00 	,8L8LT_8]8] 	,OODLLNN+++1:(B77!!&)))rS  c                 P   |                      |d          }|                      |d          }|                      |d          }|}|                     |          }|                     |          }|                     |          }|dz   |z   dz   |z   }	d }
|                      |d          }|dk    rd}
|
d	k    }|
dk    }|
d
k    }|p|}i d|d|	d|d|d|d|d|d|d|
d	|ddd|d
|dddd d|d|rdnd |rdn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
instrumentbasequote/:kind	PERPETUALr@   r>   rA   r0   symbolsettlebaseIdquoteIdsettleIdrW  r?   FrB   activecontractr   Tr   min_size	tick_sizebase_decimalsquote_decimals)amountpricer  r  minmaxmax_position_sizemin_notional)r   r  r  costcreate_timeư>)
r   rd  expiryexpiryDatetimestrike
optionType	precisionlimitscreatedinfo)r  safe_currency_codeparse_numbersafe_numberparse_precisionsafe_integer_product)rN  marketmarketIdr  r  r  r  r  r  r  rW  typeRawisSpotisSwapisFuture
isContracts                   rR  parse_marketzgrvt.parse_market  s.   2 ##FL99!!&&11""6733&&v..''00((22e#c)F2""6622k!!D&.&.H$'x
2
(2
f2
 D2
 U	2

 f2
 f2
 w2
 2
 D2
 F2
 e2
 F2
 h2
 e2
 d2
  
!2
" f.dd$#2
$ !'0uuD --c22"**6:>>))&+>>))$*>*>t?O?OPVXg?h?h*i*ijj**4+?+?@P@PQWYi@j@j+k+kll	    
  ++FJ??++F4GHH 
   
  ++FNCC  $ 00QQc2
 2
 2
 2	
rS  c                     ddi}|                      |          }|                     |dg           }|                     |          S )a  
        fetches all available currencies on an exchange

        https://api-docs.grvt.io/market_data_api/#get-currency-response

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r  r  )publicMarketPostFullV1Currencyr  parse_currencies)rN  r  r  r  responseResults        rR  fetch_currencieszgrvt.fetch_currencies  sK     r(66w?? (B??$$^444rS  rawCurrencyc                 T   |                      |d          }|                     |          }|                     |||d d d d d |                     |                     |                      |d                              d d dd d dd d dddd |                     |d          d          S )Nr  balance_decimalsr  )r  r\   depositcryptor0   )r  r0   coder1   r  r  r\   feer  r  rW  r   	numericId)r  r  safe_currency_structurer  r  r  )rN  r  r0   r  s       rR  parse_currencyzgrvt.parse_currency  s     k844&&r**++**4+?+?@P@PQ\^p@q@q+r+rss   
   
     **;==5-
 -
   	rS  r  c                 .   |                                   |                     |          }d|                     |          i}|                     |                     ||                    }|                     |di           }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://api-docs.grvt.io/market_data_api/#ticker_1

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r  r  )load_marketsr  	market_idpublicMarketPostFullV1Tickerr  r  parse_ticker)rN  r  r  r  r  r  r  s          rR  fetch_tickerzgrvt.fetch_ticker*  s     	V$$$..00
 44T[[&5Q5QRRB (B77  000rS  Ntickerr  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 d|                      |d          d|                      |d          d|                      |d          d|                      |d          dd d d d          S ) Nr  r  r  open
open_pricehigh
high_pricelow	low_pricer   
last_pricebidbest_bid_price	bidVolumebest_bid_sizeaskbest_ask_price	askVolumebest_ask_sizechange
percentage
baseVolumebuy_volume_24h_bquoteVolumebuy_volume_24h_q	markPrice
mark_price
indexPriceindex_pricevwap)averagepreviousClose)r  safe_tickersafe_symbol)rN  r  r  r  s       rR  r  zgrvt.parse_ticker]  s   > ##FL99 !
F!
d&&x88!
 D$$V\::!
 D$$V\::	!

 4##FK88!
 D$$V\::!
 4##F,<==!
 ))&/BB!
 4##F,<==!
 ))&/BB!
 d!
 $!
 $**63EFF!
 4++F4FGG!
 ))&,??!
  $**6=AA!!
" D#!
$ !'!
 !
 !
   	rS  r   c           	         |                                   d|                     |          i}|d}|dk    r|                     g d|          |d<   |                     |                     ||                    }|                     |di           }|                     |                     |d                    }|                     |d          }|                     || 	                    |          |d	d
dd          S )a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://api-docs.grvt.io/market_data_api/#orderbook-levels

        :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
        :param str [params.loc]: crypto location, default: us
        :returns dict: A dictionary of `order book structures <https://github.com/ccxt/ccxt/wiki/Manual#order-book-structure>` indexed by market symbols
        r  Nr     )r6   r   r   r3  depthr  
event_timebidsasksr  size)
r  r  find_nearest_ceilingpublicMarketPostFullV1Bookr  r  	parse8601r  parse_order_bookr1  )	rN  r  r   r  r  r  r  	timestampr  s	            rR  fetch_order_bookzgrvt.fetch_order_book  s    	$..00
 =EC<<#889K9K9KUSSGG224;;w3O3OPP" (B77NN4#3#3FL#I#IJJ	##FL99$$VT-=-=h-G-GTZ\bdkmstttrS  sincec                    |                                   |                     |          }d|d         i}|t          |d          |d<   |                     d||d          \  }}||                     |dz            |d<   |                     |                     ||                    }|                     |d	g           }|                     ||||          S )
an  
        get the list of most recent trades for a particular symbol

        https://api-docs.grvt.io/market_data_api/#trade_1

        :param str symbol: unified symbol of the market
        :param int [since]: timestamp in ms of the earliest item to fetch
        :param int [limit]: the maximum amount of items to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms for the ending date filter, default is the current time
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r  r0   Nr   r   end_time@B 
start_timer  )	r  r  r  handle_until_option_stringnumber_to_string"publicMarketPostFullV1TradeHistoryr  r  parse_trades)	rN  r  r?  r   r  r  r  r  r  s	            rR  fetch_tradeszgrvt.fetch_trades  s     	V$$&,
 "5$//GG99*gvW^__$($9$9%'/$J$JGL!::4;;wPV;W;WXX* (B77  >>>rS  tradec                    |                      |d          }|                     ||          }|                     |dd          }d }|                     |d          }d }|	|rdnd}d}n4|                     |d          rdnd	}|                     |d
          rdnd}d }|                      |d          }	|	3|                     |	          |d         |                     |d          d}|                     ||                      |d          ||                     |          |d         |||                      |d          |                      |d          d ||                      |d          d|          S )Nr  r5  r  is_taker_buyerbuyselltakeris_takermakeris_buyerr  r  fee_rate)r  currencyratetrade_idr  r  r8  order_id)r  r0   r=  datetimer  sidetakerOrMakerr  r  r  r  order)r  safe_marketr  r  r  r  
safe_tradeiso8601)
rN  rI  r  r  r=  rY  isTakerBuyerrX  r  	feeStrings
             rR  parse_tradezgrvt.parse_trade  s   Z ##E<88!!(F33--e\8LL	~~e-=>>#(455fD"LL&*nnUJ&G&GT77WL NN5*==I556D$$UE22	 )))44"7O((
;; C
 ""5*55"Y//X&(%%eW55&&uf55%%eZ88 
  
   	rS  r^   c           	         d}|                                   d}|                     |ddd          \  }}|r|                     d||||||          S |                     |          }|d         |                     | j        ||          d}	ddd	d
}
|                     |dd          }|                     |
|          |	d<   |t          |d          |	d<   |                     d|	|d          \  }	}||                     |dz            |	d<   | 	                    | 
                    |	|                    }|                     |dg           }|                     |||||          S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://api-docs.grvt.io/market_data_api/#candlestick_1

        :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 item to fetch
        :param int [limit]: the maximum amount of items to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms for the ending date filter, default is the current time
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        r   FrO   paginater0   )r  intervalTRADEMARKINDEX)r   r   r   	priceTyper   rW  Nr   rA  rB  rC  r  )r  handle_option_and_params"fetch_paginated_call_deterministicr  r  r]   r  rD  rE  publicMarketPostFullV1Kliner  r  parse_ohlcvs)rN  r  	timeframer?  r   r  maxLimitrb  r  r  priceTypeMapselectedPriceTyper  candless                 rR  fetch_ohlcvzgrvt.fetch_ohlcv<  s    88z[`aa& 	|::<QVX]_hjprz{{{V$$ ,(()YOO
 

 
 
 !,,V[&II**<9JKK"5$//GG99*gvW^__$($9$9%'/$J$JGL!33DKK4P4PQQ( ..8R88  &)UEJJJrS  c           	         |                      |dd          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )N	open_timer  r  r  r  closevolume_b)r  r  )rN  ohlcvr  s      rR  parse_ohlcvzgrvt.parse_ohlcvz  s      %%e[(CCUF++UF++UE**UG,,UJ//
 	
rS  c                 P   |t          | j        dz             |                                  d}|                     |dd          \  }}|r|                     d|||d|          S |                     |          }d|d         i}|t          |d	          |d
<   |                     d||d          \  }}||                     |dz            |d<   | 	                    | 
                    ||                    }|                     |dg           }	|                     |	|          S )a  
        fetches historical funding rate prices

        https://api-docs.grvt.io/market_data_api/#funding-rate

        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: timestamp in ms of the earliest funding rate to fetch
        :param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>` to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest item
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentFrJ   rb  rp   r  r0   r   r   rA  rB  rC  r  )r   r0   r  rh  ri  r  r  rD  rE  publicMarketPostFullV1Fundingr  r  parse_funding_rate_histories)
rN  r  r?  r   r  rb  r  r  r  r  s
             rR  fetch_funding_rate_historyzgrvt.fetch_funding_rate_history  sL    >#DG.e$efff88AZ\fgg& 	z::;TV\^cejlprxyyyV$$&,
 "5$//GG99*gvW^__$($9$9%'/$J$JGL!55dkk'66R6RSS" (B7700@@@rS  c                     |                      |d          }|                     |dd          }||                     ||          |                     |d          ||                     |          dS )Nr  funding_timer  funding_rate)r  r  fundingRater=  rW  )r  r  r1  r  r]  )rN  rawItemr  r  tss        rR  parse_funding_rate_historyzgrvt.parse_funding_rate_history  sz     ##G\::&&wII&&x88++G^DDR((
 
 	
rS  c                     d }|                      |dd          \  }}|t          | j        dz             t          |          S )NgetSubAccountIdr   zo you should set "accountId" in options or params, which can be found in the grvt dashboard, under Api-Keys page)rh  r   r0   str)rN  r  subAccountIds      rR  get_sub_account_idzgrvt.get_sub_account_id  s^    #<<VEVXcddf#DG  /`  %`  a  a  a<   rS  c                    |                                   d|                     |          i}|                     |                     ||                    }|                     |di           }|                     |          S )a  
        query for account info

        https://api-docs.grvt.io/trading_api/#sub-account-summary

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        sub_account_idr  )load_markets_and_sign_inr  &privateTradingPostFullV1AccountSummaryr  r  parse_balance)rN  r  r  r  r  s        rR  fetch_balancezgrvt.fetch_balance  s     	%%'''d55f==
 >>t{{7TZ?[?[\\: (B77!!&)))rS  c                    |                      |dd          }|||                     |          d}|                     |dg           }|                     |d          }t	          dt          |                    D ]l}||         }|                     |d          }|                     |          }	|                                 }
|                     |d          |
d	<   ||
d
<   |
||	<   m|                     |          S )Nr5  r  )r  r=  rW  spot_balancesavailable_balancer   rS  balancetotalfree)	r  r]  r  r  r  r  r  accountsafe_balance)rN  r  r=  r  spotBalancesavailableBalancer  r  
currencyIdr  r  s              rR  r  zgrvt.parse_balance  s   6 --hhOO	"Y//
 

 ~~hDD++H6IJJq#l++,, 	# 	#A"1oG))':>>J**:66DllnnG#//CCGG.GFO"F4LL  (((rS  r  c                    |                                   i }d}|!|                     |          }|d         g|d<   |t          |d          |d<   |                     d||d          \  }}||                     |dz            |d<   |                     | j        d	d
          }|rw|                     |                     ||          |||          }| 	                    |dd
          }	| 
                    |	d         d          }
|                     |
|||          S |                     |                     ||                    }|                     |dg           }|                     ||||          S )aH  
        fetch all deposits made to an account

        https://api-docs.grvt.io/trading_api/#transfer

        :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
        :param int [params.until]: timestamp in ms of the latest item
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr  rS  r   r   rA  rB  rC  *useTransfersEndpointForDepositsWithdrawalsTr  r   r  r  )r  rS  r  rD  rE  r  r   internal_fetch_transfersr  filter_transfers_by_typeget_list_from_object_valuesparse_transactions&privateTradingPostFullV1DepositHistoryr  rN  r  r?  r   r  r  rS  useTransfersEndpoint	transfersfilteredResultstransactionsr  r  s                rR  fetch_depositszgrvt.fetch_deposits:  s    	%%'''}}T**H#+F#3"4GJ"5$//GG99*gvW^__$($9$9%'/$J$JGL!#~~dl<hjnoo 	K55dkk'66R6RT\^cejkkI";;IyRVWWO;;OA<NPVWWL**<5%PPPBB4;;wX^C_C_``H  ^^Hh;;F**68UEJJJrS  c                    |                                   i }d}|d|d<   n!|                     |          }|d         g|d<   |t          |d          |d<   |                     d||d          \  }}||                     |dz            |d<   |                     | j        d	d
          }|rw|                     |                     ||          |||          }| 	                    |dd
          }	| 
                    |	d         d          }
|                     |
|||          S |                     |                     ||                    }|                     |dg           }|                     ||||          S )a  
        fetch all withdrawals made from an account

        https://docs.backpack.exchange/#tag/Capital/operation/get_withdrawals

        :param str [code]: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for(default 24 hours ago)
        :param int [limit]: the maximum number of transfer structures to retrieve(default 50, max 200)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest item
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        NrS  r  r   r   rA  rB  rC  r  T
withdrawalr   r  r  )r  rS  r  rD  rE  r  r   r  r  r  r  r  )privateTradingPostFullV1WithdrawalHistoryr  r  s                rR  fetch_withdrawalszgrvt.fetch_withdrawalsl  s    	%%'''<"&GJ}}T**H#+F#3"4GJ"5$//GG99*gvW^__$($9$9%'/$J$JGL!#~~dl<hjnoo  	K55dkk'66R6RT\^cejkkI";;I|UYZZO;;OA<NPVWWL**<5%PPPEEdkkRY[aFbFbccH2 ^^Hh;;F**68UEJJJrS  rS  c                     |                      |          }|                     |dg           }|                     ||||          }|S )Nr  )'privateTradingPostFullV1TransferHistoryr  parse_transfers)rN  reqrS  r?  r   r  rowsr  s           rR  r  zgrvt.internal_fetch_transfers  sK    ??DD< ~~h"55((xFF	rS  transactionc                 T   d }d }d }|                      |d          }|                      |d          }d|v r|                     |                      |d                    }||                     |          }	|                     |	d          }|                      |	d          }|                     |                      |	d                    }|dk    r|                      |	d          }n|d	k    r|                      |	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 ) Nfrom_account_idto_account_idtransfer_metadata	directionprovider_tx_idchainidr  endpointr  r5  initiated_timer  rS  r  r0   txidrW  networkr  
num_tokensstatusr=  rW  rh  addressFrom	addressTotagtagFromtagToupdated)commentr  )	r  	omit_zero
parse_jsonsafe_string_lowernetwork_id_to_codesafe_integer_product_2r  r  r]  )rN  r  rS  r  txIdnetworkCoder  r  metaData
parsedMetar=  r  r  s                rR  parse_transactionzgrvt.parse_transaction  s^   J 	&&{4EFF$$[/BB	+--~~d&6&6{DW&X&XYYH#!__X66
 22:{KK	''
4DEE"55d6F6FzS\6]6]^^,, $ 0 0Z H HII)++"&"2"2:z"J"JK//\K[]eff	%%k:>>
&&z8<<
K
$
 D
 I	

 
 {
 d&&{LAA
 d
 
 Y//
 t
 ;
 
 4
 t
  T!
" t#
$ '
 
 
 	
rS  c                    |t          | j        dz             |                                  i }|                     |          }d}d}|                     |ddd          \  }}|r|                     dd||||          S |t          |d          |d<   |                     d||d	          \  }}||                     |d	z            |d
<   | 	                    | 
                    ||                    }	|                     |	dg           }
|                     |
|||          }|                     |dd          }|d         S )a  
        fetch a history of internal transfers made on an account

        https://api-docs.grvt.io/trading_api/#transfer-history

        :param str code: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for
        :param int [limit]: the maximum number of transfers structures to retrieve(default 10, max 100)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: whether to paginate the results(default False)
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
        Nz* fetchTransfers() requires a code argumentr   FrW   rb  r   rA  rB  rC  r  internal   )r   r0   r  rS  rh  fetch_paginated_call_dynamicr  rD  rE  r  r  r  r  r  )rN  r  r?  r   r  r  rS  rm  rb  r  r  r  r  s                rR  fetch_transferszgrvt.fetch_transfers:  sk    <#DG.Z$Z[[[%%'''==&&88AQS]_dee& 	m445EtUTY[acklll"5$//GG99*gvW^__$($9$9%'/$J$JGL!??GU[@\@\]]< ~~h"55((xFF	77	:uUUq!!rS  Tr  transferTypec                    g }g }t          dt          |                    D ]}||         }|r|d         dk    r|d         dk    s|s|d         dk    s|d         dk    rx|                     |d         d          }|                     |          }	|                     |	d          }
|
|k    r|                    |           |                    |           ||gS )Nr   rk  0rm  r  r  r  )r  r  r  r  r  )rN  r  r  onlyMainAccountmatchedResultsnonMatchedResultsr  r[   metadataparsedMetadatar  s              rR  r  zgrvt.filter_transfers_by_typey  s;   q#i..)) 		7 		7A |H 7H]$;s$B$BxP[G\`cGcGcm|Gc  CK  LY  CZ  ^a  Ca  Ca  em  ny  ez  ~A  eA  eA++HV,<>QRR!%!:!: ,,^[II	,,"))(3333%,,X666 122rS  r  rk  rm  c           
      r   |                                   |                     |          }|                     | j        d          }|                     |ddg          r|                     |ddg          rgd}|                     |dd          \  }}d}	|                     |dd          \  }	}||	t          | j        dz             |dk    r|n|	}|dk    r|n|	}|                     |d	|          |                     |d
|          |                     |d|          |                     |d|          |d         |                     ||          | 	                                ddd	}
| 
                    |
d|          }
d}	 |                     |                     |
|                    }n`# t          $ rS}|                     |          }|dk    }|r/|                    d          rt!          | j        dz   |z             |d}~ww xY w|                     |di           }|                     ||          S )u  
        transfer currency internally between wallets on the same account

        https://api-docs.grvt.io/trading_api/#transfer_1

        :param str code: unified currency codeåå
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        r  tradingfundingNr[   tradingAccountIdfundingAccountIdz transfer(): you should set(in the options or params) "tradingAccountId" and "fundingAccountId"(you can use "0" main funding account id)r  from_sub_account_idr  to_sub_account_idr0   STANDARD)	r  r  r  r  rS  r  r  transfer_typer  r|  zYou are not authorizedzc transfer() failed. Ensure you use funding api-keys when trying to transfer from Funding accounts: r  )r  rS  r  r   in_arrayrh  r   r0   currency_to_precisionr  r   privateTradingPostFullV1Transferr  r  exception_messagefindr   r  parse_transfer)rN  r  r  rk  rm  r  rS  r  r  r  r  r  errormsgisFromFundingAccountr  s                   rR  r[   zgrvt.transfer  s    	%%'''==&&#//>QRR==y)&<== 	[$--PY\egp[qBrBr 	[$('+'D'DVZYk'l'l$f$('+'D'DVZYk'l'l$f'+;+C'  3}  )}  ~  ~  ~/:i/G/G**N^K-6)-C-C((JZI#//8IK_``#'#3#3F<QS^#_#_!--foG[\\!%!1!1&:My!Y!Y 44T6BB//11'!%

 

 ,,W6LhWW	<<T[[RX=Y=YZZHH 	 	 	((//C#.)#; # ^1I(J(J ^&tw  2W  (W  Z]  (]  ^  ^  ^K	 (B77""68444s   )F, ,
H	6AHH	r[   c                 f   |                      |d          }|                     ||          }|                     |dd          }||                      |d          ||                     |          ||                     |d          |                      |d          |                      |d          d d	S )	NrS  r5  r  tx_idr  r  r  )	r  r0   r=  rW  rS  r  rk  rm  r  )r  r  r  r]  r  )rN  r[   rS  r  r  r=  s         rR  r  zgrvt.parse_transfer  s    B %%h
;;
&&z8<<--hhOO	""8W55"Y//&&x::++H6KLL))(4GHH

 

 
	
rS  c                    |                      | j        d          d S g }|                    |                                            |                      | j        d          d u }|r'|                    |                                            |}|                     |d         di           }|                      |d          }|| j        d<   |r|                     |d         dg           }t          |          }|dk     rt          | j	        dz             |dk    r-t          | j	        d	z   | 
                    |          z             |                      |d          }|| j        d<   d S d S )
Nr  r   r   r  r  r  sub_account_idsz_ loadAccountInfos(): no sub accounts found, you might need to create an api-key in GRVT websitez loadAccountInfos(): multiple sub accounts found, please set the exchange.options["accountId"] to your preferred sub_account_id from self list: )r  r   r  0privateTradingPostFullV1AggregatedAccountSummary&privateTradingPostFullV1GetSubAccountsr  r  r  r   r0   r  )	rN  r  accountIsUndefined	responsesresult1mainAccountIdsubAccountIdsr  r  s	            rR  r  zgrvt.load_account_infos  s   DL*=>>JFMMOOPPP2 "--dlKHHDP 	KOODGGIIJJJ 	..1x<<((2CDD,9() 	5 NN9Q<9JBOOM''Fzz'  3T  )T  U  U  Uzz'  3E  )E  HL  HQ  HQ  R_  H`  H`  )`  a  a  a++M1==L(4DL%%%	5 	5rS  rh  r  c                    |                      |           |                                  |                     | j        d          }|                     |          }|||d         |                     ||          |                                 d}|                     |          \  }	}
|                     |	          }|t          | j
        dz             ||d         d<   |                     |d|          }|                     |                     ||
                    }|                     |d	i           }|                     ||          S )
a  
        make a withdrawal

        https://api-docs.grvt.io/trading_api/#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
        :param str params['network']: the network to withdraw on(mandatory)
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r  r0   )to_eth_addressr  rS  r  r  Nz( withdraw() requires a network parameterr  chain_idr}  r  )check_addressr  r  r   rS  r  r  handle_network_code_and_paramsnetwork_code_to_idr    r0   r  "privateTradingPostFullV1Withdrawalr  r  r  )rN  r  r  rh  r  r  r  rS  r  r  query	networkIdr  r  s                 rR  r\   zgrvt.withdraw$  sO    	7###%%'''#//>QRR==&&%3 44T6BB//11
 
 "@@HHU++K88	TW'QQRRR+4Z(,,W6NPXYY::4;;wPU;V;VWW (B77%%fh777rS  rW  rX  r  c                 2   |                                   |                     |          }|d         |                     ||          d}||                     ||          |d<   nd|d<   |dk    rd|d<   n#|dk    rd	|d<   nt	          | j        d
z             |dk    }	|                     |          d|g|                                 dt          | 	                                          dz   t          | 
                                          z   i|	d|                     |dd          d}
|                     |d          }|                     |	d|          }|rd	|
d<   n'|d}ndddd}|                     |||          }||
d<   |	s|rd}n|dk    rd}|                     |g d          }d}d}d}|                     ||          \  }}}}|||d}||}n	||}n||}d}|dk    }||rdnd}nS||rdnd}nJ|                     |d          }|t#          | j        dz             ||dk    r|rdnd}n|dk    r|rdnd}|                     |d d!          }||||                     |d"d          d#d$|
d%         d&<   |                     |g d'          }d(}|                     |d)|                     | j        d)d	                    }|r>d*}|                     | j        d+          |
d+<   |                     | j        d,          |
d-<   |                     |d)g          }|                     |
|          }d.|i}|                     |                     ||                    }|                     |d/i           }|                     ||          S )0a  
        create a trade order

        https://api-docs.grvt.io/trading_api/#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]: The price a trigger order is triggered at
        :param float [params.stopLossPrice]: The price a stop loss order is triggered at
        :param float [params.takeProfitPrice]: The price a take profit order is triggered at
        :param str [params.timeInForce]: "GTC", "IOC", or "POST_ONLY"
        :param bool [params.postOnly]: True or False
        :param bool [params.reduceOnly]: Ensures that the executed order does not flip the opened position.
        :param str [params.clientOrderId]: a unique id for the order
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r0   )r  r8  Nlimit_pricerM  Fis_buying_assetrL  Tz9 createOrder(): order side must be either "buy" or "sell"r  client_order_id000r\  )r  time_in_forcer]  r  r  	is_market	post_onlyreduce_onlyr   r  GOOD_TILL_TIMEFILL_OR_KILLIMMEDIATE_OR_CANCEL)GTCr   r   r  	POST_ONLYioc)r\  r[  r   	STOP_LOSSTAKE_PROFITr   zx createOrder() requires a triggerDirection parameter when triggerPrice is specified, must be "ascending" or "descending"	ascending
descendingr   LASTclosePosition)
trigger_bytrigger_priceclose_position)trigger_typetpslr  r   )r   r   r  rz  r   r{  r   r   builder_feerZ  r  )r  r  amount_to_precisionprice_to_precisionr$   r0   r  r  r  r^  
request_idr  safe_string_upperis_post_onlyr  omit handle_trigger_prices_and_paramsr   r   r  #privateTradingPostFullV1CreateOrderr  r  parse_order)rN  r  rW  rX  r  r  r  r  orderLegisMarketOrderorderRequestr   r[  tifMapr   r   r   selectedPriceselectedTypeisBuyr   r   eipTyper   signedOrderRequestr  r  datas                               rR  create_orderzgrvt.create_orderN  s   * 	%%'''V$$ ,,,VV<<
 
 &*&=&=fe&L&LH]##&*H]#6>>*/H&''U]]*.H&''tw)ddeee)"55f==!J//11!3tzz||#4#4u#<s4??CTCT?U?U#U '>>&,FF
 
 ,,V]CC$$]D&AA 	8(,L%%". ,)0 
 #..v{KPP,7L) 	4 4)%%36#L#L#LMM !#?C?d?dekms?t?t<m_f#}'@OD_!%M' ,* - , / $LU]E(.3F{{ ,05F}};#'#3#3F<N#O#O #++DG  7q  -q  r  r  r#/';666;'N{{)\998='N}};#55f>PRXYY ,"2%2&*nnV_e&T&T 3 3L$Y/ YYv'`'`'`aaF%^^FL$..Wcei:j:jkk
 	X6G&*&6&6t|Y&O&OL#*.*:*:4<*W*WL'6L>22!77gNN'
 ;;DKKQW<X<XYYz ~~h"55f---rS  c                      t          |          S N)int)rN  xs     rR  convert_to_big_int_customzgrvt.convert_to_big_int_custom  s    1vvrS  c           	      *   d}|                      |dg           }g }t          dt          |                    D ]}||         }|                     |d                   }|                     d          }	|                     |                     |d         d                    }
t          |
          }t          j	        |	|                     |                    }|d         }|
                    d	          }|                     |d
d          }t          |          dz   }t          |          }|                     |                    d	d                    |z  t          j	        |	|                     |                    z  }|d         d         |                     |          |d         d}|                     |d          }|                     |          |d         }|
                    d	          }|                     |d
d          }t          |          dz   }t          |          }|dk    }|                     |                    d	d                    |                     |          z  t          j	        |	|          z  }|                     |          |d<   nd|d<   |                    |           |d         |d         |                     |d                   |d         |d         ||d         d         |d         d         d}|dk    rz|                     | j        dd          r^|d         |d<   |                     |                     |                                           t'          |d                    z            |d<   |S )!N
1000000000r]  r   r  r   r  r  r8  .r  r  r  instrument_hashr  )rb  rd  rf  r  r  re  r  r  r  r  r	  r  r^  r`  )rU  rX  r   r[  r\  r]  r^  r`  r{  r   Tr   r  )r  r  r  r  r4  precision_from_stringr  r  mathpowsplitreplaceparse_to_intr  r  time_in_force_to_intr  r   fee_amount_multiplierfloat)rN  rZ  structureTypepriceMultiplier	orderLegsr]  r  legr  bigInt10precisionValueprecisionValueStrsizeMultiplierr8  	sizePartssizeDecsizeDecLengthsizeDecLengthStrsizeIntegerlegOrderre  r  
limitPartslimitDeclimitDecLengthlimitDecLengthStrpowerNumpriceIntegerreturnValues                                rR  eip_message_for_orderzgrvt.eip_message_for_order  s   &NN5&"55	q#i..)) 	" 	"AA,C[[\!233F55d;;H!778H8HP[I\^d8e8effN #N 3 3!Xh0N0NO`0a0abbNv;D

3I&&y!R88GLL1,M"=1188c29N9NOOR``dhdlmuw{  xV  xV  Wg  xh  xh  ei  ei  jK!&>*;< $ 1 1+ > >$'(9$: H
 ))#}==J~~j))5M*"[[--
++J2>>!$X!2$'$7$7!,1 $ > >u}}SRT?U?U V VY]YwYw  yH  ZI  ZI  !I  MQ  MU  V^  `h  Mi  Mi  !j)-):):<)H)H&&)*&KK!!!!!"23k*44U?5KLLk*.;'0,\:	
 	
 <<<PTP\^jlpAqAq<%*9%5K	"(,(9(9$:X:XY]YsYsYuYu:v:vy~  @E  FS  @T  zU  zU  ;U  )V  )VK%rS  c                    |                                   d}|                     |dd          \  }}|r|                     d||||          S d|                     |          i}d}|a|                     |          }g |d<   |d                             |d                    g |d<   |d                             |d	                    |t          |d
          |d<   |                     d||d          \  }}||                     |dz            |d<   | 	                    | 
                    ||                    }|                     |dg           }	|                     |	d||          S )a-  
        fetch all trades made by the user

        https://api-docs.grvt.io/trading_api/#fill-history

        :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 trade structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest item
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        FrN   rb  r  Nr  r  r  r  r   r   rA  rB  rC  r  )r  rh  r  r  r  r  r  rD  rE  #privateTradingPostFullV1FillHistoryr  r  rG  
rN  r  r?  r   r  rb  r  r  r  r  s
             rR  fetch_my_tradeszgrvt.fetch_my_trades@  s    	%%'''88R\]]& 	d44_feUZ\bcccd55f==
 [[((F GFOFO""6(#3444!GGG##F9$5666"5$//GG99*gvW^__$($9$9%'/$J$JGL!;;DKKQW<X<XYY@ (B77  ue<<<rS  symbolsc                    |                                   d|                     |          i}||                     |          }g |d<   g |d<   t          dt	          |                    D ]}||         }|                     |          }|d         durt          | j        dz             |d                             |d	                    |d                             |d
                    | 	                    | 
                    ||                    }|                     |dg           }|                     ||          S )am  
        fetch all open positions

        https://api-docs.grvt.io/trading_api/#positions-request

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
        r  Nr  r  r   r  Tz0 fetchPositions() supports contract markets onlyr  r  r  )r  r  market_symbolsr  r  r  r    r0   r  !privateTradingPostFullV1Positionsr  r  parse_positions)	rN  r\  r  r  r  r  r  r  r  s	            rR  fetch_positionszgrvt.fetch_positions  sI    	%%'''d55f==
 ))'22G GFO!GG1c'll++ ; ; V,,*%T11$TW/a%abbb&&vh'7888 ''y(9::::99$++gv:V:VWW4 (B77##FG444rS  positionc                    |                      |d          }|                     |dd          }|                      |d          }t          j        |d          }|rdnd}|                     i d|d	d d
|                     ||          d|                     t          j        |                      |d                              dd d|                     |d          d|                     |d          d|                     |d          d|                     |d          dd d|                     t          j        |                    d|                     |d          dd d|dd d|d| 	                    |          | 
                    |d          |                     |d          d d |                     |d           d |                     |d!          d d d d"
          S )#Nr  r5  r  r8  r  longshortr  r0   r  notionalr   liquidationPriceest_liquidation_price
entryPriceentry_priceunrealizedPnlunrealized_pnlrealizedPnlrealized_pnlr$  	contractsr)  r*  	lastPricerX  r   r=  rW  lastUpdateTimemaintenanceMargininitialMarginr   )
lastUpdateTimestamprr  maintenanceMarginPercentage
collateralrs  initialMarginPercentager   marginRatior   r   )r  r  r)   	string_gesafe_positionr1  r  
string_absr  r]  r  )rN  rb  r  r  r=  sizeRawisLongrX  s           rR  parse_positionzgrvt.parse_position  sl   , ##Hl;;--hhOO	""8V44#GS11,vvW!! #
H#
$#
 d&&x88#
 ))'*<T=M=MhXb=c=c*d*dee	#

 $#
  0 0;R S S#
 $**8]CC#
 T--h8HII#
 4++HnEE#
 $#
 **7+=g+F+FGG#
 ))(LAA#
 #
 D#
 d#
  !#
" Y//##
$ $(#4#4X?O#P#P!%!1!1(<O!P!P+/!--hHH'+((:>>!#7#
 #
 #
   	rS  c                    |                                   d|                     |          i}|                     |                     ||                    }|                     |dg           }|                     ||          S )a  
        fetch the set leverage for all contract markets

        https://api-docs.grvt.io/trading_api/#get-all-initial-leverage

        :param str[] [symbols]: a list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `leverage structures <https://docs.ccxt.com/?id=leverage-structure>`
        r  r  r  r  -privateTradingPostFullV1GetAllInitialLeverager  r  parse_leveragesrN  r\  r  r  r  r  s         rR  fetch_leverageszgrvt.fetch_leverages       	%%'''d55f==
 EEdkkRY[aFbFbcc ..9b99##GW555rS  r   c                 h   |t          | j        dz             |                                  |                     |          }|                     |          |d         |                     |          d}|                     |                     ||                    }|                     ||          S )ai  
        set the level of leverage for a market

        https://api-docs.grvt.io/trading_api/#set-initial-leverage

        :param float leverage: the rate of leverage
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        Nz) setLeverage() requires a symbol argumentr0   )r  r  r   )	r   r0   r  r  r  rE  *privateTradingPostFullV1SetInitialLeverager  parse_leverage)rN  r   r  r  r  r  r  s          rR  set_leveragezgrvt.set_leverage	  s     >#DG.Y$YZZZ%%'''V$$"55f== ,--h77
 

 BB4;;wX^C_C_`` ""8V444rS  c                     |                      |d          }|                     |d          }|                     |d          }||                     ||          |||dS )Nr  r   margin_type)r  r  r   longLeverageshortLeverage)r  r  r  r1  )rN  r   r  r  leverageValue
marginTypes         rR  r  zgrvt.parse_leverage-	  sq    $ ##Hl;;((:>>++HmDD
&&x88$)*
 
 	
rS  c                    |                                   d|                     |          i}|                     |                     ||                    }|                     |dg           }|                     ||          S )ap  
        fetches margin mode of the user

        https://api-docs.grvt.io/trading_api/#get-all-initial-leverage

        :param str[] symbols: unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `margin mode structures <https://docs.ccxt.com/?id=margin-mode-structure>`
        r  r  r  r  s         rR  fetch_margin_modeszgrvt.fetch_margin_modesJ	  r  rS  r   c                     |                      |d          }||                     ||          |                     |d          dS )Nr  r  )r  r  r   )r  r1  r  )rN  r   r  r  s       rR  parse_margin_modezgrvt.parse_margin_modeg	  sQ     ##J99&&x8800]KK
 
 	
rS  c                    |                                   d}|                     |dd          \  }}|r|                     d||||d          S d|                     |          i}d}|a|                     |          }g |d<   |d                             |d                    g |d	<   |d	                             |d
                    |t          |d          |d<   |                     d||d          \  }}||                     |dz            |d<   | 	                    | 
                    ||                    }|                     |dg           }	|                     |	|||          S )ay  
        fetch the history of funding payments paid and received on self account

        https://api-docs.grvt.io/trading_api/#funding-payment-history

        :param str [symbol]: unified market symbol
        :param int [since]: the earliest time in ms to fetch funding history for
        :param int [limit]: the maximum number of funding history structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest item
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
        FrI   rb  r   r  Nr  r  r  r  r   rA  rB  rC  r  )r  rh  r  r  r  r  r  rD  rE  -privateTradingPostFullV1FundingPaymentHistoryr  r  parse_incomesrZ  s
             rR  fetch_funding_historyzgrvt.fetch_funding_historyz	  s    	%%'''88AVXbcc& 	p445JFTY[`bhjnoood55f==
 [[((F GFOFO""6(#3444!GGG##F9$5666"5$//GG99*gvW^__$($9$9%'/$J$JGL!EEdkkRY[aFbFbcc" (B77!!&&%???rS  c           
      `   |                      |d          }|                      |d          }|                     |dd          }||                     ||          |                     |          ||                     |          |                      |d          |                     |d          dS )Nr  rS  r5  r  r  r  )r  r  r  r=  rW  r0   r  )r  r  r1  r  r]  r  )rN  incomer  r  r  r=  s         rR  parse_incomezgrvt.parse_income	  s     ##FL99%%fj99
--flHMM	&&x88++J77"Y//""6733&&vx88
 
 	
rS  c                 l   |                                   d|                     |          i}d}|a|                     |          }g |d<   |d                             |d                    g |d<   |d                             |d                    |t	          |d          |d<   |                     d	||d
          \  }}||                     |d
z            |d<   |                     |                     ||                    }| 	                    |dg           }| 
                    ||||          S )aq  
        fetches information on multiple orders made by the user

        https://api-docs.grvt.io/trading_api/#order-history

        :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
        :param int [params.until]: timestamp in ms of the latest item
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  Nr  r  r  r  r   r   rA  rB  rC  r  )r  r  r  r  r  rD  rE  $privateTradingPostFullV1OrderHistoryr  r  parse_orders)	rN  r  r?  r   r  r  r  r  r  s	            rR  fetch_orderszgrvt.fetch_orders	  sJ    	%%'''d55f==
 [[((F GFOFO""6(#3444!GGG##F9$5666"5$//GG99*gvW^__$($9$9%'/$J$JGL!<<T[[RX=Y=YZZ~ (B77  >>>rS  c                    |                                   d|                     |          i}|                     |                     ||                    }|                     |dg           }|                     |d||          S )a  
        fetch all unfilled currently open orders

        https://api-docs.grvt.io/trading_api/#open-orders

        :param str [symbol]: unified market symbol
        :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>`
        r  r  N)r  r  "privateTradingPostFullV1OpenOrdersr  r  r  )rN  r  r?  r   r  r  r  r  s           rR  fetch_open_orderszgrvt.fetch_open_orders'
  s     	%%'''d55f==
 ::4;;wPV;W;WXXz (B77  ue<<<rS  r0   c                 x   |                                   d|                     |          i}|                     |dd          }||                     |dd          }||d<   n||d<   |                     |                     ||                    }|                     |di           }|                     |          S )a  
        fetches information on an order made by the user

        https://api-docs.grvt.io/trading_api/#get-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
        :param str [params.clientOrderId]: client order id
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  clientOrderIdr  NrV  r  )r  r  safe_string_2r!  privateTradingPostFullV1Orderr  r  r$  rN  r0   r  r  r  r  r  r  s           rR  fetch_orderzgrvt.fetch_orderw
  s     	%%'''d55f==
 **6?DUVV$YYv8IJJF)6G%&&"$GJ55dkk'66R6RSSv (B77'''rS  rZ  c                    d|v r|                      |d d          S |                     |d          }|rdnd}|                     |d          }|                     |d          }|                     |d          }|rd	n|                     |          }d }	d }
d }d }d }|                     |d
          }|                     |di           }|                     |di           }|                     |dg           }|                     |dg           }d}|                     ||          }||                     |d          }|                     ||          }|                     |d          }	|                     |d          rdnd}
|                     |d          }|                     ||          }|                     ||          }|                     |dd          }t          |          }|                      i 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 ||d-|          S ).Nr  )r  r0   r  r  r   r  r	  r  r   r]  r  statetraded_sizeavg_fill_pricer   r  r8  r  rL  rM  r  r  r  
isMultiLegr  r0   rV  r  r  r=  rW  lastTradeTimeStamprt  update_timer  r  rW  r   r[  rX  r  r   r  r.  )r  filled	remainingtradesr   r\  r  )
safe_orderr  r  parse_time_in_forcer  r  r[  r  r  r]  parse_order_status)rN  rZ  r  rX  	orderType
isPostOnlyisReduceOnlytimeInForceRawr   r8  rX  r  r  avgPricer]  r  stateObjfilledAmounts	avgPricesprimaryOrderIndexfirstLegr  r=  
legsLengths                           rR  r$  zgrvt.parse_order
  s   F E>>??$ $    >>%55 (5HHg	^^E;77
~~e];;))%AA(Vddd.F.F~.V.V~~eV,,>>%R88>>%"55xCCNN8-=rBB	>>$(9::'',??H%%h77F##Hf55D NN85FGGS55VD$$X}==E%%m5FGGF''	3DEEH--hxPP	YY
  
:> 
$""5*55 
 T--h8IJJ 
 	 

 Y// 
 !$ 
 "4#<#<X}V^#_#_ 
 d--d.>.>x.R.RSS 
 fX& 
 I 
 ; 
 
 
 D 
 U 
 D 
  D! 
" x# 
$ &1 
  
  
2 3  	rS  c                 @    dddddd}|                      |||          S )Nr  r   r   ALL_OR_NONERETAIL_PRICE_IMPROVEMENT)r
  r  r  r  r  )r  )rN  rW  typess      rR  r  zgrvt.parse_time_in_forceK  s7    ##(!((B
 
 %%eT4888rS  r   c                 @    dddddd}|                      ||d          S )Nr        r   r   )r
  r  r  r  r  r   )r  )rN  r   timeInForcess      rR  r?  zgrvt.time_in_force_to_intV  s7    #$()
 
   {A>>>rS  r  c                 @    dddddd}|                      |||          S )Npendingr  closedrejectedcanceled)PENDINGOPENFILLEDREJECTED	CANCELLED)r  )rN  r  statusess      rR  r  zgrvt.parse_order_status`  s7     "#
 
 &&999rS  c                    |                                   d|                     |          i}|a|                     |          }g |d<   |d                             |d                    g |d<   |d                             |d                    |                     |                     ||                    }|                     |di           }|                     |gd          S )ab  
        cancel all open orders in a market

        https://api-docs.grvt.io/trading_api/#cancel-all-orders

        :param str symbol: cancel alls open orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  Nr  r  r  r  r  )r  r  r  r  'privateTradingPostFullV1CancelAllOrdersr  r  r  )rN  r  r  r  r  r  r  s          rR  cancel_all_orderszgrvt.cancel_all_ordersj  s     	%%'''d55f==
 [[((F GFOFO""6(#3444!GGG##F9$5666??GU[@\@\]] (B77  &4000rS  c                 v   |                                   d|                     |          i}|                     |dd          }||                     |d          }||d<   n||d<   |                     |                     ||                    }|                     |di           }|                     |          S )a  
        cancels an open order

        https://api-docs.grvt.io/trading_api/#cancel-order

        :param str id: order id
        :param str [symbol]: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.clientOrderId]: client order id
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  r  NrV  r  )r  r  r  r!  #privateTradingPostFullV1CancelOrderr  r  r$  r  s           rR  cancel_orderzgrvt.cancel_order  s     	%%'''d55f==
 **6?DUVV$YYv77F)6G%&&"$GJ;;DKKQW<X<XYY (B77'''rS  c                      dd| j         rdnddS )NzGRVT Exchanger  iF  iE  )r1   r8   chainId)isSandboxModeEnabledr  s    rR  eip_domain_datazgrvt.eip_domain_data  s(     $"7@ssS
 
 	
rS  c                 ,    |                      d          S )N10000)r4  r  s    rR  r@  zgrvt.fee_amount_multiplier  s    --g666rS  r  rB  signerAddressc           	      v   d }|dk    rv|                      d          }|d         |z  }|d         |d         |d         |d         |d         |                     |          |d	         d
         |d	         d         d}ne|dk    re|                      d          }|d         |d         |d         |                     |d         |z            |d	         d
         |d	         d         d}n|dk    s|dk    r|                     ||          }n|dk    r|                      |                                           }|d         |d         |                     t	          |d                   |z            |                     t	          |d                   |z            |d	         d
         |d	         d         d}n*|dk    r$|d         |d	         d
         |d	         d         d}|                                 }|                                 }	|                     ||	|         |          }
d|                     |
dd          z   }| 	                                }|r| j
        n| j        }|                     |          }|                     |                     |          |dd           }|                     |d                   |d	         d<   |                     |d                    |d	         d <   |                     d!|d"                   |d	         d"<   ||                     d|z             n||d	         d#<   |S )$Nr|  1000000r  r  r  r  r  r	  r  r^  r`  )rk  rl  rm  rn  ro  rp  r^  r`  r}  r  )rk  rr  ro  rp  r^  r`  rz  r{  r~  r  r  r  r  )rt  ru  rv  rw  r^  r`  r  rh  )ry  r^  r`  0xkeccakhex	secp256k1rs   vry  )r4  r>  rW  r@  rA  r  r  eth_encode_structured_datahashr  r   r   remove0x_prefixecdsaformat_signature_rssumr  )rN  r  rB  currencyObjr  messageDataamountMultiplier	amountInt
domainDatadefinitionsethEncodedMessageethEncodedMessageHashedusesPrivKeysecretOrPrivkeyprivateKeyWithoutZeror  s                   rR  r  zgrvt.create_signed_request  s   222#==iHH-0@@I&'89")*?"@$_5 '(; <!,[!9!..y99 -g6%k2<@	 	KK 666#==iHH&'89 '(8 9!,[!9!..w|/DGW/WXX -g6%k2<@ KK 111]Ff5f5f44WmLLKK<<<#==d>X>X>Z>Z[[!():!;$+,@$A$($5$5eGDZ<[6\6\_o6o$p$p"&"3"3E'BU:V4W4WZj4j"k"k -g6%k2<@ KK 777!), -g6%k2<@ K
 ))++
**,, ;;JTaHbdopp"&3DhPU)V)V"V++---8I$//dk $ 4 4_ E EJJt334KLLNceprvww	$($<$<Ys^$L$LS!$($<$<Ys^$L$LS!$(HHR3$@$@S!q~  rG)N)NtVkOk)l)l)l  N[X&rS  valuec                 f    |                     dd          }|                    d          r|S d|z   S )N@   r  r  )rjust
startswith)rN  r  paddeds      rR  r  zgrvt.format_signature_rs  s:    R%%T"" 	!M&= rS  c                     |                                  dz  d|                     | j        dd          z  dz  z   }ddddt          |          |                                 | j        rdndd	S )
NrB  expirationSeconds   r   r  r   326325)ry  r  r  r  r`  r^  r  )r  r  r   r  r^  r  )rN  r`  s     rR  r  zgrvt.default_signature  s~    &&((72Wt?P?PQUQ]_rtv?w?w5wz~5~~
j//ZZ\\!%!:E
 
 	
rS  r  keyc                     |                      |dd          }|F|                     |                     ||z                      ||<   |                     |ddg          }||gS )Nuntiltill)safe_integer_2rE  r>  r!  )rN  r  r  r  
multiplierr  s         rR  rD  zgrvt.handle_until_option_string  sl    ##FGV<<001B1B5:CU1V1VWWGCLYYv'899F  rS  c                 z    |                      |                     | j        dd          d          }|| j        d<   |S )N	requestIdr   r  )r  r  r   )rN  r  s     rR  r  zgrvt.request_id  s;    HHT..t|[!LLaPP	$-[!rS  publicGETc                    |                      ||                     |                    }| j        d         |         |z   }d}	|dk    r |r|                     |          }	|d|	z   z  }n|dk    r|                     |          }|                    d          }
|
r|                                  |	dk    r|dz   |	z   }ddi}|                    d	          s|                    d
          rd|d<   n[|                     | j	        d          }|                     | j	        d          }||t          | j        dz             ||d<   ||d<   ||||dS )Nr   r  r  ?POSTprivatezContent-Typezapplication/jsonr   r   zrm=true;CookieAuthAccountIdAuthCookieValuezJ : at first, you need to authenticate with exchange using signIn() method.X-Grvt-Account-Id)urlmethodbodyheaders)r!  extract_paramsr   	urlencoder  r  r  endswithr  r   r   r0   )rN  pathr   r  r  r  r  r  r  queryString	isPrivater   cookieValues                rR  signz	grvt.sign  s   		&$"5"5d";";<<is#d*U?? )"nnU33s[((v99V$$DNN9--	 	9++---b  czK/ 2G }}122 9dmmDW6X6X 9$.!! ,,T\?KK	"..t|=NOO&)*;-dg  9E  /E  F  F  F$/!/8+,fdwOOOrS  reasonr  r  r  r  c
                 H   |                     d          s|                     d          r|                     |dd          }
|
| j        d<   |                     |dd          }|%|                    d          d	         }|| j        d
<   | j        d
         | j        d         t	          | j        dz             n|                     |d          }|>| j        dz   |z   }|                     | j        d         ||           t          |          |                     |d          }|>| j        dz   |z   }| 
                    | j        d         ||           t          |          |                     |d          }|"|dk    r| j        dz   |z   }t          |          d S )Nr   r   r  zx-grvt-account-idr  z
Set-Cookiez
set-cookie;r   r  z5 signIn() failed to receive auth-cookie or account-idr   rI  messagerJ  r  success)r  r  r   r<  r   r0   r  throw_exactly_matched_exceptionr   r   throw_broadly_matched_exception)rN  r  r$  r  r  r  r  r  requestHeadersrequestBodyr   cookier"  	errorCodefeedbackr(  r  s                    rR  handle_errorszgrvt.handle_errors-  s   <<,-- 	6>Q1R1R 	6**74GI\]]I,5DL)''|LLF!$ll3//22=./|-.6$,:W:_)$'4k*klll ;` ((6::I$7S=4/44T_W5MyZbccc#H---**8Y??&#w}t3H889QSZ\deee'111!--hAAF)f	.A.A#'7S=4#7+H555trS  r1  )NNN)T)NN)r  )`__name__
__module____qualname__r   rM  r  r  r  r  r  r  r   r   r  r  r   r  dictr   r  r  r   r  r  r	   r   r>  r   rH  r`  listrq  rw  r   r{  r  r  r   r  r  r   r  r  r  r  r   r  r  rA  r[   r  r  r\   r   r   r   r/  r4  rW  r[  r   r   ra  r~  r   r  r2  r  r
   r  r   r  r   r  r  r  r   r  r  r  r$  r  r?  r  r  r  r  r@  r  r  r  rD  r  r#  r1  __classcell__)rQ  s   @rR  r+   r+      s6       r# r r r r r rhO
 O
 O
b! ! !      " +-    ( /1    0 (* 8 8 8 8t $& ** **$v, ** ** ** **X[
f [
 [
 [
 [
z ') 5 5Z 5 5 5 52&$ &8 & & & &P 02 11 113 11f 11 11 11 11f4 44 4 46 4 4 4 4l :>b (u (us (u3 (uY (u (u (u (uT 6:UW -? -?3 -?s -?# -?\`af\g -? -? -? -?^N N Nv N N N N N` 26DW[df <K <K# <Kc <KQT <Kkoptku <K <K <K <K|
 
 
4 
 
 
 
0 8<$]ajl 0A 0A 0AC 0AWZ 0A 0A 0A 0Ad
 
& 
 
 
 
*! ! ! $& +* +*( +* +* +* +*Z+) +) +) +) +)Z *.Dt\^ 0K 0K3 0Kc 0K 0Kcghsct 0K 0K 0K 0Kd -1tRV_a ;K ;Kc ;K ;KC ;Kfjkvfw ;K ;K ;K ;Kz! !c ! !\_ ! ! ! !Fl
 l
T l
X l
Q\ l
 l
 l
 l
\ +/TPT]_ =" ="C ="s ="# ="dhivdw =" =" =" ="~3 3# 3S 3cf 3 3 3 3 [] 75 75S 75% 75c 75c 75an 75 75 75 75r.
 .
t .
x .
= .
 .
 .
 .
`15 15 15f KOWY (8 (8S (8% (8# (8C (8^i (8 (8 (8 (8T gksu {. {.3 {.i {.y {.RW {.`c {. {. {. {.z  0 0 0d -1tRV_a C= C=c C= C=C C= C= C= C=J 26b 45 45w 45T(^ 45 45 45 45l7 7t 7V 7 7 7 7r 26b 6 6w 6Y 6 6 6 6: 9=R 5 5S 5# 5 5 5 58
 
t 
V 
x 
 
 
 
: 7;2 6 6$s) 6+ 6 6 6 6:
 
D 
* 
 
 
 
& 37TX\eg 4@ 4@C 4@s 4@RU 4@ 4@ 4@ 4@l
 
6 
 
 
 
0 *.Dt\^ ]? ]?3 ]?c ]? ]?cghmcn ]? ]? ]? ]?~ /3TXac N= N= N=3 N=c N=hlmrhs N= N= N= N=` 26b R( R(c R(3 R( R( R( R(h~ ~ ~v ~ ~ ~ ~ ~@	9 	9 	9 	9 	9 	9? ? ? ? ? ?: : : : : /32 1 1 1 1 1 1> 37r ( (s (C ( ( ( (B	
 	
 	
7 7 77 7S 7 7gj 7vz 7 7 7 7r! ! ! ! !

 

 

! !c ! ! ! !  
 &eBSW P P P P:# s  c TX `c        rS  r+   )0ccxt.base.exchanger   ccxt.abstract.grvtr   r:  ccxt.base.typesr   r   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$   r%   r&   r'   ccxt.base.decimal_to_precisionr(   ccxt.base.preciser)   r+   r  rS  rR  <module>r?     s   ( ' ' ' ' ' * * * * * *  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k  k       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . . . . . . . ) ) ) ) ) ) , , , , , , . . . . . . ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %m0 m0 m0 m0 m08[ m0 m0 m0 m0 m0rS  