hft-js 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bar.js +1 -1
- package/lib/broker.d.ts +3 -2
- package/lib/broker.js +7 -15
- package/lib/broker.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.test.js +7 -1
- package/lib/index.test.js.map +1 -1
- package/lib/interfaces.d.ts +4 -4
- package/lib/interfaces.js +1 -1
- package/lib/market.d.ts +3 -3
- package/lib/market.js +6 -4
- package/lib/market.js.map +1 -1
- package/lib/provider.d.ts +2 -2
- package/lib/provider.js +3 -3
- package/lib/provider.js.map +1 -1
- package/lib/tape.js +1 -1
- package/lib/trader.d.ts +3 -3
- package/lib/trader.js +15 -15
- package/lib/trader.js.map +1 -1
- package/lib/typedef.js +1 -1
- package/lib/utils.js +1 -1
- package/package.json +1 -1
- package/src/bar.ts +1 -1
- package/src/broker.ts +9 -19
- package/src/index.test.ts +9 -1
- package/src/index.ts +1 -1
- package/src/interfaces.ts +9 -5
- package/src/market.ts +9 -4
- package/src/provider.ts +4 -4
- package/src/tape.ts +1 -1
- package/src/trader.ts +34 -15
- package/src/typedef.ts +1 -1
- package/src/utils.ts +1 -1
package/src/trader.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* trader.ts
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c) 2025 Xiongfei Shi
|
|
4
|
+
* Copyright (c) 2025-2026 Xiongfei Shi
|
|
5
5
|
*
|
|
6
6
|
* Author: Xiongfei Shi <xiongfei.shi(a)icloud.com>
|
|
7
7
|
* License: Apache-2.0
|
|
@@ -57,6 +57,7 @@ import type {
|
|
|
57
57
|
import type {
|
|
58
58
|
ICancelOrderResultReceiver,
|
|
59
59
|
ICommissionRateReceiver,
|
|
60
|
+
IErrorReceiver,
|
|
60
61
|
IInstrumentReceiver,
|
|
61
62
|
IInstrumentsReceiver,
|
|
62
63
|
ILifecycleListener,
|
|
@@ -177,7 +178,7 @@ export class Trader extends CTPProvider implements ITraderProvider {
|
|
|
177
178
|
}
|
|
178
179
|
}
|
|
179
180
|
|
|
180
|
-
open(lifecycle: ILifecycleListener) {
|
|
181
|
+
open(lifecycle: ILifecycleListener, errorReceiver: IErrorReceiver) {
|
|
181
182
|
if (this.traderApi) {
|
|
182
183
|
return true;
|
|
183
184
|
}
|
|
@@ -197,7 +198,7 @@ export class Trader extends CTPProvider implements ITraderProvider {
|
|
|
197
198
|
this.traderApi.on<RspAuthenticateField>(
|
|
198
199
|
ctp.TraderEvent.RspAuthenticate,
|
|
199
200
|
(_, options) => {
|
|
200
|
-
if (this._isErrorResp(
|
|
201
|
+
if (this._isErrorResp(errorReceiver, options, "login-error")) {
|
|
201
202
|
return;
|
|
202
203
|
}
|
|
203
204
|
|
|
@@ -208,7 +209,7 @@ export class Trader extends CTPProvider implements ITraderProvider {
|
|
|
208
209
|
this.traderApi.on<RspUserLoginField>(
|
|
209
210
|
ctp.TraderEvent.RspUserLogin,
|
|
210
211
|
(rspUserLogin, options) => {
|
|
211
|
-
if (this._isErrorResp(
|
|
212
|
+
if (this._isErrorResp(errorReceiver, options, "login-error")) {
|
|
212
213
|
return;
|
|
213
214
|
}
|
|
214
215
|
|
|
@@ -235,7 +236,7 @@ export class Trader extends CTPProvider implements ITraderProvider {
|
|
|
235
236
|
this.traderApi.on<SettlementInfoConfirmField>(
|
|
236
237
|
ctp.TraderEvent.RspSettlementInfoConfirm,
|
|
237
238
|
(_, options) => {
|
|
238
|
-
if (this._isErrorResp(
|
|
239
|
+
if (this._isErrorResp(errorReceiver, options, "login-error")) {
|
|
239
240
|
return;
|
|
240
241
|
}
|
|
241
242
|
|
|
@@ -247,7 +248,7 @@ export class Trader extends CTPProvider implements ITraderProvider {
|
|
|
247
248
|
this.traderApi.on<OrderField>(
|
|
248
249
|
ctp.TraderEvent.RspQryOrder,
|
|
249
250
|
(order, options) => {
|
|
250
|
-
if (this._isErrorResp(
|
|
251
|
+
if (this._isErrorResp(errorReceiver, options, "query-order-error")) {
|
|
251
252
|
return;
|
|
252
253
|
}
|
|
253
254
|
|
|
@@ -266,7 +267,7 @@ export class Trader extends CTPProvider implements ITraderProvider {
|
|
|
266
267
|
this.traderApi.on<TradeField>(
|
|
267
268
|
ctp.TraderEvent.RspQryTrade,
|
|
268
269
|
(trade, options) => {
|
|
269
|
-
if (this._isErrorResp(
|
|
270
|
+
if (this._isErrorResp(errorReceiver, options, "query-trade-error")) {
|
|
270
271
|
return;
|
|
271
272
|
}
|
|
272
273
|
|
|
@@ -291,7 +292,9 @@ export class Trader extends CTPProvider implements ITraderProvider {
|
|
|
291
292
|
this.traderApi.on<InstrumentField>(
|
|
292
293
|
ctp.TraderEvent.RspQryInstrument,
|
|
293
294
|
(instrument, options) => {
|
|
294
|
-
if (
|
|
295
|
+
if (
|
|
296
|
+
this._isErrorResp(errorReceiver, options, "query-instrument-error")
|
|
297
|
+
) {
|
|
295
298
|
return;
|
|
296
299
|
}
|
|
297
300
|
|
|
@@ -319,7 +322,9 @@ export class Trader extends CTPProvider implements ITraderProvider {
|
|
|
319
322
|
this.traderApi.on<InvestorPositionField>(
|
|
320
323
|
ctp.TraderEvent.RspQryInvestorPosition,
|
|
321
324
|
(position, options) => {
|
|
322
|
-
if (
|
|
325
|
+
if (
|
|
326
|
+
this._isErrorResp(errorReceiver, options, "query-positions-error")
|
|
327
|
+
) {
|
|
323
328
|
return;
|
|
324
329
|
}
|
|
325
330
|
|
|
@@ -530,7 +535,9 @@ export class Trader extends CTPProvider implements ITraderProvider {
|
|
|
530
535
|
(marginRate, options) => {
|
|
531
536
|
const query = this.marginRatesQueue.shift();
|
|
532
537
|
|
|
533
|
-
if (
|
|
538
|
+
if (
|
|
539
|
+
this._isErrorResp(errorReceiver, options, "query-margin-rate-error")
|
|
540
|
+
) {
|
|
534
541
|
if (query) {
|
|
535
542
|
query.receiver.onMarginRate(undefined);
|
|
536
543
|
}
|
|
@@ -558,7 +565,11 @@ export class Trader extends CTPProvider implements ITraderProvider {
|
|
|
558
565
|
const query = this.commRatesQueue.shift();
|
|
559
566
|
|
|
560
567
|
if (
|
|
561
|
-
this._isErrorResp(
|
|
568
|
+
this._isErrorResp(
|
|
569
|
+
errorReceiver,
|
|
570
|
+
options,
|
|
571
|
+
"query-commission-rate-error",
|
|
572
|
+
)
|
|
562
573
|
) {
|
|
563
574
|
if (query) {
|
|
564
575
|
query.receiver.onCommissionRate(undefined);
|
|
@@ -584,7 +595,7 @@ export class Trader extends CTPProvider implements ITraderProvider {
|
|
|
584
595
|
this.traderApi.on<TradingAccountField>(
|
|
585
596
|
ctp.TraderEvent.RspQryTradingAccount,
|
|
586
597
|
(account, options) => {
|
|
587
|
-
if (this._isErrorResp(
|
|
598
|
+
if (this._isErrorResp(errorReceiver, options, "query-accounts-error")) {
|
|
588
599
|
const receivers = this.accountsQueue.toArray();
|
|
589
600
|
|
|
590
601
|
receivers.forEach((receiver) =>
|
|
@@ -615,7 +626,11 @@ export class Trader extends CTPProvider implements ITraderProvider {
|
|
|
615
626
|
ctp.TraderEvent.RspQryInvestorPositionDetail,
|
|
616
627
|
(positionDetail, options) => {
|
|
617
628
|
if (
|
|
618
|
-
this._isErrorResp(
|
|
629
|
+
this._isErrorResp(
|
|
630
|
+
errorReceiver,
|
|
631
|
+
options,
|
|
632
|
+
"query-position-details-error",
|
|
633
|
+
)
|
|
619
634
|
) {
|
|
620
635
|
const receivers = this.positionDetailsQueue.toArray();
|
|
621
636
|
|
|
@@ -686,7 +701,11 @@ export class Trader extends CTPProvider implements ITraderProvider {
|
|
|
686
701
|
ctp.TraderEvent.RspQryDepthMarketData,
|
|
687
702
|
(depthMarketData, options) => {
|
|
688
703
|
if (
|
|
689
|
-
this._isErrorResp(
|
|
704
|
+
this._isErrorResp(
|
|
705
|
+
errorReceiver,
|
|
706
|
+
options,
|
|
707
|
+
"query-depth-market-data-error",
|
|
708
|
+
)
|
|
690
709
|
) {
|
|
691
710
|
this._clearAllMarketOrders();
|
|
692
711
|
return;
|
|
@@ -754,7 +773,7 @@ export class Trader extends CTPProvider implements ITraderProvider {
|
|
|
754
773
|
return true;
|
|
755
774
|
}
|
|
756
775
|
|
|
757
|
-
close(lifecycle: ILifecycleListener) {
|
|
776
|
+
close(lifecycle: ILifecycleListener, _errorReceiver: IErrorReceiver) {
|
|
758
777
|
if (!this.traderApi) {
|
|
759
778
|
return;
|
|
760
779
|
}
|
package/src/typedef.ts
CHANGED