vegabook

vegabook

I’m using elixir-grpc to write a client for my Bloomberg API gRPC implementation. This is working quite well in Python, and I now want to bring the Bloomberg API to Elixir. Naturally timestamps are going to be necessary, but I don’t know how to use them in Elixir.

Elixir-grpc says it uses the protobuf library which in turn says that “since :protobuf version 0.14.0 we include all of the well known Google Protobuf modules” (which is strange since their latest release is 0.13.0).

Anyway I’m getting errors with Google.Protobuf.Timestamp. Here is my proto file that uses timestamps, and this successfully compiles to elixir code using protoc --elixir_out=plugins=grpc:../lib *.proto. You can see the output here, but when I try to do a simple ping/pong to the server, there’s a massive error which mentions that Google.Protobuf.Timestamp is not available:

So in Python I would bring Google.Protobuf.Timestamp (and Struct and Empty) in like this:

from google.protobuf.struct_pb2 import Struct
from google.protobuf.timestamp_pb2 import Timestamp as protoTimestamp
from google.protobuf import empty_pb2

and then I could use them, but I don’t know how to do this in Elixir. Should I be generating my own code from the canonical Google.Protobuf.Timestamp proto files? This seems strange as I would think either elixir-grpc or protobuf would have done that already.

Showing Posts 1 to 3

vegabook

vegabook OP

fabulous!

I’ll let grpc-elixir maintainers that this should be in their docs.

Goodbye python, java, c++, behold Bloomberg API data, now in Elixir:

vegabook

vegabook OP

So this seems to have changed: GitHub - elixir-protobuf/google-protos: Elixir files generated from Google's protobuf files using protobuf-elixir · GitHub and the author of google-protos is recommending just using the main protobuf library instead, which I am doing.

But this doesn’t seem to be recognising my timestamps. Here is my IntradayBarRequest protobuf definition:

message IntradayBarRequest {
string topic = 2; // securities
google.protobuf.Timestamp start = 3; // startDate
google.protobuf.Timestamp end = 4; // endDate
int32 interval = 5; // interval in minutes
map <string, string> options = 6;
}

But when I try to create timestamps, they’re not accepted:

iex(25)> tpc
%Bloomberg.IntradayBarRequest{
topic: “USDZAR Curncy”,
start: ~U[2025-09-01 13:00:00Z],
end: ~U[2025-10-30 18:12:22.878335Z],
interval: 1,
options: %{},
unknown_fields:
}
iex(26)> Bloomberg.Bbg.Stub.intraday_bar_request(chan, tpc)
** (Protobuf.EncodeError) Got error when encoding Bloomberg.IntradayBarRequest#start: ** (Protobuf.EncodeError) struct DateTime can’t be encoded as Google.Protobuf.Timestamp: ~U[2025-09-01 13:00:00Z]
(grpc 0.11.3) lib/grpc/telemetry.ex:125: anonymous fn/2 in GRPC.Telemetry.client_span/3
(telemetry 1.3.0) /home/tbrowne/code/suprabonds/deps/telemetry/src/telemetry.erl:324: :telemetry.span/3
(grpc 0.11.3) lib/grpc/telemetry.ex:118: GRPC.Telemetry.client_span/3
iex:26: (file)
[error] ** (Protobuf.EncodeError) Got error when encoding Bloomberg.IntradayBarRequest#start: ** (Protobuf.EncodeError) struct DateTime can’t be encoded as Google.Protobuf.Timestamp: ~U[2025-09-01 13:00:00Z]
(grpc 0.11.3) lib/grpc/telemetry.ex:125: anonymous fn/2 in GRPC.Telemetry.client_span/3
(telemetry 1.3.0) /home/tbrowne/code/suprabonds/deps/telemetry/src/telemetry.erl:324: :telemetry.span/3
(grpc 0.11.3) lib/grpc/telemetry.ex:118: GRPC.Telemetry.client_span/3
(elixir 1.19.1) elixir.erl:365: :elixir.eval_external_handler/3
(stdlib 7.1) erl_eval.erl:924: :erl_eval.do_apply/7
(elixir 1.19.1) elixir.erl:343: :elixir.eval_forms/4
(elixir 1.19.1) lib/module/parallel_checker.ex:152: Module.ParallelChecker.verify/1
(iex 1.19.1) lib/iex/evaluator.ex:349: IEx.Evaluator.eval_and_inspect/3
(iex 1.19.1) lib/iex/evaluator.ex:321: IEx.Evaluator.safe_eval_and_inspect/3
(iex 1.19.1) lib/iex/evaluator.ex:212: IEx.Evaluator.loop/1
(iex 1.19.1) lib/iex/evaluator.ex:38: IEx.Evaluator.init/5
(stdlib 7.1) proc_lib.erl:333: :proc_lib.init_p_do_apply/3

Different error if I try to convert those timestamps to_unix:

iex(26)> tpc = %Bloomberg.IntradayBarRequest{topic: “USDZAR Curncy”, interval: 1, start: DateTime.new!(~D[2025-09-01], ~T[13:00:00], “Etc/UTC”) |> DateTime.to_unix, end: DateTime.utc_now() |> DateTime.to_unix()}
%Bloomberg.IntradayBarRequest{
topic: “USDZAR Curncy”,
start: 1756731600,
end: 1761848742,
interval: 1,
options: %{},
unknown_fields:
}
iex(27)> Bloomberg.Bbg.Stub.intraday_bar_request(chan, tpc)
** (Protobuf.EncodeError) Got error when encoding Bloomberg.IntradayBarRequest#start: ** (Protocol.UndefinedError) protocol Enumerable not implemented for Integer. This protocol is implemented for: DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, Explorer.Series.Iterator, File.Stream, Flow, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Jason.OrderedObject, List, Map, MapSet, Phoenix.LiveView.LiveStream, Postgrex.Stream, Range, SFTPClient.Stream, Stream, Table.Mapper, Table.Zipper

Any info on how to get Elixir dates/times into Google protobuf timestamps>

EDIT: figured it out:

iex(27)> %Google.Protobuf.Timestamp{seconds: 1, nanos: 1}
%Google.Protobuf.Timestamp{seconds: 1, nanos: 1, unknown_fields: }

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews