-
-
Notifications
You must be signed in to change notification settings - Fork 93
Hi
I'm using java version "1.8.0_161" & maven for build. I added maven dependencies as described on the build instructions.
<dependency>
<groupId>net.jacobpeterson</groupId>
<artifactId>alpaca-java</artifactId>
<version>9.1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.10.0</version>
</dependency>
I added an alpaca.properties file with my creds & put it in the resources directory. However when I attempt to run a code example:
AlpacaAPI alpacaAPI = new AlpacaAPI();
try {
// Get AAPL one hour, split-adjusted bars from 7/6/2021 market open
// to 7/8/2021 market close from the SIP feed and print them out
StockBarsResponse aaplBarsResponse = alpacaAPI.stockMarketData().getBars(
"AAPL",
ZonedDateTime.of(2021, 7, 6, 9, 30, 0, 0, ZoneId.of("America/New_York")),
ZonedDateTime.of(2021, 7, 8, 12 + 4, 0, 0, 0, ZoneId.of("America/New_York")),
null,
null,
1,
BarTimePeriod.HOUR,
BarAdjustment.SPLIT,
BarFeed.SIP);
aaplBarsResponse.getBars().forEach(System.out::println);
} catch (AlpacaClientException exception) {
exception.printStackTrace();
}
I get the below error message. Not sure why since it seems like I have all dependencies. Any ideas are appreciated!
2022年08月16日 10:42:03 INFO PropertyUtil:126 - Loaded properties file: alpaca.properties
Exception in thread "main" java.lang.NoSuchMethodError: kotlin.collections.ArraysKt.copyInto([B[BIII)[B
at okio.Segment.writeTo(Segment.kt:169)
at okio.Segment.compact(Segment.kt:152)
at okio.Buffer.write(Buffer.kt:1491)
at okio.Buffer.read(Buffer.kt:1503)
at okio.Buffer.writeAll(Buffer.kt:1290)
at okio.Options$Companion.buildTrieRecursive(Options.kt:189)
at okio.Options$Companion.buildTrieRecursive(Options.kt:175)
at okio.Options$Companion.buildTrieRecursive$default(Options.kt:107)
at okio.Options$Companion.of(Options.kt:72)
at okhttp3.internal.Util.(Util.kt:70)
at okhttp3.internal.concurrent.TaskRunner.(TaskRunner.kt:309)
at okhttp3.ConnectionPool.(ConnectionPool.kt:41)
at okhttp3.ConnectionPool.(ConnectionPool.kt:47)
at okhttp3.OkHttpClient$Builder.(OkHttpClient.kt:471)
at net.jacobpeterson.alpaca.AlpacaAPI.(AlpacaAPI.java:136)
at net.jacobpeterson.alpaca.AlpacaAPI.(AlpacaAPI.java:102)
at net.jacobpeterson.alpaca.AlpacaAPI.(AlpacaAPI.java:75)
at TestClass.main(TestClass.java:74)
Thanks for developing this library, it looks cool. I've been using the python alpaca client but prefer using Java.
Best
Dwight Schrute
All reactions
Replies: 1 comment 1 reply
Hi there Dwight,
This appears to be a similar issue as described in issue #108. This happens when Maven puts a transitive dependency on the classpath with a different version than the one that a dependency declares. As far as I know, the only way to fix is to explicitly declare the version of OkHttp you want to use by adding the dependency to your pom.xml which it looks like you have already done. Perhaps the comment on this issue here would fix this particular NoSuchMethodError.
Alternatively, you can switch to Gradle and use the implementation closure.
Hope that helps! Thanks.
All reactions
Thanks! I appreciate your help. I gave it a try & get same error oddly enough. I might try a couple other version numbers but it's unlikely to work.
I cloned the project, built it & can run it as its own repo but integrating it into my current maven based project doesn't look like it is going to happen. I might just listen to the data as a service over a nats message bus or something.
I've been thinking about moving to gradle but not sure. I spend a lot of time farming beets & doing beet juice cleanses :-p
Best
Dwight Schrute