@nabeeltahirdeveloper/chart-sdk 1.1.0 → 1.2.0
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 +302 -0
- package/dist/chart-sdk.es.js +3548 -3049
- package/dist/chart-sdk.umd.js +6 -6
- package/package.json +5 -4
package/README.md
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
# @nabeeltahirdeveloper/chart-sdk
|
|
2
|
+
|
|
3
|
+
TradingView-style chart SDK for React with real-time data, trading controls, and drawing tools.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @nabeeltahirdeveloper/chart-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Peer Dependencies
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install react react-dom
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```jsx
|
|
20
|
+
import { TradingProvider, Chart, TradingToolbar } from '@nabeeltahirdeveloper/chart-sdk'
|
|
21
|
+
|
|
22
|
+
function App() {
|
|
23
|
+
return (
|
|
24
|
+
<TradingProvider baseUrl="https://your-api-url.com">
|
|
25
|
+
<TradingToolbar />
|
|
26
|
+
<Chart />
|
|
27
|
+
</TradingProvider>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Components
|
|
33
|
+
|
|
34
|
+
All components must be rendered inside a `<TradingProvider>`.
|
|
35
|
+
|
|
36
|
+
### TradingProvider
|
|
37
|
+
|
|
38
|
+
Wraps your app and provides trading state (symbols, prices, orders, drawing tools, etc).
|
|
39
|
+
|
|
40
|
+
```jsx
|
|
41
|
+
<TradingProvider baseUrl="https://your-api-url.com">
|
|
42
|
+
{children}
|
|
43
|
+
</TradingProvider>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| Prop | Type | Description |
|
|
47
|
+
|------|------|-------------|
|
|
48
|
+
| `baseUrl` | `string` | API server URL |
|
|
49
|
+
| `children` | `ReactNode` | Child components |
|
|
50
|
+
|
|
51
|
+
### Chart
|
|
52
|
+
|
|
53
|
+
Full-featured candlestick chart with real-time price updates, order lines, and drawing tools.
|
|
54
|
+
|
|
55
|
+
```jsx
|
|
56
|
+
<Chart />
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### TradingToolbar
|
|
60
|
+
|
|
61
|
+
Unified toolbar that combines all trading controls in a single row. This is the easiest way to add all controls at once.
|
|
62
|
+
|
|
63
|
+
```jsx
|
|
64
|
+
<TradingToolbar />
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
| Prop | Type | Default | Description |
|
|
68
|
+
|------|------|---------|-------------|
|
|
69
|
+
| `showCoinSelector` | `boolean` | `true` | Show/hide coin selector |
|
|
70
|
+
| `showVolumeControl` | `boolean` | `true` | Show/hide volume control |
|
|
71
|
+
| `showStopLoss` | `boolean` | `true` | Show/hide stop loss |
|
|
72
|
+
| `showTakeProfit` | `boolean` | `true` | Show/hide take profit |
|
|
73
|
+
| `showDrawingTools` | `boolean` | `true` | Show/hide drawing tools |
|
|
74
|
+
| `showDividers` | `boolean` | `true` | Show dividers between sections |
|
|
75
|
+
| `volume` | `number` | - | Controlled volume value |
|
|
76
|
+
| `onVolumeChange` | `function` | - | Volume change callback |
|
|
77
|
+
| `stopLoss` | `string` | - | Controlled stop loss value |
|
|
78
|
+
| `onStopLossChange` | `function` | - | Stop loss change callback |
|
|
79
|
+
| `stopLossEnabled` | `boolean` | - | Controlled SL toggle state |
|
|
80
|
+
| `onStopLossEnabledChange` | `function` | - | SL toggle callback |
|
|
81
|
+
| `takeProfit` | `string` | - | Controlled take profit value |
|
|
82
|
+
| `onTakeProfitChange` | `function` | - | Take profit change callback |
|
|
83
|
+
| `takeProfitEnabled` | `boolean` | - | Controlled TP toggle state |
|
|
84
|
+
| `onTakeProfitEnabledChange` | `function` | - | TP toggle callback |
|
|
85
|
+
| `coinSelectorProps` | `object` | `{}` | Props passed to CoinSelector |
|
|
86
|
+
| `volumeControlProps` | `object` | `{}` | Props passed to VolumeControl |
|
|
87
|
+
| `stopLossProps` | `object` | `{}` | Props passed to StopLoss |
|
|
88
|
+
| `takeProfitProps` | `object` | `{}` | Props passed to TakeProfit |
|
|
89
|
+
| `drawingToolsProps` | `object` | `{}` | Props passed to DrawingTools |
|
|
90
|
+
| `style` | `object` | - | Custom inline styles |
|
|
91
|
+
| `className` | `string` | - | Custom CSS class |
|
|
92
|
+
|
|
93
|
+
### CoinSelector
|
|
94
|
+
|
|
95
|
+
Searchable dropdown to select trading symbols. Symbols are categorized into Forex/Metals and Crypto. Reads from `TradingContext` automatically.
|
|
96
|
+
|
|
97
|
+
```jsx
|
|
98
|
+
import { CoinSelector } from '@nabeeltahirdeveloper/chart-sdk'
|
|
99
|
+
|
|
100
|
+
<CoinSelector />
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
| Prop | Type | Description |
|
|
104
|
+
|------|------|-------------|
|
|
105
|
+
| `style` | `object` | Custom inline styles |
|
|
106
|
+
| `className` | `string` | Custom CSS class |
|
|
107
|
+
|
|
108
|
+
### VolumeControl
|
|
109
|
+
|
|
110
|
+
Numeric input with increment/decrement buttons and preset lot-size chips. Works as controlled or uncontrolled component.
|
|
111
|
+
|
|
112
|
+
```jsx
|
|
113
|
+
import { VolumeControl } from '@nabeeltahirdeveloper/chart-sdk'
|
|
114
|
+
|
|
115
|
+
// Uncontrolled (manages its own state)
|
|
116
|
+
<VolumeControl />
|
|
117
|
+
|
|
118
|
+
// Controlled
|
|
119
|
+
const [volume, setVolume] = useState(0.1)
|
|
120
|
+
<VolumeControl value={volume} onChange={setVolume} />
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
| Prop | Type | Default | Description |
|
|
124
|
+
|------|------|---------|-------------|
|
|
125
|
+
| `value` | `number` | - | Controlled value |
|
|
126
|
+
| `onChange` | `function` | - | Change callback `(value: number) => void` |
|
|
127
|
+
| `min` | `number` | `0.01` | Minimum value |
|
|
128
|
+
| `max` | `number` | `100` | Maximum value |
|
|
129
|
+
| `step` | `number` | `0.01` | Step increment |
|
|
130
|
+
| `presets` | `number[]` | `[0.01, 0.05, 0.1, 0.5, 1.0]` | Preset buttons |
|
|
131
|
+
| `showPresets` | `boolean` | `true` | Show preset buttons |
|
|
132
|
+
| `showLabel` | `boolean` | `true` | Show "Vol" label |
|
|
133
|
+
| `label` | `string` | `"Vol"` | Custom label text |
|
|
134
|
+
| `style` | `object` | - | Custom inline styles |
|
|
135
|
+
| `className` | `string` | - | Custom CSS class |
|
|
136
|
+
|
|
137
|
+
### StopLoss
|
|
138
|
+
|
|
139
|
+
Stop loss input with toggle switch and price/pips mode. Red themed.
|
|
140
|
+
|
|
141
|
+
```jsx
|
|
142
|
+
import { StopLoss } from '@nabeeltahirdeveloper/chart-sdk'
|
|
143
|
+
|
|
144
|
+
// Uncontrolled
|
|
145
|
+
<StopLoss />
|
|
146
|
+
|
|
147
|
+
// Controlled
|
|
148
|
+
const [sl, setSl] = useState('')
|
|
149
|
+
const [slEnabled, setSlEnabled] = useState(false)
|
|
150
|
+
<StopLoss value={sl} onChange={setSl} enabled={slEnabled} onEnabledChange={setSlEnabled} />
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
| Prop | Type | Default | Description |
|
|
154
|
+
|------|------|---------|-------------|
|
|
155
|
+
| `value` | `string` | - | Controlled price/pips value |
|
|
156
|
+
| `onChange` | `function` | - | Value change callback |
|
|
157
|
+
| `enabled` | `boolean` | - | Controlled toggle state |
|
|
158
|
+
| `onEnabledChange` | `function` | - | Toggle callback |
|
|
159
|
+
| `mode` | `string` | - | Controlled mode: `"price"` or `"pips"` |
|
|
160
|
+
| `onModeChange` | `function` | - | Mode change callback |
|
|
161
|
+
| `showToggle` | `boolean` | `true` | Show on/off toggle |
|
|
162
|
+
| `showModeSwitch` | `boolean` | `true` | Show Price/Pips toggle |
|
|
163
|
+
| `showLabel` | `boolean` | `true` | Show "SL" label |
|
|
164
|
+
| `label` | `string` | `"SL"` | Custom label text |
|
|
165
|
+
| `style` | `object` | - | Custom inline styles |
|
|
166
|
+
| `className` | `string` | - | Custom CSS class |
|
|
167
|
+
|
|
168
|
+
### TakeProfit
|
|
169
|
+
|
|
170
|
+
Take profit input with toggle switch and price/pips mode. Green themed. Same API as StopLoss.
|
|
171
|
+
|
|
172
|
+
```jsx
|
|
173
|
+
import { TakeProfit } from '@nabeeltahirdeveloper/chart-sdk'
|
|
174
|
+
|
|
175
|
+
// Uncontrolled
|
|
176
|
+
<TakeProfit />
|
|
177
|
+
|
|
178
|
+
// Controlled
|
|
179
|
+
const [tp, setTp] = useState('')
|
|
180
|
+
const [tpEnabled, setTpEnabled] = useState(false)
|
|
181
|
+
<TakeProfit value={tp} onChange={setTp} enabled={tpEnabled} onEnabledChange={setTpEnabled} />
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
| Prop | Type | Default | Description |
|
|
185
|
+
|------|------|---------|-------------|
|
|
186
|
+
| `value` | `string` | - | Controlled price/pips value |
|
|
187
|
+
| `onChange` | `function` | - | Value change callback |
|
|
188
|
+
| `enabled` | `boolean` | - | Controlled toggle state |
|
|
189
|
+
| `onEnabledChange` | `function` | - | Toggle callback |
|
|
190
|
+
| `mode` | `string` | - | Controlled mode: `"price"` or `"pips"` |
|
|
191
|
+
| `onModeChange` | `function` | - | Mode change callback |
|
|
192
|
+
| `showToggle` | `boolean` | `true` | Show on/off toggle |
|
|
193
|
+
| `showModeSwitch` | `boolean` | `true` | Show Price/Pips toggle |
|
|
194
|
+
| `showLabel` | `boolean` | `true` | Show "TP" label |
|
|
195
|
+
| `label` | `string` | `"TP"` | Custom label text |
|
|
196
|
+
| `style` | `object` | - | Custom inline styles |
|
|
197
|
+
| `className` | `string` | - | Custom CSS class |
|
|
198
|
+
|
|
199
|
+
### DrawingTools
|
|
200
|
+
|
|
201
|
+
Toolbar with chart drawing tool buttons. Wired to chart context automatically.
|
|
202
|
+
|
|
203
|
+
Available tools: Crosshair, Trend Line, Parallel Channel, Fibonacci, Rectangle, Price Level.
|
|
204
|
+
|
|
205
|
+
```jsx
|
|
206
|
+
import { DrawingTools } from '@nabeeltahirdeveloper/chart-sdk'
|
|
207
|
+
|
|
208
|
+
<DrawingTools />
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
| Prop | Type | Default | Description |
|
|
212
|
+
|------|------|---------|-------------|
|
|
213
|
+
| `showLabel` | `boolean` | `true` | Show "Draw" label |
|
|
214
|
+
| `showDelete` | `boolean` | `true` | Show delete all button |
|
|
215
|
+
| `showVisibility` | `boolean` | `true` | Show visibility toggle |
|
|
216
|
+
| `label` | `string` | `"Draw"` | Custom label text |
|
|
217
|
+
| `style` | `object` | - | Custom inline styles |
|
|
218
|
+
| `className` | `string` | - | Custom CSS class |
|
|
219
|
+
|
|
220
|
+
## Using Components Individually
|
|
221
|
+
|
|
222
|
+
Import and compose components however you like:
|
|
223
|
+
|
|
224
|
+
```jsx
|
|
225
|
+
import {
|
|
226
|
+
TradingProvider,
|
|
227
|
+
Chart,
|
|
228
|
+
CoinSelector,
|
|
229
|
+
VolumeControl,
|
|
230
|
+
StopLoss,
|
|
231
|
+
TakeProfit,
|
|
232
|
+
DrawingTools,
|
|
233
|
+
} from '@nabeeltahirdeveloper/chart-sdk'
|
|
234
|
+
|
|
235
|
+
function App() {
|
|
236
|
+
const [volume, setVolume] = useState(0.1)
|
|
237
|
+
|
|
238
|
+
return (
|
|
239
|
+
<TradingProvider baseUrl="https://your-api-url.com">
|
|
240
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
|
|
241
|
+
<CoinSelector />
|
|
242
|
+
<VolumeControl value={volume} onChange={setVolume} />
|
|
243
|
+
<StopLoss />
|
|
244
|
+
<TakeProfit />
|
|
245
|
+
<DrawingTools />
|
|
246
|
+
</div>
|
|
247
|
+
<Chart />
|
|
248
|
+
</TradingProvider>
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Utilities
|
|
254
|
+
|
|
255
|
+
```jsx
|
|
256
|
+
import {
|
|
257
|
+
useTrading,
|
|
258
|
+
setChartBaseUrl,
|
|
259
|
+
setSocketBaseUrl,
|
|
260
|
+
} from '@nabeeltahirdeveloper/chart-sdk'
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### useTrading()
|
|
264
|
+
|
|
265
|
+
React hook that returns the full trading context:
|
|
266
|
+
|
|
267
|
+
```jsx
|
|
268
|
+
const {
|
|
269
|
+
selectedSymbol,
|
|
270
|
+
setSelectedSymbol,
|
|
271
|
+
selectedTimeframe,
|
|
272
|
+
setSelectedTimeframe,
|
|
273
|
+
symbols,
|
|
274
|
+
symbolsLoading,
|
|
275
|
+
orders,
|
|
276
|
+
userBalance,
|
|
277
|
+
activeTool,
|
|
278
|
+
setActiveTool,
|
|
279
|
+
chartObjects,
|
|
280
|
+
setChartObjects,
|
|
281
|
+
drawingsVisible,
|
|
282
|
+
setDrawingsVisible,
|
|
283
|
+
showGrid,
|
|
284
|
+
setShowGrid,
|
|
285
|
+
chartType,
|
|
286
|
+
setChartType,
|
|
287
|
+
currentSymbolData,
|
|
288
|
+
accountSummary,
|
|
289
|
+
} = useTrading()
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### setChartBaseUrl(url)
|
|
293
|
+
|
|
294
|
+
Set the base URL for chart API requests.
|
|
295
|
+
|
|
296
|
+
### setSocketBaseUrl(url)
|
|
297
|
+
|
|
298
|
+
Set the base URL for WebSocket connections.
|
|
299
|
+
|
|
300
|
+
## License
|
|
301
|
+
|
|
302
|
+
ISC
|