Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves error #150 #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions src/service/gateways/hitbtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ interface MarketTrade {
}

class SideMarketData {
private readonly _data : Map<string, Models.MarketSide>;
private readonly _collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'})
private _data : Map<string, Models.MarketSide>;
private _collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'})

constructor(side: Models.Side) {
const compare = side === Models.Side.Bid ?
Expand Down Expand Up @@ -169,12 +169,12 @@ class SideMarketData {
class HitBtcMarketDataGateway implements Interfaces.IMarketDataGateway {
MarketData = new Utils.Evt<Models.Market>();
MarketTrade = new Utils.Evt<Models.GatewayMarketTrade>();
private readonly _marketDataWs : WebSocket;
private _marketDataWs : WebSocket;

private _hasProcessedSnapshot = false;

private readonly _lastBids = new SideMarketData(Models.Side.Bid);
private readonly _lastAsks = new SideMarketData(Models.Side.Ask);
private _lastBids = new SideMarketData(Models.Side.Bid);
private _lastAsks = new SideMarketData(Models.Side.Ask);
private onMarketDataIncrementalRefresh = (msg : MarketDataIncrementalRefresh, t : Date) => {
if (msg.symbol !== this._symbolProvider.symbol || !this._hasProcessedSnapshot) return;
this.onMarketDataUpdate(msg.bid, msg.ask, t);
Expand Down Expand Up @@ -230,7 +230,7 @@ class HitBtcMarketDataGateway implements Interfaces.IMarketDataGateway {

ConnectChanged = new Utils.Evt<Models.ConnectivityStatus>();
private onConnectionStatusChange = () => {
if (this._marketDataWs.isConnected && this._tradesClient.connected) {
if (this._marketDataWs.isConnected) {
this.ConnectChanged.trigger(Models.ConnectivityStatus.Connected);
}
else {
Expand All @@ -250,7 +250,6 @@ class HitBtcMarketDataGateway implements Interfaces.IMarketDataGateway {
this.MarketTrade.trigger(new Models.GatewayMarketTrade(t.price, t.amount, new Date(), false, side));
};

private readonly _tradesClient : SocketIOClient.Socket;
private readonly _log = log("tribeca:gateway:HitBtcMD");
constructor(
config : Config.IConfigProvider,
Expand All @@ -264,11 +263,6 @@ class HitBtcMarketDataGateway implements Interfaces.IMarketDataGateway {
this.onConnectionStatusChange);
this._marketDataWs.connect();

this._tradesClient = io.connect(config.GetString("HitBtcSocketIoUrl") + "/trades/" + this._symbolProvider.symbol);
this._tradesClient.on("connect", this.onConnectionStatusChange);
this._tradesClient.on("trade", this.onTrade);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't take out the _tradesClient, there needs to be a way to get prints.

this._tradesClient.on("disconnect", this.onConnectionStatusChange);

request.get(
{url: url.resolve(config.GetString("HitBtcPullUrl"), "/api/1/public/" + this._symbolProvider.symbol + "/orderbook")},
(err, body, resp) => {
Expand All @@ -292,7 +286,7 @@ class HitBtcMarketDataGateway implements Interfaces.IMarketDataGateway {

class HitBtcOrderEntryGateway implements Interfaces.IOrderEntryGateway {
OrderUpdate = new Utils.Evt<Models.OrderStatusUpdate>();
private readonly _orderEntryWs : WebSocket;
private _orderEntryWs : WebSocket;

public cancelsByClientOrderId = true;

Expand Down Expand Up @@ -474,19 +468,25 @@ class HitBtcOrderEntryGateway implements Interfaces.IOrderEntryGateway {

private onMessage = (raw : Models.Timestamped<string>) => {
try {
const msg = JSON.parse(raw.data);

if (this._log.debug())
this._log.debug(msg, "message");

if (msg.hasOwnProperty("ExecutionReport")) {
this.onExecutionReport(new Models.Timestamped(msg.ExecutionReport, raw.time));
}
else if (msg.hasOwnProperty("CancelReject")) {
this.onCancelReject(new Models.Timestamped(msg.CancelReject, raw.time));
}
else {
this._log.info("unhandled message", msg);
if (raw.data == 'Slow down... You should login first.')
{
this.sendAuth("Login",{});
this.onConnectionStatusChange();
} else {
const msg = JSON.parse(raw.data);

if (this._log.debug())
this._log.debug(msg, "message");

if (msg.hasOwnProperty("ExecutionReport")) {
this.onExecutionReport(new Models.Timestamped(msg.ExecutionReport, raw.time));
}
else if (msg.hasOwnProperty("CancelReject")) {
this.onCancelReject(new Models.Timestamped(msg.CancelReject, raw.time));
}
else {
this._log.info("unhandled message", msg);
}
}
}
catch (e) {
Expand Down