{"id":8063,"date":"2025-09-04T23:22:07","date_gmt":"2025-09-05T04:22:07","guid":{"rendered":"https:\/\/librarytestdev.wpenginepowered.com\/?post_type=doc&#038;p=8063"},"modified":"2025-09-04T23:23:53","modified_gmt":"2025-09-05T04:23:53","slug":"working-with-prices-and-quantities","status":"publish","type":"doc","link":"https:\/\/library-staging.tradingtechnologies.com\/apis\/tt-net-sdk\/subscribing-for-market-data-tt-net-sdk\/working-with-prices-and-quantities\/","title":{"rendered":"Working with prices and quantities"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"working-with-the-price-class\">Working with the Price class<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For efficiency, TT .NET SDK processes and stores prices as integer values. However, you can represent price in different formats, such as Double or String, and in styles such as Ticks. You also might want to perform mathematical calculations with these prices. TT .NET SDK exposes this functionality in the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The following snippet shows some of the ways you can manipulate prices.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void m_priceSubscription_FieldsUpdated(object sender, FieldsUpdatedEventArgs e)\n{\n    if (e.Error == null)\n    {\n        Price lastP = e.Fields.GetLastTradedPriceField().Value;\n        if ( lastP.IsValid )\n        {\n            \/\/ Extract the price as a Double\n            decimal lastAsDecimal = lastP.ToDecimal();\n            \/\/ Extract the price as a String\n            string lastAsString = lastP.ToString();\n            \/\/ Extract the price in ticks\n            int lastAsTicks = lastP.ToTicks();\n            \/\/ Move up 1 tick\n            lastP++;\n            \/\/ Move down 3 ticks\n            lastP -= 3;\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Note<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">TT .NET SDK guarantees that any&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;object returned from a price subscription is a valid object. However, because the underlying value might be invalid or null. To ensure that a price contains a valid value, you should check the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_IsValid\">Price.IsValid<\/a>&nbsp;property of the returned object before using its value.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"working-with-the-quantity-class\"><a href=\"\/tt-net-sdk\/articles\/md-prices-qty.html#working-with-the-quantity-class\"><\/a>Working with the Quantity class<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As quantities can also be expressed in a variety of ways, TT .NET SDK exposes a&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Quantity.html\">Quantity<\/a>&nbsp;class. This class allows you to extract order quantities in Lots and Flow (e.g. Energy contracts). For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void m_priceSubscription_FieldsUpdated(object sender, FieldsUpdatedEventArgs e)\n{\n    if (e.Error == null)\n    {\n        QuantityField ltq = e.Fields.GetLastTradedQuantityField();\n        Quantity lastQ = ltq.Value;\n        if ( lastQ.IsValid )\n        {\n            \/\/ Extract the quantity in flow\n            int lastQinFlow = lastQ.ToFlow();\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Quantity.html\">Quantity<\/a>&nbsp;class also supports the increment and decrement operators, which are particularly useful when changing the quantity of a contract that trades in flow.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Note<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">TT .NET SDK guarantees that any&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Quantity.html\">Quantity<\/a>&nbsp;object returned from a price subscription is a valid object. However, because the underlying value might be invalid or null. To ensure that a quantity contains a valid value, you should check the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Quantity.html#tt_net_sdk_Quantity_IsValid\">Quantity<\/a>&nbsp;property of the returned object before using its value.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"other-ways-to-use-the-price-and-quantity-classes\"><a href=\"\/tt-net-sdk\/articles\/md-prices-qty.html#other-ways-to-use-the-price-and-quantity-classes\"><\/a>Other ways to use the Price and Quantity classes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;and&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Quantity.html\">Quantity<\/a>&nbsp;classes also contain a series of useful static methods that allow you to create instances directly. For example, assume your application allows users to enter prices (ps) and quantities (qs) as strings. To convert a string representation of a price to a&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;class or a quantity string to a&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Quantity.html\">Quantity<\/a>&nbsp;class for a given&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Instrument.html\">Instrument<\/a>&nbsp;(instr), you could use the static&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_FromString_tt_net_sdk_Instrument_System_String_tt_net_sdk_Rounding_\">Price.FromString<\/a>&nbsp;(or&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Quantity.html#tt_net_sdk_Quantity_FromString_tt_net_sdk_Instrument_System_String_tt_net_sdk_Rounding_\">Quantity.FromString<\/a>) method as follows.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Price p = Price.FromString( instr, ps );\nQuantity q = Quantity.FromString( instr, qs );<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<h2 class=\"wp-block-heading\" id=\"working-with-the-price-class\">Working with the Price class<\/h2>\n<p class=\"wp-block-paragraph\">For efficiency, TT .NET SDK processes and stores prices as integer values. However, you can represent price in different formats, such as Double or String, and in styles such as Ticks. You also might want to perform mathematical calculations with these prices. TT .NET SDK exposes this functionality in the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;object.<\/p>\n<p class=\"wp-block-paragraph\">The following snippet shows some of the ways you can manipulate prices.<\/p>\n<h5 class=\"wp-block-heading\">Note<\/h5>\n<p class=\"wp-block-paragraph\">TT .NET SDK guarantees that any&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;object returned from a price subscription is a valid object. However, because the underlying value might be invalid or null. To ensure that a price contains a valid value, you should check the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_IsValid\">Price.IsValid<\/a>&nbsp;property of the returned object before using its value.<\/p>\n<h2 class=\"wp-block-heading\" id=\"working-with-the-quantity-class\"><a href=\"\/tt-net-sdk\/articles\/md-prices-qty.html#working-with-the-quantity-class\"><\/a>Working with the Quantity class<\/h2>\n<p class=\"wp-block-paragraph\">As quantities can also be expressed in a variety of ways, TT .NET SDK exposes a&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Quantity.html\">Quantity<\/a>&nbsp;class. This class allows you to extract order quantities in Lots and Flow (e.g. Energy contracts). For example:<\/p>\n<p class=\"wp-block-paragraph\">The&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Quantity.html\">Quantity<\/a>&nbsp;class also supports the increment and decrement operators, which are particularly useful when changing the quantity of a contract that trades in flow.<\/p>\n<h5 class=\"wp-block-heading\">Note<\/h5>\n<p class=\"wp-block-paragraph\">TT .NET SDK guarantees that any&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Quantity.html\">Quantity<\/a>&nbsp;object returned from a price subscription is a valid object. However, because the underlying value might be invalid or null. To ensure that a quantity contains a valid value, you should check the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Quantity.html#tt_net_sdk_Quantity_IsValid\">Quantity<\/a>&nbsp;property of the returned object before using its value.<\/p>\n<h2 class=\"wp-block-heading\" id=\"other-ways-to-use-the-price-and-quantity-classes\"><a href=\"\/tt-net-sdk\/articles\/md-prices-qty.html#other-ways-to-use-the-price-and-quantity-classes\"><\/a>Other ways to use the Price and Quantity classes<\/h2>\n<p class=\"wp-block-paragraph\">The&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;and&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Quantity.html\">Quantity<\/a>&nbsp;classes also contain a series of useful static methods that allow you to create instances directly. For example, assume your application allows users to enter prices (ps) and quantities (qs) as strings. To convert a string representation of a price to a&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;class or a quantity string to a&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Quantity.html\">Quantity<\/a>&nbsp;class for a given&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Instrument.html\">Instrument<\/a>&nbsp;(instr), you could use the static&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_FromString_tt_net_sdk_Instrument_System_String_tt_net_sdk_Rounding_\">Price.FromString<\/a>&nbsp;(or&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Quantity.html#tt_net_sdk_Quantity_FromString_tt_net_sdk_Instrument_System_String_tt_net_sdk_Rounding_\">Quantity.FromString<\/a>) method as follows.<\/p>\n","protected":false},"author":2,"template":"wp-custom-template-single-doc-tt-net-sdk","meta":{"_acf_changed":true,"footnotes":""},"docs-category":[1605],"class_list":["post-8063","doc","type-doc","status-publish","hentry","docs-category-subscribing-for-market-data-tt-net-sdk"],"acf":[],"_links":{"self":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/8063","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc"}],"about":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/types\/doc"}],"author":[{"embeddable":true,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/users\/2"}],"version-history":[{"count":0,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/8063\/revisions"}],"wp:attachment":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/media?parent=8063"}],"wp:term":[{"taxonomy":"docs-category","embeddable":true,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/docs-category?post=8063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}