Skip to content

Commit

Permalink
Merge pull request #13 from coinsambacom/feat/updating-files
Browse files Browse the repository at this point in the history
Feat: updating files
  • Loading branch information
itxtoledo authored Aug 10, 2023
2 parents 516510b + 60198bc commit c1e9f0d
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 93 deletions.
5 changes: 5 additions & 0 deletions examples/foxbit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { foxbit } from "../src/exchanges";
import { FetcherHandler } from "../src/types";
import { MyFetcher } from "../test/utils/MyFetcher";
// import { OrderSide } from "../src/types/common";

FetcherHandler.setFetcher(new MyFetcher());

const ex = new foxbit();

Expand Down
2 changes: 1 addition & 1 deletion examples/pagcripto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "dotenv/config";
import { FetcherHandler } from "../src/index";
import { FetcherHandler } from "../src/utils/DTOs";
import { pagcripto } from "../src/exchanges";
import { MyFetcher } from "../test/utils/MyFetcher";
// import { OrderSide } from "../src/types/common";
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@coinsamba/js-exchanges-connector",
"description": "Collection of JavaScript implementations of cryptocurrency exchange APIs",
"version": "2.1.3",
"version": "2.1.4",
"repository": "[email protected]:coinsambacom/js-exchanges-connector.git",
"author": "Gustavo <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -46,7 +46,7 @@
"@types/jest": "^29.5.3",
"@types/lodash": "^4.14.197",
"@types/node": "^17.0.14",
"@types/ws": "^8.5.3",
"@types/ws": "^8.5.5",
"@typescript-eslint/eslint-plugin": "^5.10.2",
"@typescript-eslint/parser": "^5.10.2",
"axios": "^1.4.0",
Expand All @@ -64,12 +64,12 @@
"microbundle": "^0.15.1",
"prettier": "^2.5.1",
"ts-jest": "^29.1.1",
"ts-node-dev": "^2.0.0"
"ts-node-dev": "^2.0.0",
"typescript": "^5.1.6"
},
"dependencies": {
"fast-sort": "^3.1.3",
"lodash": "^4.17.21",
"lodash.isnumber": "^3.0.3",
"ws": "^8.8.1"
"ws": "^8.13.0"
}
}
8 changes: 6 additions & 2 deletions src/connectors/bitpreco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import {
SignerArguments,
SignerReturn,
} from "../interfaces/exchange";
import { IBalance, IOrderbook, ITicker } from "../utils/DTOs";
import { FetcherRequisitionMethods } from "../utils/FetcherHandler";
import {
FetcherRequisitionMethods,
IBalance,
IOrderbook,
ITicker,
} from "../utils/DTOs";

