I am trying to access a json element with the name "long", but VS gives an error, it detects it as a 16 bit signed integer. The other elements in Json I can access , except element "long" and "short". Is there a way around this?
var resultOpenPositions = JsonConvert.DeserializeObject<Root>(JsonopenPositions);
string ShrtLong = resultOpenPositions.positions[0].long.units; // long here gives error , vs detects it as a 16 bit signed integer
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class Long
{
public string averagePrice { get; set; }
public string pl { get; set; }
public string resettablePL { get; set; }
public List<string> tradeIDs { get; set; }
public string units { get; set; }
public string unrealizedPL { get; set; }
}
public class Short
{
public string pl { get; set; }
public string resettablePL { get; set; }
public string units { get; set; }
public string unrealizedPL { get; set; }
public string averagePrice { get; set; }
public List<string> tradeIDs { get; set; }
}
public class Position
{
public string instrument { get; set; }
public Long @long { get; set; }
public string pl { get; set; }
public string resettablePL { get; set; }
public Short @short { get; set; }
public string unrealizedPL { get; set; }
}
public class Root
{
public string lastTransactionID { get; set; }
public List<Position> positions { get; set; }
}
here is the json part:
{
"positions": [
{
"instrument": "EUR_USD",
"long": {
"units": "1",
"averagePrice": "1.13093",
"pl": "-1077.2255",
"resettablePL": "-1077.2255",
"financing": "-48.6223",
"dividendAdjustment": "0.0000",
"guaranteedExecutionFees": "0.0000",
"tradeIDs": [
"17800"
],
"unrealizedPL": "-0.0001"
},
"short": {
"units": "0",
"pl": "-543.3196",
"resettablePL": "-543.3196",
"financing": "-3.1941",
"dividendAdjustment": "0.0000",
"guaranteedExecutionFees": "0.0000",
"unrealizedPL": "0.0000"
},
"pl": "-1620.5451",
"resettablePL": "-1620.5451",
"financing": "-51.8164",
"commission": "0.0000",
"dividendAdjustment": "0.0000",
"guaranteedExecutionFees": "0.0000",
"unrealizedPL": "-0.0001",
"marginUsed": "0.0333"
}
],
"lastTransactionID": "17800"
}