如何从 Ninja Trader 的操作中使用 C# 制作 JSON post?
How to make a JSON post using C# from the operations of Ninja Trader?
我需要从 Ninja Trader 执行 JSON CSharp Post 到 Interactive Broker 的 Api C#,使用以下内容:
{
"Instrument": "SIE",
"Side": "BUY",
"Volume": "200",
"Price": "100",
"Type": "LMT",
"Accounts": ["DU1107110", "DU1107170", "DU1107180", "DU1107190"],
"Currency": "EUR",
"Exchange": "SMART",
"SecType": "STK",
"PrimaryExch": "",
"Gives you": ""
}
您需要先使用数据创建一个c#对象。
那么您需要序列化该对象,例如
var json = JsonConvert.SerializeObject(数据);
现在您需要做的就是将字符串传递给 post 方法。
var stringContent = new StringContent(json, UnicodeEncoding.Utf8, "application/json");
var client = new HttpClient();
var response = await client.PostAsync(uri, stringContent);
非常感谢!我能够做到这一点:
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);
/---------------------/
protected void postToInteractiveBroker(ExpandoObject jsonObject)
{
var json = JsonConvert.SerializeObject(jsonObject);
var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
var client = new HttpClient();
var response = client.PostAsync("http://localhost:59251/api/trades", stringContent);
Print("- - - - - - - | POST TO INTERACTIVE BROKER | - - - - - - ");
Print(response);
Print("- - - - - - - | END POST TO INTERACTIVE BROKER | - - - - - - ");
}
我需要从 Ninja Trader 执行 JSON CSharp Post 到 Interactive Broker 的 Api C#,使用以下内容:
{
"Instrument": "SIE",
"Side": "BUY",
"Volume": "200",
"Price": "100",
"Type": "LMT",
"Accounts": ["DU1107110", "DU1107170", "DU1107180", "DU1107190"],
"Currency": "EUR",
"Exchange": "SMART",
"SecType": "STK",
"PrimaryExch": "",
"Gives you": ""
}
您需要先使用数据创建一个c#对象。 那么您需要序列化该对象,例如 var json = JsonConvert.SerializeObject(数据);
现在您需要做的就是将字符串传递给 post 方法。
var stringContent = new StringContent(json, UnicodeEncoding.Utf8, "application/json");
var client = new HttpClient(); var response = await client.PostAsync(uri, stringContent);
非常感谢!我能够做到这一点:
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);
/---------------------/
protected void postToInteractiveBroker(ExpandoObject jsonObject)
{
var json = JsonConvert.SerializeObject(jsonObject);
var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
var client = new HttpClient();
var response = client.PostAsync("http://localhost:59251/api/trades", stringContent);
Print("- - - - - - - | POST TO INTERACTIVE BROKER | - - - - - - ");
Print(response);
Print("- - - - - - - | END POST TO INTERACTIVE BROKER | - - - - - - ");
}