Problem placing bets through API

Post Reply
edmundo
Posts: 2
Joined: Fri May 11, 2018 12:49 pm

Hello I am coding in Java and trying to place bets through the API using the JBetfairNG (From here: https://github.com/joelpob/jbetfairng).

Code: Select all

    public void placeBets(String marketId, Object[][] bets){

        List<PlaceInstruction> betInstructions = new ArrayList<>();
        PlaceInstruction p;
        LimitOrder l;
        System.out.println("Market\tSelection\tHandicap\tSide\tOrderType\tPrice\tSize\tPersistenceType");
        for (Object[] bet : bets) {

            l = new LimitOrder();
            l.setPrice(scaleUp((Double) bet[2]));
            l.setSize((Double) bet[3]);
            l.setPersistenceType(PersistenceType.PERSIST);

            p = new PlaceInstruction();
            p.setOrderType(OrderType.LIMIT);
            p.setSide(Side.BACK);
            p.setSelectionId((Long) bet[0]);
            p.setHandicap(0d);
            p.setLimitOrder(l);

            System.out.println(marketId + "\t" + p.getSelectionId() + "\t" + p.getHandicap() + "\t" + p.getSide() + "\t" +
                    p.getOrderType() + "\t" + l.getPrice() + "\t" + l.getSize() + "\t" + l.getPersistenceType());
            betInstructions.add(p);
        }
        try {
            BetfairServerResponse<PlaceExecutionReport> resp = client.placeOrders(marketId, betInstructions, "");
            PlaceExecutionReport report = resp.getResponse();
            System.out.println(report.getStatus());

        }catch(Exception e){
            e.printStackTrace();
        }
    }


Knowledge of the object[][] bets is not important, the printed output tells us all we need to know:
Market Selection Handicap Side OrderType Price Size PersistenceType
1.143621348 269469 0.0 BACK LIMIT 2.02 2.0 PERSIST
And here the debug variable information shows exactly the request we are making:

https://imgur.com/PLfUbWv

So why is the response returning null? Does anyone see a problem with my request?
The bet is not appearing in my account when betfair viewed in web browser.

Thanks
User avatar
northbound
Posts: 737
Joined: Mon Mar 20, 2017 11:22 pm

I use PHP and am not too familiar with Java, but here are some observations that might help you debug your app.

1 - If you send the placeOrder request from the IP address of a country where Betfair can’t accept bets, the bet won’t get placed.

2 - The placeOrder request body should have an “instructions” section. Not sure why in your code it is called “betInstructions”. Its content looks fine though.

3 - Are you sending the relevant credentials with each API request you make? Application ID, session token...
xitian
Posts: 457
Joined: Fri Jul 08, 2011 2:08 pm

I'd recommend spitting out the actual full JSON of the request you're sending and inspect that for errors.

And like northbound says, make sure you've included all the right headers and so on.

Is the login request returning successfully then? And simple things like listMarketBook for the market you're trying to place a bet on?
edmundo
Posts: 2
Joined: Fri May 11, 2018 12:49 pm

Got it thanks! I was passing in an empty String for the customer reference and it didn't like that!
Post Reply

Return to “Betfair Exchange API”