Add bisqJS and liquidJS npm modules.

This commit is contained in:
Miguel Medeiros
2021-08-10 01:30:13 -03:00
parent acc0c80953
commit 4efc927303
116 changed files with 5504 additions and 4137 deletions

137
src/app/bisq/markets.ts Normal file
View File

@@ -0,0 +1,137 @@
import { AxiosInstance } from 'axios';
import { Currencies, Depth, Markets, Hloc, MarketsInstance, Offers, Trades, Volumes } from '../../interfaces/bisq/markets';
export const useMarkets = (api: AxiosInstance): MarketsInstance => {
const getCurrencies = async (
params: {
basecurrency?: string;
type?: string;
format?: string;
} = {
basecurrency: 'BTC',
type: 'all',
format: 'jsonpretty',
}
) => {
const { data } = await api.get<Currencies>('/currencies', { params });
return data;
};
const getDepth = async (
params: {
market: string;
format?: string;
} = {
market: 'xmr_btc',
format: 'jsonpretty',
}
) => {
const { data } = await api.get<Depth>('/depth', { params });
return data;
};
const getHloc = async (params: {
market: string;
interval?: string;
timestamp_from?: string;
timestamp_to?: string;
format?: string;
}) => {
const { data } = await api.get<Hloc[]>('/hloc', { params });
return data;
};
const getMarkets = async (
params: {
format?: string;
} = {
format: 'jsonpretty',
}
) => {
const { data } = await api.get<Markets>('/markets', { params });
return data;
};
const getOffers = async (
params: {
market: string;
direction?: string;
format?: string;
} = {
market: 'xmr_btc',
format: 'jsonpretty',
}
) => {
const { data } = await api.get<Offers>('/offers', { params });
return data;
};
const getTicker = async (
params: {
market?: string;
format?: string;
} = {
format: 'jsonpretty',
}
) => {
const { data } = await api.get('/ticker', { params });
return data;
};
const getTrades = async (
params: {
market: string;
format?: string;
timestamp_from?: string;
timestamp_to?: string;
trade_id_from?: string;
trade_id_to?: string;
limit?: number;
sort?: string;
} = {
market: 'all',
format: 'jsonpretty',
timestamp_from: '2016-01-01',
timestamp_to: 'now',
limit: 100,
sort: 'desc',
}
) => {
const { data } = await api.get<Trades[]>('/trades', { params });
return data;
};
const getVolumes = async (
params: {
basecurrency: string;
market: string;
interval?: string;
timestamp_from?: string;
timestamp_to?: string;
format?: string;
} = {
basecurrency: '',
market: '',
interval: 'auto',
timestamp_from: '2016-01-01',
timestamp_to: 'now',
format: 'jsonpretty',
}
) => {
const { data } = await api.get<Volumes[]>('/trades', { params });
return data;
};
return {
getCurrencies,
getDepth,
getHloc,
getMarkets,
getOffers,
getTicker,
getTrades,
getVolumes,
};
};

View File

