Skip to content

Commit

Permalink
Merge pull request #43 from coinsambacom/fix/trubit-api
Browse files Browse the repository at this point in the history
Fix: trubit
  • Loading branch information
itxtoledo authored Jan 2, 2025
2 parents be5a266 + 22bc228 commit 13ab9fc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
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.2.0",
"version": "2.2.1",
"repository": "git@github.com:coinsambacom/js-exchanges-connector.git",
"author": "Gustavo <gustavo@obex.pw>",
"license": "MIT",
Expand Down
8 changes: 4 additions & 4 deletions src/connectors/trubit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class trubit<T = any> extends Exchange<T> {
constructor(args?: IExchangeImplementationConstructorArgs<T>) {
super({
id: "trubit",
baseUrl: "https://api-spot.trubit.com/openapi/quote/v1/ticker/24hr",
baseUrl: "https://api-spot.trubit.com/openapi",
opts: args?.opts,
});
}
Expand All @@ -51,15 +51,15 @@ export class trubit<T = any> extends Exchange<T> {
`${this.baseUrl}/quote/v1/ticker/24hr`,
);

return res.map(this.parseTicker);
return res.map(this.parseTicker.bind(this));
}

async getTicker(base: string, quote: string): Promise<ITicker> {
const res = await this.fetch<Ticker>(
`${this.baseUrl}/quote/v1/ticker/24hr?symbol=${base}${quote}`,
);

return this.parseTicker(res);
return { ...this.parseTicker(res), ...{ base, quote } };
}

private parseOrder(order: OrderbookOrder): IOrderbookOrder {
Expand All @@ -71,7 +71,7 @@ export class trubit<T = any> extends Exchange<T> {

async getBook(base: string, quote: string): Promise<IOrderbook> {
const res = await this.fetch<Orderbook>(
`${this.baseUrl}/quote/v1/depth?symbol=currencyPair=${base}${quote}&limit=100`,
`${this.baseUrl}/quote/v1/depth?symbol=${base}${quote}&limit=100`,
);

return {
Expand Down
43 changes: 43 additions & 0 deletions test/trubit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { IExchange } from "../src/utils/DTOs";

import { testAllTickers, testBook, testTicker } from "./utils/helpers";

const CONNECTOR = "trubit",
BASE = "BTC",
QUOTE = "BRL";

describe.only(CONNECTOR, () => {
let exchange: IExchange;

beforeEach(async () => {
const imported = await import(`../src/connectors/${CONNECTOR}`);

const ExchangeClass = Object.values(imported)[0] as { new (): IExchange };

exchange = new ExchangeClass();
});

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

testAllTickers(tickers);
});
});

describe("getTicker", () => {
it("should return an ITicker object", async () => {
const ticker = await exchange.getTicker!(BASE, QUOTE);

testTicker(ticker);
});
});

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

testBook(book);
});
});
});

0 comments on commit 13ab9fc

Please sign in to comment.