XChange icon indicating copy to clipboard operation
XChange copied to clipboard

How do I run something as simple as TickerDemo.java under BTC-E?

Open mahrens917 opened this issue 12 years ago • 6 comments

I am new to java and cannot get the code to run.

I am running this:

ubuntu@ip-172-31-28-169:~/XChange/xchange-examples/src/main/java$ javac com/xeiam/xchange/examples/btce/BTCEExamplesUtils.java

And I get:

com/xeiam/xchange/examples/btce/BTCEExamplesUtils.java:24: error: cannot find symbol import com.xeiam.xchange.Exchange; ^ symbol: class Exchange location: package com.xeiam.xchange com/xeiam/xchange/examples/btce/BTCEExamplesUtils.java:25: error: cannot find symbol import com.xeiam.xchange.ExchangeFactory; ^ symbol: class ExchangeFactory location: package com.xeiam.xchange

How do I get started? Thanks!

mahrens917 avatar Apr 01 '14 03:04 mahrens917

Tim, this product looks great - I just sent you some bitcoin to help with your bounties.

mahrens917 avatar Apr 01 '14 04:04 mahrens917

@mahrens917 Thanks for the BTC! I'll put it to good use.

If you're brand new to Java, you'll need to spend some time learning the basics. You'll need to learn the difference between the commands java and javac and what the classpath is. XChange has a bunch of dependencies and you'll need them to be on the classpath.

Here's the command I've used to test the last 1.10.0 release:

cd ~/workspaces/workspace_xeiam_oss/XeiamReleaseTest/lib
java -cp xchange-examples-1.10.0.jar:xchange-core-1.10.0.jar:xchange-mtgox-1.10.0.jar:slf4j-api-1.7.5.jar:rescu-1.5.0.jar:Java-WebSocket-1.3.0.jar:jackson-databind-2.1.1.jar:jackson-annotations-2.1.1.jar:jackson-core-2.1.1.jar:joda-money-0.9.jar:xchart-2.2.1.jar:jsr311-api-1.1.1.jar com.xeiam.xchange.examples.mtgox.v2.service.marketdata.polling.MtGoxOrderBookChartDemo

It won't work anymore of course since MtGox is dead, but it shows the correct command setup.

You'll also want the latest 2.0.0-SNAPSHOT jars as the 1.10.0 version is quite outdated. You can find them here: https://oss.sonatype.org/content/groups/public/com/xeiam/xchange/

Good luck.

timmolter avatar Apr 01 '14 07:04 timmolter

In case anyone else has the same issue as I do here are the steps I did to get this working:

  1. Install Eclipse
  2. Install Maven through the Eclipse Marketplace under the Eclipse Help menu
  3. Open Eclipse
  4. File -> New -> Project… -> Maven/Maven Project
  5. Check create simple project. You could use default location or uncheck checkbox and select new location.
  6. Write something to groupId and artifactId. Also you could fill Name & Description fields. Click finish.
  7. Open pom.xml file Add next code below <version/> tag
 and within <dependencies>:
    <dependency>
        <groupId>com.xeiam.xchange</groupId>
        <artifactId>xchange-core</artifactId>
        <version>2.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.xeiam.xchange</groupId>
        <artifactId>xchange-examples</artifactId>
        <version>2.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.xeiam.xchange</groupId>
        <artifactId>xchange-bitstamp</artifactId>
        <version>2.0.0</version>
    </dependency>
  1. Click save
  2. Select project - right click and choose Maven -> Update Project… and select Force Update before you hit OK.
  3. Now under the Maven dependencies folder you could open xchange-example-2.0.0.jar and find examples (for example, in com.xeiam.xchange.examples.bitstamp.marketdata you could see TickerDemo.class. You could look it source or run it (right click on the TickerDemo.class, select Run As -> Java Application).
  4. You could create your classes inside src/main folder. Copy TickerDemo.class and remove the package line and rename the class the filename of the class file created under src/main/java

mahrens917 avatar Apr 16 '14 21:04 mahrens917

@mahrens917 Yes, that's exactly right! I formatted your above comment to display the XML properly. Would it be OK if I added your above instructions to out Wiki to better help others?

timmolter avatar Apr 17 '14 07:04 timmolter

Yes, of course, that would be great!

mahrens917 avatar Apr 17 '14 10:04 mahrens917

I finally got around to doing putting a guide together: https://github.com/timmolter/XChange/wiki/Getting-Started-with-XChange-for-Noobies

timmolter avatar Aug 11 '14 20:08 timmolter