From 45e59754bc19d7acf39497791a446cc3833f86d9 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Mon, 13 Feb 2023 12:55:34 +0000 Subject: [PATCH 1/8] CFD schema was updated --- package.json | 2 +- .../OrionAggregator/ws/MessageType.ts | 1 + .../OrionAggregator/ws/SubscriptionType.ts | 1 + src/services/OrionAggregator/ws/index.ts | 30 +++++++++++++++++-- .../ws/schemas/addressUpdateSchema.ts | 4 --- .../ws/schemas/cfdBalancesSchema.ts | 4 --- .../ws/schemas/futuresTradeInfoSchema.ts | 16 ++++++++++ src/types.ts | 13 ++++++-- 8 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 src/services/OrionAggregator/ws/schemas/futuresTradeInfoSchema.ts diff --git a/package.json b/package.json index f2c053c..b9363e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.17.5", + "version": "0.17.6-rc.0", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", diff --git a/src/services/OrionAggregator/ws/MessageType.ts b/src/services/OrionAggregator/ws/MessageType.ts index 323e836..190cc0c 100644 --- a/src/services/OrionAggregator/ws/MessageType.ts +++ b/src/services/OrionAggregator/ws/MessageType.ts @@ -8,6 +8,7 @@ const MessageType = { ASSET_PAIR_CONFIG_UPDATE: 'apiu', ADDRESS_UPDATE: 'au', CFD_ADDRESS_UPDATE: 'auf', + FUTURES_TRADE_INFO_UPDATE: 'fti', BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATE: 'btasabu', UNSUBSCRIPTION_DONE: 'ud', } as const; diff --git a/src/services/OrionAggregator/ws/SubscriptionType.ts b/src/services/OrionAggregator/ws/SubscriptionType.ts index 741dad1..708e35d 100644 --- a/src/services/OrionAggregator/ws/SubscriptionType.ts +++ b/src/services/OrionAggregator/ws/SubscriptionType.ts @@ -6,6 +6,7 @@ const SubscriptionType = { CFD_ADDRESS_UPDATES_SUBSCRIBE: 'ausf', BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATES_SUBSCRIBE: 'btasabus', SWAP_SUBSCRIBE: 'ss', + FUTURES_TRADE_INFO_SUBSCRIBE: 'fts', } as const; export default SubscriptionType; diff --git a/src/services/OrionAggregator/ws/index.ts b/src/services/OrionAggregator/ws/index.ts index b7ca9d0..1a97aa8 100644 --- a/src/services/OrionAggregator/ws/index.ts +++ b/src/services/OrionAggregator/ws/index.ts @@ -11,12 +11,13 @@ import { import UnsubscriptionType from './UnsubscriptionType'; import { SwapInfoByAmountIn, SwapInfoByAmountOut, SwapInfoBase, - AssetPairUpdate, OrderbookItem, Balance, Exchange, CFDBalance, + AssetPairUpdate, OrderbookItem, Balance, Exchange, CFDBalance, SwapInfo, FuturesTradeInfo, } from '../../../types'; import unsubscriptionDoneSchema from './schemas/unsubscriptionDoneSchema'; import assetPairConfigSchema from './schemas/assetPairConfigSchema'; import { fullOrderSchema, orderUpdateSchema } from './schemas/addressUpdateSchema'; import cfdAddressUpdateSchema from './schemas/cfdAddressUpdateSchema'; +import futuresTradeInfoSchema from './schemas/futuresTradeInfoSchema'; // import errorSchema from './schemas/errorSchema'; const UNSUBSCRIBE = 'u'; @@ -62,7 +63,17 @@ type AggregatedOrderbookSubscription = { type SwapInfoSubscription = { payload: SwapSubscriptionRequest, - callback: (swapInfo: SwapInfoByAmountIn | SwapInfoByAmountOut) => void, + callback: (swapInfo: SwapInfo) => void, +} + +type FuturesTradeInfoSubscription = { + payload: { + S: string, + i: string, + a: number, + p: boolean, + }, + callback: (futuresTradeInfo: FuturesTradeInfo) => void, } type AddressUpdateUpdate = { @@ -117,6 +128,7 @@ type Subscription = { [SubscriptionType.ASSET_PAIR_CONFIG_UPDATES_SUBSCRIBE]: PairConfigSubscription, [SubscriptionType.BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATES_SUBSCRIBE]: BrokerTradableAtomicSwapBalanceSubscription, [SubscriptionType.SWAP_SUBSCRIBE]: SwapInfoSubscription + [SubscriptionType.FUTURES_TRADE_INFO_SUBSCRIBE]: FuturesTradeInfoSubscription } const exclusiveSubscriptions = [ @@ -272,6 +284,7 @@ class OrionAggregatorWS { // is swap info subscription (contains hyphen) delete this.subscriptions[SubscriptionType.SWAP_SUBSCRIBE]?.[subscription]; delete this.subscriptions[SubscriptionType.ASSET_PAIR_CONFIG_UPDATES_SUBSCRIBE]?.[subscription]; + delete this.subscriptions[SubscriptionType.FUTURES_TRADE_INFO_SUBSCRIBE]?.[subscription]; // !!! swap info subscription is uuid that contains hyphen } else if (subscription.includes('-') && subscription.split('-').length === 2) { // is pair name(AGGREGATED_ORDER_BOOK_UPDATE) const aobSubscriptions = this.subscriptions[SubscriptionType.AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE]; @@ -339,6 +352,7 @@ class OrionAggregatorWS { brokerMessageSchema, orderBookSchema, swapInfoSchema, + futuresTradeInfoSchema, errorSchema, unsubscriptionDoneSchema, ]); @@ -413,6 +427,18 @@ class OrionAggregatorWS { } } break; + case MessageType.FUTURES_TRADE_INFO_UPDATE: + this.subscriptions[SubscriptionType.FUTURES_TRADE_INFO_SUBSCRIBE]?.[json.S]?.callback({ + futuresTradeRequestId: json.id, + sender: json.S, + instrument: json.i, + buyPrice: json.bp, + sellPrice: json.sp, + buyPower: json.bpw, + sellPower: json.spw, + minAmount: json.ma, + }); + break; case MessageType.INITIALIZATION: this.onInit?.(); break; diff --git a/src/services/OrionAggregator/ws/schemas/addressUpdateSchema.ts b/src/services/OrionAggregator/ws/schemas/addressUpdateSchema.ts index 631527f..1850585 100644 --- a/src/services/OrionAggregator/ws/schemas/addressUpdateSchema.ts +++ b/src/services/OrionAggregator/ws/schemas/addressUpdateSchema.ts @@ -33,7 +33,6 @@ export const orderUpdateSchema = z.object({ A: z.number(), // settled amount S: z.enum(orderStatuses), // status l: z.boolean().optional(), // is liquidation order - cl: z.boolean().optional(), // is closing t: z.number(), // update time c: subOrderSchema.array(), }) @@ -46,7 +45,6 @@ export const orderUpdateSchema = z.object({ settledAmount: o.A, status: o.S, liquidated: o.l, - closing: o.cl, subOrders: o.c.map((so) => ({ pair: so.P, exchange: so.e, @@ -71,7 +69,6 @@ export const fullOrderSchema = z.object({ F: z.string(), // fee asset f: z.number(), // fee l: z.boolean().optional(), // is liquidation order - cl: z.boolean().optional(), // is closing o: z.boolean(), // internal only S: z.enum(orderStatuses), // status T: z.number(), // creation time / unix timestamp @@ -87,7 +84,6 @@ export const fullOrderSchema = z.object({ feeAsset: o.F, fee: o.f, liquidated: o.l, - closing: o.cl, status: o.S, date: o.T, clientOrdId: o.O, diff --git a/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts b/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts index 3af9729..e5cec0d 100644 --- a/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts +++ b/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts @@ -16,8 +16,6 @@ const cfdBalanceSchema = z mu: z.string(), fmu: z.string(), awb: z.string(), - mli: z.string(), - msi: z.string(), l: z.string(), s: z.enum(positionStatuses), }) @@ -35,8 +33,6 @@ const cfdBalanceSchema = z marginUSD: obj.mu, freeMarginUSD: obj.fmu, availableWithdrawBalance: obj.awb, - maxAvailableLong: obj.mli, - maxAvailableShort: obj.msi, leverage: obj.l, status: obj.s, })); diff --git a/src/services/OrionAggregator/ws/schemas/futuresTradeInfoSchema.ts b/src/services/OrionAggregator/ws/schemas/futuresTradeInfoSchema.ts new file mode 100644 index 0000000..ebe9471 --- /dev/null +++ b/src/services/OrionAggregator/ws/schemas/futuresTradeInfoSchema.ts @@ -0,0 +1,16 @@ +import { z } from 'zod'; +import MessageType from '../MessageType'; + +const futuresTradeInfoSchema = z.object({ + T: z.literal(MessageType.FUTURES_TRADE_INFO_UPDATE), + id: z.string(), // trade info request UUID, set by client side + S: z.string(), // sender + i: z.string(), // instrument + bp: z.number(), // buy price + sp: z.number(), // sell price + bpw: z.number(), // buy power + spw: z.number(), // sell power + ma: z.number(), // min amount +}); + +export default futuresTradeInfoSchema; diff --git a/src/types.ts b/src/types.ts index eba96f8..5c223aa 100644 --- a/src/types.ts +++ b/src/types.ts @@ -47,8 +47,6 @@ export type CFDBalance = { marginUSD: string, freeMarginUSD: string, availableWithdrawBalance: string, - maxAvailableLong: string, - maxAvailableShort: string, leverage: string, status: PositionStatus, } @@ -236,6 +234,17 @@ export type SwapInfoByAmountOut = SwapInfoBase & { export type SwapInfo = SwapInfoByAmountIn | SwapInfoByAmountOut; +export type FuturesTradeInfo = { + futuresTradeRequestId: string, + sender: string, + instrument: string, + buyPrice: number, + sellPrice: number, + buyPower: number, + sellPower: number, + minAmount: number, +} + export enum HistoryTransactionStatus { PENDING = 'Pending', DONE = 'Done', From 35b873c78934878761f28f879ac4f999e2516ed9 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Mon, 13 Feb 2023 12:59:05 +0000 Subject: [PATCH 2/8] Eslint error fix --- src/services/OrionAggregator/ws/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/OrionAggregator/ws/index.ts b/src/services/OrionAggregator/ws/index.ts index 1a97aa8..7dbfad3 100644 --- a/src/services/OrionAggregator/ws/index.ts +++ b/src/services/OrionAggregator/ws/index.ts @@ -10,8 +10,8 @@ import { } from './schemas'; import UnsubscriptionType from './UnsubscriptionType'; import { - SwapInfoByAmountIn, SwapInfoByAmountOut, SwapInfoBase, - AssetPairUpdate, OrderbookItem, Balance, Exchange, CFDBalance, SwapInfo, FuturesTradeInfo, + SwapInfoBase, AssetPairUpdate, OrderbookItem, Balance, + Exchange, CFDBalance, SwapInfo, FuturesTradeInfo, } from '../../../types'; import unsubscriptionDoneSchema from './schemas/unsubscriptionDoneSchema'; import assetPairConfigSchema from './schemas/assetPairConfigSchema'; From f49b5078df2aae5a780dbd24dbc70e060f9f555f Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Mon, 13 Feb 2023 14:09:05 +0000 Subject: [PATCH 3/8] type fix --- package.json | 2 +- src/services/OrionAggregator/ws/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b9363e2..3bf1e18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.17.6-rc.0", + "version": "0.17.6-rc.1", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", diff --git a/src/services/OrionAggregator/ws/index.ts b/src/services/OrionAggregator/ws/index.ts index 7dbfad3..44124e3 100644 --- a/src/services/OrionAggregator/ws/index.ts +++ b/src/services/OrionAggregator/ws/index.ts @@ -71,7 +71,7 @@ type FuturesTradeInfoSubscription = { S: string, i: string, a: number, - p: boolean, + p?: number, }, callback: (futuresTradeInfo: FuturesTradeInfo) => void, } From 3e9cc7bbd639fd7dd9079e4bf9ae72da483133bb Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Mon, 13 Feb 2023 16:25:01 +0000 Subject: [PATCH 4/8] FuturesTradeInfoSubscription type update --- src/services/OrionAggregator/ws/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/OrionAggregator/ws/index.ts b/src/services/OrionAggregator/ws/index.ts index 44124e3..d5445e2 100644 --- a/src/services/OrionAggregator/ws/index.ts +++ b/src/services/OrionAggregator/ws/index.ts @@ -68,7 +68,7 @@ type SwapInfoSubscription = { type FuturesTradeInfoSubscription = { payload: { - S: string, + s: string, i: string, a: number, p?: number, From 6d12509df082a8f7032a868342a97f9f39ddcd53 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Mon, 13 Feb 2023 16:26:56 +0000 Subject: [PATCH 5/8] package.json version update --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3bf1e18..2503f5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.17.6-rc.1", + "version": "0.17.6-rc.2", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", From 5ed6ab552df663cade69cdd0fc78c5860a89dce1 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Mon, 13 Feb 2023 17:24:48 +0000 Subject: [PATCH 6/8] FUTURES_TRADE_INFO_UPDATE case was updated --- src/services/OrionAggregator/ws/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/OrionAggregator/ws/index.ts b/src/services/OrionAggregator/ws/index.ts index d5445e2..d90a42e 100644 --- a/src/services/OrionAggregator/ws/index.ts +++ b/src/services/OrionAggregator/ws/index.ts @@ -428,7 +428,7 @@ class OrionAggregatorWS { } break; case MessageType.FUTURES_TRADE_INFO_UPDATE: - this.subscriptions[SubscriptionType.FUTURES_TRADE_INFO_SUBSCRIBE]?.[json.S]?.callback({ + this.subscriptions[SubscriptionType.FUTURES_TRADE_INFO_SUBSCRIBE]?.[json.id]?.callback({ futuresTradeRequestId: json.id, sender: json.S, instrument: json.i, From 17a56e7e30719b6b9f5b1bef5b09b24df0703936 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Mon, 13 Feb 2023 17:25:57 +0000 Subject: [PATCH 7/8] FUTURES_TRADE_INFO_UPDATE case was updated --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2503f5e..ecb7fad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.17.6-rc.2", + "version": "0.17.6-rc.3", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", From 7040df61425c635e2f60b9b7996ec9e72cfeb24d Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Mon, 13 Feb 2023 17:39:21 +0000 Subject: [PATCH 8/8] New version was released --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ecb7fad..8560a1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.17.6-rc.3", + "version": "0.17.6", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js",