Skip to content

Commit

Permalink
Added detailed quote (-d) information
Browse files Browse the repository at this point in the history
  • Loading branch information
frossm committed Dec 11, 2020
1 parent e5c4e48 commit 1fca3bc
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 61 deletions.
Binary file modified graphics/ScreenShot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions 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.1.2</version>
<version>2.1.3</version>
<packaging>jar</packaging>

<name>quoter</name>
Expand Down Expand Up @@ -148,7 +148,6 @@
</configuration>
</plugin>


</plugins>
</build>

Expand Down Expand Up @@ -191,7 +190,7 @@
<dependency>
<groupId>org.fross</groupId>
<artifactId>library</artifactId>
<version>2.0.0</version>
<version>2.0.3</version>
</dependency>
</dependencies>
</project>
1 change: 1 addition & 0 deletions reference/symbol.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// 20201204201405
// https://cloud.iexapis.com/stable/stock/acn/quote?token=

{
"symbol": "ACN",
Expand Down
4 changes: 2 additions & 2 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: quoter
version: '2.1.2'
version: '2.1.3'
summary: Command line utility to pull stock and index quotes
description: |
Quote fetches stock quotes and index data from IEXCloud.IO.
Expand All @@ -20,7 +20,7 @@ parts:
plugin: maven
source: https://github.com/frossm/library.git
source-type: git
source-tag: 'v2.0.0'
source-tag: 'v2.0.3'
maven-options: [install]

quoter:
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/fross/quoter/FileExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public boolean canWrite() {
public boolean exportSecurities(Symbol symbolData) {
try {
// Export the header row
List<String> fields = symbolData.queryAllFieldNames();
List<String> fields = symbolData.getAllFieldNames();
if (this.exportSymbolHeaderWritten == false) {
for (String i : fields) {
exportFileFW.append(i + ",");
Expand All @@ -98,7 +98,7 @@ public boolean exportSecurities(Symbol symbolData) {
// Export the symbol data
for (String i : fields) {
// If the data has a ',' in it remove it
String item = symbolData.query(i).replaceAll(",", "");
String item = symbolData.get(i).replaceAll(",", "");
exportFileFW.append(item + ",");
}
exportFileFW.append("\n");
Expand Down
41 changes: 25 additions & 16 deletions src/main/java/org/fross/quoter/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

package org.fross.quoter;

import org.fross.library.Format;
import org.fross.library.Output;
import org.fusesource.jansi.Ansi;

Expand All @@ -37,28 +38,36 @@
*
*/
public class Help {
static final int HEADERWIDTH = 72;

/**
* Display(): Prints help in color using the JCDP library in the output module.
*/
public static void Display() {
Output.printColorln(Ansi.Color.CYAN, "\n+----------------------------------------------------------------------+");
Output.printColorln(Ansi.Color.CYAN, "+ Quoter v" + Main.VERSION + " Help +");
Output.printColorln(Ansi.Color.CYAN, "+ " + Main.COPYRIGHT + " +");
Output.printColorln(Ansi.Color.CYAN, "+----------------------------------------------------------------------+");
Output.printColorln(Ansi.Color.CYAN, " Quoter is a tool to display stock quotes and index data");
Output.printColorln(Ansi.Color.CYAN, " https://github.com/frossm/quoter\n");
Output.printColorln(Ansi.Color.CYAN, "\n+" + "-".repeat(HEADERWIDTH - 2) + "+");
Output.printColorln(Ansi.Color.CYAN, "+" + Format.CenterText(HEADERWIDTH - 2, "Quoter v" + Main.VERSION) + "+");
Output.printColorln(Ansi.Color.CYAN, "+" + Format.CenterText(HEADERWIDTH - 2, Main.COPYRIGHT) + "+");
Output.printColorln(Ansi.Color.CYAN, "+" + "-".repeat(HEADERWIDTH - 2) + "+");
Output.printColorln(Ansi.Color.CYAN, Format.CenterText(HEADERWIDTH - 2, "Quoter is a tool to display stock quotes and index data"));
Output.printColorln(Ansi.Color.CYAN, Format.CenterText(HEADERWIDTH - 2, "https://github.com/frossm/quoter") + "\n");

Output.printColorln(Ansi.Color.WHITE, "Command Line Options");

Output.printColorln(Ansi.Color.YELLOW, "\nConfiguration:");
Output.printColorln(Ansi.Color.WHITE, " -c Configure the IEXCloud secret key. See link above for details.");
Output.printColorln(Ansi.Color.WHITE, " -k Display the IEXCloud secret key being used");

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");

Output.printColorln(Ansi.Color.YELLOW, "Command Line Options:");
Output.printColorln(Ansi.Color.WHITE, " -c Configure the IEXCloud secret key. See link above for details.");
Output.printColorln(Ansi.Color.WHITE, " -t Include a 3 month historical trend");
Output.printColorln(Ansi.Color.WHITE, " -x <file> Export results into the specified file in CSV format");
Output.printColorln(Ansi.Color.WHITE, " -k Display the IEXCloud secret key being used");
Output.printColorln(Ansi.Color.WHITE, " -D Start in debug mode and display developer information");
Output.printColorln(Ansi.Color.WHITE, " -v Display program version and exit");
Output.printColorln(Ansi.Color.WHITE, " -? | -h Display this help information");
Output.printColorln(Ansi.Color.YELLOW, "\nMisc:");
Output.printColorln(Ansi.Color.WHITE, " -D Start in debug mode and display developer information");
Output.printColorln(Ansi.Color.WHITE, " -v Display program version and exit");
Output.printColorln(Ansi.Color.WHITE, " -? | -h Display this help information");

Output.printColorln(Ansi.Color.YELLOW, "\nNote:");
Output.printColorln(Ansi.Color.WHITE, " - Quoter data is sourced from IEXCloud.io. You'll need at least the free account");
Output.printColorln(Ansi.Color.YELLOW, "\nNotes:");
Output.printColorln(Ansi.Color.WHITE, " - Quoter data is sourced from IEXCloud.io. You'll need minimally a free account");
Output.printColorln(Ansi.Color.WHITE, " - The Index data is pulled from a financial website\n");
}
}
10 changes: 5 additions & 5 deletions src/main/java/org/fross/quoter/HistoricalQuotes.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ public static void displayTrendingMap(String symb, String token) {
Symbol symbolData = new Symbol(symb, token);

// Display the symbol informational header
Output.printColorln(Ansi.Color.WHITE, "\n\n+" + "-".repeat(GRAPHWIDTH + 12) + "+");
Output.printColorln(Ansi.Color.YELLOW, symb.toUpperCase() + " / " + symbolData.query("companyName"));
Output.printColorln(Ansi.Color.YELLOW, "Exchange: " + symbolData.query("primaryExchange"));
Output.printColorln(Ansi.Color.YELLOW, "PE Ratio: " + symbolData.query("peRatio"));
Output.printColorln(Ansi.Color.YELLOW, "Market Cap: " + Format.Comma(Double.valueOf(symbolData.query("marketCap")).longValue()));
Output.printColorln(Ansi.Color.WHITE, "\n\n+--Three Month Trend" + "-".repeat(GRAPHWIDTH - 7) + "+");
Output.printColorln(Ansi.Color.YELLOW, symb.toUpperCase() + " / " + symbolData.get("companyName"));
Output.printColorln(Ansi.Color.YELLOW, "Exchange: " + symbolData.get("primaryExchange"));
Output.printColorln(Ansi.Color.YELLOW, "PE Ratio: " + symbolData.get("peRatio"));
Output.printColorln(Ansi.Color.YELLOW, "Market Cap: " + symbolData.get("marketCap"));
Output.printColorln(Ansi.Color.WHITE, "+" + "-".repeat(GRAPHWIDTH + 12) + "+\n");

// Display trending title bar
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/fross/quoter/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ protected static String[] getIndex(String idx) {
searchPatterns[1] = "\"last\":\"(.*?)\"";
searchPatterns[2] = "\"change\":\"(.*?)\"";
searchPatterns[3] = "\"change_pct\":\"(.*?)\"";
searchPatterns[4] = "'year low'.*?\\>(.*?)\\<";
searchPatterns[5] = "'year high'.*?\\>(.*?)\\<";
searchPatterns[4] = "'year high'.*?\\>(.*?)\\<";
searchPatterns[5] = "'year low'.*?\\>(.*?)\\<";

retArray[0] = idx;
for (int i = 1; i < searchPatterns.length; i++) {
Expand Down
73 changes: 53 additions & 20 deletions src/main/java/org/fross/quoter/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static void main(String[] args) {
String latestTime = "None";
boolean exportFlag = false;
boolean trendFlag = false;
boolean detailedFlag = false;
FileExporter exporter = null;

// Process application level properties file
Expand All @@ -73,14 +74,19 @@ public static void main(String[] args) {
}

// Process Command Line Options
Getopt optG = new Getopt("quote", args, "Dtckx:h?v");
Getopt optG = new Getopt("quote", args, "Dtdckx:h?v");
while ((optionEntry = optG.getopt()) != -1) {
switch (optionEntry) {
// Turn on Debug Mode
case 'D':
Debug.enable();
break;

// Show detailed stock information
case 'd':
detailedFlag = true;
break;

// Show Stock Trending
case 't':
trendFlag = true;
Expand Down Expand Up @@ -169,69 +175,69 @@ public static void main(String[] args) {
Symbol symbolData = new Symbol(currentSymbol, Prefs.QueryString("iexcloudtoken"));

// Validate the provided quote is valid
if (symbolData.query("status").compareTo("Error") == 0) {
if (symbolData.get("status").compareTo("Error") == 0) {
// Display error and skip to the next iteration
Output.printColorln(Ansi.Color.BLUE, "'" + symbolData.query("symbol") + "' is invalid");
Output.printColorln(Ansi.Color.BLUE, "'" + symbolData.get("symbol") + "' is invalid");
continue;
}

// Format the Output into an array
try {
// Symbol
outString[0] = String.format("%-8s", symbolData.query("symbol"));
outString[0] = String.format("%-8s", symbolData.get("symbol"));

// Current
try {
outString[1] = String.format("%,8.2f", Float.valueOf(symbolData.query("latestPrice")));
outString[1] = String.format("%,8.2f", Float.valueOf(symbolData.get("latestPrice")));
} catch (NumberFormatException Ex) {
outString[1] = String.format("%8s", "-");
}

// Change Amount
try {
outString[2] = String.format("%+,8.2f", Float.valueOf(symbolData.query("change")));
outString[2] = String.format("%+,8.2f", Float.valueOf(symbolData.get("change")));
} catch (NumberFormatException Ex) {
outString[2] = String.format("%8s", "-");
}

// Change Percentage
try {
outString[3] = String.format("%+,7.2f%%", (Float.valueOf(symbolData.query("changePercent")) * 100));
outString[3] = String.format("%+,7.2f%%", (Float.valueOf(symbolData.get("changePercent")) * 100));
} catch (NumberFormatException Ex) {
outString[3] = String.format("%8s", "-");
}

// Day High
try {
outString[4] = String.format("%,9.2f", Float.valueOf(symbolData.query("high")));
outString[4] = String.format("%,9.2f", Float.valueOf(symbolData.get("high")));
} catch (NumberFormatException Ex) {
outString[4] = String.format("%9s", "-");
}

// Day Low
try {
outString[5] = String.format("%,9.2f", Float.valueOf(symbolData.query("low")));
outString[5] = String.format("%,9.2f", Float.valueOf(symbolData.get("low")));
} catch (NumberFormatException Ex) {
outString[5] = String.format("%9s", "-");
}

// 52 Week High
try {
outString[6] = String.format("%,9.2f", Float.valueOf(symbolData.query("week52High")));
outString[6] = String.format("%,9.2f", Float.valueOf(symbolData.get("week52High")));
} catch (NumberFormatException Ex) {
outString[6] = String.format("%9s", "-");
}

// 52 Week Low
try {
outString[7] = String.format("%,9.2f", Float.valueOf(symbolData.query("week52Low")));
outString[7] = String.format("%,9.2f", Float.valueOf(symbolData.get("week52Low")));
} catch (NumberFormatException Ex) {
outString[7] = String.format("%9s", "-");
}

// Year to date
try {
outString[8] = String.format("%+,9.2f%%", (Float.valueOf(symbolData.query("ytdChange")) * 100));
outString[8] = String.format("%+,9.2f%%", (Float.valueOf(symbolData.get("ytdChange")) * 100));
} catch (NumberFormatException Ex) {
outString[8] = String.format("%9s", "-");
}
Expand All @@ -243,7 +249,7 @@ public static void main(String[] args) {
// Determine the color based on the change amount
Ansi.Color outputColor = Ansi.Color.WHITE;
try {
if (Float.valueOf(symbolData.query("change")) < 0) {
if (Float.valueOf(symbolData.get("change")) < 0) {
outputColor = Ansi.Color.RED;
}

Expand All @@ -258,7 +264,7 @@ public static void main(String[] args) {

// Set the latest time for output later. Since they should all be the same, just keep that last
// symbol's data
latestTime = symbolData.query("latestUpdate");
latestTime = symbolData.get("latestUpdate");

// Start a new line for the next security
Output.println("");
Expand Down Expand Up @@ -330,14 +336,36 @@ public static void main(String[] args) {
// just index data is displayed, grab a security in order to get the date
if (symbolList.isEmpty()) {
Symbol getTime = new Symbol("IBM", Prefs.QueryString("iexcloudtoken"));
latestTime = getTime.query("latestUpdate");
latestTime = getTime.get("latestUpdate");
}
Output.printColorln(Ansi.Color.CYAN, "\nData as of " + latestTime);

// Flush and close export file if needed
if (exportFlag == true) {
exporter.close();
Output.printColor(Ansi.Color.CYAN, "\nData Export Complete to '" + exporter.queryExportFilename() + "'\n");
// Display detailed stock information if selected with the -d switch
if (detailedFlag == true && !symbolList.isEmpty()) {
final int HEADERWIDTH = 80;
String[] detailedFields = { "symbol", "companyName", "primaryExchange", "open", "openTime", "close", "closeTime", "high", "highTime", "low",
"lowTime", "latestPrice", "latestVolume", "previousClose", "previousVolume", "change", "changePercent", "agTotalVolume", "marketCap",
"peRatio", "week52High", "week52Low" };

Output.printColorln(Ansi.Color.WHITE, "\nDetailed Security Information:");

// Loop through each symbol and show the detailed display
for (String symb : symbolList) {
// Create the symbol data object
Symbol symbolData = new Symbol(symb, Prefs.QueryString("iexcloudtoken"));

// Display Header
Output.printColorln(Ansi.Color.CYAN, "-".repeat(HEADERWIDTH));
Output.printColorln(Ansi.Color.YELLOW, symb.toUpperCase() + " / " + symbolData.get("companyName"));
Output.printColorln(Ansi.Color.CYAN, "-".repeat(HEADERWIDTH));

// Loop through each detailed field and display it
for (String field : detailedFields) {
Output.printColorln(Ansi.Color.WHITE, " " + String.format("%-16s", field) + " " + symbolData.get(field));
}

Output.println("");
}
}

// Display trending data if -t was provided and there is at least one symbol
Expand All @@ -347,6 +375,11 @@ public static void main(String[] args) {
}
}

}
// Flush and close export file if needed
if (exportFlag == true) {
exporter.close();
Output.printColor(Ansi.Color.CYAN, "\nData Export Complete to '" + exporter.queryExportFilename() + "'\n");
}

}
}
Loading

0 comments on commit 1fca3bc

Please sign in to comment.