c# - 有没有人有使用 betfair api 的 c# 代码?

标签 c# betfair

我正在使用 betfair exchange webservice 创建一个 c# windows 应用程序来显示当前的体育市场汇率,我使用了

getmarketpricescompressed()

返回如下价格字符串的方法:

106093239~GBP~ACTIVE~0~1~~true~5.0~1343114432333~~N:7337~1~6992.56~2.16~~~false~~~~|2.16~1036.19~L~1~2.14~97.18~L~2~2.12~5.0~L~3~|2.18~467.36~B~1~2.2~34.12~B~2~2.22~162.03~B~3~:414464~2~102181.96~1.86~~~false~~~~|1.85~2900.33~L~1~1.84~1831.59~L~2~1.83~1593.73~L~3~|1.86~58.83~B~1~1.87~1171.77~B~2~1.88~169.15~B~3~

我不知道如何正确解压这个字符串,现在我正在使用这个代码:

GetMarketPricesCompressedReq price_req1 = new GetMarketPricesCompressedReq();
            price_req1.header = header2;
            price_req1.marketId = marketid_temp;
            price_req1.currencyCode = "GBP";
            GetMarketPricesCompressedResp price_resp = new GetMarketPricesCompressedResp();
            price_resp = bfg2.getMarketPricesCompressed(price_req1);
            //MessageBox.Show(price_resp.errorCode.ToString());
            //richTextBox1.Text = "";
            //richTextBox1.Text = price_resp.marketPrices;
            string prices = price_resp.marketPrices;
            richTextBox1.Text = price_resp.marketPrices;
            string[] ab1 = prices.Split('|');
            string[] temp = ab1[1].Split('~');
            textBox3.Text = temp[0];
            textBox4.Text = temp[4];
            textBox5.Text = temp[8];
            temp = ab1[2].Split('~');
            textBox6.Text = temp[0];
            textBox7.Text = temp[4];
            textBox8.Text = temp[8];
            temp = ab1[3].Split('~');
            textBox9.Text = temp[0];
            textBox10.Text = temp[4];
            textBox11.Text = temp[8];
            temp = ab1[4].Split('~');
            textBox12.Text = temp[0];
            textBox13.Text = temp[4];
            textBox14.Text = temp[8];
            if (ab1.Length >5)
            {
                temp = ab1[5].Split('~');
                textBox15.Text = temp[0];
                textBox16.Text = temp[4];
                textBox17.Text = temp[8];
                temp = ab1[6].Split('~');
                textBox18.Text = temp[0];
                textBox19.Text = temp[4];
                textBox20.Text = temp[8];
            }

它在一些匹配中工作正常,但我观察到其他一些匹配的字符串发生变化,因此会产生异常, any1 能帮我用正确的代码来解压这个字符串吗,我用谷歌搜索了一下,找到了一个 vb 代码,它不是很有用,

顺便说一句,我想按如下方式排列数据:

enter image description here

最佳答案

考虑以下几点:

a|b|c|d

在这里,你有四个 block 。但不一定只有四个。可以是两个,也可以是六个。

尝试通过迭代您作为

的结果获得的字符串数组来进行操作
string[] ab1 = prices.Split('|');

有点像

foreach(var stringChunk in ab1)
{
    string[] temp = stringChunk.Split('~');
    // use the strings here as you please
}

考虑使用更动态的方法来呈现您的数据,使用基于行的重复控件而不是静态文本框。 =)

压缩数据的完整文档可在此处获得:https://docs.developer.betfair.com/betfair/#!page=00008360-MC.00008307-MC

关于c# - 有没有人有使用 betfair api 的 c# 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11625586/

相关文章:

c# - 使用某种编程语言 (JS/C#..) 计算 RSI(相对强弱指数)

c# - 调用 FileOpenPicker.PickSingleFileAndContinue() 时总是得到 "Access is denied"

c# - 为来自远程 api 的字典定义 Elasticsearch 映射

c# - .NET Core - HttpClient 与 RestSharp

c# - Linq to SQL 嵌套对象

c# - 在运行时按程序创建和命名对象

ios - BetFair 登录 API/iOS 中的 INPUT_VALIDATION_ERROR

php - 每 15 秒执行一次 cron

c++ - 无法使用 OpenSSL 验证服务器证书