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.

Is there possible to get IContext.getFilesDir() from outside a IStrategy object?
 Post subject: Is there possible to get IContext.getFilesDir() from outside a IStrategy object? Post rating: 0   Post Posted: Thu 19 Mar, 2015, 12:35 

User rating: 0
Joined: Wed 12 Jun, 2013, 16:19
Posts: 18
Location: PolandPoland
Hello

I need a "IContext.getFilesDir()" path in IClient connection process - it's any way to get this path outside a IStrategy object?

Simple example:

public class Main {
    private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);

    //url of the DEMO jnlp
    private static String jnlpUrl = "https://www.dukascopy.com/client/demo/jclient/jforex.jnlp";
    //user name
    private static String userName = "SampleLogin";
    //password
    private static String password = "SamplePassword";

    public static void main(String[] args) throws Exception {
        //get the instance of the IClient interface
        final IClient client = ClientFactory.getDefaultInstance();
       
        //...
       
        //start the strategy
        LOGGER.info("Starting strategy");
        client.startStrategy(new MA_Play());
        //now it's running

        // Copying required libraries before compile
        File destDir = new File("/home/work/JForex/Strategies/files"); // I NEED IContext.getFilesDir() PATH HERE
        File srcFile = new File("/some/path/MyLib.jar");
        FileUtils.copyFileToDirectory(srcFile, destDir);
    }
}



 
 Post subject: Re: Is there possible to get IContext.getFilesDir() from outside a IStrategy object? Post rating: 0   Post Posted: Thu 19 Mar, 2015, 15:39 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
It is possible to do this already

   
public class Main {
    static IClient client;
    static File destDir;

    public static void main(String[] args) throws Exception {
        //get the instance of the IClient interface
        client = ClientFactory.getDefaultInstance();
         
        //...
         
        //start the strategy
        client.startStrategy(new Dummy());
    }

   
    public static void startNext() {
        client.startStrategy(new Strategy());
    }

    public static class Dummy implements IStrategy {
        public void onStart(IContext context) throws JFException {
            destDir = context.getFilesDir();
            startNext();
            context.stop();
        }
        public void onAccount(IAccount account) throws JFException {
        }
        public void onMessage(IMessage message) throws JFException {
        }
        public void onStop() throws JFException {
        }
        public void onTick(Instrument instrument, ITick tick) throws JFException {
        }
        public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        }
    }


 
 Post subject: Re: Is there possible to get IContext.getFilesDir() from outside a IStrategy object? Post rating: 0   Post Posted: Thu 19 Mar, 2015, 17:11 

User rating: 0
Joined: Wed 12 Jun, 2013, 16:19
Posts: 18
Location: PolandPoland
A solution with using the inner (static) class it's look very strange (and it's not a perfect coding example) :) (previously I thinking about any method directly from API)
But.. thanks for the quick answer..
In the future I suggest You to add much easier solution (like method: IClient.getFilesDir()) in next SDK release :)

Regards
Mariusz


 

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