-
Notifications
You must be signed in to change notification settings - Fork 3
Transformers
Justin Tirrell edited this page Sep 12, 2019
·
1 revision
There are two functions in the iboga.core
namespace that allow you to register a function to be used as a transformer to and from the value IB receives/requires in their Java api: def-to-ib
and def-from-ib
. Each takes a fully qualified symbol representing a spec key, and a function of a single value which transforms that value (either to the value type IB expects, or from the IB value to a more clojury type.).
Transformers can be defined for any "leaf" field in a request or received message (for example :iboga.recv.historical-data/bar
or iboga.contract-details/liquid-hours
).
Examples
;;Use
(ib/def-from-ib :iboga.bar/time
(fn [v]
(-> (if (= (count v) 8) ;;breaks in year 10000
(-> v (LocalDate/parse impl/ib-datetime-formatter) .atStartOfDay)
(-> v (LocalDateTime/parse impl/ib-datetime-formatter)))
(ZonedDateTime/of (ZoneId/systemDefault)
.toInstant)))
(ib/def-from-ib :iboga.contract-details/market-rule-ids
(fn [v] (.split v ",")))
(ib/def-from-ib :iboga.contract-details/time-zone-id
(fn [x] (ZoneId/of x)))