Skip to content

CurrencyPairUtil

QuantConnect.Util.CurrencyPairUtil

Bases: Object

Utility methods for decomposing and comparing currency pairs

Match

Bases: IntEnum

Represents the relation between two currency pairs

NO_MATCH

NO_MATCH = 0

The two currency pairs don't match each other normally nor when one is reversed

EXACT_MATCH

EXACT_MATCH = 1

The two currency pairs match each other exactly

INVERSE_MATCH

INVERSE_MATCH = 2

The two currency pairs are the inverse of each other

currency_pair_dual

currency_pair_dual(
    currency_pair: Union[Symbol, str, BaseContract],
    known_symbol: str,
) -> str
currency_pair_dual(
    base_currency: str,
    quote_currency: str,
    known_symbol: str,
) -> str

Signature descriptions:

  • You have currency_pair AB and one known symbol (A or B). This function returns the other symbol (B or A).

  • You have currencyPair AB and one known symbol (A or B). This function returns the other symbol (B or A).

Parameters:

Name Type Description Default
currency_pair Optional[Union[Symbol, str, BaseContract]]

Currency pair AB

None
known_symbol str

Known part of the currency_pair (either A or B)

required
base_currency Optional[str]

The base currency of the currency pair

None
quote_currency Optional[str]

The quote currency of the currency pair

None

Returns:

Type Description
str

Depends on the signature used. Case 1: [The other part of currency_pair (either B or A), or null if known symbol is not part of currency_pair.]; Case 2: [The other part of currencyPair (either B or A), or null if known symbol is not part of the currency pair.]

compare_pair

compare_pair(
    pair_a: Union[Symbol, str, BaseContract],
    base_currency_b: str,
    quote_currency_b: str,
) -> Match

Returns how two currency pairs are related to each other

Parameters:

Name Type Description Default
pair_a Union[Symbol, str, BaseContract]

The first pair

required
base_currency_b str

The base currency of the second pair

required
quote_currency_b str

The quote currency of the second pair

required

Returns:

Type Description
Match

The Match member that represents the relation between the two pairs.

decompose_currency_pair

decompose_currency_pair(
    currency_pair: Union[Symbol, str, BaseContract],
    base_currency: Optional[str],
    quote_currency: Optional[str],
    default_quote_currency: str = ...,
) -> Tuple[None, str, str]

Decomposes the specified currency pair into a base and quote currency provided as out parameters

Parameters:

Name Type Description Default
currency_pair Union[Symbol, str, BaseContract]

The input currency pair to be decomposed

required
base_currency Optional[str]

The output base currency

required
quote_currency Optional[str]

The output quote currency

required
default_quote_currency str

Optionally can provide a default quote currency

...

is_decomposable

is_decomposable(
    currency_pair: Union[Symbol, str, BaseContract],
) -> bool

Checks whether a symbol is decomposable into a base and a quote currency

Parameters:

Name Type Description Default
currency_pair Union[Symbol, str, BaseContract]

The pair to check for

required

Returns:

Type Description
bool

True if the pair can be decomposed into base and quote currencies, false if not.

is_forex_decomposable

is_forex_decomposable(currency_pair: str) -> bool

Checks whether a symbol is decomposable into a base and a quote currency

Parameters:

Name Type Description Default
currency_pair str

The pair to check for

required

Returns:

Type Description
bool

True if the pair can be decomposed into base and quote currencies, false if not.

is_valid_security_type

is_valid_security_type(
    security_type: Optional[SecurityType],
    throw_exception: bool,
) -> bool

try_decompose_currency_pair

try_decompose_currency_pair(
    currency_pair: Union[Symbol, str, BaseContract],
    base_currency: Optional[str],
    quote_currency: Optional[str],
) -> Tuple[bool, str, str]

Tries to decomposes the specified currency pair into a base and quote currency provided as out parameters

Parameters:

Name Type Description Default
currency_pair Union[Symbol, str, BaseContract]

The input currency pair to be decomposed

required
base_currency Optional[str]

The output base currency

required
quote_currency Optional[str]

The output quote currency

required

Returns:

Type Description
Tuple[bool, str, str]

True if was able to decompose the currency pair.