### Get Market Info - Python Example Source: https://docs.pacifica.fi/api-documentation/api/rest-api/markets/get-market-info This Python code snippet demonstrates how to call the /api/v1/info endpoint using the requests library. It sends a GET request and then parses the JSON response. Ensure the 'requests' library is installed. ```Python import requests response = requests.get( "/api/v1/info", headers={\"Accept\": \"*/*\"}, ) data = response.json() ``` -------------------------------- ### Python: Setup and Initialize Keypair Source: https://docs.pacifica.fi/api-documentation/api/signing/implementation Initializes a Keypair object from a private key using base58 encoding. This is the first step in signing any API request. ```python import time import base58 import requests from solders.keypair import Keypair PRIVATE_KEY = "your_private_key_here" # Generate keypair from private key keypair = Keypair.from_bytes(base58.b58decode(PRIVATE_KEY)) public_key = str(keypair.pubkey()) ``` -------------------------------- ### Pacifica API Signing Process Source: https://docs.pacifica.fi/api-documentation/api/signing/implementation This section outlines the complete process of creating a signed request for the Pacifica API, from initial setup to building the final request payload. ```APIDOC ## Pacifica API Signing Guide This guide provides a step-by-step breakdown of Pacifica's signing implementation. ### 1. Setup and Initialization This step involves setting up your environment, including importing necessary libraries and generating a keypair from your private key. ```python import time import base58 import requests from solders.keypair import Keypair PRIVATE_KEY = "your_private_key_here" # Generate keypair from private key keypair = Keypair.from_bytes(base58.b58decode(PRIVATE_KEY)) public_key = str(keypair.pubkey()) ``` ### 2. Choose Endpoint and Define Operation Type Select the appropriate API endpoint and define the operation type and its associated data. For example, creating an order: ```python API_URL = "https://api.pacifica.fi/api/v1/orders/create" operation_type = "create_order" operation_data = { "symbol": "BTC", "price": "100000", "amount": "0.1", "side": "bid", "tif": "GTC", "reduce_only": False, "client_order_id": str(uuid.uuid4()), } ``` ### 3. Create Signature Header Construct the signature header, including a timestamp and an optional `expiry_window`. Timestamps should be in milliseconds. ```python # Get current timestamp in milliseconds timestamp = int(time.time() * 1_000) signature_header = { "timestamp": timestamp, "expiry_window": 5_000, "type": "create_order", } ``` ### 4. Combine Header and Payload Merge the signature header and the operation data into a single dictionary. ```python data_to_sign = { **signature_header, "data": operation_data, } ``` ### 5. Recursively Sort JSON Keys Implement a function to recursively sort all keys within the combined dictionary alphabetically. This ensures consistent message formatting for signing. ```python def sort_json_keys(value): if isinstance(value, dict): sorted_dict = {} for key in sorted(value.keys()): sorted_dict[key] = sort_json_keys(value[key]) return sorted_dict elif isinstance(value, list): return [sort_json_keys(item) for item in value] else: return value sorted_message = sort_json_keys(data_to_sign) ``` ### 6. Create Compact JSON Convert the sorted dictionary into a compact JSON string with no whitespace. ```python import json compact_json = json.dumps(sorted_message, separators=(',', ':')) ``` ### 7. Convert to Bytes and Generate Signature Encode the compact JSON string to UTF-8 bytes and then sign these bytes using your private key. Convert the resulting signature to a Base58 string. ```python # Convert to UTF-8 bytes message_bytes = compact_json.encode("utf-8") # Sign message bytes using your private key signature = keypair.sign_message(message_bytes) # Convert signature to Base58 string signature_b58 = base58.b58encode(bytes(signature)).decode("ascii") ``` ### 8. Build Final Request Construct the final request by combining the authentication headers (including the generated signature) with the original operation data fields. ```python request_header = { "account": public_key, "agent_wallet": None, "signature": signature_b58, "timestamp": signature_header["timestamp"], "expiry_window": signature_header["expiry_window"], } final_request = { **request_header, **operation_data, # Use the ORIGINAL create order fields } ``` ``` -------------------------------- ### Python Example: Fetching Account Settings Source: https://docs.pacifica.fi/api-documentation/api/rest-api/account/get-account-settings This Python code demonstrates how to use the 'requests' library to call the /api/v1/account/settings endpoint and parse the JSON response. It includes setting the 'Accept' header. ```python import requests response = requests.get( "/api/v1/account/settings?account=42trU9A5...", headers={"Accept": "*/*"}, ) data = response.json() ``` -------------------------------- ### Fetch Prices using Python Requests Source: https://docs.pacifica.fi/api-documentation/api/rest-api/markets/get-prices This Python code example demonstrates how to use the 'requests' library to call the '/api/v1/info/prices' endpoint and parse the JSON response. ```python import requests response = requests.get( "/api/v1/info/prices", headers={"Accept": "*/*"}, ) data = response.json() ``` -------------------------------- ### Get Kline Data Endpoint and Example URL Source: https://docs.pacifica.fi/api-documentation/api/rest-api/markets/get-kline-candle-data This snippet shows the API endpoint for retrieving kline data and an example of how to construct the URL with query parameters. ```HTTP /api/v1/kline ``` ```HTTP /api/v1/kline?symbol=BTC&interval=1m&start_time=1742243160000&end_time=1742243220000 ``` -------------------------------- ### Fetch Account Info with Python Source: https://docs.pacifica.fi/api-documentation/api/rest-api/account/get-account-info This Python code example demonstrates how to use the 'requests' library to call the /api/v1/account endpoint and parse the JSON response. ```Python import requests response = requests.get( "/api/v1/account?account=42trU9A5...", headers={"Accept": "*/*"}, ) data = response.json() ``` -------------------------------- ### Python Request for Account Balance History Source: https://docs.pacifica.fi/api-documentation/api/rest-api/account/get-account-balance-history This Python code example demonstrates how to use the 'requests' library to fetch account balance history from the API. It shows how to make the GET request and parse the JSON response. ```Python import requests response = requests.get( "/api/v1/portfolio?account/balance/history?account=42trU9A5..." headers={"Accept": "*/*"}, ) data = response.json() ``` -------------------------------- ### Get Funding History with Python Source: https://docs.pacifica.fi/api-documentation/api/rest-api/account/get-funding-history This Python code example demonstrates how to make a GET request to the funding history API using the 'requests' library. It shows how to send the request and parse the JSON response. ```Python import requests response = requests.get( "/api/v1/funding/history?account=42trU9A5...&limit=100&offset=0", headers={"Accept": "*/*"}, ) data = response.json() ``` -------------------------------- ### Python Example for Getting Recent Trades Source: https://docs.pacifica.fi/api-documentation/api/rest-api/markets/get-recent-trades A Python code snippet using the 'requests' library to call the 'Get Recent Trades' API endpoint and parse the JSON response. ```Python import requests response = requests.get( "/api/v1/trades?symbol=BTC", headers={\"Accept\": \"*/*\"}, ) data = response.json() ``` -------------------------------- ### Get Positions with Account Query Source: https://docs.pacifica.fi/api-documentation/api/rest-api/account/get-positions This example demonstrates how to construct the URL for the Get Positions endpoint, including the required 'account' query parameter to filter positions for a specific wallet address. ```HTTP /api/v1/positions?account=42trU9A5... ``` -------------------------------- ### Python Get Positions Request Source: https://docs.pacifica.fi/api-documentation/api/rest-api/account/get-positions This Python code example shows how to make a GET request to the Pacifica API's positions endpoint using the `requests` library. It includes setting the appropriate headers and parsing the JSON response. ```Python import requests response = requests.get( "/api/v1/positions?account=42trU9A5...", headers={"Accept": "*/*"}, ) data = response.json() ``` -------------------------------- ### Example Funding Rate History Request URL Source: https://docs.pacifica.fi/api-documentation/api/rest-api/markets/get-historical-funding An example of a complete URL to query the funding rate history for BTC with a limit of 200 and offset of 0. ```URL /api/v1/funding_rate/history?symbol=BTC&limit=200&offset=0 ``` -------------------------------- ### Fetch Orderbook Data (Python) Source: https://docs.pacifica.fi/api-documentation/api/rest-api/markets/get-orderbook A Python example using the 'requests' library to fetch orderbook data from the Pacifica API. It demonstrates making a GET request and parsing the JSON response. ```Python import requests response = requests.get( "api.pacifica.fi/api/v1/book?symbol=BTC", headers={\"Accept\": \"*/*\"}, ) data = response.json() ``` -------------------------------- ### Trade History Request with Parameters Source: https://docs.pacifica.fi/api-documentation/api/rest-api/account/get-trade-history An example of a GET request to the trade history endpoint, including common query parameters for filtering and pagination. ```http /api/v1/positions/history?account=42trU9A5...&start_time=1625097600000&end_time=1625184000000&granularity_in_minutes=60&limit=100" ``` -------------------------------- ### Stop Order Response Examples Source: https://docs.pacifica.fi/api-documentation/api/rest-api/orders/create-stop-order Examples of responses from the create stop order endpoint, including success (200) and error cases (400, 500). ```JSON { "order_id": 12345 } ``` ```JSON { "error": "Invalid stop order parameters", "code": 400 } ``` -------------------------------- ### Python Example: Fetch Trade History Source: https://docs.pacifica.fi/api-documentation/api/rest-api/account/get-trade-history A Python code snippet demonstrating how to use the 'requests' library to call the trade history endpoint and parse the JSON response. ```python import requests response = requests.get( "/api/v1/positions/history?account=42trU9A5...&symbol=BTC&limit=100&offset=0", headers={"Accept": "*/*"}, ) data = response.json() ``` -------------------------------- ### GET /api/v1/account/settings Source: https://docs.pacifica.fi/api-documentation/api/rest-api/account/get-account-settings Fetches the account's margin and leverage settings. Only non-default settings are returned. Markets with default settings will not appear in the response. ```APIDOC ## GET /api/v1/account/settings ### Description Retrieves the account's margin and leverage settings. This endpoint returns only the settings that have been explicitly changed from their default values (cross margin and max leverage). ### Method GET ### Endpoint /api/v1/account/settings ### Parameters #### Query Parameters - **account** (string) - required - The address of the account to retrieve settings for. ### Request Example ``` /api/v1/account/settings?account=42trU9A5... ``` ### Response #### Success Response (200) - **symbol** (string) - Trading pair symbol. - **isolated** (boolean) - Indicates if isolated margining is enabled for this symbol. - **leverage** (integer) - The current leverage set by the user (defaults to max). - **created_at** (integer) - Timestamp in milliseconds when these settings were adjusted from their default. - **updated_at** (integer) - Timestamp in milliseconds when these settings were last updated. #### Response Example ```json [ { "symbol": "ETH", "isolated": true, "leverage": 30, "created_at": 1748936203604, "updated_at": 1748936203604 } ] ``` #### Error Responses - **400**: Invalid request parameters. - **401**: Unauthorized access. - **500**: Internal server error. ``` -------------------------------- ### Cancel Stop Order Python Example Source: https://docs.pacifica.fi/api-documentation/api/rest-api/orders/cancel-stop-order Python code example using the 'requests' library to call the cancel stop order endpoint. ```python import requests payload = { "account": "42trU9A5...", "signature": "5j1Vy9Uq...", "timestamp": 1716200000000, "symbol": "BTC", "order_id": 123 } response = requests.post( "/api/v1/orders/stop/cancel", json=payload, headers={"Content-Type": "application/json"} ) data = response.json() ``` -------------------------------- ### Cancel All Orders - Python SDK Example Source: https://docs.pacifica.fi/api-documentation/api/rest-api/orders/cancel-all-orders Python code example demonstrating how to use the requests library to call the cancel all orders endpoint with a JSON payload. ```python import requests payload = { "account": "42trU9A5...", "signature": "5j1Vy9Uq...", "timestamp": 1716200000000, "all_symbols": True, "exclude_reduce_only": False } response = requests.post( "/api/v1/orders/cancel_all", json=payload, headers={"Content-Type": "application/json"} ) data = response.json() ``` -------------------------------- ### Account Settings Response Structure Source: https://docs.pacifica.fi/api-documentation/api/rest-api/account/get-account-settings This is an example of a successful response (Status 200) when retrieving account settings. Each object in the array represents a trading symbol with its specific margin and leverage configurations. ```json [ { "symbol": "ETH", "isolated": true, "leverage": 30, "created_at": 1748936203604, "updated_at": 1748936203604 } ] ``` -------------------------------- ### Stop Order Request Body Example Source: https://docs.pacifica.fi/api-documentation/api/rest-api/orders/create-stop-order Example JSON payload for creating a stop order. It includes account details, signature, timestamp, trading symbol, order side, reduce-only flag, and stop order configuration. ```JSON { "account": "42trU9A5...", "signature": "5j1Vy9Uq...", "timestamp": 1716200000000, "symbol": "BTC", "side": "long", "reduce_only": true, "stop_order": { "stop_price": "48000", "limit_price": "47950", "client_order_id": "d25ac10b-58cc-4372-a567-0e02b2c3d479", "amount": "0.1" }, "agent_wallet": "69trU9A5...", "expiry_window": 30000 } ``` -------------------------------- ### Get Account Settings Endpoint Source: https://docs.pacifica.fi/api-documentation/api/rest-api/account/get-account-settings This snippet shows the GET request to retrieve account settings. It requires an 'account' query parameter specifying the account address. The response will contain margin and leverage settings for markets that deviate from default values. ```HTTP GET /api/v1/account/settings?account=42trU9A5... ``` -------------------------------- ### Get Prices Source: https://docs.pacifica.fi/api-documentation/api/rest-api/markets/get-prices Retrieves price information for all supported trading symbols, including mark prices, funding rates, and market statistics. ```APIDOC ## GET /api/v1/info/prices ### Description This endpoint allows users to get price information for all symbols, including mark prices, funding rates, and market statistics. ### Method GET ### Endpoint /api/v1/info/prices ### Parameters ### Request Body ### Request Example ```python import requests response = requests.get( "/api/v1/info/prices", headers={\"Accept\": \"*/*\"}, ) data = response.json() ``` ### Response #### Success Response (200) - **funding** (decimal string) - funding rate paid in the past funding epoch (hour) - **mark** (decimal string) - Mark price - **mid** (decimal string) - Mid price, defined as the average of the best bid and best ask price - **next_funding** (decimal string) - estimated funding rate to be paid in the next funding epoch (hour) - **open_interest** (decimal string) - The current open interest on this symbol (in USD) - **oracle** (decimal string) - Oracle price - **symbol** (string) - Trading pair symbol - **timestamp** (integer) - Timestamp in Milliseconds - **volume_24h** (boolean) - Volume (USD) of this market in the past 24 hours - **yesterday_price** (decimal string) - Oracle price of this market 24 hours ago (USD) #### Response Example ```json [ { "funding": "0.00001250", "mark": "84050", "mid": "84050", "next_funding": "0.00001250", "open_interest": "1000000", "oracle": "84000", "symbol": "BTC", "timestamp": 1742243160000, "volume_24h": "5000000", "yesterday_price": "83500" } ] ``` #### Error Response - Status 404: No prices data available - Status 500: Internal server error ``` -------------------------------- ### Python Request to Get Open Orders Source: https://docs.pacifica.fi/api-documentation/api/rest-api/orders/get-open-orders This Python code snippet utilizes the `requests` library to make a GET request to the Pacifica API for open orders. It includes setting the account parameter and handling the JSON response. ```python import requests response = requests.get( "/api/v1/orders?account=42trU9A5...", headers={"Accept": "*/*"}, ) data = response.json() ``` -------------------------------- ### Python: Create Signature Header Source: https://docs.pacifica.fi/api-documentation/api/signing/implementation Generates the necessary header fields for signing, including timestamp and an optional expiry window. The timestamp is in milliseconds. ```python # Get current timestamp in milliseconds timestamp = int(time.time() * 1_000) signature_header = { "timestamp": timestamp, "expiry_window": 5_000, "type": "create_order", } ``` -------------------------------- ### Python: Combine Header and Payload for Signing Source: https://docs.pacifica.fi/api-documentation/api/signing/implementation Merges the signature header with the operation data into a single dictionary. This combined structure is what will be signed. ```python data_to_sign = { **signature_header, "data": operation_data, } ``` -------------------------------- ### GET /api/v1/account/api_keys Source: https://docs.pacifica.fi/api-documentation/api/signing/operation-types Lists all API keys associated with the account. ```APIDOC ## GET /api/v1/account/api_keys ### Description Lists all API keys associated with the account. ### Method GET ### Endpoint /api/v1/account/api_keys ### Parameters ### Request Example GET /api/v1/account/api_keys ### Response #### Success Response (200) - **api_keys** (array) - A list of API key objects. - **api_key** (string) - The API key. - **created_at** (string) - The timestamp when the key was created. #### Response Example { "api_keys": [ { "api_key": "pk_live_abcdef12345", "created_at": "2023-10-27T10:00:00Z" } ] } ``` -------------------------------- ### Python Code Example for Creating Market Order Source: https://docs.pacifica.fi/api-documentation/api/rest-api/orders/create-market-order This Python script demonstrates how to use the 'requests' library to send a POST request to the create market order endpoint. It includes a sample payload and shows how to process the JSON response. ```Python import requests payload = { "account": "42trU9A5...", "signature": "5j1Vy9Uq...", "timestamp": 1716200000000, "symbol": "BTC", "amount": "0.1", "side": "bid", "slippage_percent": 1, "reduce_only": False, "client_order_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479" } response = requests.post( "/api/v1/orders/create_market", json=payload, headers={"Content-Type": "application/json"} ) data = response.json() ``` -------------------------------- ### Get Order History by ID (HTTP Request) Source: https://docs.pacifica.fi/api-documentation/api/rest-api/orders/get-order-history-by-id This snippet shows the HTTP GET request to retrieve order history by a specific order ID. It includes the endpoint and a query parameter example. ```HTTP GET /api/v1/orders/history_by_id?order_id=13753364 ``` -------------------------------- ### Python Example for Updating Leverage Source: https://docs.pacifica.fi/api-documentation/api/rest-api/account/update-leverage A Python code snippet demonstrating how to use the `requests` library to call the `/api/v1/account/leverage` endpoint. It shows how to construct the payload and headers for the POST request. ```python import requests payload = { "account": "42trU9A5...", "signature": "5j1Vy9Uq...", "timestamp": 1716200000000, "symbol": "BTC", "leverage": 10 } response = requests.post( "/api/v1/account/leverage", json=payload, headers={"Content-Type": "application/json"} ) data = response.json() ``` -------------------------------- ### Place Market Order using Agent Wallet (Python) Source: https://docs.pacifica.fi/api-documentation/api/signing/agent-wallet This Python SDK example shows how to place a market order using an agent wallet for message signing. It includes adding the agent wallet's public key to the request payload. ```python import pacifica_sdk # Assume agent_wallet is already generated and contains 'public_key' and 'private_key' # Example of placing a market order using an agent wallet order_payload = { "symbol": "BTC/USD", "side": "buy", "order_type": "market", "qty": 1, "agent_wallet": agent_wallet['public_key'] } # Sign the request using the agent wallet's private key signed_payload = pacifica_sdk.sign_request(order_payload, agent_wallet['private_key']) # Send the signed request to the Pacifica API (e.g., using requests library) # response = requests.post(f"{pacifica_sdk.API_URL}/orders", json=signed_payload) # print(response.json()) ``` -------------------------------- ### Get Orderbook with Query Parameters Source: https://docs.pacifica.fi/api-documentation/api/rest-api/markets/get-orderbook Example of how to call the orderbook endpoint with a required 'symbol' query parameter. An optional 'agg_level' can be provided for price grouping. ```HTTP api/v1/book?symbol=BTC ``` -------------------------------- ### POST /api/v1/account/api_keys/create Source: https://docs.pacifica.fi/api-documentation/api/signing/operation-types Creates a new API key. ```APIDOC ## POST /api/v1/account/api_keys/create ### Description Creates a new API key. ### Method POST ### Endpoint /api/v1/account/api_keys/create ### Parameters #### Request Body - **operation_type** (string) - Required - The type of operation, which is "create_api_key". ### Request Example { "operation_type": "create_api_key" } ### Response #### Success Response (200) - **api_key** (string) - The generated API key. - **secret_key** (string) - The secret key associated with the API key. #### Response Example { "api_key": "pk_test_abcdef12345", "secret_key": "sk_test_uvwxyz67890" } ``` -------------------------------- ### Get Recent Trades with Symbol Query Source: https://docs.pacifica.fi/api-documentation/api/rest-api/markets/get-recent-trades Example of constructing the API request URL with the required 'symbol' query parameter to fetch trades for a specific trading pair, such as BTC. ```HTTP /api/v1/trades?symbol=BTC ``` -------------------------------- ### POST /api/v1/orders/create Source: https://docs.pacifica.fi/api-documentation/api/signing/operation-types Creates a new order. ```APIDOC ## POST /api/v1/orders/create ### Description Creates a new order. ### Method POST ### Endpoint /api/v1/orders/create ### Parameters #### Request Body - **operation_type** (string) - Required - The type of operation, which is "create_order". ### Request Example { "operation_type": "create_order" } ### Response #### Success Response (200) - **order_id** (string) - The unique identifier for the created order. #### Response Example { "order_id": "ord_12345abcde" } ``` -------------------------------- ### Get Kline (Candle) Data Source: https://docs.pacifica.fi/api-documentation/api/rest-api/markets/get-kline-candle-data Allows users to retrieve historical price candles for a specific market and time interval. Supports filtering by symbol, interval, start time, and optional end time. ```APIDOC ## GET /api/v1/kline ### Description This endpoint allows users to get historical price candles for a specific market and time interval. ### Method GET ### Endpoint /api/v1/kline ### Parameters #### Query Parameters - **symbol** (string) - Required - Trading pair symbol (e.g., BTC) - **interval** (string) - Required - Candlestick interval. Valid values: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 8h, 12h, 1d - **start_time** (integer) - Required - Start time in milliseconds (e.g., 1716200000000) - **end_time** (integer) - Optional - End time in milliseconds, defaults to current time if not provided (e.g., 1742243220000) ### Request Example ``` /api/v1/kline?symbol=BTC&interval=1m&start_time=1742243160000&end_time=1742243220000 ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **data** (array) - An array of kline data objects. - **t** (number) - Candle start time. - **T** (number) - Candle end time. - **s** (string) - Symbol. - **i** (string) - Time interval of candles. - **o** (decimal string) - Open price. - **c** (decimal string) - Close price. - **h** (decimal string) - High price. - **l** (decimal string) - Low price. - **v** (decimal string) - Volume. - **n** (number) - Number of trades on Pacifica for the specified symbol. - **error** (null) - Error message if any. - **code** (null) - Error code if any. #### Response Example ```json { "success": true, "data": [ { "t": 1748954160000, "T": 1748954220000, "s": "BTC", "i": "1m", "o": "105376", "c": "105376", "h": "105376", "l": "105376", "v": "0.00022", "n": 2 } ], "error": null, "code": null } ``` #### Error Responses - **Status 400**: Invalid request parameters. - **Status 401**: Unauthorized access. - **Status 500**: Internal server error. #### Code Example (Python) ```python import requests response = requests.get( "/api/v1/kline?symbol=BTC&interval=1m&start_time=1742243160000&end_time=1742243220000", headers={\"Accept\": \"*/*\"}, ) data = response.json() ``` ``` -------------------------------- ### Create Limit Order with Python SDK Source: https://docs.pacifica.fi/api-documentation/api/rest-api/orders/create-limit-order This Python code example demonstrates how to create a limit order using the Pacifica API. It utilizes the `requests` library to send a POST request to the '/api/v1/orders/create' endpoint with the order details in the JSON payload and appropriate headers. ```python import requests payload = { "account": "42trU9A5...", "signature": "5j1Vy9Uq...", "timestamp": 1716200000000, "symbol": "BTC", "price": "50000", "amount": "0.1", "side": "bid", "tif": "GTC", "reduce_only": False, "client_order_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479" } response = requests.post( "/api/v1/orders/create", json=payload, headers={"Content-Type": "application/json"} ) data = response.json() ``` -------------------------------- ### Account Info Response Structure Source: https://docs.pacifica.fi/api-documentation/api/rest-api/account/get-account-info This is an example of a successful response (Status 200) from the /api/v1/account endpoint, detailing various account metrics. ```JSON { "data": { "balance": "2000.000000", "fee_level": 0, "account_equity": "2150.250000", "available_to_spend": "1800.750000", "pending_balance": "0.000000", "total_margin_used": "349.500000", "positions_count": 2, "orders_count": 3, "stop_orders_count": 1, "updated_at": 1716200000000 }, "error": null, "code": null } ``` -------------------------------- ### Python Code Example for Creating Stop Order Source: https://docs.pacifica.fi/api-documentation/api/rest-api/orders/create-stop-order Python script using the 'requests' library to send a POST request to create a stop order. Demonstrates constructing the payload and handling the response. ```Python import requests payload = { "account": "42trU9A5...", "signature": "5j1Vy9Uq...", "timestamp": 1716200000000, "symbol": "BTC", "side": "long", "reduce_only": True, "stop_order": { "stop_price": "48000", "limit_price": "47950", "amount": "0.1" } } response = requests.post( "/api/v1/orders/stop/create", json=payload, headers={"Content-Type": "application/json"} ) data = response.json() ``` -------------------------------- ### Create Limit Order Source: https://docs.pacifica.fi/api-documentation/api/websocket/trading-operations/create-limit-order Allows users to place limit orders through Pacifica's websocket API. The Pacifica Python SDK provides a comprehensive example on using this endpoint. ```APIDOC ## POST /api/orders/limit ### Description This endpoint allows users to place limit orders through Pacifica's websocket API. ### Method POST ### Endpoint /api/orders/limit ### Parameters #### Request Body - **id** (string) - required - Client-defined request ID - **params** (object) - required - Contains action type and action parameters - **create_order** (object) - required - Specifies action type and contains parameters - **account** (string) - required - User's wallet address - **agent_wallet** (string) - optional - Agent wallet address - **signature** (string) - required - Cryptographic signature - **timestamp** (integer) - required - Current timestamp in milliseconds - **expiry_window** (integer) - optional - Signature expiry in milliseconds - **symbol** (string) - required - Trading pair symbol - **price** (string) - required - Order price - **reduce_only** (boolean) - required - Whether the order is reduce-only - **amount** (string) - required - Order amount - **side** (string) - required - Order side (bid/ask) - **tif** (string) - required - Time in force (GTC, IOC, ALO) - **client_order_id** (string) - optional - Client-defined order ID - **take_profit** (object) - optional - Take profit stop order configuration - **stop_price** (string) - required (if `take_profit` exists) - Stop trigger price - **limit_price** (string) - optional - Limit price for the triggered order - **client_order_id** (string) - Client-defined order ID for the stop order - **stop_loss** (object) - optional - Stop loss order configuration - **stop_price** (string) - required (if `stop_loss` exists) - Stop trigger price - **limit_price** (string) - optional - Limit price for the triggered order - **client_order_id** (string) - Client-defined order ID for the stop order ### Request Example ```json { "id": "660065de-8f32-46ad-ba1e-83c93d3e3966", "params": { "create_order": { "account": "AwX6321...", "signature": "5vnYpt...", "timestamp": 1749223025396, "expiry_window": 5000, "symbol": "BTC", "price": "100000.00", "reduce_only": false, "amount": "0.001", "side": "bid", "tif": "GTC", "client_order_id": "79f948fd-7556-4066-a128-083f3ea49322" } } } ``` ### Response #### Success Response (200) - **code** (integer) - Status code - **data** (object) - Contains information about placed order - **I** (string) - CLOID (if provided) - **i** (integer) - Order ID - **s** (string) - Symbol - **id** (string) - Client-defined request ID - **t** (integer) - Timestamp in milliseconds - **type** (string) - Specifies action type #### Response Example ```json { "code": 200, "data": { "I": "79f948fd-7556-4066-a128-083f3ea49322", "i": 645953, "s": "BTC" }, "id": "660065de-8f32-46ad-ba1e-83c93d3e3966", "t": 1749223025962, "type": "create_order" } ``` ``` -------------------------------- ### Hardware Wallet Signature Authentication Source: https://docs.pacifica.fi/api-documentation/api/signing/hardware-wallet This section details the process of authenticating using a hardware wallet. It explains the required message format, including the `\xffsolana offchain` header, and how to specify the hardware wallet signature type in the API request. ```APIDOC ## Hardware Wallet Signature Authentication ### Description Pacifica supports hardware wallet signature authentication via Ed25519 off-chain message signing. To use a hardware wallet, after constructing the message bytes, prepend it with the `\xffsolana offchain` header along with message length and version information. ### Method Not applicable (Illustrative example of request structure) ### Endpoint Not applicable (Illustrative example of request structure) ### Parameters #### Request Body - **signature** (object) - Required - The signature object for authentication. - **type** (string) - Required - Must be set to `"hardware"` to indicate hardware wallet signature. - **value** (string) - Required - The signature value obtained from the hardware wallet. ### Request Example ```json { "signature": { "type": "hardware", "value": "2V4Y7Mpk..." } } ``` ### Response #### Success Response (200) - **message** (string) - A success message indicating authentication. #### Response Example ```json { "message": "Successfully authenticated with hardware wallet." } ``` ### Additional Information For a detailed implementation example, refer to the Python SDK. The process involves constructing specific message bytes and using `"hardware"` as the signature type. ``` -------------------------------- ### Create Market Order Source: https://docs.pacifica.fi/api-documentation/api/websocket/trading-operations/create-market-order Allows users to place market orders through Pacifica's websocket API. The Pacifica Python SDK provides a comprehensive example on using this endpoint. ```APIDOC ## POST /api/market/order ### Description This endpoint allows users to place market orders through Pacifica's websocket API. ### Method POST ### Endpoint /api/market/order ### Parameters #### Request Body - **id** (string) - required - Client-defined request ID - **params** (object) - required - Contains action type and action parameters - **create_market_order** (object) - required - Specifies action type and contains parameters - **account** (string) - required - User's wallet address - **agent_wallet** (string) - optional - Agent wallet address - **signature** (string) - required - Cryptographic signature - **timestamp** (integer) - required - Current timestamp in milliseconds - **expiry_window** (integer) - optional - Signature expiry in milliseconds - **symbol** (string) - required - Trading pair symbol - **reduce_only** (boolean) - required - Whether the order is reduce-only - **amount** (string) - required - Order amount - **side** (string) - required - Order side (bid/ask) - **slippage_percent** (string) - required - Maximum allowed slippage in percentage, e.g. "0.5" means 0.5% max slippage - **client_order_id** (string) - optional - Client-defined order ID - **take_profit** (object) - optional - Take profit stop order configuration - **stop_price** (string) - required (if `take_profit` exists) - Stop trigger price - **limit_price** (string) - optional - Limit price for the triggered order - **client_order_id** (string) - optional - Client-defined order ID for the stop order - **stop_loss** (object) - optional - Stop loss order configuration - **stop_price** (string) - required (if `stop_loss` exists) - Stop trigger price - **limit_price** (string) - optional - Limit price for the triggered order - **client_order_id** (string) - optional - Client-defined order ID for the stop order ### Request Example ```json { "id": "660065de-8f32-46ad-ba1e-83c93d3e3966", "params": { "create_market_order": { "account": "AwX6321...", "signature": "5vnYpt...", "timestamp": 1749223025396, "expiry_window": 5000, "symbol": "BTC", "reduce_only": false, "amount": "0.001", "side": "bid", "slippage_percent": "0.5", "client_order_id": "79f948fd-7556-4066-a128-083f3ea49322" } } } ``` ### Response #### Success Response (200) - **code** (integer) - Status code - **data** (object) - Contains information about placed order - **I** (string) - CLOID (if provided) - **i** (integer) - Order ID - **s** (string) - Symbol - **id** (string) - Client-defined request ID - **t** (integer) - Timestamp in milliseconds - **type** (string) - Specifies action type #### Response Example ```json { "code": 200, "data": { "I": "79f948fd-7556-4066-a128-083f3ea49322", "i": 645953, "s": "BTC" }, "id": "660065de-8f32-46ad-ba1e-83c93d3e3966", "t": 1749223025962, "type": "create_market_order" } ``` ``` -------------------------------- ### Example of Correct Rounding (API Request) Source: https://docs.pacifica.fi/api-documentation/api/tick-and-lot-size Illustrates API requests with 'amount' and 'price' fields that comply with the specified lot size and tick size, leading to successful acceptance. This shows the correct format for API requests. ```json { "amount": "0.00002" } { "price": "100_001" } ``` -------------------------------- ### Order History API Request with Parameters Source: https://docs.pacifica.fi/api-documentation/api/rest-api/orders/get-order-history This example demonstrates how to construct a full URL for the order history endpoint, including required and optional query parameters like account, limit, and offset. ```HTTP /api/v1/orders/history?account=42trU9A5...&limit=100&offset=0 ``` -------------------------------- ### Get Account Equity History (API Endpoint) Source: https://docs.pacifica.fi/api-documentation/api/rest-api/account/get-account-equity-history This GET request retrieves the historical equity of a user's account. It requires the user's wallet address and optionally accepts start time, end time, granularity, limit, and offset parameters for filtering and pagination. The response is a JSON array of objects, each containing the account equity and a timestamp. ```HTTP GET /api/v1/portfolio Query Parameters: "account" (string, required): User's wallet address "start_time" (integer, optional): Start time in milliseconds "end_time" (integer, optional): End time in milliseconds "granularity_in_minutes" (integer, optional): Time granularity in minutes "limit" (integer, optional): Maximum number of records to return "offset" (integer, optional): Number of records to skip ``` ```HTTP /api/v1/portfolio?account=42trU9A5...&start_time=1625097600000&end_time=1625184000000&granularity_in_minutes=60&limit=100" ``` -------------------------------- ### Generate Agent Wallets with Python SDK Source: https://docs.pacifica.fi/api-documentation/api/signing/agent-wallet This snippet demonstrates how to generate agent wallets using the provided Python SDK. It is a prerequisite for using agent wallets in API interactions. ```python import pacifica_sdk # Example of generating an agent wallet agent_wallet = pacifica_sdk.generate_agent_wallet() print(f"Agent Wallet Public Key: {agent_wallet['public_key']}") print(f"Agent Wallet Private Key: {agent_wallet['private_key']}") ```