/
grpcoin.proto
139 lines (116 loc) · 4.2 KB
/
grpcoin.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
// Copyright 2021 Ahmet Alp Balkan
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";
package grpcoin;
option go_package = "api/grpcoin";
option csharp_namespace = "GrpCoin";
import "google/protobuf/timestamp.proto";
service TickerInfo {
// Watch returns real-time quotes of the ticker.
// The only supported tickers are "BTC", "ETH", "DOGE", "DOT".
//
// This stream terminates after 15 minutes, so expect being
// abruptly disconnected and need to reconnect.
//
// No authentication required.
rpc Watch (TickerWatchRequest) returns (stream Quote) {}
}
service PaperTrade {
// Returns authenticated user's portfolio.
rpc Portfolio (PortfolioRequest) returns (PortfolioResponse) {}
// Executes a trade in authenticated user's portfolio.
// All trades are executed immediately with the real-time market
// price provided on TickerInfo.Watch endpoint.
rpc Trade (TradeRequest) returns (TradeResponse) {}
// Returns symbols supported by Trade or Watch methods.
rpc ListSupportedCurrencies (ListSupportedCurrenciesRequest) returns (ListSupportedCurrenciesResponse) {}
}
// Currency represents a cryptocurrency.
message Currency {
string symbol = 1; // e.g. 'BTC' see ListSupportedCurrencies API for a full list.
}
// Amount represents a fractional number precisely without
// as opposed to losing precision due to float representation.
message Amount {
// The integral part of the amount.
// For example, 3.50 will have `units`=3.
int64 units = 1;
// Number of nano (10^-9) units that represent the fractional amount.
// For example, 3.5 is represented as `units`=3 and `nanos`=500,000,000.
//
// `nanos` must be between -999,999,999 and +999,999,999 inclusive.
//
// If `units` is positive, `nanos` must be positive or zero.
// If `units` is zero, `nanos` can be positive, zero, or negative.
// If `units` is negative, `nanos` must be negative or zero.
// For example, -1.75 is represented as `units`=-1 and `nanos`=-750,000,000.
int32 nanos = 2;
}
message TickerWatchRequest {
Currency currency = 1;
}
// Quote represents a real-time coin price.
message Quote {
google.protobuf.Timestamp t = 10;
Amount price = 20;
}
service Account {
// Tests if your token works.
//
// Send a header (gRPC metadata) named "Authorization"
// with value "Bearer XXX" where XXX is a GitHub Personal Access token
// from https://github.com/settings/tokens (no permissions needed).
rpc TestAuth (TestAuthRequest) returns (TestAuthResponse) {}
}
message TestAuthRequest {}
message TestAuthResponse {
string user_id = 10;
}
message PortfolioRequest {}
message PortfolioResponse {
// User's cash holdings in USD.
Amount cash_usd = 1;
// User's cryptocurrency positions.
repeated PortfolioPosition positions = 2;
}
message PortfolioPosition {
Currency currency = 1;
Amount amount = 2;
}
enum TradeAction {
UNDEFINED = 0;
BUY = 1; // Buy a cryptocurrency using cash holdings.
SELL = 2; // Sell a cryptocurrency for cash holdings.
}
message TradeRequest {
TradeAction action = 1;
Currency currency = 2;
Amount quantity = 3;
}
message TradeResponse {
google.protobuf.Timestamp t = 1;
TradeAction action = 2;
Currency currency = 5;
Amount quantity = 3;
Amount executed_price = 4;
message Portfolio {
Amount remaining_cash = 1; // Cash left after trade in USD available to trade
repeated PortfolioPosition positions = 2; // Updated list of positions
}
Portfolio resulting_portfolio = 6;
}
message ListSupportedCurrenciesRequest {}
message ListSupportedCurrenciesResponse {
repeated Currency supported_currencies = 1;
}