Skip to content

Commit

Permalink
feat: update indexer query
Browse files Browse the repository at this point in the history
  • Loading branch information
EchoDex committed Oct 18, 2024
1 parent 186dba6 commit 5525f4c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 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.0",
"version": "1.11.1",
"type": "module",
"main": "./dist/index.сjs",
"module": "./dist/index.js",
Expand Down
24 changes: 17 additions & 7 deletions src/IndexerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,18 @@ export class IndexerApi extends GraphClient {
order_by: { timestamp: $orderBy }
) {
id
trade_price
trade_size
market
tradeSize
tradePrice
buyer
buyOrderId
buyerBaseAmount
buyerQuoteAmount
seller
sellOrderId
sellerBaseAmount
sellerQuoteAmount
sellerIsMaker
timestamp
}
}
Expand Down Expand Up @@ -123,15 +133,15 @@ export class IndexerApi extends GraphClient {
const query = gql`
query TradeOrderEventQuery($where: TradeOrderEvent_bool_exp) {
TradeOrderEvent(where: $where) {
trade_size
trade_price
tradeSize
tradePrice
}
}
`;

type TradeOrderEventPartial = Pick<
TradeOrderEvent,
"trade_size" | "trade_price"
"tradeSize" | "tradePrice"
>;

const response = await this.client.query<{
Expand All @@ -156,8 +166,8 @@ export class IndexerApi extends GraphClient {

const data = response.data.TradeOrderEvent.reduce(
(prev, currentData) => {
const price = BigInt(currentData.trade_price);
const size = BigInt(currentData.trade_size);
const price = BigInt(currentData.tradePrice);
const size = BigInt(currentData.tradeSize);
prev.volume24h += size;

if (prev.high24h < price) {
Expand Down
8 changes: 4 additions & 4 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ export interface Order {
id: string;
asset: string;
amount: string;
initial_amount: string;
order_type: OrderType;
initialAmount: string;
orderType: OrderType;
price: string;
status: Status;
user: string;
Expand All @@ -176,8 +176,8 @@ export interface GetTradeOrderEventsParams {
export interface TradeOrderEvent {
id: string;
timestamp: string;
trade_price: string;
trade_size: string;
tradePrice: string;
tradeSize: string;
}

export type Volume = {
Expand Down
12 changes: 6 additions & 6 deletions src/query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const getOrdersQuery = (
const where: any = {};

if (params.orderType) {
where.order_type = { _eq: params.orderType };
where.orderType = { _eq: params.orderType };
}

if (params.market) {
Expand Down Expand Up @@ -52,8 +52,8 @@ export const getOrdersQuery = (
id
asset
amount
initial_amount
order_type
initialAmount
orderType
price
status
user
Expand Down Expand Up @@ -81,7 +81,7 @@ export const getActiveOrdersQuery = (
const where: any = {};

if (params.orderType) {
where.order_type = { _eq: params.orderType };
where.orderType = { _eq: params.orderType };
}

if (params.market) {
Expand Down Expand Up @@ -114,8 +114,8 @@ export const getActiveOrdersQuery = (
id
asset
amount
initial_amount
order_type
initialAmount
orderType
price
status
user
Expand Down

0 comments on commit 5525f4c

Please sign in to comment.