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.

Position summary - how to get data?
 Post subject: Position summary - how to get data? Post rating: 0   New post Posted: Mon 13 Jun, 2016, 13:11 
User avatar

User rating: 0
Joined: Sun 28 Feb, 2016, 22:52
Posts: 4
Location: PolandPoland
Hello,

how can I access data that are presented in "Position summary" tab? I've searched JForex API, but found nothing. Specifically I need to obtain effective size and price of all open orders treated as single order. I can easily calculate effective size of all the open orders, but don't know how to calculate resulting price when there are both buy and sell orders.

Best regards,
Sebastian


 
 Post subject: Re: Position summary - how to get data? Post rating: 0   New post Posted: Tue 14 Jun, 2016, 08:35 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hello,

Unfortunately, there's no option how to get to "Position Summary" tab. However, you can retrieve all orders made by your account and distinguish orders by state and OrderCommand (Buy/Sell).
This could be done easily by following example:
import com.dukascopy.api.*;

import java.util.List;

public class GetDataOrders implements IStrategy {

    private IEngine engine;
    private IConsole console;

    @Override
    public void onStart(IContext context) throws JFException {
        console = context.getConsole();
        engine = context.getEngine();

        List<IOrder> ordersList = engine.getOrders();

        console.getOut().println("\nCurrently opened " + ordersList.size() + " positions.\n");
        for (IOrder order : ordersList) {
            context.getConsole().getOut().println(
                    "Order ID: " + order.getId()
                    +"\t|\tState: " + order.getState()
                    +"\t|\tOrder Command: " + order.getOrderCommand()
                    +"\t\t|\tPrice:" + order.getOpenPrice()
                    +"\t\t|\tAmount: " + order.getAmount()
            );
        }

        double totalAmount = 0;
        double total = 0;
        for (IOrder order : ordersList) {
            if (order.getState() == IOrder.State.FILLED &&
                order.getOrderCommand() == IEngine.OrderCommand.BUY ||
                    order.getOrderCommand() == IEngine.OrderCommand.SELL) {
                totalAmount += order.getAmount();
            }
        }

        for(IOrder order : ordersList) {
            if (order.getState() == IOrder.State.FILLED &&
                    order.getOrderCommand() == IEngine.OrderCommand.BUY ||
                        order.getOrderCommand() == IEngine.OrderCommand.SELL) {
                total += order.getAmount() * order.getOpenPrice() / totalAmount;
            }
        }

        console.getOut().println("=========================== STATISTICS ===========================");
        console.getOut().println("Total amount: " + totalAmount);
        console.getOut().println("Total price: " + total);
    }

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

    }
}

Learn more about IOrder & IEngine: here

Good luck and have a nice day


 
 Post subject: Re: Position summary - how to get data? Post rating: 0   New post Posted: Wed 15 Jun, 2016, 08:20 
User avatar

User rating: 0
Joined: Sun 28 Feb, 2016, 22:52
Posts: 4
Location: PolandPoland
Hi,

thank you for your response. I was hoping that instead of calculating these valuses I can rely on values already calculaded by platform. So I will have to calculate it on my own, but that's no big deal. Regarding your example - second ("statistics") part gives correct results only for long OR short orders (as it just calculates average entry price), but fails for mix of both long and short orders.

Regards,
Sebastian


 
 Post subject: Re: Position summary - how to get data? Post rating: 0   New post Posted: Wed 15 Jun, 2016, 14:53 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We do not plan to implement separate method for this in the API.


 

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