Skip to content

Commit

Permalink
Merge pull request #22 from coinsambacom/fix/gateio-tickers
Browse files Browse the repository at this point in the history
Fix: gateio tickers
  • Loading branch information
itxtoledo authored Mar 2, 2024
2 parents c100854 + 029e123 commit cc07761
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 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.14",
"version": "2.1.15",
"repository": "[email protected]:coinsambacom/js-exchanges-connector.git",
"author": "Gustavo <[email protected]>",
"license": "MIT",
Expand Down
31 changes: 24 additions & 7 deletions src/connectors/gateio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ import {
} from "../interfaces/exchange";
import { IOrderbook, ITicker } from "../utils/DTOs";

interface GateIoTickerRes {
result: string;
last: string;
lowestAsk: string;
highestBid: string;
percentChange: string;
baseVolume: string;
quoteVolume: string;
high24hr: string;
low24hr: string;
}

interface GateIoTickersRes {
[pair: string]: GateIoTickerRes;
}

export class gateio<T = any> extends Exchange<T> {
constructor(args?: IExchangeImplementationConstructorArgs<T>) {
super({
Expand All @@ -14,26 +30,27 @@ export class gateio<T = any> extends Exchange<T> {
}

async getAllTickers(): Promise<ITicker[]> {
const res = await this.fetch(`${this.baseUrl}/tickers`);
const res = await this.fetch<GateIoTickersRes>(`${this.baseUrl}/tickers`);

const tickers: ITicker[] = [];
for (const pair in res) {
const ticker = res[pair];
const ticker = res[pair]!;

tickers.push({
exchangeId: this.id,
base: (pair.split("_")[0] as string).toUpperCase(),
quote: (pair.split("_")[1] as string).toUpperCase(),
last: ticker.last,
ask: ticker.lowestAsk,
bid: ticker.quoteVolume,
vol: ticker.vol,
last: Number(ticker.last),
ask: Number(ticker.lowestAsk),
bid: Number(ticker.highestBid),
vol: Number(ticker.quoteVolume),
});
}
return tickers;
}

async getTicker(base: string, quote: string): Promise<ITicker> {
const res = await this.fetch(
const res = await this.fetch<GateIoTickersRes>(
`${this.baseUrl}/ticker/${base.toLowerCase()}_${quote.toLowerCase()}`,
);

Expand Down

0 comments on commit cc07761

Please sign in to comment.