2022-11-12 02:27:46 +01:00

41 lines
1.3 KiB
Ruby

module Integrations
module Betfair
class Base
include HTTParty
API_BETTING_ENDPOINT = 'https://api.betfair.com/exchange/betting/rest/v1.0'.freeze
API_ACCOUNT_ENDPOINT = 'https://api.betfair.com/exchange/account/rest/v1.0'.freeze
def initialize(account_friendly_id)
@account = ExchangeAccount.find_by_id(account_friendly_id)
unless @account
puts "No exchange account for '#{account_friendly_id}'. Stopping"
return
end
self.class.pem @account.ssl_pem
@connection = Integrations::Betfair::Connection.new(@account)
end
def minimum_stake
1
end
def list_events(filter)
body = { filter: filter }
self.class.post("#{API_BETTING_ENDPOINT}/listEvents/", { headers: @connection.api_headers, body: body.to_json })
end
def debug_list_market_types
body = { filter: {} }
marketTypes = self.class.post("#{API_BETTING_ENDPOINT}/listMarketTypes/", { headers: @connection.api_headers, body: body.to_json })
results = []
marketTypes.each do |market|
results << market['marketType']
end
File.write(Rails.root.join('samples/bf_market_types.json'), results.join("\n"))
end
end
end
end