telescopeOverview

Complete B2PRIME API overview covering REST, WebSocket, and FIX APIs. Learn when to use each API type, available endpoints, and integration guidelines for trading applications

Introduction

B2PRIME provides developers with three distinct methods for data delivery, each optimized for specific use cases and performance requirements: REST, WebSocket, and FIX APIs.

The REST API provides read access to market data as well as both read and write access to trading operations. It serves as the foundation for synchronous data operations where immediate confirmation and guaranteed delivery are essential.

The WebSocket API provides access to public market data streaming as well as private account updates. It delivers real-time updates with low latency, making it ideal for live trading environments.

The FIX API provides direct access to market data and trading via the FIX 4.4 protocol. It is designed for institutional clients and algorithmic trading systems that require standardized, low-latency connectivity using the industry-standard Financial Information eXchange protocol.

This approach provides developers with flexible options for building robust, scalable trading applications that can handle both operational requirements and real-time market dynamics.

When to use REST API

  • Account configuration and settings: Managing user preferences and system configurations.

  • Order placement and modification: Creating, updating, and canceling trading orders.

  • Historical data retrieval: Accessing past trading records and market data.

  • One-time data requests: Retrieving specific information that doesn't require continuous updates.

  • Administrative operations: Account management and system administration tasks.

When to use WebSocket API

  • Real-time price monitoring: Live market price feeds and ticker updates.

  • Live position tracking: Continuous monitoring of open and closed positions.

  • Order book visualization: Real-time depth of market data.

  • Market data feeds: Streaming market statistics and trading activity.

  • Account balance monitoring: Live updates of account equity and margin status.

When to use FIX API

  • Institutional connectivity: Standardized FIX 4.4 protocol for professional trading infrastructure.

  • Algorithmic trading: Low-latency order execution and market data for automated strategies.

  • Market data streaming: Real-time order book snapshots and incremental updates via FIX protocol.

  • Multi-venue integration: Unified FIX connectivity for systems already integrated with other FIX-based venues.

General considerations

The following applies to all interface descriptions provided in this documentation:

  • Endpoints: All endpoints are relative and resolved based on a specified hostname (indicated as {host}).

  • Authentication: REST and WebSocket APIs require an access token (see Authentication). The FIX API uses in-band authentication via the Logon message with Username, Password, and Account fields provided by B2PRIME.

  • Data format: REST and WebSocket APIs return results in JSON format. The FIX API uses the standard FIX 4.4 message format.

  • Security: All communications use secure protocols (HTTPS for REST, WSS for WebSocket, encrypted TCP for FIX).

Authentication

API access requires an access token for both REST and WebSocket connections.

Authentication follows a two-step process:

  1. Generate an offline token in the Trading terminal.

  2. Exchange the offline token for an access token via API call.

Token types

Offline token

  • Limit: 10 tokens per account

  • Validity: 1 year

  • Management: Can be revoked or deleted at any time

  • Purpose: Generate access tokens

Access token

  • Type: Bearer token

  • Validity: 60 minutes

  • Purpose: Authorize API requests

1

Generate offline token

To generate an offline token:

  1. In the Trading terminal, open Settings and select API token management.

  2. Click + Create new.

  3. In the New API token popup, fill in a Name for the token, to help you identify it later.

  4. Click Create.

The newly generated token will be displayed and available for copying, along with its name and expiration date.

circle-exclamation
2

Obtain access token

Request an access token using your offline token.

Endpoint: POST /frontoffice/api/v4/access-token

Request body:

Response (Success):

accessToken string

The access token for API authorization.

expiresIn integer

The token lifetime, in seconds.

tokenType string

The authentication type, always "Bearer".

3

Using access tokens

Include the access token in API requests:

Access tokens must be refreshed before expiration by repeating the Step 2 with your offline token.

REST API: Synchronous data operations

The REST API serves as the foundation for synchronous data operations within the B2PRIME platform. This approach follows standard HTTP protocols and is ideal for operations requiring immediate confirmation and guaranteed delivery.

Key characteristics

  • Request-response operations where immediate confirmation is required.

  • Account management including settings and configuration.

  • Order placement and modification with guaranteed delivery.

  • Historical data retrieval for analysis and reporting.

  • Stateless operations that don't require persistent connections.

HTTP response codes

B2PRIME API uses conventional HTTP response codes to indicate the success or failure of requests.

Success codes:

  • 200 OK — Request successful

Error codes:

  • 400 Bad Request — Invalid request parameters

  • 401 Unauthorized — Authentication required

  • 403 Forbidden — Insufficient permissions

  • 404 Not Found — Resource not found

  • 429 Too Many RequestsRate limit exceeded

  • 500 Internal Server Error — Server error

In case of an error, an object will be returned with the following structure:

Available endpoints

  • Trading operations: Create, modify, and cancel orders; open, close, and modify positions; control price trigger settings.

  • Trading history: Retrieve detailed execution records for positions and orders.

  • Settings and configurations: Access account information, market specifications, trading sessions, and asset details.

Rate limits

Rate limits are applied per minute for each unique AccountId to ensure fair resource usage and maintain optimal API performance. All limits use the Fixed Window strategy.

When rate limits are exceeded, the API returns a 429 Too Many Requests HTTP status code.

Trading methods

  • Default limit: 600 requests per minute for all methods.

  • Reduced limit (200 rpm) applies to:

    • Get order data methods

    • Bulk close positions method

    • Price triggers methods

History methods

  • All request types: 60 requests per minute.

Settings methods

  • GET requests: 100 requests per minute.

  • POST and DELETE requests: 60 requests per minute.

circle-info

Rate limits are calculated independently for each method category. For example, you can make 100 GET requests to Settings methods and 60 requests to History methods within the same minute without hitting rate limits.

WebSocket API: Real-time data streaming

The WebSocket API delivers real-time updates with minimal latency, essential for modern trading applications. The implementation uses unidirectional communication from server to client, ensuring efficient data delivery.

Key characteristics

  • Unidirectional communication from server to client for optimal performance.

  • Real-time market data for live trading environments.

  • Position and order updates as they occur in real-time.

  • Low-latency data delivery for time-sensitive trading operations.

  • Persistent connections maintaining continuous data flow.

SignalR implementation

B2PRIME utilizes AspNetCore SignalR for WebSocket message organization and transmission, providing a robust and scalable real-time communication framework.

Resources:

SignalR provides a structured approach to real-time communication through standardized message formatting and connection management.

Connection lifecycle

The data transfer process consists of two essential phases:

  1. Connection establishment — Initial handshake, authentication, and subscription setup.

  2. Data streaming — Continuous real-time data flow with automatic reconnection handling.

Message types

SignalR utilizes numerical type indicators for different operations:

Type
Operation
Description

**4**

Subscribe

Initiate streaming subscription to a specific data feed

**5**

Unsubscribe

Terminate streaming subscription

**3**

Confirmation

Server confirmation of unsubscription

**2**

Streaming

Active data transmission in progress

Available stream types

FIX API: Standardized protocol connectivity

The FIX API provides direct access to B2PRIME via the FIX 4.4 protocol, the industry standard for electronic trading communication. It is designed for institutional clients and algorithmic trading systems.

Key characteristics

  • FIX 4.4 protocol for standardized, vendor-neutral connectivity.

  • Dedicated sessions for Market Data and Trading with separate endpoints.

  • In-band authentication via Logon message (Username, Password, Account).

  • Real-time market data with order book snapshots and incremental updates.

  • Session management with Heartbeat, Test Request, and Sequence Reset support.

Authentication

Unlike REST and WebSocket APIs, the FIX API does not use access tokens. Authentication is performed in-band as part of the FIX Logon message using credentials provided by B2PRIME:

  • Username (<553>): The client username

  • Password (<554>): The client password

  • Account (<1>): The account identifier

Available session types

  • Market Data: Subscribe to real-time order book updates, snapshots, and incremental refreshes.

  • Trading: Place orders and receive execution reports in real time.

Integration best practices

API selection strategy

  • Use REST API for operational tasks requiring confirmation (order placement, account management).

  • Use WebSocket API for real-time monitoring and market data visualization.

  • Use FIX API for institutional connectivity, algorithmic trading, and integration with existing FIX-based infrastructure.

  • Implement multiple APIs in comprehensive trading applications for optimal functionality.

Performance optimization

  • Implement proper connection pooling for REST API requests.

  • Use WebSocket subscriptions efficiently by subscribing only to required data streams.

  • Handle reconnection logic for WebSocket connections to ensure data continuity.

  • Implement appropriate error handling and retry mechanisms.

Security considerations

  • Store authentication tokens securely and implement token refresh mechanisms.

  • Use secure connections (HTTPS/WSS) for all API communications.

  • Implement proper input validation and sanitization.

  • Monitor API usage and implement rate limiting on the client side.

This comprehensive API architecture enables developers to build sophisticated trading applications that can handle both real-time market dynamics and operational trading requirements efficiently.

Last updated

Was this helpful?