mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-14 06:02:36 +03:00
CFD schema was updated
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.17.5",
|
||||
"version": "0.17.6-rc.0",
|
||||
"description": "Orion Protocol SDK",
|
||||
"main": "./lib/esm/index.js",
|
||||
"module": "./lib/esm/index.js",
|
||||
|
||||
@@ -8,6 +8,7 @@ const MessageType = {
|
||||
ASSET_PAIR_CONFIG_UPDATE: 'apiu',
|
||||
ADDRESS_UPDATE: 'au',
|
||||
CFD_ADDRESS_UPDATE: 'auf',
|
||||
FUTURES_TRADE_INFO_UPDATE: 'fti',
|
||||
BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATE: 'btasabu',
|
||||
UNSUBSCRIPTION_DONE: 'ud',
|
||||
} as const;
|
||||
|
||||
@@ -6,6 +6,7 @@ const SubscriptionType = {
|
||||
CFD_ADDRESS_UPDATES_SUBSCRIBE: 'ausf',
|
||||
BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATES_SUBSCRIBE: 'btasabus',
|
||||
SWAP_SUBSCRIBE: 'ss',
|
||||
FUTURES_TRADE_INFO_SUBSCRIBE: 'fts',
|
||||
} as const;
|
||||
|
||||
export default SubscriptionType;
|
||||
|
||||
@@ -11,12 +11,13 @@ import {
|
||||
import UnsubscriptionType from './UnsubscriptionType';
|
||||
import {
|
||||
SwapInfoByAmountIn, SwapInfoByAmountOut, SwapInfoBase,
|
||||
AssetPairUpdate, OrderbookItem, Balance, Exchange, CFDBalance,
|
||||
AssetPairUpdate, OrderbookItem, Balance, Exchange, CFDBalance, SwapInfo, FuturesTradeInfo,
|
||||
} from '../../../types';
|
||||
import unsubscriptionDoneSchema from './schemas/unsubscriptionDoneSchema';
|
||||
import assetPairConfigSchema from './schemas/assetPairConfigSchema';
|
||||
import { fullOrderSchema, orderUpdateSchema } from './schemas/addressUpdateSchema';
|
||||
import cfdAddressUpdateSchema from './schemas/cfdAddressUpdateSchema';
|
||||
import futuresTradeInfoSchema from './schemas/futuresTradeInfoSchema';
|
||||
// import errorSchema from './schemas/errorSchema';
|
||||
|
||||
const UNSUBSCRIBE = 'u';
|
||||
@@ -62,7 +63,17 @@ type AggregatedOrderbookSubscription = {
|
||||
|
||||
type SwapInfoSubscription = {
|
||||
payload: SwapSubscriptionRequest,
|
||||
callback: (swapInfo: SwapInfoByAmountIn | SwapInfoByAmountOut) => void,
|
||||
callback: (swapInfo: SwapInfo) => void,
|
||||
}
|
||||
|
||||
type FuturesTradeInfoSubscription = {
|
||||
payload: {
|
||||
S: string,
|
||||
i: string,
|
||||
a: number,
|
||||
p: boolean,
|
||||
},
|
||||
callback: (futuresTradeInfo: FuturesTradeInfo) => void,
|
||||
}
|
||||
|
||||
type AddressUpdateUpdate = {
|
||||
@@ -117,6 +128,7 @@ type Subscription = {
|
||||
[SubscriptionType.ASSET_PAIR_CONFIG_UPDATES_SUBSCRIBE]: PairConfigSubscription,
|
||||
[SubscriptionType.BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATES_SUBSCRIBE]: BrokerTradableAtomicSwapBalanceSubscription,
|
||||
[SubscriptionType.SWAP_SUBSCRIBE]: SwapInfoSubscription
|
||||
[SubscriptionType.FUTURES_TRADE_INFO_SUBSCRIBE]: FuturesTradeInfoSubscription
|
||||
}
|
||||
|
||||
const exclusiveSubscriptions = [
|
||||
@@ -272,6 +284,7 @@ class OrionAggregatorWS {
|
||||
// is swap info subscription (contains hyphen)
|
||||
delete this.subscriptions[SubscriptionType.SWAP_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
|
||||
} 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];
|
||||
@@ -339,6 +352,7 @@ class OrionAggregatorWS {
|
||||
brokerMessageSchema,
|
||||
orderBookSchema,
|
||||
swapInfoSchema,
|
||||
futuresTradeInfoSchema,
|
||||
errorSchema,
|
||||
unsubscriptionDoneSchema,
|
||||
]);
|
||||
@@ -413,6 +427,18 @@ class OrionAggregatorWS {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MessageType.FUTURES_TRADE_INFO_UPDATE:
|
||||
this.subscriptions[SubscriptionType.FUTURES_TRADE_INFO_SUBSCRIBE]?.[json.S]?.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:
|
||||
this.onInit?.();
|
||||
break;
|
||||
|
||||
@@ -33,7 +33,6 @@ export const orderUpdateSchema = z.object({
|
||||
A: z.number(), // settled amount
|
||||
S: z.enum(orderStatuses), // status
|
||||
l: z.boolean().optional(), // is liquidation order
|
||||
cl: z.boolean().optional(), // is closing
|
||||
t: z.number(), // update time
|
||||
c: subOrderSchema.array(),
|
||||
})
|
||||
@@ -46,7 +45,6 @@ export const orderUpdateSchema = z.object({
|
||||
settledAmount: o.A,
|
||||
status: o.S,
|
||||
liquidated: o.l,
|
||||
closing: o.cl,
|
||||
subOrders: o.c.map((so) => ({
|
||||
pair: so.P,
|
||||
exchange: so.e,
|
||||
@@ -71,7 +69,6 @@ export const fullOrderSchema = z.object({
|
||||
F: z.string(), // fee asset
|
||||
f: z.number(), // fee
|
||||
l: z.boolean().optional(), // is liquidation order
|
||||
cl: z.boolean().optional(), // is closing
|
||||
o: z.boolean(), // internal only
|
||||
S: z.enum(orderStatuses), // status
|
||||
T: z.number(), // creation time / unix timestamp
|
||||
@@ -87,7 +84,6 @@ export const fullOrderSchema = z.object({
|
||||
feeAsset: o.F,
|
||||
fee: o.f,
|
||||
liquidated: o.l,
|
||||
closing: o.cl,
|
||||
status: o.S,
|
||||
date: o.T,
|
||||
clientOrdId: o.O,
|
||||
|
||||
@@ -16,8 +16,6 @@ const cfdBalanceSchema = z
|
||||
mu: z.string(),
|
||||
fmu: z.string(),
|
||||
awb: z.string(),
|
||||
mli: z.string(),
|
||||
msi: z.string(),
|
||||
l: z.string(),
|
||||
s: z.enum(positionStatuses),
|
||||
})
|
||||
@@ -35,8 +33,6 @@ const cfdBalanceSchema = z
|
||||
marginUSD: obj.mu,
|
||||
freeMarginUSD: obj.fmu,
|
||||
availableWithdrawBalance: obj.awb,
|
||||
maxAvailableLong: obj.mli,
|
||||
maxAvailableShort: obj.msi,
|
||||
leverage: obj.l,
|
||||
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,
|
||||
freeMarginUSD: string,
|
||||
availableWithdrawBalance: string,
|
||||
maxAvailableLong: string,
|
||||
maxAvailableShort: string,
|
||||
leverage: string,
|
||||
status: PositionStatus,
|
||||
}
|
||||
@@ -236,6 +234,17 @@ export type SwapInfoByAmountOut = SwapInfoBase & {
|
||||
|
||||
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 {
|
||||
PENDING = 'Pending',
|
||||
DONE = 'Done',
|
||||
|
||||
Reference in New Issue
Block a user