Class: Betfair::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/em-betfair/betfair_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

config - hash of betfair credentials & API endpoints

{ "username" => "<YOUR BETFAIR USERNAME>", "password" => "<YOUR BETFAIR PASSWORD>", "product_id" => "<YOUR BETFAIR PRODUCTID>", "exchange_endpoint" => "https://api.betfair.com/exchange/v5/BFExchangeService", "global_endpoint" => "https://api.betfair.com/global/v3/BFGlobalService" }


20
21
22
23
24
25
# File 'lib/em-betfair/betfair_client.rb', line 20

def initialize config
  @config = config
  @session_token = nil
  @num_requests = {}
  EventMachine::PeriodicTimer.new(60) { reset_requests } if EM.reactor_running?
end

Instance Attribute Details

#session_tokenObject

Returns the value of attribute session_token.



16
17
18
# File 'lib/em-betfair/betfair_client.rb', line 16

def session_token
  @session_token
end

Instance Method Details

#get_all_markets(countries = nil, event_type_ids = nil, to_date = nil, from_date = nil, &block) ⇒ Betfair::Response

Returns all the available markets on Betfair.

Parameters:

  • countries (Array) (defaults to: nil)

    array of ISO 3166-1 country codes

  • event_type_ids (Array) (defaults to: nil)

    array of Betfair event ids

  • to_date (DateTime) (defaults to: nil)

    start time range of events to retrieve

  • from_date (DateTime) (defaults to: nil)

    end time range of events to retrieve

Returns:



39
40
41
42
43
# File 'lib/em-betfair/betfair_client.rb', line 39

def get_all_markets countries=nil, event_type_ids=nil, to_date=nil, from_date=nil, &block
  with_session do
    build_request "exchange", "get_all_markets", {"countries" => countries, "event_type_ids" => event_type_ids, "to_date" => to_date, "from_date" => from_date}, block
  end
end

#get_market(market_id, &block) ⇒ Betfair::Response

Returns the details for a specifc market.

Parameters:

  • market_id (String)

    Betfair market ID

Returns:



49
50
51
52
53
# File 'lib/em-betfair/betfair_client.rb', line 49

def get_market market_id, &block
  with_session do
    build_request "exchange", "get_market", {"market_id" => market_id }, block
  end
end

#get_market_prices_compressed(market_id, currency_code = nil, &block) ⇒ Betfair::Response

Returns the compressed market prices for a specifc market.

Parameters:

  • market_id (String)

    Betfair market ID

  • currency_code (String) (defaults to: nil)

    three letter ISO 4217 country code

Returns:



70
71
72
73
74
# File 'lib/em-betfair/betfair_client.rb', line 70

def get_market_prices_compressed market_id, currency_code=nil, &block
  with_session do
    build_request "exchange", "get_market_prices_compressed", {"market_id" => market_id, "currency_code" => currency_code}, block
  end
end

#get_market_traded_volume_compressed(market_id, currency_code = nil, &block) ⇒ Betfair::Response

Returns the compressed traded volumes for a specifc market.

Parameters:

  • market_id (String)

    Betfair market ID

  • currency_code (String) (defaults to: nil)

    three letter ISO 4217 country code

Returns:



81
82
83
84
85
# File 'lib/em-betfair/betfair_client.rb', line 81

def get_market_traded_volume_compressed market_id, currency_code=nil, &block
  with_session do
    build_request "exchange", "get_market_traded_volume_compressed", {"market_id" => market_id, "currency_code" => currency_code}, block
  end
end

#get_silks_v2(market_ids, &block) ⇒ Betfair::Response

Returns the runner details for specifc markets.

Parameters:

  • market_ids (Array)

    Betfair market IDs

Returns:



59
60
61
62
63
# File 'lib/em-betfair/betfair_client.rb', line 59

def get_silks_v2 market_ids, &block
  with_session do
    build_request "exchange", "get_silks_v2", {"market_ids" => market_ids }, block
  end
end

#login(&block) ⇒ Object

Creates a session on the Betfair API, used by Betfair::Client internally to maintain session.



28
29
30
# File 'lib/em-betfair/betfair_client.rb', line 28

def  &block
  build_request "global", "login", {"username" => @config["username"], "password" => @config["password"], "product_id" => @config["product_id"]}, block
end