Skip to main content

Documentation Index

Fetch the complete documentation index at: https://fireblocks-43c4b3ee-chore-add-cli.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Prerequisites

  1. Contact your CSM to enable this feature and get access to:
    1. Get Exchange Accounts Credentials Public Key endpoint
    2. Add an Exchange Account endpoint
  2. Make sure to prepare your workspace and perform all the steps necessary here.
  3. Install all the prerequisites for our TypeScript and Python SDK.

Add an Exchange Account via SDK

You can use the following code to add an exchange account

Note:

This endpoint currently only supports the following exchanges INDEPENDENT_RESERVE,BIT, BITHUMB, BITSO, CRYPTOCOM, BYBIT_V2, WHITEBIT , HITBTC, GEMINI, HUOBI, GATEIO, COINHAKO, BULLISH, BITGET, and LUNO
import base64
import json
from fireblocks.client import Fireblocks
from fireblocks.client_configuration import ClientConfiguration
from fireblocks.base_path import BasePath 
from fireblocks.models.add_exchange_account_request import AddExchangeAccountRequest
from cryptography.hazmat.primitives.serialization import load_pem_public_key
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives import hashes
from pprint import pprint

my_api_key="your_api_key"

with open('your_secret_key_file_path', 'r') as file:
    secret_key_value = file.read()

configuration = ClientConfiguration(
        api_key=my_api_key,
        secret_key=secret_key_value,
        base_path=BasePath.US #Make sure to use the correct environment. Please see the note
)

with Fireblocks(configuration) as fireblocks:
    tenant_id = None
    public_key = None

    try:
        # Get exchange accounts credentials public key
        api_response = fireblocks.exchange_accounts.get_exchange_accounts_credentials_public_key().result()
        tenant_id = api_response.data.tenant_id
        public_key = api_response.data.public_key
    except Exception as e:
        print("Exception when calling ExchangeAccountAPI->get_exchange_accounts_credentials_public_key: %s\n" % e)
        exit(1)

    # Credentials encryption
    exchange_api_key = "your_exchange_account_api_key"
    exchange_api_secret = 'your_exchange_account_secret_key'

    credentials = {
        "apiKey": exchange_api_key,
        "secret": exchange_api_secret,
        "tenantId": tenant_id,
    }

    pem_public_key = load_pem_public_key(bytearray(public_key, 'utf-8'), default_backend())
    credentials_str = bytes(json.dumps(credentials, separators=(',', ':')), 'utf-8')
    ciphertext = pem_public_key.encrypt(
        credentials_str,
        padding.OAEP(
            mgf=padding.MGF1(algorithm=hashes.SHA256()),
            algorithm=hashes.SHA256(),
            label=None
        )
    )
    
    encrypted_creds = bytes.decode(base64.b64encode(ciphertext))

    # Prepare add exchange account request
    add_exchange_account_request: AddExchangeAccountRequest = AddExchangeAccountRequest(            
                                    exchange_type='BIT',
                                    name='My BIT account',
                                    creds=encrypted_creds,
                                    key=exchange_api_key
    )

    try:
        # Add an exchange account
        future = fireblocks.exchange_accounts.add_exchange_account(add_exchange_account_request=add_exchange_account_request)
        api_response = future.result()  # Wait for the response
        print("The response of ExchangeAccountAPI->add_exchange_account:\n")
        pprint(api_response.data.to_json())
    except Exception as e:
        print("Exception when calling ExchangeAccountAPI->add_exchange_account: %s\n" % e)

Note:

Make sure you’re using the correct value for the API base URL for your environment:
  • BasePath.US - for production workspaces
  • BasePath.Sandbox - for sandbox workspaces`