Comparing version
@@ -43,6 +43,6 @@ "use strict"; | ||
return function subscribe(request) { | ||
const { timeframe, since, onNewData, priceUnit, pollingInterval = primitives_1.DEFAULT_POLLING_INTERVAL, } = request; | ||
const { timeframe, since, onNewData, priceUnit, pollingInterval = primitives_1.DEFAULT_POLLING_INTERVAL, variant, } = request; | ||
let lastTimestamp = since; | ||
const intervalId = setInterval(async () => { | ||
const data = await query({ priceUnit, since: lastTimestamp, timeframe }); | ||
const data = await query({ priceUnit, since: lastTimestamp, timeframe, variant }); | ||
if (data.length) { | ||
@@ -49,0 +49,0 @@ lastTimestamp = data[data.length - 1].timestamp; |
@@ -30,3 +30,6 @@ import { PriceUnit, Timeframe } from "./primitives"; | ||
precision: number; | ||
value?: string; | ||
/** | ||
* @default false | ||
*/ | ||
requiresRefetch?: boolean; | ||
}; | ||
@@ -33,0 +36,0 @@ export declare type Metric = { |
@@ -108,4 +108,8 @@ "use strict"; | ||
significantDigits: [2], | ||
timeframes: ["Minute", "Hour", "Day", "Week"], | ||
timeframes: ["Minute", "Hour", "Day"], | ||
title: "Ether price", | ||
variants: [ | ||
{ label: "Coinbase", precision: 1, requiresRefetch: true }, | ||
{ label: "Binance", precision: 1, requiresRefetch: true }, | ||
], | ||
}, | ||
@@ -119,3 +123,3 @@ tx_cost: { | ||
significantDigits: [2, 5], | ||
timeframes: ["Minute", "Hour", "Day", "Week"], | ||
timeframes: ["Minute", "Hour", "Day"], | ||
title: "Transaction cost", | ||
@@ -122,0 +126,0 @@ variants: [ |
@@ -1,4 +0,6 @@ | ||
declare const query: (request: import("../../primitives").QueryRequest) => import("../../primitives").QueryResult; | ||
export default query; | ||
export declare const subscribe: (request: import("../../primitives").SubscribeRequest) => import("../../primitives").SubscribeResult; | ||
import { QueryRequest, QueryResult, SubscribeRequest, SubscribeResult } from "../../protofun"; | ||
export default function query(request: QueryRequest): QueryResult; | ||
export declare const binanceSub: (request: SubscribeRequest) => SubscribeResult; | ||
export declare const coinbaseSub: (request: SubscribeRequest) => SubscribeResult; | ||
export declare function subscribe(request: SubscribeRequest): SubscribeResult; | ||
//# sourceMappingURL=eth_price.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.subscribe = void 0; | ||
exports.subscribe = exports.coinbaseSub = exports.binanceSub = void 0; | ||
const binance_adapter_1 = require("../../adapters/binance-adapter"); | ||
const coinbase_adapter_1 = require("../../adapters/coinbase-adapter"); | ||
const protofun_1 = require("../../protofun"); | ||
const query = (0, binance_adapter_1.createBinanceQuery)("ETHUSDT", (0, protofun_1.getMetric)("eth", "eth_price").timeframes); | ||
const coinbase = (0, coinbase_adapter_1.createCoinbaseQuery)("ETH-USD", (0, protofun_1.getMetric)("eth", "eth_price").timeframes); | ||
const binance = (0, binance_adapter_1.createBinanceQuery)("ETHUSDT", (0, protofun_1.getMetric)("eth", "eth_price").timeframes); | ||
async function query(request) { | ||
if (request.variant === 1) { | ||
return binance(request); | ||
} | ||
return coinbase(request); | ||
} | ||
exports.default = query; | ||
exports.subscribe = (0, binance_adapter_1.createBinanceSubscribe)(query); | ||
exports.binanceSub = (0, binance_adapter_1.createBinanceSubscribe)(query); | ||
exports.coinbaseSub = (0, coinbase_adapter_1.createCoinbaseSubscribe)(query); | ||
function subscribe(request) { | ||
if (request.variant === 1) { | ||
return (0, exports.binanceSub)(request); | ||
} | ||
return (0, exports.coinbaseSub)(request); | ||
} | ||
exports.subscribe = subscribe; | ||
//# sourceMappingURL=eth_price.js.map |
@@ -21,3 +21,3 @@ "use strict"; | ||
? Promise.resolve([]) | ||
: (0, eth_price_1.default)({ limit, since, timeframe, until }), | ||
: (0, eth_price_1.default)({ limit, since, timeframe, until, variant: 0 }), | ||
]); | ||
@@ -24,0 +24,0 @@ if (priceUnit === primitives_1.PriceUnit.ETH) { |
@@ -16,21 +16,16 @@ export declare type Timeframe = "Block" | "Minute" | "Hour" | "Day" | "Week"; | ||
/** | ||
* | ||
* | ||
* [ | ||
* [ | ||
* 1499040000000, // Kline open time | ||
* "0.01634790", // Open price | ||
* "0.80000000", // High price | ||
* "0.01575800", // Low price | ||
* "0.01577100", // Close price | ||
* "148976.11427815", // Volume | ||
* 1499644799999, // Kline Close time | ||
* "2434.19055334", // Quote asset volume | ||
* 308, // Number of trades | ||
* "1756.87402397", // Taker buy base asset volume | ||
* "28.46694368", // Taker buy quote asset volume | ||
* "0" // Unused field, ignore. | ||
* ] | ||
* 1499040000000, // Kline open time | ||
* "0.01634790", // Open price | ||
* "0.80000000", // High price | ||
* "0.01575800", // Low price | ||
* "0.01577100", // Close price | ||
* "148976.11427815", // Volume | ||
* 1499644799999, // Kline Close time | ||
* "2434.19055334", // Quote asset volume | ||
* 308, // Number of trades | ||
* "1756.87402397", // Taker buy base asset volume | ||
* "28.46694368", // Taker buy quote asset volume | ||
* "0" // Unused field, ignore. | ||
* ] | ||
* | ||
*/ | ||
@@ -45,2 +40,20 @@ export declare type BinanceKline = [ | ||
]; | ||
/** | ||
* [ | ||
* 1696564320, // time - bucket start time | ||
* 27557.89, // low - lowest price during the bucket interval | ||
* 27567.36, // high - highest price during the bucket interval | ||
* 27566.42, // open - opening price (first trade) in the bucket interval | ||
* 27562.16, // close - closing price (last trade) in the bucket interval | ||
* 4.15468916 // volume - volume of trading activity during the bucket interval | ||
* ] | ||
*/ | ||
export declare type CoinbaseBucket = [ | ||
number, | ||
number, | ||
number, | ||
number, | ||
number, | ||
number | ||
]; | ||
export declare type Candle = { | ||
@@ -63,2 +76,3 @@ close: string; | ||
until?: string; | ||
variant?: number; | ||
}; | ||
@@ -69,2 +83,3 @@ export declare type QueryResult = Promise<Candle[]>; | ||
export declare type SubscribeRequest = { | ||
onError?: (error: unknown) => void; | ||
onNewData: (data: Candle) => void; | ||
@@ -79,2 +94,3 @@ /** | ||
timeframe: Timeframe; | ||
variant?: number; | ||
}; | ||
@@ -81,0 +97,0 @@ export declare type LoggerFn = (message: string, metadata?: object) => void; |
{ | ||
"name": "protofun", | ||
"license": "UNLICENSED", | ||
"version": "0.2.10", | ||
"version": "0.3.0", | ||
"files": [ | ||
@@ -6,0 +6,0 @@ "dist", |
@@ -63,2 +63,3 @@ import { | ||
pollingInterval = DEFAULT_POLLING_INTERVAL, | ||
variant, | ||
} = request | ||
@@ -68,3 +69,3 @@ let lastTimestamp = since | ||
const intervalId = setInterval(async () => { | ||
const data = await query({ priceUnit, since: lastTimestamp, timeframe }) | ||
const data = await query({ priceUnit, since: lastTimestamp, timeframe, variant }) | ||
@@ -71,0 +72,0 @@ if (data.length) { |
@@ -75,3 +75,6 @@ import { PriceUnit, Timeframe } from "./primitives" | ||
precision: number | ||
value?: string | ||
/** | ||
* @default false | ||
*/ | ||
requiresRefetch?: boolean | ||
} | ||
@@ -159,4 +162,8 @@ | ||
significantDigits: [2], | ||
timeframes: ["Minute", "Hour", "Day", "Week"], | ||
timeframes: ["Minute", "Hour", "Day"], // TODO | ||
title: "Ether price", | ||
variants: [ | ||
{ label: "Coinbase", precision: 1, requiresRefetch: true }, | ||
{ label: "Binance", precision: 1, requiresRefetch: true }, | ||
], | ||
}, | ||
@@ -170,3 +177,3 @@ tx_cost: { | ||
significantDigits: [2, 5], | ||
timeframes: ["Minute", "Hour", "Day", "Week"], | ||
timeframes: ["Minute", "Hour", "Day"], // TODO | ||
title: "Transaction cost", | ||
@@ -173,0 +180,0 @@ variants: [ |
@@ -5,2 +5,3 @@ import { createClient, fetchExchange, gql } from "urql/core" | ||
import { | ||
Candle, | ||
DEFAULT_POLLING_INTERVAL, | ||
@@ -80,3 +81,3 @@ QueryRequest, | ||
const data = response.data[collection] as MarketDailySnapshot[] | ||
const parsed = [] | ||
const parsed: Candle[] = [] | ||
@@ -83,0 +84,0 @@ for (let i = data.length - 1; i >= 0; i--) { |
import { createBinanceQuery, createBinanceSubscribe } from "../../adapters/binance-adapter" | ||
import { getMetric } from "../../protofun" | ||
import { createCoinbaseQuery, createCoinbaseSubscribe } from "../../adapters/coinbase-adapter" | ||
import { | ||
getMetric, | ||
QueryRequest, | ||
QueryResult, | ||
SubscribeRequest, | ||
SubscribeResult, | ||
} from "../../protofun" | ||
const query = createBinanceQuery("ETHUSDT", getMetric("eth", "eth_price").timeframes) | ||
const coinbase = createCoinbaseQuery("ETH-USD", getMetric("eth", "eth_price").timeframes) | ||
const binance = createBinanceQuery("ETHUSDT", getMetric("eth", "eth_price").timeframes) | ||
export default query | ||
export default async function query(request: QueryRequest): QueryResult { | ||
if (request.variant === 1) { | ||
return binance(request) | ||
} | ||
export const subscribe = createBinanceSubscribe(query) | ||
return coinbase(request) | ||
} | ||
export const binanceSub = createBinanceSubscribe(query) | ||
export const coinbaseSub = createCoinbaseSubscribe(query) | ||
export function subscribe(request: SubscribeRequest): SubscribeResult { | ||
if (request.variant === 1) { | ||
return binanceSub(request) | ||
} | ||
return coinbaseSub(request) | ||
} |
@@ -27,3 +27,3 @@ import { | ||
? Promise.resolve([]) | ||
: queryEtherPrice({ limit, since, timeframe, until }), | ||
: queryEtherPrice({ limit, since, timeframe, until, variant: 0 }), | ||
]) | ||
@@ -30,0 +30,0 @@ |
@@ -27,21 +27,16 @@ export type Timeframe = "Block" | "Minute" | "Hour" | "Day" | "Week" | ||
/** | ||
* | ||
* | ||
* [ | ||
* [ | ||
* 1499040000000, // Kline open time | ||
* "0.01634790", // Open price | ||
* "0.80000000", // High price | ||
* "0.01575800", // Low price | ||
* "0.01577100", // Close price | ||
* "148976.11427815", // Volume | ||
* 1499644799999, // Kline Close time | ||
* "2434.19055334", // Quote asset volume | ||
* 308, // Number of trades | ||
* "1756.87402397", // Taker buy base asset volume | ||
* "28.46694368", // Taker buy quote asset volume | ||
* "0" // Unused field, ignore. | ||
* ] | ||
* 1499040000000, // Kline open time | ||
* "0.01634790", // Open price | ||
* "0.80000000", // High price | ||
* "0.01575800", // Low price | ||
* "0.01577100", // Close price | ||
* "148976.11427815", // Volume | ||
* 1499644799999, // Kline Close time | ||
* "2434.19055334", // Quote asset volume | ||
* 308, // Number of trades | ||
* "1756.87402397", // Taker buy base asset volume | ||
* "28.46694368", // Taker buy quote asset volume | ||
* "0" // Unused field, ignore. | ||
* ] | ||
* | ||
*/ | ||
@@ -57,2 +52,21 @@ export type BinanceKline = [ | ||
/** | ||
* [ | ||
* 1696564320, // time - bucket start time | ||
* 27557.89, // low - lowest price during the bucket interval | ||
* 27567.36, // high - highest price during the bucket interval | ||
* 27566.42, // open - opening price (first trade) in the bucket interval | ||
* 27562.16, // close - closing price (last trade) in the bucket interval | ||
* 4.15468916 // volume - volume of trading activity during the bucket interval | ||
* ] | ||
*/ | ||
export type CoinbaseBucket = [ | ||
number, // time | ||
number, // low | ||
number, // high | ||
number, // open | ||
number, // close | ||
number // volume | ||
] | ||
export type Candle = { | ||
@@ -76,2 +90,3 @@ close: string | ||
until?: string | ||
variant?: number | ||
} | ||
@@ -84,2 +99,3 @@ export type QueryResult = Promise<Candle[]> | ||
export type SubscribeRequest = { | ||
onError?: (error: unknown) => void | ||
onNewData: (data: Candle) => void | ||
@@ -94,2 +110,3 @@ /** | ||
timeframe: Timeframe | ||
variant?: number | ||
} | ||
@@ -96,0 +113,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
93814
17.4%77
6.94%1812
17.36%2
100%