Overview
Introduction to RISEx API and setup
RISE API Usage Examples
This document provides example usage of the RISE API using axios. For complete API documentation, please refer to the Full API Documentation.
Base URL
https://api.testnet.rise.tradeSetup
import axios from 'axios';
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
import { keccak256, type Hex } from 'viem';
import { createClientNonce } from 'risex-core';
import { formatSignature } from 'blockchain-core';
import dayjs from 'dayjs';
const API_BASE_URL = 'https://api.testnet.rise.trade';
// Create axios instance
const apiClient = axios.create({
baseURL: API_BASE_URL,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
timeout: 30000,
});
// Create nonce
function nowInNano() {
const rand6Digits = Math.round(Math.random() * 1000000)
.toString()
.padStart(6, '0');
return `${dayjs().valueOf()}${rand6Digits}`;
};
function hashToUint32(input: string) {
let hash = 0;
for (let i = 0; i < input.length; i += 1) {
hash = (hash * 31 + input.charCodeAt(i)) | 0;
}
return hash >>> 0;
}
const createClientNonce = (address: string | undefined) => {
const baseNonce = nowInNano();
const secondOfNonce = baseNonce.slice(0, -9);
return baseNonce.slice(0, -6) + hashToUint32(`${secondOfNonce}${address?.toLowerCase()}`).toString().slice(-6);
};
// Domain for EIP-712 signing
const RISEx_CHAIN_ID = 11155931;
const getRISExDomain = (authContractAddress: string) => ({
name: 'RISEx',
version: '1',
chainId: RISEx_CHAIN_ID,
verifyingContract: authContractAddress,
});
// EIP-712 Type definitions
const REGISTER_TYPES = {
EIP712Domain: [
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'chainId', type: 'uint256' },
{ name: 'verifyingContract', type: 'address' },
],
RegisterSigner: [
{ name: 'signer', type: 'address' },
{ name: 'message', type: 'string' },
{ name: 'expiration', type: 'uint40' },
{ name: 'nonce', type: 'uint256' },
],
VerifySigner: [
{ name: 'account', type: 'address' },
{ name: 'nonce', type: 'uint256' },
],
};
const VERIFY_SIGNATURE_TYPES = {
VerifySignature: [
{ name: 'account', type: 'address' },
{ name: 'target', type: 'address' }, // perp or spot address
{ name: 'hash', type: 'bytes32' },
{ name: 'nonce', type: 'uint256' },
{ name: 'deadline', type: 'uint256' }, // seconds
],
};
// Enum values
enum OrderSide {
Long = 0,
Short = 1,
}
enum STPMode {
ExpireMaker = 0,
ExpireTaker = 1,
ExpireBoth = 2,
None = 3,
}
enum OrderType {
Market = 0,
Limit = 1,
}
enum TimeInForce {
GoodTillCancelled = 0,
GoodTillTime = 1,
FillOrKill = 2,
ImmediateOrCancel = 3,
}
enum MarketsId {
BTC = 0,
ETH = 1
}Full API Documentation
For complete API documentation including:
- All request/response schemas
- Authentication requirements
- Rate limits
- WebSocket endpoints
- Error codes
Please visit: Full API Documentation