MoneyMechanics wrote:
I am having a problem with the OfferSide.toString() format with regards to my later use of OfferSide.valueOf(). If I use the toString() method for Filter and later use the volueOf it will work. Is it possible to standardize this?
The
toString() methods that you refer to are being used in the JForex platform so they can't be changed just like that.
MoneyMechanics wrote:
The reason I switched everything to toString() is because a custom defined Period (using createCustomPeriod) cannot use the .name() function.
Consider doing something like this:
package jforex.test;
import java.util.HashMap;
import java.util.Map;
import com.dukascopy.api.*;
import com.dukascopy.api.IIndicators.AppliedPrice;
@SuppressWarnings({ "rawtypes", "unchecked", "serial" })
public class DeserializeApiParams implements IStrategy {
Map<String,Class> apiObjectNames = new HashMap<String,Class> (){{
put("TYPICAL_PRICE", AppliedPrice.class);
put("BID", OfferSide.class);
put("TEN_MINS", Period.class);
}};
@Override
public void onStart(IContext context) throws JFException {
for(Map.Entry<String, Class> entry : apiObjectNames.entrySet()){
String name = entry.getKey();
Class clazz = entry.getValue();
Object o = null;
if(clazz.isEnum()){
o = Enum.valueOf(clazz, name);
} else {
try {
//we assume the field to be of the same class as clazz and that it is static field (no need to pass object instance)
o = clazz.getField(name).get(null);
} catch (Exception e) {
e.printStackTrace(context.getConsole().getErr());
}
}
context.getConsole().getOut().println(o.getClass().getSimpleName() + " - " + o.toString());
}
}
@Override
public void onTick(Instrument instrument, ITick tick) throws JFException {}
@Override
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
@Override
public void onMessage(IMessage message) throws JFException {}
@Override
public void onAccount(IAccount account) throws JFException {}
@Override
public void onStop() throws JFException {}
}