@evedex/exchange-api 1.0.32

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.
Files changed (44) hide show
  1. package/README.md +1 -0
  2. package/dist/cjs/authRestGateway.d.ts +63 -0
  3. package/dist/cjs/authRestGateway.js +96 -0
  4. package/dist/cjs/exchangeRestGateway.d.ts +91 -0
  5. package/dist/cjs/exchangeRestGateway.js +202 -0
  6. package/dist/cjs/exchangeWsGateway.d.ts +142 -0
  7. package/dist/cjs/exchangeWsGateway.js +146 -0
  8. package/dist/cjs/index.d.ts +4 -0
  9. package/dist/cjs/index.js +43 -0
  10. package/dist/cjs/package.json +3 -0
  11. package/dist/cjs/utils/exchange.d.ts +59 -0
  12. package/dist/cjs/utils/exchange.js +82 -0
  13. package/dist/cjs/utils/http.d.ts +26 -0
  14. package/dist/cjs/utils/http.js +28 -0
  15. package/dist/cjs/utils/index.d.ts +5 -0
  16. package/dist/cjs/utils/index.js +21 -0
  17. package/dist/cjs/utils/signal.d.ts +9 -0
  18. package/dist/cjs/utils/signal.js +24 -0
  19. package/dist/cjs/utils/types.d.ts +306 -0
  20. package/dist/cjs/utils/types.js +37 -0
  21. package/dist/cjs/utils/ws.d.ts +15 -0
  22. package/dist/cjs/utils/ws.js +2 -0
  23. package/dist/mjs/authRestGateway.d.ts +63 -0
  24. package/dist/mjs/authRestGateway.js +93 -0
  25. package/dist/mjs/exchangeRestGateway.d.ts +91 -0
  26. package/dist/mjs/exchangeRestGateway.js +205 -0
  27. package/dist/mjs/exchangeWsGateway.d.ts +142 -0
  28. package/dist/mjs/exchangeWsGateway.js +144 -0
  29. package/dist/mjs/index.d.ts +4 -0
  30. package/dist/mjs/index.js +4 -0
  31. package/dist/mjs/package.json +3 -0
  32. package/dist/mjs/utils/exchange.d.ts +59 -0
  33. package/dist/mjs/utils/exchange.js +81 -0
  34. package/dist/mjs/utils/http.d.ts +26 -0
  35. package/dist/mjs/utils/http.js +24 -0
  36. package/dist/mjs/utils/index.d.ts +5 -0
  37. package/dist/mjs/utils/index.js +5 -0
  38. package/dist/mjs/utils/signal.d.ts +9 -0
  39. package/dist/mjs/utils/signal.js +20 -0
  40. package/dist/mjs/utils/types.d.ts +306 -0
  41. package/dist/mjs/utils/types.js +34 -0
  42. package/dist/mjs/utils/ws.d.ts +15 -0
  43. package/dist/mjs/utils/ws.js +1 -0
  44. package/package.json +72 -0
