From 45e59754bc19d7acf39497791a446cc3833f86d9 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Mon, 13 Feb 2023 12:55:34 +0000 Subject: [PATCH] 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',