mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-17 08:41:38 +03:00
Exchange enum
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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[],
|
||||
|
||||
Reference in New Issue
Block a user