{"id":8068,"date":"2025-09-04T23:22:06","date_gmt":"2025-09-05T04:22:06","guid":{"rendered":"https:\/\/librarytestdev.wpenginepowered.com\/?post_type=doc&#038;p=8068"},"modified":"2025-09-04T23:23:52","modified_gmt":"2025-09-05T04:23:52","slug":"price-class-initializers","status":"publish","type":"doc","link":"https:\/\/library-staging.tradingtechnologies.com\/apis\/tt-net-sdk\/subscribing-for-market-data-tt-net-sdk\/more-about-prices\/an-in-depth-look-at-the-price-class\/price-class-initializers\/","title":{"rendered":"Price class: initializers"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;class has no defined constructors; instead, it provides a series of static methods that return an instance of a&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;class:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static Price FromDouble(Fill fill, double price)\npublic static Price FromDouble(Instrument instrument, double price)\npublic static Price FromDouble(InstrumentDetails instrumentDetails, double price)\npublic static Price FromDouble(Order order, double price)\npublic static Price FromDouble(OrderProfileBase orderProfile, double price)\n\npublic static Price FromString(Fill fill, string price)\npublic static Price FromString(Instrument instrument, string price)\npublic static Price FromString(InstrumentDetails instrumentDetails, string price)\npublic static Price FromString(Order order, string price)\npublic static Price FromString(OrderProfileBase orderProfile, string price)\n\npublic static Price FromTick(Fill fill, int price)\npublic static Price FromTick(Instrument instrument, int price)\npublic static Price FromTick(InstrumentDetails instrumentDetails, int price)\npublic static Price FromTick(Order order, int price)\npublic static Price FromTick(OrderProfileBase orderProfile, int price)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">These methods take a price in ticks (int), points (double), or TT Display (string) format. Additionally, these methods require information from the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentDetails.html\">InstrumentDetails<\/a>&nbsp;object associated with a contract, which you can specify directly or indirectly through the following objects (all of which reference the associated&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentDetails.html\">InstrumentDetails<\/a>):<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Instrument<\/li>\n\n\n\n<li>Fill<\/li>\n\n\n\n<li>Order<\/li>\n\n\n\n<li>OrderProfile<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">After calling one of these methods, you need to confirm that the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;object was able to correctly interpret the price that you passed to it. The&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;class includes the following properties to check the validity of a price:&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_IsValid\">IsValid<\/a>&nbsp;and&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_IsTradable\">IsTradable<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you provide a price that the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;object cannot interpret, it sets the internal price of the returned Price object to TT_INVALID_PRICE. In this scenario, the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_IsValid\">IsValid<\/a>&nbsp;property returns false. For example, assume that the variable inst represents a valid&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Instrument.html\">Instrument<\/a>&nbsp;instance for the CBOT ZB-Mar20 futures contract.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Price p = Price.FromString(inst, \"abc\");\nbool b = p.IsValid;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As &#8220;abc&#8221; is not a valid price in the TT Display format for this contract, the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_IsValid\">IsValid<\/a>&nbsp;property returns&nbsp;<strong>false<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you provide a valid price that does not fall on an allowable trading price, based on the ticking information in the associated&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.InstrumentDetails.html\">InstrumentDetails<\/a>&nbsp;instance, the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_IsTradable\">IsTradable<\/a>&nbsp;property returns&nbsp;<strong>false<\/strong>. For example, assume that the variable inst represents a valid&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Instrument.html\">Instrument<\/a>&nbsp;instance for the CBOT ZB-Mar20 futures contract.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Price p = Price.FromDouble(inst, 114.03);\nbool b = p.IsTradable;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Recall that the Tick Size of CBOT ZB futures is 1\/32 (.03125). Because 114.03 points is not an allowable trading price for this contract, the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_IsTradable\">IsTradable<\/a>&nbsp;property returns&nbsp;<strong>false<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To help in situations like this, you could use the overloaded versions of the static initializer methods that take an additional parameter that allow you to specify a rounding convention to use.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static Price FromDouble(Fill fill, double price, Rounding rounding)\npublic static Price FromDouble(Instrument instrument, double price, Rounding rounding)\npublic static Price FromDouble(InstrumentDetails instrumentDetails, double price, Rounding rounding)\npublic static Price FromDouble(Order order, double price, Rounding rounding)\npublic static Price FromDouble(OrderProfileBase orderProfile, double price, Rounding rounding)\n\npublic static Price FromString(Fill fill, string price, Rounding rounding)\npublic static Price FromString(Instrument instrument, string price, Rounding rounding)\npublic static Price FromString(InstrumentDetails instrumentDetails, string price, Rounding rounding)\npublic static Price FromString(Order order, string price, Rounding rounding)\npublic static Price FromString(OrderProfileBase orderProfile, string price, Rounding rounding)\n\npublic static Price FromTick(Fill fill, int price, Rounding rounding)\npublic static Price FromTick(Instrument instrument, int price, Rounding rounding)\npublic static Price FromTick(InstrumentDetails instrumentDetails, int price, Rounding rounding)\npublic static Price FromTick(Order order, int price, Rounding rounding)\npublic static Price FromTick(OrderProfileBase orderProfile, int price, Rounding rounding)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The rounding parameter is an enumeration with the following possible values that specifies how to round the price relative to the TT Base Tick Size:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Up<\/li>\n\n\n\n<li>Down<\/li>\n\n\n\n<li>Nearest<\/li>\n\n\n\n<li>None<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose you modified the previous example to use rounding, as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Price p = Price.FromDouble(inst, 114.03, Rounding.Up);\nbool b = p.IsTradable;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this case, the price rounds 114.03 to 114.03125, so the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_IsTradable\">IsTradable<\/a>&nbsp;property returns&nbsp;<strong>true<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also round a price relative to the Tick Size by invoking the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_Round_tt_net_sdk_Rounding_\">Round()<\/a>&nbsp;method for a&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;object. This is illustrated by extending the prior example, as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Price p2 = Price.FromDouble(inst,114.007,Rounding.Up);\nPrice p3 = p2.Round(Rounding.Up);\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When the first line of code is executed, the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;class rounds 114.007 to 114.0078125 because the TT Base Tick Size is 1\/128 (0.0078125). The&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_IsValid\">IsValid<\/a>&nbsp;property returns true but the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_IsTradable\">IsTradable<\/a>&nbsp;property returns&nbsp;<strong>false<\/strong>. When the second line of code is executed, the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;class rounds 114.0078125 to 114.03125 because the Tick Size is 1\/32 (0.03125). Now, both the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_IsValid\">IsValid<\/a>&nbsp;and&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_IsTradable\">IsTradable<\/a>&nbsp;properties return&nbsp;<strong>true<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note that the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html#tt_net_sdk_Price_Round_tt_net_sdk_Rounding_\">Round()<\/a>&nbsp;method does not modify its internal value. Instead, it returns a new&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.Price.html\">Price<\/a>&nbsp;object with the rounded value.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The&nbsp;Price&nbsp;class has no defined constructors; instead, it provides a series of static methods that re [&hellip;]<\/p>\n","protected":false},"author":2,"template":"wp-custom-template-single-doc-tt-net-sdk","meta":{"_acf_changed":true,"footnotes":""},"docs-category":[778],"class_list":["post-8068","doc","type-doc","status-publish","hentry","docs-category-an-in-depth-look-at-the-price-class"],"acf":[],"_links":{"self":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/8068","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\/8068\/revisions"}],"wp:attachment":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/media?parent=8068"}],"wp:term":[{"taxonomy":"docs-category","embeddable":true,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/docs-category?post=8068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}