Skip to content

Commit

Permalink
Merge pull request #1 from coinsambacom/feature/foxbit-orderbook
Browse files Browse the repository at this point in the history
Feature: foxbit orderbook
  • Loading branch information
itxtoledo authored Sep 9, 2022
2 parents c93a6d2 + d3b6ac4 commit b7aee1c
Show file tree
Hide file tree
Showing 10 changed files with 643 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@typescript-eslint/ban-ts-comment": "warn",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/promise-function-async": "off",
"@typescript-eslint/interface-name-prefix": "off"
}
Expand Down
9 changes: 9 additions & 0 deletions examples/foxbit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @ts-ignore
import { foxbit } from "../src/index";

const ex = new foxbit();

ex.getBook("BTC", "BRL").then((book) => console.log("book from foxbit", book));
ex.getAllTickers().then((tickers) =>
console.log("tickers from foxbit", tickers),
);
7 changes: 5 additions & 2 deletions 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.3.1",
"version": "1.4.0",
"repository": "[email protected]:coinsambacom/js-exchanges-connector.git",
"author": "Gustavo <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -37,6 +37,7 @@
"@types/node": "^17.0.14",
"@types/node-fetch": "^2.5.12",
"@types/safe-compare": "^1.1.0",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.10.2",
"@typescript-eslint/parser": "^5.10.2",
"eslint": "^8.8.0",
Expand All @@ -48,11 +49,13 @@
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-standard": "^5.0.0",
"prettier": "^2.5.1",
"ts-node-dev": "^2.0.0",
"typescript": "^4.5.5"
},
"dependencies": {
"axios": "^0.26.1",
"bottleneck": "^2.19.5",
"fast-sort": "^3.1.3"
"fast-sort": "^3.1.3",
"ws": "^8.8.1"
}
}
1 change: 1 addition & 0 deletions src/connectors/coinext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class coinext<T> extends alphapoint<T> {
super({
id: "coinext",
baseUrl: "https://api.coinext.com.br:8443/AP",
websocketUrl: "wss://api.coinext.com.br/WSGateway/",
opts: args?.opts,
limiter: args?.limiter,
});
Expand Down
1 change: 1 addition & 0 deletions src/connectors/flowbtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export class flowbtc<T> extends alphapoint<T> {
super({
id: "flowbtc",
baseUrl: "https://api.flowbtc.com.br:8443/ap",
websocketUrl: "wss://api.flowbtc.com.br/WSGateway/",
opts: args?.opts,
limiter: args?.limiter,
});
Expand Down
53 changes: 48 additions & 5 deletions src/connectors/foxbit.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
import {
Exchange,
IExchangeImplementationConstructorArgs,
} from "../interfaces/exchange";
import { alphapoint } from "../interfaces/alphapoint";
import { IExchangeImplementationConstructorArgs } from "../interfaces/exchange";
import { ITicker } from "../types/common";

export class foxbit<T> extends Exchange<T> {
interface IFoxbitAllTickers {
symbol: string;
price: number;
priceChange24hPercent: number;
name: string;
icon: string;
rank: number;
volume: number;
low: number;
high: number;
marketcap: number;
lastUpdateTimestamp: number;
}

export class foxbit<T> extends alphapoint<T> {
constructor(args?: IExchangeImplementationConstructorArgs<T>) {
super({
id: "foxbit",
baseUrl: "https://watcher.foxbit.com.br/api",
websocketUrl: "wss://api.foxbit.com.br/",
opts: args?.opts,
limiter: args?.limiter,
});

this.tickerUrl = "https://foxbit.com.br/_api/ticker?cache=0";
}

normalizeAsset(asset: string | number): string | number {
if (asset == "BTC") return 1;
else if (asset == "LTC") return 2;
else if (asset == "ETH") return 4;
else if (asset == "TUSD") return 6;
else if (asset == "XRP") return 10;
else if (asset == 1) return "BTC";
else if (asset == 2) return "LTC";
else if (asset == 4) return "ETH";
else if (asset == 6) return "TUSD";
else if (asset == 10) return "XRP";
return asset;
}

async getTicker(base: string, quote: string): Promise<ITicker> {
Expand All @@ -29,4 +58,18 @@ export class foxbit<T> extends Exchange<T> {
vol: res.vol,
};
}

async getAllTickers(): Promise<ITicker[]> {
const res = await this.fetch<IFoxbitAllTickers[]>(this.tickerUrl);

return res.map((ticker) => ({
exchangeId: this.id,
base: ticker.symbol,
quote: "BRL",
last: ticker.price,
ask: ticker.price,
bid: ticker.price,
vol: ticker.volume,
}));
}
}
Loading

0 comments on commit b7aee1c

Please sign in to comment.