### Install Dependencies Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/ruby/README.md Navigate to the Ruby examples directory in your terminal and run `bundle install` to install the necessary dependencies. ```bash bundle install ``` -------------------------------- ### Install Dependencies Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/dotnet/README.md Navigate to the DotNet examples directory in your terminal and install the necessary dependencies. ```bash dotnet restore dotnet.csproj ``` -------------------------------- ### Install Dependencies Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/php/README.md This command installs the necessary dependencies for the PHP examples using Composer. ```bash composer install ``` -------------------------------- ### Install Dependencies Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/javascript/README.md Command to install necessary dependencies for the JavaScript examples. ```bash npm install ``` -------------------------------- ### Install Dependencies Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/java/README.md Navigate to the java examples directory in your terminal and install the necessary dependencies using Maven. ```bash mvn install ``` -------------------------------- ### Running the Examples Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/swift/README.md Build and run the Swift examples using Docker. ```bash docker build -t foxbit-swift-examples . docker run --rm \ -e FOXBIT_API_KEY=$FOXBIT_API_KEY \ -e FOXBIT_API_SECRET=$FOXBIT_API_SECRET \ foxbit-swift-examples ``` -------------------------------- ### Running the Examples Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/dotnet/README.md To run the example, navigate to the project directory in the terminal and execute the following command: ```bash dotnet run ``` -------------------------------- ### Install Dependencies Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/typescript/README.md Navigate to the TypeScript examples directory in your terminal and run the following commands to install necessary dependencies. ```bash npm install -g typescript ts-node npm install ``` -------------------------------- ### Running the Examples Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/go/README.md To run the example, navigate to the project directory in the terminal and execute the following command. ```bash go run examples.go ``` -------------------------------- ### Running the Examples Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/php/README.md This command executes the PHP examples from the project directory. ```bash php examples.php ``` -------------------------------- ### Running the Examples Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/kotlin/README.md To run the example, navigate to the project directory in the terminal and execute the following command: ```bash docker build -t foxbit-kotlin-examples . docker run --rm \ -e FOXBIT_API_KEY=$FOXBIT_API_KEY \ -e FOXBIT_API_SECRET=$FOXBIT_API_SECRET \ foxbit-kotlin-examples ``` -------------------------------- ### Running the Examples Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/cpp/README.md Builds a Docker image for the C++ examples and runs it, passing API keys as environment variables. ```bash docker build -t foxbit-cpp-examples . docker run --rm \ -e FOXBIT_API_KEY=$FOXBIT_API_KEY \ -e FOXBIT_API_SECRET=$FOXBIT_API_SECRET \ foxbit-cpp-examples ``` -------------------------------- ### Install Dependencies Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/python/README.md Command to install Python dependencies using pip. ```bash pip install -r requirements.txt ``` -------------------------------- ### Running the Examples Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/python/README.md Command to execute the Python examples. ```bash python3 examples.py ``` -------------------------------- ### Running the Examples Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/ruby/README.md To run the example, navigate to the project directory in the terminal and execute the following command: ```bash ruby examples.rb ``` -------------------------------- ### Running the Examples Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/javascript/README.md Command to execute the JavaScript examples. ```bash node examples.js ``` -------------------------------- ### Running the Examples Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/java/README.md To run the example, navigate to the project directory in the terminal and execute the following command using Maven. ```bash mvn exec:java -Dexec.mainClass="br.com.foxbit.samples.FoxbitApiSamples" ``` -------------------------------- ### GET /rest/v3/orders Example Response Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/endpoints.md Example response for listing orders. ```json { "data": [ { "id": "order123", "market_symbol": "btcbrl", "side": "BUY", "type": "LIMIT", "price": "500000.0", "quantity": "0.0001", "created_at": "2024-05-26T10:00:00Z", "status": "ACTIVE" } ] } ``` -------------------------------- ### JavaScript Usage Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/configuration.md Example of how to initialize the Configuration in JavaScript. ```javascript const { Configuration } = require("@foxbit-group/rest-api"); const config = new Configuration({ apiKey: process.env.FOXBIT_API_KEY, apiSecret: process.env.FOXBIT_API_SECRET, }); ``` -------------------------------- ### Running the Examples Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/dart/README.md Commands to build and run the Dart examples using Docker. ```bash docker build -t foxbit-dart-examples . docker run --rm \ -e FOXBIT_API_KEY=$FOXBIT_API_KEY \ -e FOXBIT_API_SECRET=$FOXBIT_API_SECRET \ foxbit-dart-examples ``` -------------------------------- ### Running the Examples Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/websocket-v3/javascript/README.md Executes the JavaScript WebSocket v3 examples from the project directory. ```bash npm start ``` -------------------------------- ### Testing Environment Setup Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/configuration.md Example of setting and unsetting environment variables for API keys during testing. ```typescript // test-setup.ts beforeAll(() => { process.env.FOXBIT_API_KEY = "test_key_12345"; process.env.FOXBIT_API_SECRET = "test_secret_67890"; }); afterAll(() => { delete process.env.FOXBIT_API_KEY; delete process.env.FOXBIT_API_SECRET; }); ``` -------------------------------- ### GET /rest/v3/me - Example Response Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/endpoints.md Example response for retrieving user account information. ```json { "id": "user123", "email": "user@example.com", "status": "active" } ``` -------------------------------- ### Running the Examples Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/typescript/README.md To run the example, navigate to the project directory in the terminal and execute the following command. ```bash ts-node examples.ts ``` -------------------------------- ### TypeScript Usage Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/configuration.md Example of how to initialize the Configuration in TypeScript. ```typescript import { Configuration } from "@foxbit-group/rest-api"; const config = new Configuration({ apiKey: process.env.FOXBIT_API_KEY, apiSecret: process.env.FOXBIT_API_SECRET, }); ``` -------------------------------- ### GET /rest/v3/orders Example Request Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/endpoints.md Example request to list orders for a trading pair, filtered by state and limit. ```http GET /rest/v3/orders?market_symbol=btcbrl&state=ACTIVE&limit=50 Host: api.foxbit.com.br X-FB-ACCESS-KEY: your_api_key X-FB-ACCESS-TIMESTAMP: 1622908800000 X-FB-ACCESS-SIGNATURE: signature_hash ``` -------------------------------- ### GET /rest/v3/markets/{market_symbol}/ticker/24hr - Example Request Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/endpoints.md Example request to retrieve 24-hour ticker data for a trading pair. ```bash curl https://api.foxbit.com.br/rest/v3/markets/btcbrl/ticker/24hr ``` -------------------------------- ### Get Current User Information Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/rest-v3-api.md Example of how to retrieve authenticated user's account information. ```typescript const meResponse = await request('GET', '/rest/v3/me'); console.log('User info:', meResponse.data); ``` -------------------------------- ### GET /rest/v3/markets/{market_symbol}/ticker/24hr - Example Response Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/endpoints.md Example response for 24-hour ticker data. ```json { "data": [ { "market_symbol": "btcbrl", "open": "450000.0", "high": "520000.0", "low": "440000.0", "close": "500000.0", "volume": "150.5", "timestamp": "2024-05-26T10:00:00Z", "best": { "bid": {"price": "499900.0", "quantity": "1.5"}, "ask": {"price": "500100.0", "quantity": "2.3"} } } ] } ``` -------------------------------- ### GET /rest/v3/me - Example Request Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/endpoints.md Example request to retrieve current authenticated user's account information using axios. ```typescript const { signature, timestamp } = sign('GET', '/rest/v3/me'); const response = await axios.get('https://api.foxbit.com.br/rest/v3/me', { headers: { 'X-FB-ACCESS-KEY': process.env.FOXBIT_API_KEY, 'X-FB-ACCESS-TIMESTAMP': timestamp.toString(), 'X-FB-ACCESS-SIGNATURE': signature, } }); ``` -------------------------------- ### Create Order Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/rest-v3-api.md Example of how to place a new buy or sell order. ```typescript const order = { market_symbol: 'btcbrl', side: 'BUY', type: 'LIMIT', price: '500000.0', quantity: '0.0001', }; const orderResponse = await request('POST', '/rest/v3/orders', undefined, order); console.log('Order created:', orderResponse.data); ``` -------------------------------- ### Installation Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/README.md Install the official Foxbit REST API SDK using npm. ```bash npm install @foxbit-group/rest-api ``` -------------------------------- ### Development Environment Setup Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/configuration.md Instructions for setting up environment variables for development and adding them to .gitignore. ```bash # Create .env file (DO NOT commit this to version control) FOXBIT_API_KEY=your_dev_key FOXBIT_API_SECRET=your_dev_secret FOXBIT_USER_ID=your_user_id # Load in your application import dotenv from 'dotenv'; dotenv.config(); ``` ```text Add to .gitignore: .env .env.local *.pem credentials.json ``` -------------------------------- ### Example CreateOrderRequest Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/types.md Example of a CreateOrderRequest object. ```typescript const orderRequest: CreateOrderRequest = { market_symbol: "btcbrl", side: "BUY", type: "LIMIT", price: "500000.0", quantity: "0.0001", }; ``` -------------------------------- ### POST /rest/v3/orders - Example Request Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/endpoints.md Example request to create a new order. ```http POST /rest/v3/orders HTTP/1.1 Host: api.foxbit.com.br Content-Type: application/json X-FB-ACCESS-KEY: your_api_key X-FB-ACCESS-TIMESTAMP: 1622908800000 X-FB-ACCESS-SIGNATURE: signature_hash { "market_symbol": "btcbrl", "side": "BUY", "type": "LIMIT", "price": "500000.0", "quantity": "0.0001" } ``` -------------------------------- ### Configuration Example: INVALID_API_KEY Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/errors.md This example shows how to configure the API client with environment variables, which is relevant for handling `INVALID_API_KEY` errors. ```typescript const config = new Configuration({ apiKey: process.env.FOXBIT_API_KEY, // Ensure this is set apiSecret: process.env.FOXBIT_API_SECRET, }); ``` -------------------------------- ### POST /rest/v3/orders - Example Response Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/endpoints.md Example response for creating a new order. ```json { "id": "order123", "market_symbol": "btcbrl", "side": "BUY", "type": "LIMIT", "price": "500000.0", "quantity": "0.0001", "created_at": "2024-05-26T10:00:00Z", "status": "ACTIVE" } ``` -------------------------------- ### Connection Lifecycle Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/websocket-v2-api.md Comprehensive JavaScript example demonstrating the WebSocket connection lifecycle: opening, authenticating, subscribing to channels, receiving events, and handling closure. ```javascript const WebSocket = require("ws"); const ws = new WebSocket("wss://api.foxbit.com.br/"); // 1. Connection opens ws.onopen = () => { console.log("Connected"); // 2. Authenticate ws.send(JSON.stringify({ m: 0, i: 1, n: "AuthenticateUser", o: JSON.stringify({ /* credentials */ }), })); }; // 3. Receive authentication response ws.on("message", (data) => { const result = JSON.parse(data); if (result.n === "AuthenticateUser") { const payload = JSON.parse(result.o); if (payload.Authenticated) { // 4. Subscribe to channels ws.send(JSON.stringify({ m: 2, i: 2, n: "SubscribeLevel1", o: JSON.stringify({ OMSId: 1, MarketId: "btcbrl" }), })); } } }); // 5. Receive and process events ws.on("message", (data) => { const result = JSON.parse(data); if (result.m === 3) { // Event type console.log("Event received:", result.n, result.o); } }); // 6. Connection closes ws.onclose = () => { console.log("Connection closed"); // Implement reconnection logic }; ``` -------------------------------- ### SubscribeLevel2 Usage Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/websocket-v2-api.md JavaScript example demonstrating how to send a SubscribeLevel2 request. ```javascript ws.send(JSON.stringify({ m: 2, i: 3, n: "SubscribeLevel2", o: JSON.stringify({ OMSId: 1, MarketId: "btcbrl", Depth: 10 }), })); ``` -------------------------------- ### AuthenticateUser Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/websocket-v2-api.md Example of sending an AuthenticateUser request. ```javascript const crypto = require("crypto-js"); const userId = process.env.FOXBIT_USER_ID; const apiKey = process.env.FOXBIT_API_KEY; const apiSecret = process.env.FOXBIT_API_SECRET; const nonce = Date.now(); const signatureData = nonce + userId + apiKey; const signature = crypto .HmacSHA256(signatureData, apiSecret) .toString(crypto.enc.Hex); ws.send(JSON.stringify({ m: 0, i: 1, n: "AuthenticateUser", o: JSON.stringify({ APIKey: apiKey, Nonce: nonce, UserId: userId, Signature: signature, }), })); ``` -------------------------------- ### Multiple Configurations Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/configuration.md Example of managing multiple API accounts or environments with separate Configuration instances. ```typescript const prodConfig = new Configuration({ apiKey: process.env.FOXBIT_API_KEY_PROD, apiSecret: process.env.FOXBIT_API_SECRET_PROD, }); const devConfig = new Configuration({ apiKey: process.env.FOXBIT_API_KEY_DEV, apiSecret: process.env.FOXBIT_API_SECRET_DEV, }); const prodMemberApi = new MemberInfoApi(prodConfig); const devMemberApi = new MemberInfoApi(devConfig); ``` -------------------------------- ### PUT /rest/v3/orders/cancel Example Request (Cancel All) Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/endpoints.md Example request to cancel all open orders. ```json PUT /rest/v3/orders/cancel HTTP/1.1 Host: api.foxbit.com.br Content-Type: application/json X-FB-ACCESS-KEY: your_api_key X-FB-ACCESS-TIMESTAMP: 1622908800000 X-FB-ACCESS-SIGNATURE: signature_hash { "type": "ALL" } ``` -------------------------------- ### Signature Calculation Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/types.md Example of how to calculate the HMAC SHA256 signature for WebSocket authentication. ```typescript const signatureData = nonce + userId + apiKey; const signature = CryptoJS.HmacSHA256(signatureData, apiSecret).toString(CryptoJS.enc.Hex); ``` -------------------------------- ### SubscribeAccountEvents Usage Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/websocket-v2-api.md JavaScript example demonstrating how to send a SubscribeAccountEvents request and listen for events. ```javascript // Must authenticate first ws.send(JSON.stringify({ m: 2, i: 4, n: "SubscribeAccountEvents", o: JSON.stringify({}), })); // Listen for account events ws.on("message", (data) => { const result = JSON.parse(data); if (result.n === "SubscribeAccountEvents") { const event = JSON.parse(result.o); console.log("Account event:", event); } }); ``` -------------------------------- ### Security Best Practices - Audit Logging Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/configuration.md Example of logging successful authentication and API calls without exposing sensitive data. ```typescript // Log successful authentication (no secret exposed) console.log(`Authenticated as user: ${userId}`); // Log API calls console.log(`API call: ${method} ${endpoint}`); ``` -------------------------------- ### TypeScript/JavaScript SDK Configuration Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/configuration.md Example of configuring the Foxbit SDK using the Configuration class in TypeScript/JavaScript. ```typescript import { Configuration } from "@foxbit-group/rest-api"; const config = new Configuration({ apiKey: process.env.FOXBIT_API_KEY || '', apiSecret: process.env.FOXBIT_API_SECRET || '', }); ``` -------------------------------- ### Create Order Request Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/rest-v3-api.md Example of a JSON request body for creating a new order. ```json { "market_symbol": "btcbrl", "side": "BUY", "type": "LIMIT", "price": "500000.0", "quantity": "0.0001" } ``` -------------------------------- ### Example Error Response: INVALID_PRICE Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/errors.md This TypeScript example demonstrates the correct way to format the `price` parameter as a string to prevent `INVALID_PRICE` errors. ```typescript // Correct const orderRequest = { market_symbol: "btcbrl", side: "BUY", type: "LIMIT", price: "500000.0", // String format quantity: "0.0001", }; // Incorrect const orderRequest = { market_symbol: "btcbrl", side: "BUY", type: "LIMIT", price: 500000, // Should be string quantity: "0.0001", }; ``` -------------------------------- ### HTTP API Response Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/websocket-v3/javascript/manage-local-orderbook/README.md Example of the JSON response for the /orderbook endpoint. ```json { "market_symbol": "btcbrl", "subscribe_interval": "250", "sequence_id": 12345, "asks": [ ["45000.00", "0.5000"], ["45100.00", "1.2000"], // ... ], "bids": [ ["44900.00", "0.8000"], ["44800.00", "2.1000"], // ... ] } ``` -------------------------------- ### Production Environment - AWS Secrets Manager Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/configuration.md Example of retrieving API credentials from AWS Secrets Manager for a production environment. ```typescript import { SecretsManagerClient, GetSecretValueCommand } from "@aws-sdk/client-secrets-manager"; const client = new SecretsManagerClient({ region: "us-east-1" }); async function getCredentials() { const command = new GetSecretValueCommand({ SecretId: "foxbit/api-credentials", }); const response = await client.send(command); const secret = JSON.parse(response.SecretString!); return { apiKey: secret.api_key, apiSecret: secret.api_secret, }; } ``` -------------------------------- ### Signature Generation Example (TypeScript) Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/configuration.md Example of generating an HMAC SHA256 signature for REST v3 API requests in TypeScript. ```typescript import CryptoJS from 'crypto-js'; const apiSecret = process.env.FOXBIT_API_SECRET!; const timestamp = Date.now(); const method = 'POST'; const path = '/rest/v3/orders'; const body = JSON.stringify({ market_symbol: 'btcbrl', side: 'BUY', type: 'LIMIT', price: '500000', quantity: '0.0001' }); const preHash = `${timestamp}${method}${path}${body}`; const signature = CryptoJS.HmacSHA256(preHash, apiSecret).toString(); ``` -------------------------------- ### Example Error Response: INVALID_MARKET Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/errors.md This TypeScript example illustrates correct and incorrect usage of the `marketSymbol` parameter, highlighting how to avoid `INVALID_MARKET` errors. ```typescript // Valid const response = await tradingApi.listOrders({ marketSymbol: "btcbrl", state: "ACTIVE" }); // Invalid - will fail const response = await tradingApi.listOrders({ marketSymbol: "BTC_BRL", // Wrong format state: "ACTIVE" }); ``` -------------------------------- ### WebSocket Authentication Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/configuration.md Example of how to authenticate a WebSocket connection using API credentials and a generated signature. ```javascript const crypto = require("crypto-js"); const userId = process.env.FOXBIT_USER_ID; const apiKey = process.env.FOXBIT_API_KEY; const apiSecret = process.env.FOXBIT_API_SECRET; const nonce = Date.now(); const signatureData = nonce + userId + apiKey; const signature = crypto .HmacSHA256(signatureData, apiSecret) .toString(crypto.enc.Hex); // Send authentication message const authMessage = { m: 0, // Request type i: 1, // Sequence number n: "AuthenticateUser", o: JSON.stringify({ APIKey: apiKey, Nonce: nonce, UserId: userId, Signature: signature, }), }; ``` -------------------------------- ### Timeout Configuration Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/configuration.md Example of configuring a default timeout for Axios HTTP client instances. ```typescript import axios from 'axios'; const client = axios.create({ baseURL: 'https://api.foxbit.com.br', timeout: 10000, // 10 seconds }); ``` -------------------------------- ### Get User ID for WebSocket Use Case Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/memberinfoapi.md Example of retrieving user ID for WebSocket authentication. ```typescript // Retrieve user ID for WebSocket authentication const user = await memberApi.currentMember(); const userId = user.data.id; // Use userId in WebSocket AuthenticateUser call ``` -------------------------------- ### Get Market Ticker (24h) Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/rest-v3-api.md Retrieves 24-hour ticker data for the BTC/BRL trading pair. ```typescript const tickerResponse = await request('GET', `/rest/v3/markets/btcbrl/ticker/24hr`); const ticker = tickerResponse.data?.data?.[0]; console.log('24h ticker:', ticker); ``` -------------------------------- ### Navigate to the project directory Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3-sdk/README.md This command changes the current directory to the cloned project directory. ```bash cd foxbit-api-samples ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/python/README.md Steps to create and activate a Python virtual environment. ```bash python3 -m venv foxbit-api-samples source foxbit-api-samples/bin/activate ``` -------------------------------- ### Clone the repository Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/rest-v3/README.md This command clones the Foxbit API samples repository to your local machine. ```bash git clone git@github.com:foxbit-group/foxbit-api-samples.git ``` -------------------------------- ### API Client Initialization Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/configuration.md Example of initializing API clients (MemberInfoApi, TradingApi) after creating a configuration object. ```typescript import { Configuration, MemberInfoApi, TradingApi } from "@foxbit-group/rest-api"; const config = new Configuration({ apiKey: process.env.FOXBIT_API_KEY, apiSecret: process.env.FOXBIT_API_SECRET, }); const memberApi = new MemberInfoApi(config); const tradingApi = new TradingApi(config); ``` -------------------------------- ### Constructor Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/configuration.md Initializes the Configuration class with API credentials. ```typescript new Configuration(options: ConfigurationOptions) ``` -------------------------------- ### Environment Variables for API Credentials Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/README.md Example of how to export API key and secret as environment variables. ```bash export FOXBIT_API_KEY=your_api_key_here export FOXBIT_API_SECRET=your_api_secret_here ``` -------------------------------- ### Navigate to the project directory Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/websocket-v3/javascript/manage-local-orderbook/README.md Navigate to the project directory. ```bash cd websocket-v3/javascript/manage-local-orderbook ``` -------------------------------- ### PUT /rest/v3/orders/cancel Example Response Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/endpoints.md Example response after cancelling orders. ```json { "success": true, "message": "Order cancelled successfully", "cancelled_orders": ["order123"] } ``` -------------------------------- ### Example CancelOrdersRequest (Cancel all) Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/types.md Example of a CancelOrdersRequest object to cancel all orders. ```typescript const cancelRequest: CancelOrdersRequest = { type: "ALL", }; ``` -------------------------------- ### Constructor Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/memberinfoapi.md Initializes the MemberInfoApi with a Configuration instance. ```typescript new MemberInfoApi(config) ``` -------------------------------- ### SubscribeLevel1 Usage Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/websocket-v2-api.md Example of sending a SubscribeLevel1 request. ```javascript ws.send(JSON.stringify({ m: 2, i: 2, n: "SubscribeLevel1", o: JSON.stringify({ OMSId: 1, MarketId: "btcbrl" }), })); ``` -------------------------------- ### Create Order Usage Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/tradingapi.md Demonstrates how to create a new buy or sell order on the exchange using the TradingApi. ```typescript import { Configuration, TradingApi } from "@foxbit-group/rest-api"; const config = new Configuration({ apiKey: process.env.FOXBIT_API_KEY, apiSecret: process.env.FOXBIT_API_SECRET, }); const tradingApi = new TradingApi(config); try { const response = await tradingApi.createOrder({ createOrderRequest: { market_symbol: "btcbrl", side: "BUY", type: "LIMIT", price: "500000.0", quantity: "0.0001", }, }); console.log("Order created:", response.data); } catch (error) { console.error("Error creating order:", error); } ``` -------------------------------- ### Loading Environment Variables in Node.js Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/configuration.md Example of loading environment variables from a .env file in Node.js using the 'dotenv' package. ```javascript require('dotenv').config(); ``` -------------------------------- ### Follow Logs Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/websocket-v3/javascript/README.md Monitors WebSocket communication logs in real-time. ```bash tail -f logs/websocket-logs-[timestamp].log ``` -------------------------------- ### Setting Environment Variables (.env file for Node.js) Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/configuration.md Example of creating a .env file for storing environment variables for Node.js applications. ```dotenv FOXBIT_API_KEY=your_api_key_here FOXBIT_API_SECRET=your_api_secret_here FOXBIT_USER_ID=your_user_id_here ``` -------------------------------- ### Setting Environment Variables (Linux / macOS) Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/configuration.md Example of setting environment variables for API authentication on Linux or macOS using Bash. ```bash export FOXBIT_API_KEY=your_api_key_here export FOXBIT_API_SECRET=your_api_secret_here export FOXBIT_USER_ID=your_user_id_here ``` -------------------------------- ### Example CancelOrdersRequest (Cancel by ID) Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/types.md Example of a CancelOrdersRequest object to cancel a single order by ID. ```typescript const cancelRequest: CancelOrdersRequest = { type: "ID", id: "order123", }; ``` -------------------------------- ### Constructor Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/tradingapi.md Initializes the TradingApi with a Configuration instance containing API credentials. ```typescript new TradingApi(config) ``` -------------------------------- ### Unsubscribe from Channel Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/websocket-v2-api.md Example of a client request to unsubscribe from a channel (e.g., SubscribeLevel1). ```typescript { m: 4, i: , n: "SubscribeLevel1", o: JSON.stringify({}) } ``` -------------------------------- ### PUT /rest/v3/orders/cancel Example Request (Cancel by ID) Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/endpoints.md Example request to cancel a specific order by its ID. ```json PUT /rest/v3/orders/cancel HTTP/1.1 Host: api.foxbit.com.br Content-Type: application/json X-FB-ACCESS-KEY: your_api_key X-FB-ACCESS-TIMESTAMP: 1622908800000 X-FB-ACCESS-SIGNATURE: signature_hash { "type": "ID", "id": "order123" } ``` -------------------------------- ### Signature Generation Example Source: https://github.com/foxbit-group/foxbit-api-samples/blob/main/_autodocs/api-reference/rest-v3-api.md Example of how to generate the HMAC SHA256 signature for API requests. ```typescript import CryptoJS from 'crypto-js'; function sign(method: string, path: string, params?: Record, body?: Record) { let queryString = ''; if (params) { queryString = Object.keys(params) .map(key => `${key}=${params[key]}`) .join('&'); } let rawBody = ''; if (body) { rawBody = JSON.stringify(body); } const timestamp = Date.now(); const preHash = `${timestamp}${method}${path}${queryString}${rawBody}`; const signature = CryptoJS.HmacSHA256(preHash, process.env.FOXBIT_API_SECRET!).toString(); return { signature, timestamp }; } ```