JSON

Created at 17 Jul 2014, 10:29
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
MA

MarsBarsLars

Joined 17.07.2014

JSON
17 Jul 2014, 10:29


Hi,

How do I include JSON serialization?

Is there an included library?

MarsBarsLars


@MarsBarsLars
Replies

Invalid
17 Jul 2014, 10:40

RE:

Hi MarsBarsLars.

You can use this one http://james.newtonking.com/json. Just download and reference it using reference manager

or reference "System.Runtime.Serialization"  from .Net Framework. http://msdn.microsoft.com/en-us/library/bb410770(v=vs.100).aspx.

MarsBarsLars said:

Hi,

How do I include JSON serialization?

Is there an included library?

MarsBarsLars

 


@Invalid

MarsBarsLars
17 Jul 2014, 13:03

RE: RE:

 

Do you have a simple example?

Hi MarsBarsLars.

You can use this one http://james.newtonking.com/json. Just download and reference it using reference manager

or reference "System.Runtime.Serialization"  from .Net Framework. http://msdn.microsoft.com/en-us/library/bb410770(v=vs.100).aspx.

MarsBarsLars said:

Hi,

How do I include JSON serialization?

Is there an included library?

MarsBarsLars

 

 


@MarsBarsLars

Invalid
17 Jul 2014, 14:19

RE: RE: RE:
using Newtonsoft.Json;
using cAlgo.API;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class JSON : Robot
    {
        protected override void OnStart()
        {
            var position = ExecuteMarketOrder(TradeType.Sell, Symbol, 40000).Position;
            var json = JsonConvert.SerializeObject(position, Formatting.Indented);
            
        }
    }
}

 

will produce:

{
  "SymbolCode": "EURUSD",
  "TradeType": 1,
  "Volume": 40000,
  "Id": 2646492,
  "Profit": -2.66,
  "GrossProfit": -2.66,
  "EntryPrice": 1.35275,
  "EntryTime": "2014-07-17T11:16:25.942Z",
  "Pips": -0.9,
  "Label": "",
  "Comment": "",
  "StopLoss": null,
  "TakeProfit": null,
  "NetProfit": -5.06,
  "Swap": 0.0,
  "Commissions": -1.2
}

 

 

MarsBarsLars said:

 

Do you have a simple example?


@Invalid

MarsBarsLars
17 Jul 2014, 15:22

RE: RE: RE: RE:

 

You my friend, are a champion! Up and running. Thanks!

using Newtonsoft.Json;
using cAlgo.API;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class JSON : Robot
    {
        protected override void OnStart()
        {
            var position = ExecuteMarketOrder(TradeType.Sell, Symbol, 40000).Position;
            var json = JsonConvert.SerializeObject(position, Formatting.Indented);
            
        }
    }
}

 

will produce:

{
  "SymbolCode": "EURUSD",
  "TradeType": 1,
  "Volume": 40000,
  "Id": 2646492,
  "Profit": -2.66,
  "GrossProfit": -2.66,
  "EntryPrice": 1.35275,
  "EntryTime": "2014-07-17T11:16:25.942Z",
  "Pips": -0.9,
  "Label": "",
  "Comment": "",
  "StopLoss": null,
  "TakeProfit": null,
  "NetProfit": -5.06,
  "Swap": 0.0,
  "Commissions": -1.2
}

 

 

MarsBarsLars said:

 

Do you have a simple example?

 


@MarsBarsLars