@@ -56,8 +56,8 @@ export const useTransactions = (api: AxiosInstance): TxInstance => {
return data;
};
const postTx = async (params: { txid: string }) => {
const { data } = await api.post<string>(`/tx`, { txid: params.txid });
const postTx = async (params: { txhex: string }) => {
const { data } = await api.post<string>(`/tx`, { txhex: params.txhex });
return data;
};

View File

@@ -56,8 +56,8 @@ export const useTransactions = (api: AxiosInstance): TxInstance => {
return data;
};
const postTx = async (params: { txid: string }) => {
const { data } = await api.post<string>(`/tx`, { txid: params.txid });
const postTx = async (params: { txhex: string }) => {
const { data } = await api.post<string>(`/tx`, { txid: params.txhex });
return data;
};

33
src/index-bisq.ts Normal file
View File

@@ -0,0 +1,33 @@
import { MempoolConfig, BisqMarketsReturn } from './interfaces/index';
import { makeBisqAPI, makeBisqMarketsAPI } from './services/api/index';
import { useAddresses as useAddressesBisq } from './app/bisq/addresses';
import { useBlocks as useBlocksBisq } from './app/bisq/blocks';
import { useStatistics as useStatisticsBisq } from './app/bisq/statistics';
import { useTransactions as useTransactionsBisq } from './app/bisq/transactions';
import { useMarkets as useMarkets } from './app/bisq/markets';
const hostnameEndpointDefault = 'mempool.space';
const networkEndpointDefault = 'bisq';
const mempool = ({ hostname, network }: MempoolConfig = {
hostname: hostnameEndpointDefault,
network: networkEndpointDefault,
}): BisqMarketsReturn => {
if (!hostname) hostname = hostnameEndpointDefault;
if (!network) network = networkEndpointDefault;
const { api: apiBisq } = makeBisqAPI(hostname);
const { api: apiBisqMarkets } = makeBisqMarketsAPI();
return {
statistics: useStatisticsBisq(apiBisq),
addresses: useAddressesBisq(apiBisq),
blocks: useBlocksBisq(apiBisq),
transactions: useTransactionsBisq(apiBisq),
markets: useMarkets(apiBisqMarkets),
};
};
mempool.default = mempool;
export = mempool;

41
src/index-liquid.ts Normal file
View File

@@ -0,0 +1,41 @@
import { MempoolConfig, LiquidNetworkReturn } from './interfaces/index';
import {
makeLiquidAPI,
} from './services/api/index';
import { useAssets as useAssetsLiquid } from './app/liquid/assets';
import { useAddresses as useAddressesLiquid } from './app/liquid/addresses';
import { useBlocks as useBlocksLiquid } from './app/liquid/blocks';
import { useFees as useFeesLiquid } from './app/liquid/fees';
import { useMempool as useMempoolLiquid } from './app/liquid/mempool';
import { useTransactions as useTransactionsLiquid } from './app/liquid/transactions';
import { useWebsocket as useWebsocketLiquid } from './app/liquid/websocket';
const hostnameEndpointDefault = 'mempool.space';
const networkEndpointDefault = 'liquid';
const mempool = (
{
hostname, network }: MempoolConfig = {
hostname: hostnameEndpointDefault,
network: networkEndpointDefault,
}
): LiquidNetworkReturn => {
if (!hostname) hostname = hostnameEndpointDefault;
if (!network) network = networkEndpointDefault;
const { api: apiLiquid } = makeLiquidAPI(hostname);
return {
addresses: useAddressesLiquid(apiLiquid),
assets: useAssetsLiquid(apiLiquid),
blocks: useBlocksLiquid(apiLiquid),
fees: useFeesLiquid(apiLiquid),
mempool: useMempoolLiquid(apiLiquid),
transactions: useTransactionsLiquid(apiLiquid),
websocket: useWebsocketLiquid(hostname),
};
};
mempool.default = mempool;
export = mempool;

View File

@@ -3,6 +3,7 @@ import {
makeBitcoinAPI,
makeBisqAPI,
makeLiquidAPI,
makeBisqMarketsAPI
} from './services/api/index';
import { useAddresses } from './app/bitcoin/addresses';
@@ -17,6 +18,7 @@ import { useAddresses as useAddressesBisq } from './app/bisq/addresses';
import { useBlocks as useBlocksBisq } from './app/bisq/blocks';
import { useStatistics as useStatisticsBisq } from './app/bisq/statistics';
import { useTransactions as useTransactionsBisq } from './app/bisq/transactions';
import { useMarkets as useMarkets } from './app/bisq/markets';
import { useAssets as useAssetsLiquid } from './app/liquid/assets';
import { useAddresses as useAddressesLiquid } from './app/liquid/addresses';
@@ -40,8 +42,8 @@ const mempool = (
const { api: apiBitcoin } = makeBitcoinAPI({ hostname, network });
const { api: apiBisq } = makeBisqAPI(hostname);
const { api: apiBisqMarkets } = makeBisqMarketsAPI();
const { api: apiLiquid } = makeLiquidAPI(hostname);
return {
bitcoin: {
addresses: useAddresses(apiBitcoin),
@@ -57,6 +59,7 @@ const mempool = (
addresses: useAddressesBisq(apiBisq),
blocks: useBlocksBisq(apiBisq),
transactions: useTransactionsBisq(apiBisq),
markets: useMarkets(apiBisqMarkets),
},
liquid: {
addresses: useAddressesLiquid(apiLiquid),

View File

@@ -0,0 +1,170 @@
export interface Currencies {
[key: string]: {
code: string;
name: string;
precision: number;
_type: string;
};
}
export interface Depth {
[key: string]: {
buys: string[];
sells: string[];
};
}
export interface Hloc {
period_start: number;
open: string;
close: string;
high: string;
low: string;
avg: string;
volume_right: string;
volume_left: string;
}
export interface Markets {
[key: string]: {
pair: string;
lname: string;
rname: string;
lsymbol: string;
rsymbol: string;
lprecision: number;
rprecision: number;
ltype: string;
rtype: string;
name: string;
};
}
export interface Offers {
[key: string]: {
buys: {
offer_id: string;
offer_date: number;
direction: string;
min_amount: string;
amount: string;
price: string;
volume: string;
payment_method: string;
offer_fee_txid: string;
}[];
sells: {
offer_id: string;
offer_date: number;
direction: string;
min_amount: string;
amount: string;
price: string;
volume: string;
payment_method: string;
offer_fee_txid: string;
}[];
};
}
export interface Ticker {
[key: string]: {
last: string;
high: string;
low: string;
volume_left: number;
volume_right: number;
buy: string;
sell: string;
};
}
export interface Trades {
price: string;
amount: string;
volume: string;
payment_method: string;
trade_date: number;
market: string;
}
export interface Volumes {
price: string;
amount: string;
volume: string;
payment_method: string;
trade_date: number;
}
export interface MarketsInstance {
getCurrencies: (
params?: {
basecurrency?: string;
type?: string;
format?: string;
}
) => Promise<Currencies>;
getDepth: (
params: {
market: string;
format?: string;
}
) => Promise<Depth>;
getHloc: (
params: {
market: string;
interval?: string;
timestamp_from?: string;
timestamp_to?: string;
format?: string;
}
) => Promise<Hloc[]>;
getMarkets: (
params?: {
format?: string;
}
) => Promise<Markets>;
getOffers: (
params: {
market: string;
direction?: string;
format?: string;
}
) => Promise<Offers>;
getTicker: (
params: {
market: string;
format?: string;
}
) => Promise<Ticker>;
getTrades: (
params: {
market: string;
format?: string;
timestamp_from?: string;
timestamp_to?: string;
trade_id_from?: string;
trade_id_to?: string;
limit?: number;
sort?: string;
}
) => Promise<Trades[]>;
getVolumes: (
params: {
basecurrency: string;
market: string;
interval?: string;
timestamp_from?: string;
timestamp_to?: string;
format?: string;
}
) => Promise<Volumes[]>;
}

View File

@@ -58,5 +58,5 @@ export interface TxInstance {
vout: number;
}) => Promise<TxOutspend>;
getTxOutspends: (params: { txid: string }) => Promise<Array<TxOutspend>>;
postTx: (params: { txid: string }) => Promise<unknown>;
postTx: (params: { txhex: string }) => Promise<unknown>;
}

View File

@@ -10,6 +10,7 @@ import { AddressesInstance } from './bisq/addresses';
import { BlocksInstance } from './bisq/blocks';
import { StatsInstance } from './bisq/statistics';
import { TransactionsInstance } from './bisq/transactions';
import { MarketsInstance } from './bisq/markets';
import { AssetsInstance } from './liquid/assets';
import { BlockLiquidInstance } from './liquid/block';
@@ -33,6 +34,7 @@ export interface MempoolReturn {
blocks: BlocksInstance;
statistics: StatsInstance;
transactions: TransactionsInstance;
markets: MarketsInstance;
};
liquid: {
assets: AssetsInstance;
@@ -44,3 +46,19 @@ export interface MempoolReturn {
websocket: WsInstance;
};
}
export interface BisqMarketsReturn {
addresses: AddressesInstance;
blocks: BlocksInstance;
statistics: StatsInstance;
transactions: TransactionsInstance;
markets: MarketsInstance;
}
export interface LiquidNetworkReturn {
assets: AssetsInstance;
addresses: AddressInstance;
blocks: BlockLiquidInstance;
fees: FeeInstance;
mempool: MempoolInstance;
transactions: TxInstance;
websocket: WsInstance;
}

View File

@@ -47,6 +47,15 @@ export const makeBisqAPI = (hostname?: string): { api: AxiosInstance } => {
};
};
export const makeBisqMarketsAPI = (): { api: AxiosInstance } => {
const api = axios.create({
baseURL: `https://bisq.markets/api/v1/markets/`,
});
return {
api,
};
};
export const makeLiquidAPI = (hostname?: string): { api: AxiosInstance } => {
if(hostname?.includes("localhost")){
@@ -69,5 +78,6 @@ export const makeLiquidAPI = (hostname?: string): { api: AxiosInstance } => {
export default {
makeBitcoinAPI,
makeBisqAPI,
makeBisqMarketsAPI,
makeLiquidAPI,
};