
    _%j                        d dl mZ d dlmZ d dlZd dlmZ d dlmZm	Z	 d dl
mZ d dlmZmZ d dlmZ  G d	 d
e	          ZdS )    )annotations)DecimalN)Any)ExecutionResultHyperliquidLiveExecutor)OrderIntent)PreparedOrderPayloadprepare_order_payload)HyperliquidAssetMetac                  :    e Zd ZdZddZddZddZdddddZdS )HyperliquidTestnetExecutorzISDK-compatible executor boundary for testnet; separately wired from live.returnNonec                F   t          j        dd                                          dk    rt          d          t          j        dd                                          dk    rt          d          t          j        d          | j        k    rt          d	          d S )
N
CTB_HL_ENV testnetz0CTB_HL_ENV must be testnet for testnet executionCTB_TESTNET_TRADING_ALLOWEDtruezACTB_TESTNET_TRADING_ALLOWED must be true before testnet executionCTB_TESTNET_CONFIRMATIONz=CTB_TESTNET_CONFIRMATION does not match expected confirmation)osgetenvlowerPermissionErrorexpected_confirmation)selfs    `/home/agent/projects/CryptoTradingBot/Crypto_Agent/src/execution/hyperliquid_testnet_executor.py_check_testnet_gatesz/HyperliquidTestnetExecutor._check_testnet_gates   s    9\2&&,,..);;!"TUUU92B77==??6II!"efff9/00D4NNN!"abbb ON    intentr   metar   min_notional_usdr   r	   c               (    t          |||d          S )NT)r"   require_testnet)r
   )r   r    r!   r"   s       r   prepare_payloadz*HyperliquidTestnetExecutor.prepare_payload   s    $VTDTfjkkkkr   r   c                   | j         rt          d|d          S |                                  |j        dk    }| j                            |j        |t          |j                  d d           }t          d||d          S )Ndry_run )statusr    side_effectsbuytestnet_submitted)hyperliquid_testnet_order)r)   r    exchange_responser*   )	r'   r   r   sideexchangemarket_opencoinfloatsize)r   r    is_buyresponses       r   executez"HyperliquidTestnetExecutor.execute   s    < 	U")FQSTTTT!!###%=,,V[&%BTBTVZ\`aa&9&\d  tR  S  S  S  	Sr   N)oidcloidr2   strr8   
int | Noner9   
str | Noner   c                   | j         rd|||dS |                                  || j                            ||          S || j                            ||          S t          d          )Nr'   )r)   r2   r8   r9   zoid or cloid required)r'   r   r0   cancelcancel_by_cloid
ValueError)r   r2   r8   r9   s       r   cancel_by_oid_or_cloidz1HyperliquidTestnetExecutor.cancel_by_oid_or_cloid#   s{    < 	S'cERRR!!###?=''c222=00u===0111r   )r   r   )r    r   r!   r   r"   r   r   r	   )r    r   r   r   )r2   r:   r8   r;   r9   r<   r   r   )__name__
__module____qualname____doc__r   r%   r7   rA   r(   r   r   r   r      s        SSc c c cl l l lS S S S FJ_c 2 2 2 2 2 2 2 2r   r   )
__future__r   decimalr   r   typingr   'src.execution.hyperliquid_live_executorr   r   src.execution.order_intentr   src.execution.payloadsr	   r
   src.hyperliquid.roundingr   r   r(   r   r   <module>rM      s    " " " " " "       				       \ \ \ \ \ \ \ \ 2 2 2 2 2 2 N N N N N N N N 9 9 9 9 9 92 2 2 2 2!8 2 2 2 2 2r   