@orderly.network/hooks 1.1.9 → 1.2.0-alpha.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.
@@ -0,0 +1,33 @@
1
+ export interface RawOrderBook {
2
+ asks: [number, number][];
3
+ bids: [number, number][];
4
+ ts: number;
5
+ }
6
+ export interface RawOrderBookUpdate {
7
+ asks: [number, number][];
8
+ bids: [number, number][];
9
+ prevTs: number;
10
+ ts: number;
11
+ }
12
+ export declare const defaultRawOrderBook: RawOrderBook;
13
+ declare class OrderbookService {
14
+ private static instance;
15
+ private bufferedOrderBookUpdates;
16
+ private rawOrderBook;
17
+ constructor();
18
+ static getInstance(): OrderbookService;
19
+ private sortBufferedOrderBookUpdates;
20
+ private applyUpdateToRawOrderBook;
21
+ private applyBufferedUpdatesToRawOrderBooks;
22
+ private deleteBufferedOrderBookUpdates;
23
+ private commitOrderBook;
24
+ private pushUpdateToBuffer;
25
+ private isValidFullOrderBook;
26
+ setFullOrderbook(symbol: string, rawOrderbook: RawOrderBook): void;
27
+ updateOrderbook(symbol: string, update: RawOrderBookUpdate, callback: () => void): void;
28
+ getRawOrderbook(symbol: string): RawOrderBook;
29
+ resetOrderBook(symbol: string): void;
30
+ }
31
+ declare const orderBookService: OrderbookService;
32
+ export default orderBookService;
33
+ //# sourceMappingURL=orderbook.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orderbook.service.d.ts","sourceRoot":"","sources":["../../src/orderly/orderbook.service.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACzB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACzB,EAAE,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IAC/B,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACzB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,mBAAmB,EAAE,YAIjC,CAAC;AAEF,cAAM,gBAAgB;IAClB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAmB;IAC1C,OAAO,CAAC,wBAAwB,CAAkD;IAClF,OAAO,CAAC,YAAY,CAA0C;;IAK9D,MAAM,CAAC,WAAW;IAOlB,OAAO,CAAC,4BAA4B;IAIpC,OAAO,CAAC,yBAAyB;IAqBjC,OAAO,CAAC,mCAAmC;IAI3C,OAAO,CAAC,8BAA8B;IAItC,OAAO,CAAC,eAAe;IAsBvB,OAAO,CAAC,kBAAkB;IAgB1B,OAAO,CAAC,oBAAoB;IAU5B,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY;IAY3D,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,IAAI;IAwBhF,eAAe,CAAC,MAAM,EAAE,MAAM;IAIvB,cAAc,CAAC,MAAM,EAAE,MAAM;CAOvC;AAED,QAAA,MAAM,gBAAgB,kBAAiC,CAAC;AAExD,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,118 @@
1
+ export const defaultRawOrderBook = {
2
+ asks: [],
3
+ bids: [],
4
+ ts: 0,
5
+ };
6
+ class OrderbookService {
7
+ constructor() {
8
+ this.bufferedOrderBookUpdates = {};
9
+ this.rawOrderBook = {};
10
+ }
11
+ static getInstance() {
12
+ if (!this.instance) {
13
+ this.instance = new OrderbookService();
14
+ }
15
+ return this.instance;
16
+ }
17
+ sortBufferedOrderBookUpdates(symbol) {
18
+ this.bufferedOrderBookUpdates[symbol]?.sort((a, b) => a.ts - b.ts);
19
+ }
20
+ applyUpdateToRawOrderBook(symbol, update) {
21
+ const rawOrderBook = this.rawOrderBook[symbol];
22
+ if (!rawOrderBook || rawOrderBook.ts > update.prevTs) {
23
+ return;
24
+ }
25
+ const askMap = new Map();
26
+ const bidMap = new Map();
27
+ rawOrderBook.asks.forEach((ask) => askMap.set(ask[0], ask[1]));
28
+ rawOrderBook.bids.forEach((bid) => bidMap.set(bid[0], bid[1]));
29
+ update.asks.forEach((ask) => (ask[1] === 0 ? askMap.delete(ask[0]) : askMap.set(ask[0], ask[1])));
30
+ update.bids.forEach((bid) => (bid[1] === 0 ? bidMap.delete(bid[0]) : bidMap.set(bid[0], bid[1])));
31
+ rawOrderBook.asks = Array.from(askMap.entries()).sort((a, b) => a[0] - b[0]);
32
+ rawOrderBook.bids = Array.from(bidMap.entries()).sort((a, b) => b[0] - a[0]);
33
+ rawOrderBook.ts = update.ts;
34
+ }
35
+ applyBufferedUpdatesToRawOrderBooks(symbol) {
36
+ this.bufferedOrderBookUpdates[symbol]?.forEach((update) => this.applyUpdateToRawOrderBook(symbol, update));
37
+ }
38
+ deleteBufferedOrderBookUpdates(symbol) {
39
+ delete this.bufferedOrderBookUpdates[symbol];
40
+ }
41
+ commitOrderBook(symbol) {
42
+ const rawOrderBook = this.rawOrderBook[symbol];
43
+ if (!rawOrderBook) {
44
+ return;
45
+ }
46
+ // const orderbook = this.prepareOrderBookStore(rawOrderBook);
47
+ // if (orderbook.firstAskPrice <= orderbook.firstBidPrice) {
48
+ // console.error(SERVICE_PREFIX, 'Orderbook crossing error', { crossedAsks: orderbook.asks, crossedBids: orderbook.bids });
49
+ //
50
+ // this.rawOrderBook[symbol] = {
51
+ // ...defaultRawOrderBook,
52
+ // ts: -1, // must be -1 because it needs to cause Orderbook version error in public websocket
53
+ // };
54
+ // } else {
55
+ // orderBookStore.update(symbol, orderbook);
56
+ // depthChartService.commitDepthChart(symbol);
57
+ // }
58
+ }
59
+ pushUpdateToBuffer(symbol, update) {
60
+ if (this.bufferedOrderBookUpdates[symbol] === undefined) {
61
+ this.bufferedOrderBookUpdates[symbol] = [];
62
+ }
63
+ const buffer = this.bufferedOrderBookUpdates[symbol];
64
+ if (buffer.length > 0) {
65
+ const lastUpdate = buffer[buffer.length - 1];
66
+ if (lastUpdate.ts !== update.prevTs) {
67
+ this.bufferedOrderBookUpdates[symbol] = [];
68
+ }
69
+ }
70
+ this.bufferedOrderBookUpdates[symbol].push(update);
71
+ }
72
+ isValidFullOrderBook(symbol, currentTs) {
73
+ if ((this.bufferedOrderBookUpdates[symbol]?.length ?? 0) !== 0) {
74
+ const earliestUpdates = this.bufferedOrderBookUpdates[symbol][0];
75
+ // Incoming full orderbook is invalid if the timestamp is less than all of our buffered diff orderbook updates.
76
+ return earliestUpdates.prevTs <= currentTs;
77
+ }
78
+ return true;
79
+ }
80
+ setFullOrderbook(symbol, rawOrderbook) {
81
+ const { ts } = rawOrderbook;
82
+ this.rawOrderBook[symbol] = rawOrderbook;
83
+ this.sortBufferedOrderBookUpdates(symbol);
84
+ if (this.isValidFullOrderBook(symbol, ts)) {
85
+ this.applyBufferedUpdatesToRawOrderBooks(symbol);
86
+ }
87
+ }
88
+ ;
89
+ updateOrderbook(symbol, update, callback) {
90
+ const { asks, bids, prevTs, ts } = update;
91
+ const rawOrderBook = this.rawOrderBook[symbol];
92
+ if (!rawOrderBook) {
93
+ return;
94
+ }
95
+ const currentTs = rawOrderBook.ts;
96
+ if (currentTs === 0) {
97
+ this.pushUpdateToBuffer(symbol, { asks, bids, prevTs, ts });
98
+ return;
99
+ }
100
+ if (prevTs !== currentTs) {
101
+ this.pushUpdateToBuffer(symbol, { asks, bids, prevTs, ts });
102
+ if (callback) {
103
+ callback();
104
+ }
105
+ return;
106
+ }
107
+ this.applyUpdateToRawOrderBook(symbol, update);
108
+ this.deleteBufferedOrderBookUpdates(symbol);
109
+ }
110
+ getRawOrderbook(symbol) {
111
+ return this.rawOrderBook[symbol];
112
+ }
113
+ resetOrderBook(symbol) {
114
+ this.rawOrderBook[symbol] = defaultRawOrderBook;
115
+ }
116
+ }
117
+ const orderBookService = OrderbookService.getInstance();
118
+ export default orderBookService;
@@ -340,6 +340,7 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
340
340
  formattedOrder.order_quantity,