@@ -0,0 +1,205 @@
1
+ import { serializeQueryParams, } from "./utils";
2
+ export var InstrumentListQueryField;
3
+ (function (InstrumentListQueryField) {
4
+ InstrumentListQueryField["Metrics"] = "metrics";
5
+ })(InstrumentListQueryField || (InstrumentListQueryField = {}));
6
+ export class ExchangeRestGateway {
7
+ options;
8
+ constructor(options) {
9
+ this.options = options;
10
+ }
11
+ url(path, search) {
12
+ const url = new URL(this.options.exchangeURI);
13
+ url.pathname = path;
14
+ if (search) {
15
+ url.search = search;
16
+ }
17
+ return url.toString();
18
+ }
19
+ get(path, search) {
20
+ return this.options.httpClient
21
+ .request({
22
+ method: "GET",
23
+ url: this.url(path, search),
24
+ headers: { Accept: "application/json" },
25
+ })
26
+ .then((res) => res.data);
27
+ }
28
+ authGet(path, search) {
29
+ return this.options.httpClient
30
+ .authRequest({
31
+ method: "GET",
32
+ url: this.url(path, search),
33
+ headers: { Accept: "application/json" },
34
+ })
35
+ .then((res) => res.data);
36
+ }
37
+ authPost(path, body) {
38
+ return this.options.httpClient
39
+ .authRequest({
40
+ method: "POST",
41
+ url: this.url(path),
42
+ headers: {
43
+ Accept: "application/json",
44
+ "Content-Type": "application/json",
45
+ },
46
+ body: JSON.stringify(body),
47
+ })
48
+ .then((res) => res.data);
49
+ }
50
+ authPut(path, body) {
51
+ return this.options.httpClient
52
+ .authRequest({
53
+ method: "PUT",
54
+ url: this.url(path),
55
+ headers: {
56
+ Accept: "application/json",
57
+ "Content-Type": "application/json",
58
+ },
59
+ body: JSON.stringify(body),
60
+ })
61
+ .then((res) => res.data);
62
+ }
63
+ authDelete(path) {
64
+ return this.options.httpClient
65
+ .authRequest({
66
+ method: "DELETE",
67
+ url: this.url(path),
68
+ headers: { Accept: "application/json" },
69
+ })
70
+ .then((res) => res.data);
71
+ }
72
+ // Getters
73
+ // Market
74
+ getMarketInfo() {
75
+ return this.get("/api/market");
76
+ }
77
+ getMarketDepth(init) {
78
+ return this.get(`/api/market/${init.instrument}/deep`, serializeQueryParams({
79
+ maxLevel: init.maxLevel,
80
+ roundPrice: init.roundPrice,
81
+ }));
82
+ }
83
+ getTrades(init) {
84
+ return this.get(`/api/market/${init.instrument}/trades`);
85
+ }
86
+ getRecentTrades(init) {
87
+ return this.get(`/api/market/${init.instrument}/recent-trades`);
88
+ }
89
+ // User
90
+ me() {
91
+ return this.authGet("/api/user/me");
92
+ }
93
+ getDxFeedAuthToken() {
94
+ return this.authGet("/api/dx-feed/auth");
95
+ }
96
+ getWalletBalances() {
97
+ return this.authGet("/api/user/balance");
98
+ }
99
+ getFunding() {
100
+ return this.authGet("/api/user/funding");
101
+ }
102
+ getAvailableBalance() {
103
+ return this.authGet("/api/market/available-balance");
104
+ }
105
+ getPositions() {
106
+ return this.authGet("/api/position");
107
+ }
108
+ getOrders(query) {
109
+ return this.authGet(`/api/order`, serializeQueryParams({
110
+ ...query,
111
+ limit: query.limit,
112
+ offset: query.offset ?? 0,
113
+ }));
114
+ }
115
+ getOpenedOrders() {
116
+ return this.authGet(`/api/order/opened`);
117
+ }
118
+ getTpSl(query) {
119
+ return this.authGet(`/api/tpsl`, serializeQueryParams({
120
+ ...query,
121
+ limit: query.limit,
122
+ offset: query.offset ?? 0,
123
+ }));
124
+ }
125
+ // Instrument
126
+ getCoins() {
127
+ return this.get("/api/coin");
128
+ }
129
+ getInstruments() {
130
+ return this.get("/api/market/instrument");
131
+ }
132
+ getInstrumentsMetrics() {
133
+ return this.get(`/api/market/instrument`, serializeQueryParams({
134
+ fields: InstrumentListQueryField.Metrics,
135
+ }));
136
+ }
137
+ // Actions
138
+ // Balance
139
+ withdraw(query) {
140
+ return this.authPost("/api/transfer/pf/withdraw", query);
141
+ }
142
+ // Position
143
+ updatePosition(query) {
144
+ return this.authPut(`/api/position/${query.instrument}`, {
145
+ leverage: query.leverage,
146
+ });
147
+ }
148
+ closePosition(query) {
149
+ return this.authPost(`/api/position/${query.instrument}/close`, query);
150
+ }
151
+ // Order
152
+ createLimitOrder(query) {
153
+ return this.authPost("/api/order/limit", query);
154
+ }
155
+ replaceLimitOrder(query) {
156
+ const { quantity, limitPrice, signature } = query;
157
+ return this.authPut(`/api/order/${query.orderId}/limit`, {
158
+ quantity,
159
+ limitPrice,
160
+ signature,
161
+ });
162
+ }
163
+ createMarketOrder(query) {
164
+ return this.authPost("/api/order/market", query);
165
+ }
166
+ createStopLimitOrder(query) {
167
+ return this.authPost("/api/order/stop-limit", query);
168
+ }
169
+ replaceStopLimitOrder(init) {
170
+ const { quantity, limitPrice, stopPrice, signature } = init;
171
+ return this.authPut(`/api/order/${init.orderId}/stop-limit`, {
172
+ quantity,
173
+ limitPrice,
174
+ stopPrice,
175
+ signature,
176
+ });
177
+ }
178
+ cancelOrder(query) {
179
+ return this.authDelete(`/api/order/${query.orderId}`);
180
+ }
181
+ massCancelUserOrders(query) {
182
+ return this.authPost("/api/order/mass-cancel", query);
183
+ }
184
+ massCancelUserOrdersById(query) {
185
+ return this.authPost("/api/order/mass-cancel-by-id", query);
186
+ }
187
+ // TpSl
188
+ createTpSl(tpsl) {
189
+ return this.authPost(`/api/tpsl/${tpsl.instrument}`, tpsl);
190
+ }
191
+ updateTpSl(query) {
192
+ return this.authPut(`/api/tpsl/${query.instrument}/${query.id}`, {
193
+ instrument: query.instrument,
194
+ type: query.type,
195
+ order: query.order,
196
+ query: query.quantity,
197
+ price: query.price,
198
+ side: query.side,
199
+ signature: query.signature,
200
+ });
201
+ }
202
+ cancelTpSl(query) {
203
+ return this.authDelete(`/api/tpsl/${query.instrument}/${query.id}`);
204
+ }
205
+ }
@@ -0,0 +1,142 @@
1
+ import { utils as cryptoUtils } from "@evedex/exchange-crypto";
2
+ import { Callback, CentrifugeClient, MarketDepth, MarketDepthLevel, MatcherState, Order, OrderFillFee, Position, TpSl, OrderBookRoundPrices, type RecentTrade, type InstrumentUpdateEvent } from "./utils";
3
+ export interface HeartbeatEvent {
4
+ t: number;
5
+ }
6
+ export interface MatcherUpdateEvent {
7
+ state: MatcherState;
8
+ updatedAt: string;
9
+ }
10
+ export interface OrderBookLevelUpdate extends MarketDepthLevel {
11
+ fillingPercent: number;
12
+ }
13
+ export interface OrderBookUpdateEvent {
14
+ instrument: string;
15
+ t: number;
16
+ asks: OrderBookLevelUpdate[];
17
+ bids: OrderBookLevelUpdate[];
18
+ spread: number;
19
+ asksVolumePercent: number;
20
+ bidsVolumePercent: number;
21
+ }
22
+ export interface ListenOrderBookQuery {
23
+ instrument: string;
24
+ roundPrices?: OrderBookRoundPrices;
25
+ }
26
+ export interface UnListenOrderBookQuery {
27
+ instrument: string;
28
+ roundPrices?: OrderBookRoundPrices;
29
+ }
30
+ export interface OrderBookBestUpdateEvent extends MarketDepth {
31
+ instrument: string;
32
+ }
33
+ export interface TradeEvent {
34
+ instrument: string;
35
+ side: cryptoUtils.Side;
36
+ fillQuantity: number;
37
+ fillPrice: number;
38
+ createdAt: string;
39
+ }
40
+ export interface ListenTradeQuery {
41
+ instrument: string;
42
+ }
43
+ export interface UnListenTradeQuery {
44
+ instrument: string;
45
+ }
46
+ export interface AccountEvent {
47
+ user: string;
48
+ marginCall: boolean;
49
+ updatedAt: string;
50
+ }
51
+ export interface FundingEvent {
52
+ user: string;
53
+ coin: string;
54
+ quantity: string;
55
+ updatedAt: string;
56
+ }
57
+ export interface FundingRateEvent {
58
+ instrument: string;
59
+ fundingRate: string;
60
+ createdAt: number;
61
+ }
62
+ export interface UserParam {
63
+ userExchangeId: string | number;
64
+ }
65
+ export interface ListenAccountQuery extends UserParam {
66
+ }
67
+ export interface UnListenAccountQuery extends UserParam {
68
+ }
69
+ export interface ListenFundingQuery extends UserParam {
70
+ }
71
+ export interface UnListenFundingQuery extends UserParam {
72
+ }
73
+ export interface ListenPositionsQuery extends UserParam {
74
+ }
75
+ export interface UnListenPositionsQuery extends UserParam {
76
+ }
77
+ export interface ListenOrdersQuery extends UserParam {
78
+ }
79
+ export interface UnListenOrdersQuery extends UserParam {
80
+ }
81
+ export interface ListenOrdersFeesQuery extends UserParam {
82
+ }
83
+ export interface UnListenOrdersFeesQuery extends UserParam {
84
+ }
85
+ export interface ListenTpSlQuery extends UserParam {
86
+ }
87
+ export interface UnListenTpSlQuery extends UserParam {
88
+ }
89
+ export interface ExchangeWsGatewayOptions {
90
+ wsClient: CentrifugeClient;
91
+ }
92
+ export declare class ExchangeWsGateway {
93
+ readonly options: ExchangeWsGatewayOptions;
94
+ private readonly listenedChannels;
95
+ constructor(options: ExchangeWsGatewayOptions);
96
+ protected listenChannel<T>(name: string, recoverable: boolean, handler: Callback<{
97
+ data: T;
98
+ }>): void;
99
+ protected unListenChannel(name: string, recoverable: boolean): void;
100
+ onHeartbeat: import("./utils").Signal<HeartbeatEvent>;
101
+ listenHeartbeat(): void;
102
+ unListenHeartbeat(): void;
103
+ onMatcherUpdate: import("./utils").Signal<MatcherUpdateEvent>;
104
+ listenMatcher(): void;
105
+ unListenMatcher(): void;
106
+ onOrderBookUpdate: import("./utils").Signal<OrderBookUpdateEvent>;
107
+ listenOrderBook(query: ListenOrderBookQuery): void;
108
+ unListenOrderBook(query: UnListenOrderBookQuery): void;
109
+ onOrderBookBestUpdate: import("./utils").Signal<OrderBookBestUpdateEvent>;
110
+ listenOrderBookBest(query: ListenOrderBookQuery): void;
111
+ unListenOrderBookBest(query: UnListenOrderBookQuery): void;
112
+ onTrade: import("./utils").Signal<TradeEvent>;
113
+ listenTrades(query: ListenTradeQuery): void;
114
+ unListenTrades(query: UnListenTradeQuery): void;
115
+ onRecentTrade: import("./utils").Signal<RecentTrade>;
116
+ listenRecentTrades(query: ListenTradeQuery): void;
117
+ unListenRecentTrades(query: UnListenTradeQuery): void;
118
+ onAccountUpdate: import("./utils").Signal<AccountEvent>;
119
+ listenAccount(query: ListenAccountQuery): void;
120
+ unListenAccount(query: UnListenAccountQuery): void;
121
+ onFundingUpdate: import("./utils").Signal<FundingEvent>;
122
+ listenFunding(query: ListenFundingQuery): void;
123
+ unListenFunding(query: UnListenFundingQuery): void;
124
+ onPositionUpdate: import("./utils").Signal<Position>;
125
+ listenPositions(query: ListenPositionsQuery): void;
126
+ unListenPositions(query: UnListenPositionsQuery): void;
127
+ onOrderUpdate: import("./utils").Signal<Order>;
128
+ listenOrders(query: ListenOrdersQuery): void;
129
+ unListenOrders(query: UnListenOrdersQuery): void;
130
+ onOrderFeeUpdate: import("./utils").Signal<OrderFillFee>;
131
+ listenOrdersFees(query: ListenOrdersFeesQuery): void;
132
+ unListenOrdersFees(query: UnListenOrdersFeesQuery): void;
133
+ onTpSlUpdate: import("./utils").Signal<TpSl>;
134
+ listenTpSl(query: ListenTpSlQuery): void;
135
+ unListenTpSl(query: UnListenTpSlQuery): void;
136
+ onFundingRateUpdate: import("./utils").Signal<FundingRateEvent>;
137
+ listenFundingRate(): void;
138
+ unListenFundingRate(): void;
139
+ onInstrumentUpdate: import("./utils").Signal<InstrumentUpdateEvent>;
140
+ listenInstruments(): void;
141
+ unListenInstruments(): void;
142
+ }
@@ -0,0 +1,144 @@
1
+ import { signal, expandOrderBook, OrderBookRoundPrices, } from "./utils";
2
+ export class ExchangeWsGateway {
3
+ options;
4
+ listenedChannels = new Set();
5
+ constructor(options) {
6
+ this.options = options;
7
+ }
8
+ listenChannel(name, recoverable, handler) {
9
+ if (this.listenedChannels.has(name))
10
+ return;
11
+ const channel = this.options.wsClient.assignChannel(name, { recoverable });
12
+ channel.onPublication(handler);
13
+ channel.subscribe();
14
+ this.listenedChannels.add(name);
15
+ }
16
+ unListenChannel(name, recoverable) {
17
+ if (!this.listenedChannels.has(name))
18
+ return;
19
+ this.options.wsClient.assignChannel(name, { recoverable }).unsubscribe();
20
+ this.listenedChannels.delete(name);
21
+ }
22
+ // Market
23
+ onHeartbeat = signal();
24
+ listenHeartbeat() {
25
+ this.listenChannel("heartbeat", false, (ctx) => this.onHeartbeat(ctx.data));
26
+ }
27
+ unListenHeartbeat() {
28
+ this.unListenChannel("heartbeat", false);
29
+ }
30
+ onMatcherUpdate = signal();
31
+ listenMatcher() {
32
+ this.listenChannel("info", false, (ctx) => this.onMatcherUpdate(ctx.data));
33
+ }
34
+ unListenMatcher() {
35
+ this.unListenChannel("info", false);
36
+ }
37
+ onOrderBookUpdate = signal();
38
+ listenOrderBook(query) {
39
+ this.listenChannel(`orderBook-${query.instrument}-${query.roundPrices ?? OrderBookRoundPrices.OneTenth}`, false, ({ data: { instrument, orderBook } }) => this.onOrderBookUpdate({
40
+ instrument,
41
+ ...expandOrderBook(orderBook),
42
+ }));
43
+ }
44
+ unListenOrderBook(query) {
45
+ this.unListenChannel(`orderBook-${query.instrument}-${query.roundPrices ?? OrderBookRoundPrices.OneTenth}`, false);
46
+ }
47
+ onOrderBookBestUpdate = signal();
48
+ listenOrderBookBest(query) {
49
+ this.listenChannel(`orderBook-${query.instrument}-best`, false, ({ data: { instrument, orderBook } }) => {
50
+ this.onOrderBookBestUpdate({
51
+ instrument,
52
+ t: orderBook.t,
53
+ asks: orderBook.asks,
54
+ bids: orderBook.bids,
55
+ });
56
+ });
57
+ }
58
+ unListenOrderBookBest(query) {
59
+ this.unListenChannel(`orderBook-${query.instrument}-best`, false);
60
+ }
61
+ onTrade = signal();
62
+ listenTrades(query) {
63
+ this.listenChannel(`trade-${query.instrument}`, false, ({ data }) => this.onTrade({
64
+ instrument: data.instrument,
65
+ side: data.side,
66
+ fillQuantity: data.fillQuantity,
67
+ fillPrice: data.fillPrice,
68
+ createdAt: data.createdAt,
69
+ }));
70
+ }
71
+ unListenTrades(query) {
72
+ this.unListenChannel(`trade-${query.instrument}`, false);
73
+ }
74
+ onRecentTrade = signal();
75
+ listenRecentTrades(query) {
76
+ this.listenChannel(`recent-trade-${query.instrument}`, false, ({ data }) => this.onRecentTrade({
77
+ instrument: data.instrument,
78
+ side: data.side,
79
+ fillQuantity: data.fillQuantity,
80
+ fillPrice: data.fillPrice,
81
+ createdAt: data.createdAt,
82
+ }));
83
+ }
84
+ unListenRecentTrades(query) {
85
+ this.unListenChannel(`recent-trade-${query.instrument}`, false);
86
+ }
87
+ // User
88
+ onAccountUpdate = signal();
89
+ listenAccount(query) {
90
+ this.listenChannel(`user-${query.userExchangeId}`, true, ({ data }) => this.onAccountUpdate(data));
91
+ }
92
+ unListenAccount(query) {
93
+ this.unListenChannel(`user-${query.userExchangeId}`, true);
94
+ }
95
+ onFundingUpdate = signal();
96
+ listenFunding(query) {
97
+ this.listenChannel(`funding-${query.userExchangeId}`, true, ({ data }) => this.onFundingUpdate(data));
98
+ }
99
+ unListenFunding(query) {
100
+ this.unListenChannel(`funding-${query.userExchangeId}`, true);
101
+ }
102
+ onPositionUpdate = signal();
103
+ listenPositions(query) {
104
+ this.listenChannel(`position-${query.userExchangeId}`, true, ({ data }) => this.onPositionUpdate(data));
105
+ }
106
+ unListenPositions(query) {
107
+ this.unListenChannel(`position-${query.userExchangeId}`, true);
108
+ }
109
+ onOrderUpdate = signal();
110
+ listenOrders(query) {
111
+ this.listenChannel(`order-${query.userExchangeId}`, true, ({ data }) => this.onOrderUpdate(data));
112
+ }
113
+ unListenOrders(query) {
114
+ this.unListenChannel(`order-${query.userExchangeId}`, true);
115
+ }
116
+ onOrderFeeUpdate = signal();
117
+ listenOrdersFees(query) {
118
+ this.listenChannel(`order-fee-${query.userExchangeId}`, true, ({ data }) => this.onOrderFeeUpdate(data));
119
+ }
120
+ unListenOrdersFees(query) {
121
+ this.unListenChannel(`order-fee-${query.userExchangeId}`, true);
122
+ }
123
+ onTpSlUpdate = signal();
124
+ listenTpSl(query) {
125
+ this.listenChannel(`tpsl-${query.userExchangeId}`, true, ({ data }) => this.onTpSlUpdate(data));
126
+ }
127
+ unListenTpSl(query) {
128
+ this.unListenChannel(`tpsl-${query.userExchangeId}`, true);
129
+ }
130
+ onFundingRateUpdate = signal();
131
+ listenFundingRate() {
132
+ this.listenChannel("funding-rate", true, ({ data }) => this.onFundingRateUpdate(data));
133
+ }
134
+ unListenFundingRate() {
135
+ this.unListenChannel("funding-rate", true);
136
+ }
137
+ onInstrumentUpdate = signal();
138
+ listenInstruments() {
139
+ this.listenChannel("instruments", false, ({ data }) => this.onInstrumentUpdate(data));
140
+ }
141
+ unListenInstruments() {
142
+ this.unListenChannel("instruments", false);
143
+ }
144
+ }
@@ -0,0 +1,4 @@
1
+ export * as utils from "./utils";
2
+ export * from "./exchangeWsGateway";
3
+ export * from "./exchangeRestGateway";
4
+ export * from "./authRestGateway";
@@ -0,0 +1,4 @@
1
+ export * as utils from "./utils";
2
+ export * from "./exchangeWsGateway";
3
+ export * from "./exchangeRestGateway";
4
+ export * from "./authRestGateway";
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,59 @@
1
+ import { MarketDepth } from "./types";
2
+ export declare enum MatcherState {
3
+ Active = "active",
4
+ RequestStatusFail = "request-status-fail",
5
+ MeDead = "me-dead",
6
+ DbAdminDead = "db-admin-dead"
7
+ }
8
+ export declare enum OrderBookRoundPrices {
9
+ OneTenth = "0.1",
10
+ One = "1",
11
+ Ten = "10",
12
+ Fifty = "50",
13
+ Hundred = "100"
14
+ }
15
+ export declare enum OrderStatus {
16
+ New = "NEW",
17
+ PartiallyFilled = "PARTIALLY_FILLED",
18
+ Filled = "FILLED",
19
+ Cancelled = "CANCELLED",
20
+ Rejected = "REJECTED",
21
+ Expired = "EXPIRED",
22
+ Replaced = "REPLACED"
23
+ }
24
+ export declare enum OrderGroup {
25
+ Manually = "manually",
26
+ TpSl = "tpsl",
27
+ Liquidation = "liquidation",
28
+ Adl = "adl"
29
+ }
30
+ export declare enum OrderType {
31
+ Limit = "LIMIT",
32
+ Market = "MARKET",
33
+ Stop = "STOP",
34
+ StopLimit = "STOP_LIMIT"
35
+ }
36
+ export declare enum TpSlStatus {
37
+ WaitOrder = "waitOrder",
38
+ Active = "active",
39
+ Process = "process",
40
+ Triggered = "triggered",
41
+ Done = "done",
42
+ Cancelled = "cancelled"
43
+ }
44
+ export declare function expandOrderBook(orderBook: MarketDepth): {
45
+ t: number;
46
+ asks: {
47
+ fillingPercent: number;
48
+ price: number;
49
+ quantity: number;
50
+ }[];
51
+ bids: {
52
+ fillingPercent: number;
53
+ price: number;
54
+ quantity: number;
55
+ }[];
56
+ asksVolumePercent: number;
57
+ bidsVolumePercent: number;
58
+ spread: number;
59
+ };
@@ -0,0 +1,81 @@
1
+ import Big from "big.js";
2
+ export var MatcherState;
3
+ (function (MatcherState) {
4
+ MatcherState["Active"] = "active";
5
+ MatcherState["RequestStatusFail"] = "request-status-fail";
6
+ MatcherState["MeDead"] = "me-dead";
7
+ MatcherState["DbAdminDead"] = "db-admin-dead";
8
+ })(MatcherState || (MatcherState = {}));
9
+ export var OrderBookRoundPrices;
10
+ (function (OrderBookRoundPrices) {
11
+ OrderBookRoundPrices["OneTenth"] = "0.1";
12
+ OrderBookRoundPrices["One"] = "1";
13
+ OrderBookRoundPrices["Ten"] = "10";
14
+ OrderBookRoundPrices["Fifty"] = "50";
15
+ OrderBookRoundPrices["Hundred"] = "100";
16
+ })(OrderBookRoundPrices || (OrderBookRoundPrices = {}));
17
+ export var OrderStatus;
18
+ (function (OrderStatus) {
19
+ OrderStatus["New"] = "NEW";
20
+ OrderStatus["PartiallyFilled"] = "PARTIALLY_FILLED";
21
+ OrderStatus["Filled"] = "FILLED";
22
+ OrderStatus["Cancelled"] = "CANCELLED";
23
+ OrderStatus["Rejected"] = "REJECTED";
24
+ OrderStatus["Expired"] = "EXPIRED";
25
+ OrderStatus["Replaced"] = "REPLACED";
26
+ })(OrderStatus || (OrderStatus = {}));
27
+ export var OrderGroup;
28
+ (function (OrderGroup) {
29
+ OrderGroup["Manually"] = "manually";
30
+ OrderGroup["TpSl"] = "tpsl";
31
+ OrderGroup["Liquidation"] = "liquidation";
32
+ OrderGroup["Adl"] = "adl";
33
+ })(OrderGroup || (OrderGroup = {}));
34
+ export var OrderType;
35
+ (function (OrderType) {
36
+ OrderType["Limit"] = "LIMIT";
37
+ OrderType["Market"] = "MARKET";
38
+ OrderType["Stop"] = "STOP";
39
+ OrderType["StopLimit"] = "STOP_LIMIT";
40
+ })(OrderType || (OrderType = {}));
41
+ export var TpSlStatus;
42
+ (function (TpSlStatus) {
43
+ TpSlStatus["WaitOrder"] = "waitOrder";
44
+ TpSlStatus["Active"] = "active";
45
+ TpSlStatus["Process"] = "process";
46
+ TpSlStatus["Triggered"] = "triggered";
47
+ TpSlStatus["Done"] = "done";
48
+ TpSlStatus["Cancelled"] = "cancelled";
49
+ })(TpSlStatus || (TpSlStatus = {}));
50
+ export function expandOrderBook(orderBook) {
51
+ const asksMetrics = orderBook.asks.reduce(({ max, sum }, { quantity }) => ({
52
+ max: Math.max(quantity, max),
53
+ sum: Big(quantity).plus(sum).toString(),
54
+ }), { max: 0, sum: "0" });
55
+ const bidsMetrics = orderBook.bids.reduce(({ max, sum }, { quantity }) => ({
56
+ max: Math.max(quantity, max),
57
+ sum: Big(quantity).plus(sum).toString(),
58
+ }), { max: 0, sum: "0" });
59
+ const asks = orderBook.asks.reverse().map((item) => ({
60
+ ...item,
61
+ fillingPercent: item.quantity / asksMetrics.max,
62
+ }));
63
+ const bids = orderBook.bids.reverse().map((item) => ({
64
+ ...item,
65
+ fillingPercent: item.quantity / bidsMetrics.max,
66
+ }));
67
+ const orderBookVolume = Big(asksMetrics.sum).plus(bidsMetrics.sum);
68
+ const asksVolumePercent = !orderBookVolume.eq(0)
69
+ ? Big(asksMetrics.sum).div(orderBookVolume).toNumber()
70
+ : 0;
71
+ const bidsVolumePercent = 1 - asksVolumePercent;
72
+ const spread = bids.length && asks.length ? asks[0].price - bids[0].price : 0;
73
+ return {
74
+ t: orderBook.t,
75
+ asks,
76
+ bids,
77
+ asksVolumePercent,
78
+ bidsVolumePercent,
79
+ spread,
80
+ };
81
+ }
@@ -0,0 +1,26 @@
1
+ import { ApiKey, JWT, RefreshedJWT } from "./types";
2
+ type Method = "get" | "GET" | "delete" | "DELETE" | "head" | "HEAD" | "options" | "OPTIONS" | "post" | "POST" | "put" | "PUT" | "patch" | "PATCH" | "purge" | "PURGE" | "link" | "LINK" | "unlink" | "UNLINK";
3
+ export interface Request {
4
+ method: Method | string;
5
+ url: string;
6
+ headers?: Record<string, string>;
7
+ body?: string;
8
+ }
9
+ export interface Response<Data> {
10
+ status: number;
11
+ statusText?: string;
12
+ headers?: Record<string, string>;
13
+ data: Data;
14
+ }
15
+ export declare class RequestError extends Error {
16
+ response?: Response<any>;
17
+ constructor(message: string, response?: Response<any>);
18
+ }
19
+ export interface HttpClient {
20
+ setSession(session: JWT | RefreshedJWT | ApiKey): any;
21
+ getSession(): JWT | RefreshedJWT | ApiKey | undefined;
22
+ request<Data>(requestConfig: Request): Promise<Response<Data>>;
23
+ authRequest<Data>(requestConfig: Request): Promise<Response<Data>>;
24
+ }
25
+ export declare function serializeQueryParams<P extends object>(params: P): string;
26
+ export {};