From 56387b18a4950c685c65fdf094fbf28749ad6c19 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Thu, 16 Mar 2023 08:20:39 +0000 Subject: [PATCH 1/4] Update cfd balance schema --- package.json | 2 +- src/constants/cfdExecutionTypes.ts | 3 +++ .../OrionAggregator/ws/schemas/cfdBalancesSchema.ts | 7 ++++++- src/types.ts | 4 ++++ 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 src/constants/cfdExecutionTypes.ts diff --git a/package.json b/package.json index 60f3eca..5f55352 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.17.36", + "version": "0.17.37-rc.1", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", diff --git a/src/constants/cfdExecutionTypes.ts b/src/constants/cfdExecutionTypes.ts new file mode 100644 index 0000000..bc82566 --- /dev/null +++ b/src/constants/cfdExecutionTypes.ts @@ -0,0 +1,3 @@ +const executionTypes = ['LIMIT', 'STOP_LIMIT'] as const; + +export default executionTypes; diff --git a/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts b/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts index e7abacd..48d4a97 100644 --- a/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts +++ b/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts @@ -1,5 +1,6 @@ import { z } from 'zod'; import positionStatuses from '../../../../constants/positionStatuses'; +import executionTypes from '../../../../constants/cfdExecutionTypes'; const cfdBalanceSchema = z .object({ @@ -23,6 +24,8 @@ const cfdBalanceSchema = z sfrs: z.string(), sfrd: z.string(), sop: z.string().optional(), + E: z.enum(executionTypes), + C: z.string().optional(), }) .transform((obj) => ({ instrument: obj.i, @@ -44,7 +47,9 @@ const cfdBalanceSchema = z longFundingRatePerDay: obj.lfrd, shortFundingRatePerSecond: obj.sfrs, shortFundingRatePerDay: obj.sfrd, - stopOutPrice: obj.sop + stopOutPrice: obj.sop, + executionType: obj.E, + triggerCondition: obj.C, })); const cfdBalancesSchema = z.array(cfdBalanceSchema); diff --git a/src/types.ts b/src/types.ts index 891d740..b150dea 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,6 +4,7 @@ import type exchanges from './constants/exchanges'; import type subOrderStatuses from './constants/subOrderStatuses'; import type positionStatuses from './constants/positionStatuses'; import type { knownEnvs } from './config/schemas'; +import type executionTypes from './constants/cfdExecutionTypes'; export type DeepPartial = T extends object ? { [P in keyof T]?: DeepPartial; @@ -34,6 +35,7 @@ export type Balance = { } export type PositionStatus = typeof positionStatuses[number]; +export type ExecutionType = typeof executionTypes[number]; export type CFDBalance = { instrument: string @@ -56,6 +58,8 @@ export type CFDBalance = { shortFundingRatePerSecond: string shortFundingRatePerDay: string stopOutPrice: string | undefined + executionType: ExecutionType + triggerCondition: string | undefined } export type Order = { From f7b8b828e5786dee577851f076fe20e69901d92a Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Thu, 16 Mar 2023 14:52:14 +0000 Subject: [PATCH 2/4] Update orderUpdateSchema --- .../OrionAggregator/ws/schemas/addressUpdateSchema.ts | 9 +++++++++ .../OrionAggregator/ws/schemas/cfdBalancesSchema.ts | 4 ---- src/types.ts | 2 -- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/services/OrionAggregator/ws/schemas/addressUpdateSchema.ts b/src/services/OrionAggregator/ws/schemas/addressUpdateSchema.ts index 583c684..d9f53b5 100644 --- a/src/services/OrionAggregator/ws/schemas/addressUpdateSchema.ts +++ b/src/services/OrionAggregator/ws/schemas/addressUpdateSchema.ts @@ -5,6 +5,7 @@ import subOrderStatuses from '../../../../constants/subOrderStatuses'; import MessageType from '../MessageType'; import balancesSchema from './balancesSchema'; import baseMessageSchema from './baseMessageSchema'; +import executionTypes from '../../../../constants/cfdExecutionTypes'; const baseAddressUpdate = baseMessageSchema.extend({ id: z.string(), @@ -34,6 +35,8 @@ export const orderUpdateSchema = z.object({ S: z.enum(orderStatuses), // status l: z.boolean().optional(), // is liquidation order t: z.number(), // update time + E: z.enum(executionTypes).optional(), // execution type + C: z.string().optional(), // trigger condition c: subOrderSchema.array(), }) .transform((val) => ({ @@ -45,6 +48,8 @@ export const orderUpdateSchema = z.object({ settledAmount: o.A, status: o.S, liquidated: o.l, + executionType: o.E, + triggerCondition: o.C, subOrders: o.c.map((so) => ({ pair: so.P, exchange: so.e, @@ -75,6 +80,8 @@ export const fullOrderSchema = z.object({ T: z.number(), // creation time / unix timestamp t: z.number(), // update time c: subOrderSchema.array(), + E: z.enum(executionTypes).optional(), // execution type + C: z.string().optional(), // trigger condition }).transform((val) => ({ ...val, k: 'full' as const, @@ -93,6 +100,8 @@ export const fullOrderSchema = z.object({ pair: o.P, amount: o.a, price: o.p, + executionType: o.E, + triggerCondition: o.C, subOrders: o.c.map((so) => ({ pair: so.P, exchange: so.e, diff --git a/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts b/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts index 48d4a97..3f7c91b 100644 --- a/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts +++ b/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts @@ -24,8 +24,6 @@ const cfdBalanceSchema = z sfrs: z.string(), sfrd: z.string(), sop: z.string().optional(), - E: z.enum(executionTypes), - C: z.string().optional(), }) .transform((obj) => ({ instrument: obj.i, @@ -48,8 +46,6 @@ const cfdBalanceSchema = z shortFundingRatePerSecond: obj.sfrs, shortFundingRatePerDay: obj.sfrd, stopOutPrice: obj.sop, - executionType: obj.E, - triggerCondition: obj.C, })); const cfdBalancesSchema = z.array(cfdBalanceSchema); diff --git a/src/types.ts b/src/types.ts index b150dea..a77b780 100644 --- a/src/types.ts +++ b/src/types.ts @@ -58,8 +58,6 @@ export type CFDBalance = { shortFundingRatePerSecond: string shortFundingRatePerDay: string stopOutPrice: string | undefined - executionType: ExecutionType - triggerCondition: string | undefined } export type Order = { From aac4c3070f58acab906a5637304c98c6508bf7af Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Thu, 16 Mar 2023 14:52:34 +0000 Subject: [PATCH 3/4] Update orderUpdateSchema --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5f55352..a4a3c62 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.17.37-rc.1", + "version": "0.17.37-rc.2", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", From a37aa5c69528480a7ca4943f7289514e5ea3d34e Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Thu, 16 Mar 2023 14:56:46 +0000 Subject: [PATCH 4/4] Small fix --- src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts b/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts index 3f7c91b..5037864 100644 --- a/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts +++ b/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts @@ -1,6 +1,5 @@ import { z } from 'zod'; import positionStatuses from '../../../../constants/positionStatuses'; -import executionTypes from '../../../../constants/cfdExecutionTypes'; const cfdBalanceSchema = z .object({