341
341
  formattedOrder.total,
342
342
  formattedOrder.trigger_price,
343
+ formattedOrder.order_type,
343
344
  markPrice,
344
345
  ]);
345
346
  //====== update orderbook ask0/bid0 ======
@@ -1 +1 @@
1
- {"version":3,"file":"useOrderbookStream.d.ts","sourceRoot":"","sources":["../../src/orderly/useOrderbookStream.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC;AAErC,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,aAAa,EAAE,CAAC;IACtB,IAAI,EAAE,aAAa,EAAE,CAAC;CACvB,CAAC;AAyFF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UACnB,MAAM,GAAG,SAAS,SAClB,MAAM,WACJ,OAAO,QACV,aAAa,KAClB,aAyDF,CAAC;AAgCF,eAAO,MAAM,cAAc,SAAU,aAAa,UAAU,aAAa;;;CAWxE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAIF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,WACrB,MAAM,YACL,aAAa,YACZ,gBAAgB;;;;;;;;;;;2BAgIgB,MAAM;;;;;;;;;IAmDjD,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
1
+ {"version":3,"file":"useOrderbookStream.d.ts","sourceRoot":"","sources":["../../src/orderly/useOrderbookStream.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC;AAErC,MAAM,MAAM,aAAa,GAAG;IACxB,IAAI,EAAE,aAAa,EAAE,CAAC;IACtB,IAAI,EAAE,aAAa,EAAE,CAAC;CACzB,CAAC;AAyFF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UACjB,MAAM,GAAG,SAAS,SAClB,MAAM,WACJ,OAAO,QACV,aAAa,KACpB,aAyDF,CAAC;AAgCF,eAAO,MAAM,cAAc,SAAU,aAAa,UAAU,aAAa;;;CAWxE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAIF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,WACnB,MAAM,YACL,aAAa,YACZ,gBAAgB;;;;;;;;;;;2BA8GgB,MAAM;;;;;;;;;IAmDnD,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
@@ -7,6 +7,7 @@ import { useSymbolsInfo } from "./useSymbolsInfo";
7
7
  import { Decimal } from "@orderly.network/utils";
8
8
  import { min } from "ramda";
9
9
  import { SDKError } from "@orderly.network/types";
10
+ import orderbooksService from './orderbook.service';
10
11
  const paddingFn = (len) => Array(len).fill([Number.NaN, Number.NaN, Number.NaN, Number.NaN]);
11
12
  const asksSortFn = (a, b) => a[0] - b[0];
12
13
  const bidsSortFn = (a, b) => b[0] - a[0];
@@ -202,74 +203,54 @@ export const useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
202
203
  const eventEmitter = useEventEmitter();
203
204
  // const orderbookRequest =
204
205
  useEffect(() => {
206
+ let needRequestFullOrderbook = true;
205
207
  setIsLoading(true);
206
- let ignore = false;
207
- ws.onceSubscribe({
208
- event: "request",
209
- id: `${symbol}@orderbook`,
210
- params: {
211
- type: "orderbook",
212
- symbol: symbol,
213
- },
208
+ let orderBookUpdateSub;
209
+ let fullOrderBookUpdateSub;
210
+ orderBookUpdateSub = ws.subscribe({
211
+ event: "subscribe",
212
+ topic: `${symbol}@orderbookupdate`,
214
213
  }, {
214
+ formatter: (message) => message,
215
215
  onMessage: (message) => {
216
- if (ignore)
217
- return;
218
- //
219
- if (!!message) {
220
- // sort and filter qty > 0
221
- let bids = [...message.bids.sort(bidsSortFn)];
222
- bids = bids.filter((item) => !isNaN(item[0]) && item[1] > 0);
223
- let asks = [...message.asks.sort(asksSortFn)];
224
- asks = asks.filter((item) => !isNaN(item[0]) && item[1] > 0);
225
- // const reduceOrderbookData = reduceOrderbook(depth, level, {
226
- // bids: bids,
227
- // asks: asks,
228
- // });
229
- setRequestData({ bids: bids, asks: asks });
230
- setData({ bids: [...bids], asks: [...asks] });
231
- }
232
- setIsLoading(false);
233
- },
216
+ const { data: wsData, ts } = message;
217
+ const { asks, bids, prevTs } = wsData;
218
+ orderbooksService.updateOrderbook(symbol, { asks, bids, ts, prevTs }, () => needRequestFullOrderbook = true);
219
+ const data = orderbooksService.getRawOrderbook(symbol);
220
+ setData({ bids: data.bids, asks: data.asks });
221
+ }
234
222
  });
223
+ if (needRequestFullOrderbook) {
224
+ setIsLoading(true);
225
+ fullOrderBookUpdateSub = ws.onceSubscribe({
226
+ event: "request",
227
+ id: `${symbol}@orderbook`,
228
+ params: {
229
+ type: "orderbook",
230
+ symbol: symbol,
231
+ },
232
+ }, {
233
+ formatter: (message) => message,
234
+ onMessage: (message) => {
235
+ const { symbol, asks, bids, ts } = message.data;
236
+ orderbooksService.setFullOrderbook(symbol, { asks, bids, ts });
237
+ const data = orderbooksService.getRawOrderbook(symbol);
238
+ setData({ bids: data.bids, asks: data.asks });
239
+ setIsLoading(false);
240
+ },
241
+ });
242
+ needRequestFullOrderbook = false;
243
+ }
235
244
  return () => {
236
- setRequestData(null);
237
- ignore = true;
238
- // clean the data;
245
+ // unsubscribe
246
+ orderBookUpdateSub?.();
247
+ fullOrderBookUpdateSub?.();
248
+ orderbooksService.resetOrderBook(symbol);
239
249
  setData(INIT_DATA);
240
- prevMiddlePrice.current = 0;
241
250
  };
242
251
  }, [symbol]);
243
252
  // const {data:markPrices} = useMarkPricesStream();
244
253
  const { data: markPrice } = useMarkPrice(symbol);
245
- useEffect(() => {
246
- if (!requestData)
247
- return;
248
- let ignore = false;
249
- const subscription = ws.subscribe({
250
- event: "subscribe",
251
- topic: `${symbol}@orderbookupdate`,
252
- }, {
253
- onMessage: (message) => {
254
- //
255
- if (ignore)
256
- return;
257
- setData((data) => {
258
- const mergedData = !message.asks && !message.bids
259
- ? data
260
- : mergeOrderbook(data, message);
261
- return mergedData;
262
- // const reducedData = reduceOrderbook(depth, level, mergedData);
263
- // return reducedData;
264
- });
265
- },
266
- });
267
- return () => {
268
- ignore = true;
269
- prevMiddlePrice.current = 0;
270
- subscription?.(); //unsubscribe
271
- };
272
- }, [symbol, requestData]);
273
254
  const onItemClick = useCallback((item) => {
274
255
  eventEmitter.emit("orderbook:item:click", item);
275
256
  }, []);
@@ -277,10 +258,22 @@ export const useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
277
258
  //
278
259
  setDepth(() => depth);
279
260
  }, []);
261
+ const reducedData = reduceOrderbook(depth, level, padding, {
262
+ asks: [...data.asks],
263
+ bids: [...data.bids],
264
+ });
265
+ // emit the asks0 and bids0
266
+ useEffect(() => {
267
+ const updateData = [
268
+ reducedData.asks?.[reducedData.asks.length - 1]?.[0],
269
+ reducedData.bids?.[0]?.[0]
270
+ ];
271
+ eventEmitter.emit("orderbook:update", updateData);
272
+ }, [reducedData.asks?.[reducedData.asks.length - 1]?.[0], reducedData.bids?.[0]?.[0]]);
280
273
  const middlePrice = useMemo(() => {
281
274
  let asksFrist = 0, bidsFirst = 0;
282
275
  if (data.asks.length > 0) {
283
- asksFrist = data.asks[0][0];
276
+ asksFrist = reducedData.asks?.[reducedData.asks.length - 1]?.[0];
284
277
  }
285
278
  if (data.bids.length > 0) {
286
279
  bidsFirst = data.bids[0][0];
@@ -292,18 +285,6 @@ export const useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
292
285
  useEffect(() => {
293
286
  prevMiddlePrice.current = middlePrice;
294
287
  }, [middlePrice]);
295
- const reducedData = reduceOrderbook(depth, level, padding, {
296
- asks: [...data.asks],
297
- bids: [...data.bids],
298
- });
299
- // emit the asks0 and bids0
300
- useEffect(() => {
301
- const updateData = [
302
- reducedData.asks?.[reducedData.asks.length - 1]?.[0],
303
- reducedData.bids?.[0]?.[0]
304
- ];
305
- eventEmitter.emit("orderbook:update", updateData);
306
- }, [reducedData.asks?.[reducedData.asks.length - 1]?.[0], reducedData.bids?.[0]?.[0]]);
307
288
  return [
308
289
  {
309
290
  asks: reducedData.asks.slice(-level),
@@ -1 +1 @@
1
- {"version":3,"file":"dataPaint.d.ts","sourceRoot":"","sources":["../../../src/services/painter/dataPaint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAc,MAAM,aAAa,CAAC;AAGjE,qBAAa,SAAU,SAAQ,SAAS;IACtC,OAAO,CAAC,qBAAqB,CAAO;IAEpC,OAAO,CAAC,oBAAoB,CAAoB;IAChD,OAAO,CAAC,kBAAkB,CAAsB;IAEhD,OAAO,CAAC,YAAY,CAAK;IAEnB,IAAI,CAAC,OAAO,EAAE,WAAW;IAoC/B,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,YAAY;IA2EpB,OAAO,CAAC,iBAAiB;IAyEzB,OAAO,CAAC,gBAAgB;IAoCxB,OAAO,CAAC,aAAa;IAmBrB,OAAO,CAAC,gBAAgB;IAoBxB,OAAO,CAAC,SAAS;IAuCjB,OAAO,CAAC,MAAM;CAGf"}
1
+ {"version":3,"file":"dataPaint.d.ts","sourceRoot":"","sources":["../../../src/services/painter/dataPaint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAc,MAAM,aAAa,CAAC;AAGjE,qBAAa,SAAU,SAAQ,SAAS;IACtC,OAAO,CAAC,qBAAqB,CAAO;IAEpC,OAAO,CAAC,oBAAoB,CAAoB;IAChD,OAAO,CAAC,kBAAkB,CAAsB;IAEhD,OAAO,CAAC,YAAY,CAAK;IAEnB,IAAI,CAAC,OAAO,EAAE,WAAW;IAsC/B,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,YAAY;IA2EpB,OAAO,CAAC,iBAAiB;IAyEzB,OAAO,CAAC,gBAAgB;IAuCxB,OAAO,CAAC,aAAa;IAmBrB,OAAO,CAAC,gBAAgB;IAsBxB,OAAO,CAAC,SAAS;IAuCjB,OAAO,CAAC,MAAM;CAGf"}
@@ -12,10 +12,12 @@ export class DataPaint extends BasePaint {
12
12
  async draw(options) {
13
13
  const needDrawDetails = Array.isArray(options.data?.position?.informations) &&
14
14
  (options.data?.position?.informations?.length ?? 0) > 0;
15
- const hasMessage = !!options.data?.message;
15
+ // const hasMessage = !!options.data?.message;
16
+ const hasMessage = true;
16
17
  this.transformTop = hasMessage ? 0 : needDrawDetails ? -40 : -150;
17
18
  // If position details are not displayed, the position PNL information will be margin
18
- const offsetTop = hasMessage ? 50 : 100;
19
+ // const offsetTop = hasMessage ? 50 : 100;
20
+ const offsetTop = 100;
19
21
  // const offsetMessage = hasMessage ? 0 : -50;
20
22
  if (!!options.data?.message) {
21
23
  this.drawMessage(options);
@@ -164,8 +166,11 @@ export class DataPaint extends BasePaint {
164
166
  const isVertical = (options.data?.position.informations.length ?? 0) === 2;
165
167
  options.data?.position.informations.forEach((info, index) => {
166
168
  // let cellWidth = this.positionInfoCellWidth;
167
- let left = position.left + this.positionInfoCellWidth * Math.floor(index / 2);
168
- let top = position.top + (index % 2) * 38 + this.transformTop;
169
+ let left = position.left + (index % 2) * this.positionInfoCellWidth;
170
+ // let top = (position.top as number) + (index / 2) * 38 + this.transformTop;
171
+ let top = position.top +
172
+ Math.floor(index / 2) * 38 +
173
+ this.transformTop;
169
174
  this._drawText(info.title, {
170
175
  left: this._ratio(left),
171
176
  top: this._ratio(top),
@@ -201,7 +206,8 @@ export class DataPaint extends BasePaint {
201
206
  const layout = path(["layout", "updateTime"], options);
202
207
  const { position } = layout;
203
208
  const top = this.painter.height - position.bottom;
204
- const left = this.painter.width - position.right;
209
+ const left = position.left;
210
+ console.log("*******", left, top, options.data?.updateTime);
205
211
  this._drawText(options.data?.updateTime, {
206
212
  left: this._ratio(left),
207
213
  top: this._ratio(top),
@@ -5,7 +5,7 @@ export const DefaultLayoutConfig = {
5
5
  textBaseline: "bottom",
6
6
  position: {
7
7
  left: 20,
8
- bottom: 17,
8
+ bottom: 32,
9
9
  },
10
10
  },
11
11
  message: {
@@ -46,11 +46,11 @@ export const DefaultLayoutConfig = {
46
46
  },
47
47
  updateTime: {
48
48
  fontSize: 10,
49
- color: "rgba(255,255,255,0.5)",
50
- textAlign: "end",
49
+ color: "rgba(255,255,255,0.3)",
50
+ // textAlign: "end",
51
51
  textBaseline: "bottom",
52
52
  position: {
53
- right: 20,
53
+ left: 20,
54
54
  bottom: 17,
55
55
  },
56
56
  },
@@ -1 +1 @@
1
- {"version":3,"file":"createOrder.d.ts","sourceRoot":"","sources":["../../src/utils/createOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,GAAG,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAK1E,MAAM,MAAM,YAAY,GAAG;KACxB,CAAC,IAAI,MAAM,WAAW,CAAC,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;CAC7D,CAAC;AACF,MAAM,MAAM,eAAe,GAAG,IAAI,CAChC,WAAW,EACX,aAAa,GAAG,gBAAgB,GAAG,OAAO,CAC3C,CAAC;AAEF,KAAK,eAAe,GAAG;IAErB,MAAM,EAAE,GAAG,CAAC,SAAS,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,KAAK,WAAW,CAAC;IACvE,QAAQ,EAAE,CACR,MAAM,EAAE,eAAe,EACvB,OA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e,EACvB,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,YAAY,CAAC;CA+DzB;AACD,qBAAa,sBAAuB,SAAQ,iBAAiB;IAC3D,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,EAAE,eAAe,GAAG,WAAW;IAsB5D,QAAQ,CACN,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,YAAY,CAAC;CAgBzB;AAED,qBAAa,mBAAoB,SAAQ,gBAAgB;IACvD,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW;IAOtC,QAAQ,CACN,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,YAAY,CAAC;CAGzB;AAED,eAAO,MAAM,mBAAmB,aAQ/B,CAAC;AAEF,qBAAa,YAAY;IACvB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,IAAI;CA0BpD"}
@@ -98,7 +98,10 @@ export class LimitOrderCreator extends BaseOrderCreator {
98
98
  delete order['total'];
99
99
  delete order['trigger_price'];
100
100
  delete order['isStopOrder'];
101
- console.log("create", order);
101
+ const { quote_dp } = config.symbol;
102
+ if (values.order_price) {
103
+ order["order_price"] = new Decimal(Number.parseFloat(values.order_price.toString())).toFixed(quote_dp, Decimal.ROUND_DOWN);
104
+ }
102
105
  return order;
103
106
  }
104
107
  validate(values, config) {
@@ -186,6 +189,13 @@ export class StopLimitOrderCreator extends LimitOrderCreator {
186
189
  // @ts-ignore
187
190
  delete order["isStopOrder"];
188
191
  delete order['total'];
192
+ const { quote_dp } = config.symbol;
193
+ if (values.order_price) {
194
+ order["order_price"] = new Decimal(Number.parseFloat(values.order_price.toString())).toFixed(quote_dp, Decimal.ROUND_DOWN);
195
+ }
196
+ if (values.trigger_price) {
197
+ order["trigger_price"] = new Decimal(Number.parseFloat(values.trigger_price.toString())).toFixed(quote_dp, Decimal.ROUND_DOWN);
198
+ }
189
199
  return order;
190
200
  }
191
201
  validate(values, config) {
package/esm/version.d.ts CHANGED
@@ -5,6 +5,6 @@ declare global {
5
5
  };
6
6
  }
7
7
  }
8
- declare const _default: "1.1.9";
8
+ declare const _default: "1.2.0-alpha.0";
9
9
  export default _default;
10
10
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,mBAAmB,CAAC,EAAE;YAClB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;SACzB,CAAC;KACL;CACJ;;AAMD,wBAAuB"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,mBAAmB,CAAC,EAAE;YAClB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;SACzB,CAAC;KACL;CACJ;;AAMD,wBAA+B"}
package/esm/version.js CHANGED
@@ -1,6 +1,6 @@
1
1
  if (typeof window !== 'undefined') {
2
2
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
3
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.1.9";
3
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.2.0-alpha.0";
4
4
  }
5
5
  ;
6
- export default "1.1.9";
6
+ export default "1.2.0-alpha.0";
@@ -0,0 +1,33 @@
1
+ export interface RawOrderBook {
2
+ asks: [number, number][];
3
+ bids: [number, number][];
4
+ ts: number;
5
+ }
6
+ export interface RawOrderBookUpdate {
7
+ asks: [number, number][];
8
+ bids: [number, number][];
9
+ prevTs: number;
10
+ ts: number;
11
+ }
12
+ export declare const defaultRawOrderBook: RawOrderBook;
13
+ declare class OrderbookService {
14
+ private static instance;
15
+ private bufferedOrderBookUpdates;
16
+ private rawOrderBook;
17
+ constructor();
18
+ static getInstance(): OrderbookService;
19
+ private sortBufferedOrderBookUpdates;
20
+ private applyUpdateToRawOrderBook;
21
+ private applyBufferedUpdatesToRawOrderBooks;
22
+ private deleteBufferedOrderBookUpdates;
23
+ private commitOrderBook;
24
+ private pushUpdateToBuffer;
25
+ private isValidFullOrderBook;
26
+ setFullOrderbook(symbol: string, rawOrderbook: RawOrderBook): void;
27
+ updateOrderbook(symbol: string, update: RawOrderBookUpdate, callback: () => void): void;
28
+ getRawOrderbook(symbol: string): RawOrderBook;
29
+ resetOrderBook(symbol: string): void;
30
+ }
31
+ declare const orderBookService: OrderbookService;
32
+ export default orderBookService;
33
+ //# sourceMappingURL=orderbook.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orderbook.service.d.ts","sourceRoot":"","sources":["../../src/orderly/orderbook.service.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACzB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACzB,EAAE,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IAC/B,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACzB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,mBAAmB,EAAE,YAIjC,CAAC;AAEF,cAAM,gBAAgB;IAClB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAmB;IAC1C,OAAO,CAAC,wBAAwB,CAAkD;IAClF,OAAO,CAAC,YAAY,CAA0C;;IAK9D,MAAM,CAAC,WAAW;IAOlB,OAAO,CAAC,4BAA4B;IAIpC,OAAO,CAAC,yBAAyB;IAqBjC,OAAO,CAAC,mCAAmC;IAI3C,OAAO,CAAC,8BAA8B;IAItC,OAAO,CAAC,eAAe;IAsBvB,OAAO,CAAC,kBAAkB;IAgB1B,OAAO,CAAC,oBAAoB;IAU5B,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY;IAY3D,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,IAAI;IAwBhF,eAAe,CAAC,MAAM,EAAE,MAAM;IAIvB,cAAc,CAAC,MAAM,EAAE,MAAM;CAOvC;AAED,QAAA,MAAM,gBAAgB,kBAAiC,CAAC;AAExD,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultRawOrderBook = void 0;
4
+ exports.defaultRawOrderBook = {
5
+ asks: [],
6
+ bids: [],
7
+ ts: 0,
8
+ };
9
+ class OrderbookService {
10
+ constructor() {
11
+ this.bufferedOrderBookUpdates = {};
12
+ this.rawOrderBook = {};
13
+ }
14
+ static getInstance() {
15
+ if (!this.instance) {
16
+ this.instance = new OrderbookService();
17
+ }
18
+ return this.instance;
19
+ }
20
+ sortBufferedOrderBookUpdates(symbol) {
21
+ this.bufferedOrderBookUpdates[symbol]?.sort((a, b) => a.ts - b.ts);
22
+ }
23
+ applyUpdateToRawOrderBook(symbol, update) {
24
+ const rawOrderBook = this.rawOrderBook[symbol];
25
+ if (!rawOrderBook || rawOrderBook.ts > update.prevTs) {
26
+ return;
27
+ }
28
+ const askMap = new Map();
29
+ const bidMap = new Map();
30
+ rawOrderBook.asks.forEach((ask) => askMap.set(ask[0], ask[1]));
31
+ rawOrderBook.bids.forEach((bid) => bidMap.set(bid[0], bid[1]));
32
+ update.asks.forEach((ask) => (ask[1] === 0 ? askMap.delete(ask[0]) : askMap.set(ask[0], ask[1])));
33
+ update.bids.forEach((bid) => (bid[1] === 0 ? bidMap.delete(bid[0]) : bidMap.set(bid[0], bid[1])));
34
+ rawOrderBook.asks = Array.from(askMap.entries()).sort((a, b) => a[0] - b[0]);
35
+ rawOrderBook.bids = Array.from(bidMap.entries()).sort((a, b) => b[0] - a[0]);
36
+ rawOrderBook.ts = update.ts;
37
+ }
38
+ applyBufferedUpdatesToRawOrderBooks(symbol) {
39
+ this.bufferedOrderBookUpdates[symbol]?.forEach((update) => this.applyUpdateToRawOrderBook(symbol, update));
40
+ }
41
+ deleteBufferedOrderBookUpdates(symbol) {
42
+ delete this.bufferedOrderBookUpdates[symbol];
43
+ }
44
+ commitOrderBook(symbol) {
45
+ const rawOrderBook = this.rawOrderBook[symbol];
46
+ if (!rawOrderBook) {
47
+ return;
48
+ }
49
+ // const orderbook = this.prepareOrderBookStore(rawOrderBook);
50
+ // if (orderbook.firstAskPrice <= orderbook.firstBidPrice) {
51
+ // console.error(SERVICE_PREFIX, 'Orderbook crossing error', { crossedAsks: orderbook.asks, crossedBids: orderbook.bids });
52
+ //
53
+ // this.rawOrderBook[symbol] = {
54
+ // ...defaultRawOrderBook,
55
+ // ts: -1, // must be -1 because it needs to cause Orderbook version error in public websocket
56
+ // };
57
+ // } else {
58
+ // orderBookStore.update(symbol, orderbook);
59
+ // depthChartService.commitDepthChart(symbol);
60
+ // }
61
+ }
62
+ pushUpdateToBuffer(symbol, update) {
63
+ if (this.bufferedOrderBookUpdates[symbol] === undefined) {
64
+ this.bufferedOrderBookUpdates[symbol] = [];
65
+ }
66
+ const buffer = this.bufferedOrderBookUpdates[symbol];
67
+ if (buffer.length > 0) {
68
+ const lastUpdate = buffer[buffer.length - 1];
69
+ if (lastUpdate.ts !== update.prevTs) {
70
+ this.bufferedOrderBookUpdates[symbol] = [];
71
+ }
72
+ }
73
+ this.bufferedOrderBookUpdates[symbol].push(update);
74
+ }
75
+ isValidFullOrderBook(symbol, currentTs) {
76
+ if ((this.bufferedOrderBookUpdates[symbol]?.length ?? 0) !== 0) {
77
+ const earliestUpdates = this.bufferedOrderBookUpdates[symbol][0];
78
+ // Incoming full orderbook is invalid if the timestamp is less than all of our buffered diff orderbook updates.
79
+ return earliestUpdates.prevTs <= currentTs;
80
+ }
81
+ return true;
82
+ }
83
+ setFullOrderbook(symbol, rawOrderbook) {
84
+ const { ts } = rawOrderbook;
85
+ this.rawOrderBook[symbol] = rawOrderbook;
86
+ this.sortBufferedOrderBookUpdates(symbol);
87
+ if (this.isValidFullOrderBook(symbol, ts)) {
88
+ this.applyBufferedUpdatesToRawOrderBooks(symbol);
89
+ }
90
+ }
91
+ ;
92
+ updateOrderbook(symbol, update, callback) {
93
+ const { asks, bids, prevTs, ts } = update;
94
+ const rawOrderBook = this.rawOrderBook[symbol];
95
+ if (!rawOrderBook) {
96
+ return;
97
+ }
98
+ const currentTs = rawOrderBook.ts;
99
+ if (currentTs === 0) {
100
+ this.pushUpdateToBuffer(symbol, { asks, bids, prevTs, ts });
101
+ return;
102
+ }
103
+ if (prevTs !== currentTs) {
104
+ this.pushUpdateToBuffer(symbol, { asks, bids, prevTs, ts });
105
+ if (callback) {
106
+ callback();
107
+ }
108
+ return;
109
+ }
110
+ this.applyUpdateToRawOrderBook(symbol, update);
111
+ this.deleteBufferedOrderBookUpdates(symbol);
112
+ }
113
+ getRawOrderbook(symbol) {
114
+ return this.rawOrderBook[symbol];
115
+ }
116
+ resetOrderBook(symbol) {
117
+ this.rawOrderBook[symbol] = exports.defaultRawOrderBook;
118
+ }
119
+ }
120
+ const orderBookService = OrderbookService.getInstance();
121
+ exports.default = orderBookService;
@@ -343,6 +343,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
343
343
  formattedOrder.order_quantity,
344
344
  formattedOrder.total,
345
345
  formattedOrder.trigger_price,
346
+ formattedOrder.order_type,
346
347
  markPrice,
347
348
  ]);
348
349
  //====== update orderbook ask0/bid0 ======
@@ -1 +1 @@
1
- {"version":3,"file":"useOrderbookStream.d.ts","sourceRoot":"","sources":["../../src/orderly/useOrderbookStream.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,aAAa,GAAG,MA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ACH,eAAO,MAAM,kBAAkB,WACnB,MAAM,YACL,aAAa,YACZ,gBAAgB;;;;;;;;;;;2BA8GgB,MAAM;;;;;;;;;IAmDnD,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.useOrderbookStream = exports.mergeOrderbook = exports.reduceOrderbook = void 0;
4
7
  const react_1 = require("react");
@@ -10,6 +13,7 @@ const useSymbolsInfo_1 = require("./useSymbolsInfo");
10
13
  const utils_1 = require("@orderly.network/utils");
11
14
  const ramda_1 = require("ramda");
12
15
  const types_1 = require("@orderly.network/types");
16
+ const orderbook_service_1 = __importDefault(require("./orderbook.service"));
13
17
  const paddingFn = (len) => Array(len).fill([Number.NaN, Number.NaN, Number.NaN, Number.NaN]);
14
18
  const asksSortFn = (a, b) => a[0] - b[0];
15
19
  const bidsSortFn = (a, b) => b[0] - a[0];
@@ -207,74 +211,54 @@ const useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
207
211
  const eventEmitter = (0, useEventEmitter_1.useEventEmitter)();
208
212
  // const orderbookRequest =
209
213
  (0, react_1.useEffect)(() => {
214
+ let needRequestFullOrderbook = true;
210
215
  setIsLoading(true);
211
- let ignore = false;
212
- ws.onceSubscribe({
213
- event: "request",
214
- id: `${symbol}@orderbook`,
215
- params: {
216
- type: "orderbook",
217
- symbol: symbol,
218
- },
216
+ let orderBookUpdateSub;
217
+ let fullOrderBookUpdateSub;
218
+ orderBookUpdateSub = ws.subscribe({
219
+ event: "subscribe",
220
+ topic: `${symbol}@orderbookupdate`,
219
221
  }, {
222
+ formatter: (message) => message,
220
223
  onMessage: (message) => {
221
- if (ignore)
222
- return;
223
- //
224
- if (!!message) {
225
- // sort and filter qty > 0
226
- let bids = [...message.bids.sort(bidsSortFn)];
227
- bids = bids.filter((item) => !isNaN(item[0]) && item[1] > 0);
228
- let asks = [...message.asks.sort(asksSortFn)];
229
- asks = asks.filter((item) => !isNaN(item[0]) && item[1] > 0);
230
- // const reduceOrderbookData = reduceOrderbook(depth, level, {
231
- // bids: bids,
232
- // asks: asks,
233
- // });
234
- setRequestData({ bids: bids, asks: asks });
235
- setData({ bids: [...bids], asks: [...asks] });
236
- }
237
- setIsLoading(false);
238
- },
224
+ const { data: wsData, ts } = message;
225
+ const { asks, bids, prevTs } = wsData;
226
+ orderbook_service_1.default.updateOrderbook(symbol, { asks, bids, ts, prevTs }, () => needRequestFullOrderbook = true);
227
+ const data = orderbook_service_1.default.getRawOrderbook(symbol);
228
+ setData({ bids: data.bids, asks: data.asks });
229
+ }
239
230
  });
231
+ if (needRequestFullOrderbook) {
232
+ setIsLoading(true);
233
+ fullOrderBookUpdateSub = ws.onceSubscribe({
234
+ event: "request",
235
+ id: `${symbol}@orderbook`,
236
+ params: {
237
+ type: "orderbook",
238
+ symbol: symbol,
239
+ },
240
+ }, {
241
+ formatter: (message) => message,
242
+ onMessage: (message) => {
243
+ const { symbol, asks, bids, ts } = message.data;
244
+ orderbook_service_1.default.setFullOrderbook(symbol, { asks, bids, ts });
245
+ const data = orderbook_service_1.default.getRawOrderbook(symbol);
246
+ setData({ bids: data.bids, asks: data.asks });
247
+ setIsLoading(false);
248
+ },
249
+ });
250
+ needRequestFullOrderbook = false;
251
+ }
240
252
  return () => {
241
- setRequestData(null);
242
- ignore = true;
243
- // clean the data;
253
+ // unsubscribe
254
+ orderBookUpdateSub?.();
255
+ fullOrderBookUpdateSub?.();
256
+ orderbook_service_1.default.resetOrderBook(symbol);
244
257
  setData(INIT_DATA);
245
- prevMiddlePrice.current = 0;
246
258
  };
247
259
  }, [symbol]);
248
260
  // const {data:markPrices} = useMarkPricesStream();
249
261
  const { data: markPrice } = (0, useMarkPrice_1.useMarkPrice)(symbol);
250
- (0, react_1.useEffect)(() => {
251
- if (!requestData)
252
- return;
253
- let ignore = false;
254
- const subscription = ws.subscribe({
255
- event: "subscribe",
256
- topic: `${symbol}@orderbookupdate`,
257
- }, {
258
- onMessage: (message) => {
259
- //
260
- if (ignore)
261
- return;
262
- setData((data) => {
263
- const mergedData = !message.asks && !message.bids
264
- ? data
265
- : (0, exports.mergeOrderbook)(data, message);
266
- return mergedData;
267
- // const reducedData = reduceOrderbook(depth, level, mergedData);
268
- // return reducedData;
269
- });
270
- },
271
- });
272
- return () => {
273
- ignore = true;
274
- prevMiddlePrice.current = 0;
275
- subscription?.(); //unsubscribe
276
- };
277
- }, [symbol, requestData]);
278
262
  const onItemClick = (0, react_1.useCallback)((item) => {
279
263
  eventEmitter.emit("orderbook:item:click", item);
280
264
  }, []);
@@ -282,10 +266,22 @@ const useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
282
266
  //
283
267
  setDepth(() => depth);
284
268
  }, []);
269
+ const reducedData = (0, exports.reduceOrderbook)(depth, level, padding, {
270
+ asks: [...data.asks],
271
+ bids: [...data.bids],
272
+ });
273
+ // emit the asks0 and bids0
274
+ (0, react_1.useEffect)(() => {
275
+ const updateData = [
276
+ reducedData.asks?.[reducedData.asks.length - 1]?.[0],
277
+ reducedData.bids?.[0]?.[0]
278
+ ];
279
+ eventEmitter.emit("orderbook:update", updateData);
280
+ }, [reducedData.asks?.[reducedData.asks.length - 1]?.[0], reducedData.bids?.[0]?.[0]]);
285
281
  const middlePrice = (0, react_1.useMemo)(() => {
286
282
  let asksFrist = 0, bidsFirst = 0;
287
283
  if (data.asks.length > 0) {
288
- asksFrist = data.asks[0][0];
284
+ asksFrist = reducedData.asks?.[reducedData.asks.length - 1]?.[0];
289
285
  }
290
286
  if (data.bids.length > 0) {
291
287
  bidsFirst = data.bids[0][0];
@@ -297,18 +293,6 @@ const useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
297
293
  (0, react_1.useEffect)(() => {
298
294
  prevMiddlePrice.current = middlePrice;
299
295
  }, [middlePrice]);
300
- const reducedData = (0, exports.reduceOrderbook)(depth, level, padding, {
301
- asks: [...data.asks],
302
- bids: [...data.bids],
303
- });
304
- // emit the asks0 and bids0
305
- (0, react_1.useEffect)(() => {
306
- const updateData = [
307
- reducedData.asks?.[reducedData.asks.length - 1]?.[0],
308
- reducedData.bids?.[0]?.[0]
309
- ];
310
- eventEmitter.emit("orderbook:update", updateData);
311
- }, [reducedData.asks?.[reducedData.asks.length - 1]?.[0], reducedData.bids?.[0]?.[0]]);
312
296
  return [
313
297
  {
314
298
  asks: reducedData.asks.slice(-level),
@@ -1 +1 @@
1
- {"version":3,"file":"dataPaint.d.ts","sourceRoot":"","sources":["../../../src/services/painter/dataPaint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAc,MAAM,aAAa,CAAC;AAGjE,qBAAa,SAAU,SAAQ,SAAS;IACtC,OAAO,CAAC,qBAAqB,CAAO;IAEpC,OAAO,CAAC,oBAAoB,CAAoB;IAChD,OAAO,CAAC,kBAAkB,CAAsB;IAEhD,OAAO,CAAC,YAAY,CAAK;IAEnB,IAAI,CAAC,OAAO,EAAE,WAAW;IAoC/B,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,YAAY;IA2EpB,OAAO,CAAC,iBAAiB;IAyEzB,OAAO,CAAC,gBAAgB;IAoCxB,OAAO,CAAC,aAAa;IAmBrB,OAAO,CAAC,gBAAgB;IAoBxB,OAAO,CAAC,SAAS;IAuCjB,OAAO,CAAC,MAAM;CAGf"}
1
+ {"version":3,"file":"dataPaint.d.ts","sourceRoot":"","sources":["../../../src/services/painter/dataPaint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAc,MAAM,aAAa,CAAC;AAGjE,qBAAa,SAAU,SAAQ,SAAS;IACtC,OAAO,CAAC,qBAAqB,CAAO;IAEpC,OAAO,CAAC,oBAAoB,CAAoB;IAChD,OAAO,CAAC,kBAAkB,CAAsB;IAEhD,OAAO,CAAC,YAAY,CAAK;IAEnB,IAAI,CAAC,OAAO,EAAE,WAAW;IAsC/B,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,YAAY;IA2EpB,OAAO,CAAC,iBAAiB;IAyEzB,OAAO,CAAC,gBAAgB;IAuCxB,OAAO,CAAC,aAAa;IAmBrB,OAAO,CAAC,gBAAgB;IAsBxB,OAAO,CAAC,SAAS;IAuCjB,OAAO,CAAC,MAAM;CAGf"}
@@ -15,10 +15,12 @@ class DataPaint extends basePaint_1.BasePaint {
15
15
  async draw(options) {
16
16
  const needDrawDetails = Array.isArray(options.data?.position?.informations) &&
17
17
  (options.data?.position?.informations?.length ?? 0) > 0;
18
- const hasMessage = !!options.data?.message;
18
+ // const hasMessage = !!options.data?.message;
19
+ const hasMessage = true;
19
20
  this.transformTop = hasMessage ? 0 : needDrawDetails ? -40 : -150;
20
21
  // If position details are not displayed, the position PNL information will be margin
21
- const offsetTop = hasMessage ? 50 : 100;
22
+ // const offsetTop = hasMessage ? 50 : 100;
23
+ const offsetTop = 100;
22
24
  // const offsetMessage = hasMessage ? 0 : -50;
23
25
  if (!!options.data?.message) {
24
26
  this.drawMessage(options);
@@ -167,8 +169,11 @@ class DataPaint extends basePaint_1.BasePaint {
167
169
  const isVertical = (options.data?.position.informations.length ?? 0) === 2;
168
170
  options.data?.position.informations.forEach((info, index) => {
169
171
  // let cellWidth = this.positionInfoCellWidth;
170
- let left = position.left + this.positionInfoCellWidth * Math.floor(index / 2);
171
- let top = position.top + (index % 2) * 38 + this.transformTop;
172
+ let left = position.left + (index % 2) * this.positionInfoCellWidth;
173
+ // let top = (position.top as number) + (index / 2) * 38 + this.transformTop;
174
+ let top = position.top +
175
+ Math.floor(index / 2) * 38 +
176
+ this.transformTop;
172
177
  this._drawText(info.title, {
173
178
  left: this._ratio(left),
174
179
  top: this._ratio(top),
@@ -204,7 +209,8 @@ class DataPaint extends basePaint_1.BasePaint {
204
209
  const layout = (0, ramda_1.path)(["layout", "updateTime"], options);
205
210
  const { position } = layout;
206
211
  const top = this.painter.height - position.bottom;
207
- const left = this.painter.width - position.right;
212
+ const left = position.left;
213
+ console.log("*******", left, top, options.data?.updateTime);
208
214
  this._drawText(options.data?.updateTime, {
209
215
  left: this._ratio(left),
210
216
  top: this._ratio(top),
@@ -8,7 +8,7 @@ exports.DefaultLayoutConfig = {
8
8
  textBaseline: "bottom",
9
9
  position: {
10
10
  left: 20,
11
- bottom: 17,
11
+ bottom: 32,
12
12
  },
13
13
  },
14
14
  message: {
@@ -49,11 +49,11 @@ exports.DefaultLayoutConfig = {
49
49
  },
50
50
  updateTime: {
51
51
  fontSize: 10,
52
- color: "rgba(255,255,255,0.5)",
53
- textAlign: "end",
52
+ color: "rgba(255,255,255,0.3)",
53
+ // textAlign: "end",
54
54
  textBaseline: "bottom",
55
55
  position: {
56
- right: 20,
56
+ left: 20,
57
57
  bottom: 17,
58
58
  },
59
59
  },
@@ -1 +1 @@
1
- {"version":3,"file":"createOrder.d.ts","sourceRoot":"","sources":["../../src/utils/createOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,GAAG,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAK1E,MAAM,MAAM,YAAY,GAAG;KACxB,CAAC,IAAI,MAAM,WAAW,CAAC,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;CAC7D,CAAC;AACF,MAAM,MAAM,eAAe,GAAG,IAAI,CAChC,WAAW,EACX,aAAa,GAAG,gBAAgB,GAAG,OAAO,CAC3C,CAAC;AAEF,KAAK,eAAe,GAAG;IAErB,MAAM,EAAE,GAAG,CAAC,SAAS,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO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AE,WAAW,EAAE,MAAM,EAAE,eAAe,GAAG,WAAW;IA+BjE,QAAQ,CACN,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,YAAY,CAAC;CA+DzB;AACD,qBAAa,sBAAuB,SAAQ,iBAAiB;IAC3D,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,EAAE,eAAe,GAAG,WAAW;IAsB5D,QAAQ,CACN,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,YAAY,CAAC;CAgBzB;AAED,qBAAa,mBAAoB,SAAQ,gBAAgB;IACvD,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW;IAOtC,QAAQ,CACN,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,YAAY,CAAC;CAGzB;AAED,eAAO,MAAM,mBAAmB,aAQ/B,CAAC;AAEF,qBAAa,YAAY;IACvB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,IAAI;CA0BpD"}
@@ -102,7 +102,10 @@ class LimitOrderCreator extends BaseOrderCreator {
102
102
  delete order['total'];
103
103
  delete order['trigger_price'];
104
104
  delete order['isStopOrder'];
105
- console.log("create", order);
105
+ const { quote_dp } = config.symbol;
106
+ if (values.order_price) {
107
+ order["order_price"] = new utils_1.Decimal(Number.parseFloat(values.order_price.toString())).toFixed(quote_dp, utils_1.Decimal.ROUND_DOWN);
108
+ }
106
109
  return order;
107
110
  }
108
111
  validate(values, config) {
@@ -195,6 +198,13 @@ class StopLimitOrderCreator extends LimitOrderCreator {
195
198
  // @ts-ignore
196
199
  delete order["isStopOrder"];
197
200
  delete order['total'];
201
+ const { quote_dp } = config.symbol;
202
+ if (values.order_price) {
203
+ order["order_price"] = new utils_1.Decimal(Number.parseFloat(values.order_price.toString())).toFixed(quote_dp, utils_1.Decimal.ROUND_DOWN);
204
+ }
205
+ if (values.trigger_price) {
206
+ order["trigger_price"] = new utils_1.Decimal(Number.parseFloat(values.trigger_price.toString())).toFixed(quote_dp, utils_1.Decimal.ROUND_DOWN);
207
+ }
198
208
  return order;
199
209
  }
200
210
  validate(values, config) {
package/lib/version.d.ts CHANGED
@@ -5,6 +5,6 @@ declare global {
5
5
  };
6
6
  }
7
7
  }
8
- declare const _default: "1.1.9";
8
+ declare const _default: "1.2.0-alpha.0";
9
9
  export default _default;
10
10
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,mBAAmB,CAAC,EAAE;YAClB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;SACzB,CAAC;KACL;CACJ;;AAMD,wBAAuB"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,mBAAmB,CAAC,EAAE;YAClB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;SACzB,CAAC;KACL;CACJ;;AAMD,wBAA+B"}
package/lib/version.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  if (typeof window !== 'undefined') {
4
4
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
5
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.1.9";
5
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.2.0-alpha.0";
6
6
  }
7
7
  ;
8
- exports.default = "1.1.9";
8
+ exports.default = "1.2.0-alpha.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orderly.network/hooks",
3
- "version": "1.1.9",
3
+ "version": "1.2.0-alpha.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -34,11 +34,11 @@
34
34
  "swr": "^2.2.4",
35
35
  "use-constant": "^1.1.1",
36
36
  "use-debounce": "^9.0.4",
37
- "@orderly.network/core": "0.2.8",
38
- "@orderly.network/net": "1.1.8",
39
- "@orderly.network/perp": "2.0.8",
40
- "@orderly.network/types": "0.2.8",
41
- "@orderly.network/utils": "0.1.8"
37
+ "@orderly.network/core": "1.2.0-alpha.0",
38
+ "@orderly.network/net": "1.2.0-alpha.0",
39
+ "@orderly.network/types": "1.2.0-alpha.0",
40
+ "@orderly.network/utils": "1.2.0-alpha.0",
41
+ "@orderly.network/perp": "3.0.0-alpha.0"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public"