update stock example

This commit is contained in:
Asim Aslam
2021-06-29 13:27:47 +01:00
parent 3e3d2810f8
commit f1b118c38c
4 changed files with 45 additions and 31 deletions

View File

@@ -47,28 +47,35 @@
"description": "Returns historic order book for a given date", "description": "Returns historic order book for a given date",
"request": { "request": {
"stock": "AAPL", "stock": "AAPL",
"date": "2020-10-01" "date": "2020-10-01",
"start": "2020-10-01T10:00:00Z",
"end": "2020-10-01T11:00:00Z",
"limit": 3
}, },
"response": { "response": {
"symbol": "AAPL", "symbol": "AAPL",
"date": "2020-10-01", "date": "2020-10-01",
"orders": [ "orders": [
{ {
"bid_price": 101, "ask_price": 117.49,
"bid_size": 112, "bid_price": 117.3,
"timestamp": "2020-10-01T08:00:00.037685138Z"
},
{
"bid_price": 116.52,
"bid_size": 1,
"timestamp": "2020-10-01T08:00:00.053150454Z"
},
{
"ask_price": 116.92,
"bid_price": 116.7,
"ask_size": 1, "ask_size": 1,
"bid_size": 3, "bid_size": 1,
"timestamp": "2020-10-01T08:00:17.417598642Z" "timestamp": "2020-10-01T10:00:02.672770187Z"
},
{
"ask_price": 117.47,
"bid_price": 117.35,
"ask_size": 2,
"bid_size": 1,
"timestamp": "2020-10-01T10:00:33.258111144Z"
},
{
"ask_price": 117.47,
"bid_price": 117.3,
"ask_size": 2,
"bid_size": 2,
"timestamp": "2020-10-01T10:00:33.386282508Z"
} }
] ]
} }

View File

@@ -71,13 +71,20 @@ func (s *Stock) OrderBook(ctx context.Context, req *pb.OrderBookRequest, rsp *pb
uri := fmt.Sprintf("%shistory/stock/all?apikey=%s&stock=%s&date=%s&limit=%d", s.Api, s.Key, req.Stock, req.Date, req.Limit) uri := fmt.Sprintf("%shistory/stock/all?apikey=%s&stock=%s&date=%s&limit=%d", s.Api, s.Key, req.Stock, req.Date, req.Limit)
if req.Start > 0 { if len(req.Start) > 0 {
uri = fmt.Sprintf("%s&ts=%d", uri, req.Start) t, err := time.Parse(time.RFC3339Nano, req.Start)
if err != nil {
return errors.BadRequest("stock.orderbook", "invalid start datetime")
} }
if req.End > 0 { uri = fmt.Sprintf("%s&ts=%d", uri, t.UTC().UnixNano())
uri = fmt.Sprintf("%s&te=%d", uri, req.End) }
if len(req.End) > 0 {
t, err := time.Parse(time.RFC3339Nano, req.End)
if err != nil {
return errors.BadRequest("stock.orderbook", "invalid end datetime")
}
uri = fmt.Sprintf("%s&te=%d", uri, t.UTC().UnixNano())
} }
resp, err := http.Get(uri) resp, err := http.Get(uri)
if err != nil { if err != nil {
logger.Errorf("Failed to get orderbook: %v\n", err) logger.Errorf("Failed to get orderbook: %v\n", err)

View File

@@ -114,10 +114,10 @@ type OrderBookRequest struct {
Stock string `protobuf:"bytes,1,opt,name=stock,proto3" json:"stock,omitempty"` Stock string `protobuf:"bytes,1,opt,name=stock,proto3" json:"stock,omitempty"`
// the date in format YYYY-MM-dd // the date in format YYYY-MM-dd
Date string `protobuf:"bytes,2,opt,name=date,proto3" json:"date,omitempty"` Date string `protobuf:"bytes,2,opt,name=date,proto3" json:"date,omitempty"`
// optional nanosecond timestamp start // optional RFC3339Nano start time e.g 2006-01-02T15:04:05.999999999Z07:00
Start int64 `protobuf:"varint,3,opt,name=start,proto3" json:"start,omitempty"` Start string `protobuf:"bytes,3,opt,name=start,proto3" json:"start,omitempty"`
// optional nanosecond timestamp end // optional RFC3339Nano end time e.g 2006-01-02T15:04:05.999999999Z07:00
End int64 `protobuf:"varint,4,opt,name=end,proto3" json:"end,omitempty"` End string `protobuf:"bytes,4,opt,name=end,proto3" json:"end,omitempty"`
// limit number of prices // limit number of prices
Limit int32 `protobuf:"varint,5,opt,name=limit,proto3" json:"limit,omitempty"` Limit int32 `protobuf:"varint,5,opt,name=limit,proto3" json:"limit,omitempty"`
} }
@@ -168,18 +168,18 @@ func (x *OrderBookRequest) GetDate() string {
return "" return ""
} }
func (x *OrderBookRequest) GetStart() int64 { func (x *OrderBookRequest) GetStart() string {
if x != nil { if x != nil {
return x.Start return x.Start
} }
return 0 return ""
} }
func (x *OrderBookRequest) GetEnd() int64 { func (x *OrderBookRequest) GetEnd() string {
if x != nil { if x != nil {
return x.End return x.End
} }
return 0 return ""
} }
func (x *OrderBookRequest) GetLimit() int32 { func (x *OrderBookRequest) GetLimit() int32 {
@@ -681,9 +681,9 @@ var file_proto_stock_proto_rawDesc = []byte{
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x18, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x12, 0x12, 0x0a, 0x04,
0x64, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x65, 0x64, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x65,
0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x6e, 0x64, 0x18, 0x04, 0x20, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x6e, 0x64, 0x18, 0x04, 0x20,
0x01, 0x28, 0x03, 0x52, 0x03, 0x65, 0x6e, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x01, 0x28, 0x09, 0x52, 0x03, 0x65, 0x6e, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69,
0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0x65, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0x65,
0x0a, 0x11, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x6f, 0x6f, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x0a, 0x11, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x6f, 0x6f, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x18, 0x01, 0x20, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x18, 0x01, 0x20,

View File

@@ -30,10 +30,10 @@ message OrderBookRequest {
string stock = 1; string stock = 1;
// the date in format YYYY-MM-dd // the date in format YYYY-MM-dd
string date = 2; string date = 2;
// optional nanosecond timestamp start // optional RFC3339Nano start time e.g 2006-01-02T15:04:05.999999999Z07:00
int64 start = 3; string start = 3;
// optional nanosecond timestamp end // optional RFC3339Nano end time e.g 2006-01-02T15:04:05.999999999Z07:00
int64 end = 4; string end = 4;
// limit number of prices // limit number of prices
int32 limit = 5; int32 limit = 5;
} }