Skip to content

LeanDataWriter

QuantConnect.Data.LeanDataWriter

LeanDataWriter(
    resolution: Resolution,
    symbol: Union[Symbol, str, BaseContract],
    data_directory: str,
    tick_type: TickType = ...,
    data_cache_provider: IDataCacheProvider = None,
    write_policy: Optional[WritePolicy] = None,
    map_symbol: bool = False,
)
LeanDataWriter(
    data_directory: str,
    resolution: Resolution,
    security_type: SecurityType,
    tick_type: TickType,
    data_cache_provider: IDataCacheProvider = None,
    write_policy: Optional[WritePolicy] = None,
)

Bases: Object

Data writer for saving an IEnumerable of BaseData into the LEAN data directory.

Create a new lean data writer to this base data directory.

Parameters:

Name Type Description Default
symbol Optional[Union[Symbol, str, BaseContract]]

Symbol string

None
data_directory str

Base data directory

required
resolution Resolution

Resolution of the desired output data

required
tick_type TickType

The tick type

...
data_cache_provider IDataCacheProvider

The data cache provider to use

None
write_policy Optional[WritePolicy]

The file write policy to use

None
map_symbol Optional[bool]

True if the symbol should be mapped while writting the data

False
security_type Optional[SecurityType]

The security type

None

map_file_provider

map_file_provider: Lazy[IMapFileProvider]

The map file provider instance to use

download_and_save

download_and_save(
    brokerage: IBrokerage,
    symbols: List[Symbol],
    start_time_utc: Union[datetime, date],
    end_time_utc: Union[datetime, date],
) -> None

Downloads historical data from the brokerage and saves it in LEAN format.

Parameters:

Name Type Description Default
brokerage IBrokerage

The brokerage from where to fetch the data

required
symbols List[Symbol]

The list of symbols

required
start_time_utc Union[datetime, date]

The starting date/time (UTC)

required
end_time_utc Union[datetime, date]

The ending date/time (UTC)

required

write

write(source: List[BaseData]) -> None

Given the constructor parameters, write out the data in LEAN format.

Parameters:

Name Type Description Default
source List[BaseData]

IEnumerable source of the data: sorted from oldest to newest.

required