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.

Run jforex-sdk client without disk writes
 Post subject: Run jforex-sdk client without disk writes Post rating: 0   New post Posted: Wed 18 Dec, 2013, 17:27 

User rating: 0
Joined: Thu 12 Dec, 2013, 20:09
Posts: 5
Location: France,
I would like to configure jForex-SDK to do no disk write and read operation, because I'd run a program on a remote server where I don't have write rights.
Is it possible, to disable the writing operations? probably it's for cache, but I will not use history functions, it's just for live ticks

Thanks


 
 Post subject: Re: Run jforex-sdk client without disk writes Post rating: 0   New post Posted: Thu 19 Dec, 2013, 08:34 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
If you don't subscribe to any instruments from IClient, then the cache should not get read, for running a remote strategy from the SDK, use IClient.getRemoteStrategyManager().startStrategy.


 
 Post subject: Re: Run jforex-sdk client without disk writes Post rating: 0   New post Posted: Thu 19 Dec, 2013, 13:47 

User rating: 0
Joined: Thu 12 Dec, 2013, 20:09
Posts: 5
Location: France,
I'm running it from a servlet, this is the error:
com.dukascopy.charts.data.datacache.DataCacheException: Cannot create cache directory [/temp/.cache]. File.exists() - [false] File.mkdirs() - [false]
   at com.dukascopy.charts.data.datacache.CacheManager.<init>(CacheManager.java:170)
   at com.dukascopy.charts.data.datacache.CacheManager.<init>(CacheManager.java:97)
   at com.dukascopy.charts.data.datacache.LocalCacheManager.<init>(LocalCacheManager.java:98)
   at com.dukascopy.charts.data.datacache.FeedDataProvider.<init>(FeedDataProvider.java:202)
   at com.dukascopy.charts.data.datacache.FeedDataProvider.createFeedDataProvider(FeedDataProvider.java:271)
   at com.dukascopy.charts.data.datacache.FeedDataProvider.createFeedDataProvider(FeedDataProvider.java:247)
   at com.dukascopy.api.impl.connect.DCClientImpl.connect(DCClientImpl.java:258)
   at com.dukascopy.api.impl.connect.DCClientImpl.connect(DCClientImpl.java:232)
   at ws.Main.startJforex(Main.java:81)
   at ws.MiscServlet.init(MiscServlet.java:38)
   at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1235)
   at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1148)
   at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1044)
   at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5013)
   at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5310)
   at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
   at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
   at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
   at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:698)
   at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1119)
   at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1760)
   at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
   at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
   at java.util.concurrent.FutureTask.run(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)


and the code:
    public static void startJforex() throws Exception {

        final IClient client = ClientFactory.getDefaultInstance();
        client.setSystemListener(new ISystemListener() {
            private int lightReconnects = 3;
            public void onStart(long processId) {
            }
            public void onStop(long processId) {
                if (client.getStartedStrategies().size() == 0) {
                    System.exit(0);
                }
            }
            public void onConnect() {
                lightReconnects = 3;
            }
            public void onDisconnect() {
                if (lightReconnects > 0) {
                    client.reconnect();
                    --lightReconnects;
                } else {
                    try {
                        Thread.sleep(10000);
                    } catch (InterruptedException e) {
                    }
                    try {
                        client.connect(jnlpUrl, userName, password);
                    } catch (Exception e) {
                    }
                }
            }
        });
        client.connect(jnlpUrl, userName, password);

        int i = 10; //wait max ten seconds
        while (i > 0 && !client.isConnected()) {
            Thread.sleep(1000);
            i--;
        }
        if (!client.isConnected()) {
            System.exit(1);
        }
        /*Set<Instrument> instruments = new HashSet<Instrument>();
        instruments.add(Instrument.EURUSD);
        client.setSubscribedInstruments(instruments);*/
        Thread.sleep(5000);
        System.out.println("------Strategy starting");
        client.startStrategy(new Strategy());
    }


public class Strategy implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;

    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
        this.userInterface = context.getUserInterface();

        System.out.println("------Strategy started");

        Set<Instrument> instruments = new HashSet<Instrument>();
        instruments.add(Instrument.EURUSD);
        context.setSubscribedInstruments(instruments);
    }

    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 {

        DBObject o=new BasicDBObject("time", tick.getTime())
                .append("bid", tick.getBid())
                .append("totalBidVolume", tick.getTotalBidVolume())
                .append("bids", tick.getBids())
                .append("bidVolumes", tick.getBidVolumes())
                .append("ask", tick.getAsk())
                .append("totalAskVolume", tick.getTotalAskVolume())
                .append("asks", tick.getAsks())
                .append("askVolumes", tick.getAskVolumes());

        WsServlet.broadcast("ticks", o.toString());

    }

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}


 
 Post subject: Re: Run jforex-sdk client without disk writes Post rating: 0   New post Posted: Thu 19 Dec, 2013, 15:15 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
How do you upload the strategy if you don't have write access?

Maybe an alternative solution is to modify the cache location to a directory (your home directory for instance?) where you have write access? See https://www.dukascopy.com/client/javadoc ... io.File%29

        instruments.add(Instrument.EURUSD);
        context.setSubscribedInstruments(instruments);

Here you subscribe to the EURUSD instrument.


 
 Post subject: Re: Run jforex-sdk client without disk writes Post rating: 0   New post Posted: Thu 19 Dec, 2013, 16:07 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
I think you need to re-think what you're trying to do.

A servlet is not designed to run something "persistent"
like an IClient which is itself running IStrategy instances.
A servlet instance is not designed as a long-running process.

And the servlet "container" is "sandboxed" with restrictions
as you can see.

What are you really trying to do? I think your overall
design needs to be reconsidered to accomplish your
goals. If you need a persistent IClient running, you can't
do it as a servlet, or you shouldn't even try to do it
in that way.

Give us more details, like do you have shell access to your
server? I wrote an IClient API hosting process which runs
N concurrent IStrategies, and this process embeds a Jetty
servlet container so that I can gain access to the strategies
at runtime through a browser interface.

So it embeds a servlet container environment, but it does
not run *inside* a servlet container as a servlet...

HyperScalper


 
 Post subject: Re: Run jforex-sdk client without disk writes Post rating: 0   New post Posted: Thu 19 Dec, 2013, 19:34 

User rating: 0
Joined: Thu 12 Dec, 2013, 20:09
Posts: 5
Location: France,
tcsabina wrote:
How do you upload the strategy if you don't have write access?

I can't write anywhere, it's being run on a cloud Host for java applications(https://www.cloudbees.com/)

hyperscalper wrote:
What are you really trying to do?

A simple web order-book

Thanks for your support, this is not something important, it was a small attempt to make a web widget based on jforex ticks


 

Jump to:  

cron
  © 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