Merge branch 'main' into futures_list

# Conflicts:
#	package.json
#	src/services/OrionAggregator/ws/index.ts
#	src/types.ts
This commit is contained in:
Mikhail Gladchenko
2023-01-10 09:23:14 +00:00
8 changed files with 125 additions and 83 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,11 +16,25 @@ 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.array(z.enum(exchanges)),
path: z.object({
units: z.object({
assetPair: z.string(),
action: z.string(),
}).array(),
}),
marketAmountOut: z.number().optional(),
marketAmountIn: z.number().optional(),
marketPrice: z.number(),
availableAmountIn: z.number().optional(),
availableAmountOut: z.number().optional(),
}).array(),
});
const swapInfoByAmountIn = swapInfoBase.extend({

View File

@@ -11,10 +11,11 @@ import {
import UnsubscriptionType from './UnsubscriptionType';
import {
SwapInfoByAmountIn, SwapInfoByAmountOut, SwapInfoBase,
FullOrder, OrderUpdate, AssetPairUpdate, OrderbookItem, Balance, Exchange, CFDBalance,
AssetPairUpdate, OrderbookItem, Balance, Exchange, CFDBalance,
} from '../../../types';
import unsubscriptionDoneSchema from './schemas/unsubscriptionDoneSchema';
import assetPairConfigSchema from './schemas/assetPairConfigSchema';
import { fullOrderSchema, orderUpdateSchema } from './schemas/addressUpdateSchema';
import cfdAddressUpdateSchema from "./schemas/cfdAddressUpdateSchema";
// import errorSchema from './schemas/errorSchema';
@@ -72,7 +73,7 @@ type AddressUpdateUpdate = {
Balance
>
>,
order?: OrderUpdate | FullOrder
order?: z.infer<typeof orderUpdateSchema> | z.infer<typeof fullOrderSchema>
}
type AddressUpdateInitial = {
@@ -83,7 +84,7 @@ type AddressUpdateInitial = {
Balance
>
>,
orders?: FullOrder[] // The field is not defined if the user has no orders
orders?: z.infer<typeof fullOrderSchema>[] // The field is not defined if the user has no orders
}
type CfdAddressUpdateUpdate = {
@@ -337,8 +338,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,
@@ -350,6 +351,15 @@ class OrionAggregatorWS {
safePrice: json.oi.sp,
},
},
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
@@ -503,7 +513,7 @@ class OrionAggregatorWS {
switch (json.k) { // message kind
case 'i': { // initial
const fullOrders = json.o
? json.o.reduce<FullOrder[]>((prev, o) => {
? json.o.reduce<z.infer<typeof fullOrderSchema>[]>((prev, o) => {
prev.push(o);
return prev;
@@ -520,7 +530,7 @@ class OrionAggregatorWS {
}
break;
case 'u': { // update
let orderUpdate: OrderUpdate | FullOrder | undefined;
let orderUpdate: z.infer<typeof orderUpdateSchema> | z.infer<typeof fullOrderSchema> | undefined;
if (json.o) {
const firstOrder = json.o[0];
orderUpdate = firstOrder;

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

@@ -23,6 +23,15 @@ const swapInfoSchemaBase = baseMessageSchema.extend({
a: z.number(), // amount
sp: z.number(), // safe price (with safe deviation but without slippage)
}).optional(),
as: z.object({ // execution alternatives
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
mp: z.number(), // market price
aa: z.number().optional(), // available amount in
aao: z.number().optional(), // available amount out
}).array(),
});
const swapInfoSchemaByAmountIn = swapInfoSchemaBase.extend({

View File

@@ -1,18 +1,6 @@
import BigNumber from 'bignumber.js';
import { z } from 'zod';
import exchanges from './constants/exchanges';
import subOrderStatuses from './constants/subOrderStatuses';
import { fullOrderSchema, orderUpdateSchema } from './services/OrionAggregator/ws/schemas/addressUpdateSchema';
export type OrderbookItem = {
price: string,
amount: string,
exchanges: string[],
vob: {
side: 'BUY' | 'SELL',
pairName: string
}[]
}
export type AssetPairUpdate = {
minQty: number,
@@ -29,9 +17,6 @@ export type SubOrder = {
side: 'BUY' | 'SELL',
subOrdQty: number
}
export type FullOrder = z.infer<typeof fullOrderSchema>;
export type OrderUpdate = z.infer<typeof orderUpdateSchema>;
export type Balance = {
tradable: string,
@@ -114,43 +99,6 @@ export interface Pair {
vol24h: string;
}
export type SwapInfoBase = {
swapRequestId: string,
assetIn: string,
assetOut: string,
amountIn: number,
amountOut: number,
minAmounIn: number,
minAmounOut: number,
path: string[],
exchanges?: string[],
poolOptimal: boolean,
price?: number,
marketPrice?: number,
orderInfo?: {
pair: string,
side: 'BUY' | 'SELL',
amount: number,
safePrice: number,
}
}
export type SwapInfoByAmountIn = SwapInfoBase & {
kind: 'exactSpend',
availableAmountIn?: number,
marketAmountOut?: number,
}
export type SwapInfoByAmountOut = SwapInfoBase & {
kind: 'exactReceive',
marketAmountIn?: number,
availableAmountOut?: number,
}
export type SwapInfo = SwapInfoByAmountIn | SwapInfoByAmountOut;
export enum SupportedChainId {
MAINNET = '1',
ROPSTEN = '3',
@@ -213,6 +161,64 @@ export type BalanceIssue = {
export type Exchange = typeof exchanges[number];
export type OrderbookItem = {
price: string,
amount: string,
exchanges: Exchange[],
vob: {
side: 'BUY' | 'SELL',
pairName: string
}[]
}
export type SwapInfoAlternative = {
exchanges: Exchange[],
path: string[],
marketAmountOut?: number,
marketAmountIn?: number,
marketPrice: number,
availableAmountIn?: number,
availableAmountOut?: number,
}
export type SwapInfoBase = {
swapRequestId: string,
assetIn: string,
assetOut: string,
amountIn: number,
amountOut: number,
minAmountIn: number,
minAmountOut: number,
path: string[],
exchanges?: Exchange[],
poolOptimal: boolean,
price?: number,
marketPrice?: number,
orderInfo?: {
pair: string,
side: 'BUY' | 'SELL',
amount: number,
safePrice: number,
},
alternatives: SwapInfoAlternative[],
}
export type SwapInfoByAmountIn = SwapInfoBase & {
kind: 'exactSpend',
availableAmountIn?: number,
marketAmountOut?: number,
}
export type SwapInfoByAmountOut = SwapInfoBase & {
kind: 'exactReceive',
marketAmountIn?: number,
availableAmountOut?: number,
}
export type SwapInfo = SwapInfoByAmountIn | SwapInfoByAmountOut;
export enum HistoryTransactionStatus {
PENDING = 'Pending',
DONE = 'Done',