-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from coinsambacom/feat/isis-trade
added isis trade
- Loading branch information
Showing
6 changed files
with
148 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.10", | ||
"version": "2.1.11", | ||
"repository": "[email protected]:coinsambacom/js-exchanges-connector.git", | ||
"author": "Gustavo <[email protected]>", | ||
"license": "MIT", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { | ||
Exchange, | ||
IExchangeImplementationConstructorArgs, | ||
} from "../interfaces/exchange"; | ||
import { IOrderbook, IOrderbookOrder, ITicker } from "../utils/DTOs"; | ||
import { parseBRLNumberString } from "../utils/utils"; | ||
|
||
interface BaseRes<T> { | ||
success: boolean; | ||
message: string; | ||
result: T; | ||
} | ||
|
||
interface IsisTradeOrderbookOrder { | ||
timestamp: number; | ||
price: string; | ||
quantity: string; | ||
} | ||
|
||
export class isistrade<T = any> extends Exchange<T> { | ||
constructor(args?: IExchangeImplementationConstructorArgs<T>) { | ||
super({ | ||
id: "isistrade", | ||
baseUrl: "https://isistrade.com/api", | ||
opts: args?.opts, | ||
}); | ||
} | ||
|
||
async getAllTickersByQuote(quote: string): Promise<ITicker[]> { | ||
const res = await this.fetch< | ||
BaseRes< | ||
{ | ||
timestamp: number; | ||
marketName: string; | ||
marketAsset: string; | ||
baseAsset: string; | ||
marketAssetName: string; | ||
baseAssetName: string; | ||
high: string; | ||
low: string; | ||
last: string; | ||
volume: string; | ||
baseVolume: string; | ||
bid: string; | ||
ask: string; | ||
isActive: boolean; | ||
infoMessage: string; | ||
}[] | ||
> | ||
>(`${this.baseUrl}/public/marketsummaries?basemarket=${quote}`); | ||
|
||
return res.result.map((t) => ({ | ||
exchangeId: this.id, | ||
base: t.marketAsset, | ||
quote: t.baseAsset, | ||
ask: parseBRLNumberString(t.ask), | ||
bid: parseBRLNumberString(t.bid), | ||
last: parseBRLNumberString(t.last), | ||
vol: parseBRLNumberString(t.volume), | ||
})); | ||
} | ||
|
||
private parseOrder({ | ||
price, | ||
quantity, | ||
}: IsisTradeOrderbookOrder): IOrderbookOrder { | ||
return { | ||
price: Number(price), | ||
amount: Number(quantity), | ||
}; | ||
} | ||
|
||
async getBook(base: string, quote: string): Promise<IOrderbook> { | ||
const res = await this.fetch< | ||
BaseRes<{ | ||
sell: IsisTradeOrderbookOrder[]; | ||
buy: IsisTradeOrderbookOrder[]; | ||
}> | ||
>( | ||
`${this.baseUrl}/public/orderbook?market=${base}_${quote}&type=ALL&depth=20`, | ||
); | ||
|
||
return { | ||
asks: res.result.sell.map(this.parseOrder), | ||
bids: res.result.buy.map(this.parseOrder), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const parseBRLNumberString = (numberInString: string) => { | ||
const strFormatted = numberInString.replace(/\./g, "").replace(",", "."); | ||
|
||
return parseFloat(strFormatted); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { expect } from "chai"; | ||
import { isistrade } from "../src/connectors/isistrade"; | ||
import { FetcherHandler } from "../src/utils/DTOs"; | ||
import { MyFetcher } from "./utils/MyFetcher"; | ||
import { expectPropertyTypes } from "./utils/helpers"; | ||
|
||
describe("isistrade", () => { | ||
let exchange: isistrade; | ||
|
||
beforeEach(() => { | ||
exchange = new isistrade(); | ||
const fetcher = new MyFetcher(); | ||
|
||
FetcherHandler.setFetcher(fetcher); | ||
}); | ||
|
||
describe("getAllTickersByQuote", () => { | ||
it("should return an array of ITicker objects", async () => { | ||
const tickers = await exchange.getAllTickersByQuote("BRL"); | ||
|
||
expect(Array.isArray(tickers)).to.be.true; | ||
|
||
if (tickers.length > 0) { | ||
const ticker = tickers[0]; | ||
|
||
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", "BRL"); | ||
|
||
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"); | ||
} | ||
}); | ||
}); | ||
}); |