xapi-node
Advanced tools
Comparing version 1.0.32 to 1.0.33
@@ -10,3 +10,3 @@ import { Transaction, TransactionReject, Transactions } from "../interface/XapiTypeGuard"; | ||
protected WebSocket: WebSocketModule; | ||
constructor(); | ||
constructor(rateLimit: number); | ||
addTransaction(transaction: Transaction<null, null>, transactionId: string): void; | ||
@@ -13,0 +13,0 @@ private sendMessage; |
@@ -21,4 +21,4 @@ "use strict"; | ||
__extends(MessageTube, _super); | ||
function MessageTube() { | ||
var _this = _super.call(this) || this; | ||
function MessageTube(rateLimit) { | ||
var _this = _super.call(this, rateLimit) || this; | ||
_this.transactions = {}; | ||
@@ -119,3 +119,4 @@ _this._lastReceivedMessage = new Time_1.Time(false); | ||
var _this = this; | ||
var timeoutMs = this.messagesElapsedTime.length > 4 ? Math.max(1155 - this.messagesElapsedTime[this.messagesElapsedTime.length - 5].elapsedMs(), 0) : 100; | ||
var timeoutMs = this.messagesElapsedTime.length <= 4 ? 100 | ||
: Math.max((this.rateLimit() + 5) - this.messagesElapsedTime[this.messagesElapsedTime.length - 5].elapsedMs(), 0); | ||
this.isKillerCalled = setTimeout(function () { | ||
@@ -139,3 +140,5 @@ _this.isKillerCalled = null; | ||
else { | ||
this.callKillQueuTimeout(); | ||
if (this.isKillerCalled === null) { | ||
this.callKillQueuTimeout(); | ||
} | ||
break; | ||
@@ -142,0 +145,0 @@ } |
@@ -8,2 +8,5 @@ import { MessagesQueue } from "../interface/XapiTypeGuard"; | ||
protected isKillerCalled: any; | ||
private _rateLimit; | ||
protected rateLimit(): number; | ||
constructor(rateLimit: number); | ||
protected addQueu(transactionId: string): boolean; | ||
@@ -10,0 +13,0 @@ protected addElapsedTime(time: Time): void; |
@@ -19,9 +19,11 @@ "use strict"; | ||
__extends(Queue, _super); | ||
function Queue() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
function Queue(rateLimit) { | ||
var _this = _super.call(this) || this; | ||
_this.messageQueues = []; | ||
_this.messagesElapsedTime = []; | ||
_this.isKillerCalled = null; | ||
_this._rateLimit = rateLimit; | ||
return _this; | ||
} | ||
Queue.prototype.rateLimit = function () { return this._rateLimit; }; | ||
Queue.prototype.addQueu = function (transactionId) { | ||
@@ -42,3 +44,3 @@ if (this.messageQueues.length < 150) { | ||
return (this.messagesElapsedTime.length > 4) && | ||
(this.messagesElapsedTime[this.messagesElapsedTime.length - 5].elapsedMs() < 1150); | ||
(this.messagesElapsedTime[this.messagesElapsedTime.length - 5].elapsedMs() < this._rateLimit); | ||
}; | ||
@@ -45,0 +47,0 @@ Queue.prototype.stopQueuKiller = function () { |
import XAPI from '../XAPI'; | ||
import { CALENDAR_RECORD, IB_RECORD, NEWS_TOPIC_RECORD, STEP_RULE_RECORD, SYMBOL_RECORD, TRADE_RECORD, TRADE_TRANS_INFO, TRADING_HOURS_RECORD } from '../../interface/Definitions'; | ||
import { CALENDAR_RECORD, IB_RECORD, NEWS_TOPIC_RECORD, STEP_RULE_RECORD, SYMBOL_RECORD, TRADE_RECORD, TRADE_TRANS_INFO, TRADING_HOURS_RECORD } from '../..'; | ||
import { Transaction } from '../../interface/XapiTypeGuard'; | ||
@@ -4,0 +4,0 @@ import { getChartLastRequestResponse, getChartRangeRequestResponse, getCommissionDefResponse, getCurrentUserDataResponse, getMarginLevelResponse, getMarginTradeResponse, getProfitCalculationResponse, getServerTimeResponse, getTickPricesResponse, getVersionResponse, tradeTransactionResponse, tradeTransactionStatusResponse } from '../../interface/Response'; |
@@ -23,3 +23,3 @@ "use strict"; | ||
function SocketConnection(XAPI) { | ||
var _this = _super.call(this) || this; | ||
var _this = _super.call(this, XAPI.rateLimit) || this; | ||
_this.status = false; | ||
@@ -26,0 +26,0 @@ _this.XAPI = XAPI; |
@@ -34,3 +34,3 @@ "use strict"; | ||
function StreamConnection(XAPI) { | ||
var _this = _super.call(this) || this; | ||
var _this = _super.call(this, XAPI.rateLimit) || this; | ||
_this.status = false; | ||
@@ -37,0 +37,0 @@ _this.XAPI = XAPI; |
@@ -5,3 +5,3 @@ import Stream from "./Stream/Stream"; | ||
export declare const DefaultHostname = "ws.xtb.com"; | ||
export interface XAPILogin { | ||
export interface XAPIConfig { | ||
accountId?: string | null; | ||
@@ -12,2 +12,3 @@ password?: string | null; | ||
host?: string; | ||
rateLimit?: number; | ||
} | ||
@@ -29,3 +30,5 @@ export interface XAPIAccount { | ||
private _transactionIdIncrement; | ||
constructor({ accountId, password, type, appName, host }: XAPILogin); | ||
private _rateLimit; | ||
readonly rateLimit: number; | ||
constructor({ accountId, password, type, appName, host, rateLimit }: XAPIConfig); | ||
createTransactionId(): string; | ||
@@ -32,0 +35,0 @@ protected account: XAPIAccount; |
@@ -24,3 +24,3 @@ "use strict"; | ||
function XAPI(_a) { | ||
var _b = _a.accountId, accountId = _b === void 0 ? null : _b, _c = _a.password, password = _c === void 0 ? null : _c, _d = _a.type, type = _d === void 0 ? null : _d, _e = _a.appName, appName = _e === void 0 ? undefined : _e, _f = _a.host, host = _f === void 0 ? exports.DefaultHostname : _f; | ||
var _b = _a.accountId, accountId = _b === void 0 ? null : _b, _c = _a.password, password = _c === void 0 ? null : _c, _d = _a.type, type = _d === void 0 ? null : _d, _e = _a.appName, appName = _e === void 0 ? undefined : _e, _f = _a.host, host = _f === void 0 ? exports.DefaultHostname : _f, _g = _a.rateLimit, rateLimit = _g === void 0 ? 1200 : _g; | ||
var _this = _super.call(this) || this; | ||
@@ -30,2 +30,3 @@ _this._tryReconnect = false; | ||
_this._transactionIdIncrement = 0; | ||
_this._rateLimit = 1200; | ||
_this.account = { | ||
@@ -39,2 +40,3 @@ type: "demo", | ||
}; | ||
_this._rateLimit = rateLimit; | ||
_this.Socket = new Socket_1.default(_this); | ||
@@ -75,2 +77,7 @@ _this.Stream = new Stream_1.default(_this); | ||
}); | ||
Object.defineProperty(XAPI.prototype, "rateLimit", { | ||
get: function () { return this._rateLimit; }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
XAPI.prototype.createTransactionId = function () { | ||
@@ -77,0 +84,0 @@ this._transactionIdIncrement += 1; |
@@ -1,2 +0,2 @@ | ||
import { XAPI, XAPILogin } from "./core/XAPI"; | ||
import { XAPI, XAPIConfig } from "./core/XAPI"; | ||
export default XAPI; | ||
@@ -9,2 +9,2 @@ import { CALENDAR_RECORD, IB_RECORD, NEWS_TOPIC_RECORD, STEP_RULE_RECORD, SYMBOL_RECORD, TRADE_RECORD, TRADE_TRANS_INFO, TRADING_HOURS_RECORD, STREAMING_TRADE_RECORD, STREAMING_TICK_RECORD, STREAMING_PROFIT_RECORD, STREAMING_NEWS_RECORD, STREAMING_KEEP_ALIVE_RECORD, TRADING_RECORD, QUOTES_RECORD, TICK_RECORD, STEP_RECORD, RATE_INFO_RECORD, STREAMING_TRADE_STATUS_RECORD, STREAMING_CANDLE_RECORD, STREAMING_BALANCE_RECORD, CHART_LAST_INFO_RECORD, CHART_RANGE_INFO_RECORD } from './interface/Definitions'; | ||
export { Candle }; | ||
export { XAPILogin }; | ||
export { XAPIConfig }; |
{ | ||
"name": "xapi-node", | ||
"version": "1.0.32", | ||
"version": "1.0.33", | ||
"description": "This package is make possible to get data from market, execute order or limit orders with NodeJS through WebSocket connection", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -18,4 +18,4 @@ import { | ||
constructor() { | ||
super(); | ||
constructor(rateLimit: number) { | ||
super(rateLimit); | ||
} | ||
@@ -111,3 +111,4 @@ | ||
protected callKillQueuTimeout() { | ||
const timeoutMs = this.messagesElapsedTime.length > 4 ? Math.max(1155 - this.messagesElapsedTime[this.messagesElapsedTime.length - 5].elapsedMs(), 0) : 100; | ||
const timeoutMs = this.messagesElapsedTime.length <= 4 ? 100 | ||
: Math.max((this.rateLimit() + 5) - this.messagesElapsedTime[this.messagesElapsedTime.length - 5].elapsedMs(), 0); | ||
this.isKillerCalled = setTimeout(() => { | ||
@@ -131,3 +132,5 @@ this.isKillerCalled = null; | ||
} else { | ||
this.callKillQueuTimeout(); | ||
if (this.isKillerCalled === null) { | ||
this.callKillQueuTimeout(); | ||
} | ||
break; | ||
@@ -134,0 +137,0 @@ } |
@@ -9,2 +9,8 @@ import {MessagesQueue} from "../interface/XapiTypeGuard"; | ||
protected isKillerCalled: any = null; | ||
private _rateLimit: number; | ||
protected rateLimit() { return this._rateLimit; } | ||
constructor(rateLimit: number) { | ||
super(); | ||
this._rateLimit = rateLimit; | ||
} | ||
@@ -28,3 +34,3 @@ protected addQueu(transactionId: string): boolean { | ||
return (this.messagesElapsedTime.length > 4) && | ||
(this.messagesElapsedTime[this.messagesElapsedTime.length - 5].elapsedMs() < 1150); | ||
(this.messagesElapsedTime[this.messagesElapsedTime.length - 5].elapsedMs() < this._rateLimit); | ||
} | ||
@@ -31,0 +37,0 @@ |
@@ -11,3 +11,3 @@ import XAPI from '../XAPI'; | ||
TRADING_HOURS_RECORD | ||
} from '../../interface/Definitions'; | ||
} from '../..'; | ||
import { Transaction } from '../../interface/XapiTypeGuard'; | ||
@@ -14,0 +14,0 @@ import { |
@@ -18,3 +18,3 @@ import { | ||
constructor(XAPI: XAPI) { | ||
super(); | ||
super(XAPI.rateLimit); | ||
this.XAPI = XAPI; | ||
@@ -21,0 +21,0 @@ } |
@@ -16,3 +16,3 @@ import XAPI from "../XAPI"; | ||
constructor(XAPI: XAPI) { | ||
super(); | ||
super(XAPI.rateLimit); | ||
this.XAPI = XAPI; | ||
@@ -19,0 +19,0 @@ } |
@@ -8,3 +8,3 @@ import Stream from "./Stream/Stream"; | ||
export interface XAPILogin { | ||
export interface XAPIConfig { | ||
accountId ?: string | null, | ||
@@ -14,3 +14,4 @@ password ?: string | null, | ||
appName ?: string, | ||
host ?: string | ||
host ?: string, | ||
rateLimit ?: number | ||
} | ||
@@ -35,2 +36,4 @@ | ||
private _transactionIdIncrement: number = 0; | ||
private _rateLimit: number = 1200; | ||
public get rateLimit() { return this._rateLimit; } | ||
@@ -42,5 +45,6 @@ constructor({ | ||
appName = undefined, | ||
host = DefaultHostname}: XAPILogin) { | ||
host = DefaultHostname, | ||
rateLimit = 1200}: XAPIConfig) { | ||
super(); | ||
this._rateLimit = rateLimit; | ||
this.Socket = new Socket(this); | ||
@@ -47,0 +51,0 @@ this.Stream = new Stream(this); |
@@ -1,2 +0,2 @@ | ||
import { XAPI, XAPILogin } from "./core/XAPI"; | ||
import { XAPI, XAPIConfig } from "./core/XAPI"; | ||
export default XAPI; | ||
@@ -61,2 +61,2 @@ | ||
export { XAPILogin }; | ||
export { XAPIConfig }; |
@@ -11,3 +11,3 @@ /* src/sensitive.json | ||
import * as path from 'path'; | ||
import XAPI, {XAPILogin} from "../core/XAPI"; | ||
import XAPI, {XAPIConfig} from "../core/XAPI"; | ||
@@ -21,3 +21,3 @@ function test(jsonPath: string) { | ||
const {accountId, password, type}: XAPILogin = JSON.parse(fs.readFileSync(login).toString().trim()); | ||
const {accountId, password, type}: XAPIConfig = JSON.parse(fs.readFileSync(login).toString().trim()); | ||
if (typeof (accountId) !== "string" | ||
@@ -24,0 +24,0 @@ || typeof (password) !== "string" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
179218
3870