Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@blockworks-foundation/mango-feeds

Package Overview
Dependencies
Maintainers
7
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blockworks-foundation/mango-feeds - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

dist/cjs/scripts/orderbook.d.ts

2

dist/cjs/scripts/fills.js

@@ -7,3 +7,3 @@ "use strict";

// Subscribe on connection
const fillsFeed = new src_1.FillsFeed('ws://localhost:8080', {
const fillsFeed = new src_1.FillsFeed('wss://api.mngo.cloud/fills/v1/', {
reconnectionIntervalMs: RECONNECT_INTERVAL_MS,

@@ -10,0 +10,0 @@ reconnectionMaxAttempts: RECONNECT_ATTEMPTS_MAX,

@@ -0,1 +1,2 @@

import { ReconnectingWebsocketFeed } from './util';
interface FillsFeedOptions {

@@ -44,33 +45,13 @@ subscriptions?: FillsFeedSubscribeParams;

}
interface StatusMessage {
success: boolean;
message: string;
}
export declare class FillsFeed {
private _url;
private _socket;
export declare class FillsFeed extends ReconnectingWebsocketFeed {
private _subscriptions?;
private _connected;
private _reconnectionIntervalMs;
private _reconnectionAttempts;
private _reconnectionMaxAttempts;
private _onConnect;
private _onDisconnect;
private _onFill;
private _onHead;
private _onStatus;
constructor(url: string, options?: FillsFeedOptions);
private _reconnectionAttemptsExhausted;
private _connect;
subscribe(subscriptions: FillsFeedSubscribeParams): void;
unsubscribe(marketId: string): void;
disconnect(): void;
connected(): boolean;
onConnect(callback: () => void): void;
onDisconnect(callback: () => void): void;
onFill(callback: (update: FillEventUpdate) => void): void;
onHead(callback: (update: HeadUpdate) => void): void;
onStatus(callback: (update: StatusMessage) => void): void;
}
export {};
//# sourceMappingURL=fills.d.ts.map
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FillsFeed = void 0;
const ws_1 = __importDefault(require("ws"));
const WebSocket = global.WebSocket || ws_1.default;
const util_1 = require("./util");
function isFillEventUpdate(obj) {

@@ -15,79 +11,23 @@ return obj.event !== undefined;

}
function isStatusMessage(obj) {
return obj.success !== undefined;
}
class FillsFeed {
_url;
_socket;
class FillsFeed extends util_1.ReconnectingWebsocketFeed {
_subscriptions;
_connected;
_reconnectionIntervalMs;
_reconnectionAttempts;
_reconnectionMaxAttempts;
_onConnect = null;
_onDisconnect = null;
_onFill = null;
_onHead = null;
_onStatus = null;
constructor(url, options) {
this._url = url;
super(url, options?.reconnectionIntervalMs, options?.reconnectionMaxAttempts);
this._subscriptions = options?.subscriptions;
this._reconnectionIntervalMs = options?.reconnectionIntervalMs ?? 5000;
this._reconnectionAttempts = 0;
this._reconnectionMaxAttempts = options?.reconnectionMaxAttempts ?? -1;
this._connect();
}
_reconnectionAttemptsExhausted() {
return (this._reconnectionMaxAttempts != -1 &&
this._reconnectionAttempts >= this._reconnectionMaxAttempts);
}
_connect() {
this._socket = new WebSocket(this._url);
this._socket.addEventListener('error', (err) => {
console.warn(`[FillsFeed] connection error: ${err.message}`);
if (this._reconnectionAttemptsExhausted()) {
console.error('[FillsFeed] fatal connection error');
throw err.error;
this.onMessage((data) => {
if (isFillEventUpdate(data) && this._onFill) {
this._onFill(data);
}
});
this._socket.addEventListener('open', () => {
if (this._subscriptions !== undefined) {
this.subscribe(this._subscriptions);
else if (isHeadUpdate(data) && this._onHead) {
this._onHead(data);
}
this._connected = true;
this._reconnectionAttempts = 0;
if (this._onConnect)
this._onConnect();
});
this._socket.addEventListener('close', () => {
this._connected = false;
setTimeout(() => {
if (!this._reconnectionAttemptsExhausted()) {
this._reconnectionAttempts++;
this._connect();
}
}, this._reconnectionIntervalMs);
if (this._onDisconnect)
this._onDisconnect(this._reconnectionAttemptsExhausted());
});
this._socket.addEventListener('message', (msg) => {
try {
const data = JSON.parse(msg.data);
if (isFillEventUpdate(data) && this._onFill) {
this._onFill(data);
}
else if (isHeadUpdate(data) && this._onHead) {
this._onHead(data);
}
else if (isStatusMessage(data) && this._onStatus) {
this._onStatus(data);
}
}
catch (err) {
console.warn('[FillsFeed] error deserializing message', err);
}
});
if (this._subscriptions !== undefined) {
this.subscribe(this._subscriptions);
}
}
subscribe(subscriptions) {
if (this._connected) {
if (this.connected()) {
this._socket.send(JSON.stringify({

@@ -103,3 +43,3 @@ command: 'subscribe',

unsubscribe(marketId) {
if (this._connected) {
if (this.connected()) {
this._socket.send(JSON.stringify({

@@ -114,20 +54,2 @@ command: 'unsubscribe',

}
disconnect() {
if (this._connected) {
this._socket.close();
this._connected = false;
}
else {
console.warn('[FillsFeed] attempt to disconnect when not connected');
}
}
connected() {
return this._connected;
}
onConnect(callback) {
this._onConnect = callback;
}
onDisconnect(callback) {
this._onDisconnect = callback;
}
onFill(callback) {

@@ -139,6 +61,3 @@ this._onFill = callback;

}
onStatus(callback) {
this._onStatus = callback;
}
}
exports.FillsFeed = FillsFeed;

@@ -1,2 +0,4 @@

export * from './fills';
import { FillsFeed } from './fills';
import { OrderbookFeed } from './orderbook';
export { FillsFeed, OrderbookFeed };
//# sourceMappingURL=index.d.ts.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./fills"), exports);
exports.OrderbookFeed = exports.FillsFeed = void 0;
const fills_1 = require("./fills");
Object.defineProperty(exports, "FillsFeed", { enumerable: true, get: function () { return fills_1.FillsFeed; } });
const orderbook_1 = require("./orderbook");
Object.defineProperty(exports, "OrderbookFeed", { enumerable: true, get: function () { return orderbook_1.OrderbookFeed; } });

@@ -0,1 +1,37 @@

import { ReconnectingWebsocketFeed } from './util';
interface OrderbookFeedOptions {
subscriptions?: OrderbookFeedSubscribeParams;
reconnectionIntervalMs?: number;
reconnectionMaxAttempts?: number;
}
interface OrderbookFeedSubscribeParams {
marketId?: string;
marketIds?: string[];
}
interface OrderbookL2Update {
market: string;
side: 'bid' | 'ask';
update: [number, number][];
slot: number;
writeVersion: number;
}
interface OrderbookL2Checkpoint {
market: string;
side: 'bid' | 'ask';
bids: [number, number][];
asks: [number, number][];
slot: number;
writeVersion: number;
}
export declare class OrderbookFeed extends ReconnectingWebsocketFeed {
private _subscriptions?;
private _onL2Update;
private _onL2Checkpoint;
constructor(url: string, options?: OrderbookFeedOptions);
subscribe(subscriptions: OrderbookFeedSubscribeParams): void;
unsubscribe(marketId: string): void;
onL2Update(callback: (update: OrderbookL2Update) => void): void;
onL2Checkpoint(callback: (checkpoint: OrderbookL2Checkpoint) => void): void;
}
export {};
//# sourceMappingURL=orderbook.d.ts.map

@@ -0,1 +1,2 @@

import { ReconnectingWebsocketFeed } from './util';
interface FillsFeedOptions {

@@ -44,33 +45,13 @@ subscriptions?: FillsFeedSubscribeParams;

}
interface StatusMessage {
success: boolean;
message: string;
}
export declare class FillsFeed {
private _url;
private _socket;
export declare class FillsFeed extends ReconnectingWebsocketFeed {
private _subscriptions?;
private _connected;
private _reconnectionIntervalMs;
private _reconnectionAttempts;
private _reconnectionMaxAttempts;
private _onConnect;
private _onDisconnect;
private _onFill;
private _onHead;
private _onStatus;
constructor(url: string, options?: FillsFeedOptions);
private _reconnectionAttemptsExhausted;
private _connect;
subscribe(subscriptions: FillsFeedSubscribeParams): void;
unsubscribe(marketId: string): void;
disconnect(): void;
connected(): boolean;
onConnect(callback: () => void): void;
onDisconnect(callback: () => void): void;
onFill(callback: (update: FillEventUpdate) => void): void;
onHead(callback: (update: HeadUpdate) => void): void;
onStatus(callback: (update: StatusMessage) => void): void;
}
export {};
//# sourceMappingURL=fills.d.ts.map

@@ -1,3 +0,2 @@

import ws from 'ws';
const WebSocket = global.WebSocket || ws;
import { ReconnectingWebsocketFeed } from './util';
function isFillEventUpdate(obj) {

@@ -9,79 +8,23 @@ return obj.event !== undefined;

}
function isStatusMessage(obj) {
return obj.success !== undefined;
}
export class FillsFeed {
_url;
_socket;
export class FillsFeed extends ReconnectingWebsocketFeed {
_subscriptions;
_connected;
_reconnectionIntervalMs;
_reconnectionAttempts;
_reconnectionMaxAttempts;
_onConnect = null;
_onDisconnect = null;
_onFill = null;
_onHead = null;
_onStatus = null;
constructor(url, options) {
this._url = url;
super(url, options?.reconnectionIntervalMs, options?.reconnectionMaxAttempts);
this._subscriptions = options?.subscriptions;
this._reconnectionIntervalMs = options?.reconnectionIntervalMs ?? 5000;
this._reconnectionAttempts = 0;
this._reconnectionMaxAttempts = options?.reconnectionMaxAttempts ?? -1;
this._connect();
}
_reconnectionAttemptsExhausted() {
return (this._reconnectionMaxAttempts != -1 &&
this._reconnectionAttempts >= this._reconnectionMaxAttempts);
}
_connect() {
this._socket = new WebSocket(this._url);
this._socket.addEventListener('error', (err) => {
console.warn(`[FillsFeed] connection error: ${err.message}`);
if (this._reconnectionAttemptsExhausted()) {
console.error('[FillsFeed] fatal connection error');
throw err.error;
this.onMessage((data) => {
if (isFillEventUpdate(data) && this._onFill) {
this._onFill(data);
}
});
this._socket.addEventListener('open', () => {
if (this._subscriptions !== undefined) {
this.subscribe(this._subscriptions);
else if (isHeadUpdate(data) && this._onHead) {
this._onHead(data);
}
this._connected = true;
this._reconnectionAttempts = 0;
if (this._onConnect)
this._onConnect();
});
this._socket.addEventListener('close', () => {
this._connected = false;
setTimeout(() => {
if (!this._reconnectionAttemptsExhausted()) {
this._reconnectionAttempts++;
this._connect();
}
}, this._reconnectionIntervalMs);
if (this._onDisconnect)
this._onDisconnect(this._reconnectionAttemptsExhausted());
});
this._socket.addEventListener('message', (msg) => {
try {
const data = JSON.parse(msg.data);
if (isFillEventUpdate(data) && this._onFill) {
this._onFill(data);
}
else if (isHeadUpdate(data) && this._onHead) {
this._onHead(data);
}
else if (isStatusMessage(data) && this._onStatus) {
this._onStatus(data);
}
}
catch (err) {
console.warn('[FillsFeed] error deserializing message', err);
}
});
if (this._subscriptions !== undefined) {
this.subscribe(this._subscriptions);
}
}
subscribe(subscriptions) {
if (this._connected) {
if (this.connected()) {
this._socket.send(JSON.stringify({

@@ -97,3 +40,3 @@ command: 'subscribe',

unsubscribe(marketId) {
if (this._connected) {
if (this.connected()) {
this._socket.send(JSON.stringify({

@@ -108,20 +51,2 @@ command: 'unsubscribe',

}
disconnect() {
if (this._connected) {
this._socket.close();
this._connected = false;
}
else {
console.warn('[FillsFeed] attempt to disconnect when not connected');
}
}
connected() {
return this._connected;
}
onConnect(callback) {
this._onConnect = callback;
}
onDisconnect(callback) {
this._onDisconnect = callback;
}
onFill(callback) {

@@ -133,5 +58,2 @@ this._onFill = callback;

}
onStatus(callback) {
this._onStatus = callback;
}
}

@@ -1,2 +0,4 @@

export * from './fills';
import { FillsFeed } from './fills';
import { OrderbookFeed } from './orderbook';
export { FillsFeed, OrderbookFeed };
//# sourceMappingURL=index.d.ts.map

@@ -1,1 +0,3 @@

export * from './fills';
import { FillsFeed } from './fills';
import { OrderbookFeed } from './orderbook';
export { FillsFeed, OrderbookFeed };

@@ -0,1 +1,37 @@

import { ReconnectingWebsocketFeed } from './util';
interface OrderbookFeedOptions {
subscriptions?: OrderbookFeedSubscribeParams;
reconnectionIntervalMs?: number;
reconnectionMaxAttempts?: number;
}
interface OrderbookFeedSubscribeParams {
marketId?: string;
marketIds?: string[];
}
interface OrderbookL2Update {
market: string;
side: 'bid' | 'ask';
update: [number, number][];
slot: number;
writeVersion: number;
}
interface OrderbookL2Checkpoint {
market: string;
side: 'bid' | 'ask';
bids: [number, number][];
asks: [number, number][];
slot: number;
writeVersion: number;
}
export declare class OrderbookFeed extends ReconnectingWebsocketFeed {
private _subscriptions?;
private _onL2Update;
private _onL2Checkpoint;
constructor(url: string, options?: OrderbookFeedOptions);
subscribe(subscriptions: OrderbookFeedSubscribeParams): void;
unsubscribe(marketId: string): void;
onL2Update(callback: (update: OrderbookL2Update) => void): void;
onL2Checkpoint(callback: (checkpoint: OrderbookL2Checkpoint) => void): void;
}
export {};
//# sourceMappingURL=orderbook.d.ts.map

@@ -0,1 +1,2 @@

import { ReconnectingWebsocketFeed } from './util';
interface FillsFeedOptions {

@@ -44,33 +45,13 @@ subscriptions?: FillsFeedSubscribeParams;

}
interface StatusMessage {
success: boolean;
message: string;
}
export declare class FillsFeed {
private _url;
private _socket;
export declare class FillsFeed extends ReconnectingWebsocketFeed {
private _subscriptions?;
private _connected;
private _reconnectionIntervalMs;
private _reconnectionAttempts;
private _reconnectionMaxAttempts;
private _onConnect;
private _onDisconnect;
private _onFill;
private _onHead;
private _onStatus;
constructor(url: string, options?: FillsFeedOptions);
private _reconnectionAttemptsExhausted;
private _connect;
subscribe(subscriptions: FillsFeedSubscribeParams): void;
unsubscribe(marketId: string): void;
disconnect(): void;
connected(): boolean;
onConnect(callback: () => void): void;
onDisconnect(callback: () => void): void;
onFill(callback: (update: FillEventUpdate) => void): void;
onHead(callback: (update: HeadUpdate) => void): void;
onStatus(callback: (update: StatusMessage) => void): void;
}
export {};
//# sourceMappingURL=fills.d.ts.map

@@ -1,2 +0,4 @@

export * from './fills';
import { FillsFeed } from './fills';
import { OrderbookFeed } from './orderbook';
export { FillsFeed, OrderbookFeed };
//# sourceMappingURL=index.d.ts.map

@@ -0,1 +1,37 @@

import { ReconnectingWebsocketFeed } from './util';
interface OrderbookFeedOptions {
subscriptions?: OrderbookFeedSubscribeParams;
reconnectionIntervalMs?: number;
reconnectionMaxAttempts?: number;
}
interface OrderbookFeedSubscribeParams {
marketId?: string;
marketIds?: string[];
}
interface OrderbookL2Update {
market: string;
side: 'bid' | 'ask';
update: [number, number][];
slot: number;
writeVersion: number;
}
interface OrderbookL2Checkpoint {
market: string;
side: 'bid' | 'ask';
bids: [number, number][];
asks: [number, number][];
slot: number;
writeVersion: number;
}
export declare class OrderbookFeed extends ReconnectingWebsocketFeed {
private _subscriptions?;
private _onL2Update;
private _onL2Checkpoint;
constructor(url: string, options?: OrderbookFeedOptions);
subscribe(subscriptions: OrderbookFeedSubscribeParams): void;
unsubscribe(marketId: string): void;
onL2Update(callback: (update: OrderbookL2Update) => void): void;
onL2Checkpoint(callback: (checkpoint: OrderbookL2Checkpoint) => void): void;
}
export {};
//# sourceMappingURL=orderbook.d.ts.map
{
"name": "@blockworks-foundation/mango-feeds",
"version": "0.1.5",
"version": "0.1.6",
"description": "Typescript Client for mango-feeds.",

@@ -5,0 +5,0 @@ "repository": "https://github.com/blockworks-foundation/mango-feeds",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc