Skip to content

Commit

Permalink
Added -n switch to only perform stock quotes and skip the index quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
frossm committed Apr 19, 2021
1 parent 8a9f283 commit 5a9946c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 48 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Note that if Quoter has been installed via a snap, `quoter -c` is all that is ne
|-z | Disable colorized output|
|-b | Use the IEXCloud.io sandbox instead of the production environment. Note, the `-b` sandbox switch must be the first command line switch. It's used during development and probably not much use for normal users. Please note that the sandbox requires a sandbox key, not the production key. This can be obtained via the IEXCloud dashboard and set with the `-c` command line switch when in sandbox (`-b`) mode|
|-w COLUMNS| Set a custom width for the trending display. This is the number of columns the output should use. I have quoter aliased and I call it with my current column width|
|-n| Hide the index display and just show the stock quotes. If no stocks are provided, then nothing will happen|

#### Security Information
|Option|Description|
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.fross</groupId>
<artifactId>quoter</artifactId>
<version>2.6.0</version>
<version>2.6.1</version>
<packaging>jar</packaging>

<name>quoter</name>
Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: quoter
version: '2.6.0'
version: '2.6.1'
summary: Command line utility to pull stock and index quotes
description: |
Quote fetches stock quotes and index data from IEXCloud.IO.
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/fross/quoter/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public static void Display() {
Output.printColorln(Ansi.Color.WHITE, " -z Disable colorized output");
Output.printColorln(Ansi.Color.WHITE, " -b Use IEXCloud Sandbox URL instead of production");
Output.printColorln(Ansi.Color.WHITE, " -w WIDTH Width, in columns, of output for the trending display");

Output.printColorln(Ansi.Color.WHITE, " -n Hide the Index display and just show stock quotes");

Output.printColorln(Ansi.Color.YELLOW, "\nSecurity Information:");
Output.printColorln(Ansi.Color.WHITE, " -d Display more detailed security information");
Output.printColorln(Ansi.Color.WHITE, " -t Include a 3 month historical trend");
Expand Down
98 changes: 53 additions & 45 deletions src/main/java/org/fross/quoter/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public static void main(String[] args) {
boolean saveSymbolsFlag = false;
boolean ignoreSavedFlag = false;
boolean sandboxFlag = false;
boolean displayIndexDataFlag = true;

// Process application level properties file
// Update properties from Maven at build time:
Expand All @@ -92,7 +93,7 @@ public static void main(String[] args) {
}

// Process Command Line Options
Getopt optG = new Getopt("quote", args, "ckdtx:sriDvzbw:h?");
Getopt optG = new Getopt("quote", args, "ckdtx:sriDvzbw:nh?");
while ((optionEntry = optG.getopt()) != -1) {
switch (optionEntry) {
// Turn on Debug Mode
Expand Down Expand Up @@ -131,6 +132,11 @@ public static void main(String[] args) {
sandboxFlag = true;
break;

// Disable displaying the index data
case 'n':
displayIndexDataFlag = false;
break;

// Set custom console width to use with the trending display
case 'w':
try {
Expand Down Expand Up @@ -372,58 +378,60 @@ public static void main(String[] args) {
}
}

Output.println("");
}

// Display Index Output Header
Output.printColorln(Ansi.Color.CYAN, "-------------------------------------------------------------------------------");
Output.printColorln(Ansi.Color.WHITE, "Index Current Change Change% 52WHigh 52WLow");
Output.printColorln(Ansi.Color.CYAN, "-------------------------------------------------------------------------------");
// Unless disabled, display the index data
if (displayIndexDataFlag == true) {
// Display Index Output Header
Output.printColorln(Ansi.Color.CYAN, "\n-------------------------------------------------------------------------------");
Output.printColorln(Ansi.Color.WHITE, "Index Current Change Change% 52WHigh 52WLow");
Output.printColorln(Ansi.Color.CYAN, "-------------------------------------------------------------------------------");

// Loop through the three indexes and display the results
String[] indexList = { "DOW", "NASDAQ", "S&P" };
for (int i = 0; i < indexList.length; i++) {
String[] outString = new String[6];
String[] result = Index.getIndex(indexList[i]);
try {
// Download the web page and return the results array
Output.debugPrint("Getting Index data for: " + indexList[i]);
// Loop through the three indexes and display the results
String[] indexList = { "DOW", "NASDAQ", "S&P" };
for (int i = 0; i < indexList.length; i++) {
String[] outString = new String[6];
String[] result = Index.getIndex(indexList[i]);
try {
// Download the web page and return the results array
Output.debugPrint("Getting Index data for: " + indexList[i]);

// Determine the color based on the change amount
Ansi.Color outputColor = Ansi.Color.WHITE;
if (Float.valueOf(result[2]) < 0) {
outputColor = Ansi.Color.RED;
}
// Determine the color based on the change amount
Ansi.Color outputColor = Ansi.Color.WHITE;
if (Float.valueOf(result[2]) < 0) {
outputColor = Ansi.Color.RED;
}

// Format the Output
// Symbol
outString[0] = String.format("%-10s", result[0]);
// Current
outString[1] = String.format("%,10.2f", Float.valueOf(result[1].replace(",", "")));
// Change Amount
outString[2] = String.format("%+,10.2f", Float.valueOf(result[2].replace(",", "")));
// Change Percentage
outString[3] = String.format("%+,10.2f%%", Float.valueOf(result[3].replace("%", "")));
// 52Week High
outString[4] = String.format("%,14.2f", Float.valueOf(result[4].replace(",", "")));
// 52Week Low
outString[5] = String.format("%,14.2f", Float.valueOf(result[5].replace(",", "")));

// Display Index results to the screen
for (int k = 0; k < outString.length; k++) {
Output.printColor(outputColor, outString[k]);
}
// Format the Output
// Symbol
outString[0] = String.format("%-10s", result[0]);
// Current
outString[1] = String.format("%,10.2f", Float.valueOf(result[1].replace(",", "")));
// Change Amount
outString[2] = String.format("%+,10.2f", Float.valueOf(result[2].replace(",", "")));
// Change Percentage
outString[3] = String.format("%+,10.2f%%", Float.valueOf(result[3].replace("%", "")));
// 52Week High
outString[4] = String.format("%,14.2f", Float.valueOf(result[4].replace(",", "")));
// 52Week Low
outString[5] = String.format("%,14.2f", Float.valueOf(result[5].replace(",", "")));

// Start a new line for the next index
Output.println("");
// Display Index results to the screen
for (int k = 0; k < outString.length; k++) {
Output.printColor(outputColor, outString[k]);
}

// If export is chosen, dump this index's data to the export file
if (exportFlag == true && exporter.canWrite()) {
exporter.exportIndexes(result);
}
} catch (Exception Ex) {
Output.printColorln(Ansi.Color.RED, outString[0] + ": No Data");
// Start a new line for the next index
Output.println("");

// If export is chosen, dump this index's data to the export file
if (exportFlag == true && exporter.canWrite()) {
exporter.exportIndexes(result);
}
} catch (Exception Ex) {
Output.printColorln(Ansi.Color.RED, outString[0] + ": No Data");

}
}
}

Expand Down

0 comments on commit 5a9946c

Please sign in to comment.