diff --git a/examples/pagcripto_otc.ts b/examples/pagcripto_otc.ts new file mode 100644 index 0000000..8f4f2e1 --- /dev/null +++ b/examples/pagcripto_otc.ts @@ -0,0 +1,13 @@ +import { pagcripto_otc } from "../src/exchanges"; +import { FetcherHandler } from "../src/utils/DTOs"; +import { MyFetcher } from "../test/utils/MyFetcher"; +// import { OrderSide } from "../src/types/common"; + +FetcherHandler.setFetcher(new MyFetcher()); + +const ex = new pagcripto_otc(); + +// ex.getBook("BTC", "BRL").then((book) => console.log("book from", ex.id, book)); +ex.getAllTickers().then((tickers) => + console.log("tickers from ", ex.id, tickers), +); diff --git a/package.json b/package.json index ceed0ba..a349e08 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@coinsamba/js-exchanges-connector", "description": "Collection of JavaScript implementations of cryptocurrency exchange APIs", - "version": "2.1.7", + "version": "2.1.8", "repository": "git@github.com:coinsambacom/js-exchanges-connector.git", "author": "Gustavo ", "license": "MIT", diff --git a/src/connectors/pagcripto_otc.ts b/src/connectors/pagcripto_otc.ts index e78c41d..17cfc87 100644 --- a/src/connectors/pagcripto_otc.ts +++ b/src/connectors/pagcripto_otc.ts @@ -7,6 +7,19 @@ import { IOrderbook, ITicker } from "../utils/DTOs"; import { ConnectorError, ERROR_TYPES } from "../utils/ConnectorError"; import { isNumber } from "lodash"; +interface PagCriptoTicker { + volume: string; + last: string; + buy: string; + sell: string; +} + +interface PagCriptoTickersRes { + otc_tickers: { + [symbol: string]: PagCriptoTicker; + }; +} + interface IPagCriptoOTCTickerRes { otc_ticker: { crypto: string; @@ -61,6 +74,29 @@ export class pagcripto_otc extends Exchange { }; } + async getAllTickers(): Promise { + const res = await this.fetch( + `${this.baseUrl}/tickers`, + ); + + const tickers: ITicker[] = Object.keys(res.otc_tickers).map((v) => { + const ticker = res.otc_tickers[v]!; + const base = v.toUpperCase(); + + return { + exchangeId: this.id, + base, + quote: "BRL", + last: Number(ticker.last), + ask: Number(ticker.sell), + bid: Number(ticker.buy), + vol: Number(ticker.volume), + }; + }); + + return tickers; + } + private amountByCurreny(currency: string): number { if (currency === "BTC") return 1001; if (currency === "ETH") return 10000; diff --git a/test/utils/MyFetcher.ts b/test/utils/MyFetcher.ts index a786209..7ffae4a 100644 --- a/test/utils/MyFetcher.ts +++ b/test/utils/MyFetcher.ts @@ -3,7 +3,7 @@ import { ICustomFetcher, FetcherArgs, FetcherRequisitionMethods, -} from "../../src/types"; +} from "../../src/utils/DTOs"; export class MyFetcher implements ICustomFetcher { private parseAxiosError(e: AxiosError) {