interface BitprecoOrderbookRes {
bids?: BitprecoOrderbookOrder[];
Expand Down
1 change: 1 addition & 0 deletions src/connectors/foxbit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface IFoxbitAllTickers {

export class foxbit<T> extends alphapoint<T> {
private tickerUrl: string;

constructor(args?: IExchangeImplementationConstructorArgs<T>) {
super({
id: "foxbit",
Expand Down
2 changes: 1 addition & 1 deletion src/connectors/pagcripto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {
PlaceOrderArguments,
GetHistoryArguments,
History,
FetcherRequisitionMethods,
} from "../utils/DTOs";
import { ConnectorError, ERROR_TYPES } from "../utils/ConnectorError";
import { FetcherRequisitionMethods } from "../utils/FetcherHandler";

interface PagCriptoBaseRes {
code: string;
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * as exchanges from "./exchanges";
export * as types from "./types";
export { FetcherHandler } from "./utils/FetcherHandler";
8 changes: 2 additions & 6 deletions src/interfaces/exchange.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { FetcherHandler } from "../utils/DTOs";
import { ConnectorError, ERROR_TYPES } from "../utils/ConnectorError";
import {
FetcherHandler,
FetcherArgs,
FetcherObjectArgs,
} from "../utils/FetcherHandler";
import { IExchange } from "../utils/DTOs";
import { FetcherArgs, FetcherObjectArgs, IExchange } from "../utils/DTOs";

/**
* Represents the arguments for signing requests.
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./interfaces/exchange";
export * from "./utils/DTOs";
export * from "./utils/ConnectorError";
export * from "./utils/FetcherHandler";
64 changes: 64 additions & 0 deletions src/utils/DTOs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,67 @@ export interface IExchange {
*/
getBook?: (base: string, quote: string) => Promise<IOrderbook>;
}

/**
* Enum representing different types of HTTP request methods.
*/
export enum FetcherRequisitionMethods {
GET = "get",
POST = "post",
}

export interface FetcherObjectArgs {
url: string;
method: FetcherRequisitionMethods;
headers: Record<string, string | number | boolean>;
data?: Record<string, any>;
opts?: any;
}

/**
* Type representing the arguments for making an HTTP request.
* It can be either a string representing the URL or an object with additional options.
*/
export type FetcherArgs = string | FetcherObjectArgs;

/**
* Interface representing a custom fetcher with a fetch method.
*/
export interface ICustomFetcher {
fetch: <T>(args: FetcherArgs) => Promise<T>;
}

/**
* Class responsible for handling HTTP requests using Axios.
* It provides the ability to set a custom fetcher and performs requests based on the provided arguments.
*/
class FetcherHandler {
private fetcher?: ICustomFetcher;

/**
* Sets a custom fetcher implementation.
* @param fetcher The custom fetcher implementing the ICustomFetcher interface.
*/
setFetcher(fetcher: ICustomFetcher): void {
this.fetcher = fetcher;
}

/**
* Performs an HTTP request using Axios.
* If a custom fetcher is set, it delegates the request to the custom fetcher.
* @param args The arguments for the HTTP request.
* @returns A promise that resolves to the response data.
* @throws ConnectorError if an AxiosError occurs during the request.
*/
async fetch<ResponseType>(args: FetcherArgs): Promise<ResponseType> {
if (this.fetcher) {
return this.fetcher.fetch<ResponseType>(args);
} else {
throw Error("need to attach fetcher before this call");
}
}
}

// Singleton instance of the Fetcher class
const instance = new FetcherHandler();
export { instance as FetcherHandler };
63 changes: 0 additions & 63 deletions src/utils/FetcherHandler.ts

This file was deleted.

26 changes: 13 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1805,10 +1805,10 @@
resolved "https://registry.yarnpkg.com/@types/strip-json-comments/-/strip-json-comments-0.0.30.tgz#9aa30c04db212a9a0649d6ae6fd50accc40748a1"
integrity sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==

"@types/ws@^8.5.3":
version "8.5.3"
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.3.tgz#7d25a1ffbecd3c4f2d35068d0b283c037003274d"
integrity sha512-6YOoWjruKj1uLf3INHH7D3qTXwFfEsg1kf3c0uDdSBJwfa/llkwIjrAGV7j7mVgGNbzTQ3HiHKKDXl6bJPD97w==
"@types/ws@^8.5.5":
version "8.5.5"
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.5.tgz#af587964aa06682702ee6dcbc7be41a80e4b28eb"
integrity sha512-lwhs8hktwxSjf9UaZ9tG5M03PGogvFaH8gUgLNbN9HKIg0dvv6q+gkSuJ8HN4/VbyxkuLzCjlN7GquQ0gUJfIg==
dependencies:
"@types/node" "*"

Expand Down Expand Up @@ -4593,11 +4593,6 @@ lodash.debounce@^4.0.8:
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
integrity sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==

lodash.isnumber@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz#3ce76810c5928d03352301ac287317f11c0b1ffc"
integrity sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==

[email protected], lodash.memoize@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
Expand Down Expand Up @@ -6229,6 +6224,11 @@ typescript@^4.1.3:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==

typescript@^5.1.6:
version "5.1.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274"
integrity sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==

unbox-primitive@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.1.tgz#085e215625ec3162574dc8859abee78a59b14471"
Expand Down Expand Up @@ -6379,10 +6379,10 @@ write-file-atomic@^4.0.2:
imurmurhash "^0.1.4"
signal-exit "^3.0.7"

ws@^8.8.1:
version "8.8.1"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.8.1.tgz#5dbad0feb7ade8ecc99b830c1d77c913d4955ff0"
integrity sha512-bGy2JzvzkPowEJV++hF07hAD6niYSr0JzBNo/J29WsB57A2r7Wlc1UFcTR9IzrPvuNVO4B8LGqF8qcpsVOhJCA==
ws@^8.13.0:
version "8.13.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0"
integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==

xtend@^4.0.0:
version "4.0.2"
Expand Down

0 comments on commit c1e9f0d

Please sign in to comment.