GithubHelp home page GithubHelp logo

Comments (13)

timmolter avatar timmolter commented on August 21, 2024

My hunch is that JodaMoney isn't picking up our packaged MoneyData.csv file and is instead using JodaMoney's verison.

from xchange.

veken0m avatar veken0m commented on August 21, 2024

Tried to update to joda-money 0.7 in Bitcoinium and I get the following error:

[2013-01-26 19:46:12 - Bitcoinium] Error generating final archive: Found duplicate file for APK: org/joda/money/MoneyData.csv
Origin 1: C:\Users\Michael\Documents\GitHub\bitcoinium\libs\joda-money-0.7.jar
Origin 2: C:\Users\Michael\Documents\GitHub\bitcoinium\libs\xchange-core-1.4.0-20130123.143334-17.jar

The MoneyData.csv files are clashing when using 0.7. This error is not present when using joda-money 0.6

Edit: Seems the joda-money-0.6.jar I was using didn't have MoneyData.csv. Must have removed it because it was causing issues...

from xchange.

timmolter avatar timmolter commented on August 21, 2024

OK, I found out what the deal is. JodaMoney has it's own MoneyData.csv file. And XChange has one too, that should override JodaMoney's. The class DefaultCurrencyUnitDataProvider.java reads the first resource named '/org/joda/money/MoneyData.csv' on the classpath. Now for whatever reason, JodaMoney's version is getting on the classpath first or there in a clash as in Michael's case.

I even tried creating my own CurrencyUnitDataProvider, and having JodaMoney use the system property:

System.setProperty("org.joda.money.CurrencyUnitDataProvider", "com.xeiam.xchange.currency.XChangeCurrencyUnitDataProvider");

, to load my CurrencyUnitDataProvider. This works, but I would need to put the following code in every unit test:

static {
// set the CurrencyUnitDataProvider for Joda Money to XChange's own implementation
System.setProperty("org.joda.money.CurrencyUnitDataProvider", "com.xeiam.xchange.currency.XChangeCurrencyUnitDataProvider");
}

, which doesn't sit with me well.

I'm going to need more time to think about this. Here are the options:

  1. Pull JodaMoney's src into XChange and avoid the loading of the CSV file completely.
  2. Come up with XChange's own currency and "BigMoney" handling. (It's really just a 3-char String and a Big Decimal!)
  3. Figure out how to globally set a system property FIRST for all example classes and tests so that XChangeCurrencyUnitDataProvider is used.
  4. Others???

from xchange.

DougTanner avatar DougTanner commented on August 21, 2024

That sounds like what was happening, I eventually got it to work by adding the following line to MoneyData.csv in my own compiled Joda:
BTC,1,3,ZZ
Will this cause any problems for me if I try to execute trades?

What is the best way to fix this locally for me (temporarily)?

from xchange.

timmolter avatar timmolter commented on August 21, 2024

Perfect. That's fine for now and will not cause any problems. That's the best way to fix the problem temporarily.

from xchange.

gary-rowe avatar gary-rowe commented on August 21, 2024

Pulling JodaMoney's (JM's) code into XChange will lead to endless merge and conflict issues that we don't want. Re-writing JM to suit XChange will mean we miss out on a wide range of potential bugs discovered in the main project and not ported to our fork.

Another option is to simply offer a pull request to the JM guys and ask for BTC,-1,-1, to be added to their currency file. Then there is no longer a problem.

As a backup plan in case we can't get BTC in there, I've taken a look at Tim's solution involving XChangeCurrencyUnitDataProvider in combination with XChangeCurrencies.csv and I think it is probably the next best approach.

The system property appears to be the recommended way of implementing the behaviour judging by the code in JM's CurrencyUnit. It does raise the problem of initialisation order, though. Using a static block approach opens us up to an execution order problem. We must ensure that XChange classes are referenced before JM CurrencyUnit otherwise the wrong currency unit provider will be referenced. This could be a problem if people decide to have XChange as a "load on demand" type feature with JM being at the core of their design. The JM code will clearly get referenced first, with XChange coming along as an optional second.

Therefore, I would lean towards having a dedicated XChange initialisation code block that does nothing other than configure JM to use our currency list. This would mean code like the following in MoneyUtils.

public static final String JODA_MONEY_DEFAULT = "org.joda.money.DefaultCurrencyUnitDataProvider";
public static final String XCHANGE_DEFAULT = "com.xeiam.xchange.currency.XChangeCurrencyUnitDataProvider";

... 

public static void setCurrencyUnitDataProvider(String currencyUnitDataProvider) {
System.setProperty("org.joda.money.CurrencyUnitDataProvider",currencyUnitDataProvider);
}

and then encouraging people to put this in their startup code:

    MoneyUtils.setCurrencyUnitDataProvider(MoneyUtils.XCHANGE_DEFAULT);

This then allows the external user to set their own currency provider through a simple mechanism that is respected by XChange. Later on if JM adopts Bitcoin then we can simply change the recommendation and point XCHANGE_DEFAULT to the JM implementation.

How does that sound?

from xchange.

timmolter avatar timmolter commented on August 21, 2024

That sounds good, Gary, especially for now in the short term as I'm trying to get 1.4.0 out the door. I wonder if it would make more sense in the medium/long-term to ask JM to provide a public method to overwrite the loaded MoneyData.csv file. That way, in exchange, we could simple enforce/recommend that all currency handling is doen through MoneyUtils, and we can make sure that our CSV file is loaded. That way, the burden isn't on the end user to understand what MoneyUtils.setCurrencyUnitDataProvider(MoneyUtils.XCHANGE_DEFAULT); does and why they need it. I can see them not using it, and getting lots of "bug reports" about it.

If we could change JM, would having that public override method be the best solution? Or can you think of an even better solution? I'm sure if we tell JM about our issue and suggest an elegant solution, he'd happily accept a pull request that fixes it.

from xchange.

gary-rowe avatar gary-rowe commented on August 21, 2024

Raised an issue with JM.

from xchange.

gary-rowe avatar gary-rowe commented on August 21, 2024

Looks like this will be fixed in the 0.8 release of Joda Money. Can close this issue when we see it in Maven Central.

from xchange.

timmolter avatar timmolter commented on August 21, 2024

JodaMoney was updated to 0.8, which includes a solution to this problem.

Doug and Michael, can you test this?? It should work fine now.

from xchange.

timmolter avatar timmolter commented on August 21, 2024

The latest snapshot jar is here: https://oss.sonatype.org/content/groups/public/com/xeiam/xchange/xchange-core/1.4.0-SNAPSHOT/

You'll need the newest one.

from xchange.

veken0m avatar veken0m commented on August 21, 2024

Works perfectly in Bitcoinium with latest 1.4.0-SNAPSHOT and joda-money-0.8.jar

from xchange.

timmolter avatar timmolter commented on August 21, 2024

OK, I'm closing this then!

from xchange.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.