Perpetual

Spot

hot
hot

APEX BLOG

Stay at the forefront of decentralization
with regular ApeX news, deals and research.


    Filters
    AllLearn

    A Practical Guide to Integrating ApeX API

    Apr 03, 2024

    3 min read

    DEX

    ApeX

    Order Book

    banner

    ApeX API empowers you to elevate your trades by enabling the integration of trading bots and applications with ApeX's decentralized and self-custodial trading platform, ApeX Pro. This unlocks a world of possibilities, including automated trading, real-time market analysis and advanced strategies. Supporting popular programming languages like Python, Java, and Node.js, the ApeX API is widely accessible.

    Let's dive into how to get set up with ApeX API.

    Getting Started with the ApeX API

    Obtaining Stark Key

    1. To get started, head to your ApeX account and navigate to your user profile (under your wallet address). Click on API Management in the dropdown menu to proceed. Next, click on Stark Key. Your Stark Key will provide you with full permission to trade and withdraw on ApeX Pro.

    1. Please note that your Stark Key is unique, and cannot be modified. Read the Terms and Conditions carefully, and click on Next when you agree.

    Generating an API

    1. Click on Generate API. Proceed by filling in your API Name, and selecting your IP Address Access. Choose between Unrestricted Access or Restrict to Trusted IPs Only. Note: Unrestricted Access allows access from any IP address. We recommend opting for Restrict to Trusted IP's Only as it's more secure to pair your API Key with trusted third-party platforms.

    1. Once you have configured your API settings, your API management system will be successfully set up! It is important to note that your API Key Passphrase and API Key Secret will only be visible during the creation process and will not be accessible thereafter. Therefore, it is crucial to ensure that you secure your keys in a safe and secure location.

      Note: Please keep your API credentials confidential. Treat them like your login credentials and avoid sharing them with anyone. Click on Done to return to the API management page.

      To re-visit all the details of your API Management system, click on View.

    You've now successfully generated all the information required for you to trade and withdraw on ApeX Pro with an API! Remember to save your API Key upon generation, as it will not be displayed again.

    Connecting your API with Python3 API Connector

    1. To install the official Python3 API connector, use pip, the Python package installer. Follow the official Python guide on how to install pip here.

    2. Next, integrate ApeX with Python by typing in the following command: pip install apexpro.

    3. To generate a web session (HTTP session), import the apexpro.constants and apexpro.http_public modules by using the following commands:

    1. Create an HTTP session using the HttpPublic class, specifying the desired environment (e.g., APEX_HTTP_MAIN for Mainnet). Choose between Testnet and Mainnet to create an HTTP session from.

    Placing Trades

    1. To place a trade, import apexpro.http_private_stark_key_sign module.

    2. Initiate the HttpPrivateStark class, providing your API credentials, Private Stark Key, and other order parameters.

    3. Use create_order_v2 method to create various order types with specific details like symbol, side (buy/sell), price, and quantity.

    Canceling Orders

    1. Import apexpro.http_private module.

    2. Add HttpPrivate class with your API credentials.

    3. Use the delete_order method, specifying the order ID and token to cancel an existing order.

    Reviewing Open Orders

    1. Initiate HttpPrivate class.

    2. Use the open_orders_v2 command with the desired token to retrieve a list of your currently open orders.


    Beyond just placing and cancelling orders, users can use APIs for a range of features such as fetching funding rates, accessing market depth, retrieving candlestick data, and obtaining ticker data. APIs can also be used to highlight how to access historical funding rate data, providing a comprehensive overview of the tools at your disposal for advanced trading strategies.

    Stay tuned to our upcoming articles that will delve into additional functions of APIs.

    Happy Trading!

    2