Skip to content

Commit

Permalink
Merge pull request #19 from coinsambacom/feat/paxos
Browse files Browse the repository at this point in the history
Feat/paxos
  • Loading branch information
itxtoledo authored Nov 22, 2023
2 parents 4ee47fd + a208169 commit ad3d13c
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ binance.getAllTickers().then(tickers => console.log(tickers));
| noxbitcoin 🇧🇷 | 1 | | | |
| pagcripto_otc 🇧🇷 | 1 | | | 1 |
| pagcripto 🇧🇷 | 1 | | 1 | 1 |
| paxos 🌐 | 1 | | | 1 |
| poloniex 🌐 | 1 | 1 | | 1 |
| quidax 🇳🇬 | | | 1 | 1 |
| satoshitango 🇦🇷 | | | 1 | 1 |
Expand Down
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.11",
"version": "2.1.12",
"repository": "[email protected]:coinsambacom/js-exchanges-connector.git",
"author": "Gustavo <[email protected]>",
"license": "MIT",
Expand Down
86 changes: 86 additions & 0 deletions src/connectors/paxos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {
Exchange,
IExchangeImplementationConstructorArgs,
} from "../interfaces/exchange";
import { IOrderbook, ITicker } from "../utils/DTOs";

interface PaxosTickerRes {
market: string;
best_bid: Bestbid;
best_ask: Bestbid;
last_execution: Bestbid;
last_day: Lastday;
today: Lastday;
snapshot_at: string;
}

interface Lastday {
high: string;
low: string;
open: string;
volume: string;
volume_weighted_average_price: string;
range: Range;
}

interface Range {
begin: string;
end: string;
}

interface Bestbid {
price: string;
amount: string;
}

interface PaxosOrderbookRes {
market: string;
asks: IPaxosOrderbookOrder[];
bids: IPaxosOrderbookOrder[];
}

interface IPaxosOrderbookOrder {
price: string;
amount: string;
}

export class paxos<T = any> extends Exchange<T> {
constructor(args?: IExchangeImplementationConstructorArgs<T>) {
super({
id: "paxos",
baseUrl: "https://api.paxos.com",
opts: args?.opts,
});
}

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

return {
exchangeId: this.id,
base,
quote,
last: Number(res.last_execution.price),
ask: Number(res.best_ask.price),
bid: Number(res.best_bid.price),
vol: Number(res.today.volume),
};
}

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

async getBook(base: string, quote: string): Promise<IOrderbook> {
const res = await this.fetch<PaxosOrderbookRes>(
`${this.baseUrl}/v2/markets/${base}${quote}/order-book`,
);

return {
asks: res.asks.map(this.parseOrder),
bids: res.bids.map(this.parseOrder),
};
}
}
1 change: 1 addition & 0 deletions src/exchanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export { mercadobitcoin } from "./connectors/mercadobitcoin";
export { novadax } from "./connectors/novadax";
export { noxbitcoin } from "./connectors/noxbitcoin";
export { pagcripto } from "./connectors/pagcripto";
export { paxos } from "./connectors/paxos";
export { pagcripto_otc } from "./connectors/pagcripto_otc";
export { poloniex } from "./connectors/poloniex";
export { satoshitango } from "./connectors/satoshitango";
Expand Down
46 changes: 46 additions & 0 deletions test/paxos.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { expect } from "chai";
import { paxos } from "../src/connectors/paxos";
import { FetcherHandler } from "../src/utils/DTOs";
import { MyFetcher } from "./utils/MyFetcher";
import { expectPropertyTypes } from "./utils/helpers";

describe("paxos", () => {
let exchange: paxos;

beforeEach(() => {
exchange = new paxos();
const fetcher = new MyFetcher();

FetcherHandler.setFetcher(fetcher);
});

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

expectPropertyTypes(ticker, ["exchangeId", "base", "quote"], "string");
expectPropertyTypes(ticker, ["last", "ask", "bid", "vol"], "number");
});
});

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

expect(book).to.have.property("asks");
expect(book).to.have.property("bids");
expect(Array.isArray(book.asks)).to.be.true;
expect(Array.isArray(book.bids)).to.be.true;

if (book.asks.length > 0) {
const ask = book.asks[0];
expectPropertyTypes(ask, ["price", "amount"], "number");
}

if (book.bids.length > 0) {
const bid = book.bids[0];
expectPropertyTypes(bid, ["price", "amount"], "number");
}
});
});
});

0 comments on commit ad3d13c

Please sign in to comment.