-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexchange.proto
140 lines (110 loc) · 2.59 KB
/
exchange.proto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
syntax = "proto3";
// python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. exchange.proto
package exchange;
service ExchangeService {
// Connection functions
rpc Alive (Empty) returns (ReviveInfo) {}
rpc RequestHeartbeat (Empty) returns (HeartbeatResponse) {}
// Voting functions
rpc ProposeCommit (CommitRequest) returns (CommitVote) {}
rpc SendVoteResult (CommitVote) returns (Empty) {}
// Client (broker) functions
rpc Ping (Empty) returns (Empty) {}
// From institutions to exchange
rpc SendOrder(OrderInfo) returns (OrderId) {}
rpc CancelOrder(OrderId) returns (Result) {}
rpc GetOrderList(Ticker) returns (OrderList) {}
rpc DepositCash(Deposit) returns (Result) {}
// From exchange to institutions, brokers
rpc OrderFill(UserInfo) returns (FillInfo) {}
}
service BrokerService {
// From user to broker
rpc LogIn(UserInfo) returns (Result) {}
rpc LogOut(Empty) returns (Result) {} // may or may not end up using log in / log out
rpc Register(UserInfo) returns (Result) {}
rpc SendOrder(OrderInfo) returns (OrderId) {}
rpc CancelOrder(CancelRequest) returns (Result) {}
rpc GetBalance(UserId) returns (Balance) {}
rpc DepositCash(Deposit) returns (Empty) {}
rpc GetStocks(UserId) returns (UserStocks) {}
rpc GetOrderList(Ticker) returns (OrderList) {}
// From broker to user
rpc OrderFill(UserInfo) returns (BrokerFillInfo) {}
}
enum OrderType {
BID = 0;
ASK = 1;
}
message OrderList {
bytes pickle = 1;
}
message Ticker {
string ticker = 1;
}
message UserStocks {
bytes pickle = 1;
}
message Deposit {
int32 uid = 1;
int32 amount = 2;
}
message CancelRequest {
int32 uid = 1;
int32 oid = 2;
}
message OrderId {
int64 oid = 1;
}
message ReviveInfo {
int64 primary_port = 1;
string commit_log = 2;
bytes db_bytes = 3;
bool updates = 4;
}
message HeartbeatResponse {
int64 port = 1;
bool primary = 2;
}
message CommitRequest {
string commit = 1;
int64 ballot_id = 2;
}
message CommitVote {
bool approve = 1;
string commit = 2;
int64 ballot_id = 3;
}
message Result {
bool result = 1;
string message = 2;
}
message Empty {}
message Balance {
int32 balance = 1;
}
message UserId {
int32 uid = 1;
}
message FillInfo {
int32 oid = 1;
int32 amount_filled = 2;
int32 execution_price = 3;
}
message BrokerFillInfo {
int32 oid = 1;
string ticker = 2;
OrderType order_type = 3;
int32 amount_filled = 4;
int32 execution_price = 5;
}
message OrderInfo {
string ticker = 1;
int32 quantity = 2;
int32 price = 3;
int32 uid = 4;
OrderType type = 5;
}
message UserInfo {
int32 uid = 1;
}