RC2_IMPORT_BLOCKED
importstatements are not allowed in RaamCode.
What it means
RaamCode strategies cannot import any module — neither the Python standard library nor third-party packages. The transpiler refuses every import and from ... import statement.
Why
Three reasons:
- Determinism. Imported modules can read the environment, make network calls, or have version-specific behaviour. None of those are safe in a strategy that must produce identical results in backtest, paper, and live.
- Isolation. Strategies share infrastructure. An
importthat could pull arbitrary code defeats the entire sandbox. - Reviewability. A strategy that’s a few classes and arithmetic is auditable. One that imports
random,requests, ornumpyis not.
How to fix it
Every common motivation for an import has a RaamCode replacement:
| You wrote | Use this instead |
|---|---|
import numpy as np for np.mean, np.std |
sum(series) / len(series) inside a custom indicator, or the built-in StdDev. |
import math for math.sqrt, math.log |
Nothing — math.* is ambient. Write math.sqrt(x) with no import at all. |
import datetime to read the date |
self.trade.timestamp.hour / .minute / .weekday() / .month, and self.bar_count for the bar index. |
from typing import List |
RaamCode is untyped at the source level. Drop the import. |
import random |
Strategies must be deterministic. There is no random API, by design. |
import math gets its own message, because it is the one import people write for a library that is already there:
import mathis not needed — the math.* standard library is always available. Remove this line.
For numerical work inside an indicator, use Series plus a custom Indicator subclass — see Custom Indicators.
Common patterns
import math
class Bad(Strategy): trade = Symbol() sizing = FixedCapital()
def execute(self): if self.trade.is_flat: self.buy(self.trade)class Good(Strategy): trade = Symbol() sizing = FixedCapital()
def execute(self): sma = SMA(20, on=self.trade) sd = StdDev(20, on=self.trade)
# Bollinger bands without numpy — and math.* with no import upper = sma.value + 2 * sd.value lower = sma.value - 2 * sd.value span = math.sqrt(upper - lower)
if self.trade.close < lower and span > 0 and self.trade.is_flat: self.buy(self.trade)