mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-22 21:59:44 +03:00
Merge
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@orionprotocol/sdk",
|
"name": "@orionprotocol/sdk",
|
||||||
"version": "0.17.7-rc.2",
|
"version": "0.17.7-rc.3",
|
||||||
"description": "Orion Protocol SDK",
|
"description": "Orion Protocol SDK",
|
||||||
"main": "./lib/esm/index.js",
|
"main": "./lib/esm/index.js",
|
||||||
"module": "./lib/esm/index.js",
|
"module": "./lib/esm/index.js",
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const MessageType = {
|
|||||||
ASSET_PAIR_CONFIG_UPDATE: 'apiu',
|
ASSET_PAIR_CONFIG_UPDATE: 'apiu',
|
||||||
ADDRESS_UPDATE: 'au',
|
ADDRESS_UPDATE: 'au',
|
||||||
CFD_ADDRESS_UPDATE: 'auf',
|
CFD_ADDRESS_UPDATE: 'auf',
|
||||||
|
FUTURES_TRADE_INFO_UPDATE: 'fti',
|
||||||
BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATE: 'btasabu',
|
BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATE: 'btasabu',
|
||||||
UNSUBSCRIPTION_DONE: 'ud',
|
UNSUBSCRIPTION_DONE: 'ud',
|
||||||
} as const;
|
} as const;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const SubscriptionType = {
|
|||||||
CFD_ADDRESS_UPDATES_SUBSCRIBE: 'ausf',
|
CFD_ADDRESS_UPDATES_SUBSCRIBE: 'ausf',
|
||||||
BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATES_SUBSCRIBE: 'btasabus',
|
BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATES_SUBSCRIBE: 'btasabus',
|
||||||
SWAP_SUBSCRIBE: 'ss',
|
SWAP_SUBSCRIBE: 'ss',
|
||||||
|
FUTURES_TRADE_INFO_SUBSCRIBE: 'fts',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export default SubscriptionType;
|
export default SubscriptionType;
|
||||||
|
|||||||
@@ -10,13 +10,14 @@ import {
|
|||||||
} from './schemas';
|
} from './schemas';
|
||||||
import UnsubscriptionType from './UnsubscriptionType';
|
import UnsubscriptionType from './UnsubscriptionType';
|
||||||
import {
|
import {
|
||||||
type SwapInfoByAmountIn, type SwapInfoByAmountOut, type SwapInfoBase,
|
type SwapInfoBase, type AssetPairUpdate, type OrderbookItem,
|
||||||
type AssetPairUpdate, type OrderbookItem, type Balance, type Exchange, type CFDBalance,
|
type Balance, type Exchange, type CFDBalance, type FuturesTradeInfo, type SwapInfo,
|
||||||
} from '../../../types';
|
} from '../../../types';
|
||||||
import unsubscriptionDoneSchema from './schemas/unsubscriptionDoneSchema';
|
import unsubscriptionDoneSchema from './schemas/unsubscriptionDoneSchema';
|
||||||
import assetPairConfigSchema from './schemas/assetPairConfigSchema';
|
import assetPairConfigSchema from './schemas/assetPairConfigSchema';
|
||||||
import { type fullOrderSchema, type orderUpdateSchema } from './schemas/addressUpdateSchema';
|
import { type fullOrderSchema, type orderUpdateSchema } from './schemas/addressUpdateSchema';
|
||||||
import cfdAddressUpdateSchema from './schemas/cfdAddressUpdateSchema';
|
import cfdAddressUpdateSchema from './schemas/cfdAddressUpdateSchema';
|
||||||
|
import futuresTradeInfoSchema from './schemas/futuresTradeInfoSchema';
|
||||||
// import errorSchema from './schemas/errorSchema';
|
// import errorSchema from './schemas/errorSchema';
|
||||||
|
|
||||||
const UNSUBSCRIBE = 'u';
|
const UNSUBSCRIBE = 'u';
|
||||||
@@ -62,7 +63,17 @@ type AggregatedOrderbookSubscription = {
|
|||||||
|
|
||||||
type SwapInfoSubscription = {
|
type SwapInfoSubscription = {
|
||||||
payload: SwapSubscriptionRequest
|
payload: SwapSubscriptionRequest
|
||||||
callback: (swapInfo: SwapInfoByAmountIn | SwapInfoByAmountOut) => void
|
callback: (swapInfo: SwapInfo) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
type FuturesTradeInfoSubscription = {
|
||||||
|
payload: {
|
||||||
|
s: string
|
||||||
|
i: string
|
||||||
|
a: number
|
||||||
|
p?: number
|
||||||
|
}
|
||||||
|
callback: (futuresTradeInfo: FuturesTradeInfo) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddressUpdateUpdate = {
|
type AddressUpdateUpdate = {
|
||||||
@@ -117,6 +128,7 @@ type Subscription = {
|
|||||||
[SubscriptionType.ASSET_PAIR_CONFIG_UPDATES_SUBSCRIBE]: PairConfigSubscription
|
[SubscriptionType.ASSET_PAIR_CONFIG_UPDATES_SUBSCRIBE]: PairConfigSubscription
|
||||||
[SubscriptionType.BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATES_SUBSCRIBE]: BrokerTradableAtomicSwapBalanceSubscription
|
[SubscriptionType.BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATES_SUBSCRIBE]: BrokerTradableAtomicSwapBalanceSubscription
|
||||||
[SubscriptionType.SWAP_SUBSCRIBE]: SwapInfoSubscription
|
[SubscriptionType.SWAP_SUBSCRIBE]: SwapInfoSubscription
|
||||||
|
[SubscriptionType.FUTURES_TRADE_INFO_SUBSCRIBE]: FuturesTradeInfoSubscription
|
||||||
}
|
}
|
||||||
|
|
||||||
const exclusiveSubscriptions = [
|
const exclusiveSubscriptions = [
|
||||||
@@ -272,6 +284,7 @@ class OrionAggregatorWS {
|
|||||||
// is swap info subscription (contains hyphen)
|
// is swap info subscription (contains hyphen)
|
||||||
delete this.subscriptions[SubscriptionType.SWAP_SUBSCRIBE]?.[subscription];
|
delete this.subscriptions[SubscriptionType.SWAP_SUBSCRIBE]?.[subscription];
|
||||||
delete this.subscriptions[SubscriptionType.ASSET_PAIR_CONFIG_UPDATES_SUBSCRIBE]?.[subscription];
|
delete this.subscriptions[SubscriptionType.ASSET_PAIR_CONFIG_UPDATES_SUBSCRIBE]?.[subscription];
|
||||||
|
delete this.subscriptions[SubscriptionType.FUTURES_TRADE_INFO_SUBSCRIBE]?.[subscription];
|
||||||
// !!! swap info subscription is uuid that contains hyphen
|
// !!! swap info subscription is uuid that contains hyphen
|
||||||
} else if (subscription.includes('-') && subscription.split('-').length === 2) { // is pair name(AGGREGATED_ORDER_BOOK_UPDATE)
|
} 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];
|
const aobSubscriptions = this.subscriptions[SubscriptionType.AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE];
|
||||||
@@ -340,6 +353,7 @@ class OrionAggregatorWS {
|
|||||||
brokerMessageSchema,
|
brokerMessageSchema,
|
||||||
orderBookSchema,
|
orderBookSchema,
|
||||||
swapInfoSchema,
|
swapInfoSchema,
|
||||||
|
futuresTradeInfoSchema,
|
||||||
errorSchema,
|
errorSchema,
|
||||||
unsubscriptionDoneSchema,
|
unsubscriptionDoneSchema,
|
||||||
]);
|
]);
|
||||||
@@ -414,6 +428,18 @@ class OrionAggregatorWS {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case MessageType.FUTURES_TRADE_INFO_UPDATE:
|
||||||
|
this.subscriptions[SubscriptionType.FUTURES_TRADE_INFO_SUBSCRIBE]?.[json.id]?.callback({
|
||||||
|
futuresTradeRequestId: json.id,
|
||||||
|
sender: json.S,
|
||||||
|
instrument: json.i,
|
||||||
|
buyPrice: json.bp,
|
||||||
|
sellPrice: json.sp,
|
||||||
|
buyPower: json.bpw,
|
||||||
|
sellPower: json.spw,
|
||||||
|
minAmount: json.ma,
|
||||||
|
});
|
||||||
|
break;
|
||||||
case MessageType.INITIALIZATION:
|
case MessageType.INITIALIZATION:
|
||||||
this.onInit?.();
|
this.onInit?.();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ export const orderUpdateSchema = z.object({
|
|||||||
A: z.number(), // settled amount
|
A: z.number(), // settled amount
|
||||||
S: z.enum(orderStatuses), // status
|
S: z.enum(orderStatuses), // status
|
||||||
l: z.boolean().optional(), // is liquidation order
|
l: z.boolean().optional(), // is liquidation order
|
||||||
cl: z.boolean().optional(), // is closing
|
|
||||||
t: z.number(), // update time
|
t: z.number(), // update time
|
||||||
c: subOrderSchema.array(),
|
c: subOrderSchema.array(),
|
||||||
})
|
})
|
||||||
@@ -46,7 +45,6 @@ export const orderUpdateSchema = z.object({
|
|||||||
settledAmount: o.A,
|
settledAmount: o.A,
|
||||||
status: o.S,
|
status: o.S,
|
||||||
liquidated: o.l,
|
liquidated: o.l,
|
||||||
closing: o.cl,
|
|
||||||
subOrders: o.c.map((so) => ({
|
subOrders: o.c.map((so) => ({
|
||||||
pair: so.P,
|
pair: so.P,
|
||||||
exchange: so.e,
|
exchange: so.e,
|
||||||
@@ -71,7 +69,6 @@ export const fullOrderSchema = z.object({
|
|||||||
F: z.string(), // fee asset
|
F: z.string(), // fee asset
|
||||||
f: z.number(), // fee
|
f: z.number(), // fee
|
||||||
l: z.boolean().optional(), // is liquidation order
|
l: z.boolean().optional(), // is liquidation order
|
||||||
cl: z.boolean().optional(), // is closing
|
|
||||||
o: z.boolean(), // internal only
|
o: z.boolean(), // internal only
|
||||||
S: z.enum(orderStatuses), // status
|
S: z.enum(orderStatuses), // status
|
||||||
T: z.number(), // creation time / unix timestamp
|
T: z.number(), // creation time / unix timestamp
|
||||||
@@ -87,7 +84,6 @@ export const fullOrderSchema = z.object({
|
|||||||
feeAsset: o.F,
|
feeAsset: o.F,
|
||||||
fee: o.f,
|
fee: o.f,
|
||||||
liquidated: o.l,
|
liquidated: o.l,
|
||||||
closing: o.cl,
|
|
||||||
status: o.S,
|
status: o.S,
|
||||||
date: o.T,
|
date: o.T,
|
||||||
clientOrdId: o.O,
|
clientOrdId: o.O,
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ const cfdBalanceSchema = z
|
|||||||
mu: z.string(),
|
mu: z.string(),
|
||||||
fmu: z.string(),
|
fmu: z.string(),
|
||||||
awb: z.string(),
|
awb: z.string(),
|
||||||
mli: z.string(),
|
|
||||||
msi: z.string(),
|
|
||||||
l: z.string(),
|
l: z.string(),
|
||||||
s: z.enum(positionStatuses),
|
s: z.enum(positionStatuses),
|
||||||
})
|
})
|
||||||
@@ -35,8 +33,6 @@ const cfdBalanceSchema = z
|
|||||||
marginUSD: obj.mu,
|
marginUSD: obj.mu,
|
||||||
freeMarginUSD: obj.fmu,
|
freeMarginUSD: obj.fmu,
|
||||||
availableWithdrawBalance: obj.awb,
|
availableWithdrawBalance: obj.awb,
|
||||||
maxAvailableLong: obj.mli,
|
|
||||||
maxAvailableShort: obj.msi,
|
|
||||||
leverage: obj.l,
|
leverage: obj.l,
|
||||||
status: obj.s,
|
status: obj.s,
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { z } from 'zod';
|
||||||
|
import MessageType from '../MessageType';
|
||||||
|
|
||||||
|
const futuresTradeInfoSchema = z.object({
|
||||||
|
T: z.literal(MessageType.FUTURES_TRADE_INFO_UPDATE),
|
||||||
|
id: z.string(), // trade info request UUID, set by client side
|
||||||
|
S: z.string(), // sender
|
||||||
|
i: z.string(), // instrument
|
||||||
|
bp: z.number(), // buy price
|
||||||
|
sp: z.number(), // sell price
|
||||||
|
bpw: z.number(), // buy power
|
||||||
|
spw: z.number(), // sell power
|
||||||
|
ma: z.number(), // min amount
|
||||||
|
});
|
||||||
|
|
||||||
|
export default futuresTradeInfoSchema;
|
||||||
13
src/types.ts
13
src/types.ts
@@ -47,8 +47,6 @@ export type CFDBalance = {
|
|||||||
marginUSD: string
|
marginUSD: string
|
||||||
freeMarginUSD: string
|
freeMarginUSD: string
|
||||||
availableWithdrawBalance: string
|
availableWithdrawBalance: string
|
||||||
maxAvailableLong: string
|
|
||||||
maxAvailableShort: string
|
|
||||||
leverage: string
|
leverage: string
|
||||||
status: PositionStatus
|
status: PositionStatus
|
||||||
}
|
}
|
||||||
@@ -236,6 +234,17 @@ export type SwapInfoByAmountOut = SwapInfoBase & {
|
|||||||
|
|
||||||
export type SwapInfo = SwapInfoByAmountIn | SwapInfoByAmountOut;
|
export type SwapInfo = SwapInfoByAmountIn | SwapInfoByAmountOut;
|
||||||
|
|
||||||
|
export type FuturesTradeInfo = {
|
||||||
|
futuresTradeRequestId: string
|
||||||
|
sender: string
|
||||||
|
instrument: string
|
||||||
|
buyPrice: number
|
||||||
|
sellPrice: number
|
||||||
|
buyPower: number
|
||||||
|
sellPower: number
|
||||||
|
minAmount: number
|
||||||
|
}
|
||||||
|
|
||||||
export enum HistoryTransactionStatus {
|
export enum HistoryTransactionStatus {
|
||||||
PENDING = 'Pending',
|
PENDING = 'Pending',
|
||||||
DONE = 'Done',
|
DONE = 'Done',
|
||||||
|
|||||||
Reference in New Issue
Block a user