Skip to content

Commit

Permalink
Option data type bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rylorin committed Aug 30, 2023
1 parent 0c1fe69 commit 1bee81f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/api/contract/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Contract } from "./contract";
export class Option implements Contract {
constructor(
public symbol: string,
public lastTradeDateOrContractMonth: string,
public expiry: string,
public strike: number,
public right: OptionType,
public exchange?: string,
Expand All @@ -20,6 +20,10 @@ export class Option implements Contract {

public secType = SecType.OPT;
public multiplier = 100;

public get lastTradeDateOrContractMonth(): string {
return this.expiry;
}
}

export default Option;
29 changes: 16 additions & 13 deletions src/tools/market-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import path from "path";
import { Subscription } from "rxjs";

import { SecType, OptionType } from "../";
import { SecType, OptionType ,Option, Contract} from "../";
import { IBApiNextError, IBApiNextTickType, IBApiTickType, MarketDataType } from "../api-next";
import logger from "../common/logger";
import { IBApiNextApp } from "./common/ib-api-next-app";
Expand All @@ -17,7 +17,7 @@ import { IBApiNextApp } from "./common/ib-api-next-app";
const DESCRIPTION_TEXT = "Print real time market data of a given contract id.";
const USAGE_TEXT = "Usage: market-data.js <options>";
const OPTION_ARGUMENTS: [string, string][] = [
["conid=<number>", "Contract ID (conId) of the contract."],
// ["conid=<number>", "Contract ID (conId) of the contract."],
["symbol=<name>", "The symbol name."],
[
"sectype=<type>",
Expand Down Expand Up @@ -53,22 +53,25 @@ class PrintMarketDataApp extends IBApiNextApp {
* Start the app.
*/
start(): void {
let contract: Contract | Option;
const scriptName = path.basename(__filename);
logger.debug(`Starting ${scriptName} script`);
this.connect(this.cmdLineArgs.watch ? 10000 : 0);
this.api.setMarketDataType(MarketDataType.DELAYED);
if (this.cmdLineArgs.sectype as SecType == SecType.OPT) {
contract = new Option( this.cmdLineArgs.symbol as string, this.cmdLineArgs.expiry as string,+this.cmdLineArgs.strike,this.cmdLineArgs.right as OptionType,this.cmdLineArgs.exchange as string,this.cmdLineArgs.currency as string);
} else contract= {
conId: this.cmdLineArgs.conid as number ?? undefined,
symbol: this.cmdLineArgs.symbol as string,
secType: this.cmdLineArgs.sectype as SecType,
exchange: this.cmdLineArgs.exchange as string,
currency: this.cmdLineArgs.currency as string,
lastTradeDateOrContractMonth: this.cmdLineArgs.expiry as string,
strike: (this.cmdLineArgs.strike as number) ?? undefined,
right: this.cmdLineArgs.right as OptionType,
}

Check failure on line 72 in src/tools/market-data.ts

View workflow job for this annotation

GitHub Actions / job

Missing semicolon
this.subscription$ = this.api
.getMarketData(
{
conId: this.cmdLineArgs.conid as number ?? undefined,
symbol: this.cmdLineArgs.symbol as string,
secType: this.cmdLineArgs.sectype as SecType,
exchange: this.cmdLineArgs.exchange as string,
currency: this.cmdLineArgs.currency as string,
lastTradeDateOrContractMonth: this.cmdLineArgs.expiry as string,
strike: (this.cmdLineArgs.strike as number) ?? undefined,
right: this.cmdLineArgs.right as OptionType,
},
.getMarketData(contract,
this.cmdLineArgs.ticks as string,
false,
false
Expand Down

0 comments on commit 1bee81f

Please sign in to comment.