JJev Cookbook
课程首页 中文文档 拓展阅读 GitHub ↗

拓展阅读 / Jev Trader:交易决策工程

知识库收录材料 · 原始文件 ↗ · 来源、版本与许可

APIs


description: Use Bun instead of Node.js, npm, pnpm, or vite. globs: ".ts, .tsx, .html, .css, .js, .jsx, package.json" alwaysApply: false


Default to using Bun instead of Node.js.

  • Use bun <file> instead of node <file> or ts-node <file>

  • Use bun test instead of jest or vitest

  • Use bun build <file.html|file.ts|file.css> instead of webpack or esbuild

  • Use bun install instead of npm install or yarn install or pnpm install

  • Use bun run <script> instead of npm run <script> or yarn run <script> or pnpm run <script>

  • Use bunx <package> <command> instead of npx <package> <command>

  • Bun automatically loads .env, so don't use dotenv.

APIs

  • Bun.serve() supports WebSockets, HTTPS, and routes. Don't use express.

  • bun:sqlite for SQLite. Don't use better-sqlite3.

  • Bun.redis for Redis. Don't use ioredis.

  • Bun.sql for Postgres. Don't use pg or postgres.js.

  • WebSocket is built-in. Don't use ws.

  • Prefer Bun.file over node:fs's readFile/writeFile

  • Bun.$ls instead of execa.

Testing

Use bun test to run tests.

ts#index.test.ts
import { test, expect } from "bun:test";

test("hello world", () => {
  expect(1).toBe(1);
});

Frontend

Use HTML imports with Bun.serve(). Don't use vite. HTML imports fully support React, CSS, Tailwind.

Server:

ts#index.ts
import index from "./index.html"

Bun.serve({
  routes: {
    "/": index,
    "/api/users/:id": {
      GET: (req) => {
        return new Response(JSON.stringify({ id: req.params.id }));
      },
    },
  },
  // optional websocket support
  websocket: {
    open: (ws) => {
      ws.send("Hello, world!");
    },
    message: (ws, message) => {
      ws.send(message);
    },
    close: (ws) => {
      // handle close
    }
  },
  development: {
    hmr: true,
    console: true,
  }
})

HTML files can import .tsx, .jsx or .js files directly and Bun's bundler will transpile & bundle automatically. <link> tags can point to stylesheets and Bun's CSS bundler will bundle.

html#index.html
<html>
  <body>
    <h1>Hello, world!</h1>
    <script type="module" src="./frontend.tsx"></script>
  </body>
</html>

With the following frontend.tsx:

tsx#frontend.tsx
import React from "react";
import { createRoot } from "react-dom/client";

// import .css files directly and it works
import './index.css';

const root = createRoot(document.body);

export default function Frontend() {
  return <h1>Hello, world!</h1>;
}

root.render(<Frontend />);

Then, run index.ts

sh
bun --hot ./index.ts

For more information, read the Bun API docs in node_modules/bun-types/docs/**.mdx.

The core message (do not break this)

The demo exists to support this tweet. Every design or strategy change must keep all four claims true:

I built a trading bot with Jev!

Jev decides if it should "buy" or "sell", given the price feed of an asset pair, and executes real trades.

It uses Monad to place the orders on Kuru's on-chain order book in every 300ms block.

Demo link: https://jev-trader.vercel.app

Non-negotiables: Jev makes the buy/sell call (not code), from the price feed; real trades from a real wallet; an order placed on Kuru's on-chain book every 300 ms block; the demo is the live dashboard. Never decide every N blocks. No middle dots, em dashes or en dashes in any rendered text. No blinking or pulsing indicators.

第十一章知识库收录材料 · 来源、版本与许可 · 第三方内容版权归各自作者;观点与数字请对照原始来源核验。