Skip to content

Commit 73d5be9

Browse files
committed
feat(): add Next.js demo project with initial configuration and components for bybit sdk
1 parent cf3c2dc commit 73d5be9

21 files changed

+7140
-3
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "awesome-crypto-examples",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"private": true,
55
"description": "Awesome crypto automation & algo trading examples",
66
"main": "index.js",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}

src/demos/nextjs-bybit/.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env*.local
29+
30+
# vercel
31+
.vercel
32+
33+
# typescript
34+
*.tsbuildinfo
35+
next-env.d.ts

src/demos/nextjs-bybit/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
# or
14+
bun run dev
15+
```
16+
17+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18+
19+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20+
21+
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
22+
23+
## Learn More
24+
25+
To learn more about Next.js, take a look at the following resources:
26+
27+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29+
30+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
31+
32+
## Deploy on Vercel
33+
34+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35+
36+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use client';
2+
3+
import { useEffect } from 'react';
4+
import { applyGlobalPolyfill } from '../lib/global-pollyfill';
5+
6+
export function GlobalPolyfill() {
7+
useEffect(() => {
8+
applyGlobalPolyfill();
9+
}, []);
10+
11+
return null;
12+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use client';
2+
3+
import { ChangeEvent, useEffect, useState } from 'react';
4+
5+
import { socketClient as ws } from '../lib/api/bybit-clients';
6+
7+
8+
ws.on('update', (data) => {
9+
console.log('data received', data);
10+
});
11+
12+
ws.on('open', (data) => {
13+
console.log('connection opened open:', data.wsKey);
14+
});
15+
ws.on('response', (data) => {
16+
console.log('log response: ', JSON.stringify(data, null, 2));
17+
});
18+
ws.on('reconnect', ({ wsKey }) => {
19+
console.log('ws automatically reconnecting.... ', wsKey);
20+
});
21+
ws.on('reconnected', (data) => {
22+
console.log('ws has reconnected ', data?.wsKey);
23+
});
24+
25+
ws.on('exception', (data) => {
26+
console.error('ws exception: ', data);
27+
});
28+
29+
export default function OptionSelector() {
30+
const [selectedOption, setSelectedOption] = useState('');
31+
32+
const handleValueChange = (e: ChangeEvent<HTMLSelectElement>) => {
33+
e.preventDefault();
34+
const value = e.target.value;
35+
if (value) {
36+
if (selectedOption && selectedOption !== value) {
37+
ws.unsubscribeV5(`tickers.${selectedOption}`, 'linear');
38+
}
39+
40+
ws.subscribeV5(`tickers.${value}`, 'linear');
41+
42+
} else {
43+
if (selectedOption) {
44+
ws.unsubscribeV5(`ticker.${selectedOption}`, 'linear');
45+
}
46+
}
47+
48+
setSelectedOption(value);
49+
};
50+
51+
useEffect(() => {
52+
console.log(selectedOption);
53+
}, [selectedOption]);
54+
55+
return (
56+
<div>
57+
<select
58+
onChange={handleValueChange}
59+
value={selectedOption}
60+
name="option-selector"
61+
>
62+
<option value="">Select an option</option>
63+
<option value="BTCUSDT">BTCUSDT</option>
64+
<option value="ETHUSDT">ETHUSDT</option>
65+
<option value="SOLUSDT">SOLUSDT</option>
66+
</select>
67+
</div>
68+
);
69+
}
25.3 KB
Binary file not shown.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
4+
5+
:root {
6+
--foreground-rgb: 0, 0, 0;
7+
--background-start-rgb: 214, 219, 220;
8+
--background-end-rgb: 255, 255, 255;
9+
}
10+
11+
@media (prefers-color-scheme: dark) {
12+
:root {
13+
--foreground-rgb: 255, 255, 255;
14+
--background-start-rgb: 0, 0, 0;
15+
--background-end-rgb: 0, 0, 0;
16+
}
17+
}
18+
19+
body {
20+
color: rgb(var(--foreground-rgb));
21+
background: linear-gradient(
22+
to bottom,
23+
transparent,
24+
rgb(var(--background-end-rgb))
25+
)
26+
rgb(var(--background-start-rgb));
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { GlobalPolyfill } from './GlobalPollyfill';
2+
// import './globals.css';
3+
import type { Metadata } from 'next';
4+
import { Inter } from 'next/font/google';
5+
6+
const inter = Inter({ subsets: ['latin'] });
7+
8+
export const metadata: Metadata = {
9+
title: 'Create Next App',
10+
description: 'Generated by create next app',
11+
};
12+
13+
export default function RootLayout({
14+
children,
15+
}: {
16+
children: React.ReactNode;
17+
}) {
18+
return (
19+
<html lang="en">
20+
<GlobalPolyfill />
21+
<body className={inter.className}>{children}</body>
22+
</html>
23+
);
24+
}

0 commit comments

Comments
 (0)