Skip to content

Commit

Permalink
Merge pull request #15 from coinsambacom/feat/pagcripto_otc_all_tickers
Browse files Browse the repository at this point in the history
Feat: added "getAllTickers" to pagcripto otc
  • Loading branch information
itxtoledo authored Aug 17, 2023
2 parents 54c1f7d + 39d588c commit dd2047a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
13 changes: 13 additions & 0 deletions examples/pagcripto_otc.ts
Original file line number Diff line number Diff line change
@@ -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),
);
2 changes: 1 addition & 1 deletion 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.7",
"version": "2.1.8",
"repository": "[email protected]:coinsambacom/js-exchanges-connector.git",
"author": "Gustavo <[email protected]>",
"license": "MIT",
Expand Down
36 changes: 36 additions & 0 deletions src/connectors/pagcripto_otc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,6 +74,29 @@ export class pagcripto_otc<T = any> extends Exchange<T> {
};
}

async getAllTickers(): Promise<ITicker[]> {
const res = await this.fetch<PagCriptoTickersRes>(
`${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;
Expand Down
2 changes: 1 addition & 1 deletion test/utils/MyFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ICustomFetcher,
FetcherArgs,
FetcherRequisitionMethods,
} from "../../src/types";
} from "../../src/utils/DTOs";

export class MyFetcher implements ICustomFetcher {
private parseAxiosError(e: AxiosError) {
Expand Down

0 comments on commit dd2047a

Please sign in to comment.