You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@rholabs/rho-sdk

Package Overview
Dependencies
Maintainers
0
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rholabs/rho-sdk - npm Package Compare versions

Comparing version

to
0.4.0-alpha10

src/v2/api/auth.ts

113

lib/types.d.ts

@@ -467,2 +467,3 @@ import { BrowserProvider, JsonRpcSigner, JsonRpcProvider } from "ethers";

gatewayUrl?: string;
authServiceUrl?: string;
}

@@ -472,2 +473,3 @@ export interface RhoV2Config {

gatewayUrl: string;
authServiceUrl: string;
}

@@ -508,4 +510,4 @@ export interface Currency {

}
export type TimeInForce = 'GTC' | 'IOC';
export interface CreateOrderRequest {
clientOrderId: string;
userId: string;

@@ -516,5 +518,20 @@ portfolioId: string;

orderType: OrderType;
price: string;
price?: string;
qty: string;
timeInForce?: TimeInForce;
}
export interface CancelOrderRequest {
userId: string;
symbol: string;
clientOrderId?: string;
orderId?: string;
}
export interface CancelOrderResponse {
symbol: string;
processingType: string;
seqId: string;
trades: any;
orderExecutionReports: OrderExecutionReport[];
stateUpdates: any;
}
export enum OrderStatus {

@@ -630,2 +647,74 @@ created = 0

}
export type OrderBookSide = 'ask' | 'bid';
export interface Order {
price: string;
volume: string;
}
export interface SymbolStats {
"symbol": string;
"highPrice": string;
"lowPrice": string;
"lastPrice": string;
"lastOpenInterest": string;
"lastAccumulatedVolume": string;
"lastAccumulatedTradesCount": string;
"lastUpdateTime": string;
"priceChange": string;
"volumeChange": string;
"tradesCountChange": string;
"openInterestChange": string;
"seqId": string;
}
export interface OrderBookTrade {
accumulatedTradesCountAfter: string;
accumulatedVolumeBefore: string;
openInterestAfter: string;
openInterestBefore: string;
price: string;
priceBefore: string;
seqId: string;
side: OrderSide;
symbol: string;
time: string;
volume: string;
}
export type OrderBookCandleInterval = '1m' | '5m' | '15m' | '1h' | '1d';
export interface OrderBookCandle {
accumulatedTradesCountAtOpen: string;
accumulatedVolumeAtClose: string;
accumulatedVolumeAtOpen: string;
closePrice: string;
closeTime: string;
highPrice: string;
interval: string;
lowPrice: string;
openInterestAtClose: string;
openInterestAtOpen: string;
openPrice: string;
openTime: string;
seqId: string;
symbol: string;
tradesCount: string;
volume: string;
}
export interface JWTTokensPair {
accessToken: string;
refreshToken: string;
tokenType: string;
}
export type Role = 'admin' | 'user';
export interface UserBlockchainAccount {
id: string;
address: string;
}
export interface UserAccount {
id: string;
roles: Role[];
blockchainAccounts: UserBlockchainAccount[];
copperAccounts: any[];
createdAt: string;
iat: number;
exp: number;
jti: string;
}
declare class RhoV2API {

@@ -635,7 +724,27 @@ constructor(config: RhoV2Config);

postOrder(requestData: CreateOrderRequest): Promise<CreateOrderResponse>;
cancelOrder(requestData: CancelOrderRequest): Promise<CancelOrderResponse>;
getPortfolios(userId: string): Promise<UserPortfolio[]>;
getOrderBook(symbol: string, depth?: number): Promise<{
symbol: string;
asks: Order[];
bids: Order[];
}>;
getSymbolStats(symbols: string[]): Promise<SymbolStats[]>;
getCandles(params: {
symbol: string;
interval: OrderBookCandleInterval;
from?: string;
to?: string;
}): Promise<OrderBookCandle[]>;
}
declare class RhoV2AuthAPI {
constructor(config: RhoV2Config);
getPublicKey(): Promise<string>;
requestSignIn(address: string): Promise<number>;
verifyRequest(address: string, signature: string): Promise<JWTTokensPair>;
}
export class RhoV2SDK {
config: RhoV2Config;
api: RhoV2API;
auth: RhoV2AuthAPI;
constructor(configParams?: RhoV2ConfigParams);

@@ -642,0 +751,0 @@ }

