@rolla-finance/mm-api-client
v1.7.1
Published
Client library to interact with the Rolla ecosystem
Downloads
11
Readme
Rolla marker maker client
This package contains
- TypeScript client for the Rolla REST api
- WebSocket client for handling quote requests
The REST client is generated from the OpenAPI specification, is type-safe and easy to use.
Installation
npm install @rolla-finance/mm-api-client
Api client usage
Some of the calls that the client makes require jwt token authentication, generated using Sign-In with Ethereum. For that reason we require that you provide private key and chain id that we use to generate the authentication string, or provide a function that returns the authentication string. These credentials are used to generate the jwt token that is used for authentication. MM api client automatically refreshes the token when it expires.
The client uses Axios for http requests. You can pass in an existing Axios instance as well as other axios options in the second constructor argument.
Basic api client usage is as follows:
import { RollaApiClient } from '@rolla-finance/mm-api-client';
const client = new RollaApiClient({
privateKey: 'private_key',
chainId: 96,
});
// or construct with a function that returns the authentication string
const apiClient = new RollaApiClient(() =>
someFunctionToGetAuthenticationString()
);
const assetsResponse = await client.getAllAssets();
await client.getMarketMakerActiveQuotes({
optionAddress: '0x1',
underlyingAddress: '0x2',
});
// etc.
WebSocket client usage
Websocket is used for receiving quote requests and metatransactions. The client is a wrapper around the ws package. As a market maker receiving data, you need to authenticate with the server. The authentication is done using a similar mechanism as the REST api, using ethereum private key and chain id.
import {
MarketMakerQuoteRequestDto,
MarketMakerQuoteResponseDto,
RollaWS,
RollaApiClient
} from "@rolla-finance/mm-api-client";
export const apiClient = new RollaApiClient({
privateKey: 'private_key',
chainId: 96,
});
const rollaWs = await apiClient.initRollaWS({
// if set to true, this will generate additional logs
debugMode: true,
// how many times to retry connecting to the server until giving up
retryCount: Infinity,
// how long to wait between retries
retryInterval: 1000,
});
// subscribe to quote requests, this will call the provided function when one or more quote requests are received
rollaWs.subscribeToQuoteRequests(listenAndRespondToQuotes);
// subscribe to meta transactions, this will call the provided function when one or more meta transactions are received
rollaWs.subscribeToMetaTxs(listenAndRespondToMetaTransactions);
const listenAndRespondToQuotes = async (requests: MarketMakerQuoteRequestDto[]) {
const responses = await yourLogicForGeneratingQuotes(requests);
if (responses.length) {
await apiClient.postQuoteResponses({
marketMakerQuoteResponseDto: responses,
});
}
}
const listenAndRespondToMetaTransactions = async (lastLookRequests: SignedMetaTransactionDto[]) {
const signedResponses = await yourLogicForProcessingLastLookResponses(lastLookRequests);
await apiClient.postMetaTransactionResponses({
lastLookResponseWithOrderSignatureDto: signedResponses,
});
}
License
BSL-1.0