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.

Receive message to other machines on same account
 Post subject: Receive message to other machines on same account Post rating: 0   New post Posted: Fri 13 Apr, 2012, 15:59 

User rating: 0
Joined: Fri 13 Apr, 2012, 15:48
Posts: 1
THE PROBLEM: I've written a strategy that succeeds at broadcasting a message to other strategies running on the same machine, same account. However, strategies running on another machine, same account, do not receive the message.

OTHER BACKGROUND INFORMATION:

I'm currently on a demo account, if that makes a difference, as I log in with DEMO3xXxxx. My live account is in the process of funding and I would like to finish testing this in the demo account, if possible, before the live account opens.

The code for the strategy in question is shown below... it's called "football.jfx" The metaphor for this program is "passing a football" between three people (machines), each running "football" at separate locations on the same account. This program does not do any trading, but helps coordinate the trading of 3 separate machines on the same account. To do this, it both sends and receives a message to identify who "now has" the football (a status indication in a text file on each machine's C:drive). Other strategies trading on each machine can then look at that C:drive status file and act accordingly, in tandem, on a joint trading effort. This is like "team trading" one account with one member of the team playing a particular role (having the football) where that responsibility can shift among team members (by passing the football).

Here is specifically how the "football" code works: when any of the 3 machines stops and restarts this strategy, they must check one of three boxes to indicate who is now getting the ball, then the message is sent and received by all 3 machines so those status files can be updated accordingly (kept in sync as to who has the ball).

THE CODE:

package jforex;

import java.io.*;
import com.dukascopy.api.*;

@RequiresFullAccess

public class football implements IStrategy {
    private IEngine engine;
    private IConsole console;

@Configurable("Ennes") public boolean ennesGetsFootball = false;
@Configurable("Teo") public boolean teoGetsFootball = false;
@Configurable("Erto") public boolean ertoGetsFootball = false;

public String whoHasFootball;
public String theMan;
public String machineID;
public String oldFootballStatus;       
public String newFootballStatus;
public String typeOfMessage;
               
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
       
// test for valid input
    whoHasFootball = "";
    if (ennesGetsFootball) {whoHasFootball = "Ennes";}
    if (teoGetsFootball) {whoHasFootball = "Teo";}           
    if (ertoGetsFootball) {whoHasFootball = "Erto";}
    if (whoHasFootball.equals("")) {
        print("FOOTBALL: no one was selected. Program aborted.");
        context.stop(); return; }
    if ((ennesGetsFootball && !teoGetsFootball && !ertoGetsFootball) ||   
       (!ennesGetsFootball && teoGetsFootball && !ertoGetsFootball) ||   
       (!ennesGetsFootball && !teoGetsFootball && ertoGetsFootball)) {
           // do nothing - only one was selected 
       } else {
          print("FOOTBALL: more than one was selected. Program aborted.");
          context.stop(); return;
       }
     
// one entry was correctly made, so send the message out               
    engine.broadcast("footballHandoff",whoHasFootball);

    } // end of onStart routine

    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
        if (message.getContent() == null) {
            return; 
        } // else this is a football message
       
        theMan = message.getContent();
        if (theMan.equals("Teo")) {
            teoGetsFootball = true;
            ertoGetsFootball = false;
            ennesGetsFootball = false;
        } else {
            if (theMan.equals("Erto")) {
                teoGetsFootball = false;
                ertoGetsFootball = true;
                ennesGetsFootball = false;
            } else {
                if (theMan.equals("Ennes")) {
                    teoGetsFootball = false;
                    ertoGetsFootball = false;
                    ennesGetsFootball = true;
                } else {
                     return;
                }
            }
        }
    print("FOOTBALL: the football is being given to "+theMan);     
    getOldFootballStatus();
    putNewFootballStatus();
   
    } // end of onMessage section

    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 {
    }

private void print(String str) {
console.getOut().println(str);
}

public void getOldFootballStatus() {
try {
  FileReader file1 = new FileReader ("C:\\RimRockData\\Params\\Strata05FootballStatus.txt");
  BufferedReader buffer1 = new BufferedReader(file1);
  String line1 = "";
  int i = 0;
  while((line1=buffer1.readLine()) != null) {
      i++;
      switch(i) {
      case 1: machineID = String.valueOf(line1); break;
      case 2: oldFootballStatus = String.valueOf(line1); break;
      default: {
              }
          }
      }
  print("FOOTBALL: this machine's old football status: "+oldFootballStatus);   
  buffer1.close();
  }
catch(IOException e) {
  print("FOOTBALL: I/O error reading from Football Status file: "+e.getMessage());
  }
} // end of getOldFootballStatus


public void putNewFootballStatus() {

// assign new football status based on who's machine this is and whether they are to get the football 
newFootballStatus = "0";
if (machineID.equals("Erto") &&  ertoGetsFootball) {newFootballStatus = "1";}
if (machineID.equals("Teo") &&  teoGetsFootball) {newFootballStatus = "1";}
if (machineID.equals("Ennes") && ennesGetsFootball) {newFootballStatus = "1";}

/*  Diagnostics
print("newFootballStatus = "+newFootballStatus);
print("machineID = "+machineID);
print("ertoGetsFootball = "+ertoGetsFootball);
print("teoGetsFootball = "+teoGetsFootball);
print("ennesGetsFootball = "+ennesGetsFootball);
*/

try {
   FileWriter file2 = new FileWriter ("C:\\RimRockData\\Params\\Strata05FootballStatus.txt");                                       
   BufferedWriter buffer2 = new BufferedWriter(file2);
   String line2 = "";
// write machineID
   line2 = machineID;
   buffer2.write(line2);
   buffer2.newLine();
// write footballStatus
   line2 = newFootballStatus;
   buffer2.write(line2);
   buffer2.newLine();
   buffer2.close();
   print("FOOTBALL: football status on this machine has been changed to: "+newFootballStatus);
   print("FOOTBALL: %%%%%%%%%%% END OF PASS PLAY %%%%%%%%%%%%%");
}
catch(IOException e) {
   print("FOOTBALL: I/O error writing to Football Status file: "+e.getMessage());
}
} // end of putNewFootballStatus

} // end of football source code


 
 Post subject: Re: Receive message to other machines on same account Post rating: 0   New post Posted: Mon 16 Apr, 2012, 11:51 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The broadcasting happens on platform side (not the server side), hence, the message can't be received by strategies that are ran on another workstation. Theoretically you could store some information in IOrder comment field which can be set on order creation, by the following method:
https://www.dukascopy.com/client/javadoc/com/dukascopy/api/IEngine.html#submitOrder(java.lang.String,%20com.dukascopy.api.Instrument,%20com.dukascopy.api.IEngine.OrderCommand,%20double,%20double,%20double,%20double,%20double,%20long,%20java.lang.String)


 

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