@taphubhq/sdk-core 0.23.0 → 0.23.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +27 -47
- package/dist/index.d.mts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +27 -47
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -472,6 +472,8 @@ function normaliseBid(node) {
|
|
|
472
472
|
price2: node.price2,
|
|
473
473
|
status: coerceStatus(node.status),
|
|
474
474
|
payout: node.payout || null,
|
|
475
|
+
refundRate: node.refund_rate ?? null,
|
|
476
|
+
refundAmount: node.refund_amount ?? null,
|
|
475
477
|
slippage: node.slippage,
|
|
476
478
|
createdAt: node.created_at || null,
|
|
477
479
|
meta: parseMeta(node.meta)
|
|
@@ -494,12 +496,12 @@ var PLACE_BID_MUTATION = `mutation PlaceBid($input: PlaceBidInput!) {
|
|
|
494
496
|
}`;
|
|
495
497
|
var MY_BIDS_QUERY = `query MyBids($statuses: [BidStatus!], $limit: Int, $offset: Int, $pairId: ID) {
|
|
496
498
|
myBids(statuses: $statuses, limit: $limit, offset: $offset, pairId: $pairId) {
|
|
497
|
-
id user_id pair_id currency amount coefficient time1 time2 price1 price2 status payout slippage created_at meta
|
|
499
|
+
id user_id pair_id currency amount coefficient time1 time2 price1 price2 status payout refund_rate refund_amount slippage created_at meta
|
|
498
500
|
}
|
|
499
501
|
}`;
|
|
500
502
|
var CANCEL_BID_MUTATION = `mutation CancelBid($input: CancelBidInput!) {
|
|
501
503
|
cancelBid(input: $input) {
|
|
502
|
-
bid { id user_id pair_id currency amount coefficient time1 time2 price1 price2 status cancelled payout slippage created_at meta }
|
|
504
|
+
bid { id user_id pair_id currency amount coefficient time1 time2 price1 price2 status cancelled payout refund_rate refund_amount slippage created_at meta }
|
|
503
505
|
refund_amount
|
|
504
506
|
new_balance
|
|
505
507
|
}
|
|
@@ -1828,31 +1830,11 @@ function classifyBackendHealth(samples) {
|
|
|
1828
1830
|
}
|
|
1829
1831
|
return "ok";
|
|
1830
1832
|
}
|
|
1831
|
-
var
|
|
1832
|
-
var
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
var JITTER_LEAVE_POOR = 120;
|
|
1837
|
-
var isPoor = (m) => m.rtt > RTT_FAIR_TO_POOR || m.jitter > JITTER_POOR;
|
|
1838
|
-
var canLeavePoor = (m) => m.rtt < RTT_POOR_TO_FAIR && m.jitter < JITTER_LEAVE_POOR;
|
|
1839
|
-
var isFairUpper = (rtt) => rtt > RTT_GOOD_TO_FAIR;
|
|
1840
|
-
var canReachGood = (rtt) => rtt < RTT_FAIR_TO_GOOD;
|
|
1841
|
-
function classifyNetworkLevel(metrics, current) {
|
|
1842
|
-
if (current === "offline") {
|
|
1843
|
-
return isPoor(metrics) ? "poor" : "fair";
|
|
1844
|
-
}
|
|
1845
|
-
if (current === "good") {
|
|
1846
|
-
if (isPoor(metrics)) return "fair";
|
|
1847
|
-
if (isFairUpper(metrics.rtt)) return "fair";
|
|
1848
|
-
return "good";
|
|
1849
|
-
}
|
|
1850
|
-
if (current === "fair") {
|
|
1851
|
-
if (isPoor(metrics)) return "poor";
|
|
1852
|
-
if (canReachGood(metrics.rtt)) return "good";
|
|
1853
|
-
return "fair";
|
|
1854
|
-
}
|
|
1855
|
-
if (canLeavePoor(metrics)) return "fair";
|
|
1833
|
+
var GOOD_MAX_MS = 150;
|
|
1834
|
+
var FAIR_MAX_MS = 400;
|
|
1835
|
+
function classifyNetworkLevel(rtt) {
|
|
1836
|
+
if (rtt <= GOOD_MAX_MS) return "good";
|
|
1837
|
+
if (rtt <= FAIR_MAX_MS) return "fair";
|
|
1856
1838
|
return "poor";
|
|
1857
1839
|
}
|
|
1858
1840
|
|
|
@@ -1875,24 +1857,30 @@ var RttSmoother = class {
|
|
|
1875
1857
|
candidateCount = 0;
|
|
1876
1858
|
overrideOffline = false;
|
|
1877
1859
|
consecutiveOutliers = 0;
|
|
1878
|
-
add(rtt
|
|
1860
|
+
add(rtt) {
|
|
1879
1861
|
if (this.ema > 0 && rtt > OUTLIER_MULTIPLIER * this.ema) {
|
|
1880
1862
|
this.consecutiveOutliers += 1;
|
|
1881
1863
|
if (this.consecutiveOutliers < 2) return;
|
|
1882
1864
|
} else {
|
|
1883
1865
|
this.consecutiveOutliers = 0;
|
|
1884
1866
|
}
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1867
|
+
const coldStart = this.ema === 0;
|
|
1868
|
+
this.ema = coldStart ? rtt : EMA_ALPHA * rtt + (1 - EMA_ALPHA) * this.ema;
|
|
1869
|
+
const next = classifyNetworkLevel(this.ema);
|
|
1870
|
+
if (coldStart) {
|
|
1871
|
+
this.committed = next;
|
|
1890
1872
|
this.candidate = next;
|
|
1891
1873
|
this.candidateCount = 1;
|
|
1892
|
-
}
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1874
|
+
} else {
|
|
1875
|
+
if (next === this.candidate) {
|
|
1876
|
+
this.candidateCount += 1;
|
|
1877
|
+
} else {
|
|
1878
|
+
this.candidate = next;
|
|
1879
|
+
this.candidateCount = 1;
|
|
1880
|
+
}
|
|
1881
|
+
if (this.candidateCount >= this.requiredSamplesFor(next)) {
|
|
1882
|
+
this.committed = next;
|
|
1883
|
+
}
|
|
1896
1884
|
}
|
|
1897
1885
|
this.level = this.overrideOffline ? "offline" : this.committed;
|
|
1898
1886
|
}
|
|
@@ -1960,9 +1948,6 @@ var NetworkQualityMonitor = class {
|
|
|
1960
1948
|
if (bucket.length > WINDOW_MAX_SAMPLES_PER_SOURCE) {
|
|
1961
1949
|
bucket.shift();
|
|
1962
1950
|
}
|
|
1963
|
-
if (sample.source === "mqtt" && sample.reason === "ok") {
|
|
1964
|
-
this.smoother.add(sample.rtt, this.deriveMetrics());
|
|
1965
|
-
}
|
|
1966
1951
|
this.recompute(prevMqttConnectedOverride);
|
|
1967
1952
|
}
|
|
1968
1953
|
seedFromConnection(seed) {
|
|
@@ -1996,6 +1981,7 @@ var NetworkQualityMonitor = class {
|
|
|
1996
1981
|
this.recompute(prevMqttConnected);
|
|
1997
1982
|
}
|
|
1998
1983
|
notifyMqttPing(rttMs) {
|
|
1984
|
+
this.smoother.add(rttMs);
|
|
1999
1985
|
this.addSample({
|
|
2000
1986
|
ts: this.now(),
|
|
2001
1987
|
rtt: rttMs,
|
|
@@ -2093,10 +2079,7 @@ var NetworkQualityMonitor = class {
|
|
|
2093
2079
|
const httpSamples = effectiveSamples.filter((s) => isHttpSource(s.source));
|
|
2094
2080
|
const backend = classifyBackendHealth(httpSamples);
|
|
2095
2081
|
const metrics = this.deriveMetricsFrom(effectiveSamples);
|
|
2096
|
-
const candidate = classifyNetworkLevel(
|
|
2097
|
-
{ rtt: metrics.emaForLevel, jitter: metrics.jitter },
|
|
2098
|
-
this.committedNetwork
|
|
2099
|
-
);
|
|
2082
|
+
const candidate = classifyNetworkLevel(metrics.emaForLevel);
|
|
2100
2083
|
let nextNetwork = this.smoother.level;
|
|
2101
2084
|
if (effectiveSamples.length === 0) {
|
|
2102
2085
|
nextNetwork = this.committedNetwork;
|
|
@@ -2121,9 +2104,6 @@ var NetworkQualityMonitor = class {
|
|
|
2121
2104
|
this.bus.emit("network:change", { previous: prev, current });
|
|
2122
2105
|
}
|
|
2123
2106
|
}
|
|
2124
|
-
deriveMetrics() {
|
|
2125
|
-
return this.deriveMetricsFrom(this.allHttpAndMqttSamples());
|
|
2126
|
-
}
|
|
2127
2107
|
deriveMetricsFrom(samples) {
|
|
2128
2108
|
const httpSamples = samples.filter((s) => isHttpSource(s.source));
|
|
2129
2109
|
const total = httpSamples.length;
|
package/dist/index.d.mts
CHANGED
|
@@ -211,6 +211,16 @@ interface Bid {
|
|
|
211
211
|
status: BidStatus;
|
|
212
212
|
payout: string | null;
|
|
213
213
|
slippage: number;
|
|
214
|
+
/**
|
|
215
|
+
* Refund terms frozen at cancel time. Present only on cancelled bids — absent
|
|
216
|
+
* (or null) on pending/won/lost bids, and on bids reconstructed from realtime
|
|
217
|
+
* store state which doesn't carry per-bid refund. `refundRate` is the rate
|
|
218
|
+
* applied (0.0–1.0); `refundAmount` is the credited amount. Prefer
|
|
219
|
+
* `refundAmount` for display — it's the exact value the server returned, so
|
|
220
|
+
* it needs no recompute from a config rate.
|
|
221
|
+
*/
|
|
222
|
+
refundRate?: string | null;
|
|
223
|
+
refundAmount?: string | null;
|
|
214
224
|
/** ISO-8601 string passthrough from the server. */
|
|
215
225
|
createdAt: string | null;
|
|
216
226
|
/**
|
|
@@ -1052,7 +1062,6 @@ declare class NetworkQualityMonitor {
|
|
|
1052
1062
|
private detachBrowserListeners;
|
|
1053
1063
|
private pruneWindow;
|
|
1054
1064
|
private recompute;
|
|
1055
|
-
private deriveMetrics;
|
|
1056
1065
|
private deriveMetricsFrom;
|
|
1057
1066
|
private isHardOffline;
|
|
1058
1067
|
private allHttpAndMqttSamples;
|
package/dist/index.d.ts
CHANGED
|
@@ -211,6 +211,16 @@ interface Bid {
|
|
|
211
211
|
status: BidStatus;
|
|
212
212
|
payout: string | null;
|
|
213
213
|
slippage: number;
|
|
214
|
+
/**
|
|
215
|
+
* Refund terms frozen at cancel time. Present only on cancelled bids — absent
|
|
216
|
+
* (or null) on pending/won/lost bids, and on bids reconstructed from realtime
|
|
217
|
+
* store state which doesn't carry per-bid refund. `refundRate` is the rate
|
|
218
|
+
* applied (0.0–1.0); `refundAmount` is the credited amount. Prefer
|
|
219
|
+
* `refundAmount` for display — it's the exact value the server returned, so
|
|
220
|
+
* it needs no recompute from a config rate.
|
|
221
|
+
*/
|
|
222
|
+
refundRate?: string | null;
|
|
223
|
+
refundAmount?: string | null;
|
|
214
224
|
/** ISO-8601 string passthrough from the server. */
|
|
215
225
|
createdAt: string | null;
|
|
216
226
|
/**
|
|
@@ -1052,7 +1062,6 @@ declare class NetworkQualityMonitor {
|
|
|
1052
1062
|
private detachBrowserListeners;
|
|
1053
1063
|
private pruneWindow;
|
|
1054
1064
|
private recompute;
|
|
1055
|
-
private deriveMetrics;
|
|
1056
1065
|
private deriveMetricsFrom;
|
|
1057
1066
|
private isHardOffline;
|
|
1058
1067
|
private allHttpAndMqttSamples;
|
package/dist/index.js
CHANGED
|
@@ -407,6 +407,8 @@ function normaliseBid(node) {
|
|
|
407
407
|
price2: node.price2,
|
|
408
408
|
status: coerceStatus(node.status),
|
|
409
409
|
payout: node.payout || null,
|
|
410
|
+
refundRate: node.refund_rate ?? null,
|
|
411
|
+
refundAmount: node.refund_amount ?? null,
|
|
410
412
|
slippage: node.slippage,
|
|
411
413
|
createdAt: node.created_at || null,
|
|
412
414
|
meta: parseMeta(node.meta)
|
|
@@ -429,12 +431,12 @@ var PLACE_BID_MUTATION = `mutation PlaceBid($input: PlaceBidInput!) {
|
|
|
429
431
|
}`;
|
|
430
432
|
var MY_BIDS_QUERY = `query MyBids($statuses: [BidStatus!], $limit: Int, $offset: Int, $pairId: ID) {
|
|
431
433
|
myBids(statuses: $statuses, limit: $limit, offset: $offset, pairId: $pairId) {
|
|
432
|
-
id user_id pair_id currency amount coefficient time1 time2 price1 price2 status payout slippage created_at meta
|
|
434
|
+
id user_id pair_id currency amount coefficient time1 time2 price1 price2 status payout refund_rate refund_amount slippage created_at meta
|
|
433
435
|
}
|
|
434
436
|
}`;
|
|
435
437
|
var CANCEL_BID_MUTATION = `mutation CancelBid($input: CancelBidInput!) {
|
|
436
438
|
cancelBid(input: $input) {
|
|
437
|
-
bid { id user_id pair_id currency amount coefficient time1 time2 price1 price2 status cancelled payout slippage created_at meta }
|
|
439
|
+
bid { id user_id pair_id currency amount coefficient time1 time2 price1 price2 status cancelled payout refund_rate refund_amount slippage created_at meta }
|
|
438
440
|
refund_amount
|
|
439
441
|
new_balance
|
|
440
442
|
}
|
|
@@ -1763,31 +1765,11 @@ function classifyBackendHealth(samples) {
|
|
|
1763
1765
|
}
|
|
1764
1766
|
return "ok";
|
|
1765
1767
|
}
|
|
1766
|
-
var
|
|
1767
|
-
var
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
var JITTER_LEAVE_POOR = 120;
|
|
1772
|
-
var isPoor = (m) => m.rtt > RTT_FAIR_TO_POOR || m.jitter > JITTER_POOR;
|
|
1773
|
-
var canLeavePoor = (m) => m.rtt < RTT_POOR_TO_FAIR && m.jitter < JITTER_LEAVE_POOR;
|
|
1774
|
-
var isFairUpper = (rtt) => rtt > RTT_GOOD_TO_FAIR;
|
|
1775
|
-
var canReachGood = (rtt) => rtt < RTT_FAIR_TO_GOOD;
|
|
1776
|
-
function classifyNetworkLevel(metrics, current) {
|
|
1777
|
-
if (current === "offline") {
|
|
1778
|
-
return isPoor(metrics) ? "poor" : "fair";
|
|
1779
|
-
}
|
|
1780
|
-
if (current === "good") {
|
|
1781
|
-
if (isPoor(metrics)) return "fair";
|
|
1782
|
-
if (isFairUpper(metrics.rtt)) return "fair";
|
|
1783
|
-
return "good";
|
|
1784
|
-
}
|
|
1785
|
-
if (current === "fair") {
|
|
1786
|
-
if (isPoor(metrics)) return "poor";
|
|
1787
|
-
if (canReachGood(metrics.rtt)) return "good";
|
|
1788
|
-
return "fair";
|
|
1789
|
-
}
|
|
1790
|
-
if (canLeavePoor(metrics)) return "fair";
|
|
1768
|
+
var GOOD_MAX_MS = 150;
|
|
1769
|
+
var FAIR_MAX_MS = 400;
|
|
1770
|
+
function classifyNetworkLevel(rtt) {
|
|
1771
|
+
if (rtt <= GOOD_MAX_MS) return "good";
|
|
1772
|
+
if (rtt <= FAIR_MAX_MS) return "fair";
|
|
1791
1773
|
return "poor";
|
|
1792
1774
|
}
|
|
1793
1775
|
|
|
@@ -1810,24 +1792,30 @@ var RttSmoother = class {
|
|
|
1810
1792
|
candidateCount = 0;
|
|
1811
1793
|
overrideOffline = false;
|
|
1812
1794
|
consecutiveOutliers = 0;
|
|
1813
|
-
add(rtt
|
|
1795
|
+
add(rtt) {
|
|
1814
1796
|
if (this.ema > 0 && rtt > OUTLIER_MULTIPLIER * this.ema) {
|
|
1815
1797
|
this.consecutiveOutliers += 1;
|
|
1816
1798
|
if (this.consecutiveOutliers < 2) return;
|
|
1817
1799
|
} else {
|
|
1818
1800
|
this.consecutiveOutliers = 0;
|
|
1819
1801
|
}
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1802
|
+
const coldStart = this.ema === 0;
|
|
1803
|
+
this.ema = coldStart ? rtt : EMA_ALPHA * rtt + (1 - EMA_ALPHA) * this.ema;
|
|
1804
|
+
const next = classifyNetworkLevel(this.ema);
|
|
1805
|
+
if (coldStart) {
|
|
1806
|
+
this.committed = next;
|
|
1825
1807
|
this.candidate = next;
|
|
1826
1808
|
this.candidateCount = 1;
|
|
1827
|
-
}
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1809
|
+
} else {
|
|
1810
|
+
if (next === this.candidate) {
|
|
1811
|
+
this.candidateCount += 1;
|
|
1812
|
+
} else {
|
|
1813
|
+
this.candidate = next;
|
|
1814
|
+
this.candidateCount = 1;
|
|
1815
|
+
}
|
|
1816
|
+
if (this.candidateCount >= this.requiredSamplesFor(next)) {
|
|
1817
|
+
this.committed = next;
|
|
1818
|
+
}
|
|
1831
1819
|
}
|
|
1832
1820
|
this.level = this.overrideOffline ? "offline" : this.committed;
|
|
1833
1821
|
}
|
|
@@ -1895,9 +1883,6 @@ var NetworkQualityMonitor = class {
|
|
|
1895
1883
|
if (bucket.length > WINDOW_MAX_SAMPLES_PER_SOURCE) {
|
|
1896
1884
|
bucket.shift();
|
|
1897
1885
|
}
|
|
1898
|
-
if (sample.source === "mqtt" && sample.reason === "ok") {
|
|
1899
|
-
this.smoother.add(sample.rtt, this.deriveMetrics());
|
|
1900
|
-
}
|
|
1901
1886
|
this.recompute(prevMqttConnectedOverride);
|
|
1902
1887
|
}
|
|
1903
1888
|
seedFromConnection(seed) {
|
|
@@ -1931,6 +1916,7 @@ var NetworkQualityMonitor = class {
|
|
|
1931
1916
|
this.recompute(prevMqttConnected);
|
|
1932
1917
|
}
|
|
1933
1918
|
notifyMqttPing(rttMs) {
|
|
1919
|
+
this.smoother.add(rttMs);
|
|
1934
1920
|
this.addSample({
|
|
1935
1921
|
ts: this.now(),
|
|
1936
1922
|
rtt: rttMs,
|
|
@@ -2028,10 +2014,7 @@ var NetworkQualityMonitor = class {
|
|
|
2028
2014
|
const httpSamples = effectiveSamples.filter((s) => isHttpSource(s.source));
|
|
2029
2015
|
const backend = classifyBackendHealth(httpSamples);
|
|
2030
2016
|
const metrics = this.deriveMetricsFrom(effectiveSamples);
|
|
2031
|
-
const candidate = classifyNetworkLevel(
|
|
2032
|
-
{ rtt: metrics.emaForLevel, jitter: metrics.jitter },
|
|
2033
|
-
this.committedNetwork
|
|
2034
|
-
);
|
|
2017
|
+
const candidate = classifyNetworkLevel(metrics.emaForLevel);
|
|
2035
2018
|
let nextNetwork = this.smoother.level;
|
|
2036
2019
|
if (effectiveSamples.length === 0) {
|
|
2037
2020
|
nextNetwork = this.committedNetwork;
|
|
@@ -2056,9 +2039,6 @@ var NetworkQualityMonitor = class {
|
|
|
2056
2039
|
this.bus.emit("network:change", { previous: prev, current });
|
|
2057
2040
|
}
|
|
2058
2041
|
}
|
|
2059
|
-
deriveMetrics() {
|
|
2060
|
-
return this.deriveMetricsFrom(this.allHttpAndMqttSamples());
|
|
2061
|
-
}
|
|
2062
2042
|
deriveMetricsFrom(samples) {
|
|
2063
2043
|
const httpSamples = samples.filter((s) => isHttpSource(s.source));
|
|
2064
2044
|
const total = httpSamples.length;
|