Skip to content

Docs: Python custom slippage model — implement get_slippage_approximation, don't subclass ISlippageModel #2736

Description

@Martin-Molinero

Gap. A Python custom slippage model is a plain class with one method, get_slippage_approximation(self, asset, order) -> float. Generated code guesses the method name (get_slippage, get_slippage_approx, get_price_adjustment, GetPriceChange) or subclasses the interface (class M(ISlippageModel)). Both fail at set_slippage_model: "ISlippageModel must be fully implemented. Please implement these missing methods …: GetSlippageApproximation" or "interface takes exactly one argument". The Model Structure page shows the correct class, but nothing warns about these forms or points to the built-in models that cover most needs.

Evidence (Sep 24–29). ISlippageModel must be fully implemented / object does not implement ISlippageModel: 34 errors from 34 users, plus interface takes exactly one argument: 7 errors from 7 users. In 8 sampled cases, every one used a wrong method name or inherited from ISlippageModel. Fee, fill and buying-power models show no equivalent errors.

Proposed change. In skill-templates/orders/SKILL.md (the "Fee / slippage / fill / buying-power models" section) and 03 Writing Algorithms/24 Reality Modeling/03 Slippage/01 Key Concepts/05 Model Structure:

Prefer a built-in model: ConstantSlippageModel(0.0005) (a percent of price), VolumeShareSlippageModel(), or NullSlippageModel.instance (zero slippage).
For a custom model, write a plain class. Don't inherit from ISlippageModel. Implement exactly get_slippage_approximation, which returns the slippage in price units:

class HalfSpreadSlippageModel:
    def get_slippage_approximation(self, asset: Security, order: Order) -> float:
        return (asset.ask_price - asset.bid_price) / 2

self.securities[symbol].set_slippage_model(HalfSpreadSlippageModel())

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions