Defining Events

An event is an occurrence of a particular item at a specific time. The "complex" events are distilled from the incoming events through some specific conditions.

In DolphinDB, an event is defined using a class, following the Object-Oriented Programming. Each event class can create event instances with a specific schema. These event instances share the same event name (eventType) and a predefined set of event fields that determine the event schema.

Syntax

class eventType {
  // define the data members
  field_name1 :: filed_type1
  ...
  field_namen :: filed_typen
  // define constructor with the same name as class
  def eventType(a,..., b){
  // initialize the data members
  field_name1 = a
  ...
  field_namen = b
  }
}

where,

eventType is the name of the class (starts with a letter or underscore "_") that defines a specific event type.

field_name1 … field_namen is the name of event fields.

field_type1 … filed_typen is the data type of event fields. The supported data forms and types are listed in the following table.

Data Forms Data Types
Scalar Can be any DolphinDB data types
Vector BOOL, CHAR, SHORT, INT, INDEX, LONG, DATE, MONTH, TIME, MINUTE, SECOND, DATETIME, TIMESTAMP, NANOTIME, NANOTIMESTAMP, DATEHOUR, FLOAT, DOUBLE, STRING, BLOB, INT128, UUID, IPADDR, POINT, COMPLEX, DECIMAL32(S), DECIMAL64(S), DECIMAL128(S), DURATION, ANY
Array Vector ARRAY: Data types + the square bracket "[]", i.e., INT[], DOUBLE[], DECIMAL32(3)[], etc.

Examples

Define an event "orders" containing 6 event fields and declare a constructor with the following script.

class orders{
    trader :: STRING
    market :: STRING
    code :: STRING
    price :: DOUBLE
    qty :: INT
    eventTime :: TIMESTAMP
    def orders(t, m, c, p, q){
        trader = t
        market = m
        code = c
        price = p
        qty = q
        eventTime = now()
    }
}