Petersoj / alpaca-java

A Java API for Alpaca, the commission free, algo friendly, stock trading broker. https://alpaca.markets
https://petersoj.github.io/alpaca-java/
MIT License
198 stars 84 forks source link

alpaca.properties not loading for v3.0.0 #7

Closed Petersoj closed 5 years ago

Petersoj commented 5 years ago

There now seems to be an issue with loading the alpaca.properties file. When using the no-parameter overloaded constructor (to instantiate AlpacaAPI with properties file), the KEY_ID_VALUE and SECRET_VALUE in the AlpacaProperties class stay as "PLACEHOLDER". This issue did not exist with 2.0 or 1.1. Why does the commit 16397a503ac6b78a81e250bee391af1036ee95b2 modify the way property/resource files are opened/streamed? Simply using the default class loader rather than the system class loader seemed to work great.

mainstringargs commented 5 years ago

When building an application using the installDist target, the properties did not load correctly. I'll try to replicate and fix. Where is your alpaca.properties file in relation to your workspace? Is the alpaca.properties enclosing directory on your classpath in however you are running the application?

Petersoj commented 5 years ago

My alpaca.properties file is simply in src/main/java/resources which is automatically put on the classpath when packaging with maven. The resource does exist when trying to load it via AlpacaProperties.class.getResourceAsStream("/alpaca.properties");

mainstringargs commented 5 years ago

Can you try again? I just pushed 3.0.2. I've updated the logic a little bit to make it more forgiving. It also will log out the files it is using:

[INFO ] 2019-05-29 16:51:03.263 [main] PolygonProperties - Found polygon.properties File: file:/C:/builds/alpaca-java-mvn-test/target/classes/polygon.properties
[INFO ] 2019-05-29 16:51:03.266 [main] PolygonProperties - Found polygon.properties File: jar:file:/C:/Users/XYZ/.m2/repository/io/github/mainstringargs/alpaca-java/3.0.2/alpaca-java-3.0.2.jar!/polygon.properties
[INFO ] 2019-05-29 16:51:03.267 [main] AlpacaProperties - Found alpaca.properties File: file:/C:/builds/alpaca-java-mvn-test/target/classes/alpaca.properties
[INFO ] 2019-05-29 16:51:03.267 [main] AlpacaProperties - Found alpaca.properties File: jar:file:/C:/Users/XYZ/.m2/repository/io/github/mainstringargs/alpaca-java/3.0.2/alpaca-java-3.0.2.jar!/alpaca.properties

They are in the order that will be searched for the property.

Petersoj commented 5 years ago

Works great now. Thanks!