Skip to content

Commit

Permalink
feat: release for 0.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
EchoDex committed Oct 25, 2024
1 parent e4414fe commit af1a64d
Show file tree
Hide file tree
Showing 9 changed files with 609 additions and 138 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@compolabs/spark-orderbook-ts-sdk",
"version": "1.11.5",
"version": "1.12.0",
"type": "module",
"main": "./dist/index.сjs",
"module": "./dist/index.js",
Expand Down
36 changes: 34 additions & 2 deletions src/IndexerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
gql,
Observable,
} from "@apollo/client";
import { Undefinable } from "tsdef";

import BN from "./utils/BN";
import { generateWhereFilter } from "./utils/generateWhereFilter";
Expand All @@ -16,6 +17,8 @@ import {
Order,
OrderType,
TradeOrderEvent,
UserInfo,
UserInfoParams,
Volume,
} from "./interface";
import { getActiveOrdersQuery, getOrdersQuery } from "./query";
Expand Down Expand Up @@ -133,8 +136,6 @@ export class IndexerApi extends GraphClient {
},
});

console.log(response);

if (!response.data.TradeOrderEvent.length) {
return {
volume24h: BN.ZERO.toString(),
Expand Down Expand Up @@ -172,4 +173,35 @@ export class IndexerApi extends GraphClient {
low24h: data.low24h.toString(),
};
};

getUserInfo = async (
params: UserInfoParams,
): Promise<Undefinable<UserInfo>> => {
const query = gql`
query UserQuery($where: User_bool_exp) {
User(where: $where) {
id
active
canceled
closed
timestamp
}
}
`;

const response = await this.client.query<{
UserQuery: UserInfo[];
}>({
query,
variables: {
where: generateWhereFilter(params),
},
});

if (!response.data.UserQuery.length) {
return;
}

return response.data.UserQuery[0];
};
}
6 changes: 6 additions & 0 deletions src/ReadActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,10 @@ export class ReadActions {

return result.value.toString();
}

async fetchMinOrderPrice(): Promise<string> {
const result = await this.marketFactory.functions.min_order_price().get();

return result.value.toString();
}
}
11 changes: 11 additions & 0 deletions src/SparkOrderbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
SparkParams,
SpotOrderWithoutTimestamp,
TradeOrderEvent,
UserInfo,
UserInfoParams,
UserMarketBalance,
UserProtocolFee,
Volume,
Expand Down Expand Up @@ -239,6 +241,10 @@ export class SparkOrderbook {
return this.activeIndexerApi.getVolume(params);
}

async fetchUserInfo(params: UserInfoParams): Promise<Undefinable<UserInfo>> {
return this.activeIndexerApi.getUserInfo(params);
}

async fetchMarkets(assetIdPairs: [string, string][]): Promise<Markets> {
const read = await this.getRead();
return read.fetchMarkets(assetIdPairs);
Expand Down Expand Up @@ -321,6 +327,11 @@ export class SparkOrderbook {
return read.fetchMinOrderSize();
}

async fetchMinOrderPrice(): Promise<string> {
const read = await this.getRead();
return read.fetchMinOrderPrice();
}

/**
* @experimental
* Returns the current instance to allow method chaining.
Expand Down
12 changes: 12 additions & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,15 @@ export interface UserProtocolFee {
takerFee: string;
makerFee: string;
}

export interface UserInfoParams {
user: string;
}

export interface UserInfo {
id: string;
active: number;
canceled: number;
closed: number;
timestamp: string;
}
Loading

0 comments on commit af1a64d

Please sign in to comment.