Example setup functions in python

Supported Markets

Asset

Market ID

Description

APT/USDC

301

Aptos-based trading market.

BTC/USDC

302

Bitcoin-based trading market.

ETH/USDC

303

Ethereum-based trading market.

Prerequisites

Install Required Packages

Before you begin, install the following dependencies:

pip install requests
pip install os
pip install aptos_sdk

We will see how to implement the view functions : (Example get market info function)

1. Get Market Info:

# 1. Importing Required Libraries
import requests
import os

# 2. Main Function Setup
def main():
    try:
        # 3. API Endpoint Setup
        base_url = 'https://perps-tradeapi.kanalabs.io/getMarketInfo'

        # 4. Parameters Setup
        params = {
            'marketId': 'your_marketId'  # Replace with the actual marketId Eg: --> 66, 67, 68 --> (type number)
        }

        # 5. Headers Setup
        headers = {
            'x-api-key': os.getenv('API_KEY')  # API key passed in the headers from environment variables
        }

        # 6. API Request
        response = requests.get(base_url, params=params, headers=headers)

        # Ensure the response is successful
        response.raise_for_status()

        # 7. Extract and Log Data
        get_market_info = response.json()
        print("getMarketInfo: ", get_market_info)

    # 8. Error Handling
    except requests.exceptions.RequestException as error:
        print('An error occurred:', error)

# 9. Call the Main Function
if __name__ == "__main__":
    try:
        main()
    except Exception as error:
        print('An error occurred:', error)

We will see how to implement the run functions : (Example deposit function)

2. Depsoit Function:

We will see how to implement the websocket client initialization code: (Example order book stream) Example code to fetch the Order Book Client Initialization Code:

3. Order Book Stream:

Example code to fetch the Fill Events Client Initialization Code:

4. Fill Events Stream: (Recent Trdes)

We will see how to implement the Fill Events Data :

5. Get Fill Events Data:

We will see how to implement the Order Status Data:

6. Get Order Status Data:

Last updated