Skip to content

feat: update functions and type according to latest espresso repo #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,785 changes: 2,321 additions & 1,464 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/client/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
GetAccountBalanceResponse,
GenerateNewAPIKeyResponse,
AccountBalance,
GetAPIKeyResponse,
// AccountStream,
// AccountBalanceStream,
} from '../../types';
Expand Down Expand Up @@ -65,6 +66,11 @@ export class Accounts extends Api {
return this.resolveAxiosData(res);
}

public getApiKey(): Promise<GetAPIKeyResponse> {
const res = this.axiosInstance.get('/accounts/api-key');
return this.resolveAxiosData(res);
}

public buildDepositTransaction(
data: BuildDepositTransactionRequest,
): Promise<BuildDepositTransactionResponse> {
Expand Down
7 changes: 6 additions & 1 deletion src/client/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AxiosInstance } from 'axios';
import { Api } from '../api';
import { GetTermsAndConditionResponse } from '../../types';
import { GetHydraCycleResponse, GetTermsAndConditionResponse } from '../../types';

export class App extends Api {
private axiosInstance: AxiosInstance;
Expand All @@ -14,4 +14,9 @@ export class App extends Api {
const res = this.axiosInstance.get('/app/terms-and-conditions');
return this.resolveAxiosData(res);
}

public getHydraCycle(): Promise<GetHydraCycleResponse> {
const res = this.axiosInstance.get('/app/hydra-cycle');
return this.resolveAxiosData(res);
}
}
22 changes: 19 additions & 3 deletions src/types/models/order.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type TradingSymbol = 'ADAUSDX';

export type OrderStatus = 'building' | 'open' | 'closed' | 'failed' | 'cancelled';
export type OrderStatus = 'building' | 'processing' | 'open' | 'closed' | 'failed' | 'cancelled';

export type OrderSide = 'buy' | 'sell';

Expand All @@ -16,18 +16,34 @@ export const OrderTypes = {
LimitOrder: 'limit' as OrderType,
};

export type OrderExecutionRole = 'maker' | 'taker';

export type OrderExecutionRecordJSON = {
id: string;
order_id: string;
execution_price: number;
filled_amount: string;
fee_unit: string;
fee_amount: string;
role: OrderExecutionRole;
counter_party_order_id: string;
create_time: number;
};

export type OrderJSON = {
order_id: string;
status: OrderStatus;
symbol: TradingSymbol;
orig_qty: string;
executed_qty: string;
side: OrderSide;
price: string;
price: number;
type: OrderType;
fee_amount: number;
fee_charged: string;
fee_unit: string;
executed_price: number;
slippage: string;
create_time: number;
update_time: number;
fills?: OrderExecutionRecordJSON[];
};
17 changes: 14 additions & 3 deletions src/types/requests/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Asset, UTxO } from '@meshsdk/core';
import { UTxO } from '@meshsdk/core';
import { TradingSymbol, OrderSide, OrderType } from '../models/order';

// SignInRequest to be refactored
Expand All @@ -12,6 +12,11 @@ export type SignInRequest = {
// quantity: number;
// };

export type Asset = {
unit: string;
quantity: string;
};

export type BuildDepositTransactionRequest = {
deposit_amount: Asset[];
input_utxos: UTxO[];
Expand All @@ -34,7 +39,7 @@ export type GetMarketDepthRequest = {
};

export type GetMarketPriceRequest = {
pair: string;
pair: TradingSymbol;
};

export type Interval = '15m' | '30m' | '1h' | '1d' | '1w' | '1M';
Expand All @@ -53,7 +58,7 @@ export type BuildPlaceOrderTransactionRequest = {
quantity: number;
price?: number;
max_slippage_basis_point?: number;
max_slippage?: boolean;
max_slippage: boolean;
};

export type PostOrderRequest = BuildPlaceOrderTransactionRequest;
Expand All @@ -70,3 +75,9 @@ export type BuildCancelOrderTransactionRequest = {
export type SubmitCancelOrderTransactionRequest = {
signed_tx: string;
};

export type Status = 'open' | 'closed';

export type GetOrderRecordRequest = {
status?: Status;
};
23 changes: 14 additions & 9 deletions src/types/responses/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ export type SignInResponse = {
// tx_hash: string;
// };

export type TransactionStatus =
| 'building'
| 'held_for_order'
| 'submitted'
| 'submission_failed'
| 'confirmed';
export type TransactionStatus = 'building' | 'submitted' | 'submission_failed' | 'confirmed';

export type DepositRecord = {
created_at: string;
Expand All @@ -53,6 +48,7 @@ export type GetOrderRecordResponse = {

export type WithdrawalRecord = {
created_at: string;
status: TransactionStatus;
assets: Asset[];
};

Expand All @@ -62,6 +58,7 @@ export type GetAccountBalanceResponse = AccountBalance[];

export type GenerateNewAPIKeyResponse = {
api_key: string;
created_at: string;
};

export type BuildDepositTransactionResponse = {
Expand All @@ -80,9 +77,7 @@ export type SubmitWithdrawalTransactionResponse = {
tx_hash: string;
};

export type GetTermsAndConditionResponse = {
value: string;
};
export type GetTermsAndConditionResponse = string;

export type MarketDepth = {
price: number;
Expand Down Expand Up @@ -128,3 +123,13 @@ export type BuildCancelOrderTransactionResponse = {
export type SubmitCancelOrderTransactionResponse = {
tx_hash: string;
};

export type GetAPIKeyResponse = {
api_key: string;
created_at: string;
};

export type GetHydraCycleResponse = {
start: string;
end: string;
};