Exchange enum

This commit is contained in:
Aleksandr Kraiz
2022-12-14 19:04:41 +04:00
parent e5baa6f4a6
commit 625785bf7d
8 changed files with 48 additions and 51 deletions

View File

@@ -1,4 +1,5 @@
import { z } from 'zod';
import { exchanges } from '../../../constants';
const orderbookElementSchema = z.object({
price: z.number(),
@@ -11,7 +12,7 @@ const orderbookElementSchema = z.object({
const aggregatedOrderbookElementSchema = orderbookElementSchema
.extend({
exchanges: z.string().array(),
exchanges: z.enum(exchanges).array(),
});
export const aggregatedOrderbookSchema = z.object({

View File

@@ -1,4 +1,5 @@
import { z } from 'zod';
import { exchanges } from '../../../constants';
const swapInfoBase = z.object({
id: z.string(),
@@ -15,13 +16,13 @@ const swapInfoBase = z.object({
amount: z.number(),
safePrice: z.number(),
}).nullable(),
exchanges: z.array(z.string()),
exchanges: z.array(z.enum(exchanges)),
price: z.number().nullable(), // spending asset price
minAmountOut: z.number(),
minAmountIn: z.number(),
marketPrice: z.number().nullable(), // spending asset market price
alternatives: z.object({ // execution alternatives
exchanges: z.string().array(),
exchanges: z.array(z.enum(exchanges)),
path: z.object({
units: z.object({
assetPair: z.string(),

View File

@@ -11,7 +11,7 @@ import {
import UnsubscriptionType from './UnsubscriptionType';
import {
SwapInfoByAmountIn, SwapInfoByAmountOut, SwapInfoBase,
FullOrder, OrderUpdate, AssetPairUpdate, OrderbookItem, Balance, Exchange, SwapInfoAlternative,
FullOrder, OrderUpdate, AssetPairUpdate, OrderbookItem, Balance, Exchange,
} from '../../../types';
import unsubscriptionDoneSchema from './schemas/unsubscriptionDoneSchema';
import assetPairConfigSchema from './schemas/assetPairConfigSchema';
@@ -300,20 +300,6 @@ class OrionAggregatorWS {
// To implement
break;
case MessageType.SWAP_INFO: {
let alternatives: SwapInfoAlternative[] = [];
if (json.as) {
alternatives = json.as.map((item) => ({
exchanges: item.e,
path: item.ps,
marketAmountOut: item.mo,
marketAmountIn: item.mi,
marketPrice: item.mp,
availableAmountIn: item.aa,
availableAmountOut: item.aao,
}));
}
const baseSwapInfo: SwapInfoBase = {
swapRequestId: json.S,
assetIn: json.ai,
@@ -322,8 +308,8 @@ class OrionAggregatorWS {
amountOut: json.o,
price: json.p,
marketPrice: json.mp,
minAmounOut: json.mao,
minAmounIn: json.ma,
minAmountOut: json.mao,
minAmountIn: json.ma,
path: json.ps,
exchanges: json.e,
poolOptimal: json.po,
@@ -335,7 +321,15 @@ class OrionAggregatorWS {
safePrice: json.oi.sp,
},
},
alternatives,
alternatives: json.as.map((item) => ({
exchanges: item.e,
path: item.ps,
marketAmountOut: item.mo,
marketAmountIn: item.mi,
marketPrice: item.mp,
availableAmountIn: item.aa,
availableAmountOut: item.aao,
})),
};
switch (json.k) { // kind

View File

@@ -1,4 +1,5 @@
import { z } from 'zod';
import { exchanges } from '../../../../constants';
import orderStatuses from '../../../../constants/orderStatuses';
import subOrderStatuses from '../../../../constants/subOrderStatuses';
import MessageType from '../MessageType';
@@ -21,7 +22,7 @@ const subOrderSchema = z.object({
a: z.number(), // amount
A: z.number(), // settled amount
p: z.number(), // avg weighed settlement price
e: z.string(), // exchange
e: z.enum(exchanges), // exchange
b: z.string(), // broker address
S: z.enum(subOrderStatuses), // status
o: z.boolean(), // internal only

View File

@@ -24,7 +24,7 @@ const swapInfoSchemaBase = baseMessageSchema.extend({
sp: z.number(), // safe price (with safe deviation but without slippage)
}).optional(),
as: z.object({ // execution alternatives
e: z.string().array(), // exchanges
e: z.enum(exchanges).array(), // exchanges
ps: z.string().array(), // path
mo: z.number().optional(), // market amount out
mi: z.number().optional(), // market amount in

View File

@@ -100,8 +100,8 @@ export type SwapInfoBase = {
assetOut: string,
amountIn: number,
amountOut: number,
minAmounIn: number,
minAmounOut: number,
minAmountIn: number,
minAmountOut: number,
path: string[],
exchanges?: string[],