2

package.json
{
"name": "@rholabs/rho-sdk",
"version": "0.4.0-alpha1",
"version": "0.4.0-alpha10",
"description": "Rho Protocol SDK",

@@ -5,0 +5,0 @@ "source": "src/index.ts",

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

import { CreateOrderRequest, CreateOrderResponse, Market, RhoV2Config, UserPortfolio } from '../typings'
import {
CancelOrderRequest,
CancelOrderResponse,
CreateOrderRequest,
CreateOrderResponse,
Market,
Order,
OrderBookCandle,
OrderBookCandleInterval,
RhoV2Config,
SymbolStats,
UserPortfolio
} from '../typings'
import axios, { Axios } from 'axios'

@@ -39,2 +51,14 @@

async cancelOrder(requestData: CancelOrderRequest) {
const { data } = await this.client.post<{
data: CancelOrderResponse
message: string
}>('/orders/cancel', requestData, {
headers: {
'Content-Type': 'application/json'
}
})
return data.data
}
async getPortfolios(userId: string) {

@@ -48,2 +72,47 @@ const { data } = await this.client.get<{

}
async getOrderBook(symbol: string, depth = 20) {
const { data } = await this.client.get<{
data: {
symbol: string
asks: Order[]
bids: Order[]
}
}>(`/markets/symbols/${symbol}/order-book`, {
params: {
depth
}
})
return data.data
}
async getSymbolStats(symbols: string[]): Promise<SymbolStats[]> {
const symbolsList = symbols
.map((symbol, index) => `${index === 0 ? '?' : '&'}symbols=${symbol}`)
.join('')
const { data } = await this.client.get<{
data: SymbolStats[]
}>(`markets/symbols/stats${symbolsList}`)
return data.data
}
async getCandles(params: {
symbol: string
interval: OrderBookCandleInterval
from?: string
to?: string
}): Promise<OrderBookCandle[]> {
const { symbol, interval, from, to } = params
const { data } = await this.client.get<{
data: OrderBookCandle[]
}>(`/markets/symbols/${symbol}/candles`, {
params: {
interval,
from,
to
}
})
return data.data
}
}

@@ -5,3 +5,4 @@ import { RhoV2Config } from './typings'

network: 'mainnet',
gatewayUrl: ''
gatewayUrl: '',
authServiceUrl: ''
}

@@ -11,3 +12,4 @@

network: 'mainnet',
gatewayUrl: ''
gatewayUrl: '',
authServiceUrl: ''
}

@@ -17,3 +19,4 @@

network: 'custom',
gatewayUrl: 'http://localhost:8081'
gatewayUrl: 'http://localhost:8081',
authServiceUrl: ''
}

@@ -8,2 +8,3 @@ import { RhoV2Config, RhoV2ConfigParams } from './typings'

import { RhoV2API } from './api'
import { RhoV2AuthAPI } from './api/auth'
export * from './typings'

@@ -14,2 +15,3 @@

api: RhoV2API
auth: RhoV2AuthAPI

@@ -19,2 +21,3 @@ constructor(configParams: RhoV2ConfigParams = {}) {

this.api = new RhoV2API(this.config)
this.auth = new RhoV2AuthAPI(this.config)
}

@@ -21,0 +24,0 @@

@@ -6,2 +6,3 @@ export type NetworkType = 'mainnet' | 'testnet' | 'custom'

gatewayUrl?: string
authServiceUrl?: string
}

@@ -12,2 +13,3 @@

gatewayUrl: string
authServiceUrl: string
}

@@ -56,4 +58,5 @@

