/*
   Extended protocol description
*/

// Domain declaration
domain com.chronoxor

// Package declaration
package protoex offset 10

// Protocol version
version 1.0

// Package imports
import proto

// Extended order side declaration
enum OrderSide : byte
{
    buy;
    sell;
    tell;
}

// Extended order type declaration
enum OrderType : byte
{
    market;
    limit;
    stop;
    stoplimit;
}

// Extended order declaration
struct Order(1)
{
    [key] int32 id;
    string symbol;
    OrderSide side;
    OrderType type;
    double price = 0.0;
    double volume = 0.0;
    double tp = 10.0;
    double sl = -10.0;
}

// Extended account balance declaration
struct Balance(base) : proto.Balance
{
    double locked = 0.0;
}

// Balance account state declaration
flags StateEx : byte
{
    unknown = 0x00;
    invalid = 0x01;
    initialized = 0x02;
    calculated = 0x04;
    broken = 0x08;
    happy = 0x10;
    sad = 0x20;
    good = initialized | calculated;
    bad = unknown | invalid | broken;
}

// Extended account declaration
struct Account(3)
{
    [key] int32 id;
    string name;
    StateEx state = StateEx.initialized | StateEx.bad | StateEx.sad;
    Balance wallet;
    Balance? asset;
    Order[] orders;
}

// Extended order message declaration
message OrderMessage
{
    Order body;
}

// Extended balance message declaration
message BalanceMessage
{
    Balance body;
}

// Extended account message declaration
message AccountMessage
{
    Account body;
}
