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.

order amount currency and account equity currency
 Post subject: order amount currency and account equity currency Post rating: 0   New post Posted: Fri 01 Jul, 2011, 10:08 
User avatar

User rating: 6
Joined: Thu 19 May, 2011, 11:14
Posts: 235
Location: South Africa,
Suppose the account currency and the instrument being traded are unknown at compile time:
What is the simplest way to open a position with amount = K*equity ?
(where K is a given constant)

Since order amounts are specified in the instrument's primary currency, while account equity is provided in account currency, I am thinking of using this messy conversion:
    private double getEquityInPrimaryCurrency(Instrument i) {
        Currency pri = i.getPrimaryCurrency();
        Currency acc = context.getAccount().getCurrency();
       
        double r;
       
        if(pri.equals(acc)){
            r = 1;
        } else {
            String priCode = pri.getCurrencyCode();
            String accCode = acc.getCurrencyCode();

            Instrument ratio = Instrument.fromString(priCode + '/' + accCode);
            try{
                if(ratio != null){
                    r = 1/context.getHistory().getLastTick(ratio).getBid();
                } else {
                    ratio = Instrument.fromString(accCode + '/' + priCode);
                    r = context.getHistory().getLastTick(ratio).getBid();
                }
            } catch (JFException ex){
                console.getErr().println("Cannot determine ratio between " + priCode + " and " + accCode + ". Try subscribing to the relevant instrument.");
                r = 0;
            }
        }
        return context.getAccount().getEquity()*r;
    }
And then to submit:
context.getEngine().submitOrder(label, instrument, orderCommand, K*getEquityInPrimaryCurrency(instrument))

But this is messy and sometimes would require subscription to an extra instrument. Is there in the API a better solution that I am missing?


 
 Post subject: Re: order amount currency and account equity currency Post rating: 0   New post Posted: Mon 04 Jul, 2011, 17:02 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Isak wrote:
But this is messy and sometimes would require subscription to an extra instrument. Is there in the API a better solution that I am missing?
No, at the current implementation there is not.


 

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