
syntax = "proto3";

package ts_cop;

message DINT32 {
    int32 value = 1;
    double time = 2;
}

message DINT64 {
    int64 value = 1;
    double time = 2;
}

message DFLOAT {
    float value = 1;
    double time = 2;
}

message DDOUBLE {
    double value = 1;
    double time = 2;
}

message DSTRING {
    string value = 1;
    double time = 2;
}

message DBOOL {
    bool value = 1;
    double time = 2;
}

message CI {
    string value = 1; // json
}

message CIList {
    repeated CI ci_list = 1;
}

message SI {
    string symbol = 1;
    double ratio = 2;
    string parent_id = 3;
    string si_id = 4;
    double created = 5; // unix time
    double last_update = 6; // unix time
    string strategy_name = 7;
    bool live_mode = 8;
    string strategy_id = 9;
    string symbol_id = 10;
    string parent_strategy_name = 11;
}

message SIList {
    repeated SI si_list = 1;
}

message TSOrder {
    string symbol = 1;
    double quantity = 2;
    double fill_quantity = 3;
    string parent_id = 4;
    string order_id = 5;
    string platform_order_id = 6;
    double created = 7; // unix time
    double last_update = 8; // unix time
    string strategy_name = 9;
    bool live_mode = 10;
    string strategy_id = 11;
    string order_status = 12;
    string execution_broker = 13;
    string clearing_broker = 14;
    string account = 15;
    double price = 16;
    double fee = 17;
    string exchange = 18;
    string ccy = 19;
    string fee_ccy = 20;
    string symbol_id = 21;
    string parent_strategy_name = 22;
}

message TSOrderList {
    repeated TSOrder order_list = 1;
}

message TSTrade {
    string symbol = 1;
    double quantity = 2;
    string parent_id = 3;
    string trade_id = 4;
    double created = 5; // unix time
    double last_update = 6; // unix time
    string strategy_name = 7;
    bool live_mode = 8;
    string strategy_id = 9;
    string trade_status = 10;
    string execution_broker = 11;
    string clearing_broker = 12;
    double settlement_date = 13; // unix time
    double fx_ratio = 14;
    string account = 15;
    double price = 16;
    double fee = 17;
    string exchange = 18;
    string ccy = 19;
    string fee_ccy = 20;
    string symbol_id = 21;
    string parent_strategy_name = 22;
}

message TSTradeList {
    repeated TSTrade trade_list = 1;
}

message TSDATA {
    int32 int32_data = 1;
    int64 int64_data = 2;
    float float_data = 3;
    double double_data = 4;
    string string_data = 5;
    bool bool_data = 6;
    TSOrderList order_data = 7;
    TSTradeList trade_data = 8;
    SIList si_data = 9;
    CIList ci_data = 10;
    DINT32 d_int32_data = 11;
    DINT64 d_int64_data = 12;
    DFLOAT d_float_data = 13;
    DDOUBLE d_double_data = 14;
    DSTRING d_string_data = 15;
    DBOOL d_bool_data = 16;
}

message Cop {
    enum MsgType {
        Listing = 0;
        Strategy = 1;
        System = 2;
    }
    enum FidNum {
        Dummy = 0;
        // 00001 - 10000 --- int32
        // 10001 - 20000 --- int64
        // 20001 - 30000 --- float
        // 30001 - 40000 --- double
        // 40001 - 50000 --- string
        // 50001 - 60000 --- other
        CI = 50001;
        SI = 50002;
        Order = 50003;
        Trade = 50004;
        Order_Snap = 50005;
        // 60001 - 70000 --- bool
        // 70001 - 80000 --- d_int32
        // 80001 - 90000 --- d_int64
        // 90001 - 100000 --- d_float
        // 100001 - 110000 --- d_double
        // comment the following enum to reduce the file size
        // Cash = 100001;
        // UnsettledCash = 100002;
        // TotalUnleveredAbsoluteHoldingsCost = 100003;
        // TotalAbsoluteHoldingsCost = 100004;
        // TotalHoldingsValue = 100005;
        // TotalUnrealisedProfit = 100006;
        // TotalUnrealizedProfit = 100007;
        // TotalPortfolioValue = 100008;
        // TotalFees = 100009;
        // TotalProfit = 100010;
        // TotalNetProfit = 100011;
        // TotalSaleVolume = 100012;
        // TotalMarginUsed = 100013;
        // MarginRemaining = 100014;
        // 110001 - 120000 --- d_string
        // 120001 - 130000 --- d_bool
    }

    // header
    string msg_id = 1;
    MsgType msg_type = 2;
    string sender = 3;
    int32 instance_id = 4;
    int64 seq_num = 5;
    double created_time = 6; // unix time
    string strategy_id = 7;

    // body
    map<int32, TSDATA> data_map = 8;
}