export type TimeInForce = 'GTC' | 'IOC'
export interface CreateOrderRequest {
clientOrderId: string
userId: string

@@ -64,7 +67,23 @@ portfolioId: string

orderType: OrderType
price: string
price?: string // not required for the market order
qty: string
// timeInForce: string
timeInForce?: TimeInForce
}
export interface CancelOrderRequest {
userId: string
symbol: string
clientOrderId?: string
orderId?: string
}
export interface CancelOrderResponse {
symbol: string
processingType: string
seqId: string
trades: any
orderExecutionReports: OrderExecutionReport[]
stateUpdates: any
}
export enum OrderStatus {

@@ -188,1 +207,82 @@ created = 0

}
export type OrderBookSide = 'ask' | 'bid'
export interface Order {
price: string
volume: string
}
export interface SymbolStats {
"symbol": string
"highPrice": string
"lowPrice": string
"lastPrice": string
"lastOpenInterest": string
"lastAccumulatedVolume": string
"lastAccumulatedTradesCount": string
"lastUpdateTime": string
"priceChange": string
"volumeChange": string
"tradesCountChange": string
"openInterestChange": string
"seqId": string
}
export interface OrderBookTrade {
accumulatedTradesCountAfter: string
accumulatedVolumeBefore: string
openInterestAfter: string
openInterestBefore: string
price: string
priceBefore: string
seqId: string
side: OrderSide
symbol: string
time: string
volume: string
}
export type OrderBookCandleInterval = '1m' | '5m' | '15m' | '1h' | '1d'
export interface OrderBookCandle {
accumulatedTradesCountAtOpen: string
accumulatedVolumeAtClose: string
accumulatedVolumeAtOpen: string
closePrice: string
closeTime: string
highPrice: string
interval: string
lowPrice: string
openInterestAtClose: string
openInterestAtOpen: string
openPrice: string
openTime: string
seqId: string
symbol: string
tradesCount: string
volume: string
}
export interface JWTTokensPair {
accessToken: string
refreshToken: string
tokenType: string
}
export type Role = 'admin' | 'user'
export interface UserBlockchainAccount {
id: string
address: string
}
export interface UserAccount {
id: string
roles: Role[]
blockchainAccounts: UserBlockchainAccount[]
copperAccounts: any[]
createdAt: string
iat: number
exp: number
jti: string
}
import * as dotenv from 'dotenv'
import { describe, expect, test } from '@jest/globals'
import { RhoV2SDK } from '../src'
import { CreateOrderRequest, OrderSide, OrderType } from '../src/v2'
import { CreateOrderRequest, OrderSide, OrderType } from '../src'

@@ -14,7 +14,8 @@ dotenv.config()

network: 'custom',
gatewayUrl: 'http://localhost:8081'
gatewayUrl: 'http://localhost:8081',
authServiceUrl: 'http://localhost:8085',
})
})
describe('API', () => {
describe('OrderBook API', () => {
test(

@@ -34,3 +35,2 @@ 'getMarkets',

const orderRequest: CreateOrderRequest = {
"clientOrderId": "12345",
"userId": "Petr-2",

@@ -58,2 +58,69 @@ "portfolioId": "default-usd",

)
test(
'getOrderBook',
async () => {
const {
symbol,
asks,
bids
} = await sdk.api.getOrderBook('BINANCE-BTCUSDT-DEC24')
expect(symbol.length).toBeGreaterThan(0)
expect(asks.length).toBeGreaterThanOrEqual(0)
expect(bids.length).toBeGreaterThanOrEqual(0)
},
waitTimeout
)
test(
'getSymbolStats',
async () => {
const symbol = 'BINANCE-BTCUSDT-DEC24'
const items = await sdk.api.getSymbolStats([symbol])
expect(items.length).toBeGreaterThan(0)
expect(items[0].symbol).toBe(symbol)
},
waitTimeout
)
test(
'getCandles',
async () => {
const symbol = 'BINANCE-BTCUSDT-DEC24'
const from = new Date(Date.now() - 2 * 60 * 60 * 1000).toISOString()
const to = new Date().toISOString()
const candles = await sdk.api.getCandles({
symbol,
interval: '1m',
from,
to
})
expect(candles.length).toBeGreaterThan(0)
expect(candles[0].symbol).toBe(symbol)
},
waitTimeout
)
})
describe('Auth API', () => {
test(
'getPublicKey',
async () => {
const publicKey = await sdk.auth.getPublicKey()
expect(typeof publicKey).toBe('string')
expect(publicKey.length).toBeGreaterThan(0)
},
waitTimeout
)
test(
'requestSignIn',
async () => {
const userAddress = '0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0'
const nonce = await sdk.auth.requestSignIn(userAddress)
expect(typeof nonce).toBe('number')
expect(nonce).toBeGreaterThan(0)
},
waitTimeout
)
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet