### Install GMX Python SDK using Pip Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md This snippet provides the command to install the GMX Python SDK directly from PyPI using the pip package manager, enabling quick setup for development. ```Shell pip install gmx-python-sdk ``` -------------------------------- ### Create and Configure Conda Environment for GMX Python SDK Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md This set of commands guides users through creating a new Conda environment, activating it, and installing all necessary Python dependencies (numpy, hexbytes, web3, pyaml, pandas, numerize) required for the GMX Python SDK to function correctly, especially if not using pip. ```Shell conda create --name gmx_sdk python=3.10 conda activate gmx_sdk pip install numpy pip install hexbytes pip install web3==6.10.0 pip install pyaml pip install pandas==1.4.2 pip install numerize ``` -------------------------------- ### Estimate GMX Swap Output in Python Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md This example demonstrates how to use the `EstimateSwapOutput` class to calculate the estimated output and price impact for a token swap on GMX. It allows specifying input and output tokens by either symbol or contract address. ```python from gmx_python_sdk.example_scripts.estimate_swap_output import EstimateSwapOutput from gmx_python_sdk.scripts.v2.gmx_utils import ConfigManager config = ConfigManager("arbitrum") config.set_config() in_token_symbol = "GMX" out_token_symbol = "USDC" token_amount = 10 in_token_address = None out_token_address = None token_amount_expanded = None output = EstimateSwapOutput(config=config).get_swap_output( in_token_symbol=in_token_symbol, out_token_symbol=out_token_symbol, token_amount=token_amount, in_token_address=in_token_address, out_token_address=out_token_address, token_amount_expanded=token_amount_expanded ) ``` ```APIDOC EstimateSwapOutput.get_swap_output: Estimates the output amount and price impact for a token swap. Parameters: in_token_symbol (str, optional): Symbol of the input token (e.g., "GMX"). out_token_symbol (str, optional): Symbol of the output token (e.g., "USDC"). token_amount (int/float): The amount of the input token. in_token_address (str, optional): Contract address of the input token. Used if symbol is not provided. out_token_address (str, optional): Contract address of the output token. Used if symbol is not provided. token_amount_expanded (str, optional): The token amount in expanded format (e.g., with decimals applied). If provided, `token_amount` is ignored. Returns: dict: A dictionary containing the estimated output number of tokens and the price impact. ``` -------------------------------- ### Process Swap Order Parameters with GMX Python SDK Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md This Python code demonstrates how to use the `OrderArgumentParser` to prepare parameters for a 'swap' order. The parser is configured with `is_swap=True`, and the `process_parameters_dictionary` method transforms the input dictionary. Key parameters for a swap include `out_token_symbol`, `start_token_symbol`, `size_delta_usd`, and `initial_collateral_delta` (amount of start tokens to swap out). ```python from gmx_python_sdk.scripts.v2.order.order_argument_parser import OrderArgumentParser from gmx_python_sdk.scripts.v2.gmx_utils import ConfigManager config = ConfigManager("arbitrum") config.set_config() parameters = { "chain": 'arbitrum', # token to use as collateral. Start token swaps into collateral token if different "out_token_symbol": "ETH", # the token to start with - WETH not supported yet "start_token_symbol": "USDC", # True for long, False for short "is_long": False, # Position size in in USD "size_delta_usd": 0, # Amount of start tokens to swap out "initial_collateral_delta": 10, # as a percentage "slippage_percent": 0.03 } order_parameters = OrderArgumentParser( config=config, is_swap=True ).process_parameters_dictionary( parameters ) ``` -------------------------------- ### Process Decrease Order Parameters with GMX Python SDK Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md This Python example illustrates how to utilize the `OrderArgumentParser` to format parameters for a 'decrease' order. The parser is initialized with `is_decrease=True`, and the `process_parameters_dictionary` method converts the input dictionary. Important parameters include `size_delta` for the position amount to close and `initial_collateral_delta` for the collateral to remove. ```python from gmx_python_sdk.scripts.v2.order.order_argument_parser import OrderArgumentParser from gmx_python_sdk.scripts.v2.gmx_utils import ConfigManager config = ConfigManager("arbitrum") config.set_config() parameters = { "chain": 'arbitrum', "index_token_symbol": "ARB", "collateral_token_symbol": "USDC", # set start token the same as your collateral "start_token_symbol": "USDC", "is_long": False, # amount of your position you want to close in USD "size_delta": 12, # amount of collateral you want to remove in collateral tokens "initial_collateral_delta": 6, # as a percentage "slippage_percent": 0.03 } order_parameters = OrderArgumentParser( config=config, is_decrease=True ).process_parameters_dictionary( parameters ) ``` -------------------------------- ### Retrieve GMX v2 Statistics with Python SDK Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md This example illustrates how to obtain various GMX v2 protocol statistics, such as available liquidity, borrow APR, claimable fees, TVL, funding APR, and open interest. The `GetGMXv2Stats` class can be initialized with options to save the output to JSON or CSV files. ```python from gmx_python_sdk.example_scripts.get_gmx_stats import GetGMXv2Stats from gmx_python_sdk.scripts.v2.gmx_utils import ConfigManager to_json = False to_csv = False config = ConfigManager(chain='arbitrum') config.set_config() stats_object = GetGMXv2Stats( config=config, to_json=to_json, to_csv=to_csv ) liquidity = stats_object.get_available_liquidity() borrow_apr = stats_object.get_borrow_apr() claimable_fees = stats_object.get_claimable_fees() contract_tvl = stats_object.get_contract_tvl() funding_apr = stats_object.get_funding_apr() gm_prices = stats_object.get_gm_price() markets = stats_object.get_available_markets() open_interest = stats_object.get_open_interest() oracle_prices = stats_object.get_oracle_prices() pool_tvl = stats_object.get_pool_tvl() ``` -------------------------------- ### Process Liquidity Withdraw Parameters with GMX Python SDK Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md This Python example demonstrates how to use the `LiquidityArgumentParser` to prepare parameters for a liquidity 'withdraw' operation. The parser is configured with `is_withdraw=True`, and the `process_parameters_dictionary` method transforms the input dictionary. Key parameters for a withdrawal include `market_token_symbol`, `out_token_symbol`, and `gm_amount` (the amount of GM tokens to withdraw). ```python from gmx_python_sdk.scripts.v2.order.liquidity_argument_parser import LiquidityArgumentParser from gmx_python_sdk.scripts.v2.gmx_utils import ConfigManager parameters = { "chain": "arbitrum", "market_token_symbol": "ETH", "out_token_symbol": "ETH", "gm_amount": 1 } output = LiquidityArgumentParser( config=config, is_withdraw=True ).process_parameters_dictionary( parameters ) ``` -------------------------------- ### Execute a Swap Order on GMX (Python) Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md Shows how to initiate a token swap on GMX using the Python SDK. This is done by instantiating a `SwapOrder` object, defining the input and output tokens, market, and other swap-specific parameters. ```python from gmx_python_sdk_scripts.v2.order.create_swap_order import SwapOrder order = SwapOrder( config=config, market_key=market_key, start_token=start_token, out_token=out_token, collateral_address=collateral_address, index_token_address=index_token_address, is_long=is_long, size_delta=size_delta, initial_collateral_delta_amount=initial_collateral_delta_amount, slippage_percent=slippage_percent, swap_path=swap_path, debug_mode=debug_mode ) ``` ```APIDOC SwapOrder Constructor Parameters: config: type obj An initialized configuration object (avalanche currently in testing still). market_key: type str The contract address of the GMX market you want to (first) market you want to swap through. start_token: type str The contract address of the token you start the swap with. out_token: type str The contract address of the token you want out. collateral_address: type str The contract address of the token you start the swap with. index_token: type str The contract address of the token you want out. is_long: type bool Set to False. size_delta_usd: type int Set to 0. initial_collateral_delta_amount: type int The amount of start token you are swapping. slippage_percent: type float The percentage you want to allow for price slippage. swap_path: type list() A list of GMX market addresses your swap will go through. debug_mode: type bool Set to true to create an order without submitting it. ``` -------------------------------- ### Create GMX Deposit Order in Python Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md This snippet demonstrates how to initialize a `DepositOrder` object to facilitate deposits into a GMX liquidity pool. It requires a configuration object, the target market key, and specifies initial long and short token amounts for the deposit. ```python from gmx_python_sdk_scripts.v2.order.create_deposit_order import DepositOrder order = DepositOrder( config=config, market_key=market_key, initial_long_token=initial_long_token, initial_short_token=initial_short_token, long_token_amount=long_token_amount, short_token_amount=short_token_amount, debug_mode=debug_mode ) ``` ```APIDOC DepositOrder(__init__): Initializes a new deposit order for a GMX pool. Parameters: config (obj): An initialized configuration object (e.g., for 'arbitrum'). market_key (str): The contract address of the GMX market for the deposit. initial_long_token (str, optional): The contract address of the token to deposit into the long side. Can be None. initial_short_token (str, optional): The contract address of the token to deposit into the short side. Can be None. long_token_amount (str): The amount of token to add to the long side. Can be '0'. short_token_amount (str): The amount of token to add to the short side. Can be '0'. debug_mode (bool): Set to true to create an order without submitting it. ``` -------------------------------- ### Process Increase Order Parameters with GMX Python SDK Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md This Python snippet demonstrates how to use the `OrderArgumentParser` class to process human-readable parameters for an 'increase' order. It initializes the parser with `is_increase=True` and then calls `process_parameters_dictionary` to reformat the input dictionary for order creation. Key parameters include `index_token_symbol`, `collateral_token_symbol`, `size_delta`, and `slippage_percent`. ```python from gmx_python_sdk.scripts.v2.order.order_argument_parser import OrderArgumentParser from gmx_python_sdk.scripts.v2.gmx_utils import ConfigManager config = ConfigManager("arbitrum") config.set_config() parameters = { "chain": 'arbitrum', # the market you want to trade on "index_token_symbol": "ARB", # the token you want as collateral "collateral_token_symbol": "ARB", # the token to start with "start_token_symbol": "USDC", # True for long, False for short "is_long": False, # in USD "size_delta": 6.69, # if leverage is passed, will calculate number of tokens in start_token_symbol amount "leverage": 1, # as a percentage "slippage_percent": 0.03 } order_parameters = OrderArgumentParser( config=config, is_increase=True ).process_parameters_dictionary( parameters ) ``` -------------------------------- ### GMX Python SDK Configuration File Structure Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md This YAML snippet illustrates the structure of the configuration file for the GMX Python SDK. It defines RPC endpoints for different chains (Arbitrum, Avalanche), their corresponding chain IDs, and placeholders for a user's private key and wallet address, essential for executing transactions. ```YAML rpcs: arbitrum: arbitrum_rpc avalanche: avax_rpc chain_ids: arbitrum: 42161 avalanche: 43114 private_key: private_key user_wallet_address: user_wallet_address ``` -------------------------------- ### Create GMX Withdrawal Order in Python Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md This snippet illustrates how to initialize a `WithdrawOrder` object to facilitate withdrawals from a GMX liquidity pool. It takes a configuration object, the market key, the desired output token, and the amount of GM tokens to burn. ```python from gmx_python_sdk_scripts.v2.order.create_withdrawal_order import WithdrawOrder order = WithdrawOrder( config=config, market_key=market_key, out_token=out_token, gm_amount=gm_amount, debug_mode=debug_mode ) ``` ```APIDOC WithdrawOrder(__init__): Initializes a new withdrawal order from a GMX pool. Parameters: config (obj): An initialized configuration object (e.g., for 'arbitrum'). market_key (str): The contract address of the GMX market to withdraw from. out_token (str): The contract address of the token to receive upon withdrawal. gm_amount (str): The amount of GM tokens to burn for the withdrawal. debug_mode (bool): Set to true to create an order without submitting it. ``` -------------------------------- ### Process Liquidity Deposit Parameters with GMX Python SDK Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md This Python snippet illustrates the use of the `LiquidityArgumentParser` class to process parameters for a liquidity 'deposit' operation. The parser is initialized with `is_deposit=True`, and the `process_parameters_dictionary` method converts the input dictionary into the required format. Relevant parameters include `market_token_symbol`, `long_token_usd`, and `short_token_usd` for specifying the deposit amounts. ```python from gmx_python_sdk.scripts.v2.order.liquidity_argument_parser import LiquidityArgumentParser from gmx_python_sdk.scripts.v2.gmx_utils import ConfigManager config = ConfigManager("arbitrum") config.set_config() parameters = { "chain": "arbitrum", "market_token_symbol": "ETH", "long_token_symbol": "ETH", "short_token_symbol": "USDC", "long_token_usd": 10, "short_token_usd": 10 } output = LiquidityArgumentParser( config=config, is_deposit=True ).process_parameters_dictionary( parameters ) ``` -------------------------------- ### Create or Increase GMX Position (Python) Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md Demonstrates how to create or increase a trading position on GMX using the Python SDK. This involves instantiating an `IncreaseOrder` object with various parameters defining the market, collateral, trade direction, and size. ```python from gmx_python_sdk_scripts.v2.order.create_increase_order import IncreaseOrder order = IncreaseOrder( config=config, market_key=market_key, collateral_address=collateral_address, index_token_address=index_token_address, is_long=is_long, size_delta_usd=size_delta_usd, initial_collateral_delta_amount=initial_collateral_delta_amount, slippage_percent=slippage_percent, swap_path=swap_path, debug_mode=debug_mode ) ``` ```APIDOC IncreaseOrder Constructor Parameters: config: type obj An initialized configuration object (avalanche currently in testing still). market_key: type str The contract address of the GMX market you want to increase a position on. collateral_address: type str The contract address of the token you want to use as collateral. index_token_address: type str The contract address of the token you want to trade. is_long: type bool True for a long position or False for a short position. size_delta_usd: type int The size of the position you want to open, represented as 10^30. initial_collateral_delta_amount: type int The amount of token you want to use as collateral, represented as 10^decimal of that token. slippage_percent: type float The percentage you want to allow for price slippage. swap_path: type list(str) A list of the GMX markets you will need to swap through if the starting token is different from the collateral token. debug_mode: type bool Set to true to create an order without submitting it. ``` -------------------------------- ### Enable Debug Mode for GMX Order Creation in Python Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md This snippet demonstrates how to initialize an order creation class (e.g., `IncreaseOrder`) in debug mode. Setting `debug_mode=True` allows users to submit parameters and build transaction data without actually executing the transaction on the blockchain, which is useful for testing and validation. ```python from gmx_python_sdk.scripts.v2.order.create_increase_order import IncreaseOrder order = IncreaseOrder( config=config, market_key=market_key, collateral_address=collateral_address, index_token_address=index_token_address, is_long=is_long, size_delta_usd=size_delta_usd, initial_collateral_delta_amount=initial_collateral_delta_amount, slippage_percent=slippage_percent, swap_path=swap_path, debug_mode=True ) ``` -------------------------------- ### Close GMX Positions using Python SDK Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md This snippet demonstrates how to close open GMX positions by first fetching all active positions and then transforming the relevant position data into order parameters. It allows specifying the amount of position size or collateral to close as a decimal. ```python from gmx_python_sdk.example_scripts.get_positions import get_positions, transform_open_position_to_order_parameters from gmx_python_sdk.scripts.v2.gmx_utils import ConfigManager config = ConfigManager(chain='arbitrum') config.set_config() address = None market_symbol = "ETH" out_token = "ETH" is_long = False slippage_percent = 0.003 amount_of_position_to_close = 1 amount_of_collateral_to_remove = 1 # gets all open positions as a dictionary, which the keys as each position positions = get_positions( config=config, address=address ) order_parameters = transform_open_position_to_order_parameters( config=config, positions=positions, market_symbol=market_symbol, is_long=is_long, slippage_percent=slippage_percent, out_token=out_token, amount_of_position_to_close=amount_of_position_to_close, amount_of_collateral_to_remove=amount_of_collateral_to_remove ) ``` -------------------------------- ### Specify Python Version for GMX Python SDK Development Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md This snippet indicates the specific Python version (3.10.4) that the GMX Python SDK was developed and tested with, ensuring compatibility for users. ```Python python=3.10.4 ``` -------------------------------- ### Close or Decrease GMX Position (Python) Source: https://github.com/snipermonke01/gmx_python_sdk/blob/main/README.md Illustrates how to close or decrease an existing trading position on GMX using the Python SDK. It involves creating a `DecreaseOrder` object, specifying the market, collateral, trade direction, and the amount by which to reduce the position. ```python from gmx_python_sdk_scripts.v2.order.create_decrease_order import DecreaseOrder order = DecreaseOrder( config=config, market_key=market_key, collateral_address=collateral_address, index_token_address=index_token_address, is_long=is_long, size_delta_usd=size_delta_usd, initial_collateral_delta_amount=initial_collateral_delta_amount, slippage_percent=slippage_percent, swap_path=swap_path, debug_mode=debug_mode ) ``` ```APIDOC DecreaseOrder Constructor Parameters: config: type obj An initialized configuration object (avalanche currently in testing still). market_key: type str The contract address of the GMX market you want to decrease a position for. collateral_address: type str The contract address of the token you are using as collateral. index_token_address: type str The contract address of the token you are trading. is_long: type bool True for a long position or False for a short position. size_delta_usd: type int The size of the decrease to apply to your position, represented as 10^30. initial_collateral_delta_amount: type int The amount of collateral token you want to remove, represented as 10^decimal of that token. slippage_percent: type float The percentage you want to allow for price slippage. swap_path: type list(str) A list of the GMX markets you will need to swap through to get your desired out token. debug_mode: type bool Set to true to create an order without submitting it. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.