{"id":8091,"date":"2025-09-04T23:21:38","date_gmt":"2025-09-05T04:21:38","guid":{"rendered":"https:\/\/librarytestdev.wpenginepowered.com\/?post_type=doc&#038;p=8091"},"modified":"2025-09-04T23:23:48","modified_gmt":"2025-09-05T04:23:48","slug":"autospreader","status":"publish","type":"doc","link":"https:\/\/library-staging.tradingtechnologies.com\/apis\/tt-net-sdk\/working-with-algos\/autospreader\/","title":{"rendered":"Autospreader"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Synthetic spread definitions are treated as instruments. Before you can launch your synthetic spread, you first need to fetch its definition as detailed in&nbsp;<a href=\"\/tt-net-sdk\/articles\/instr-instruments.html\">Working with Instruments<\/a>. Specifically, you follow the same steps as you would to fetch an exchange native instrument, except you:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Set the market name to &#8220;ASE&#8221;.<\/li>\n\n\n\n<li>Set the product type to &#8220;Synthetic&#8221;.<\/li>\n\n\n\n<li>Set the product name to &#8220;ASE&#8221;.<\/li>\n\n\n\n<li>Set the alias to the user-defined name associated with the synthetic spread.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"fetching-autospreader-spread-definitions\"><a href=\"\/tt-net-sdk\/articles\/algo-ase.html#fetching-autospreader-spread-definitions\"><\/a>Fetching Autospreader Spread Definitions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The following code snippet demonstrates how to fetch the list of all Autospreader spread definitions.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>InstrumentCatalogSubscription spreadCatalog_ = null;\n\npublic void SubscribeSpreadDefinitions()\n{\n    if (spreadCatalog_ is null)\n    {\n        spreadCatalog_ = new InstrumentCatalogSubscription(Product.Autospreader, \n            m_callback_disp);\n        spreadCatalog_.OnData += OnSpreadDefinitionNotification;\n        spreadCatalog_.Start();\n    }\n}\n\npublic void OnSpreadDefinitionNotification(object sender, InstrumentCatalogEventArgs e)\n{\n    Console.WriteLine(\"OnSpreadDefinitionNotification \" + e?.Event + \" \" + e?.Message);\n    switch (e.Event)\n    {\n        case ProductDataEvent.Found:\n            Console.WriteLine(\"Here are all the current spread definitions\");\n            foreach (var sp in e.InstrumentCatalog.InstrumentList)\n            {\n                Console.WriteLine(\"Spread \" + sp.Name);\n            }\n            break;\n        case ProductDataEvent.InstrumentDeleted:\n            foreach (var sp in e.Deleted)\n            {\n                Console.WriteLine(\"Spread \" + sp.Name + \" was deleted.\");\n            }\n            break;\n        case ProductDataEvent.InstrumentUpdated:\n            foreach (var sp in e.Updated)\n            {\n                Console.WriteLine(\"Spread \" + sp.Name + \" was updated.\");\n            }\n            break;\n        case ProductDataEvent.InstrumentCreated:\n            foreach (var sp in e.Added)\n            {\n                Console.WriteLine(\"Spread \" + sp.Name + \" was created.\");\n            }\n            break;\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once you have the instrument corresponding to your spread definition, you can&nbsp;<a href=\"\/tt-net-sdk\/articles\/md-market-data.html\">subscribe for market data<\/a>&nbsp;and&nbsp;<a href=\"\/tt-net-sdk\/articles\/of-submitting-orders.html\">route orders<\/a>&nbsp;for these instruments by following the same steps as you would for an exchange native instrument.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note: As Autospreader orders are filled, you will receive fill messages for each leg order as well as fill messages for the parent order. These parent fill messages will have an ExecType of \u2018Trade\u2019 and an OrdStatus of \u2018PartiallyFilled\u2019. When the Autospreader order is fully filled, you will receive a deletion event with an ExecType of \u2018Canceled\u2019 and an OrdStatus of \u2018Filled\u2019. It is done in this manner to account for possible overfill scenarios when quoting more than one leg.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-autospreader-spread-definitions\"><a href=\"\/tt-net-sdk\/articles\/algo-ase.html#creating-autospreader-spread-definitions\"><\/a>Creating Autospreader Spread Definitions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can also create new Autospreader spread definitions from scratch as follows.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public void Test_CreateSpread()\n{\n    SubscribeSpreadDefinitions();\n\n    Instrument newInst;\n\n    var spdetail = new SpreadDetails(\"my.nettest\");\n    spdetail.Color = System.Drawing.Color.GreenYellow;\n    spdetail.PricingModel = PricingModel.Implied;\n\n    InstrumentLookup leg1Lookup = new InstrumentLookup(tt_net_sdk.Dispatcher.Current, MarketId.CME, ProductType.Future, \"GE\", \"GE Jun23\");\n    InstrumentLookup leg2Lookup = new InstrumentLookup(tt_net_sdk.Dispatcher.Current, MarketId.CME, ProductType.Future, \"GE\", \"GE Sep23\");\n\n    if ((leg1Lookup.Get() == ProductDataEvent.Found) &amp;&amp; (leg2Lookup.Get() == ProductDataEvent.Found))\n    {\n        var leg1 = new SpreadLegDetails(leg1Lookup.Instrument, 1, 1.0M);\n        leg1.ActiveQuoting = true;\n        leg1.IsLeanIndicative = false;\n        leg1.MinLeanQty = \"ThisLeg.DisclosedRemainingQuantity\";\n        spdetail.AppendLeg(leg1);\n\n        var leg2 = new SpreadLegDetails(leg2Lookup.Instrument, -1, -1.0M);\n        leg2.ActiveQuoting = true;\n        leg2.IsLeanIndicative = false;\n        leg2.MinLeanQty = \"ThisLeg.DisclosedRemainingQuantity\";\n        spdetail.AppendLeg(leg2);\n\n        ASReturnCodes rtnCode;\n        newInst = AutospreaderManager.AddSpreadDetails(spdetail, out rtnCode);\n        if (newInst is null)\n        {\n            Console.WriteLine(\"unable to add new spread. \" + spdetail.Name);\n        }\n        else\n        {\n            Console.WriteLine(\"Created new spread. \" + newInst.Name + \" key:\" + newInst.Key);\n        }\n        Console.WriteLine(\"Add return: \" + rtnCode);\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once you have created the Autospreader spread definition, you can manipulate it as demonstrated in the code snippets below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Deleting an Autospreader spread definition\n\npublic void Test_DeleteSpread()\n{\n        SubscribeSpreadDefinitions();\n\n        InstrumentLookup spreadLookup = new InstrumentLookup(tt_net_sdk.Dispatcher.Current, MarketId.ASE, ProductType.Synthetic, Product.Autospreader.Alias, \"my.nettest\");\n\n        if (spreadLookup.Get() == ProductDataEvent.Found)\n        {\n                Console.WriteLine(\"Attempting to delete spread instrument.\" + spreadLookup.Alias);\n                SpreadDetails details = spreadLookup.Instrument.GetSpreadDetails();\n                ASReturnCodes rtnCode = AutospreaderManager.DeleteSpreadDetails(details);\n                Console.WriteLine(\"Delete return: \" + rtnCode);\n        }\n        else\n        {\n                Console.WriteLine(\"Unable to find spread instrument.\" + spreadLookup.Alias);\n        }\n}\n\n\n\/\/ Changing the instrument of an existing Autospreader spread definition\n\n\npublic void Test_ModifySpread()\n{\n        InstrumentLookup spreadLookup = new InstrumentLookup(tt_net_sdk.Dispatcher.Current, MarketId.ASE, ProductType.Synthetic, Product.Autospreader.Alias, \"my.nettest\");\n\n        if (spreadLookup.Get() == ProductDataEvent.Found)\n        {\n                SpreadDetails sp = spreadLookup.Instrument.GetSpreadDetails();\n                Console.WriteLine(\"Found spread instrument.\" + sp.Name + \" (\" +\n                        spreadLookup.Instrument.InstrumentDetails.Version + \")\");\n\n                InstrumentLookup newLegLookup = new InstrumentLookup(tt_net_sdk.Dispatcher.Current, \n                        MarketId.CME, ProductType.Future, \"6A\", \"6A Mar22\");\n\n                if (newLegLookup.Get() == ProductDataEvent.Found)\n                {\n                        SpreadLegDetails leg1 = sp.GetLeg(0);\n                        leg1.Instrument = newLegLookup.Instrument;\n                        sp.Updateleg(0, leg1);\n\n                        ASReturnCodes rtnCode;\n                        Instrument newSpreadInst = AutospreaderManager.UpdateSpreadDetails(sp, out rtnCode);\n                        sp = newSpreadInst.GetSpreadDetails();\n                        Console.WriteLine(\"Update to find spread instrument.\" + sp.Name + \" (\" + \n                                newSpreadInst.InstrumentDetails.Version + \")\");\n                }\n        }\n        else\n        {\n                Console.WriteLine(\"Unable to find spread instrument.\" + spreadLookup.Alias);\n        }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">There are methods to get\/set the leg accounts. # To set the leg account by using the Account Object, use SetLegAccount(index, Account object)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"assigning-rules-to-a-spread\"><a href=\"\/tt-net-sdk\/articles\/algo-ase.html#assigning-rules-to-a-spread\"><\/a>Assigning Rules to a Spread<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Retrieve a list of available spread rules using&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.AutospreaderManager.html#tt_net_sdk_AutospreaderManager_GetSpreadRules\">AutospreaderManager.GetSpreadRules()<\/a>. A rule can be located in this global collection of available rules and assigned to a spread. Then the rule can be configured on a leg by leg basis.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the following sample code as a guide.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>InstrumentLookup spreadLookup = new InstrumentLookup(tt_net_sdk.Dispatcher.Current, MarketId.ASE, ProductType.Synthetic,\n                                                         Product.Autospreader.Alias, spreadName);\n    if (spreadLookup.Get() == ProductDataEvent.Found)\n    {\n        SpreadDetails details = spreadLookup.Instrument.GetSpreadDetails();\n        var rules = AutospreaderManager.GetSpreadRules();\n        SpreadRule ttRule;\n        if (rules.TryGetValue(\"(TT) Minimum Increment Quote\", out ttRule))\n        {\n            \/\/ rule exists so it can be use but make sure it is not aleady assigned\n            \/\/ since a rule can only be attached once to a spread\n            var existingRule = details.GetRule(ttRule.Name);\n            if (existingRule is null)\n                details.AppendRule(ttRule);\n                \n            \/\/ change the rule default values on second leg\n            var leg1 = details.GetLeg(1);\n            \/\/ enable using the rule name\n            leg1.EnableRule(ttRule.Name, true);\n            leg1.SetRuleCustomVariable(ttRule.Name, \"minIncrement\", 6);\n            \n            \/\/ disable the default values on first leg\n            var leg0 = details.GetLeg(0);\n            \/\/ enable using the rule index\n            leg0.EnableRule(0, false);\n            \n            \/\/ save the changes\n            ASReturnCodes retCode = ASReturnCodes.FailToSave;\n            AutospreaderManager.UpdateSpreadDetails(details, out retCode);\n            if (retCode == ASReturnCodes.Success)\n                Console.WriteLine(\"Successfull updated \" + spreadLookup.Instrument.InstrumentDetails.Name);\n            else\n                Console.WriteLine(\"FAILED to updated \" + spreadLookup.Instrument.InstrumentDetails.Name);\n        }\n    }\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"setting-the-account-on-different-legs-of-the-spread\"><a href=\"\/tt-net-sdk\/articles\/algo-ase.html#setting-the-account-on-different-legs-of-the-spread\"><\/a>Setting the Account on Different Legs of the Spread<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are three (3) methods to get\/set the account on the different legs of the spread:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>To set the leg account by using the Account Object, use\u00a0<strong>SetLegAccount<\/strong>\u00a0(<em>index<\/em>,\u00a0<em>Account Object<\/em>),<\/li>\n\n\n\n<li>To set the leg account by using the Account Name, use\u00a0<strong>SetLegAccountName<\/strong>\u00a0(<em>index<\/em>,\u00a0<em>accountname<\/em>) .<\/li>\n\n\n\n<li>To get the account for the Leg, you can use the method\u00a0<strong>LegAccount<\/strong>\u00a0(<em>index<\/em>).<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>: When setting the value for index, remember that the value begins with 0. So to set the account on the first leg, set index equal to 0, the second leg, index equals 1 and so on.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Synthetic spread definitions are treated as instruments. Before you can launch your synthetic spread, you firs [&hellip;]<\/p>\n","protected":false},"author":2,"template":"wp-custom-template-single-doc-tt-net-sdk","meta":{"_acf_changed":true,"footnotes":""},"docs-category":[1611],"class_list":["post-8091","doc","type-doc","status-publish","hentry","docs-category-working-with-algos"],"acf":[],"_links":{"self":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/8091","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\/8091\/revisions"}],"wp:attachment":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/media?parent=8091"}],"wp:term":[{"taxonomy":"docs-category","embeddable":true,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/docs-category?post=8091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}