https://github.com/modfin/mf-json-rpc
websocket implementation of json-rpc as used at modular finance
https://github.com/modfin/mf-json-rpc
Last synced: 10 months ago
JSON representation
websocket implementation of json-rpc as used at modular finance
- Host: GitHub
- URL: https://github.com/modfin/mf-json-rpc
- Owner: modfin
- Created: 2020-09-15T08:00:16.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-05T12:26:50.000Z (over 3 years ago)
- Last Synced: 2025-08-14T02:27:59.016Z (11 months ago)
- Language: TypeScript
- Size: 393 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# MF JSON RPC
### Install
```
npm i @modfin/mf-json-rpc
```
### Call (standard request/response)
```javascript
import { Rpc } from '@modfin/mf-json-rpc'
const client = new Rpc({ uri: 'ws://localhost:7357' })
// (don't need to wait for any connection to be established, it's handled internally)
const res = await client.call('method', { optional: 'params' })
```
### Stream
TODO: maybe expose a generator or some fancy cycle.js stream, but is a simple callback for now
```javascript
import { Rpc } from '@modfin/mf-json-rpc'
const client = new Rpc({ uri: 'ws://localhost:7357' })
let updates = []
client.stream('method_with_stream_support', { optional: 'params' }, update => {
updates = [...updates, update]
})
```
### Options
```javascript
const client = new Rpc({ uri: 'ws://localhost:7357' })
const res = await client.call(
'method',
{ optional: 'params' },
{ headers: { Authorization: authToken } }
)
client.stream(
'method_with_stream_support',
{ optional: 'params' },
update => { updates = [...updates, update] },
{ headers: { Authorization: authToken } }
)
```
### Typescript support
Some methods have a template parameter to indicate the expected shape of e.g. a result:
```Typescript
interface ComplexType { s: string, n: number, nested: { a: (number | string)[] } }
const complexResponse: MFJsonRpcResponse = await client.call('complex-method')
const complexResult: ComplexType = complexResponse.result
```