Code Monkey home page Code Monkey logo

jbetfairapi's Introduction

JBetfairAPI

A JAVA Implementation of the Betfair exchange API (NG)

####How to use To be able to use this JBetfairAPI you need to have a functioning Betfair account, you can create one at www.betfair.com. Apart from a regular betting account you also need to have an application key to get access to the Betfair REST interface that JBetfairAPI relies on. Information on how to create an application key can be found here: https://api.developer.betfair.com/services/webapps/docs/x/PYAS

An example application is included, to run:

mvn clean compile assembly:single
java -jar target/JBetfairAPI-1.0-SNAPSHOT-jar-with-dependencies.jar <AppKey> <username>

JBetfairAPI currently supports the following operations:

  • listEventTypes
  • listCompetitions
  • listTimeRanges
  • listEvents
  • listMarketTypes
  • listCountries
  • listVenues
  • listMarketCatalogue
  • listMarketBook
  • listMarketProfitAndLoss
  • listCurrentOrders
  • listClearedOrders
  • placeOrders
  • cancelOrders
  • replaceOrders
  • updateOrders
  • createDeveloperAppKeys
  • getAccountDetails
  • getAccountFunds
  • getDeveloperAppKeys
  • getAccountStatement
  • listCurrencyRates

####Dependencies

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>2.17</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
    <version>2.17</version>
</dependency>

####Example code ######Login to the Betfair Exchange and retrieve a list of Soccer events in Britain

// Login to the betfair API service
ApplicationToken token = BetfairAPI.login("user", "pass", "appKey");
// Check that login went OK 
if (token.getStatus().equals(SimpleTypes.LoginStatusCode.SUCCESS)) {
    System.out.println("Failed to login with StatusCode: " + token.getStatus() + " error: " + token.getError());
    System.exit(1);
}

// Create a executor with the credentials retrieved at login
Executor exec = new BetfairExecutor();
exec.setApplicationToken(token);

// Create an OperationBuilder, this is a convenience class to create operation objects
OperationBuilder opf = new OperationBuilder(exec);

// Countries to include
Set<String> countries = new HashSet<String>();
countries.add("GB");

// Create a market filter that filters out Soccer events in Great Britain (GB)
MarketFilter filter = new MarketFilter.Builder()
    .withTextQuery("Soccer")
    .withMarketCountries(countries)
    .build();
    
// Execute the listEvents operation
ArrayList<EventResult> results = opf.listEvents(filter).build().execute();
    
// Print retrieved competitions
for(EventResult result : results) {
    System.out.println(result.getEvent().getOpenDate().toString() + " " + result.getEvent().getName());
}

######Place 100 Currency units at odds 2.5 on marketid = 1, selection = 0

Executor exec = new BetfairExecutor();
OperationBuilder opf = new OperationBuilder(exec);
String marketId = "1";
long selectionId = 0;

// Create a LimitOrder
LimitOrder limitOrder = new LimitOrder.Builder(2.5, PersistenceType.PERSIST, 100).build();

// Create a placeInstruction with OrderType = LIMIT, OrderType = BACK
PlaceInstruction instruction = new PlaceInstruction.Builder(OrderType.LIMIT, selectionId, Side.BACK).withLimitOrder(limitOrder).build();

// Create a list of PlaceInstructions and add our order
List<PlaceInstruction> instructions = new ArrayList<PlaceInstruction>();
instructions.add(instruction);

// Place Order
PlaceExecutionReport result = opf.placeOrders(marketId, instructions).build().execute();

//Do something with the result.....

jbetfairapi's People

Contributors

72miguelgomes avatar bjornn3 avatar joaogbcravo avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.