Skip to content

Commit

Permalink
Merge pull request #1 from jamesbuch/development
Browse files Browse the repository at this point in the history
Dev branch
  • Loading branch information
jamesbuch authored Sep 15, 2024
2 parents b4707c0 + 6f95d42 commit 65e4536
Show file tree
Hide file tree
Showing 27 changed files with 3,843 additions and 252 deletions.
15 changes: 15 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"presets": [
[
"@babel/env",
{
"modules": false,
"targets": {
"node": "18"
}
}
],
"@babel/typescript"
],
"plugins": ["add-import-extension"]
}
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tseslint from 'typescript-eslint';
export default tseslint.config(
{
// config with just ignores is the replacement for `.eslintignore`
ignores: ['**/build/**', '**/dist/**', '**/examples/**'],
ignores: ['**/build/**', '**/dist/**', '**/examples/**', '**/*.d.ts'],
},
eslint.configs.recommended,
...tseslint.configs.recommended,
Expand Down
3,627 changes: 3,426 additions & 201 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@
"license": "BSD-3-Clause",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": ["dist", "LICENSE", "README.md", "package.json"],
"files": [
"dist",
"LICENSE",
"README.md",
"package.json"
],
"type": "module",
"author": {
"name": "James Buchanan",
"email": "jamesbuch1337@gmail.com",
"url": "https://github.com/jamesbuch"
},
"scripts": {
"build": "tsc",
"build": "run-p -s build:*",
"build:main": "babel -x .ts -d dist src",
"build:types": "tsc",
"test": "jest",
"dev": "node --loader ts-node/esm --experimental-specifier-resolution=node examples/demo.ts",
"lint": "eslint ."
Expand All @@ -40,17 +47,23 @@
"winston": "^3.14.2"
},
"devDependencies": {
"@babel/cli": "^7.25.6",
"@babel/preset-env": "^7.25.4",
"@babel/preset-typescript": "^7.24.7",
"@eslint/js": "^9.10.0",
"@jest/globals": "^29.7.0",
"@tsconfig/strictest": "^2.0.5",
"@types/eslint__js": "^8.42.3",
"@types/jest": "^29.5.13",
"@types/node": "^22.5.4",
"@types/winston": "^2.4.4",
"@typescript-eslint/eslint-plugin": "8.5.0",
"@typescript-eslint/parser": "8.5.0",
"babel-plugin-add-import-extension": "^1.6.0",
"dotenv": "^16.4.5",
"eslint": "^9.10.0",
"jest": "^29.7.0",
"npm-run-all": "^4.1.5",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.2",
Expand Down
34 changes: 34 additions & 0 deletions src/authenticatedApi.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { CoinspotApiBase } from './coinspotApiBase';
import { StatusResponse, CoinDepositAddressResponse, QuoteResponse, PlaceOrderResponse, EditOrderResponse, BuyNowOrderResponse, SellNowOrderResponse, SwapNowOrderResponse, CancelOrderResponse, CoinWithdrawalDetailsResponse } from './types';
export declare class AuthenticatedCoinspotApi extends CoinspotApiBase {
getStatus(): Promise<StatusResponse>;
getCoinWithdrawalDetails(cointype: string): Promise<CoinWithdrawalDetailsResponse>;
getCoinDepositAddress(cointype: string): Promise<CoinDepositAddressResponse>;
getBuyNowQuote(cointype: string, amount: number, amounttype: 'coin' | 'aud'): Promise<QuoteResponse>;
getSellNowQuote(cointype: string, amount: number, amounttype: 'coin' | 'aud'): Promise<QuoteResponse>;
getSwapNowQuote(cointypesell: string, cointypebuy: string, amount: number): Promise<QuoteResponse>;
placeMarketBuyOrder(cointype: string, amount: number, rate: number, markettype?: string): Promise<PlaceOrderResponse>;
editOpenMarketBuyOrder(cointype: string, id: string, rate: number, newrate: number): Promise<EditOrderResponse>;
placeBuyNowOrder(cointype: string, amounttype: 'coin' | 'aud', amount: number, options?: {
rate?: number;
threshold?: number;
direction?: 'UP' | 'DOWN' | 'BOTH';
}): Promise<BuyNowOrderResponse>;
placeMarketSellOrder(cointype: string, amount: number, rate: number, markettype?: string): Promise<PlaceOrderResponse>;
editOpenMarketSellOrder(cointype: string, id: string, rate: number, newrate: number): Promise<EditOrderResponse>;
placeSellNowOrder(cointype: string, amounttype: 'coin' | 'aud', amount: number, options?: {
rate?: number;
threshold?: number;
direction?: 'UP' | 'DOWN' | 'BOTH';
}): Promise<SellNowOrderResponse>;
placeSwapNowOrder(cointypesell: string, cointypebuy: string, amount: number, options?: {
rate?: number;
threshold?: number;
direction?: 'UP' | 'DOWN' | 'BOTH';
}): Promise<SwapNowOrderResponse>;
cancelBuyOrder(id: string): Promise<CancelOrderResponse>;
cancelAllBuyOrders(coin?: string): Promise<CancelOrderResponse>;
cancelSellOrder(id: string): Promise<CancelOrderResponse>;
cancelAllSellOrders(coin?: string): Promise<CancelOrderResponse>;
}
//# sourceMappingURL=authenticatedApi.d.ts.map
1 change: 1 addition & 0 deletions src/authenticatedApi.d.ts.map

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

42 changes: 42 additions & 0 deletions src/authenticatedReadOnlyApi.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { AffiliatePaymentsResponse, BalancesResponse, CoinWithdrawalResponse, CompletedMarketOrdersResponse, CompletedOrdersResponse, DepositHistoryResponse, OpenLimitOrdersResponse, OpenMarketOrdersResponse, OpenOrdersResponse, ReadOnlyStatusResponse, ReferralPaymentsResponse, SendReceiveHistoryResponse, SingleCoinBalanceResponse, WithdrawalHistoryResponse } from './types';
import { CoinspotApiBase } from './coinspotApiBase';
export declare class AuthenticatedCoinspotReadOnlyApi extends CoinspotApiBase {
getBalances(): Promise<BalancesResponse>;
withdrawCoin(cointype: string, amount: number, address: string, options?: {
emailconfirm?: 'YES' | 'NO';
network?: string;
paymentid?: string;
}): Promise<CoinWithdrawalResponse>;
getReadOnlyStatus(): Promise<ReadOnlyStatusResponse>;
getOpenMarketOrders(cointype: string, markettype?: string): Promise<OpenMarketOrdersResponse>;
getMyOpenMarketOrders(cointype?: string, markettype?: string): Promise<OpenOrdersResponse>;
getCompletedMarketOrders(options: {
cointype?: string;
markettype?: string;
startdate?: string;
enddate?: string;
limit?: number;
}): Promise<CompletedMarketOrdersResponse>;
getSingleCoinBalance(cointype: string, available: 'yes' | 'no'): Promise<SingleCoinBalanceResponse>;
getMyOpenLimitOrders(cointype?: string): Promise<OpenLimitOrdersResponse>;
getMyOrderHistory(options: {
cointype?: string;
markettype?: string;
startdate?: string;
enddate?: string;
limit?: number;
}): Promise<CompletedOrdersResponse>;
getMyMarketOrderHistory(options: {
cointype?: string;
markettype?: string;
startdate?: string;
enddate?: string;
limit?: number;
}): Promise<CompletedOrdersResponse>;
getMySendReceiveHistory(startdate?: string, enddate?: string): Promise<SendReceiveHistoryResponse>;
getMyDepositHistory(startdate?: string, enddate?: string): Promise<DepositHistoryResponse>;
getMyWithdrawalHistory(startdate?: string, enddate?: string): Promise<WithdrawalHistoryResponse>;
getMyAffiliatePayments(): Promise<AffiliatePaymentsResponse>;
getMyReferralPayments(): Promise<ReferralPaymentsResponse>;
}
//# sourceMappingURL=authenticatedReadOnlyApi.d.ts.map
1 change: 1 addition & 0 deletions src/authenticatedReadOnlyApi.d.ts.map

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

13 changes: 1 addition & 12 deletions src/authenticatedReadOnlyApi.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import { AffiliatePaymentsResponse, BalancesResponse, CoinBalance, CoinWithdrawalResponse, CompletedMarketOrdersResponse, CompletedOrdersResponse, DepositHistoryResponse, OpenLimitOrdersResponse, OpenMarketOrdersResponse, OpenOrdersResponse, ReadOnlyStatusResponse, ReferralPaymentsResponse, SendReceiveHistoryResponse, SingleCoinBalanceResponse, WithdrawalHistoryResponse } from './types';
import { AffiliatePaymentsResponse, BalancesResponse, CoinWithdrawalResponse, CompletedMarketOrdersResponse, CompletedOrdersResponse, DepositHistoryResponse, OpenLimitOrdersResponse, OpenMarketOrdersResponse, OpenOrdersResponse, ReadOnlyStatusResponse, ReferralPaymentsResponse, SendReceiveHistoryResponse, SingleCoinBalanceResponse, WithdrawalHistoryResponse } from './types';
import { CoinspotApiBase } from './coinspotApiBase';

export class AuthenticatedCoinspotReadOnlyApi extends CoinspotApiBase {
async getBalances(): Promise<BalancesResponse> {
return this.request<BalancesResponse>('/my/balances', {}, true);
}

// Helper method to get balances in a more usable format
async getFormattedBalances(): Promise<{ [coin: string]: CoinBalance }> {
const response = await this.getBalances();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return response.balances.reduce((acc: any, entry: any | ArrayLike<unknown>) => {
const [coin, balance] = Object.entries(entry)[0];
acc[coin] = balance;
return acc;
}, {} as { [coin: string]: CoinBalance });
}

// Add more methods for other authenticated endpoints
async withdrawCoin(cointype: string, amount: number, address: string, options?: {
emailconfirm?: 'YES' | 'NO';
Expand Down
7 changes: 7 additions & 0 deletions src/coinspotApiBase.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export declare class CoinspotApiBase {
protected key: string;
protected secret: string;
constructor(key: string, secret: string);
protected request<T>(path: string, data?: any, readOnly?: boolean): Promise<T>;
}
//# sourceMappingURL=coinspotApiBase.d.ts.map
1 change: 1 addition & 0 deletions src/coinspotApiBase.d.ts.map

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

2 changes: 2 additions & 0 deletions src/examples/demo.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=demo.d.ts.map
1 change: 1 addition & 0 deletions src/examples/demo.d.ts.map

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

4 changes: 2 additions & 2 deletions src/examples/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Coinspot } from '../index';
import dotenv from 'dotenv';
dotenv.config();

const API_KEY = process.env.COINSPOT_API_KEY;
const API_SECRET = process.env.COINSPOT_API_SECRET;
const API_KEY = process.env['COINSPOT_API_KEY'];
const API_SECRET = process.env['COINSPOT_API_SECRET'];

const coinspot = new Coinspot(API_KEY, API_SECRET);

Expand Down
25 changes: 25 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { CoinspotPublicApi } from './publicApi';
import { AuthenticatedCoinspotReadOnlyApi } from './authenticatedReadOnlyApi';
import { AuthenticatedCoinspotApi } from './authenticatedApi';
export * from './types';
export declare class Coinspot {
readonly public: CoinspotPublicApi;
readonly readOnly: AuthenticatedCoinspotReadOnlyApi | null;
readonly authenticated: AuthenticatedCoinspotApi | null;
private apiKeyRequiredMessage;
constructor(apiKey?: string, apiSecret?: string);
latestCoinPrice(coin: string): Promise<import("./types").SingleCoinPriceResponse>;
latestPrices(): Promise<import("./types").LatestPricesResponse>;
latestBuyPrice(coin: string): Promise<import("./types").BuySellPriceResponse>;
latestSellPrice(coin: string): Promise<import("./types").BuySellPriceResponse>;
openOrderList(coin: string): Promise<import("./types").OpenOrdersResponse>;
completedOrderList(coin: string): Promise<import("./types").CompletedOrdersResponse>;
coinBalance(coin: string): Promise<import("./types").SingleCoinBalanceResponse>;
balance(): Promise<import("./types").BalancesResponse>;
coinDepositAddress(coin: string): Promise<import("./types").CoinDepositAddressResponse>;
marketBuyOrder(coin: string, amount: number, rate: number): Promise<import("./types").PlaceOrderResponse>;
marketSellOrder(coin: string, amount: number, rate: number): Promise<import("./types").PlaceOrderResponse>;
}
export declare const createCoinspotApi: (apiKey?: string, apiSecret?: string) => Coinspot;
export default Coinspot;
//# sourceMappingURL=index.d.ts.map
1 change: 1 addition & 0 deletions src/index.d.ts.map

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

10 changes: 10 additions & 0 deletions src/publicApi.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { LatestPricesResponse, SingleCoinPriceResponse, BuySellPriceResponse, OpenOrdersResponse, CompletedOrdersResponse } from './types';
export declare class CoinspotPublicApi {
getLatestPrices(): Promise<LatestPricesResponse>;
getLatestCoinPrice(coin: string): Promise<SingleCoinPriceResponse>;
getLatestBuyPrice(coin: string): Promise<BuySellPriceResponse>;
getLatestSellPrice(coin: string): Promise<BuySellPriceResponse>;
getOpenOrders(coin: string): Promise<OpenOrdersResponse>;
getCompletedOrders(coin: string): Promise<CompletedOrdersResponse>;
}
//# sourceMappingURL=publicApi.d.ts.map
1 change: 1 addition & 0 deletions src/publicApi.d.ts.map

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

Loading

0 comments on commit 65e4536

Please sign in to comment.