我需要执行以下操作,从Ninja Trader到Interactive Broker的Api C#发送一个JSON CSharp帖子:
{
"Instrument": "SIE",
"Side": "BUY",
"Volume": "200",
"Price": "100",
"Type": "LMT",
"Accounts": ["DU1107110", "DU1107170", "DU1107180", "DU1107190"],
"Currency": "EUR",
"Exchange": "SMART",
"SecType": "STK",
"PrimaryExch": "",
"Gives you": ""
}
答案 0 :(得分:0)
您需要先使用数据创建一个c#对象。 那么您需要序列化该对象,例如 var json = JsonConvert.SerializeObject(data);
现在您要做的就是将字符串传递给post方法。
var stringContent = new StringContent(json,UnicodeEncoding.Utf8,“ application / json”);
var client = new HttpClient(); var response = await client.PostAsync(uri,stringContent);
答案 1 :(得分:0)
非常感谢!我能够做到这一点:
maxChar('355385')
"5"
/ --------------------- /
dynamic jsonObject = new ExpandoObject();
jsonObject.Instrument= "SIE"; //Instrument.FullName
jsonObject.Side= "BUY";
jsonObject.Volume=quantity;
jsonObject.Price= "100";
jsonObject.Type= "LMT";
jsonObject.Accounts = new string[1];
jsonObject.Accounts[0] = "DU1107160";
jsonObject.Currency= "EUR";
jsonObject.Exchange= "SMART";
jsonObject.SecType= "STK";
jsonObject.PrimaryExch= "";
jsonObject.Date= "";
postToInteractiveBroker(jsonObject);