mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-28 16:48:00 +03:00
feat: add pair config subscription
This commit is contained in:
@@ -5,6 +5,7 @@ const MessageType = {
|
||||
INITIALIZATION: 'i',
|
||||
AGGREGATED_ORDER_BOOK_UPDATE: 'aobu',
|
||||
ASSET_PAIRS_CONFIG_UPDATE: 'apcu',
|
||||
ASSET_PAIR_CONFIG_UPDATE: 'apiu',
|
||||
ADDRESS_UPDATE: 'au',
|
||||
BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATE: 'btasabu',
|
||||
UNSUBSCRIPTION_DONE: 'ud',
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const SubscriptionType = {
|
||||
ASSET_PAIRS_CONFIG_UPDATES_SUBSCRIBE: 'apcus',
|
||||
ASSET_PAIR_CONFIG_UPDATES_SUBSCRIBE: 'apius',
|
||||
AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE: 'aobus',
|
||||
ADDRESS_UPDATES_SUBSCRIBE: 'aus',
|
||||
BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATES_SUBSCRIBE: 'btasabus',
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
FullOrder, OrderUpdate, AssetPairUpdate, OrderbookItem, Balance, Exchange,
|
||||
} from '../../../types';
|
||||
import unsubscriptionDoneSchema from './schemas/unsubscriptionDoneSchema';
|
||||
import assetPairConfigSchema from './schemas/assetPairConfigSchema';
|
||||
// import errorSchema from './schemas/errorSchema';
|
||||
|
||||
const mapFullOrder = (o: z.infer<typeof fullOrderSchema>): FullOrder => ({
|
||||
@@ -77,13 +78,19 @@ type BrokerTradableAtomicSwapBalanceSubscription = {
|
||||
callback: (balances: Partial<Record<string, number>>) => void,
|
||||
}
|
||||
|
||||
type PairConfigSubscription = {
|
||||
type PairsConfigSubscription = {
|
||||
callback: ({ kind, data }: {
|
||||
kind: 'initial' | 'update',
|
||||
data: Partial<Record<string, AssetPairUpdate>>,
|
||||
}) => void,
|
||||
}
|
||||
|
||||
type PairConfigSubscription = {
|
||||
callback: ({ data }: {
|
||||
data: AssetPairUpdate,
|
||||
}) => void,
|
||||
}
|
||||
|
||||
type AggregatedOrderbookSubscription = {
|
||||
payload: string,
|
||||
callback: (
|
||||
@@ -128,7 +135,8 @@ type AddressUpdateSubscription = {
|
||||
type Subscription = {
|
||||
[SubscriptionType.ADDRESS_UPDATES_SUBSCRIBE]: AddressUpdateSubscription,
|
||||
[SubscriptionType.AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE]: AggregatedOrderbookSubscription,
|
||||
[SubscriptionType.ASSET_PAIRS_CONFIG_UPDATES_SUBSCRIBE]: PairConfigSubscription,
|
||||
[SubscriptionType.ASSET_PAIRS_CONFIG_UPDATES_SUBSCRIBE]: PairsConfigSubscription,
|
||||
[SubscriptionType.ASSET_PAIR_CONFIG_UPDATES_SUBSCRIBE]: PairConfigSubscription,
|
||||
[SubscriptionType.BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATES_SUBSCRIBE]: BrokerTradableAtomicSwapBalanceSubscription,
|
||||
[SubscriptionType.SWAP_SUBSCRIBE]: SwapInfoSubscription
|
||||
}
|
||||
@@ -243,8 +251,10 @@ class OrionAggregatorWS {
|
||||
delete this.subscriptions[SubscriptionType.ADDRESS_UPDATES_SUBSCRIBE]?.[key];
|
||||
}
|
||||
}
|
||||
} else if (uuidValidate(subscription)) { // is swap info subscription (contains hyphen)
|
||||
} else if (uuidValidate(subscription)) {
|
||||
// is swap info subscription (contains hyphen)
|
||||
delete this.subscriptions[SubscriptionType.SWAP_SUBSCRIBE]?.[subscription];
|
||||
delete this.subscriptions[SubscriptionType.ASSET_PAIR_CONFIG_UPDATES_SUBSCRIBE]?.[subscription];
|
||||
// !!! swap info subscription is uuid that contains hyphen
|
||||
} else if (subscription.includes('-') && subscription.split('-').length === 2) { // is pair name(AGGREGATED_ORDER_BOOK_UPDATE)
|
||||
const aobSubscriptions = this.subscriptions[SubscriptionType.AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE];
|
||||
@@ -305,6 +315,7 @@ class OrionAggregatorWS {
|
||||
pingPongMessageSchema,
|
||||
addressUpdateSchema,
|
||||
assetPairsConfigSchema,
|
||||
assetPairConfigSchema,
|
||||
brokerMessageSchema,
|
||||
orderBookSchema,
|
||||
swapInfoSchema,
|
||||
@@ -407,6 +418,16 @@ class OrionAggregatorWS {
|
||||
);
|
||||
}
|
||||
break;
|
||||
case MessageType.ASSET_PAIR_CONFIG_UPDATE: {
|
||||
const pair = json;
|
||||
const [, minQty, pricePrecision] = pair.u;
|
||||
|
||||
this.subscriptions[SubscriptionType.ASSET_PAIR_CONFIG_UPDATES_SUBSCRIBE]?.[json.id]?.callback({
|
||||
data: { minQty, pricePrecision },
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
case MessageType.ASSET_PAIRS_CONFIG_UPDATE: {
|
||||
const pairs = json;
|
||||
const priceUpdates: Partial<Record<string, AssetPairUpdate>> = {};
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { z } from 'zod';
|
||||
import MessageType from '../MessageType';
|
||||
import baseMessageSchema from './baseMessageSchema';
|
||||
|
||||
const assetPairConfigSchema = baseMessageSchema.extend({
|
||||
id: z.string(),
|
||||
T: z.literal(MessageType.ASSET_PAIR_CONFIG_UPDATE),
|
||||
u: z.tuple([
|
||||
z.string(), // pairName
|
||||
z.number(), // minQty
|
||||
z.number(), // pricePrecision
|
||||
]),
|
||||
});
|
||||
|
||||
export default assetPairConfigSchema;
|
||||
Reference in New Issue
Block a user