Code Monkey home page Code Monkey logo

stream-api-sample-code's Introduction

stream-api-sample-code

Sample code for the exchange stream api which provides real-time market and order data from the betfair exchange.

Console App

The console app enables you to explore most of the API functions; please note that:

  1. Your appkey must be setup for streaming (contact Developer Support via https://developer.betfair.com/support/)
  2. Credentials for .net are stored in AppData in plain text

Note: Use stream-api.betfair.com in production (stream-api-integration.betfair.com is for testing and has no backup).

Client overview

The basic client structure is separated into a number of components:

  • AppKeyAndSessionProvider - this class is used to authenticate & provide a session token.
  • Client - this class provides a connection to the stream
  • ClientCache - this class provides a thread safe cache that may be used to:
  • Respond to discrete changes
  • Respond to batch changes
  • Directly query the cache

Getting started

The below is found in the ClientCacheTest and exhibits the basic setup user story:

        //1: Create a session provider
        AppKeyAndSessionProvider sessionProvider = new AppKeyAndSessionProvider(
            AppKeyAndSessionProvider.SSO_HOST_COM,
            AppKey,
            UserName,
            Password);

        //2: Create a client
        Client client = new Client(
            "stream-api-integration.betfair.com", //NOTE: use production endpoint in prod: stream-api.betfair.com
            443,
            sessionProvider);

        //3: Create a cache
        ClientCache cache = new ClientCache(client);

        //4: Setup order subscription
        //Register for change events
        cache.OrderCache.OrderMarketChanged += 
            (sender, arg) => Console.WriteLine("Order:" + arg.Snap);
        //Subscribe to orders    
        cache.SubscribeOrders();

        //5: Setup market subscription
        //Register for change events
        cache.MarketCache.MarketChanged += 
            (sender, arg) => Console.WriteLine("Market:" + arg.Snap);
        //Subscribe to markets (use a valid market id or filter)
        cache.SubscribeMarkets("1.125037533");

Connection semantics

A few tips on basic connections:

  1. No need to explicitly start / stop if using client cache
  2. Status event allows you to monitor status
  3. AutoReconnect is enabled by default and will establish and re-subscribe any subscriptions.
  4. Exceptions are routed up to subscribe methods

Market Subscription

A few tips on market subscription:

  1. MarketDataFilter - correctly setting this on the cache improves performance
  2. MarketFilter - you are not limited to knowing specific market ids; wildcards let you know as soon as a market appears
  3. ConflateMs - you can slow down the data rate (to say a GUI refresh rate).
  4. By default markets are deleted on close

Order Subscription

A few tips on order subscription:

  1. Orders are retrieved for your id
  2. On initial connection (or re-connect) only unmatched / executable orders are returned.
  3. Matches are price point aggregated
  4. By default markets are deleted on close

Specification & Schema

###Specification: https://github.com/betfair/stream-api-sample-code/blob/master/stream-api-specification.pdf

###Schema We publish a swagger schema to define the object model: http://editor.swagger.io/#/?import=https://raw.githubusercontent.com/betfair/stream-api-sample-code/master/ESASwaggerSchema.json (Note: the stream is not a rest service so generated swagger clients are of limited use although you can use the generated object model)

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.