Skip to content

Commit b702671

Browse files
Merge pull request #500 from yshing/update-ws-endpoint
Change of Websocket Endpoint to ws.bitmex.com
2 parents b4c8432 + 1aad526 commit b702671

7 files changed

Lines changed: 17 additions & 18 deletions

File tree

official-ws/nodejs/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ const getStreams = require('./lib/getStreams');
99
const DEFAULT_MAX_TABLE_LEN = 10000;
1010

1111
const endpoints = {
12-
production: 'wss://www.bitmex.com/realtime',
13-
testnet: 'wss://testnet.bitmex.com/realtime'
12+
production: 'wss://ws.bitmex.com/realtime',
13+
testnet: 'wss://ws.testnet.bitmex.com/realtime'
1414
};
15+
const httpEndpoints = {
16+
production: 'https://www.bitmex.com/api/v1',
17+
testnet: 'https://testnet.bitmex.com/api/v1'
18+
}
1519
const noSymbolTables = BitMEXClient.noSymbolTables = [
1620
'account',
1721
'affiliate',
@@ -45,6 +49,9 @@ function BitMEXClient(options) {
4549
if (!options.endpoint) {
4650
options.endpoint = options.testnet ? endpoints.testnet : endpoints.production;
4751
}
52+
if (!options.httpEndpoint) {
53+
options.httpEndpoint = options.testnet ? httpEndpoints.testnet : httpEndpoints.production;
54+
}
4855
if (process.env.BITMEX_ENDPOINT) options.endpoint = process.env.BITMEX_ENDPOINT;
4956
debug(options)
5057

@@ -57,7 +64,7 @@ function BitMEXClient(options) {
5764
}
5865

5966
// Get valid streams so we can validate our subscriptions.
60-
getStreams(options.endpoint, function(err, streams) {
67+
getStreams(options.httpEndpoint, function(err, streams) {
6168
if (err) throw err;
6269
emitter.initialized = true;
6370
emitter.streams = streams;

official-ws/nodejs/lib/getStreams.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
const superagent = require('superagent');
2-
const url = require('url');
32
const debug = require('debug')('BitMEX:realtime-api:getStreams');
43

5-
module.exports = function(wsEndpoint, callback) {
6-
const parsed = url.parse(wsEndpoint);
7-
const httpEndpoint = url.format({
8-
protocol: parsed.protocol === 'wss:' ? 'https:' : 'http',
9-
host: parsed.host
10-
});
11-
4+
module.exports = function(httpEndpoint, callback) {
125
superagent
13-
.get(httpEndpoint + '/api/v1/schema/websocketHelp')
6+
.get(httpEndpoint + '/schema/websocketHelp')
147
.end(function(err, res) {
158
if (err) return callback(err);
169
const streams = res.body.subscriptionSubjects;

official-ws/nodejs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bitmex-realtime-api",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "A library for interacting with BitMEX's websocket API.",
55
"main": "index.js",
66
"repository": "https://github.com/BitMEX/api-connectors.git",

official-ws/python/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ and unauthenticated clients. Some endpoints require credentials, for more info s
1616
To get started, instantiate a connection:
1717

1818
from bitmex_websocket import BitMEXWebsocket
19-
ws = BitMEXWebsocket(endpoint="https://testnet.bitmex.com/api/v1", symbol="XBTUSD", api_key=None, api_secret=None)
19+
ws = BitMEXWebsocket(endpoint="wss://ws.testnet.bitmex.com/realtime", symbol="XBTUSD", api_key=None, api_secret=None)
2020

2121
If you want to subscribe to authenticated data streams, [create an API key](https://testnet.bitmex.com/app/apiKeys) and
2222
supply the corresponding values in `api_key` and `api_secret`. BitMEX has two systems - `testnet` for simulated

official-ws/python/bitmex_websocket.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ def __get_url(self, subscriptions):
163163
), subscriptions)
164164

165165
urlParts = list(urllib.parse.urlparse(self.endpoint))
166-
urlParts[0] = urlParts[0].replace('http', 'ws')
167-
urlParts[2] = "/realtime?subscribe={}".format(','.join(subscriptions_full))
166+
urlParts[2] += "?subscribe={}".format(','.join(subscriptions_full))
168167
return urllib.parse.urlunparse(urlParts)
169168

170169
def __wait_for_account(self):

official-ws/python/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def run():
88
logger = setup_logger()
99

1010
# Instantiating the WS will make it connect. Be sure to add your api_key/api_secret.
11-
ws = BitMEXWebsocket(endpoint="https://testnet.bitmex.com/api/v1", symbol="XBTUSD",
11+
ws = BitMEXWebsocket(endpoint="wss://ws.testnet.bitmex.com/realtime", symbol="XBTUSD",
1212
api_key=None, api_secret=None)
1313

1414
logger.info("Instrument data: %s" % ws.get_instrument())

official-ws/python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
here = dirname(__file__)
66

77
setup(name='bitmex-ws',
8-
version='0.4.0',
8+
version='0.5.0',
99
description='Sample adapter for connecting to the BitMEX Websocket API.',
1010
long_description=open(join(here, 'README.md')).read(),
1111
author='Samuel Reed',

0 commit comments

Comments
 (0)