syntax = "proto3";
package types;
option go_package = "../types";

message Exchange {}

message ExchangeAction {
    oneof value {
        LimitOrder  limitOrder  = 1;
        MarketOrder marketOrder = 2;
        RevokeOrder revokeOrder = 3;
    }
    int32 ty = 6;
}
//限价订单
message LimitOrder {
    //交易对
    asset leftAsset = 1;
    //交易对
    asset rightAsset = 2;
    //价格
    int64 price = 3;
    //总量
    int64 amount = 4;
    //操作， 1为买，2为卖
    int32 op = 5;
}

//市价委托
message MarketOrder {
    //资产1
    asset leftAsset = 1;
    //资产2
    asset rightAsset = 2;
    //总量
    int64 amount = 3;
    //操作， 1为买，2为卖
    int32 op = 4;
}

//撤回订单
message RevokeOrder {
    //订单号
    int64 orderID = 1;
}
//资产类型
message asset {
    string execer = 1;
    string symbol = 2;
}

//订单信息
message Order {
    int64 orderID = 1;
    oneof value {
        LimitOrder  limitOrder  = 2;
        MarketOrder marketOrder = 3;
    }
    //挂单类型
    int32 ty = 4;
    //已经成交的数量
    int64 executed = 5;
    //成交均价
    int64 AVG_price = 6;
    //余额
    int64 balance = 7;
    //状态,0 挂单中ordered， 1 完成completed， 2撤回 revoked
    int32 status = 8;
    //用户地址
    string addr = 9;
    //更新时间
    int64 updateTime = 10;
    //索引
    int64 index = 11;
}

//查询接口
message QueryMarketDepth {
    //资产1
    asset leftAsset = 1;
    //资产2
    asset rightAsset = 2;
    //操作， 1为买，2为卖
    int32 op = 3;
    // 这里用价格作为索引值
    string primaryKey = 4;
    //单页返回多少条记录，默认返回10条,为了系统安全最多单次只能返回20条
    int32 count = 5;
}
//市场深度
message MarketDepth {
    //资产1
    asset leftAsset = 1;
    //资产2
    asset rightAsset = 2;
    //价格
    int64 price = 3;
    //总量
    int64 amount = 4;
    //操作， 1为买，2为卖
    int32 op = 5;
}
//查询接口返回的市场深度列表
message MarketDepthList {
    repeated MarketDepth list       = 1;
    string               primaryKey = 2;
}

//查询最新得成交信息,外部接口
message QueryHistoryOrderList {
    //资产1
    asset leftAsset = 1;
    //资产2
    asset rightAsset = 2;
    // 索引值
    string primaryKey = 3;
    //单页返回多少条记录，默认返回10条,为了系统安全最多单次只能返回20条
    int32 count = 4;
    // 0降序，1升序，默认降序
    int32 direction = 5;
}

//根据orderID去查询订单信息
message QueryOrder {
    int64 orderID = 1;
}
//根据地址，状态查询用户自己的挂单信息
message QueryOrderList {
    //挂单状态必填(默认是0,只查询ordered挂单中的)
    int32 status = 1;
    //用户地址信息，必填
    string address = 2;
    // 主键索引
    string primaryKey = 3;
    //单页返回多少条记录，默认返回10条,为了系统安全最多单次只能返回20条
    int32 count = 4;
    // 0降序，1升序，默认降序
    int32 direction = 5;
}
//订单列表
message OrderList {
    repeated Order list       = 1;
    string         primaryKey = 2;
}

// exchange执行票据日志
message ReceiptExchange {
    Order    order             = 1;
    repeated Order matchOrders = 2;
    int64          index       = 3;
}
service exchange {}
