From af70f5c3e0a1030879832e1555ea8f5c5056ca4a Mon Sep 17 00:00:00 2001 From: Demid Date: Tue, 10 Jan 2023 13:54:40 +0300 Subject: [PATCH] updated schemas, updated version --- package.json | 2 +- src/services/OrionAggregator/index.ts | 32 ++++++++++++++++++- .../ws/schemas/cfdBalancesSchema.ts | 12 +++---- .../OrionAggregator/ws/schemas/index.ts | 1 + src/types.ts | 12 +++---- 5 files changed, 45 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 7df7bad..8987074 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.16.0-rc.12", + "version": "0.16.0-rc.13", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", diff --git a/src/services/OrionAggregator/index.ts b/src/services/OrionAggregator/index.ts index 066470e..ac6b18f 100644 --- a/src/services/OrionAggregator/index.ts +++ b/src/services/OrionAggregator/index.ts @@ -9,7 +9,7 @@ import errorSchema from './schemas/errorSchema'; import placeAtomicSwapSchema from './schemas/placeAtomicSwapSchema'; import { OrionAggregatorWS } from './ws'; import { atomicSwapHistorySchema } from './schemas/atomicSwapHistorySchema'; -import { Exchange, SignedCancelOrderRequest, SignedOrder } from '../../types'; +import {Exchange, SignedCancelOrderRequest, SignedCFDOrder, SignedOrder} from '../../types'; import { pairConfigSchema } from './schemas'; import { aggregatedOrderbookSchema, exchangeOrderbookSchema, poolReservesSchema, @@ -34,6 +34,7 @@ class OrionAggregator { this.getTradeProfits = this.getTradeProfits.bind(this); this.placeAtomicSwap = this.placeAtomicSwap.bind(this); this.placeOrder = this.placeOrder.bind(this); + this.placeCFDOrder = this.placeCFDOrder.bind(this); this.cancelOrder = this.cancelOrder.bind(this); this.checkWhitelisted = this.checkWhitelisted.bind(this); this.getLockedBalance = this.getLockedBalance.bind(this); @@ -172,6 +173,35 @@ class OrionAggregator { errorSchema, ); + placeCFDOrder = ( + signedOrder: SignedCFDOrder + ) => { + const headers = { + 'Content-Type': 'application/json', + Accept: 'application/json', + }; + + return fetchWithValidation( + `${this.apiUrl}/api/v1/order/futures`, + z.object({ + orderId: z.string(), + placementRequests: z.array( + z.object({ + amount: z.number(), + brokerAddress: z.string(), + exchange: z.string(), + }), + ).optional(), + }), + { + headers, + method: 'POST', + body: JSON.stringify(signedOrder), + }, + errorSchema, + ); + }; + getSwapInfo = ( type: 'exactSpend' | 'exactReceive', assetIn: string, diff --git a/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts b/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts index 8a49ad3..12de05f 100644 --- a/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts +++ b/src/services/OrionAggregator/ws/schemas/cfdBalancesSchema.ts @@ -2,12 +2,12 @@ import { z } from 'zod'; const cfdBalanceSchema = z.object({ i: z.string(), - b: z.number(), - p: z.number(), - pp: z.number(), - fr: z.number(), - sfrl: z.number(), - lfrl: z.number(), + b: z.string(), + p: z.string(), + pp: z.string(), + fr: z.string(), + sfrl: z.string(), + lfrl: z.string(), }) .transform((obj) => ({ instrument: obj.i, diff --git a/src/services/OrionAggregator/ws/schemas/index.ts b/src/services/OrionAggregator/ws/schemas/index.ts index a0ca21d..36743dc 100644 --- a/src/services/OrionAggregator/ws/schemas/index.ts +++ b/src/services/OrionAggregator/ws/schemas/index.ts @@ -7,5 +7,6 @@ export { default as initMessageSchema } from './initMessageSchema'; export { default as pingPongMessageSchema } from './pingPongMessageSchema'; export { default as swapInfoSchema } from './swapInfoSchema'; export { default as balancesSchema } from './balancesSchema'; +export { default as cfdBalancesSchema } from './cfdBalancesSchema'; export * from './orderBookSchema'; diff --git a/src/types.ts b/src/types.ts index be9482b..2f11b49 100644 --- a/src/types.ts +++ b/src/types.ts @@ -28,12 +28,12 @@ export type Balance = { export type CFDBalance = { instrument: string, - balance: number, - position: number, - positionPrice: number, - fundingRate: number, - lastShortFundingRate: number, - lastLongFundingRate: number, + balance: string, + position: string, + positionPrice: string, + fundingRate: string, + lastShortFundingRate: string, + lastLongFundingRate: string, } export interface Order {