-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add PriceProver and integration test
- Loading branch information
Showing
17 changed files
with
411 additions
and
301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "depends/pagesigner-cli"] | ||
path = depends/pagesigner-cli | ||
url = [email protected]:AbstrLabs/pagesigner-cli.git | ||
[submodule "depends/pagesigner-cli"] | ||
path = depends/pagesigner-cli | ||
url = [email protected]:AbstrLabs/pagesigner-cli.git |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice. | ||
#Sun Mar 06 23:48:53 JST 2022 | ||
xjsnark-1.0.jar>= | ||
xjsnark-1.0.pom>= |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>akosba</groupId> | ||
<artifactId>xjsnark</artifactId> | ||
<version>1.0</version> | ||
<description>POM was created from install:install-file</description> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<metadata> | ||
<groupId>akosba</groupId> | ||
<artifactId>xjsnark</artifactId> | ||
<versioning> | ||
<release>1.0</release> | ||
<versions> | ||
<version>1.0</version> | ||
</versions> | ||
<lastUpdated>20220306144853</lastUpdated> | ||
</versioning> | ||
</metadata> |
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 78 additions & 75 deletions
153
src/main/java/com/abstrlabs/priceprover/PageSignerCallBack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,78 @@ | ||
package com.abstrlabs.priceprover; | ||
|
||
import com.abstrlabs.priceprover.util.CommandExecutor; | ||
import lombok.extern.log4j.Log4j2; | ||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.util.concurrent.Callable; | ||
|
||
@Log4j2 | ||
@Command(name = "pagesigner", description = "Call pagesigner-cli and generate a stock price notray json") | ||
public class PageSignerCallBack implements Callable<Integer> { | ||
|
||
@Option(names = {"-as", "--asset"}, defaultValue = "aIBM", description = "the asset name used to obtain the price data jason and the notary file via PageSinger.") | ||
String asset; | ||
|
||
@Option(names = {"-op", "--outputPath"}, defaultValue = "./out", description = "output path for generated headers and notary files") | ||
String outputPath; | ||
|
||
@Override | ||
public Integer call(){ | ||
String assetName = normalizeAssetName(asset); | ||
|
||
try { | ||
//generate header.txt | ||
String currentWorkingDir = System.getProperty("user.dir"); | ||
String headersPath = currentWorkingDir + "/headers.txt"; | ||
String content = "GET /query?function=GLOBAL_QUOTE&symbol=" + assetName + "&apikey=demo HTTP/1.1\n" + | ||
"Host: www.alphavantage.co"; | ||
File headersFile = new File(headersPath); | ||
if (headersFile.createNewFile()) { | ||
log.info("Headers file created successfully"); | ||
}; | ||
FileWriter headersWriter = new FileWriter(headersFile); | ||
headersWriter.write(content); | ||
headersWriter.close(); | ||
|
||
//call pagesigner-cli | ||
String[] pagesignerCommand = new String[]{"./depends/pagesigner-cli/pgsg-node.js", "notarize", "www.alphavantage.co", "--headers", headersPath, outputPath}; | ||
CommandExecutor ce = new CommandExecutor(); | ||
String missionName = "Call pagesigner-cli"; | ||
if (ce.execute(missionName, pagesignerCommand)) { | ||
log.info("saved the notary file into path:" + outputPath); | ||
return 0; | ||
} else { | ||
return -1; | ||
} | ||
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return -2; | ||
} | ||
} | ||
|
||
/** | ||
* input : asset name, eg. aIBM, aAAPL | ||
* output: normalized asset name, eg. IBM, AAPL | ||
*/ | ||
private String normalizeAssetName(String asset) { | ||
if (asset.length() > 1 && asset.charAt(0) == 'a') { | ||
asset = asset.substring(1); | ||
} | ||
log.info("The normalized asset name is " + asset); | ||
return asset; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int exitCode = new CommandLine(new PageSignerCallBack()).execute(args); | ||
System.exit(exitCode); | ||
} | ||
} | ||
package com.abstrlabs.priceprover; | ||
|
||
import com.abstrlabs.priceprover.util.CommandExecutor; | ||
import lombok.extern.log4j.Log4j2; | ||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.concurrent.Callable; | ||
|
||
@Log4j2 | ||
@Command(name = "notarize", description = "Call pagesigner-cli and notarize the stock price") | ||
public class PageSignerCallBack implements Callable<Integer> { | ||
|
||
private static final String HEADERS = "headers"; | ||
|
||
@Option(names = {"-as", "--asset"}, defaultValue = "aIBM", description = "the asset name used to obtain the price data jason and the notary file via PageSinger.") | ||
String asset; | ||
|
||
@Option(names = {"-op", "--outputPath"}, defaultValue = "./out", description = "output path for generated headers and notary files") | ||
String outputPath; | ||
|
||
@Override | ||
public Integer call(){ | ||
String assetName = normalizeAssetName(asset); | ||
|
||
try { | ||
// generate header.txt | ||
String headersPath = String.valueOf(Paths.get(outputPath, HEADERS)); | ||
String content = "GET /query?function=GLOBAL_QUOTE&symbol=" + assetName + "&apikey=demo HTTP/1.1\n" + | ||
"Host: www.alphavantage.co"; | ||
File headersFile = new File(headersPath); | ||
if (headersFile.createNewFile()) { | ||
log.info("Headers file created successfully"); | ||
}; | ||
FileWriter headersWriter = new FileWriter(headersFile); | ||
headersWriter.write(content); | ||
headersWriter.close(); | ||
|
||
// call pagesigner-cli | ||
String[] pagesignerCommand = new String[]{"./depends/pagesigner-cli/pgsg-node.js", "notarize", "www.alphavantage.co", "--headers", headersPath, outputPath}; | ||
CommandExecutor ce = new CommandExecutor(); | ||
String missionName = "Call pagesigner-cli"; | ||
if (ce.execute(missionName, pagesignerCommand)) { | ||
log.info("saved the notary file into path:" + outputPath); | ||
return 0; | ||
} else { | ||
return -1; | ||
} | ||
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return -2; | ||
} | ||
} | ||
|
||
/** | ||
* input : asset name, eg. aIBM, aAAPL | ||
* output: normalized asset name, eg. IBM, AAPL | ||
*/ | ||
private String normalizeAssetName(String asset) { | ||
if (asset.length() > 1 && asset.charAt(0) == 'a') { | ||
asset = asset.substring(1); | ||
} | ||
log.debug("The normalized asset name is " + asset); | ||
return asset; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int exitCode = new CommandLine(new PageSignerCallBack()).execute(args); | ||
System.exit(exitCode); | ||
} | ||
} |
Oops, something went wrong.