Skip to content

Commit

Permalink
fix return
Browse files Browse the repository at this point in the history
  • Loading branch information
itxtoledo committed Sep 16, 2023
1 parent dd2047a commit 07c48fa
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 44 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.1.8",
"version": "2.1.9",
"repository": "[email protected]:coinsambacom/js-exchanges-connector.git",
"author": "Gustavo <[email protected]>",
"license": "MIT",
Expand Down
25 changes: 11 additions & 14 deletions src/connectors/bitcointrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,17 @@ export class bitcointrade<T = any> extends Exchange<T> {

const tickers: ITicker[] = [];

for (const pair in res) {
if (pair.startsWith(quote)) {
const ticker = res[pair];
if (ticker) {
tickers.push({
exchangeId: this.id,
base: pair.replace(quote, ""),
quote,
last: ticker.last,
ask: ticker.sell,
bid: ticker.buy,
vol: ticker.volume,
});
}
for (const ticker of res) {
if (ticker.pair.startsWith(quote)) {
tickers.push({
exchangeId: this.id,
base: ticker.pair.replace(quote, ""),
quote,
last: ticker.last,
ask: ticker.sell,
bid: ticker.buy,
vol: ticker.volume,
});
}
}

Expand Down
85 changes: 58 additions & 27 deletions src/connectors/cexio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,41 @@ import {
} from "../interfaces/exchange";
import { IOrderbook, ITicker } from "../utils/DTOs";

export interface CexioBaseRes {
e: string;
ok: string;
}

export interface CexioTickersRes extends CexioBaseRes {
data: {
timestamp: string;
pair: string;
low: string;
high: string;
last: string;
volume: string;
volume30d: string;
priceChange: string;
priceChangePercentage: string;
bid?: number;
ask?: number;
}[];
}

export interface CexioTickerRes {
timestamp: string;
pair: string;
low: string;
high: string;
last: string;
volume: string;
volume30d: string;
priceChange: string;
priceChangePercentage: string;
bid?: number;
ask?: number;
}

export class cexio<T = any> extends Exchange<T> {
constructor(args?: IExchangeImplementationConstructorArgs<T>) {
super({
Expand All @@ -14,45 +49,41 @@ export class cexio<T = any> extends Exchange<T> {
}

async getAllTickersByQuote(quote: string): Promise<ITicker[]> {
let res = await this.fetch(this.baseUrl + "/tickers/" + quote);
const { data: res } = await this.fetch<CexioTickersRes>(
this.baseUrl + "/tickers/" + quote,
);

res = res.data;
return res.map(
(t: {
pair: { split: (arg0: string) => [any, any] };
last: any;
ask: any;
bid: any;
volume: any;
}) => {
const [base, quote] = t.pair.split(":");
return res.map((t) => {
const [base, quote] = t.pair.split(":") as [string, string];
const last = Number(t.last);

return {
exchangeId: this.id,
base,
quote,
last: t.last,
ask: t.ask,
bid: t.bid,
vol: t.volume,
};
},
);
return {
exchangeId: this.id,
base,
quote,
last: last,
ask: t.ask ?? last,
bid: t.bid ?? last,
vol: Number(t.volume),
};
});
}

async getTicker(base: string, quote: string): Promise<ITicker> {
const res = await this.fetch(
const res = await this.fetch<CexioTickerRes>(
this.baseUrl + "/ticker/" + base + "/" + quote,
);

const last = Number(res.last);

return {
exchangeId: this.id,
base,
quote,
last: res.last,
ask: res.ask,
bid: res.bid,
vol: res.volume,
last: last,
ask: res.ask ?? last,
bid: res.bid ?? last,
vol: Number(res.volume),
};
}

Expand Down
5 changes: 3 additions & 2 deletions src/connectors/cryptomarket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ export class cryptomarket<T = any> extends Exchange<T> {
}

async getAllTickersByQuote(quote: string): Promise<ITicker[]> {
const { data: res } = await this.fetch<ICryptoMarketTickersRes>(
const res = await this.fetch<ICryptoMarketTickersRes>(
this.baseUrl + "/public/ticker",
);

const tickers: ITicker[] = [];

for (const pair in res) {
if (pair.endsWith(quote)) {
const ticker = res[pair] as ICryptoMarketTicker;
const ticker = res[pair]!;

tickers.push({
exchangeId: this.id,
base: pair.replace(quote, ""),
Expand Down

0 comments on commit 07c48fa

Please sign in to comment.