Skip to content

Commit

Permalink
fix tauros
Browse files Browse the repository at this point in the history
  • Loading branch information
itxtoledo committed Jul 21, 2022
1 parent 97faca2 commit 5f99a6a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 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": "1.2.0",
"version": "1.2.1",
"repository": "[email protected]:coinsambacom/js-exchanges-connector.git",
"author": "Gustavo <[email protected]>",
"license": "MIT",
Expand Down
51 changes: 37 additions & 14 deletions src/connectors/tauros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@ import {
Exchange,
IExchangeImplementationConstructorArgs,
} from "../interfaces/exchange";
import { IOrderbook, ITicker } from "../types/common";
import { IOrderbook, IOrderbookOrder, ITicker } from "../types/common";
import { ConnectorError, ERROR_TYPES } from "../utils/ConnectorError";

interface ITaurosOrderbookOrder {
amount: number;
value: number;
price: string;
created_at: string;
id: number;
}

interface ITaurosOrderbookRes {
success: boolean;
msg: any;
payload: {
bids: ITaurosOrderbookOrder[];
asks: ITaurosOrderbookOrder[];
};
}

export class tauros<T> extends Exchange<T> {
constructor(args?: IExchangeImplementationConstructorArgs<T>) {
super({
Expand Down Expand Up @@ -39,23 +56,29 @@ export class tauros<T> extends Exchange<T> {
);
}

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

async getBook(base: string, quote: string): Promise<IOrderbook> {
let res = await this.fetch(
`${this.baseUrl}/v1/trading/orders/?market=${base}-${quote}`,
const res = await this.fetch<ITaurosOrderbookRes>(
`${this.baseUrl}/v2/trading/${base}-${quote}/orders/?market=`,
);
if (!res || !res.data)
throw new ConnectorError(ERROR_TYPES.API_RESPONSE_ERROR);
res = res.data;
if (!res.success) {
throw new ConnectorError(ERROR_TYPES.API_RESPONSE_ERROR, res.msg);
}

const book = res.payload;

return {
asks: res.asks.map(({ price, amount }) => ({
price: price,
amount: amount,
})),
bids: res.bids.map(({ price, amount }) => ({
price: price,
amount: amount,
})),
asks: book.asks.map(this.parseOrder),
bids: book.bids.map(this.parseOrder),
};
}
}

0 comments on commit 5f99a6a

Please sign in to comment.