LUSID has a bi-directional translation engine that can be used as part of a workflow to:
Translate LUSID's data model to an external data model in preparation for exporting data from LUSID.
Translate an external data model to LUSID's data model in preparation for importing data into LUSID.
The process is as follows:
Upload a translation script to LUSID. This is a Javascript document that translates to and/or from LUSID's data model, depending on the operation you want to perform.
Optionally, create and upload a translation dialect (schema) to validate the output. If you omit the dialect, the translation operation succeeds but the output is unvalidated.
Perform the translation, passing in the data to translate and supplying the translation script to use and, optionally, a dialect.
Example: Translating FxForward instruments from LUSID to a 3rd party and back again
A FxForward in LUSID's data model | The same FxForward in an example data model |
Uploading a translation script
Every translation script must contain the following code. Note the scriptInterfaceVersion
should be set to 1
at the time of writing, though this number may increment as more functionality is introduced:
The <your-translation-code-here>
block must contain all the code necessary to translate key/value pairs in the input data model to key/value pairs in the output data model.
In our example, since we're translating both to and from LUSID, we'll use a switch statement to differentiate between translation directions. (You could use the same switch statement to distinguish between asset classes in a uni-directional translation script.)
To translate from LUSID to the example data model, a TranslateFxForwardLUSIDToExample
function might look like this:
To translate from the example data model to LUSID, a TranslateFxForwardExampleToLUSID
function might look like this:
To load a translation script into LUSID we call the UpsertTranslationScript API, specifying in the body of the request:
An
id
that uniquely identifies the script in LUSID, consisting of ascope
,code
and semanticversion
.A
body
that comprises the script as a string. Note double quote characters must be escaped using\
.
For example, to upload our bi-directional translation script for FxForwards:
Performing a translation
To translate data item(s) we call the TranslateEntities API, specifying in the body of the request:
A
scriptId
that identifies the translation script to use.An
entityPayloads
object containing one or more data items to translate. Each must be keyed by an ephemeral ID to track errors in the response. Double quote characters must be escaped using\
.
For example, to translate our example FxForward from LUSID to the example data model, we supply the instrument in LUSID's data model as a string:
If the translation is successful, the values
object in the response contains the FxForward serialised to the example data model (unsuccessful translations are reported in the failed
object):
To translate from the example data model back to LUSID, we supply the FxForward in the example data model as a string:
The values
object should now contain the FxForward serialised to the LUSID data model again: