I've spent a few weeks investigating the response time on the new API-NG. Using various ServicePointManager settings and varying request headers, the lowest response time I can get for a single market is approx 50ms.
I've tested both endpoints JSON and REST and both give roughly the same performance.
I've also tested various 3rd party applications that are on the Vendor Program and they are reporting response times about 20ms faster on the same market.
vendor1 = 30ms - 35ms
vendor2 = 31ms - 40ms
vendor3 = 30ms - 35ms
Do apps on the vendor program get priority/faster responses? Are other people experiencing similar differences?
Can anyone suggest any further improvements to get the same speed as the vendors?
If anyone wants to test, below is some C# code that tests both the REST and JSON endpoints, the code runs on a form with 2 buttons and 3 textboxes.
Just change user details in
I've tested both endpoints JSON and REST and both give roughly the same performance.
I've also tested various 3rd party applications that are on the Vendor Program and they are reporting response times about 20ms faster on the same market.
vendor1 = 30ms - 35ms
vendor2 = 31ms - 40ms
vendor3 = 30ms - 35ms
Do apps on the vendor program get priority/faster responses? Are other people experiencing similar differences?
Can anyone suggest any further improvements to get the same speed as the vendors?
If anyone wants to test, below is some C# code that tests both the REST and JSON endpoints, the code runs on a form with 2 buttons and 3 textboxes.
Just change user details in
Code:
private string m_AppKey = "<APPKEYHERE>";
private string username = "USERNAME";
private string password = "PASSWORD";
private string m_marketId = "1.116868859";
Code:
public partial class Form1 : Form
{
//Add reference to Newtonsoft.Json
private string m_SSOID;
private string m_AppKey = "<APPKEYHERE>";
private string username = "USERNAME";
private string password = "PASSWORD";
private string m_marketId = "1.116868859";
private Stopwatch stopwatch = new Stopwatch();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = "";
stopwatch.Reset();
stopwatch.Start();
textBox2.Text = JsonEndPoint();
stopwatch.Stop();
textBox3.Text = stopwatch.Elapsed.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
textBox2.Text = "";
stopwatch.Reset();
stopwatch.Start();
textBox2.Text = RestEndPoint();
stopwatch.Stop();
textBox3.Text = stopwatch.Elapsed.ToString();
}
private string JsonEndPoint()
{
string endPoint = "https://api.betfair.com/exchange/betting/json-rpc/v1/";
string method = "SportsAPING/v1.0/listMarketBook";
string result = "";
ServicePointManager.Expect100Continue = false;
ServicePointManager.DefaultConnectionLimit = 200;
ServicePointManager.MaxServicePointIdleTime = 2000;
if (m_SSOID == null)
nonInteractiveLogin();
IList<string> marketIds = new List<string>();
marketIds.Add(m_marketId);
ISet<PriceData> priceData = new HashSet<PriceData>();
priceData.Add(PriceData.EX_BEST_OFFERS);
var priceProjection = new PriceProjection();
priceProjection.PriceData = priceData;
var args = new Dictionary<string, object>();
args["marketIds"] = marketIds;
args["priceProjection"] = priceProjection;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(endPoint);
req.AutomaticDecompression = DecompressionMethods.GZip;
req.Timeout = 10000;
req.ReadWriteTimeout = 10000;
req.Method = "POST";
req.Proxy = null;
req.KeepAlive = true;
req.ContentType = "application/json";
req.Accept = "application/json";
req.Headers.Add("X-Application", m_AppKey);
req.Headers.Add("X-Authentication", m_SSOID);
StreamWriter sw = new StreamWriter(req.GetRequestStream());
var call = new JsonRequest { Method = method, Id = 1, Params = args };
JsonConvert.Export(call, sw);
sw.Close();
using (var resp = req.GetResponse())
{
using (var sr = new StreamReader(resp.GetResponseStream()))
{
result = sr.ReadToEnd();
}
}
return result;
}
private string RestEndPoint()
{
string endPoint = "https://api.betfair.com/exchange/betting/rest/v1.0/listMarketBook/";
string result = "";
string postData = "{\"marketIds\":[\"" + m_marketId + "\"],\"priceProjection\":{\"priceData\":[\"EX_BEST_OFFERS\"]}}";
ServicePointManager.Expect100Continue = false;
ServicePointManager.DefaultConnectionLimit = 200;
ServicePointManager.MaxServicePointIdleTime = 2000;
if (m_SSOID == null)
nonInteractiveLogin();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(endPoint);
req.AutomaticDecompression = DecompressionMethods.GZip;
req.Timeout = 10000;
req.ReadWriteTimeout = 10000;
req.Method = "POST";
req.Proxy = null;
req.KeepAlive = true;
req.ContentType = "application/json";
req.Accept = "application/json";
req.Headers.Add("X-Application", m_AppKey);
req.Headers.Add("X-Authentication", m_SSOID);
StreamWriter sw = new StreamWriter(req.GetRequestStream());
sw.Write(postData);
sw.Close();
using (var resp = req.GetResponse())
{
using (var sr = new StreamReader(resp.GetResponseStream()))
{
result = sr.ReadToEnd();
}
}
return result;
}
public string nonInteractiveLogin()
{
textBox1.Text = "";
string ssoid = String.Empty;
string[] info;
try
{
string uri = string.Format("https://identitysso.betfair.com/api/login?username={0}&password={1}&login=true&redirectMethod=POST&product=home.betfair.int&url=https://www.betfair.com/", username, password);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(uri);
myRequest.Method = "POST";
myRequest.Timeout = 5000;
WebResponse thePage = myRequest.GetResponse();
info = thePage.Headers.GetValues("Set-Cookie");
int i = 0;
while (ssoid == String.Empty && i < info.Length)
{
if (info[i].Contains("ssoid="))
{
ssoid = info[i].Split(new string[] { "ssoid=" }, StringSplitOptions.None)[1].Split(';')[0];
m_SSOID = ssoid;
textBox1.Text = m_SSOID;
}
++i;
}
if (ssoid.Length == 0)
{
textBox1.Text = "Login Error";
}
}
catch (System.Exception ex)
{
Console.WriteLine("Message :{0} ", ex.Message);
}
return ssoid;
}
}


Comment