mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-05 07:26:47 +00:00
gctrpc: endpoints now optionally return timestamps in nanoseconds (configurable) (#718)
* config: add remoteControl/gRPC/timeInNanoSeconds * grpc: consult with remoteControl/gRPC/timeInNanoSeconds whether timestamps should be in seconds or nanos * engine: test if RPCServer.unixTimestamp() respects config/remoteControl/gRPC/timeInNanoSeconds * engine: implement TestRPCServer_GetTicker_LastUpdatedNanos that makes sure TickerResponse.LastUpdated is returned in nanoseconds if configured * config_example.json: add remoteControl/gRPC/timeInNanoSeconds * engine: (1) test RPCServer.unixTimestamp() in parallel, (2) increase time tolerance of TestRPCServer_GetTicker_LastUpdatedNanos() * engine: TestRPCServer_GetTicker_LastUpdatedNanos() now fetches a mock-up ticker to check timestamps
This commit is contained in:
@@ -363,7 +363,7 @@ func (s *RPCServer) GetTicker(_ context.Context, r *gctrpc.GetTickerRequest) (*g
|
||||
|
||||
resp := &gctrpc.TickerResponse{
|
||||
Pair: r.Pair,
|
||||
LastUpdated: t.LastUpdated.Unix(),
|
||||
LastUpdated: s.unixTimestamp(t.LastUpdated),
|
||||
Last: t.Last,
|
||||
High: t.High,
|
||||
Low: t.Low,
|
||||
@@ -394,7 +394,7 @@ func (s *RPCServer) GetTickers(_ context.Context, _ *gctrpc.GetTickersRequest) (
|
||||
Base: val.Pair.Base.String(),
|
||||
Quote: val.Pair.Quote.String(),
|
||||
},
|
||||
LastUpdated: val.LastUpdated.Unix(),
|
||||
LastUpdated: s.unixTimestamp(val.LastUpdated),
|
||||
Last: val.Last,
|
||||
High: val.High,
|
||||
Low: val.Low,
|
||||
@@ -456,7 +456,7 @@ func (s *RPCServer) GetOrderbook(_ context.Context, r *gctrpc.GetOrderbookReques
|
||||
Pair: r.Pair,
|
||||
Bids: bids,
|
||||
Asks: asks,
|
||||
LastUpdated: ob.LastUpdated.Unix(),
|
||||
LastUpdated: s.unixTimestamp(ob.LastUpdated),
|
||||
AssetType: r.AssetType,
|
||||
}
|
||||
|
||||
@@ -500,7 +500,7 @@ func (s *RPCServer) GetOrderbooks(_ context.Context, _ *gctrpc.GetOrderbooksRequ
|
||||
Quote: currencies[z].Quote.String(),
|
||||
},
|
||||
AssetType: assets[y].String(),
|
||||
LastUpdated: resp.LastUpdated.Unix(),
|
||||
LastUpdated: s.unixTimestamp(resp.LastUpdated),
|
||||
}
|
||||
for i := range resp.Bids {
|
||||
ob.Bids = append(ob.Bids, &gctrpc.OrderbookItem{
|
||||
@@ -911,7 +911,7 @@ func (s *RPCServer) GetOrders(_ context.Context, r *gctrpc.GetOrdersRequest) (*g
|
||||
Total: resp[x].Trades[i].Total,
|
||||
}
|
||||
if !resp[x].Trades[i].Timestamp.IsZero() {
|
||||
t.CreationTime = resp[x].Trades[i].Timestamp.Unix()
|
||||
t.CreationTime = s.unixTimestamp(resp[x].Trades[i].Timestamp)
|
||||
}
|
||||
trades = append(trades, t)
|
||||
}
|
||||
@@ -933,10 +933,10 @@ func (s *RPCServer) GetOrders(_ context.Context, r *gctrpc.GetOrdersRequest) (*g
|
||||
Trades: trades,
|
||||
}
|
||||
if !resp[x].Date.IsZero() {
|
||||
o.CreationTime = resp[x].Date.Unix()
|
||||
o.CreationTime = s.unixTimestamp(resp[x].Date)
|
||||
}
|
||||
if !resp[x].LastUpdated.IsZero() {
|
||||
o.UpdateTime = resp[x].LastUpdated.Unix()
|
||||
o.UpdateTime = s.unixTimestamp(resp[x].LastUpdated)
|
||||
}
|
||||
orders = append(orders, o)
|
||||
}
|
||||
@@ -995,7 +995,7 @@ func (s *RPCServer) GetManagedOrders(_ context.Context, r *gctrpc.GetOrdersReque
|
||||
Total: resp[x].Trades[i].Total,
|
||||
}
|
||||
if !resp[x].Trades[i].Timestamp.IsZero() {
|
||||
t.CreationTime = resp[x].Trades[i].Timestamp.Unix()
|
||||
t.CreationTime = s.unixTimestamp(resp[x].Trades[i].Timestamp)
|
||||
}
|
||||
trades = append(trades, t)
|
||||
}
|
||||
@@ -1017,10 +1017,10 @@ func (s *RPCServer) GetManagedOrders(_ context.Context, r *gctrpc.GetOrdersReque
|
||||
Trades: trades,
|
||||
}
|
||||
if !resp[x].Date.IsZero() {
|
||||
o.CreationTime = resp[x].Date.Unix()
|
||||
o.CreationTime = s.unixTimestamp(resp[x].Date)
|
||||
}
|
||||
if !resp[x].LastUpdated.IsZero() {
|
||||
o.UpdateTime = resp[x].LastUpdated.Unix()
|
||||
o.UpdateTime = s.unixTimestamp(resp[x].LastUpdated)
|
||||
}
|
||||
orders = append(orders, o)
|
||||
}
|
||||
@@ -1062,7 +1062,7 @@ func (s *RPCServer) GetOrder(_ context.Context, r *gctrpc.GetOrderRequest) (*gct
|
||||
var trades []*gctrpc.TradeHistory
|
||||
for i := range result.Trades {
|
||||
trades = append(trades, &gctrpc.TradeHistory{
|
||||
CreationTime: result.Trades[i].Timestamp.Unix(),
|
||||
CreationTime: s.unixTimestamp(result.Trades[i].Timestamp),
|
||||
Id: result.Trades[i].TID,
|
||||
Price: result.Trades[i].Price,
|
||||
Amount: result.Trades[i].Amount,
|
||||
@@ -1075,11 +1075,11 @@ func (s *RPCServer) GetOrder(_ context.Context, r *gctrpc.GetOrderRequest) (*gct
|
||||
}
|
||||
|
||||
var creationTime, updateTime int64
|
||||
if result.Date.Unix() > 0 {
|
||||
creationTime = result.Date.Unix()
|
||||
if !result.Date.IsZero() {
|
||||
creationTime = s.unixTimestamp(result.Date)
|
||||
}
|
||||
if result.LastUpdated.Unix() > 0 {
|
||||
updateTime = result.LastUpdated.Unix()
|
||||
if !result.LastUpdated.IsZero() {
|
||||
updateTime = s.unixTimestamp(result.LastUpdated)
|
||||
}
|
||||
|
||||
return &gctrpc.OrderDetails{
|
||||
@@ -1924,7 +1924,7 @@ func (s *RPCServer) GetTickerStream(r *gctrpc.GetTickerStreamRequest, stream gct
|
||||
Base: t.Pair.Base.String(),
|
||||
Quote: t.Pair.Quote.String(),
|
||||
Delimiter: t.Pair.Delimiter},
|
||||
LastUpdated: t.LastUpdated.Unix(),
|
||||
LastUpdated: s.unixTimestamp(t.LastUpdated),
|
||||
Last: t.Last,
|
||||
High: t.High,
|
||||
Low: t.Low,
|
||||
@@ -1969,7 +1969,7 @@ func (s *RPCServer) GetExchangeTickerStream(r *gctrpc.GetExchangeTickerStreamReq
|
||||
Base: t.Pair.Base.String(),
|
||||
Quote: t.Pair.Quote.String(),
|
||||
Delimiter: t.Pair.Delimiter},
|
||||
LastUpdated: t.LastUpdated.Unix(),
|
||||
LastUpdated: s.unixTimestamp(t.LastUpdated),
|
||||
Last: t.Last,
|
||||
High: t.High,
|
||||
Low: t.Low,
|
||||
@@ -3656,3 +3656,12 @@ func (s *RPCServer) GetDataHistoryJobSummary(_ context.Context, r *gctrpc.GetDat
|
||||
ResultSummaries: job.ResultRanges,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// unixTimestamp returns given time in either unix seconds or unix nanoseconds, depending
|
||||
// on the remoteControl/gRPC/timeInNanoSeconds boolean configuration.
|
||||
func (s *RPCServer) unixTimestamp(x time.Time) int64 {
|
||||
if s.Config.RemoteControl.GRPC.TimeInNanoSeconds {
|
||||
return x.UnixNano()
|
||||
}
|
||||
return x.Unix()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user