Merge pull request #73 from orionprotocol/OP-3658-trigger-condition

OP-3658 Update cfd balance schema
This commit is contained in:
Mikhail Gladchenko
2023-03-17 08:53:24 +00:00
committed by GitHub
5 changed files with 16 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.17.36",
"version": "0.17.37-rc.2",
"description": "Orion Protocol SDK",
"main": "./lib/esm/index.js",
"module": "./lib/esm/index.js",

View File

@@ -0,0 +1,3 @@
const executionTypes = ['LIMIT', 'STOP_LIMIT'] as const;
export default executionTypes;

View File

@@ -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,

View File

@@ -44,7 +44,7 @@ const cfdBalanceSchema = z
longFundingRatePerDay: obj.lfrd,
shortFundingRatePerSecond: obj.sfrs,
shortFundingRatePerDay: obj.sfrd,
stopOutPrice: obj.sop
stopOutPrice: obj.sop,
}));
const cfdBalancesSchema = z.array(cfdBalanceSchema);

View File

@@ -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> = T extends object ? {
[P in keyof T]?: DeepPartial<T[P]>;
@@ -34,6 +35,7 @@ export type Balance = {
}
export type PositionStatus = typeof positionStatuses[number];
export type ExecutionType = typeof executionTypes[number];
export type CFDBalance = {
instrument: string