Comments (13)
My hunch is that JodaMoney isn't picking up our packaged MoneyData.csv file and is instead using JodaMoney's verison.
from xchange.
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.
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:
- Pull JodaMoney's src into XChange and avoid the loading of the CSV file completely.
- Come up with XChange's own currency and "BigMoney" handling. (It's really just a 3-char String and a Big Decimal!)
- Figure out how to globally set a system property FIRST for all example classes and tests so that XChangeCurrencyUnitDataProvider is used.
- Others???
from xchange.
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.
Perfect. That's fine for now and will not cause any problems. That's the best way to fix the problem temporarily.
from xchange.
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.
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.
Raised an issue with JM.
from xchange.
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.
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.
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.
Works perfectly in Bitcoinium with latest 1.4.0-SNAPSHOT and joda-money-0.8.jar
from xchange.
OK, I'm closing this then!
from xchange.
Related Issues (20)
- Incompatibility with Jackson 2.15.x (as used by Spring Boot 3.1.x)
- is okx thread safe? HOT 2
- large backlog of pull requests HOT 34
- BINANCE FUTURE exchangeMetaData, need some advise
- Supporting Coinbase Advanced Trading
- java.lang.NoClassDefFoundError: jakarta/ws/rs/Path HOT 4
- Binance futures URL problem HOT 5
- Add bitcoin as a topic to this repository HOT 1
- [Binance-stream] Confusion about bookTicker usage HOT 1
- Converting to BinanceKlines gets this error: java.lang.String and java.lang.Boolean are in module java.base of loader 'bootstrap' HOT 7
- BitfinexAdapters.adaptTicker(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexTicker bitfinexTicker) NPE HOT 5
- Invalid Symbol Error with ByBit v5 API Integration HOT 5
- [Binance] UserReference / ClientID not populated in Trades or Orders properly
- Bybit problem with Instrument conversion for options. java.text.ParseException: Unparseable date: "31MAY24" HOT 1
- Bankera exchange exists? HOT 1
- TradeOgreAdapters.adaptCurrencyPair() build a wrong CurrencyPair HOT 2
- org.knowm.xchange.exceptions.NotYetImplementedForExchangeException: getTrades of OkexStreamingExchange HOT 2
- [Binance] Kline class cast exception HOT 1
- [Bitstamp] WithdrawalRequest object does not support txid field HOT 4
- [Bitstamp] Implement client call for the V2 withdrawal-fees endpoint HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xchange.