@nabeeltahirdeveloper/chart-sdk 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +144 -150
- package/package.json +50 -48
- package/dist/chart-sdk.es.js +0 -20354
- package/dist/chart-sdk.umd.js +0 -43
package/README.md
CHANGED
|
@@ -20,12 +20,12 @@ npm install react react-dom
|
|
|
20
20
|
import { TradingProvider, Chart, TradingToolbar } from '@nabeeltahirdeveloper/chart-sdk'
|
|
21
21
|
|
|
22
22
|
function App() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
return (
|
|
24
|
+
<TradingProvider baseUrl='https://your-api-url.com'>
|
|
25
|
+
<TradingToolbar />
|
|
26
|
+
<Chart />
|
|
27
|
+
</TradingProvider>
|
|
28
|
+
)
|
|
29
29
|
}
|
|
30
30
|
```
|
|
31
31
|
|
|
@@ -38,29 +38,27 @@ All components must be rendered inside a `<TradingProvider>`.
|
|
|
38
38
|
Wraps your app and provides trading state (symbols, prices, orders, drawing tools, etc).
|
|
39
39
|
|
|
40
40
|
```jsx
|
|
41
|
-
<TradingProvider baseUrl=
|
|
42
|
-
{children}
|
|
43
|
-
</TradingProvider>
|
|
41
|
+
<TradingProvider baseUrl='https://your-api-url.com'>{children}</TradingProvider>
|
|
44
42
|
```
|
|
45
43
|
|
|
46
|
-
| Prop
|
|
47
|
-
|
|
48
|
-
| `baseUrl`
|
|
49
|
-
| `endpoints` | `object`
|
|
50
|
-
| `children`
|
|
44
|
+
| Prop | Type | Description |
|
|
45
|
+
| ----------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
46
|
+
| `baseUrl` | `string` | **Your project's backend API URL.** All SDK API calls (trades, candles, symbols, account) go to this URL. If omitted, uses `VITE_BASE_URL` env or `http://localhost:8000`. |
|
|
47
|
+
| `endpoints` | `object` | **Optional:** Custom endpoint paths. If your backend uses different paths, override them here. Default: `{ candles: '/api/chart/candles', symbols: '/api/symbols', trades: '/api/trades', account: '/api/user/account' }` |
|
|
48
|
+
| `children` | `ReactNode` | Child components |
|
|
51
49
|
|
|
52
50
|
**Example with custom endpoints:**
|
|
51
|
+
|
|
53
52
|
```jsx
|
|
54
|
-
<TradingProvider
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
<Chart />
|
|
53
|
+
<TradingProvider
|
|
54
|
+
baseUrl='https://api-mt5-project.com'
|
|
55
|
+
endpoints={{
|
|
56
|
+
candles: '/api/v1/chart/candles', // MT5 backend path
|
|
57
|
+
symbols: '/api/v1/symbols',
|
|
58
|
+
trades: '/api/v1/trades',
|
|
59
|
+
account: '/api/v1/user/account',
|
|
60
|
+
}}>
|
|
61
|
+
<Chart />
|
|
64
62
|
</TradingProvider>
|
|
65
63
|
```
|
|
66
64
|
|
|
@@ -80,31 +78,31 @@ Unified toolbar that combines all trading controls in a single row. This is the
|
|
|
80
78
|
<TradingToolbar />
|
|
81
79
|
```
|
|
82
80
|
|
|
83
|
-
| Prop
|
|
84
|
-
|
|
85
|
-
| `showCoinSelector`
|
|
86
|
-
| `showVolumeControl`
|
|
87
|
-
| `showStopLoss`
|
|
88
|
-
| `showTakeProfit`
|
|
89
|
-
| `showDrawingTools`
|
|
90
|
-
| `showDividers`
|
|
91
|
-
| `volume`
|
|
92
|
-
| `onVolumeChange`
|
|
93
|
-
| `stopLoss`
|
|
94
|
-
| `onStopLossChange`
|
|
95
|
-
| `stopLossEnabled`
|
|
96
|
-
| `onStopLossEnabledChange`
|
|
97
|
-
| `takeProfit`
|
|
98
|
-
| `onTakeProfitChange`
|
|
99
|
-
| `takeProfitEnabled`
|
|
100
|
-
| `onTakeProfitEnabledChange` | `function` | -
|
|
101
|
-
| `coinSelectorProps`
|
|
102
|
-
| `volumeControlProps`
|
|
103
|
-
| `stopLossProps`
|
|
104
|
-
| `takeProfitProps`
|
|
105
|
-
| `drawingToolsProps`
|
|
106
|
-
| `style`
|
|
107
|
-
| `className`
|
|
81
|
+
| Prop | Type | Default | Description |
|
|
82
|
+
| --------------------------- | ---------- | ------- | ------------------------------ |
|
|
83
|
+
| `showCoinSelector` | `boolean` | `true` | Show/hide coin selector |
|
|
84
|
+
| `showVolumeControl` | `boolean` | `true` | Show/hide volume control |
|
|
85
|
+
| `showStopLoss` | `boolean` | `true` | Show/hide stop loss |
|
|
86
|
+
| `showTakeProfit` | `boolean` | `true` | Show/hide take profit |
|
|
87
|
+
| `showDrawingTools` | `boolean` | `true` | Show/hide drawing tools |
|
|
88
|
+
| `showDividers` | `boolean` | `true` | Show dividers between sections |
|
|
89
|
+
| `volume` | `number` | - | Controlled volume value |
|
|
90
|
+
| `onVolumeChange` | `function` | - | Volume change callback |
|
|
91
|
+
| `stopLoss` | `string` | - | Controlled stop loss value |
|
|
92
|
+
| `onStopLossChange` | `function` | - | Stop loss change callback |
|
|
93
|
+
| `stopLossEnabled` | `boolean` | - | Controlled SL toggle state |
|
|
94
|
+
| `onStopLossEnabledChange` | `function` | - | SL toggle callback |
|
|
95
|
+
| `takeProfit` | `string` | - | Controlled take profit value |
|
|
96
|
+
| `onTakeProfitChange` | `function` | - | Take profit change callback |
|
|
97
|
+
| `takeProfitEnabled` | `boolean` | - | Controlled TP toggle state |
|
|
98
|
+
| `onTakeProfitEnabledChange` | `function` | - | TP toggle callback |
|
|
99
|
+
| `coinSelectorProps` | `object` | `{}` | Props passed to CoinSelector |
|
|
100
|
+
| `volumeControlProps` | `object` | `{}` | Props passed to VolumeControl |
|
|
101
|
+
| `stopLossProps` | `object` | `{}` | Props passed to StopLoss |
|
|
102
|
+
| `takeProfitProps` | `object` | `{}` | Props passed to TakeProfit |
|
|
103
|
+
| `drawingToolsProps` | `object` | `{}` | Props passed to DrawingTools |
|
|
104
|
+
| `style` | `object` | - | Custom inline styles |
|
|
105
|
+
| `className` | `string` | - | Custom CSS class |
|
|
108
106
|
|
|
109
107
|
### CoinSelector
|
|
110
108
|
|
|
@@ -113,13 +111,13 @@ Searchable dropdown to select trading symbols. Symbols are categorized into Fore
|
|
|
113
111
|
```jsx
|
|
114
112
|
import { CoinSelector } from '@nabeeltahirdeveloper/chart-sdk'
|
|
115
113
|
|
|
116
|
-
|
|
114
|
+
;<CoinSelector />
|
|
117
115
|
```
|
|
118
116
|
|
|
119
|
-
| Prop
|
|
120
|
-
|
|
121
|
-
| `style`
|
|
122
|
-
| `className` | `string` | Custom CSS class
|
|
117
|
+
| Prop | Type | Description |
|
|
118
|
+
| ----------- | -------- | -------------------- |
|
|
119
|
+
| `style` | `object` | Custom inline styles |
|
|
120
|
+
| `className` | `string` | Custom CSS class |
|
|
123
121
|
|
|
124
122
|
### VolumeControl
|
|
125
123
|
|
|
@@ -136,19 +134,19 @@ const [volume, setVolume] = useState(0.1)
|
|
|
136
134
|
<VolumeControl value={volume} onChange={setVolume} />
|
|
137
135
|
```
|
|
138
136
|
|
|
139
|
-
| Prop
|
|
140
|
-
|
|
141
|
-
| `value`
|
|
142
|
-
| `onChange`
|
|
143
|
-
| `min`
|
|
144
|
-
| `max`
|
|
145
|
-
| `step`
|
|
146
|
-
| `presets`
|
|
147
|
-
| `showPresets` | `boolean`
|
|
148
|
-
| `showLabel`
|
|
149
|
-
| `label`
|
|
150
|
-
| `style`
|
|
151
|
-
| `className`
|
|
137
|
+
| Prop | Type | Default | Description |
|
|
138
|
+
| ------------- | ---------- | ----------------------------- | ----------------------------------------- |
|
|
139
|
+
| `value` | `number` | - | Controlled value |
|
|
140
|
+
| `onChange` | `function` | - | Change callback `(value: number) => void` |
|
|
141
|
+
| `min` | `number` | `0.01` | Minimum value |
|
|
142
|
+
| `max` | `number` | `100` | Maximum value |
|
|
143
|
+
| `step` | `number` | `0.01` | Step increment |
|
|
144
|
+
| `presets` | `number[]` | `[0.01, 0.05, 0.1, 0.5, 1.0]` | Preset buttons |
|
|
145
|
+
| `showPresets` | `boolean` | `true` | Show preset buttons |
|
|
146
|
+
| `showLabel` | `boolean` | `true` | Show "Vol" label |
|
|
147
|
+
| `label` | `string` | `"Vol"` | Custom label text |
|
|
148
|
+
| `style` | `object` | - | Custom inline styles |
|
|
149
|
+
| `className` | `string` | - | Custom CSS class |
|
|
152
150
|
|
|
153
151
|
### StopLoss
|
|
154
152
|
|
|
@@ -166,20 +164,20 @@ const [slEnabled, setSlEnabled] = useState(false)
|
|
|
166
164
|
<StopLoss value={sl} onChange={setSl} enabled={slEnabled} onEnabledChange={setSlEnabled} />
|
|
167
165
|
```
|
|
168
166
|
|
|
169
|
-
| Prop
|
|
170
|
-
|
|
171
|
-
| `value`
|
|
172
|
-
| `onChange`
|
|
173
|
-
| `enabled`
|
|
174
|
-
| `onEnabledChange` | `function` | -
|
|
175
|
-
| `mode`
|
|
176
|
-
| `onModeChange`
|
|
177
|
-
| `showToggle`
|
|
178
|
-
| `showModeSwitch`
|
|
179
|
-
| `showLabel`
|
|
180
|
-
| `label`
|
|
181
|
-
| `style`
|
|
182
|
-
| `className`
|
|
167
|
+
| Prop | Type | Default | Description |
|
|
168
|
+
| ----------------- | ---------- | ------- | -------------------------------------- |
|
|
169
|
+
| `value` | `string` | - | Controlled price/pips value |
|
|
170
|
+
| `onChange` | `function` | - | Value change callback |
|
|
171
|
+
| `enabled` | `boolean` | - | Controlled toggle state |
|
|
172
|
+
| `onEnabledChange` | `function` | - | Toggle callback |
|
|
173
|
+
| `mode` | `string` | - | Controlled mode: `"price"` or `"pips"` |
|
|
174
|
+
| `onModeChange` | `function` | - | Mode change callback |
|
|
175
|
+
| `showToggle` | `boolean` | `true` | Show on/off toggle |
|
|
176
|
+
| `showModeSwitch` | `boolean` | `true` | Show Price/Pips toggle |
|
|
177
|
+
| `showLabel` | `boolean` | `true` | Show "SL" label |
|
|
178
|
+
| `label` | `string` | `"SL"` | Custom label text |
|
|
179
|
+
| `style` | `object` | - | Custom inline styles |
|
|
180
|
+
| `className` | `string` | - | Custom CSS class |
|
|
183
181
|
|
|
184
182
|
### TakeProfit
|
|
185
183
|
|
|
@@ -197,20 +195,20 @@ const [tpEnabled, setTpEnabled] = useState(false)
|
|
|
197
195
|
<TakeProfit value={tp} onChange={setTp} enabled={tpEnabled} onEnabledChange={setTpEnabled} />
|
|
198
196
|
```
|
|
199
197
|
|
|
200
|
-
| Prop
|
|
201
|
-
|
|
202
|
-
| `value`
|
|
203
|
-
| `onChange`
|
|
204
|
-
| `enabled`
|
|
205
|
-
| `onEnabledChange` | `function` | -
|
|
206
|
-
| `mode`
|
|
207
|
-
| `onModeChange`
|
|
208
|
-
| `showToggle`
|
|
209
|
-
| `showModeSwitch`
|
|
210
|
-
| `showLabel`
|
|
211
|
-
| `label`
|
|
212
|
-
| `style`
|
|
213
|
-
| `className`
|
|
198
|
+
| Prop | Type | Default | Description |
|
|
199
|
+
| ----------------- | ---------- | ------- | -------------------------------------- |
|
|
200
|
+
| `value` | `string` | - | Controlled price/pips value |
|
|
201
|
+
| `onChange` | `function` | - | Value change callback |
|
|
202
|
+
| `enabled` | `boolean` | - | Controlled toggle state |
|
|
203
|
+
| `onEnabledChange` | `function` | - | Toggle callback |
|
|
204
|
+
| `mode` | `string` | - | Controlled mode: `"price"` or `"pips"` |
|
|
205
|
+
| `onModeChange` | `function` | - | Mode change callback |
|
|
206
|
+
| `showToggle` | `boolean` | `true` | Show on/off toggle |
|
|
207
|
+
| `showModeSwitch` | `boolean` | `true` | Show Price/Pips toggle |
|
|
208
|
+
| `showLabel` | `boolean` | `true` | Show "TP" label |
|
|
209
|
+
| `label` | `string` | `"TP"` | Custom label text |
|
|
210
|
+
| `style` | `object` | - | Custom inline styles |
|
|
211
|
+
| `className` | `string` | - | Custom CSS class |
|
|
214
212
|
|
|
215
213
|
### DrawingTools
|
|
216
214
|
|
|
@@ -221,17 +219,17 @@ Available tools: Crosshair, Trend Line, Parallel Channel, Fibonacci, Rectangle,
|
|
|
221
219
|
```jsx
|
|
222
220
|
import { DrawingTools } from '@nabeeltahirdeveloper/chart-sdk'
|
|
223
221
|
|
|
224
|
-
|
|
222
|
+
;<DrawingTools />
|
|
225
223
|
```
|
|
226
224
|
|
|
227
|
-
| Prop
|
|
228
|
-
|
|
229
|
-
| `showLabel`
|
|
230
|
-
| `showDelete`
|
|
231
|
-
| `showVisibility` | `boolean` | `true`
|
|
232
|
-
| `label`
|
|
233
|
-
| `style`
|
|
234
|
-
| `className`
|
|
225
|
+
| Prop | Type | Default | Description |
|
|
226
|
+
| ---------------- | --------- | -------- | ---------------------- |
|
|
227
|
+
| `showLabel` | `boolean` | `true` | Show "Draw" label |
|
|
228
|
+
| `showDelete` | `boolean` | `true` | Show delete all button |
|
|
229
|
+
| `showVisibility` | `boolean` | `true` | Show visibility toggle |
|
|
230
|
+
| `label` | `string` | `"Draw"` | Custom label text |
|
|
231
|
+
| `style` | `object` | - | Custom inline styles |
|
|
232
|
+
| `className` | `string` | - | Custom CSS class |
|
|
235
233
|
|
|
236
234
|
## Using Components Individually
|
|
237
235
|
|
|
@@ -239,41 +237,37 @@ Import and compose components however you like:
|
|
|
239
237
|
|
|
240
238
|
```jsx
|
|
241
239
|
import {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
240
|
+
TradingProvider,
|
|
241
|
+
Chart,
|
|
242
|
+
CoinSelector,
|
|
243
|
+
VolumeControl,
|
|
244
|
+
StopLoss,
|
|
245
|
+
TakeProfit,
|
|
246
|
+
DrawingTools,
|
|
249
247
|
} from '@nabeeltahirdeveloper/chart-sdk'
|
|
250
248
|
|
|
251
249
|
function App() {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
250
|
+
const [volume, setVolume] = useState(0.1)
|
|
251
|
+
|
|
252
|
+
return (
|
|
253
|
+
<TradingProvider baseUrl='https://your-api-url.com'>
|
|
254
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
|
|
255
|
+
<CoinSelector />
|
|
256
|
+
<VolumeControl value={volume} onChange={setVolume} />
|
|
257
|
+
<StopLoss />
|
|
258
|
+
<TakeProfit />
|
|
259
|
+
<DrawingTools />
|
|
260
|
+
</div>
|
|
261
|
+
<Chart />
|
|
262
|
+
</TradingProvider>
|
|
263
|
+
)
|
|
266
264
|
}
|
|
267
265
|
```
|
|
268
266
|
|
|
269
267
|
## Utilities
|
|
270
268
|
|
|
271
269
|
```jsx
|
|
272
|
-
import {
|
|
273
|
-
useTrading,
|
|
274
|
-
setChartBaseUrl,
|
|
275
|
-
setSocketBaseUrl,
|
|
276
|
-
} from '@nabeeltahirdeveloper/chart-sdk'
|
|
270
|
+
import { useTrading, setChartBaseUrl, setSocketBaseUrl } from '@nabeeltahirdeveloper/chart-sdk'
|
|
277
271
|
```
|
|
278
272
|
|
|
279
273
|
### useTrading()
|
|
@@ -282,26 +276,26 @@ React hook that returns the full trading context:
|
|
|
282
276
|
|
|
283
277
|
```jsx
|
|
284
278
|
const {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
279
|
+
selectedSymbol,
|
|
280
|
+
setSelectedSymbol,
|
|
281
|
+
selectedTimeframe,
|
|
282
|
+
setSelectedTimeframe,
|
|
283
|
+
symbols,
|
|
284
|
+
symbolsLoading,
|
|
285
|
+
orders,
|
|
286
|
+
userBalance,
|
|
287
|
+
activeTool,
|
|
288
|
+
setActiveTool,
|
|
289
|
+
chartObjects,
|
|
290
|
+
setChartObjects,
|
|
291
|
+
drawingsVisible,
|
|
292
|
+
setDrawingsVisible,
|
|
293
|
+
showGrid,
|
|
294
|
+
setShowGrid,
|
|
295
|
+
chartType,
|
|
296
|
+
setChartType,
|
|
297
|
+
currentSymbolData,
|
|
298
|
+
accountSummary,
|
|
305
299
|
} = useTrading()
|
|
306
300
|
```
|
|
307
301
|
|
package/package.json
CHANGED
|
@@ -1,50 +1,52 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
2
|
+
"name": "@nabeeltahirdeveloper/chart-sdk",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"main": "dist/chart-sdk.umd.js",
|
|
5
|
+
"module": "dist/chart-sdk.es.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/chart-sdk.es.js",
|
|
9
|
+
"require": "./dist/chart-sdk.umd.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
14
|
+
"build": "vite build",
|
|
15
|
+
"format": "prettier --write ."
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"chart",
|
|
19
|
+
"trading",
|
|
20
|
+
"candlestick",
|
|
21
|
+
"sdk",
|
|
22
|
+
"lightweight-charts",
|
|
23
|
+
"react"
|
|
24
|
+
],
|
|
25
|
+
"author": "nabeeltahirdeveloper",
|
|
26
|
+
"license": "ISC",
|
|
27
|
+
"description": "Chart SDK - TradingView-style chart component with real-time Binance data",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/nabeeltahirdeveloper/chart-sdk"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@vitejs/plugin-react": "^5.1.2",
|
|
38
|
+
"prettier": "^3.8.1",
|
|
39
|
+
"vite": "^7.3.1"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"axios": "^1.13.4",
|
|
43
|
+
"html2canvas": "^1.4.1",
|
|
44
|
+
"lightweight-charts": "^4.1.0",
|
|
45
|
+
"react-icons": "^5.5.0",
|
|
46
|
+
"socket.io-client": "^4.8.3"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"react": ">=17.0.0",
|
|
50
|
+
"react-dom": ">=17.0.0"
|
|
51
|
+
}
|
|
50
52
|
}
|