@rholabs/rho-sdk
Version:
Rho Protocol SDK
165 lines (151 loc) • 4.05 kB
text/typescript
import * as dotenv from 'dotenv'
import { describe, expect, test } from '@jest/globals'
import { RhoV2SDK } from '../src'
import { CreateOrderRequest, OrderSide, OrderType } from '../src'
dotenv.config()
const waitTimeout = 10000
let sdk: RhoV2SDK
beforeAll(async () => {
sdk = new RhoV2SDK({
network: 'custom',
gatewayUrl: 'https://api.exchange.rhoservice.com',
authServiceUrl: 'https://auth.exchange.rhoservice.com',
})
})
describe('OrderBook API', () => {
test(
'getMarkets',
async () => {
const markets = await sdk.api.getMarkets()
expect(markets.length).toBeGreaterThan(0)
expect(markets[0].futures.length).toBeGreaterThan(0)
},
waitTimeout
)
test(
'postOrder',
async () => {
const orderRequest: CreateOrderRequest = {
"userId": "Petr-2",
"portfolioId": "default-usd",
"symbol": "BINANCE-BTCUSDT-SEP24",
"side": OrderSide.buy,
"orderType": OrderType.limit,
"price": "0.0492",
"qty": "10"
}
const order = await sdk.api.postOrder(orderRequest)
expect(order.orders.length).toBeGreaterThan(0)
},
waitTimeout
)
test(
'getPortfolios',
async () => {
const portfolios = await sdk.api.getPortfolios('Petr-2')
expect(portfolios.length).toBeGreaterThan(0)
},
waitTimeout
)
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 symbols = [
'BINANCE-BTCUSDT:DEC24',
'BINANCE-ETHUSDT:DEC24',
]
const items = await sdk.api.getSymbolStats(symbols)
expect(items.length).toBeGreaterThan(0)
expect(items[0].symbol).toBe(symbols[0])
},
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
)
test(
'getFloatingRateCandles',
async () => {
const marketId = 'BINANCE-BTCUSDT'
const from = new Date(Date.now() - 2 * 60 * 60 * 1000).toISOString()
const to = new Date().toISOString()
const candles = await sdk.api.getFloatingRateCandles({
marketId,
interval: '1d',
from,
to
})
expect(candles.length).toBeGreaterThan(0)
expect(candles[0].marketId).toBe(marketId)
expect(+candles[0].openRate).toBeGreaterThan(0)
},
waitTimeout
)
test(
'getPortfolioCandles',
async () => {
const userId = 'e5a9fecd-9a6c-47cc-97a7-a2d499f96b01'
const portfolioId = 'default-usd'
const from = new Date(Date.now() - 2 * 60 * 60 * 1000).toISOString()
const to = new Date().toISOString()
const candles = await sdk.api.getPortfolioCandles({
userId,
portfolioId,
interval: '1d',
from,
to
})
expect(candles.length).toBeGreaterThan(0)
},
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
)
})