sgcWebSockets · Technical Document

Bitmex API

Bitmex WebSocket and REST client — public market data plus authenticated trading and position streams.

Overview

Bitmex is a cryptocurrency exchange and derivative trading platform.

At a glance

Component class
TsgcWSAPI_Bitmex
Standards / spec
Bitmex API explorer
Transports
TCP, TLS
Platforms
Windows, macOS, Linux, iOS, Android
Frameworks
VCL, FireMonkey, Lazarus / FPC, .NET
Edition
Standard / Professional / Enterprise

Features

Technical specification

Standards & specsBitmex API explorer
Component classTsgcWSAPI_Bitmex (unit sgcWebSocket_API_Bitmex)
FrameworksVCL, FireMonkey, Lazarus / FPC, .NET
PlatformsWindows, macOS, Linux, iOS, Android

Main properties

The principal published / public properties used to configure and drive the component. Consult the online help for the full list.

ClientPublished or public property used to configure or query the component.
OnBitmexSubscribedPublished or public property used to configure or query the component.
OnBitmexUnsubscribedPublished or public property used to configure or query the component.
OnBitmexAuthenticatedPublished or public property used to configure or query the component.
OnConnectPublished or public property used to configure or query the component.
OnBitmexConnectPublished or public property used to configure or query the component.
OnBitmexMessagePublished or public property used to configure or query the component.
OnBitmexErrorPublished or public property used to configure or query the component.
OnDisconnectPublished or public property used to configure or query the component.
OnBitmexHTTPExceptionPublished or public property used to configure or query the component.

Main methods

The principal public methods exposed by the component.

Subscribe()Public procedure exposed by the component.
Unsubscribe()Public procedure exposed by the component.
Authenticate()Public procedure exposed by the component.
CancelAllAfter()Public procedure exposed by the component.

Quick Start

Drop the component on a form, configure the properties below and activate it. The snippet that follows shows the typical Bitmex | Connect WebSocket API configuration sourced from the online help.

About this scenario. In order to connect to Bitmex WebSocket API, just create a new Bitmex API client and attach to TsgcWebSocketClient.

Delphi (VCL / FireMonkey)

oClient := TsgcWebSocketClient.Create(nil);
oBitmex := TsgcWSAPI_Bitmex.Create(nil);
oBitmex .Client := oClient;
oClient.Active := True;

C++ Builder

TsgcWebSocketClient oClient = new TsgcWebSocketClient();
TsgcWSAPI_Bitmex oBitmex = new TsgcWSAPI_Bitmex();
oBitmex->Client = oClient;
oClient->Active = true;

.NET (C#)

TsgcWebSocketClient oClient = new TsgcWebSocketClient();
TsgcWSAPI_Bitmex oBitmex = new TsgcWSAPI_Bitmex();
oBitmex.Client = oClient;
oClient.Active = true;

Common scenarios

The following scenarios are lifted verbatim from the online help. Each shows the configuration and method calls needed to drive the component through a specific real-world flow.

1 · Bitmex | Subscribe WebSocket Channel

Bitmex offers a variety of channels where you can subscribe to get real-time updates of market data, orders... Find below a sample of how subscribe to a Trade Channel:

Delphi (VCL / FireMonkey)
oClient := TsgcWebSocketClient.Create(nil);
oBitmex := TsgcWSAPI_Bitmex.Create(nil);
oBitmex.Client := oClient;
oBitmex.Subscribe(btmTrade, 'XBTUSD');
procedure OnBitmexMessage(Sender: TObject; const aTopic: TwsBitmexTopics; const aMessage: string);
begin
// here you will receive the trade updates
end;
C++ Builder
TsgcWebSocketClient oClient = new TsgcWebSocketClient();
TsgcWSAPI_Bitmex oBitmex = new TsgcWSAPI_Bitmex();
oBitmex->Client = oClient;
oBitmex->Subscribe(btmTrade, "XBTUSD");
void OnBitmexMessage(Sender: TObject; const aTopic: TwsBitmexTopics; const aMessage: string)
{
// here you will receive the trade updates
}
.NET (C#)
TsgcWebSocketClient oClient = new TsgcWebSocketClient();
TsgcWSAPI_Bitmex oBitmex = new TsgcWSAPI_Bitmex();
oBitmex.Client = oClient;
oBitmex.Subscribe(btmTrade, "xbtusd");	
void OnBitmexMessage(Sender: TObject; const aTopic: TwsBitmexTopics; const aMessage: string)
{
// here you will receive the tradeupdates
}

2 · Bitmex | How to Place Orders

The Bitmex REST API offer public and private endpoints. The Private endpoints require that messages are signed to increase the security of transactions.

Delphi (VCL / FireMonkey)
// buy market order
BITMEX.REST_API.PlaceMarketOrder(bmosBuy, 'XBTUSD', 100);
// sell limit order at 45000
BITMEX.REST_API.PlaceLimitOrder(bmosSell, 'XBTUSD', 100, 45000.00);
// stop order at 48000
BITMEX.REST_API.PlaceStopOrder(bmosSell, 'XBTUSD', 100, 48000.00);
C++ Builder
// buy market order
BITMEX->REST_API->PlaceMarketOrder(bmosBuy, "XBTUSD", 100);
// sell limit order at 45000
BITMEX->REST_API->PlaceLimitOrder(bmosSell, "XBTUSD", 100, 45000.00);
// stop order at 48000
BITMEX->REST_API->PlaceStopOrder(bmosSell, "XBTUSD", 100, 48000.00);
.NET (C#)
// buy market order
BITMEX.REST_API.PlaceMarketOrder(bmosBuy, "XBTUSD", 100);
// sell limit order at 45000
BITMEX.REST_API.PlaceLimitOrder(bmosSell, "XBTUSD", 100, 45000.00);
// stop order at 48000
BITMEX.REST_API.PlaceStopOrder(bmosSell, "XBTUSD", 100, 48000.00);

Sources used to build this document

Every external claim links back to a primary source. The online-help references decode the canonical deep-link the company maintains for this component.

Document scope. This document covers the publicly-documented surface of the Bitmex API component shipped with sgcWebSockets. For full property, method and event reference consult the online help linked above.