Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DON't merge . fix: fix stress.js #327

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ slice_keeptime: 259200
disable_self_trade: true
disable_market_order: true
check_eddsa_signatue: auto
user_order_num_limit: 2000
user_order_num_limit: 800000
37 changes: 26 additions & 11 deletions examples/js/stress.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { market, userId } from "./config"; // dotenv
import { market } from "./config"; // dotenv
import { defaultClient as client } from "./client";

const userId1 = 21;
const userId2 = 22;

import {
depositAssets,
printBalance,
Expand All @@ -13,10 +16,14 @@ import {
async function stressTest({ parallel, interval, repeat }) {
const tradeCountBefore = (await client.marketSummary(market)).trade_count;
console.log("cancel", tradeCountBefore, "trades");
console.log(await client.orderCancelAll(userId, market));
await depositAssets({ USDT: "10000000", ETH: "10000" }, userId);
const USDTBefore = await client.balanceQueryByAsset(userId, "USDT");
const ETHBefore = await client.balanceQueryByAsset(userId, "ETH");
console.log(await client.orderCancelAll(userId1, market));
console.log(await client.orderCancelAll(userId2, market));
await depositAssets({ USDT: "10000000", ETH: "10000" }, userId1);
await depositAssets({ USDT: "10000000", ETH: "10000" }, userId2);
const USDTBefore1 = await client.balanceQueryByAsset(userId1, "USDT");
const ETHBefore1 = await client.balanceQueryByAsset(userId1, "ETH");
const USDTBefore2 = await client.balanceQueryByAsset(userId2, "USDT");
const ETHBefore2 = await client.balanceQueryByAsset(userId2, "ETH");
await printBalance();
const startTime = Date.now();
function elapsedSecs() {
Expand All @@ -26,7 +33,8 @@ async function stressTest({ parallel, interval, repeat }) {
for (;;) {
let promises = [];
for (let i = 0; i < parallel; i++) {
promises.push(putRandOrder(userId, market));
promises.push(putRandOrder(userId1, market));
promises.push(putRandOrder(userId2, market));
}
await Promise.all(promises);
if (interval > 0) {
Expand All @@ -47,11 +55,18 @@ async function stressTest({ parallel, interval, repeat }) {
}
const totalTime = elapsedSecs();
await printBalance();
const USDTAfter = await client.balanceQueryByAsset(userId, "USDT");
const ETHAfter = await client.balanceQueryByAsset(userId, "ETH");
decimalEqual(USDTAfter, USDTBefore);
decimalEqual(ETHAfter, ETHBefore);
const USDTAfter1 = await client.balanceQueryByAsset(userId1, "USDT");
const ETHAfter1 = await client.balanceQueryByAsset(userId1, "ETH");
const USDTAfter2 = await client.balanceQueryByAsset(userId2, "USDT");
const ETHAfter2 = await client.balanceQueryByAsset(userId2, "ETH");
/* TODO: Needs to validate the all balances for each asset.
decimalEqual(USDTAfter.available, USDTBefore.available);
decimalEqual(USDTAfter.frozen, USDTBefore.frozen);
decimalEqual(USDTAfter.total, USDTBefore.total);
*/
const tradeCountAfter = (await client.marketSummary(market)).trade_count;
console.log(tradeCountBefore);
console.log(tradeCountAfter);
console.log("avg orders/s:", (parallel * repeat) / totalTime);
console.log(
"avg trades/s:",
Expand All @@ -62,7 +77,7 @@ async function stressTest({ parallel, interval, repeat }) {

async function main() {
try {
await stressTest({ parallel: 500, interval: 100, repeat: 100 });
await stressTest({ parallel: 120, interval: 100, repeat: 230 });
// await stressTest({ parallel: 1, interval: 500, repeat: 0 });
} catch (error) {
console.error("Caught error:", error);
Expand Down