Closed Caceresenzo closed 3 years ago
On the same note, why not using BigDecimal
instead of String
? (for numeric fields)
Is there a way to use a Java enum instead of a String field in such cases? (see below) while you can use @SerializedName from GSON?
The reason I didn't originally use the @SerializedName
for those enums was because Alpaca was changing them (along with ActivityType
's) which would result in a null value for that field in the generated POJO. Those likely won't be changing too much anymore so I'll convert those fields to their enum equivalents in the schema in the next release.
On the same note, why not using
BigDecimal
instead ofString
? (for numeric fields)
Which schemas/fields are you referring too?
The reason I didn't originally use the @SerializedName for those enums was because Alpaca was changing them (along with ActivityType's) which would result in a null value for that field in the generated POJO. Those likely won't be changing too much anymore so I'll convert those fields to their enum equivalents in the schema in the next release.
Ok thanks for telling me
Which schemas/fields are you referring too?
At pretty much any decimal field.
(these are some few exemple)
I don't recall the exact reason I decided to use String
there, but I believe it is for the following reasons: double
was causing some users to get parse exceptions due to overflow as Alpaca/Polygon was sending very large (or small) numbers occasionally and BigDecimal
fixes overflow issues, but increases overhead (especially on the market data stream). So I just left it up to the user to either take the string and parse it as a double
or BigDecimal
themselves. I imagine that double
is fine in some places now though, so I can take a look and change it from String
to double
where appropriate. Hope that clears things up.
I was expecting that kind of answer for the numeric values.
In contrary, the enum change will reduce overhead :)
@Caceresenzo I've added TradeUpdateEvent
and ActivityType
enums to their associated JSON schemas as seen here on the development
branch. I've tested it out on my end, but if you'd like to test it, clone the development
branch and run ./gradlew clean build install
. I'll integrate into the next release.
Unfortunately I do not have the time to test it... But I will happily update my code when the update is released :)
Thanks for your work
Hi
Is there a way to use a Java enum instead of a String field in such cases? (see below)
https://github.com/Petersoj/alpaca-java/blob/d4e5ac830767a6b69259192c60645433272435a6/schema_json/alpaca/streaming/trade/trade_update.json#L5-L8
Here is what I was using for replacement:
Since the enum fields returned by Alpaca's API are in lowercase, I see a big usage of https://github.com/Petersoj/alpaca-java/blob/d4e5ac830767a6b69259192c60645433272435a6/src/main/java/net/jacobpeterson/abstracts/enums/APIName.java#L3-L6
while you can use
@SerializedName
from GSON? (i am a Jackson user, so i can't really tell you is this the correct way to do it, but take a look at this: https://stackoverflow.com/a/18343576/7292958)