Parameters#

It is possible to use gateways to manage strategy parameters.

The benefit, of placing this logic with the gateways, is that all parameter changes can be captured in the event-logs.

Strategies will receive an initial snapshot of all parameters upon connecting to a gateway. Any further updates will be communicated to the strategies as incremental updates.

Implementation#

The gateways use a dedicated thread to manage external requests. This includes an initial handshake with clients as well as the general query interfaces for metrics, parameters, etc.

Any updates to parameters will be validated and processed by this thread before an internal queue will be used to hand over the final update to the low latency thread.

A SQLite database is used to persist parameters between sessions. This database can be found in the cache directory and the table name is parameters.

Note

Other databases can potentially be supported as well. The benefit of using SQLite is that it doesn’t require the user to maintain a database instance.

Interface#

Note

The REST interface will default to JSON when the Accept or Content-Type HTTP headers are missing.

GET /api/parameters

Fetch all users.

$ curl http://localhost/api/parameters \
      --verbose \
      --write-out '\n' \
      --unix-socket ~/run/metrics/deribit.sock

*   Trying /home/thraneh/run/metrics/deribit.sock:0...
* Connected to localhost (/home/thraneh/run/metrics/deribit.sock) port 80 (#0)
> GET /api/parameters HTTP/1.1
> Host: localhost
> User-Agent: curl/7.81.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: roq-deribit/0.9.4
< Access-Control-Allow-Origin: *
< Cache-Control: no-store
< Date: Sun, 14 May 2023 03:05:52 GMT
< Content-Type: application/json
< Content-Length: 10
<
* Connection #0 to host localhost left intact
["trader"]
GET /api/parameters?user=<user>

Fetch all parameters for a user.

$ curl http://localhost/api/parameters?user=trader \
      --verbose \
      --write-out '\n' \
      --unix-socket ~/run/metrics/deribit.sock

*   Trying /home/thraneh/run/metrics/deribit.sock:0...
* Connected to localhost (/home/thraneh/run/metrics/deribit.sock) port 80 (#0)
> GET /api/parameters?user=trader HTTP/1.1
> Host: localhost
> User-Agent: curl/7.81.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: roq-deribit/0.9.4
< Access-Control-Allow-Origin: *
< Cache-Control: no-store
< Date: Sun, 14 May 2023 03:05:14 GMT
< Content-Type: application/json
< Content-Length: 13
<
* Connection #0 to host localhost left intact
["bar","foo"]
$ curl http://localhost/api/parameters?user=unknown \
      --verbose \
      --write-out '\n' \
      --unix-socket ~/run/metrics/deribit.sock

*   Trying /home/thraneh/run/metrics/deribit.sock:0...
* Connected to localhost (/home/thraneh/run/metrics/deribit.sock) port 80 (#0)
> GET /api/parameters?user=unknown HTTP/1.1
> Host: localhost
> User-Agent: curl/7.81.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 NOT_FOUND
< Server: roq-deribit/0.9.4
< Access-Control-Allow-Origin: *
< Connection: close
< Date: Sun, 14 May 2023 03:04:18 GMT
< Content-Length: 0
<
* Closing connection 0
PUT /api/parameters?user=<user>

Update parameters for user.

Note

You may send any number of parameter updates as object (single) or array of objects (multiple).

The object(s) must contain the following primary key

  • label

The object(s) may contain either of these optional secondary keys

  • account

  • exchange

  • symbol

$ curl http://localhost/api/parameters?user=trader \
      --verbose \
      --write-out '\n' \
      --unix-socket ~/run/metrics/deribit.sock \
      --request PUT \
      --header 'Content-Type: application/json' \
      --data '{"label":"foo","value":"123"}'

*   Trying /home/thraneh/run/metrics/deribit.sock:0...
* Connected to localhost (/home/thraneh/run/metrics/deribit.sock) port 80 (#0)
> PUT /api/parameters?user=trader HTTP/1.1
> Host: localhost
> User-Agent: curl/7.81.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 29
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: roq-deribit/0.9.4
< Access-Control-Allow-Origin: *
< Date: Sun, 14 May 2023 03:31:39 GMT
< Content-Length: 0
<
* Connection #0 to host localhost left intact
$ curl http://localhost/api/parameters?user=trader \
      --verbose \
      --write-out '\n' \
      --unix-socket ~/run/metrics/deribit.sock \
      --request PUT \
      --header 'Content-Type: application/json' \
      --data '[{"label":"foo","account":"A1","value":"123"},{"label":"bar","exchange":"deribit","symbol":"BTC-PERPETUAL","value":"abc"}]'

*   Trying /home/thraneh/run/metrics/deribit.sock:0...
* Connected to localhost (/home/thraneh/run/metrics/deribit.sock) port 80 (#0)
> PUT /api/parameters?user=trader HTTP/1.1
> Host: localhost
> User-Agent: curl/7.81.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 122
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: roq-deribit/0.9.4
< Access-Control-Allow-Origin: *
< Date: Sun, 14 May 2023 03:32:19 GMT
< Content-Length: 0
<
* Connection #0 to host localhost left intact
GET /api/parameters/<label>?user=<user>

Fetch parameter for user and label.

$ curl http://localhost/api/parameters/foo?user=trader \
      --verbose \
      --write-out '\n' \
      --unix-socket ~/run/metrics/deribit.sock

*   Trying /home/thraneh/run/metrics/deribit.sock:0...
* Connected to localhost (/home/thraneh/run/metrics/deribit.sock) port 80 (#0)
> GET /api/parameters/foo?user=trader HTTP/1.1
> Host: localhost
> User-Agent: curl/7.81.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: roq-deribit/0.9.4
< Access-Control-Allow-Origin: *
< Cache-Control: no-store
< Date: Sun, 14 May 2023 03:09:47 GMT
< Content-Type: application/json
< Content-Length: 572
<
* Connection #0 to host localhost left intact
[{"label":"foo","account":"A1","exchange":"deribit","symbol":"BTC","value":"1234567890"},{"label":"foo","account":null,"exchange":"deribit","symbol":"BTC-PERPETUAL","value":"abc"},{"label":"foo","account":"A1","exchange":null,"symbol":null,"value":"123"},{"label":"foo","account":null,"exchange":null,"symbol":null,"value":"234"},{"label":"foo","account":"a2","exchange":null,"symbol":null,"value":"abcdef"},{"label":"foo","account":null,"exchange":"deribit","symbol":"1","value":"abcdef"},{"label":"foo","account":null,"exchange":"deribit","symbol":"2","value":"defghi"}]
$ curl http://localhost/api/parameters/unknown?user=trader \
      --verbose \
      --write-out '\n' \
      --unix-socket ~/run/metrics/deribit.sock

*   Trying /home/thraneh/run/metrics/deribit.sock:0...
* Connected to localhost (/home/thraneh/run/metrics/deribit.sock) port 80 (#0)
> GET /api/parameters/unknown?user=trader HTTP/1.1
> Host: localhost
> User-Agent: curl/7.81.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 NOT_FOUND
< Server: roq-deribit/0.9.4
< Access-Control-Allow-Origin: *
< Connection: close
< Date: Sun, 14 May 2023 03:10:18 GMT
< Content-Length: 0
<
* Closing connection 0
PUT /api/parameters/<label>?user=<user>

Update parameter for user and label.

Note

You may send any number of parameter updates as object (single) or array of objects (multiple).

The object(s) may contain either of these optional secondary keys

  • account

  • exchange

  • symbol

$ curl http://localhost/api/parameters/foo?user=trader \
      --verbose \
      --write-out '\n' \
      --unix-socket ~/run/metrics/deribit.sock \
      --request PUT \
      --header 'Content-Type: application/json' \
      --data '{"value":"123"}'

*   Trying /home/thraneh/run/metrics/deribit.sock:0...
* Connected to localhost (/home/thraneh/run/metrics/deribit.sock) port 80 (#0)
> PUT /api/parameters/foo?user=trader HTTP/1.1
> Host: localhost
> User-Agent: curl/7.81.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 15
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: roq-deribit/0.9.4
< Access-Control-Allow-Origin: *
< Date: Sun, 14 May 2023 03:32:53 GMT
< Content-Length: 0
<
* Connection #0 to host localhost left intact
$ curl http://localhost/api/parameters/foo?user=trader \
      --verbose \
      --write-out '\n' \
      --unix-socket ~/run/metrics/deribit.sock \
      --request PUT \
      --header 'Content-Type: application/json' \
      --data '[{"account":"A1","value":"123"},{"exchange":"deribit","symbol":"BTC-PERPETUAL","value":"abc"}]'

*   Trying /home/thraneh/run/metrics/deribit.sock:0...
* Connected to localhost (/home/thraneh/run/metrics/deribit.sock) port 80 (#0)
> PUT /api/parameters/foo?user=trader HTTP/1.1
> Host: localhost
> User-Agent: curl/7.81.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 94
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: roq-deribit/0.9.4
< Access-Control-Allow-Origin: *
< Date: Sun, 14 May 2023 03:33:31 GMT
< Content-Length: 0
<
* Connection #0 to host localhost left intact