Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

OfferSide toString question
 Post subject: OfferSide toString question Post rating: 0   New post Posted: Tue 16 Oct, 2012, 21:24 
User avatar

User rating: 0
Joined: Thu 16 Jun, 2011, 21:37
Posts: 98
Location: SwitzerlandSwitzerland
Hi Support,

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? I was using the name() function, but have since switched everything to toString().
The reason I switched everything to toString() is because a custom defined Period (using createCustomPeriod) cannot use the .name() function.

Is it possible to have the OfferSide.toString() output a format that can be read by the valueOf function?

I have also noticed that when using the toString on Period, PriceRange and TickBarSize there are three different print conventions in use. Period outputs the number and time interval unit, PriceRange outputs the number (as a word) with an underscore and "PIPS" and lastly the TickBarSize was just a number.
Would it be be possible to standardize the output to "# 'interval unit'" as the Period.toString() method current does?
ie: "5 Mins", "4 Pips" and "10 Ticks"

Thanks again,
mm


 
 Post subject: Re: OfferSide toString question Post rating: 0   New post Posted: Tue 16 Oct, 2012, 21:29 
User avatar

User rating: 0
Joined: Thu 16 Jun, 2011, 21:37
Posts: 98
Location: SwitzerlandSwitzerland
I just realized that this not only applies to OfferSide, but also AppliedPrice. Is it possible to change the toString method for that class too?

regards,
mm


 
The Best Answer  Post subject: Re: OfferSide toString question Post rating: 0   New post Posted: Wed 17 Oct, 2012, 12:14 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
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 {}
}


Attachments:
DeserializeApiParams.java [1.77 KiB]
Downloaded 270 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: OfferSide toString question Post rating: 0   New post Posted: Wed 17 Oct, 2012, 18:53 
User avatar

User rating: 0
Joined: Thu 16 Jun, 2011, 21:37
Posts: 98
Location: SwitzerlandSwitzerland
Many thanks for this. I was thinking of doing this, but just wanted to see if it could be implemented on your end first :)

Cheers,
mm


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com