Skip to content

Commit

Permalink
Merge pull request #18 from coinsambacom/feat/isis-trade
Browse files Browse the repository at this point in the history
added isis trade
  • Loading branch information
itxtoledo authored Nov 21, 2023
2 parents 2bb5955 + dad8481 commit 4ee47fd
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ binance.getAllTickers().then(tickers => console.log(tickers));
| ftx 🌐 | 1 | | | 1 |
| gateio 🌐 | 1 | 1 | | 1 |
| isbit 🇲🇽 | 1 | | | 1 |
| isistrade 🇧🇷 | | | 1 | 1 |
| kraken 🌐 | 1 | | | 1 |
| kucoin 🌐 | 1 | 1 | | 1 |
| liqi 🇧🇷 | 1 | 1 | | 1 |
Expand Down
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.10",
"version": "2.1.11",
"repository": "[email protected]:coinsambacom/js-exchanges-connector.git",
"author": "Gustavo <[email protected]>",
"license": "MIT",
Expand Down
88 changes: 88 additions & 0 deletions src/connectors/isistrade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import {
Exchange,
IExchangeImplementationConstructorArgs,
} from "../interfaces/exchange";
import { IOrderbook, IOrderbookOrder, ITicker } from "../utils/DTOs";
import { parseBRLNumberString } from "../utils/utils";

interface BaseRes<T> {
success: boolean;
message: string;
result: T;
}

interface IsisTradeOrderbookOrder {
timestamp: number;
price: string;
quantity: string;
}

export class isistrade<T = any> extends Exchange<T> {
constructor(args?: IExchangeImplementationConstructorArgs<T>) {
super({
id: "isistrade",
baseUrl: "https://isistrade.com/api",
opts: args?.opts,
});
}

async getAllTickersByQuote(quote: string): Promise<ITicker[]> {
const res = await this.fetch<
BaseRes<
{
timestamp: number;
marketName: string;
marketAsset: string;
baseAsset: string;
marketAssetName: string;
baseAssetName: string;
high: string;
low: string;
last: string;
volume: string;
baseVolume: string;
bid: string;
ask: string;
isActive: boolean;
infoMessage: string;
}[]
>
>(`${this.baseUrl}/public/marketsummaries?basemarket=${quote}`);

return res.result.map((t) => ({
exchangeId: this.id,
base: t.marketAsset,
quote: t.baseAsset,
ask: parseBRLNumberString(t.ask),
bid: parseBRLNumberString(t.bid),
last: parseBRLNumberString(t.last),
vol: parseBRLNumberString(t.volume),
}));
}

private parseOrder({
price,
quantity,
}: IsisTradeOrderbookOrder): IOrderbookOrder {
return {
price: Number(price),
amount: Number(quantity),
};
}

async getBook(base: string, quote: string): Promise<IOrderbook> {
const res = await this.fetch<
BaseRes<{
sell: IsisTradeOrderbookOrder[];
buy: IsisTradeOrderbookOrder[];
}>
>(
`${this.baseUrl}/public/orderbook?market=${base}_${quote}&type=ALL&depth=20`,
);

return {
asks: res.result.sell.map(this.parseOrder),
bids: res.result.buy.map(this.parseOrder),
};
}
}
1 change: 1 addition & 0 deletions src/exchanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export { ftx } from "./connectors/ftx";
export { gateio } from "./connectors/gateio";
export { huobi } from "./connectors/huobi";
export { isbit } from "./connectors/isbit";
export { isistrade } from "./connectors/isistrade";
export { kraken } from "./connectors/kraken";
export { mercadobitcoin } from "./connectors/mercadobitcoin";
export { novadax } from "./connectors/novadax";
Expand Down
5 changes: 5 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const parseBRLNumberString = (numberInString: string) => {
const strFormatted = numberInString.replace(/\./g, "").replace(",", ".");

return parseFloat(strFormatted);
};
52 changes: 52 additions & 0 deletions test/isistrade.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { expect } from "chai";
import { isistrade } from "../src/connectors/isistrade";
import { FetcherHandler } from "../src/utils/DTOs";
import { MyFetcher } from "./utils/MyFetcher";
import { expectPropertyTypes } from "./utils/helpers";

describe("isistrade", () => {
let exchange: isistrade;

beforeEach(() => {
exchange = new isistrade();
const fetcher = new MyFetcher();

FetcherHandler.setFetcher(fetcher);
});

describe("getAllTickersByQuote", () => {
it("should return an array of ITicker objects", async () => {
const tickers = await exchange.getAllTickersByQuote("BRL");

expect(Array.isArray(tickers)).to.be.true;

if (tickers.length > 0) {
const ticker = tickers[0];

expectPropertyTypes(ticker, ["exchangeId", "base", "quote"], "string");
expectPropertyTypes(ticker, ["last", "ask", "bid", "vol"], "number");
}
});
});

describe("getBook", () => {
it("should return an IOrderbook object", async () => {
const book = await exchange.getBook("BTC", "BRL");

expect(book).to.have.property("asks");
expect(book).to.have.property("bids");
expect(Array.isArray(book.asks)).to.be.true;
expect(Array.isArray(book.bids)).to.be.true;

if (book.asks.length > 0) {
const ask = book.asks[0];
expectPropertyTypes(ask, ["price", "amount"], "number");
}

if (book.bids.length > 0) {
const bid = book.bids[0];
expectPropertyTypes(bid, ["price", "amount"], "number");
}
});
});
});

0 comments on commit 4ee47fd

Please sign in to comment.