# otp.config

### *class* Config

Bases: [`object`](https://docs.python.org/3/library/functions.html#object)

This object is used to access `onetick.py` configuration variables.

Configuration variables may be accessed via `otp.config['...']` syntax, e.g. `otp.config['tz']`.

Configuration variables may be changed by:

* during python runtime by modifying properties of object `otp.config`,
* by setting environment variables *before* importing `onetick.py` module.

During python runtime you can modify properties of `otp.config` object either directly or via context manager:
`with otp.config('property', 'value'):`

Also special environment variable `OTP_DEFAULT_CONFIG_PATH` can be used to specify a file,
from which configuration variables will be taken.
This file will be read only once on module loading or when getting one of the configuration variables
when the environment variable is discovered.
The names of the variables in this file are the same as the names of environment variables.

In case several methods of setting configuration variables are used,
the following order of priority is in place:

1. Value that is set by modifying object `otp.config`
2. Value that is set via environment variable
3. Value that is set in file `OTP_DEFAULT_CONFIG_PATH`
4. Default value specified in the source code

To reset configuration value that has been set by modifying object `otp.config`,
special value `otp.config.default` should be assigned to it.

Most of the config vars are optional and have default values,
but some of them need to be set manually.

There are also some environment variables that do not have
corresponding property in `otp.config` object:

* `OTP_BASE_FOLDER_FOR_GENERATED_RESOURCE`:
  a folder where all intermediate queries, files and databases
  generated by `onetick-py` are located.
  The default value is system-dependent, e.g. some generated
  directory with a unique name under a standard directory **/tmp** for Linux.

**The following properties must be set manually in most cases:**

#### default_start_time *: [datetime](datetime/dt.md#onetick.py.datetime), [datetime](datetime/dt.md#onetick.py.datetime)* *= nothing*

Default start time used for running queries, e.g. with [`otp.run`](run.md#onetick.py.run).

Can be set using environment variable `OTP_DEFAULT_START_TIME`.

Format of the env variable: `%Y/%m/%d %H:%M:%S.%f`, `%Y/%m/%d %H:%M:%S`.

#### default_end_time *: [datetime](datetime/dt.md#onetick.py.datetime), [datetime](datetime/dt.md#onetick.py.datetime)* *= nothing*

Default end time used for running queries, e.g. with [`otp.run`](run.md#onetick.py.run).

Can be set using environment variable `OTP_DEFAULT_END_TIME`.

Format of the env variable: `%Y/%m/%d %H:%M:%S.%f`, `%Y/%m/%d %H:%M:%S`.

#### default_db *: [str](https://docs.python.org/3/library/stdtypes.html#str)* *= nothing*

Default database name used for running queries, e.g. with [`otp.run`](run.md#onetick.py.run). Default value is not set. In this case it should be set in symbol name for each running query. Also special value LOCAL can be used.This means the query will be processed on the client machine, if it has OneTick installed, otherwise it will be processed on the first available OneTick server, depending on client or server configuration.

Can be set using environment variable `OTP_DEFAULT_DB`.

#### default_symbol *: [str](https://docs.python.org/3/library/stdtypes.html#str)* *= nothing*

Default symbol name used for running queries, e.g. with [`otp.run`](run.md#onetick.py.run).

Can be set using environment variable `OTP_DEFAULT_SYMBOL`.

**The following properties can be changed:**

#### tz *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType* *= None*

Default timezone used for running queries and creating databases, e.g. with [`otp.run`](run.md#onetick.py.run). Default value is the local timezone of your machine.

Can be set using environment variable `OTP_DEFAULT_TZ`.

#### context *: [str](https://docs.python.org/3/library/stdtypes.html#str)* *= 'DEFAULT'*

Default context used for running queries, e.g. with [`otp.run`](run.md#onetick.py.run).Note: In WebAPI mode it will have None value.

Can be set using environment variable `OTP_CONTEXT`.

#### default_symbology *: [str](https://docs.python.org/3/library/stdtypes.html#str)* *= 'BZX'*

Default database symbology.

Can be set using environment variable `OTP_DEFAULT_SYMBOLOGY`.

#### default_concurrency *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType, [int](https://docs.python.org/3/library/functions.html#int)* *= None*

Default concurrency level used for running queries, e.g. with [`otp.run`](run.md#onetick.py.run). Default value is `None` which means that the value is adaptive and is set to 0 (meaning concurrency will be auto-assigned by OneTick server) on the latest OneTick versions where it is supported or to 1 (meaning no concurrency) on older versions. Special value `local_number_of_cores` can be used to set concurrency to the number of cores of the machine where python code executes (this corresponds to the previous default logic still expected by some users).

Can be set using environment variable `OTP_DEFAULT_CONCURRENCY`.

#### presort_force_default_concurrency *: [bool](https://docs.python.org/3/library/functions.html#bool)* *= False*

By default concurrency value for PRESORT EPs is empty and inherited from the concurrency level set in the query where this EP is used. However, is some cases it may be desirable to force setting default concurrency level for all PRESORT EPs (this corresponds to the previous default logic still expected by some users), for example when PRESORT is located in the first stage query and cannot inherit concurrency from the main query.

Can be set using environment variable `OTP_PRESORT_FORCE_DEFAULT_CONCURRENCY`.

#### default_batch_size *: [int](https://docs.python.org/3/library/functions.html#int)* *= 0*

Default batch size used for running queries, e.g. with [`otp.run`](run.md#onetick.py.run). Batch size is the maximum number of symbols that are processed at once. The value of 0 means unlimited -- works faster for simple queries, but may consume too much memory for complex queries.

Can be set using environment variable `OTP_DEFAULT_BATCH_SIZE`.

#### default_license_dir *: [str](https://docs.python.org/3/library/stdtypes.html#str)* *= '/license'*

Default path for license directory. Needed for user to be allowed to use OneTick API. Default value is system-dependent: **/license** for Linux systems and **C:/OMD/client_data/config/license_repository** for Windows systems.

Can be set using environment variable `OTP_DEFAULT_LICENSE_DIR`.

#### default_license_file *: [str](https://docs.python.org/3/library/stdtypes.html#str)* *= '/license/license.dat'*

Default path for license file. Needed for user to be allowed to use OneTick API. Default value is system-dependent: **/license/license.dat** for Linux systems and **C:/OMD/client_data/config/license.dat** for Windows systems.

Can be set using environment variable `OTP_DEFAULT_LICENSE_FILE`.

#### default_fault_tolerance *: [str](https://docs.python.org/3/library/stdtypes.html#str)* *= 'FALSE'*

Default value for USE_FT query property. Default is FALSE. If set to TRUE, the query will be rerun on a different tick server in case of connection errors or if server times out. The query is restarted even if some data has already been received.

Can be set using environment variable `OTP_DEFAULT_FAULT_TOLERANCE`.

#### min_same_host_retry_interval_sec *: NoneType, [int](https://docs.python.org/3/library/functions.html#int)* *= None*

Default value for min_same_host_retry_interval_sec query FT property. It is an integer value that specifies the minimum number of seconds that need to have passed from the last failure in order to retry a host, if all hosts have failed. If the value is negative, hosts are not retried. Default value is not set, which means it will be set internally by OneTick to 5 minutes. This property is used only if [`default_fault_tolerance`](#onetick.py.configuration.Config.default_fault_tolerance) is set to True.

Can be set using environment variable `OTP_MIN_SAME_HOST_RETRY_INTERVAL_SEC`.

#### default_username *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType* *= None*

Default username to call queries. By default the name of the owner of the current process is used.

Can be set using environment variable `OTP_DEFAULT_USERNAME`.

#### default_auth_username *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType* *= None*

Default username used for authentication.

Can be set using environment variable `OTP_DEFAULT_AUTH_USERNAME`.

#### default_password *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType* *= None*

Default password used for authentication.

Can be set using environment variable `OTP_DEFAULT_PASSWORD`.

#### http_address *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType* *= None*

Default HTTP server used as WebAPI endpoint.

Can be set using environment variable `OTP_HTTP_ADDRESS`.

#### http_username *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType* *= None*

Username used for WebAPI authentication.

Can be set using environment variable `OTP_HTTP_USERNAME`.

#### http_password *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType* *= None*

Password used for WebAPI authentication.

Can be set using environment variable `OTP_HTTP_PASSWORD`.

#### http_proxy *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType* *= None*

HTTP proxy used for WebAPI requests.

Can be set using environment variable `HTTP_PROXY`.

#### https_proxy *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType* *= None*

HTTPS proxy used for WebAPI requests.

Can be set using environment variable `HTTPS_PROXY`.

#### access_token *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType* *= None*

SSO access token for WebAPI endpoint.

Can be set using environment variable `OTP_ACCESS_TOKEN`.

#### client_id *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType* *= None*

Client ID for obtaining SSO access token.

Can be set using environment variable `OTP_CLIENT_ID`.

#### client_secret *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType* *= None*

Client Secret for obtaining SSO access token.

Can be set using environment variable `OTP_CLIENT_SECRET`.

#### access_token_url *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType* *= None*

URL for obtaining SSO access token.

Can be set using environment variable `OTP_ACCESS_TOKEN_URL`.

#### access_token_scope *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType* *= None*

Scope for obtaining SSO access token.

Can be set using environment variable `OTP_ACCESS_TOKEN_SCOPE`.

#### trusted_certificates_file *: [bool](https://docs.python.org/3/library/functions.html#bool), NoneType, [str](https://docs.python.org/3/library/stdtypes.html#str)* *= None*

Either a boolean, in which case it controls whether we verify the server TLS certificate or a string with the path to the file with list of trusted Certificate Authority certificates for WebAPI requests. Default behaviour implies verification is enabled.

Can be set using environment variable `OTP_SSL_CERT_FILE`.

#### max_expected_ticks_per_symbol *: NoneType, [int](https://docs.python.org/3/library/functions.html#int)* *= None*

Expected maximum number of ticks per symbol (used for performance optimizations). Default is 2000.

Can be set using environment variable `OTP_MAX_EXPECTED_TICKS_PER_SYMBOL`.

#### show_stack_info *: [bool](https://docs.python.org/3/library/functions.html#bool), [str](https://docs.python.org/3/library/stdtypes.html#str), [int](https://docs.python.org/3/library/functions.html#int)* *= False*

Show stack info (filename and line or stack trace) in OneTick exceptions.

#### log_symbol *: [bool](https://docs.python.org/3/library/functions.html#bool), [str](https://docs.python.org/3/library/stdtypes.html#str), [int](https://docs.python.org/3/library/functions.html#int)* *= False*

Log currently executed symbol. Note, this only works with unbound symbols. Note, in this case [`otp.run`](run.md#onetick.py.run) does not produce the output so it should be used only for debugging purposes.

Can be set using environment variable `OTP_LOG_SYMBOL`.

#### ignore_ticks_in_unentitled_time_range *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType, [bool](https://docs.python.org/3/library/functions.html#bool), [int](https://docs.python.org/3/library/functions.html#int)* *= None*

Default value for IGNORE_TICKS_IN_UNENTITLED_TIME_RANGE query property. By default it is set to None, which means that the property is not set in queries and the OneTick server may decide what to do, if configured.

Can be set using environment variable `OTP_IGNORE_TICKS_IN_UNENTITLED_TIME_RANGE`.

#### main_query_generated_filename *: [str](https://docs.python.org/3/library/stdtypes.html#str)* *= ''*

The name of the .otq file with generated main query executed by otp.run.

Can be set using environment variable `OTP_MAIN_QUERY_GENERATED_FILENAME`.

#### logging *: [str](https://docs.python.org/3/library/stdtypes.html#str)* *= 'WARNING'*

The logging level string or path to the file with configuration. Check the documentation of python logging module for the configuration formats. JSON format (in the file with .json suffix) and python configparser formats are supported.

Can be set using environment variable `OTP_LOGGING`.

#### otq_debug_mode *: [bool](https://docs.python.org/3/library/functions.html#bool), [str](https://docs.python.org/3/library/stdtypes.html#str), [int](https://docs.python.org/3/library/functions.html#int)* *= False*

Enable .otq files debug mode. If set to True, onetick.py will keep all generated otq files and log their paths to the console.

Can be set using environment variable `OTP_OTQ_DEBUG_MODE`.

#### allow_lowercase_in_saved_fields *: [bool](https://docs.python.org/3/library/functions.html#bool)* *= True*

Allow using lower case characters in field names that are being stored in Onetick databases. If set to False, onetick.py would not allow saving fields with lower case characters to a database.

#### clean_up_tmp_files *: [bool](https://docs.python.org/3/library/functions.html#bool), [str](https://docs.python.org/3/library/stdtypes.html#str), [int](https://docs.python.org/3/library/functions.html#int)* *= True*

Control deleting temporary files created by onetick-py. Temporary files are OneTick configuration files and generated .otq queries.

Can be set using environment variable `OTP_CLEAN_UP_TMP_FILES`.

#### default_schema_policy *: [str](https://docs.python.org/3/library/stdtypes.html#str), NoneType* *= None*

Default schema policy when querying onetick database. See parameter `schema_policy` in [`otp.DataSource`](sources/data_source.md#onetick.py.DataSource) for the list of supported values.

Can be set using environment variable `OTP_DEFAULT_SCHEMA_POLICY`.

#### disable_compatibility_checks *: [bool](https://docs.python.org/3/library/functions.html#bool)* *= False*

Disable compatibility checks when querying OneTick database. Using this parameter outside test environment could lead to unexpected errors.

Can be set using environment variable `OTP_DISABLE_COMPATIBILITY_CHECKS`.

#### print_symbol_errors *: [bool](https://docs.python.org/3/library/functions.html#bool)* *= True*

When calling otp.run that returns dataframe as result print symbol errors from OneTick as python warnings.

Can be set using environment variable `OTP_PRINT_SYMBOL_ERRORS`.

**The following properties are derived and thus read-only:**

#### default_db_symbol *: [str](https://docs.python.org/3/library/stdtypes.html#str)* *= US_COMP_SAMPLE::AAPL*

Default symbol with database. Defined with [`default_db`](#onetick.py.configuration.Config.default_db) and [`default_symbol`](#onetick.py.configuration.Config.default_symbol) as string **default_db::default_symbol**.

#### default_date *: [datetime](datetime/dt.md#onetick.py.datetime)* *= 2024-02-01 00:00:00*

Default date. Defined as a date part of [`default_start_time`](#onetick.py.configuration.Config.default_start_time).
