Skip to content

Commit

Permalink
Merge pull request #307 from KomodoPlatform/event-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
gcharang authored Sep 13, 2024
2 parents 5265dd8 + a531e14 commit 8a2d1ce
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 18 deletions.
1 change: 1 addition & 0 deletions filepathSlugs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,7 @@
"example-without-balances",
"balance-infos",
"derivation-method",
"event-stream-config",
"numeric-formats-value",
"fee-info",
"examples",
Expand Down
40 changes: 40 additions & 0 deletions src/pages/komodo-defi-framework/api/common_structures/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,46 @@ Where the value indicates:
```
</CollapsibleSection>

### EventStreamConfig

The `EventStreamConfig` object defines which events will be streamed to the client:

| Parameter | Type | Description |
| ------------------------------ | ------ | -------------------------------------------------------------------------------------- |
| access\_control\_allow\_origin | string | Defines CORS whitelist. Use "\*" to allow fromi any origin. |
| active\_events | object | Events to be streamed to the client, along with configuration defineing frequency etc. |
| worker\_path | string | WASM only. Path to a custom `worker.js` file. |

Active events are defined as follows:

* NETWORK: Network status changes. Requires `stream_interval_seconds` configuration.
* HEARTBEAT: Allows clients to easily determine whether channels are functioning. Requires `stream_interval_seconds` configuration.
* COIN\_BALANCE: Balance changes. Does not require `stream_interval_seconds` configuration, as the event is triggered by the balance change.

<Note>
The `COIN_BALANCE` event may not be available for all coins or tokens.
</Note>

An example of the event stream output can then be viewed in [https://github.com/KomodoPlatform/komodo-defi-framework/blob/main/examples/sse/index.html](https://github.com/KomodoPlatform/komodo-defi-framework/blob/main/examples/sse/index.html)

<CollapsibleSection expandedText="Hide Example" collapsedText="Show Example">
```json
"event_stream_configuration": {
"access_control_allow_origin": "*",
"active_events": {
"NETWORK": {
"stream_interval_seconds": 1.5,
},
"COIN_BALANCE": {},
"HEATBEAT": {
"stream_interval_seconds": 2.4,
}
},
"worker_path": "index.js"
}
```
</CollapsibleSection>

### NumericFormatsValue

The `NumericFormatsValue` returns a price or amount in three different formats: `fraction`, `rational`, and `decimal`.
Expand Down
37 changes: 19 additions & 18 deletions src/pages/komodo-defi-framework/setup/configure-mm2-json/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,25 @@ When running the Komodo DeFi API via commandline with the `mm2` binary, some bas

### Configuration Parameters

| Parameter | Type | Description |
| ----------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| gui | string | Information to identify which app, tool or product is using the API, e.g. `KomodoWallet iOS 1.0.1`. Helps developers identify if an issue is related to specific builds or operating systems etc. |
| netid | integer | Nework ID number, telling the Komodo DeFi Framework which network to join. 8762 is the current main network, though alternative netids can be used for testing or "private" trades as long as seed nodes exist to support it. |
| passphrase | string | Your passphrase; this is the source of each of your coins private keys. [**KEEP IT SAFE!**](https://www.youtube.com/watch?v=WFpxVbTqhB8) |
| rpc\_password | string | For RPC requests that need authentication, this will need to match the `userpass` value in the request body. |
| allow\_weak\_password | boolean | Optional, defaults to `false`. If `true`, will allow low entropy rpc\_password. If `false` rpc\_password must not have 3 of the same characters in a row, must be between 8-32 characters in length, must contain at least one of each of the following: numeric, uppercase, lowercase, special character (e.g. !#$\*). It also can not contain the word "password", or the chars `<`, `>`, or `&`. |
| dbdir | string | Optional, defaults to a subfolder named `DB` in the path of your `mm2` binary. This path will store the Komodo DeFi-API database data. |
| rpcip | string | Optional, defaults to `127.0.0.1`. IP address to bind to for RPC server. |
| rpcport | integer | Optional, defaults to `7783`. Port to use for RPC communication. |
| rpc\_local\_only | boolean | Optional, defaults to `true`. If `false` the Komodo DeFi Framework API will allow rpc methods sent from external IP addresses. **Warning:** Only use this if you know what you are doing, and have put the appropriate security measures in place. |
| i\_am\_seed | boolean | Optional, defaults to `false`. Runs Komodo DeFi Framework API as a seed node mode (acting as a relay for Komodo DeFi Framework API clients). Use of this mode is not reccomended on the main network (8762) as it could result in a pubkey ban if non-compliant. On alternative testing or private networks, at least one seed node is required to relay information to other Komodo DeFi Framework API clients using the same netID. |
| seednodes | list of strings | Optional. If operating on a test or private netID, the IP address of at least one seed node is required (on the main network, these are already hardcoded) |
| enable\_hd | boolean | Optional. If `true`, the Komodo DeFi-API will work in only the [HD mode](/komodo-defi-framework/api/v20-dev/hd_wallets_overview/), and coins will need to have a coin derivation path entry in the `coins` file for activation. Defaults to `false`. |
| message\_service\_cfg | object | Optional. This data is used to configure [Telegram](https://telegram.org/) messenger alerts for swap events when running using the [makerbot functionality](/komodo-defi-framework/api/v20/start_simple_market_maker_bot/). For more information check out the [telegram alerts guide](/komodo-defi-framework/api/v20/telegram_alerts/) |
| metrics | integer | Optional, defaults to `300`. The interval in seconds which metrics are logged. Set to `0` to disable metrics. |
| prometheusport | integer | Optional. Only used if you are logging metrics in [Prometheus](https://prometheus.io/) and [Grafana](https://grafana.com/). For more information check out the [Komodo DeFi metrics guide](/komodo-defi-framework/tutorials/api-metrics/) |
| prometheus\_credentials | integer | Optional. Only used if you are logging metrics in [Prometheus](https://prometheus.io/) and [Grafana](https://grafana.com/) with authentication. For more information check out the [Komodo DeFi metrics guide](/komodo-defi-framework/tutorials/api-metrics/) |
| Parameter | Type | Description |
| ---------------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| gui | string | Information to identify which app, tool or product is using the API, e.g. `KomodoWallet iOS 1.0.1`. Helps developers identify if an issue is related to specific builds or operating systems etc. |
| netid | integer | Nework ID number, telling the Komodo DeFi Framework which network to join. 8762 is the current main network, though alternative netids can be used for testing or "private" trades as long as seed nodes exist to support it. |
| passphrase | string | Your passphrase; this is the source of each of your coins private keys. [**KEEP IT SAFE!**](https://www.youtube.com/watch?v=WFpxVbTqhB8) |
| rpc\_password | string | For RPC requests that need authentication, this will need to match the `userpass` value in the request body. |
| allow\_weak\_password | boolean | Optional, defaults to `false`. If `true`, will allow low entropy rpc\_password. If `false` rpc\_password must not have 3 of the same characters in a row, must be between 8-32 characters in length, must contain at least one of each of the following: numeric, uppercase, lowercase, special character (e.g. !#$\*). It also can not contain the word "password", or the chars `<`, `>`, or `&`. |
| dbdir | string | Optional, defaults to a subfolder named `DB` in the path of your `mm2` binary. This path will store the Komodo DeFi-API database data. |
| rpcip | string | Optional, defaults to `127.0.0.1`. IP address to bind to for RPC server. |
| rpcport | integer | Optional, defaults to `7783`. Port to use for RPC communication. |
| rpc\_local\_only | boolean | Optional, defaults to `true`. If `false` the Komodo DeFi Framework API will allow rpc methods sent from external IP addresses. **Warning:** Only use this if you know what you are doing, and have put the appropriate security measures in place. |
| i\_am\_seed | boolean | Optional, defaults to `false`. Runs Komodo DeFi Framework API as a seed node mode (acting as a relay for Komodo DeFi Framework API clients). Use of this mode is not reccomended on the main network (8762) as it could result in a pubkey ban if non-compliant. On alternative testing or private networks, at least one seed node is required to relay information to other Komodo DeFi Framework API clients using the same netID. |
| seednodes | list of strings | Optional. If operating on a test or private netID, the IP address of at least one seed node is required (on the main network, these are already hardcoded) |
| enable\_hd | boolean | Optional. If `true`, the Komodo DeFi-API will work in only the [HD mode](/komodo-defi-framework/api/v20-dev/hd_wallets_overview/), and coins will need to have a coin derivation path entry in the `coins` file for activation. Defaults to `false`. |
| message\_service\_cfg | object | Optional. This data is used to configure [Telegram](https://telegram.org/) messenger alerts for swap events when running using the [makerbot functionality](/komodo-defi-framework/api/v20/start_simple_market_maker_bot/). For more information check out the [telegram alerts guide](/komodo-defi-framework/api/v20/telegram_alerts/) |
| metrics | integer | Optional, defaults to `300`. The interval in seconds which metrics are logged. Set to `0` to disable metrics. |
| prometheusport | integer | Optional. Only used if you are logging metrics in [Prometheus](https://prometheus.io/) and [Grafana](https://grafana.com/). For more information check out the [Komodo DeFi metrics guide](/komodo-defi-framework/tutorials/api-metrics/) |
| prometheus\_credentials | integer | Optional. Only used if you are logging metrics in [Prometheus](https://prometheus.io/) and [Grafana](https://grafana.com/) with authentication. For more information check out the [Komodo DeFi metrics guide](/komodo-defi-framework/tutorials/api-metrics/) |
| event\_stream\_configuration | object | Optional, a standard [EventStreamConfig](/komodo-defi-framework/api/v20/#derivation-method) object. Configuration for subscribing to events. |

#### Example (allowing weak password):

Expand Down

0 comments on commit 8a2d1ce

Please sign in to comment.