Projects

Shared Libraries

Introduction

Project libraries are QuantConnect projects you can merge into your project to avoid duplicating code files. If you have tools that you use across several projects, create a library.

Create Libraries

Follow these steps to create a library:

  1. Create a new project.
  2. In the project panel, click Add Library.
  3. Click Create New.
  4. In the Input Library Name field, enter a name for the library (for example, Calculators).
  5. To create a library directory, set the name to directoryName / libraryName (for example, Tools / Calculators).

  6. Click Create Library.
  7. The template library files are added to your project. View the files in the Explorer panel.

  8. In the right navigation menu, click the Explorer icon Explorer icon.
  9. In Explorer panel, open the Library.pyLibrary.cs file, rename it to reflect its purpose (e.g.: TaxesCalculator.pyTaxesCalculator.cs), and implement your library.

Add Libraries

Follow these steps to add a library to your project:

  1. Open the project.
  2. In the Project panel, click Add Library.
  3. Click the Choose a library... field and then click a library from the drop-down menu.
  4. Click Add Library (e.g. Calculators).
  5. The library files are added to your project. To view the files, in the right navigation menu, click the Explorer icon.

  6. Import the library into your project to use the library.
  7. using Calculators;
    namespace QuantConnect.Algorithm.CSharp
    {
        public class AddLibraryAlgorithm : QCAlgorithm
        {
            private TaxesCalculator _taxesCalculator = new();
        }
    }
    from Calculators.TaxesCalculator import TaxesCalculator
    class AddLibraryAlgorithm(QCAlgorithm):
        taxes_calculator = TaxesCalculator()

Rename Libraries

To rename a library, open the library project file and then rename the project.

Remove Libraries

Follow these steps to remove a library from your project:

  1. Open the project that contains the library you want to remove.
  2. In the Project panel, hover over the library name and then click the trash can icon that appears.
  3. Delete a library from a project

    The library files are removed from your project.

Delete Libraries

To delete a library, delete the library project file.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: