Skip to content

Commit

Permalink
change futuresTradesStreamSchema.ts (Real Time Trades)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJuze committed Mar 1, 2024
1 parent 30bde57 commit efce193
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package",
"name": "@electra.finance/sdk",
"version": "0.2.13",
"version": "0.2.14-rc100",
"description": "Electra finance SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { default as orderStatuses } from './orderStatuses.js';
export { default as subOrderStatuses } from './subOrderStatuses.js';
export { default as networkCodes } from './networkCodes.js';

export * from './orderSides';
export * from './chains.js';
export * from './precisions.js';
export * from './gasLimits.js';
Expand Down
4 changes: 4 additions & 0 deletions src/constants/orderSides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const orderSides = [
'SELL',
'BUY'
] as const
1 change: 1 addition & 0 deletions src/services/Aggregator/ws/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ class AggregatorWS {
id: json.id,
instrument: json.i,
side: json.s,
positionSide: json.ps,
amount: json.a,
leverage: json.l,
price: json.p,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { z } from 'zod';
import MessageType from '../MessageType.js';
import { positionSides } from '../../../../constants/positionStatuses';
import { networkCodes } from '../../../../constants';
import { networkCodes, orderSides } from '../../../../constants';
import addressSchema from '../../../../addressSchema';
// import addressSchema from '../../../../addressSchema';

export const futuresTradesStreamSchema = z.object({
T: z.literal(MessageType.FUTURES_TRADES_STREAM_UPDATE), // futures trades stream update
_: z.number(), // timestamp
S: z.string(), // sender // TODO: change to addressSchema
S: addressSchema, // sender
id: z.string(), // request id
i: z.string(), // instrument
s: z.enum(positionSides), // trade side (LONG/SHORT)
s: z.enum(orderSides), // trade side (SELL/BUY)
ps: z.enum(positionSides), // trade side (SELL/BUY)
a: z.string(), // trade amount
l: z.string(), // leverage
p: z.string(), // price
Expand Down
6 changes: 4 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type subOrderStatuses from './constants/subOrderStatuses.js';
import type positionStatuses from './constants/positionStatuses.js';
import type { positionSides } from './constants/positionStatuses.js';
import type { knownEnvs } from './config/schemas';
import type { networkCodes } from './constants';
import type { orderSides, networkCodes } from './constants';

export type DeepPartial<T> = T extends object ? {
[P in keyof T]?: DeepPartial<T[P]>;
Expand Down Expand Up @@ -34,6 +34,7 @@ export type Balance = {
allowance: string
}

export type OrderSide = typeof orderSides[number];
export type PositionSide = typeof positionSides[number];
export type PositionStatus = typeof positionStatuses[number];

Expand Down Expand Up @@ -260,7 +261,8 @@ export type FuturesTradesStream = {
sender: string
id: string
instrument: string
side: PositionSide
side: OrderSide
positionSide: PositionSide
amount: string
leverage: string
price: string
Expand Down

0 comments on commit efce193

Please sign in to comment.