/*
   Protocol description
*/

// Domain declaration
domain com.chronoxor

// Package declaration
package proto

// Protocol version
version 1.0

// Order side declaration
enum OrderSide : byte
{
    buy;
    sell;
}

// Order type declaration
enum OrderType : byte
{
    market;
    limit;
    stop;
}

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

// Account balance declaration
struct Balance(2)
{
    [key] string currency;
    double amount = 0.0;
}

// Account state declaration
flags State : byte
{
    unknown = 0x00;
    invalid = 0x01;
    initialized = 0x02;
    calculated = 0x04;
    broken = 0x08;
    good = initialized | calculated;
    bad = unknown | invalid | broken;
}

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

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

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

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