Socket
Socket
Sign inDemoInstall

@rolla-finance/mm-api-client

Package Overview
Dependencies
57
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @rolla-finance/mm-api-client

Client library to interact with the Rolla ecosystem


Version published
Weekly downloads
10
Maintainers
1
Install size
2.15 MB
Created
Weekly downloads
 

Readme

Source

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

FAQs

Last updated on 02 Mar 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc