Skip to content

Commit

Permalink
More enums and enforce typing
Browse files Browse the repository at this point in the history
  • Loading branch information
rylorin committed Sep 22, 2023
1 parent b43d599 commit 09522ab
Show file tree
Hide file tree
Showing 25 changed files with 210 additions and 91 deletions.
15 changes: 8 additions & 7 deletions src/api-next/api-next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
ScannerSubscription,
SecType,
TagValue,
WhatToShow,
} from "../";
import LogLevel from "../api/data/enum/log-level";
import OrderStatus from "../api/order/enum/order-status";
Expand Down Expand Up @@ -491,7 +492,7 @@ export class IBApiNext {
* - AccruedCash — Total accrued cash value of stock, commodities and securities
* - BuyingPower — Buying power serves as a measurement of the dollar value of securities that one may purchase in a securities account without depositing additional funds
* - EquityWithLoanValue — Forms the basis for determining whether a client has the necessary assets to either initiate or maintain security positions. Cash + stocks + bonds + mutual funds
* - PreviousEquityWithLoanValue — Marginable Equity with Loan value as of 16:00 ET the previous day
* - PreviousDayEquityWithLoanValue — Marginable Equity with Loan value as of 16:00 ET the previous day
* - GrossPositionValue — The sum of the absolute value of all stock and equity option positions
* - RegTEquity — Regulation T equity for universal account
* - RegTMargin — Regulation T margin for universal account
Expand Down Expand Up @@ -1617,7 +1618,7 @@ export class IBApiNext {
*/
getHeadTimestamp(
contract: Contract,
whatToShow: string,
whatToShow: WhatToShow,
useRTH: boolean,
formatDate: number,
): Promise<string> {
Expand Down Expand Up @@ -1754,7 +1755,7 @@ export class IBApiNext {
endDateTime: string | undefined,
durationStr: string,
barSizeSetting: BarSizeSetting,
whatToShow: string,
whatToShow: WhatToShow,
useRTH: number,
formatDate: number,
): Promise<Bar[]> {
Expand Down Expand Up @@ -1858,7 +1859,7 @@ export class IBApiNext {
getHistoricalDataUpdates(
contract: Contract,
barSizeSetting: BarSizeSetting,
whatToShow: string,
whatToShow: WhatToShow,
formatDate: number,
): Observable<Bar> {
return this.subscriptions
Expand Down Expand Up @@ -1943,7 +1944,7 @@ export class IBApiNext {
startDateTime,
endDateTime,
numberOfTicks,
"MIDPOINT",
WhatToShow.MIDPOINT,
useRTH,
false,
);
Expand Down Expand Up @@ -2013,7 +2014,7 @@ export class IBApiNext {
startDateTime,
endDateTime,
numberOfTicks,
"BID_ASK",
WhatToShow.BID_ASK,
useRTH,
ignoreSize,
);
Expand Down Expand Up @@ -2079,7 +2080,7 @@ export class IBApiNext {
startDateTime,
endDateTime,
numberOfTicks,
"TRADES",
WhatToShow.TRADES,
useRTH,
false,
);
Expand Down
10 changes: 5 additions & 5 deletions src/api-next/market-scanner/market-scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ export type MarketScannerUpdate = ItemListUpdate<MarketScannerRows>;
export enum LocationCode {
BOND_US = "BOND.US",
EFP = "EFP",
FUT_ECBOT = "FUT.ECBOT",
// FUT_ECBOT = "FUT.ECBOT",
FUT_EU_BELFOX = "FUT.EU.BELFOX",
FUT_EU_DTB = "FUT.EU.DTB",
// FUT_EU_DTB = "FUT.EU.DTB",
FUT_EU_FTA = "FUT.EU.FTA",
FUT_EU_IDEM = "FUT.EU.IDEM",
FUT_EU_LIFFE = "FUT.EU.LIFFE",
FUT_EU_MEFFRV = "FUT.EU.MEFFRV",
FUT_EU_MONEP = "FUT.EU.MONEP",
FUT_EU = "FUT.EU",
FUT_GLOBEX = "FUT.GLOBEX",
// FUT_GLOBEX = "FUT.GLOBEX",
FUT_HK_HKFE = "FUT.HK.HKFE",
FUT_HK_JAPAN = "FUT.HK.JAPAN",
FUT_HK_KSE = "FUT.HK.KSE",
Expand All @@ -42,11 +42,11 @@ export enum LocationCode {
FUT_NA_CDE = "FUT.NA.CDE",
FUT_NA = "FUT.NA",
FUT_NYBOT = "FUT.NYBOT",
FUT_NYMEX = "FUT.NYMEX",
// FUT_NYMEX = "FUT.NYMEX",
FUT_NYSELIFFE = "FUT.NYSELIFFE",
FUT_US = "FUT.US",
IND_EU_BELFOX = "IND.EU.BELFOX",
IND_EU_DTB = "IND.EU.DTB",
// IND_EU_DTB = "IND.EU.DTB",
IND_EU_FTA = "IND.EU.FTA",
IND_EU_LIFFE = "IND.EU.LIFFE",
IND_EU_MONEP = "IND.EU.MONEP",
Expand Down
14 changes: 7 additions & 7 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
/* eslint @typescript-eslint/no-unsafe-declaration-merging:warn */
import { EventEmitter } from "eventemitter3";
import { DurationUnit } from "..";
import { DurationUnit, WhatToShow } from "..";

import { ErrorCode } from "../common/errorCode";
import { Controller } from "../core/io/controller";
Expand Down Expand Up @@ -575,7 +575,7 @@ export class IBApi extends EventEmitter {
* securities account without depositing additional funds
* - EquityWithLoanValue — Forms the basis for determining whether a client has the necessary assets to either
* initiate or maintain security positions. Cash + stocks + bonds + mutual funds
* - PreviousEquityWithLoanValue — Marginable Equity with Loan value as of 16:00 ET the previous day
* - PreviousDayEquityWithLoanValue — Marginable Equity with Loan value as of 16:00 ET the previous day
* - GrossPositionValue — The sum of the absolute value of all stock and equity option positions
* - RegTEquity — Regulation T equity for universal account
* - RegTMargin — Regulation T margin for universal account
Expand Down Expand Up @@ -869,7 +869,7 @@ export class IBApi extends EventEmitter {
reqHeadTimestamp(
reqId: number,
contract: Contract,
whatToShow: string,
whatToShow: WhatToShow,
useRTH: boolean,
formatDate: number,
): IBApi {
Expand Down Expand Up @@ -968,7 +968,7 @@ export class IBApi extends EventEmitter {
endDateTime: string,
durationStr: string,
barSizeSetting: BarSizeSetting,
whatToShow: string,
whatToShow: WhatToShow,
useRTH: number,
formatDate: number,
keepUpToDate: boolean,
Expand Down Expand Up @@ -1040,7 +1040,7 @@ export class IBApi extends EventEmitter {
startDateTime: string,
endDateTime: string,
numberOfTicks: number,
whatToShow: string,
whatToShow: WhatToShow,
useRTH: number,
ignoreSize: boolean,
): IBApi {
Expand Down Expand Up @@ -1378,7 +1378,7 @@ export class IBApi extends EventEmitter {
reqId: number,
contract: Contract,
barSize: number,
whatToShow: string,
whatToShow: WhatToShow,
useRTH: boolean,
realTimeBarsOptions: TagValue[] = [],
): IBApi {
Expand Down Expand Up @@ -1758,7 +1758,7 @@ export declare interface IBApi {
* securities account without depositing additional funds.
* - EquityWithLoanValue: Forms the basis for determining whether a client has the necessary assets to either
* initiate or maintain security positions. Cash + stocks + bonds + mutual funds
* - PreviousEquityWithLoanValue: Marginable Equity with Loan value as of 16:00 ET the previous day
* - PreviousDayEquityWithLoanValue: Marginable Equity with Loan value as of 16:00 ET the previous day
* - GrossPositionValue: The sum of the absolute value of all stock and equity option positions
* - RegTEquity:Regulation T equity for universal account
* - RegTMargin. Regulation T margin for universal account
Expand Down
46 changes: 32 additions & 14 deletions src/api/data/enum/sec-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,53 @@ export enum SecType {
/* Future */
FUT = "FUT",

/* Index. */
IND = "IND",
CONTFUT = "CONTFUT",

/** Futures option. */
FOP = "FOP",
/** Forex pair. */
CASH = "CASH",

/** Bond. */
BOND = "BOND",

/** Contract for Difference. */
CFD = "CFD",

/** Forex pair. */
CASH = "CASH",
/** Futures option. */
FOP = "FOP",

/** Warrant. */
WAR = "WAR",

IOPT = "IOPT",

FWD = "FWD",

/** Combo. */
BAG = "BAG",

/** Warrant. */
WAR = "WAR",
/* Index. */
IND = "IND",

/** Bond. */
BOND = "BOND",
BILL = "BILL",

/** Commodity. */
CMDTY = "CMDTY",
/** Mutual fund. */
FUND = "FUND",

FIXED = "FIXED",

SLB = "SLB",

/** News. */
NEWS = "NEWS",

/** Mutual fund. */
FUND = "FUND",
/** Commodity. */
CMDTY = "CMDTY",

BSK = "BSK",

ICU = "ICU",

ICS = "ICS",

/** Cryptocurrency. */
CRYPTO = "CRYPTO ",
Expand Down
24 changes: 24 additions & 0 deletions src/api/historical/what-to-show.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* WhatToShow.
*/

export const WhatToShow = {
None: "",

// only these are valid for real-time bars
TRADES: "TRADES",
MIDPOINT: "MIDPOINT",
BID: "BID",
ASK: "ASK",

BID_ASK: "BID_ASK",
HISTORICAL_VOLATILITY: "HISTORICAL_VOLATILITY",
OPTION_IMPLIED_VOLATILITY: "OPTION_IMPLIED_VOLATILITY",
YIELD_ASK: "YIELD_ASK",
YIELD_BID: "YIELD_BID",
YIELD_BID_ASK: "YIELD_BID_ASK",
YIELD_LAST: "YIELD_LAST",
ADJUSTED_LAST: "ADJUSTED_LAST",
SCHEDULE: "SCHEDULE",
} as const;
export type WhatToShow = (typeof WhatToShow)[keyof typeof WhatToShow];
4 changes: 4 additions & 0 deletions src/api/market/tickType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ export enum TickType {
/** Number of shares available to short (TWS Build 974+ is required) */
SHORTABLE_SHARES = 89,

DELAYED_HALTED = 90,

REUTERS_2_MUTUAL_FUNDS = 91,

/**
* Today's closing price of ETF's Net Asset Value (NAV).
* Calculation is based on prices of ETF's underlying securities.
Expand Down
2 changes: 1 addition & 1 deletion src/api/order/enum/orderType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export enum OrderType {
MTL = "MTL",
PASSV_REL = "PASSV REL",
PEG_BENCH = "PEG BENCH",
PEG_BEST = "PEG BEST",
PEG_MID = "PEG MID",
PEG_MKT = "PEG MKT",
PEG_PRIM = "PEG PRIM",
PEG_STK = "PEG STK",
PEG_BEST = "PEG BEST",
REL_PLUS_LMT = "REL + LMT",
REL_PLUS_MKT = "REL + MKT",
SNAP_MID = "SNAP MID",
Expand Down
18 changes: 18 additions & 0 deletions src/api/order/enum/tif.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Time in Force.
*/

export const TimeInForce = {
DAY: "DAY",
GTC: "GTC",
OPG: "OPG",
IOC: "IOC",
GTD: "GTD",
GTT: "GTT",
AUC: "AUC",
FOK: "FOK",
GTX: "GTX",
DTC: "DTC",
Minutes: "Minutes",
} as const;
export type TimeInForce = (typeof TimeInForce)[keyof typeof TimeInForce];
11 changes: 6 additions & 5 deletions src/api/order/order.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import SoftDollarTier from "../data/container/soft-dollar-tier";
import TagValue from "../data/container/tag-value";
import OrderCondition from "./condition/order-condition";
import OrderAction from "./enum/order-action";
import { SoftDollarTier } from "../data/container/soft-dollar-tier";
import { TagValue } from "../data/container/tag-value";
import { OrderCondition } from "./condition/order-condition";
import { OrderAction } from "./enum/order-action";
import { OrderType } from "./enum/orderType";
import { TimeInForce } from "./enum/tif";
import { OrderComboLeg } from "./orderComboLeg";

/**
Expand Down Expand Up @@ -77,7 +78,7 @@ export interface Order {
* - FOK - If the entire Fill-or-Kill order does not execute as soon as it becomes available, the entire order is canceled.
* - DTC - Day until Canceled
*/
tif?: string;
tif?: TimeInForce;

/** One-Cancels-All group identifier. */
ocaGroup?: string;
Expand Down
5 changes: 3 additions & 2 deletions src/api/order/stop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import OrderAction from "./enum/order-action";
import { OrderType } from "./enum/orderType";
import { TimeInForce } from "./enum/tif";

/**
* Represents a stop order.
Expand All @@ -11,11 +12,11 @@ export class StopOrder {
public totalQuantity: number,
public transmit?: boolean,
public parentId?: number,
public tif?: string
public tif?: TimeInForce,
) {
this.transmit = this.transmit ?? true;
this.parentId = this.parentId ?? 0;
this.tif = this.tif ?? "DAY";
this.tif = this.tif ?? TimeInForce.DAY;
}

public orderType = OrderType.STP;
Expand Down
5 changes: 3 additions & 2 deletions src/api/order/stopLimit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import OrderAction from "./enum/order-action";
import { OrderType } from "./enum/orderType";
import { TimeInForce } from "./enum/tif";

/**
* Represents a stop-limit order.
Expand All @@ -12,11 +13,11 @@ export class StopLimitOrder {
public totalQuantity?: boolean,
public transmit?: boolean,
public parentId?: number,
public tif?: string
public tif?: TimeInForce,
) {
this.transmit = this.transmit ?? true;
this.parentId = this.parentId ?? 0;
this.tif = this.tif ?? "DAY";
this.tif = this.tif ?? TimeInForce.DAY;
}

public orderType = OrderType.STP_LMT;
Expand Down
7 changes: 4 additions & 3 deletions src/api/order/trailingStop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import OrderAction from "./enum/order-action";
import { OrderAction } from "./enum/order-action";
import { OrderType } from "./enum/orderType";
import { TimeInForce } from "./enum/tif";

/**
* Represents a trailing-stop order.
Expand Down Expand Up @@ -32,11 +33,11 @@ export class TrailingStopOrder {
public trailingPercent?: number,
public transmit?: boolean,
public parentId?: number,
public tif?: string
public tif?: TimeInForce,
) {
this.transmit = this.transmit ?? true;
this.parentId = this.parentId ?? 0;
this.tif = this.tif ?? "DAY";
this.tif = this.tif ?? TimeInForce.DAY;
}

/** The order's type (must be [[OrderType.TRAIL]]). */
Expand Down
Loading

0 comments on commit 09522ab

Please sign in to comment.