-
Notifications
You must be signed in to change notification settings - Fork 0
/
mgo.proto
338 lines (264 loc) · 12.1 KB
/
mgo.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
syntax = "proto3";
package mgo.portfolio.v1;
import "google/api/annotations.proto";
import "google/api/field_behavior.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";
option go_package = "github.com/oxisto/money-gopher/gen;portfoliov1";
// Currency is a currency value in the lowest unit of the selected currency
// (e.g., cents for EUR/USD).
message Currency {
int32 value = 1 [(google.api.field_behavior) = REQUIRED];
string symbol = 2 [(google.api.field_behavior) = REQUIRED];
}
message CreatePortfolioRequest {
Portfolio portfolio = 1 [(google.api.field_behavior) = REQUIRED];
}
message ListPortfoliosRequest {}
message ListPortfoliosResponse {
repeated Portfolio portfolios = 1 [(google.api.field_behavior) = REQUIRED];
}
message GetPortfolioRequest {
string name = 1 [(google.api.field_behavior) = REQUIRED];
}
message UpdatePortfolioRequest {
Portfolio portfolio = 1 [(google.api.field_behavior) = REQUIRED];
google.protobuf.FieldMask updateMask = 2 [(google.api.field_behavior) = REQUIRED];
}
message DeletePortfolioRequest {
string name = 1 [(google.api.field_behavior) = REQUIRED];
}
message GetPortfolioSnapshotRequest {
// PortfolioName is the name / identifier of the portfolio we want to
// "snapshot".
string portfolio_name = 1 [(google.api.field_behavior) = REQUIRED];
// Time is the point in time of the requested snapshot.
google.protobuf.Timestamp time = 2 [(google.api.field_behavior) = REQUIRED];
}
message CreatePortfolioTransactionRequest {
PortfolioEvent transaction = 1 [(google.api.field_behavior) = REQUIRED];
}
message GetPortfolioTransactionRequest {
string name = 1 [(google.api.field_behavior) = REQUIRED];
}
message ListPortfolioTransactionsRequest {
string portfolio_name = 1 [(google.api.field_behavior) = REQUIRED];
}
message ListPortfolioTransactionsResponse {
repeated PortfolioEvent transactions = 1 [(google.api.field_behavior) = REQUIRED];
}
message UpdatePortfolioTransactionRequest {
PortfolioEvent transaction = 1 [(google.api.field_behavior) = REQUIRED];
google.protobuf.FieldMask updateMask = 2 [(google.api.field_behavior) = REQUIRED];
}
message DeletePortfolioTransactionRequest {
int32 transaction_id = 1 [(google.api.field_behavior) = REQUIRED];
}
message ImportTransactionsRequest {
string portfolio_name = 1 [(google.api.field_behavior) = REQUIRED];
string from_csv = 2 [(google.api.field_behavior) = REQUIRED];
}
message CreateBankAccountRequest {
BankAccount bank_account = 1 [(google.api.field_behavior) = REQUIRED];
}
message UpdateBankAccountRequest {
BankAccount account = 1 [(google.api.field_behavior) = REQUIRED];
google.protobuf.FieldMask updateMask = 2 [(google.api.field_behavior) = REQUIRED];
}
message DeleteBankAccountRequest {
string name = 1 [(google.api.field_behavior) = REQUIRED];
}
message Portfolio {
string name = 1 [(google.api.field_behavior) = REQUIRED];
string display_name = 2 [(google.api.field_behavior) = REQUIRED];
// BankAccountName contains the name/identifier of the underlying bank
// account.
string bank_account_name = 3 [(google.api.field_behavior) = REQUIRED];
// Events contains all portfolio events, such as buy/sell transactions,
// dividends or other. They need to be ordered by time (ascending).
repeated PortfolioEvent events = 5;
}
message BankAccount {
string name = 1 [(google.api.field_behavior) = REQUIRED];
string display_name = 2 [(google.api.field_behavior) = REQUIRED];
}
// PortfolioSnapshot represents a snapshot in time of the portfolio. It can for
// example be the current state of the portfolio but also represent the state of
// the portfolio at a certain time in the past.
message PortfolioSnapshot {
// Time is the time when this snapshot was taken.
google.protobuf.Timestamp time = 1 [(google.api.field_behavior) = REQUIRED];
// Positions holds the current positions within the snapshot and their value.
map<string, PortfolioPosition> positions = 2 [(google.api.field_behavior) = REQUIRED];
// FirstTransactionTime is the time of the first transaction with the
// snapshot.
optional google.protobuf.Timestamp first_transaction_time = 3 [(google.api.field_behavior) = REQUIRED];
// TotalPurchaseValue contains the total purchase value of all asset positions
Currency total_purchase_value = 10 [(google.api.field_behavior) = REQUIRED];
// TotalMarketValue contains the total market value of all asset positions
Currency total_market_value = 11 [(google.api.field_behavior) = REQUIRED];
// TotalProfitOrLoss contains the total absolute amount of profit or loss in
// this snapshot, based on asset value.
Currency total_profit_or_loss = 20 [(google.api.field_behavior) = REQUIRED];
// TotalGains contains the total relative amount of profit or loss in this
// snapshot, based on asset value.
double total_gains = 21 [(google.api.field_behavior) = REQUIRED];
// Cash contains the current amount of cash in the portfolio's bank
// account(s).
Currency cash = 22 [(google.api.field_behavior) = REQUIRED];
// TotalPortfolioValue contains the amount of cash plus the total market value
// of all assets.
Currency total_portfolio_value = 23 [(google.api.field_behavior) = REQUIRED];
}
message PortfolioPosition {
Security security = 1 [(google.api.field_behavior) = REQUIRED];
double amount = 2 [(google.api.field_behavior) = REQUIRED];
// PurchaseValue was the market value of this position when it was bought
// (net; exclusive of any fees).
Currency purchase_value = 5 [(google.api.field_behavior) = REQUIRED];
// PurchasePrice was the market price of this position when it was bought
// (net; exclusive of any fees).
Currency purchase_price = 6 [(google.api.field_behavior) = REQUIRED];
// MarketValue is the current market value of this position, as retrieved from
// the securities service.
Currency market_value = 10 [(google.api.field_behavior) = REQUIRED];
// MarketPrice is the current market price of this position, as retrieved from
// the securities service.
Currency market_price = 11 [(google.api.field_behavior) = REQUIRED];
// TotalFees is the total amount of fees accumulating in this position through
// various transactions.
Currency total_fees = 15 [(google.api.field_behavior) = REQUIRED];
// ProfitOrLoss contains the absolute amount of profit or loss in this
// position.
Currency profit_or_loss = 20 [(google.api.field_behavior) = REQUIRED];
// Gains contains the relative amount of profit or loss in this position.
double gains = 21 [(google.api.field_behavior) = REQUIRED];
}
enum PortfolioEventType {
PORTFOLIO_EVENT_TYPE_UNSPECIFIED = 0;
PORTFOLIO_EVENT_TYPE_BUY = 1;
PORTFOLIO_EVENT_TYPE_SELL = 2;
PORTFOLIO_EVENT_TYPE_DELIVERY_INBOUND = 3;
PORTFOLIO_EVENT_TYPE_DELIVERY_OUTBOUND = 4;
PORTFOLIO_EVENT_TYPE_DIVIDEND = 10;
PORTFOLIO_EVENT_TYPE_INTEREST = 11;
PORTFOLIO_EVENT_TYPE_DEPOSIT_CASH = 20;
PORTFOLIO_EVENT_TYPE_WITHDRAW_CASH = 21;
PORTFOLIO_EVENT_TYPE_ACCOUNT_FEES = 30;
PORTFOLIO_EVENT_TYPE_TAX_REFUND = 31;
}
message PortfolioEvent {
string name = 1 [(google.api.field_behavior) = REQUIRED];
PortfolioEventType type = 2 [(google.api.field_behavior) = REQUIRED];
google.protobuf.Timestamp time = 3 [(google.api.field_behavior) = REQUIRED];
string portfolio_name = 4 [(google.api.field_behavior) = REQUIRED];
string security_name = 5 [(google.api.field_behavior) = REQUIRED];
double amount = 10 [(google.api.field_behavior) = REQUIRED];
Currency price = 11 [(google.api.field_behavior) = REQUIRED];
Currency fees = 12 [(google.api.field_behavior) = REQUIRED];
Currency taxes = 13 [(google.api.field_behavior) = REQUIRED];
}
service PortfolioService {
rpc CreatePortfolio(CreatePortfolioRequest) returns (Portfolio) {
option (google.api.http) = {
post: "/v1/portfolios"
body: "portfolio"
};
}
rpc ListPortfolios(ListPortfoliosRequest) returns (ListPortfoliosResponse) {
option idempotency_level = NO_SIDE_EFFECTS;
option (google.api.http) = {get: "/v1/portfolios"};
}
rpc GetPortfolio(GetPortfolioRequest) returns (Portfolio) {
option idempotency_level = NO_SIDE_EFFECTS;
option (google.api.http) = {get: "/v1/portfolios/{name}"};
}
rpc UpdatePortfolio(UpdatePortfolioRequest) returns (Portfolio);
rpc DeletePortfolio(DeletePortfolioRequest) returns (google.protobuf.Empty);
rpc GetPortfolioSnapshot(GetPortfolioSnapshotRequest) returns (PortfolioSnapshot) {
option idempotency_level = NO_SIDE_EFFECTS;
option (google.api.http) = {get: "/v1/portfolios/{portfolio_name}/snapshot"};
}
rpc CreatePortfolioTransaction(CreatePortfolioTransactionRequest) returns (PortfolioEvent) {
option (google.api.http) = {
post: "/v1/portfolios/{transaction.portfolio_name}/transactions"
body: "transaction"
};
}
rpc GetPortfolioTransaction(GetPortfolioTransactionRequest) returns (PortfolioEvent) {
option idempotency_level = NO_SIDE_EFFECTS;
option (google.api.http) = {get: "/v1/transactions/{name}"};
}
rpc ListPortfolioTransactions(ListPortfolioTransactionsRequest) returns (ListPortfolioTransactionsResponse) {
option idempotency_level = NO_SIDE_EFFECTS;
option (google.api.http) = {get: "/v1/portfolios/{portfolio_name}/transactions"};
}
rpc UpdatePortfolioTransaction(UpdatePortfolioTransactionRequest) returns (PortfolioEvent) {
option (google.api.http) = {
put: "/v1/transactions/{transaction.name}"
body: "transaction"
};
}
rpc DeletePortfolioTransaction(DeletePortfolioTransactionRequest) returns (google.protobuf.Empty);
rpc ImportTransactions(ImportTransactionsRequest) returns (google.protobuf.Empty);
rpc CreateBankAccount(CreateBankAccountRequest) returns (BankAccount);
rpc UpdateBankAccount(UpdateBankAccountRequest) returns (BankAccount);
rpc DeleteBankAccount(DeleteBankAccountRequest) returns (google.protobuf.Empty);
}
message Security {
// Name contains the unique resource name. For a stock or bond, this should be
// an ISIN.
string name = 1 [(google.api.field_behavior) = REQUIRED];
// DisplayName contains the human readable name.
string display_name = 2 [(google.api.field_behavior) = REQUIRED];
repeated ListedSecurity listed_on = 4 [(google.api.field_behavior) = REQUIRED];
optional string quote_provider = 10 [(google.api.field_behavior) = REQUIRED];
}
message ListedSecurity {
string security_name = 1 [(google.api.field_behavior) = REQUIRED];
string ticker = 3 [(google.api.field_behavior) = REQUIRED];
string currency = 4 [(google.api.field_behavior) = REQUIRED];
optional Currency latest_quote = 5;
optional google.protobuf.Timestamp latest_quote_timestamp = 6;
}
message ListSecuritiesRequest {
message Filter {
repeated string security_names = 1;
}
optional Filter filter = 5;
}
message ListSecuritiesResponse {
repeated Security securities = 1 [(google.api.field_behavior) = REQUIRED];
}
message GetSecurityRequest {
string name = 1 [(google.api.field_behavior) = REQUIRED];
}
message CreateSecurityRequest {
Security security = 1 [(google.api.field_behavior) = REQUIRED];
}
message UpdateSecurityRequest {
Security security = 1 [(google.api.field_behavior) = REQUIRED];
google.protobuf.FieldMask updateMask = 2 [(google.api.field_behavior) = REQUIRED];
}
message DeleteSecurityRequest {
string name = 1 [(google.api.field_behavior) = REQUIRED];
}
message TriggerQuoteUpdateRequest {
repeated string security_names = 1;
}
message TriggerQuoteUpdateResponse {}
service SecuritiesService {
rpc ListSecurities(ListSecuritiesRequest) returns (ListSecuritiesResponse) {
option idempotency_level = NO_SIDE_EFFECTS;
option (google.api.http) = {get: "/v1/securities"};
}
rpc GetSecurity(GetSecurityRequest) returns (Security) {
option idempotency_level = NO_SIDE_EFFECTS;
option (google.api.http) = {get: "/v1/securities/{name}"};
}
rpc CreateSecurity(CreateSecurityRequest) returns (Security);
rpc UpdateSecurity(UpdateSecurityRequest) returns (Security);
rpc DeleteSecurity(DeleteSecurityRequest) returns (google.protobuf.Empty);
rpc TriggerSecurityQuoteUpdate(TriggerQuoteUpdateRequest) returns (TriggerQuoteUpdateResponse);
}