Skip to content

IAssetConverter.Convert

method · IAssetConverter · cAlgo.API.Internals

DesktopCLICloud

Converts an asset to another asset.

Overloads

Convert(double value, Asset from, Asset to)

Converts an asset to another asset.

double Convert(double value, Asset from, Asset to)
api.AssetConverter.Convert(value: float, from: Asset, to: Asset) -> float

Parameters

Name C# type Python type Description
value double float The value you want to convert from Asset
from Asset Asset Actual or current asset of the value
to Asset Asset Target asset

Returns double — Value in to / target asset

Examples

var valueInQuoteAsset = AssetConverter.Convert(1000, Account.Asset, Symbol.QuoteAsset);
Print("1000 {0} is {1} {2}", Account.Asset.Name, valueInQuoteAsset, Symbol.QuoteAsset.Name);
valueInQuoteAsset = api.AssetConverter.Convert(1000, api.Account.Asset, api.Symbol.QuoteAsset)
api.Print(f"1000 {api.Account.Asset.Name} is {valueInQuoteAsset} {api.Symbol.QuoteAsset.Name}")

Convert(double value, string from, string to)

Converts an asset to another asset.

double Convert(double value, string from, string to)
api.AssetConverter.Convert(value: float, from: str, to: str) -> float

Parameters

Name C# type Python type Description
value double float The value you want to convert from Asset
from string str Actual or current asset of the value
to string str Target asset

Returns double — Value in to / target asset

Examples

var valueInJpy = AssetConverter.Convert(100, "EUR", "JPY");
Print("100 EUR is {0} JPY", valueInJpy);
valueInJpy = api.AssetConverter.Convert(100, "EUR", "JPY")
api.Print(f"100 EUR is {valueInJpy} JPY")

Convert(double value, Asset from, string to)

Converts an asset to another asset.

double Convert(double value, Asset from, string to)
api.AssetConverter.Convert(value: float, from: Asset, to: str) -> float

Parameters

Name C# type Python type Description
value double float The value you want to convert from Asset
from Asset Asset Actual or current asset of the value
to string str Target asset name

Returns double — Value in to / target asset

Examples

var balanceInUsd = AssetConverter.Convert(Account.Balance, Account.Asset, "USD");
Print("Balance in USD: {0}", balanceInUsd);
balanceInUsd = api.AssetConverter.Convert(api.Account.Balance, api.Account.Asset, "USD")
api.Print(f"Balance in USD: {balanceInUsd}")

Convert(double value, string from, Asset to)

Converts an asset to another asset.

double Convert(double value, string from, Asset to)
api.AssetConverter.Convert(value: float, from: str, to: Asset) -> float

Parameters

Name C# type Python type Description
value double float The value you want to convert from Asset
from string str Actual or current asset name of the value
to Asset Asset Target asset

Returns double — Value in to / target asset

Examples

var valueInAccountAsset = AssetConverter.Convert(500, "GBP", Account.Asset);
Print("500 GBP is {0} {1}", valueInAccountAsset, Account.Asset.Name);
valueInAccountAsset = api.AssetConverter.Convert(500, "GBP", api.Account.Asset)
api.Print(f"500 GBP is {valueInAccountAsset} {api.Account.Asset.Name}")