Skip to content

Commit

Permalink
getOpenOrders tool added
Browse files Browse the repository at this point in the history
  • Loading branch information
rylorin committed Oct 10, 2023
1 parent 1c0d419 commit 8cfe8d8
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 15 deletions.
53 changes: 53 additions & 0 deletions src/tools/open-orders-all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* This App will print IBKR account open orders to console.
*/

import { IBApiNextError } from "..";
import { IBApiNextApp } from "./common/ib-api-next-app";

/////////////////////////////////////////////////////////////////////////////////
// The help text. //
/////////////////////////////////////////////////////////////////////////////////

const DESCRIPTION_TEXT = "Prints the account open orders.";
const USAGE_TEXT = "Usage: open-orders.js <options>";
const OPTION_ARGUMENTS: [string, string][] = [];
const EXAMPLE_TEXT = "open-orders.js";

//////////////////////////////////////////////////////////////////////////////
// The App code //
//////////////////////////////////////////////////////////////////////////////

class OpenOrdersApp extends IBApiNextApp {
constructor() {
super(DESCRIPTION_TEXT, USAGE_TEXT, OPTION_ARGUMENTS, EXAMPLE_TEXT);
}

/**
* Start the app.
*/
start(): void {
super.start();

this.api
.getAllOpenOrders()
.then((orders) => {
this.printObject(orders);
this.stop();
})
.catch((err: IBApiNextError) => {
this.error(`getAllOpenOrders failed with '${err}'`);
});
}

/**
* Stop the app with success code.
*/
stop() {
this.exit();
}
}

// run the app

new OpenOrdersApp().start();
4 changes: 2 additions & 2 deletions src/tools/open-orders-auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class OpenOrdersApp extends IBApiNextApp {
this.printObject(data);
},
error: (err: IBApiNextError) => {
this.error(`getOpenOrders failed with '${err.error.message}'`);
this.error(`getAutoOpenOrders failed with '${err.error.message}'`);
},
complete: () => {
console.log("getOpenOrders completed.");
console.log("getAutoOpenOrders completed.");
},
});
}
Expand Down
35 changes: 22 additions & 13 deletions src/tools/open-orders.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/**
* This App will print IBKR account open orders to console.
* This App will print real-time updates of the IBKR account open orders.
*/

import { Subscription } from "rxjs";

import { IBApiNextError } from "../";
import { IBApiNextApp } from "./common/ib-api-next-app";

Expand All @@ -10,9 +12,9 @@ import { IBApiNextApp } from "./common/ib-api-next-app";
/////////////////////////////////////////////////////////////////////////////////

const DESCRIPTION_TEXT = "Prints the account open orders.";
const USAGE_TEXT = "Usage: open-orders.js <options>";
const OPTION_ARGUMENTS: [string, string][] = [];
const EXAMPLE_TEXT = "open-orders.js";
const USAGE_TEXT = "Usage: open-orders-updates.js <options>";
const OPTION_ARGUMENTS: [string, string][] = [["bind", "auto bind orders"]];
const EXAMPLE_TEXT = "open-orders-updates.js";

//////////////////////////////////////////////////////////////////////////////
// The App code //
Expand All @@ -23,27 +25,34 @@ class OpenOrdersApp extends IBApiNextApp {
super(DESCRIPTION_TEXT, USAGE_TEXT, OPTION_ARGUMENTS, EXAMPLE_TEXT);
}

/** The [[Subscription]] on the open orders. */
private subscription$: Subscription;

/**
* Start the app.
*/
start(): void {
super.start();

this.api
.getAllOpenOrders()
.then((orders) => {
this.printObject(orders);
this.stop();
})
.catch((err: IBApiNextError) => {
this.error(`getAllOpenOrders failed with '${err}'`);
});
this.subscription$ = this.api.getOpenOrders().subscribe({
next: (data) => {
this.printObject(data);
},
error: (err: IBApiNextError) => {
this.error(`getOpenOrders failed with '${err.error.message}'`);
},
complete: () => {
console.log("getOpenOrders completed.");
},
});
}

/**
* Stop the app with success code.
*/
stop() {
console.log("app stopping.");
this.subscription$?.unsubscribe();
this.exit();
}
}
Expand Down

0 comments on commit 8cfe8d8

Please sign in to comment.