Skip to content

Asset

Summary

The asset represents a currency.

Signature

1
public abstract interface Asset

Namespace

cAlgo.API

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
 using cAlgo.API;
 namespace cAlgo.Robots
 {
     [Robot(AccessRights = AccessRights.None)]
     public class NewcBot2 : Robot
     {
         protected override void OnStart()
         {
             foreach (var assetName in Assets)
             {
                 var asset = Assets.GetAsset(assetName);
                 Print($"Asset Name: {assetName} | Asset Digits: {asset.Digits});
             }
         }
     }
 }
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
 import clr
 clr.AddReference("cAlgo.API")
 # Import cAlgo API types
 from cAlgo.API import *
 # Import trading wrapper functions
 from robot_wrapper import *
 class Test():
     def on_start(self):
         for assetName in api.Assets:
             asset = api.Assets.GetAsset(assetName)
             print(f"Asset Name: {assetName} | Asset Digits: {asset.Digits}")

See Also

Methods

Convert (2)

Convert (1 of 2)

Summary

Converts value to another asset.

Signature

1
public abstract double Convert(Asset to, double value)

Parameters

Name Type Description
to Asset Target asset
value double The value you want to convert from current Asset

Return Value

double

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 using cAlgo.API;
 using System.Text;
 namespace cAlgo.Robots
 {
     [Robot(AccessRights = AccessRights.None)]
     public class AssetConversionTest : Robot
     {
         [Parameter(DefaultValue = "CAD")]
         public string ConvertToAssetName { get; set; }
         [Parameter(DefaultValue = 10)]
         public double AmountToConvert { get; set; }
         protected override void OnStart()
         {
             var convertToAsset = Assets.GetAsset(ConvertToAssetName);
             if (convertToAsset == null)
             {
                 Print("Asset {0} not found", ConvertToAssetName);
                 Stop();
                 return;
             }
             var result = Account.Asset.Convert(convertToAsset, AmountToConvert);
             Print("Result : {0}", result);
         }
     }
 }
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
 import clr
 clr.AddReference("cAlgo.API")
 # Import cAlgo API types
 from cAlgo.API import *
 # Import trading wrapper functions
 from robot_wrapper import *
 class Test():
     def on_start(self):
         convertToAsset = api.Assets.GetAsset(api.ConvertToAssetName)
         if convertToAsset is None:
             print(f"Asset {api.ConvertToAssetName} not found")
             api.Stop()
             return
         result = api.Account.Asset.Convert(convertToAsset, api.AmountToConvert)
         api.Print(f"Result : {result}");

See Also

Related Tutorials

Convert (2 of 2)

Summary

Converts value to another asset.

Signature

1
public abstract double Convert(string to, double value)

Parameters

Name Type Description
to string Target asset
value double The value you want to convert from current Asset

Return Value

double

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 using cAlgo.API;
 using System.Text;
 namespace cAlgo.Robots
 {
     [Robot(AccessRights = AccessRights.None)]
     public class AssetConversionTest : Robot
     {
         [Parameter(DefaultValue = "CAD")]
         public string ConvertToAssetName { get; set; }
         [Parameter(DefaultValue = 10)]
         public double AmountToConvert { get; set; }
         protected override void OnStart()
         {
             var convertToAssetExist = Assets.Exists(ConvertToAssetName);
             if (!convertToAssetExist)
             {
                 Print("Asset {0} not found", ConvertToAssetName);
                 Stop();
                 return;
             }
             var result = Account.Asset.Convert(ConvertToAssetName, AmountToConvert);
             Print("Result : {0}", result);
         }
     }
 }
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
 import clr
 clr.AddReference("cAlgo.API")
 # Import cAlgo API types
 from cAlgo.API import *
 # Import trading wrapper functions
 from robot_wrapper import *
 class Test():
     def on_start(self):
         if api.Assets.Exists(api.ConvertToAssetName) == False:
             print(f"Asset {api.ConvertToAssetName} not found")
             api.Stop()
             return
         result = api.Account.Asset.Convert(api.ConvertToAssetName, api.AmountToConvert)
         api.Print(f"Result : {result}");

See Also

Related Tutorials

Properties

Name

Summary

The asset Name

Signature

1
public abstract string Name {get;}

Return Value

string

Digits

Summary

Number of asset digits

Signature

1
public abstract int Digits {get;}

Return Value

int