@mnie/provider-sbi-sec 0.0.0 → 0.1.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/dist/index.d.mts +23 -2
- package/dist/index.mjs +370 -45
- package/package.json +2 -9
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommonMethods, FinancialProvider, InvestmentMethods, MethodDefinition } from "@mnie/types";
|
|
1
|
+
import { CommonMethods, FinancialProvider, IncrementalPage, IncrementalPageRequest, InvestmentMethods, MethodDefinition } from "@mnie/types";
|
|
2
2
|
export type * from "@mnie/types";
|
|
3
3
|
|
|
4
4
|
//#region src/types.d.ts
|
|
@@ -231,6 +231,15 @@ interface IssueChart {
|
|
|
231
231
|
latestDateTime?: string;
|
|
232
232
|
error?: SbiMethodError;
|
|
233
233
|
}
|
|
234
|
+
interface IssueTick {
|
|
235
|
+
sequenceNumber: string;
|
|
236
|
+
time: string;
|
|
237
|
+
price: CurrencyAmount;
|
|
238
|
+
volume: number | null;
|
|
239
|
+
}
|
|
240
|
+
interface IssueTickList extends IncrementalPage<IssueTick> {
|
|
241
|
+
issue: IssueRef;
|
|
242
|
+
}
|
|
234
243
|
interface Quote {
|
|
235
244
|
issue: IssueRef;
|
|
236
245
|
price?: CurrencyAmount;
|
|
@@ -373,6 +382,16 @@ interface OrderPreview {
|
|
|
373
382
|
message?: string;
|
|
374
383
|
correction?: OrderCorrectionPreOrder;
|
|
375
384
|
error?: SbiMethodError;
|
|
385
|
+
/** Settlement currency for orders that offer settlement modes. */
|
|
386
|
+
settlementCurrency?: CurrencyAmount['currency'];
|
|
387
|
+
/** Estimated amount in the instrument's trading currency. */
|
|
388
|
+
tradeAmount?: CurrencyAmount;
|
|
389
|
+
/** Cash amount the provider reserves, in the settlement currency. */
|
|
390
|
+
heldAmount?: CurrencyAmount;
|
|
391
|
+
/** Buying power reported for the order, in the settlement currency. */
|
|
392
|
+
buyingPower?: CurrencyAmount;
|
|
393
|
+
/** Exchange rate applied to settlement-currency amounts. */
|
|
394
|
+
exchangeRate?: string;
|
|
376
395
|
}
|
|
377
396
|
interface StockOrderPreOrderPriceStep {
|
|
378
397
|
from?: CurrencyAmount;
|
|
@@ -511,6 +530,7 @@ type IssueChartOptions = IssueOptions & {
|
|
|
511
530
|
unit?: number; /** Number of historical prices to request. Defaults to 120. */
|
|
512
531
|
count?: number;
|
|
513
532
|
};
|
|
533
|
+
type IssueTicksOptions = IssueOptions & IncrementalPageRequest;
|
|
514
534
|
interface IssueSearchOptions {
|
|
515
535
|
/** Search text, such as an issue code, name, or keyword. */
|
|
516
536
|
query: string;
|
|
@@ -524,6 +544,7 @@ interface IssueSearchOptions {
|
|
|
524
544
|
type SbiSecOperations = CommonMethods & InvestmentMethods & {
|
|
525
545
|
'market.index.major': MethodDefinition<Record<string, never>, MarketIndex[]>;
|
|
526
546
|
'market.issue.chart': MethodDefinition<IssueChartOptions, IssueChart>;
|
|
547
|
+
'market.issue.ticks': MethodDefinition<IssueTicksOptions, IssueTickList>;
|
|
527
548
|
'market.issue.search': MethodDefinition<IssueSearchOptions, IssueSearchResult>;
|
|
528
549
|
'market.issue.suggest': MethodDefinition<IssueSearchOptions, IssueSearchResult>;
|
|
529
550
|
'market.issue.board': MethodDefinition<IssueOptions, Board>;
|
|
@@ -554,4 +575,4 @@ declare class SbiServerError extends Error {
|
|
|
554
575
|
}
|
|
555
576
|
declare const getSbiServerErrorMessage: (code: string) => string;
|
|
556
577
|
//#endregion
|
|
557
|
-
export { type AccountAssetsValuationDetail, type AccountAssetsValuationSummary, type AccountAssetsValuations, type ChartPeriod, type ChartPrice, type ExchangeAccountKind, type ExchangeOrderPreview, type ExchangeOrderReceipt, type ExchangeOrderSide, type ExchangeRateInfo, type ExchangeSellMethod, type ExchangeSpecificMethod, type IssueChart, type IssueSearchItem, type IssueSearchResult, type IssueSearchStatus, type LoginWithPasskeyOptions, type MarketCode, type OrderCorrectionPreOrder, type OrderCorrectionPreOrderDetail, type OrderPreview, type PasskeyAssertionProvider, type PasskeyLoginResponse, type PlaintextStoredWebAuthnCredential, SBI_SERVER_ERROR_MESSAGES, type SbiClientOptions, type SbiEndpointOptions, type SbiSecOperations, SbiServerError, type SbiServerErrorOptions, type StockOrderPreOrder, type StockOrderPreOrderMarginTradeType, type StockOrderPreOrderPaymentLimit, type StockOrderPreOrderPriceStep, type StoredWebAuthnCredential, type StoredWebAuthnCredentialSecret, type TradeRecord, type TradeRecordList, type WebAuthnAlgorithm, type WebAuthnAssertion, type WebAuthnAssertionRequest, type WebAuthnJwk, type WebAuthnTransport, type WebAuthnUserVerification, connectWithPasskey, createStoredCredentialPasskeyProvider, getSbiServerErrorMessage };
|
|
578
|
+
export { type AccountAssetsValuationDetail, type AccountAssetsValuationSummary, type AccountAssetsValuations, type ChartPeriod, type ChartPrice, type ExchangeAccountKind, type ExchangeOrderPreview, type ExchangeOrderReceipt, type ExchangeOrderSide, type ExchangeRateInfo, type ExchangeSellMethod, type ExchangeSpecificMethod, type IssueChart, type IssueSearchItem, type IssueSearchResult, type IssueSearchStatus, type IssueTick, type IssueTickList, type LoginWithPasskeyOptions, type MarketCode, type OrderCorrectionPreOrder, type OrderCorrectionPreOrderDetail, type OrderPreview, type PasskeyAssertionProvider, type PasskeyLoginResponse, type PlaintextStoredWebAuthnCredential, SBI_SERVER_ERROR_MESSAGES, type SbiClientOptions, type SbiEndpointOptions, type SbiSecOperations, SbiServerError, type SbiServerErrorOptions, type StockOrderPreOrder, type StockOrderPreOrderMarginTradeType, type StockOrderPreOrderPaymentLimit, type StockOrderPreOrderPriceStep, type StoredWebAuthnCredential, type StoredWebAuthnCredentialSecret, type TradeRecord, type TradeRecordList, type WebAuthnAlgorithm, type WebAuthnAssertion, type WebAuthnAssertionRequest, type WebAuthnJwk, type WebAuthnTransport, type WebAuthnUserVerification, connectWithPasskey, createStoredCredentialPasskeyProvider, getSbiServerErrorMessage };
|
package/dist/index.mjs
CHANGED
|
@@ -9018,9 +9018,9 @@ const createUsStockAdapter = (session) => ({
|
|
|
9018
9018
|
const order = objectAt(data, ["createForeignStockOrder", "order"]);
|
|
9019
9019
|
return {
|
|
9020
9020
|
accepted: true,
|
|
9021
|
-
orderId: stringAt(order, ["
|
|
9021
|
+
orderId: stringAt(order, ["orderSubNo"]) ?? stringAt(order, ["orderNo"]),
|
|
9022
9022
|
acceptedAt: stringAt(order, ["orderInputDatetime"]),
|
|
9023
|
-
message: stringAt(data, ["createForeignStockOrder", "
|
|
9023
|
+
message: stringAt(order, ["orderStatus"]) ?? stringArrayAt(data, ["createForeignStockOrder", "warningStatuses"]).join(",")
|
|
9024
9024
|
};
|
|
9025
9025
|
},
|
|
9026
9026
|
estimateCorrection: async (options) => {
|
|
@@ -9036,14 +9036,14 @@ const createUsStockAdapter = (session) => ({
|
|
|
9036
9036
|
rics: [usRic(order.issue.code, market)]
|
|
9037
9037
|
}), ["getForeignStockUpdatedOrderInitialization"]);
|
|
9038
9038
|
const initOrder = objectAt(init, ["order"]);
|
|
9039
|
+
const initSettlementCurrency = usSettlementCurrency(initOrder) ?? order.settlementCurrency;
|
|
9039
9040
|
return {
|
|
9040
9041
|
issue: order.issue,
|
|
9041
9042
|
side: order.side,
|
|
9042
9043
|
quantity: numberAt(initOrder, ["orderQuantity"]) ?? order.quantity ?? options.quantity,
|
|
9043
9044
|
price: usd(stringAt(initOrder, ["orderPrice"]) ?? String(options.price ?? "")),
|
|
9044
|
-
estimatedAmount:
|
|
9045
|
-
|
|
9046
|
-
tax: usd(stringAt(initOrder, ["frnCommissionCtax"])),
|
|
9045
|
+
estimatedAmount: usSettlementSideAmount(initOrder) ?? order.settledAmount,
|
|
9046
|
+
settlementCurrency: initSettlementCurrency,
|
|
9047
9047
|
warnings: [],
|
|
9048
9048
|
confirmationId: input.orderSubNo,
|
|
9049
9049
|
correction: usOrderCorrectionPreOrderFromOrder(order, init)
|
|
@@ -9068,9 +9068,10 @@ const createUsStockAdapter = (session) => ({
|
|
|
9068
9068
|
side: order.side,
|
|
9069
9069
|
quantity: order.unexecutedQuantity ?? order.quantity ?? void 0,
|
|
9070
9070
|
price: order.price,
|
|
9071
|
-
estimatedAmount:
|
|
9072
|
-
|
|
9073
|
-
|
|
9071
|
+
estimatedAmount: order.settledAmount ?? order.heldAmount,
|
|
9072
|
+
settlementCurrency: order.settlementCurrency,
|
|
9073
|
+
commission: void 0,
|
|
9074
|
+
tax: void 0,
|
|
9074
9075
|
warnings: [],
|
|
9075
9076
|
confirmationId: orderSubNo,
|
|
9076
9077
|
correction: usOrderCorrectionPreOrderFromOrder(order)
|
|
@@ -9166,7 +9167,9 @@ const fetchUsOrders = async (session, options) => {
|
|
|
9166
9167
|
pageSize: options?.limit ?? 999
|
|
9167
9168
|
}
|
|
9168
9169
|
} });
|
|
9169
|
-
const
|
|
9170
|
+
const rows = arrayAt(data, ["listForeignStockOrders", "orderDecodes"]);
|
|
9171
|
+
const orders = rows.map((order) => orderFromGraphql(order));
|
|
9172
|
+
await Promise.all(orders.map((order, index) => hydrateUsOrder(session, order, rows[index])));
|
|
9170
9173
|
const list = objectAt(data, ["listForeignStockOrders"]);
|
|
9171
9174
|
return {
|
|
9172
9175
|
orders: orders.filter((order) => {
|
|
@@ -9196,12 +9199,63 @@ const fetchUsOrderDetail = async (session, options) => {
|
|
|
9196
9199
|
}), ["getForeignStockOrderDetail", "orderDetail"]);
|
|
9197
9200
|
const order = objectAt(detail, ["order"]);
|
|
9198
9201
|
if (!order) throw new Error("orders.inquiry.detail returned no US stock order detail");
|
|
9199
|
-
|
|
9202
|
+
const parsed = orderFromGraphql(order, {
|
|
9200
9203
|
issue: base.issue,
|
|
9201
9204
|
cancelable: booleanAt(detail, ["cancelable"]),
|
|
9202
9205
|
correctable: booleanAt(detail, ["correctable"])
|
|
9203
9206
|
});
|
|
9207
|
+
await hydrateUsOrder(session, parsed, order);
|
|
9208
|
+
return parsed;
|
|
9204
9209
|
};
|
|
9210
|
+
/**
|
|
9211
|
+
* Supplies the settlement-side amounts SBI never puts on order-list rows.
|
|
9212
|
+
* Open buys replay the order through `confirmForeignStockCreatedOrder` so the
|
|
9213
|
+
* reservation matches the broker's own hold calculation (buffered FX and
|
|
9214
|
+
* fees). Orders with executions read the settled amount from the order
|
|
9215
|
+
* detail. Amounts that cannot be established stay unset so callers must not
|
|
9216
|
+
* substitute estimates.
|
|
9217
|
+
*/
|
|
9218
|
+
const hydrateUsOrder = async (session, order, raw) => {
|
|
9219
|
+
const executed = order.executedQuantity ?? 0;
|
|
9220
|
+
const unexecuted = order.unexecutedQuantity ?? 0;
|
|
9221
|
+
if (executed > 0) {
|
|
9222
|
+
if (order.settledAmount?.value != null) return;
|
|
9223
|
+
const orderNo = order.orderNumber ?? stringAt(raw, ["orderNo"]);
|
|
9224
|
+
if (!orderNo) return;
|
|
9225
|
+
try {
|
|
9226
|
+
const detailOrder = objectAt(await callUsGraphql(session, "GetOrderSettlementDetail", ORDER_SETTLEMENT_DETAIL, { input: { orderNo } }), [
|
|
9227
|
+
"getForeignStockOrderDetail",
|
|
9228
|
+
"orderDetail",
|
|
9229
|
+
"order"
|
|
9230
|
+
]);
|
|
9231
|
+
order.settlementCurrency ??= usSettlementCurrency(detailOrder);
|
|
9232
|
+
const settled = usSettledAmount(detailOrder);
|
|
9233
|
+
if (settled?.value != null) order.settledAmount = settled;
|
|
9234
|
+
} catch {}
|
|
9235
|
+
return;
|
|
9236
|
+
}
|
|
9237
|
+
if (order.status !== "open" || order.side !== "buy" || unexecuted <= 0) return;
|
|
9238
|
+
if (!session.tradePassword) return;
|
|
9239
|
+
try {
|
|
9240
|
+
const confirmed = objectAt(await callUsGraphql(session, "ConfirmOrderCreating", CONFIRM_ORDER, { input: { order: usHoldConfirmInput(raw, unexecuted, order) } }, { tradePassword: session.tradePassword }), ["confirmForeignStockCreatedOrder", "order"]);
|
|
9241
|
+
order.settlementCurrency ??= usSettlementCurrency(confirmed);
|
|
9242
|
+
const held = usSettlementSideAmount(confirmed);
|
|
9243
|
+
if (held?.value != null) order.heldAmount = held;
|
|
9244
|
+
} catch {}
|
|
9245
|
+
};
|
|
9246
|
+
const usHoldConfirmInput = (raw, unexecuted, order) => ({
|
|
9247
|
+
countryCode: COUNTRY_US,
|
|
9248
|
+
marketCode: stringAt(raw, ["market", "marketCode"]) ?? (order.issue.market ? usGraphqlMarketCode(order.issue.market) : void 0),
|
|
9249
|
+
securitiesCode: stringAt(raw, ["securities", "securitiesCode"]) || order.issue.code || void 0,
|
|
9250
|
+
buySellCode: "BUY",
|
|
9251
|
+
orderQuantity: String(unexecuted),
|
|
9252
|
+
orderPrice: stringAt(raw, ["orderPriceKindCode"]) === "LIMIT" ? stringAt(raw, ["orderPrice"]) : void 0,
|
|
9253
|
+
orderPriceKindCode: stringAt(raw, ["orderPriceKindCode"]),
|
|
9254
|
+
orderLimitCode: stringAt(raw, ["orderLimitCode"]),
|
|
9255
|
+
orderTerm: stringAt(raw, ["orderTerm"]),
|
|
9256
|
+
specificAccountCode: stringAt(raw, ["specificAccountCode"]),
|
|
9257
|
+
settlementMethodCode: stringAt(raw, ["settlementMethodCode"])
|
|
9258
|
+
});
|
|
9205
9259
|
const fetchUsTradeRecords = async (session, options) => {
|
|
9206
9260
|
if (options.market) requireUsMarket(options.market, "orders.inquiry.tradeRecords");
|
|
9207
9261
|
const dateRange = usInquiryDateRange(options);
|
|
@@ -9329,6 +9383,8 @@ const priceLevels = (source, priceKey, quantityKey) => {
|
|
|
9329
9383
|
const orderPreviewFromConfirmation = (data, options) => {
|
|
9330
9384
|
const confirmation = objectAt(data, ["confirmForeignStockCreatedOrder"]);
|
|
9331
9385
|
const order = objectAt(confirmation, ["order"]);
|
|
9386
|
+
const settlementCurrency = usSettlementCurrency(order);
|
|
9387
|
+
const settlementAmount = usSettlementSideAmount(order);
|
|
9332
9388
|
return {
|
|
9333
9389
|
issue: {
|
|
9334
9390
|
code: options.issueCode,
|
|
@@ -9337,18 +9393,59 @@ const orderPreviewFromConfirmation = (data, options) => {
|
|
|
9337
9393
|
side: options.side,
|
|
9338
9394
|
quantity: options.quantity,
|
|
9339
9395
|
price: usd(String(options.price ?? "")),
|
|
9340
|
-
estimatedAmount:
|
|
9341
|
-
|
|
9342
|
-
|
|
9396
|
+
estimatedAmount: settlementAmount,
|
|
9397
|
+
heldAmount: options.side === "buy" ? settlementAmount : void 0,
|
|
9398
|
+
settlementCurrency,
|
|
9399
|
+
tradeAmount: usTradeAmount(order),
|
|
9400
|
+
buyingPower: currencyAmount(stringAt(confirmation, ["buyPossibleAmount"]), settlementCurrency),
|
|
9401
|
+
exchangeRate: stringAt(order, ["exchangeRate"]),
|
|
9402
|
+
commission: currencyAmount(stringAt(order, settlementCurrency === "JPY" ? ["commissionAmount"] : ["frnCommissionAmount"]), settlementCurrency),
|
|
9403
|
+
tax: currencyAmount(stringAt(order, settlementCurrency === "JPY" ? ["commissionCtax"] : ["frnCommissionCtax"]), settlementCurrency),
|
|
9343
9404
|
warnings: stringArrayAt(confirmation, ["warningStatuses"]),
|
|
9344
|
-
confirmationId: stringAt(order, ["orderNo"])
|
|
9405
|
+
confirmationId: stringAt(order, ["orderNo"]) || stringAt(order, ["orderSubNo"]) || randomUUID()
|
|
9345
9406
|
};
|
|
9346
9407
|
};
|
|
9408
|
+
/**
|
|
9409
|
+
* Resolves the settlement currency of a US stock order row.
|
|
9410
|
+
* `settlementCurrencyCode` is authoritative; the method code maps to JPY or
|
|
9411
|
+
* the instrument's trade currency (always USD for US stocks).
|
|
9412
|
+
*/
|
|
9413
|
+
const usSettlementCurrency = (order) => {
|
|
9414
|
+
const explicit = stringAt(order, ["settlementCurrencyCode"]);
|
|
9415
|
+
if (explicit === "JPY" || explicit === "USD") return explicit;
|
|
9416
|
+
const method = stringAt(order, ["settlementMethodCode"]);
|
|
9417
|
+
if (method === "YEN_SETTLEMENT") return "JPY";
|
|
9418
|
+
if (method === "FOREIGN_SETTLEMENT") return "USD";
|
|
9419
|
+
};
|
|
9420
|
+
/**
|
|
9421
|
+
* Picks the settlement-side amount from a US stock order row. SBI returns
|
|
9422
|
+
* `netAmount` in JPY and `frnNetAmount` in the foreign (trade) currency; only
|
|
9423
|
+
* the side matching the settlement currency is populated.
|
|
9424
|
+
*/
|
|
9425
|
+
const usSettlementSideAmount = (order) => {
|
|
9426
|
+
const currency = usSettlementCurrency(order);
|
|
9427
|
+
if (!currency) return void 0;
|
|
9428
|
+
return currencyAmount(stringAt(order, currency === "JPY" ? ["netAmount"] : ["frnNetAmount"]), currency);
|
|
9429
|
+
};
|
|
9430
|
+
/**
|
|
9431
|
+
* Settlement amount actually paid or received for the executed quantity.
|
|
9432
|
+
* `executionNetAmount` is the JPY-side executed total; there is no foreign
|
|
9433
|
+
* counterpart, so foreign settlement keeps `frnNetAmount`.
|
|
9434
|
+
*/
|
|
9435
|
+
const usSettledAmount = (order) => {
|
|
9436
|
+
const currency = usSettlementCurrency(order);
|
|
9437
|
+
if (!currency) return void 0;
|
|
9438
|
+
return currencyAmount((currency === "JPY" ? stringAt(order, ["executionNetAmount"]) : void 0) || stringAt(order, currency === "JPY" ? ["netAmount"] : ["frnNetAmount"]), currency);
|
|
9439
|
+
};
|
|
9440
|
+
/** Trade-currency contract amount (`frn*` fields are always USD for US stocks). */
|
|
9441
|
+
const usTradeAmount = (order) => usd(stringAt(order, ["frnNetAmount"]) || stringAt(order, ["frnGrossAmount"]));
|
|
9347
9442
|
const orderFromGraphql = (value, extra = {}) => {
|
|
9348
9443
|
const market = extra.issue?.market ?? usMarketFromGraphql(objectAt(value, ["market"]));
|
|
9349
9444
|
const securities = objectAt(value, ["securities"]);
|
|
9350
9445
|
const orderNo = stringAt(value, ["orderNo"]);
|
|
9351
9446
|
const orderSubNo = stringAt(value, ["orderSubNo"]);
|
|
9447
|
+
const executed = numberAt(value, ["executionQuantity"]);
|
|
9448
|
+
const row = value && typeof value === "object" ? value : void 0;
|
|
9352
9449
|
return {
|
|
9353
9450
|
id: orderSubNo ?? orderNo ?? "",
|
|
9354
9451
|
issue: {
|
|
@@ -9361,7 +9458,7 @@ const orderFromGraphql = (value, extra = {}) => {
|
|
|
9361
9458
|
statusText: stringAt(value, ["orderStatus"]),
|
|
9362
9459
|
quantity: numberAt(value, ["orderQuantity"]),
|
|
9363
9460
|
unexecutedQuantity: numberAt(value, ["unexecutedQuantity"]),
|
|
9364
|
-
executedQuantity:
|
|
9461
|
+
executedQuantity: executed,
|
|
9365
9462
|
price: usd(stringAt(value, ["orderPrice"])),
|
|
9366
9463
|
executedPrice: usd(stringAt(value, ["executionAveragePrice"])),
|
|
9367
9464
|
orderedAt: stringAt(value, ["orderInputDatetime"]),
|
|
@@ -9371,7 +9468,9 @@ const orderFromGraphql = (value, extra = {}) => {
|
|
|
9371
9468
|
accountType: mapUsSpecificAccount(stringAt(value, ["specificAccountCode"])),
|
|
9372
9469
|
depositType: mapUsSpecificAccount(stringAt(value, ["specificAccountCode"])),
|
|
9373
9470
|
cancelable: extra.cancelable,
|
|
9374
|
-
correctable: extra.correctable
|
|
9471
|
+
correctable: extra.correctable,
|
|
9472
|
+
settlementCurrency: usSettlementCurrency(row),
|
|
9473
|
+
settledAmount: executed != null && executed > 0 ? usSettledAmount(row) : void 0
|
|
9375
9474
|
};
|
|
9376
9475
|
};
|
|
9377
9476
|
const cashPositionFromUsBalance = (balance, fallbackMarket) => {
|
|
@@ -9464,14 +9563,20 @@ const usOrderCorrectionPreOrderFromOrder = (order, init) => ({
|
|
|
9464
9563
|
const orderUpdatePreviewFromConfirmation = (data, order, options) => {
|
|
9465
9564
|
const confirmation = objectAt(data, ["confirmForeignStockUpdatedOrder"]);
|
|
9466
9565
|
const confirmedOrder = objectAt(confirmation, ["order"]);
|
|
9566
|
+
const settlementCurrency = usSettlementCurrency(confirmedOrder) ?? order.settlementCurrency;
|
|
9567
|
+
const settlementAmount = usSettlementSideAmount(confirmedOrder);
|
|
9467
9568
|
return {
|
|
9468
9569
|
issue: order.issue,
|
|
9469
9570
|
side: order.side,
|
|
9470
9571
|
quantity: options.quantity,
|
|
9471
9572
|
price: usd(stringAt(confirmedOrder, ["orderPrice"]) ?? String(options.price ?? "")),
|
|
9472
|
-
estimatedAmount:
|
|
9473
|
-
|
|
9474
|
-
|
|
9573
|
+
estimatedAmount: settlementAmount,
|
|
9574
|
+
heldAmount: order.side === "buy" ? settlementAmount : void 0,
|
|
9575
|
+
settlementCurrency,
|
|
9576
|
+
tradeAmount: usTradeAmount(confirmedOrder),
|
|
9577
|
+
exchangeRate: stringAt(confirmedOrder, ["exchangeRate"]),
|
|
9578
|
+
commission: currencyAmount(stringAt(confirmedOrder, settlementCurrency === "JPY" ? ["commissionAmount"] : ["frnCommissionAmount"]), settlementCurrency),
|
|
9579
|
+
tax: currencyAmount(stringAt(confirmedOrder, settlementCurrency === "JPY" ? ["commissionCtax"] : ["frnCommissionCtax"]), settlementCurrency),
|
|
9475
9580
|
warnings: stringArrayAt(confirmation, ["warningStatuses"]),
|
|
9476
9581
|
confirmationId: stringAt(confirmedOrder, ["orderSubNo"]) ?? order.orderSubNo,
|
|
9477
9582
|
correction: usOrderCorrectionPreOrderFromOrder(order)
|
|
@@ -9629,9 +9734,9 @@ const mapOrderStatus$1 = (value) => {
|
|
|
9629
9734
|
};
|
|
9630
9735
|
const usMarketFromGraphql = (market, fallback = "XNAS") => {
|
|
9631
9736
|
const code = stringAt(market, ["marketCode"]);
|
|
9632
|
-
if (code === "NASDAQ" || code === "XNAS") return "XNAS";
|
|
9633
|
-
if (code === "NYSE" || code === "XNYS") return "XNYS";
|
|
9634
|
-
if (code === "NYSE_ARCA" || code === "ARCX") return "ARCX";
|
|
9737
|
+
if (code === "NASDAQ" || code === "US_NASDAQ" || code === "XNAS") return "XNAS";
|
|
9738
|
+
if (code === "NYSE" || code === "US_NYSE" || code === "US_AMEX" || code === "XNYS") return "XNYS";
|
|
9739
|
+
if (code === "NYSE_ARCA" || code === "US_ARCA" || code === "ARCX") return "ARCX";
|
|
9635
9740
|
return fallback;
|
|
9636
9741
|
};
|
|
9637
9742
|
const mapUsSpecificAccount = (value) => {
|
|
@@ -9656,6 +9761,11 @@ const usd = (text) => ({
|
|
|
9656
9761
|
text: text?.trim() ?? "",
|
|
9657
9762
|
currency: "USD"
|
|
9658
9763
|
});
|
|
9764
|
+
const currencyAmount = (text, currency) => currency == null ? void 0 : {
|
|
9765
|
+
value: parseNumber$1(text),
|
|
9766
|
+
text: text?.trim() ?? "",
|
|
9767
|
+
currency
|
|
9768
|
+
};
|
|
9659
9769
|
const percent$1 = (text) => ({
|
|
9660
9770
|
value: parseNumber$1(text),
|
|
9661
9771
|
text: text?.trim() ?? ""
|
|
@@ -9786,7 +9896,11 @@ query ConfirmOrderCreating($input: Input_fstock_order_ConfirmForeignStockCreated
|
|
|
9786
9896
|
confirmForeignStockCreatedOrder(input: $input) {
|
|
9787
9897
|
buyPossibleAmount estimatePrice nisaBuyLimitAmount sellPossibleQuantity warningStatuses
|
|
9788
9898
|
order {
|
|
9789
|
-
orderNo orderSubNo orderInputDatetime orderQuantity orderPrice
|
|
9899
|
+
orderNo orderSubNo orderInputDatetime orderQuantity orderPrice
|
|
9900
|
+
settlementMethodCode settlementCurrencyCode tradeCurrencyCode exchangeRate
|
|
9901
|
+
grossAmount frnGrossAmount localCharge frnLocalCharge localNetAmount frnLocalNetAmount
|
|
9902
|
+
commissionAmount frnCommissionAmount commissionCtax frnCommissionCtax
|
|
9903
|
+
netAmount frnNetAmount
|
|
9790
9904
|
securities { securitiesCode securitiesName securitiesShortName }
|
|
9791
9905
|
market { marketCode marketName marketShortName }
|
|
9792
9906
|
}
|
|
@@ -9796,11 +9910,13 @@ const SUBMIT_ORDER = `
|
|
|
9796
9910
|
mutation SubmitOrderCreating($input: Input_fstock_order_CreateForeignStockOrderRequest) {
|
|
9797
9911
|
createForeignStockOrder(input: $input) {
|
|
9798
9912
|
order {
|
|
9799
|
-
orderNo orderSubNo orderInputDatetime orderQuantity orderPrice
|
|
9913
|
+
orderNo orderSubNo orderInputDatetime orderQuantity orderPrice orderStatus
|
|
9914
|
+
settlementMethodCode settlementCurrencyCode tradeCurrencyCode exchangeRate
|
|
9915
|
+
netAmount frnNetAmount
|
|
9800
9916
|
securities { securitiesCode securitiesName securitiesShortName }
|
|
9801
9917
|
market { marketCode marketName marketShortName }
|
|
9802
9918
|
}
|
|
9803
|
-
|
|
9919
|
+
warningStatuses
|
|
9804
9920
|
}
|
|
9805
9921
|
}`;
|
|
9806
9922
|
const ORDER_LIST = `
|
|
@@ -9809,6 +9925,7 @@ query GetOrderList($input: Input_fstock_order_ListForeignStockOrdersRequest) {
|
|
|
9809
9925
|
orderDecodes {
|
|
9810
9926
|
orderNo orderSubNo buySellCode orderStatus orderQuantity unexecutedQuantity executionQuantity
|
|
9811
9927
|
orderPrice executionAveragePrice orderInputDatetime orderTerm specificAccountCode
|
|
9928
|
+
orderPriceKindCode orderLimitCode settlementMethodCode executionStatus
|
|
9812
9929
|
securities { securitiesCode securitiesName securitiesShortName }
|
|
9813
9930
|
market { marketCode marketName marketShortName }
|
|
9814
9931
|
}
|
|
@@ -9823,7 +9940,8 @@ query GetOrderUpdatingInitialData($countryCode: common_enums_CountryEnum_Country
|
|
|
9823
9940
|
orderPriceKindCodes buyPossibleAmount
|
|
9824
9941
|
order {
|
|
9825
9942
|
orderNo orderSubNo buySellCode orderStatus orderQuantity unexecutedQuantity executionQuantity
|
|
9826
|
-
orderPrice executionAveragePrice orderInputDatetime orderTerm
|
|
9943
|
+
orderPrice executionAveragePrice orderInputDatetime orderTerm
|
|
9944
|
+
settlementMethodCode settlementCurrencyCode netAmount frnNetAmount
|
|
9827
9945
|
securities { securitiesCode securitiesName securitiesShortName }
|
|
9828
9946
|
market { marketCode marketName marketShortName }
|
|
9829
9947
|
}
|
|
@@ -9844,7 +9962,10 @@ query ConfirmOrderUpdating($input: Input_fstock_order_ConfirmForeignStockUpdated
|
|
|
9844
9962
|
buyPossibleAmount nisaBuyLimitAmount warningStatuses
|
|
9845
9963
|
order {
|
|
9846
9964
|
orderNo orderSubNo buySellCode orderStatus orderQuantity unexecutedQuantity executionQuantity
|
|
9847
|
-
orderPrice executionAveragePrice orderInputDatetime orderTerm
|
|
9965
|
+
orderPrice executionAveragePrice orderInputDatetime orderTerm
|
|
9966
|
+
settlementMethodCode settlementCurrencyCode tradeCurrencyCode exchangeRate
|
|
9967
|
+
grossAmount frnGrossAmount commissionAmount frnCommissionAmount
|
|
9968
|
+
commissionCtax frnCommissionCtax netAmount frnNetAmount
|
|
9848
9969
|
securities { securitiesCode securitiesName securitiesShortName }
|
|
9849
9970
|
market { marketCode marketName marketShortName }
|
|
9850
9971
|
}
|
|
@@ -9878,6 +9999,17 @@ mutation SubmitOrderCancelling($input: Input_fstock_order_DeleteForeignStockOrde
|
|
|
9878
9999
|
}
|
|
9879
10000
|
}
|
|
9880
10001
|
}`;
|
|
10002
|
+
const ORDER_SETTLEMENT_DETAIL = `
|
|
10003
|
+
query GetOrderSettlementDetail($input: Input_fstock_order_GetForeignStockOrderDetailRequest) {
|
|
10004
|
+
getForeignStockOrderDetail(input: $input) {
|
|
10005
|
+
orderDetail {
|
|
10006
|
+
order {
|
|
10007
|
+
orderNo orderSubNo orderStatus settlementMethodCode settlementCurrencyCode tradeCurrencyCode
|
|
10008
|
+
executionQuantity unexecutedQuantity netAmount frnNetAmount executionNetAmount exchangeRate
|
|
10009
|
+
}
|
|
10010
|
+
}
|
|
10011
|
+
}
|
|
10012
|
+
}`;
|
|
9881
10013
|
const ORDER_DETAIL = `
|
|
9882
10014
|
query GetOrderDetail($input: Input_fstock_order_GetForeignStockOrderDetailRequest, $inputStockSecurities: Input_fstock_securities_GetForeignStockSecuritiesRequest, $inputStockPrice: Input_information_marketprice_ListMarketPricesRequest) {
|
|
9883
10015
|
getForeignStockOrderDetail(input: $input) {
|
|
@@ -9954,6 +10086,7 @@ const DEFAULT_PAGE_INDEX = 0;
|
|
|
9954
10086
|
const DEFAULT_PAGE_LIMIT = 999;
|
|
9955
10087
|
const DEFAULT_MARKET_POLL_INTERVAL_SECONDS = 5;
|
|
9956
10088
|
const DEFAULT_CHART_COUNT = 120;
|
|
10089
|
+
const MTS_TICK_PAGE_MAX = 500;
|
|
9957
10090
|
const CHART_PERIOD_MTS_CODES = {
|
|
9958
10091
|
minute: "1",
|
|
9959
10092
|
day: "2",
|
|
@@ -10013,6 +10146,19 @@ async function* pollMarketIssueBoard(fetchBoard, options) {
|
|
|
10013
10146
|
}
|
|
10014
10147
|
if (options.signal?.aborted) throw abortError(options.signal);
|
|
10015
10148
|
}
|
|
10149
|
+
async function* pollMarketIssueTicks(fetchTicks, options) {
|
|
10150
|
+
const intervalMs = pollingIntervalMs(options.intervalSeconds);
|
|
10151
|
+
if ("cursor" in options && options.cursor != null) throw new Error("market.issue.pollTicks does not accept cursor; use afterCursor instead");
|
|
10152
|
+
const normalized = normalizedIssueTicksOptions(options);
|
|
10153
|
+
let afterCursor = normalized.afterSequenceNumber ? encodeAfterTickCursor(normalized.afterSequenceNumber) : void 0;
|
|
10154
|
+
while (!options.signal?.aborted) {
|
|
10155
|
+
const batch = await fetchTicks(afterCursor);
|
|
10156
|
+
if (batch.latestCursor) afterCursor = batch.latestCursor;
|
|
10157
|
+
yield batch;
|
|
10158
|
+
await waitForPollingInterval(intervalMs, options.signal);
|
|
10159
|
+
}
|
|
10160
|
+
if (options.signal?.aborted) throw abortError(options.signal);
|
|
10161
|
+
}
|
|
10016
10162
|
const debugMts = (label, value) => {
|
|
10017
10163
|
if (process.env.SBI_CLIENT_DEBUG_MTS !== "1") return;
|
|
10018
10164
|
console.error(`[sbi-client:mts] ${label}`, JSON.stringify(value, null, 2));
|
|
@@ -10088,6 +10234,14 @@ const createMethodsFromSession = (session) => {
|
|
|
10088
10234
|
board: async (options) => isUsMarket(options.market) ? usStock.board(options) : parseBoardLike(await callMts(session, "F1207", issueTrin(options)), options),
|
|
10089
10235
|
pollBoard: (options) => pollMarketIssueBoard(async () => isUsMarket(options.market) ? usStock.board(options) : parseBoardLike(await callMts(session, "F1207", issueTrin(options)), options), options),
|
|
10090
10236
|
chart: async (options) => isUsMarket(options.market) ? usStock.chart(options) : parseIssueChart(await callMtsReturningHeaderError(session, "F1851", issueChartTrin(options)), options),
|
|
10237
|
+
ticks: async (options) => rejectUsMarket(options, "market.issue.ticks") ?? parseIssueTicks(await callMts(session, "F1802", issueTicksTrin(options, "market.issue.ticks")), options, "market.issue.ticks"),
|
|
10238
|
+
pollTicks: (options) => pollMarketIssueTicks(async (afterCursor) => rejectUsMarket(options, "market.issue.pollTicks") ?? parseIssueTicks(await callMts(session, "F1802", issueTicksTrin({
|
|
10239
|
+
...options,
|
|
10240
|
+
afterCursor
|
|
10241
|
+
}, "market.issue.pollTicks")), {
|
|
10242
|
+
...options,
|
|
10243
|
+
afterCursor
|
|
10244
|
+
}, "market.issue.pollTicks"), options),
|
|
10091
10245
|
openOrders: async (options) => isUsMarket(options.market) ? usStock.openOrders(options) : parseOrdersLoose(await callMtsReturningHeaderError(session, "F2504", openOrdersTrin(session, options)), options),
|
|
10092
10246
|
tradingInfo: async (options) => isUsMarket(options.market) ? usStock.tradingInfo(options) : parseBoardLike(await callMts(session, tradingInfoTrCode(options), tradingInfoTrin(session, options)), options)
|
|
10093
10247
|
},
|
|
@@ -10111,7 +10265,19 @@ const createMethodsFromSession = (session) => {
|
|
|
10111
10265
|
orders: {
|
|
10112
10266
|
inquiry: {
|
|
10113
10267
|
executionsToday: async (options) => options?.market && isUsMarket(options.market) ? usStock.orders(options) : parseOrdersLoose(await callMtsReturningHeaderError(session, "F2503", orderInquiryTrin(session, options)), options),
|
|
10114
|
-
open: async (options) =>
|
|
10268
|
+
open: async (options) => {
|
|
10269
|
+
if (options?.market && isUsMarket(options.market)) return usStock.orders(options);
|
|
10270
|
+
const domestic = parseOrdersLoose(await callMtsReturningHeaderError(session, "F2511", recentOrdersTrin(session, options)), options);
|
|
10271
|
+
if (options?.market || !session.foreignStock) return domestic;
|
|
10272
|
+
const us = await usStock.orders({
|
|
10273
|
+
issueCode: options?.issueCode,
|
|
10274
|
+
status: options?.status ?? "open"
|
|
10275
|
+
});
|
|
10276
|
+
return {
|
|
10277
|
+
...domestic,
|
|
10278
|
+
orders: [...domestic.orders, ...us.orders]
|
|
10279
|
+
};
|
|
10280
|
+
},
|
|
10115
10281
|
detail: async (options) => {
|
|
10116
10282
|
if (isUsMarket(options.market)) return usStock.orderDetail(options);
|
|
10117
10283
|
throw new Error("orders.inquiry.detail is currently implemented only for US stock markets");
|
|
@@ -11661,6 +11827,58 @@ const parseIssueChart = (response, options) => {
|
|
|
11661
11827
|
latestDateTime
|
|
11662
11828
|
};
|
|
11663
11829
|
};
|
|
11830
|
+
const formatTickTime = (value) => /^\d{4}$/.test(value) ? `${value.slice(0, 2)}:${value.slice(2, 4)}` : value;
|
|
11831
|
+
const encodeBeforeTickCursor = (sequenceNumber) => `before:${sequenceNumber}`;
|
|
11832
|
+
const encodeAfterTickCursor = (sequenceNumber) => `after:${sequenceNumber}`;
|
|
11833
|
+
const hasOlderTicksAfterIncremental = (oldestSequenceNumber, afterSequenceNumber) => {
|
|
11834
|
+
if (/^\d+$/.test(oldestSequenceNumber) && /^\d+$/.test(afterSequenceNumber)) return BigInt(oldestSequenceNumber) > BigInt(afterSequenceNumber) + 1n;
|
|
11835
|
+
return true;
|
|
11836
|
+
};
|
|
11837
|
+
const parseIssueTicks = (response, options, methodName = "market.issue.ticks") => {
|
|
11838
|
+
const { afterSequenceNumber, limit } = normalizedIssueTicksOptions(options);
|
|
11839
|
+
if (response.buffer.length <= MTS_HEADER_BYTES) return {
|
|
11840
|
+
issue: {
|
|
11841
|
+
code: options.issueCode,
|
|
11842
|
+
market: options.market
|
|
11843
|
+
},
|
|
11844
|
+
items: []
|
|
11845
|
+
};
|
|
11846
|
+
const reader = readerFor(response);
|
|
11847
|
+
const code = reader.text(5);
|
|
11848
|
+
const market = reader.text(3);
|
|
11849
|
+
const recordCount = reader.int(4) ?? 0;
|
|
11850
|
+
const rawTicks = [];
|
|
11851
|
+
for (let i = 0; i < recordCount && reader.remaining >= 35; i++) {
|
|
11852
|
+
const sequenceNumber = reader.text(8);
|
|
11853
|
+
const time = formatTickTime(reader.text(4));
|
|
11854
|
+
const price = yen(reader.text(11));
|
|
11855
|
+
reader.skip(1);
|
|
11856
|
+
const volume = parseNumber(reader.text(11));
|
|
11857
|
+
if (!sequenceNumber && price.value == null) continue;
|
|
11858
|
+
rawTicks.push({
|
|
11859
|
+
sequenceNumber,
|
|
11860
|
+
time,
|
|
11861
|
+
price,
|
|
11862
|
+
volume
|
|
11863
|
+
});
|
|
11864
|
+
}
|
|
11865
|
+
const items = limit != null ? rawTicks.slice(0, limit) : rawTicks;
|
|
11866
|
+
const latestSequenceNumber = emptyToUndefined$1(items[0]?.sequenceNumber);
|
|
11867
|
+
const oldestSequenceNumber = emptyToUndefined$1(items[items.length - 1]?.sequenceNumber);
|
|
11868
|
+
const atOpeningTick = oldestSequenceNumber != null && /^0+$/.test(oldestSequenceNumber);
|
|
11869
|
+
const truncatedByLimit = limit != null && rawTicks.length > limit;
|
|
11870
|
+
const nextCursor = oldestSequenceNumber != null && !atOpeningTick && (truncatedByLimit || rawTicks.length >= MTS_TICK_PAGE_MAX && (afterSequenceNumber == null || hasOlderTicksAfterIncremental(oldestSequenceNumber, afterSequenceNumber))) && oldestSequenceNumber ? encodeBeforeTickCursor(oldestSequenceNumber) : void 0;
|
|
11871
|
+
const latestCursor = latestSequenceNumber ? encodeAfterTickCursor(latestSequenceNumber) : void 0;
|
|
11872
|
+
return {
|
|
11873
|
+
issue: {
|
|
11874
|
+
code: emptyToUndefined$1(code) ?? options.issueCode,
|
|
11875
|
+
market: publicDomesticMarket(market, methodName) ?? options.market
|
|
11876
|
+
},
|
|
11877
|
+
items,
|
|
11878
|
+
...nextCursor ? { nextCursor } : {},
|
|
11879
|
+
...latestCursor ? { latestCursor } : {}
|
|
11880
|
+
};
|
|
11881
|
+
};
|
|
11664
11882
|
const parseBoardResponse = (response, options) => {
|
|
11665
11883
|
const reader = readerFor(response);
|
|
11666
11884
|
const code = reader.text(5);
|
|
@@ -13034,6 +13252,51 @@ const issueChartTrin = (options) => {
|
|
|
13034
13252
|
}
|
|
13035
13253
|
]);
|
|
13036
13254
|
};
|
|
13255
|
+
const parseTickCursor = (value, expectedDirection, fieldName) => {
|
|
13256
|
+
const trimmed = value?.trim();
|
|
13257
|
+
if (!trimmed) return void 0;
|
|
13258
|
+
const match = /^(before|after):(\S+)$/.exec(trimmed);
|
|
13259
|
+
if (!match) throw new Error(`${fieldName} must be a valid tick cursor`);
|
|
13260
|
+
const [, direction, sequenceNumber] = match;
|
|
13261
|
+
if (direction !== expectedDirection) throw new Error(expectedDirection === "before" ? "cursor expects a nextCursor token; pass latestCursor to afterCursor instead" : "afterCursor expects a latestCursor token; pass nextCursor to cursor instead");
|
|
13262
|
+
if (!sequenceNumber || sequenceNumber.length > 8) throw new Error(`${fieldName} sequence number must be at most 8 non-whitespace characters`);
|
|
13263
|
+
return sequenceNumber;
|
|
13264
|
+
};
|
|
13265
|
+
const normalizedIssueTicksOptions = (options) => {
|
|
13266
|
+
const beforeSequenceNumber = parseTickCursor(options.cursor, "before", "cursor");
|
|
13267
|
+
const afterSequenceNumber = parseTickCursor(options.afterCursor, "after", "afterCursor");
|
|
13268
|
+
if (beforeSequenceNumber && afterSequenceNumber) throw new Error("cursor and afterCursor cannot be used together");
|
|
13269
|
+
const limit = options.limit;
|
|
13270
|
+
if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) throw new Error("limit must be a positive integer");
|
|
13271
|
+
return {
|
|
13272
|
+
beforeSequenceNumber,
|
|
13273
|
+
afterSequenceNumber,
|
|
13274
|
+
limit
|
|
13275
|
+
};
|
|
13276
|
+
};
|
|
13277
|
+
const issueTicksTrin = (options, methodName = "market.issue.ticks") => {
|
|
13278
|
+
const { beforeSequenceNumber, afterSequenceNumber } = normalizedIssueTicksOptions(options);
|
|
13279
|
+
const sequenceNumber = beforeSequenceNumber ?? afterSequenceNumber ?? "";
|
|
13280
|
+
const directionFlag = beforeSequenceNumber ? "A" : "D";
|
|
13281
|
+
return fixedTrin([
|
|
13282
|
+
{
|
|
13283
|
+
width: 5,
|
|
13284
|
+
value: options.issueCode
|
|
13285
|
+
},
|
|
13286
|
+
{
|
|
13287
|
+
width: 3,
|
|
13288
|
+
value: domesticMarketToMts(options.market, methodName)
|
|
13289
|
+
},
|
|
13290
|
+
{
|
|
13291
|
+
width: 8,
|
|
13292
|
+
value: sequenceNumber
|
|
13293
|
+
},
|
|
13294
|
+
{
|
|
13295
|
+
width: 1,
|
|
13296
|
+
value: directionFlag
|
|
13297
|
+
}
|
|
13298
|
+
]);
|
|
13299
|
+
};
|
|
13037
13300
|
const newsListTrin = () => fixedTrin([
|
|
13038
13301
|
{
|
|
13039
13302
|
width: 3,
|
|
@@ -15411,6 +15674,7 @@ const priceCondition = (request) => {
|
|
|
15411
15674
|
const cashOrderInput = (request) => {
|
|
15412
15675
|
if (request.amount) throw new Error("SBI Securities does not support amount-specified orders");
|
|
15413
15676
|
const market = sbiMarket(request.execution?.venue, "execution.venue");
|
|
15677
|
+
if (request.settlementMethod && !isUsMarket(market)) throw new Error("settlementMethod is supported only for US stock orders");
|
|
15414
15678
|
const quantity = finiteNumber(request.quantity, "quantity");
|
|
15415
15679
|
const accountType = sbiAccountType(request.accountType);
|
|
15416
15680
|
const isSKabu = market === "STK";
|
|
@@ -15420,7 +15684,8 @@ const cashOrderInput = (request) => {
|
|
|
15420
15684
|
side: request.side,
|
|
15421
15685
|
quantity,
|
|
15422
15686
|
accountType,
|
|
15423
|
-
depositType: accountType
|
|
15687
|
+
depositType: accountType,
|
|
15688
|
+
foreignStockSettlementMethod: request.settlementMethod
|
|
15424
15689
|
};
|
|
15425
15690
|
if (isSKabu) {
|
|
15426
15691
|
if (request.execution?.priceType !== "market" || request.execution.limitPrice) throw new Error("S-kabu supports market orders only");
|
|
@@ -15464,22 +15729,28 @@ const ifdOrderInput = (request) => {
|
|
|
15464
15729
|
ifdPrice: request.strategy.exit.limitPrice ? finiteNumber(request.strategy.exit.limitPrice.value, "strategy.exit.limitPrice.value") : void 0
|
|
15465
15730
|
};
|
|
15466
15731
|
};
|
|
15467
|
-
const commonPreview = (preview, request) =>
|
|
15468
|
-
|
|
15469
|
-
|
|
15470
|
-
|
|
15471
|
-
|
|
15472
|
-
|
|
15473
|
-
|
|
15732
|
+
const commonPreview = (preview, request) => {
|
|
15733
|
+
const heldAmount = money(preview.heldAmount) ?? money(preview.estimatedAmount);
|
|
15734
|
+
return {
|
|
15735
|
+
estimatedAmount: money(preview.estimatedAmount),
|
|
15736
|
+
tradeAmount: money(preview.tradeAmount),
|
|
15737
|
+
heldAmount,
|
|
15738
|
+
settlementCurrency: preview.settlementCurrency,
|
|
15739
|
+
warnings: [...preview.warnings, ...preview.message ? [preview.message] : []],
|
|
15740
|
+
confirmationToken: preview.confirmationId,
|
|
15741
|
+
projectedAssetChanges: orderReservationChanges(request, heldAmount)
|
|
15742
|
+
};
|
|
15743
|
+
};
|
|
15744
|
+
const orderReservationChanges = (request, heldAmount) => {
|
|
15474
15745
|
if (request.side === "buy") {
|
|
15475
|
-
if (!
|
|
15746
|
+
if (!heldAmount) throw new Error("provider did not return the settlement order amount");
|
|
15476
15747
|
return [{
|
|
15477
15748
|
asset: {
|
|
15478
15749
|
kind: "cash",
|
|
15479
|
-
currency:
|
|
15750
|
+
currency: heldAmount.currency
|
|
15480
15751
|
},
|
|
15481
|
-
availableDelta: `-${
|
|
15482
|
-
reservedDelta:
|
|
15752
|
+
availableDelta: `-${heldAmount.value}`,
|
|
15753
|
+
reservedDelta: heldAmount.value,
|
|
15483
15754
|
pendingDelta: "0"
|
|
15484
15755
|
}];
|
|
15485
15756
|
}
|
|
@@ -15587,6 +15858,7 @@ const commonOrder = (order, accountId) => ({
|
|
|
15587
15858
|
statusText: order.statusText,
|
|
15588
15859
|
cancelable: order.cancelable,
|
|
15589
15860
|
correctable: order.correctable,
|
|
15861
|
+
settlementCurrency: order.settlementCurrency,
|
|
15590
15862
|
accountInformation: order.accountInformation
|
|
15591
15863
|
});
|
|
15592
15864
|
const commonCashPosition = (position, accountId) => ({
|
|
@@ -15649,7 +15921,6 @@ const orderEffects = (order) => {
|
|
|
15649
15921
|
if (!order.id) return void 0;
|
|
15650
15922
|
const executed = order.executedQuantity ?? 0;
|
|
15651
15923
|
const unexecuted = order.status === "executed" || order.status === "cancelled" || order.status === "expired" || order.status === "rejected" ? 0 : order.unexecutedQuantity ?? Math.max((order.quantity ?? 0) - executed, 0);
|
|
15652
|
-
const fees = (order.commission?.value ?? 0) + (order.tax?.value ?? 0);
|
|
15653
15924
|
const security = {
|
|
15654
15925
|
kind: "security",
|
|
15655
15926
|
instrumentId: order.issue.code,
|
|
@@ -15657,11 +15928,61 @@ const orderEffects = (order) => {
|
|
|
15657
15928
|
positionType: "cash",
|
|
15658
15929
|
...order.accountType ? { accountType: order.accountType } : {}
|
|
15659
15930
|
};
|
|
15931
|
+
const changes = [];
|
|
15932
|
+
if (order.settlementCurrency) {
|
|
15933
|
+
const cash = {
|
|
15934
|
+
kind: "cash",
|
|
15935
|
+
currency: order.settlementCurrency
|
|
15936
|
+
};
|
|
15937
|
+
if (executed > 0 && unexecuted > 0) return void 0;
|
|
15938
|
+
if (order.side === "buy") {
|
|
15939
|
+
const reserved = unexecuted > 0 ? order.heldAmount?.value : 0;
|
|
15940
|
+
const spent = executed > 0 ? order.settledAmount?.value : 0;
|
|
15941
|
+
if (reserved == null || spent == null) return void 0;
|
|
15942
|
+
if (reserved + spent > 0) changes.push({
|
|
15943
|
+
asset: cash,
|
|
15944
|
+
availableDelta: `-${reserved + spent}`,
|
|
15945
|
+
reservedDelta: String(reserved),
|
|
15946
|
+
pendingDelta: "0"
|
|
15947
|
+
});
|
|
15948
|
+
if (executed > 0) changes.push({
|
|
15949
|
+
asset: security,
|
|
15950
|
+
availableDelta: String(executed),
|
|
15951
|
+
reservedDelta: "0",
|
|
15952
|
+
pendingDelta: "0"
|
|
15953
|
+
});
|
|
15954
|
+
return {
|
|
15955
|
+
referenceId: order.id,
|
|
15956
|
+
changes
|
|
15957
|
+
};
|
|
15958
|
+
}
|
|
15959
|
+
const total = executed + unexecuted;
|
|
15960
|
+
if (total > 0) changes.push({
|
|
15961
|
+
asset: security,
|
|
15962
|
+
availableDelta: `-${total}`,
|
|
15963
|
+
reservedDelta: String(unexecuted),
|
|
15964
|
+
pendingDelta: "0"
|
|
15965
|
+
});
|
|
15966
|
+
if (executed > 0) {
|
|
15967
|
+
const settled = order.settledAmount?.value;
|
|
15968
|
+
if (settled == null) return void 0;
|
|
15969
|
+
changes.push({
|
|
15970
|
+
asset: cash,
|
|
15971
|
+
availableDelta: String(settled),
|
|
15972
|
+
reservedDelta: "0",
|
|
15973
|
+
pendingDelta: "0"
|
|
15974
|
+
});
|
|
15975
|
+
}
|
|
15976
|
+
return {
|
|
15977
|
+
referenceId: order.id,
|
|
15978
|
+
changes
|
|
15979
|
+
};
|
|
15980
|
+
}
|
|
15981
|
+
const fees = (order.commission?.value ?? 0) + (order.tax?.value ?? 0);
|
|
15660
15982
|
const cash = {
|
|
15661
15983
|
kind: "cash",
|
|
15662
15984
|
currency: "JPY"
|
|
15663
15985
|
};
|
|
15664
|
-
const changes = [];
|
|
15665
15986
|
if (order.side === "buy") {
|
|
15666
15987
|
const reserved = unexecuted > 0 ? order.price?.value == null ? void 0 : unexecuted * order.price.value : 0;
|
|
15667
15988
|
const spent = executed > 0 ? order.executedPrice?.value == null ? void 0 : executed * order.executedPrice.value + fees : 0;
|
|
@@ -15778,6 +16099,7 @@ const createProviderFromClient = (client) => {
|
|
|
15778
16099
|
"investments.orders.cancel",
|
|
15779
16100
|
"market.index.major",
|
|
15780
16101
|
"market.issue.chart",
|
|
16102
|
+
"market.issue.ticks",
|
|
15781
16103
|
"market.issue.search",
|
|
15782
16104
|
"market.issue.suggest",
|
|
15783
16105
|
"market.issue.board"
|
|
@@ -15859,6 +16181,7 @@ const createProviderFromClient = (client) => {
|
|
|
15859
16181
|
invoke: async (name, request) => {
|
|
15860
16182
|
if (name === "market.index.major") return await client.market.index.major();
|
|
15861
16183
|
if (name === "market.issue.chart") return await client.market.issue.chart(request);
|
|
16184
|
+
if (name === "market.issue.ticks") return await client.market.issue.ticks(request);
|
|
15862
16185
|
if (name === "market.issue.search") return await client.market.issue.search(request);
|
|
15863
16186
|
if (name === "market.issue.suggest") return await client.market.issue.suggest(request);
|
|
15864
16187
|
if (name === "market.issue.board") return await client.market.issue.board(request);
|
|
@@ -15961,13 +16284,14 @@ const createProviderFromClient = (client) => {
|
|
|
15961
16284
|
return result;
|
|
15962
16285
|
}
|
|
15963
16286
|
const placement = input;
|
|
16287
|
+
const usMarket = "market" in options && isUsMarket(options.market);
|
|
15964
16288
|
const receipt = input.strategy?.kind === "ifd" ? await client.orders.ifd.place({
|
|
15965
16289
|
...options,
|
|
15966
16290
|
confirmationId: placement.confirmationToken,
|
|
15967
16291
|
allowTrading: true
|
|
15968
16292
|
}) : await client.orders.cash.place({
|
|
15969
16293
|
...options,
|
|
15970
|
-
confirmationId: placement.confirmationToken,
|
|
16294
|
+
confirmationId: usMarket ? void 0 : placement.confirmationToken,
|
|
15971
16295
|
allowTrading: true
|
|
15972
16296
|
});
|
|
15973
16297
|
const result = commonReceipt(input, receipt, currentAccount.id);
|
|
@@ -16152,12 +16476,13 @@ const createProviderFromClient = (client) => {
|
|
|
16152
16476
|
const hydrated = mergeExecutionDetails(order, execution);
|
|
16153
16477
|
return withOrderEffects(commonOrder(hydrated, currentAccount.id), hydrated);
|
|
16154
16478
|
}
|
|
16155
|
-
|
|
16479
|
+
const detail = await client.orders.inquiry.detail({
|
|
16156
16480
|
orderNumber: source?.orderNumber,
|
|
16157
16481
|
orderId: source?.orderSubNo ?? source?.id ?? input.orderId,
|
|
16158
16482
|
issueCode: source?.issue.code ?? input.instrumentId,
|
|
16159
16483
|
market
|
|
16160
|
-
})
|
|
16484
|
+
});
|
|
16485
|
+
return withOrderEffects(commonOrder(detail, currentAccount.id), detail);
|
|
16161
16486
|
}
|
|
16162
16487
|
if (name === "investments.trades.list") {
|
|
16163
16488
|
const input = request;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mnie/provider-sbi-sec",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,16 +23,9 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@mnie/types": "0.
|
|
26
|
+
"@mnie/types": "^0.1.0",
|
|
27
27
|
"iconv-lite": "^0.7.2"
|
|
28
28
|
},
|
|
29
|
-
"devDependencies": {
|
|
30
|
-
"@repo/tsconfig": "0.0.0",
|
|
31
|
-
"@types/bun": "latest"
|
|
32
|
-
},
|
|
33
|
-
"peerDependencies": {
|
|
34
|
-
"typescript": "^5"
|
|
35
|
-
},
|
|
36
29
|
"scripts": {
|
|
37
30
|
"build": "cd ../.. && vp run @mnie/types#build && cd packages/provider-sbi-sec && vp pack",
|
|
38
31
|
"dev": "vp pack --watch --no-clean",
|