@dreamcash-org/mcp 0.3.2 → 0.3.4
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/THIRD_PARTY_LICENSES.md +2 -2
- package/dist/dreamcash-mcp.js +97 -20
- package/package.json +1 -1
|
@@ -731,7 +731,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
731
731
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
732
732
|
THE SOFTWARE.
|
|
733
733
|
|
|
734
|
-
## @noble/hashes
|
|
734
|
+
## @noble/hashes 1.8.0 (MIT)
|
|
735
735
|
|
|
736
736
|
The MIT License (MIT)
|
|
737
737
|
|
|
@@ -755,7 +755,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
755
755
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
756
756
|
THE SOFTWARE.
|
|
757
757
|
|
|
758
|
-
## @noble/hashes
|
|
758
|
+
## @noble/hashes 2.4.0 (MIT)
|
|
759
759
|
|
|
760
760
|
The MIT License (MIT)
|
|
761
761
|
|
package/dist/dreamcash-mcp.js
CHANGED
|
@@ -21115,7 +21115,7 @@ import { createHash } from "node:crypto";
|
|
|
21115
21115
|
// package.json
|
|
21116
21116
|
var package_default = {
|
|
21117
21117
|
name: "@dreamcash-org/mcp",
|
|
21118
|
-
version: "0.3.
|
|
21118
|
+
version: "0.3.4",
|
|
21119
21119
|
description: "Connect your own AI agent to your Dreamcash account: it reads your account and trades, each trade confirmed by you or on its own within your limits.",
|
|
21120
21120
|
keywords: [
|
|
21121
21121
|
"mcp",
|
|
@@ -26161,6 +26161,7 @@ var outcomeAssetId = (coin) => {
|
|
|
26161
26161
|
return HIP4_ASSET_INDEX_OFFSET + n;
|
|
26162
26162
|
};
|
|
26163
26163
|
// src/shared/planTypes.ts
|
|
26164
|
+
var tpslPriceFromFill = (fillPrice, pct, kind, isLong) => fillPrice * (100 + (kind === "tp" === isLong ? pct : -pct)) / 100;
|
|
26164
26165
|
var AGENT_KEY_METHODS = [
|
|
26165
26166
|
"order",
|
|
26166
26167
|
"cancel",
|
|
@@ -48214,7 +48215,9 @@ var REQUEST_TOOLS = {
|
|
|
48214
48215
|
reduceOnly: a.reduce_only,
|
|
48215
48216
|
slippagePct: a.slippage_pct,
|
|
48216
48217
|
takeProfitPrice: a.take_profit_price,
|
|
48217
|
-
stopLossPrice: a.stop_loss_price
|
|
48218
|
+
stopLossPrice: a.stop_loss_price,
|
|
48219
|
+
takeProfitPct: a.take_profit_pct,
|
|
48220
|
+
stopLossPct: a.stop_loss_pct
|
|
48218
48221
|
}
|
|
48219
48222
|
}),
|
|
48220
48223
|
request_close_position: (a) => ({
|
|
@@ -48811,15 +48814,70 @@ var fillTotalsOf = (content) => {
|
|
|
48811
48814
|
const { result } = JSON.parse(text2.text);
|
|
48812
48815
|
if (typeof result?.fees_usd !== "number")
|
|
48813
48816
|
return;
|
|
48817
|
+
return Object.fromEntries(Object.entries(result).filter(([field, value]) => field.endsWith("_usd") && typeof value === "number"));
|
|
48818
|
+
} catch {
|
|
48819
|
+
return;
|
|
48820
|
+
}
|
|
48821
|
+
};
|
|
48822
|
+
var SET_LEGS_TOOL = "request_set_tp_sl";
|
|
48823
|
+
var LEGS_NOT_SET = "Until these legs show on the book, the position has none: tell the user. Read the request with get_trade_request; if they didn't go on, set them with request_set_tp_sl.";
|
|
48824
|
+
var legsFromFill = (requestId, asked, executed) => {
|
|
48825
|
+
const { side, takeProfitPct, stopLossPct } = asked.params;
|
|
48826
|
+
const asksLegs = takeProfitPct !== undefined || stopLossPct !== undefined;
|
|
48827
|
+
if (asked.kind !== "ORDER" || !asksLegs || !("status" in executed)) {
|
|
48828
|
+
return;
|
|
48829
|
+
}
|
|
48830
|
+
const fill = executed.result?.averagePrice;
|
|
48831
|
+
if (executed.status === "claimed") {
|
|
48814
48832
|
return {
|
|
48815
|
-
|
|
48816
|
-
fees_usd: result.fees_usd,
|
|
48817
|
-
dreamcash_part_of_fees_usd: result.dreamcash_part_of_fees_usd
|
|
48833
|
+
problem: `The order's outcome isn't known yet, so its take-profit and stop-loss aren't set. ${LEGS_NOT_SET}`
|
|
48818
48834
|
};
|
|
48819
|
-
}
|
|
48835
|
+
}
|
|
48836
|
+
if (executed.status !== "executed")
|
|
48820
48837
|
return;
|
|
48838
|
+
if (!(typeof fill === "number" && fill > 0)) {
|
|
48839
|
+
return {
|
|
48840
|
+
problem: `The order filled, but its average price isn't known yet, so its take-profit and stop-loss aren't set. ${LEGS_NOT_SET}`
|
|
48841
|
+
};
|
|
48821
48842
|
}
|
|
48843
|
+
const priceAt = (pct, kind) => typeof pct === "number" ? tpslPriceFromFill(fill, pct, kind, side === "long") : undefined;
|
|
48844
|
+
return {
|
|
48845
|
+
call: {
|
|
48846
|
+
market: asked.market,
|
|
48847
|
+
...asked.wallet !== undefined && { wallet: asked.wallet },
|
|
48848
|
+
take_profit_price: priceAt(takeProfitPct, "tp"),
|
|
48849
|
+
stop_loss_price: priceAt(stopLossPct, "sl"),
|
|
48850
|
+
idempotency_key: `legs-from-fill-${requestId}`
|
|
48851
|
+
}
|
|
48852
|
+
};
|
|
48853
|
+
};
|
|
48854
|
+
var legsSetBy = (call, result) => {
|
|
48855
|
+
const text2 = result.content.find((block) => block.type === "text");
|
|
48856
|
+
let answer;
|
|
48857
|
+
try {
|
|
48858
|
+
answer = text2?.type === "text" ? JSON.parse(text2.text) : undefined;
|
|
48859
|
+
} catch {
|
|
48860
|
+
answer = text2?.type === "text" ? text2.text : undefined;
|
|
48861
|
+
}
|
|
48862
|
+
const set = !result.isError && answer?.status === "executed";
|
|
48863
|
+
return {
|
|
48864
|
+
set,
|
|
48865
|
+
take_profit_price: call.take_profit_price,
|
|
48866
|
+
stop_loss_price: call.stop_loss_price,
|
|
48867
|
+
request: answer,
|
|
48868
|
+
...!set && { warning: LEGS_NOT_SET }
|
|
48869
|
+
};
|
|
48822
48870
|
};
|
|
48871
|
+
var withField = (content, field, value) => content.map((block) => {
|
|
48872
|
+
if (block.type !== "text")
|
|
48873
|
+
return block;
|
|
48874
|
+
try {
|
|
48875
|
+
const answer = JSON.parse(block.text);
|
|
48876
|
+
return { ...block, text: JSON.stringify({ ...answer, [field]: value }) };
|
|
48877
|
+
} catch {
|
|
48878
|
+
return block;
|
|
48879
|
+
}
|
|
48880
|
+
});
|
|
48823
48881
|
var tradeRequestToExecute = (tool, args, result) => {
|
|
48824
48882
|
if (result.isError)
|
|
48825
48883
|
return;
|
|
@@ -48980,6 +49038,30 @@ var createDreamcashServer = ({
|
|
|
48980
49038
|
return { placed: false, error: guidanceFor(error2) };
|
|
48981
49039
|
}
|
|
48982
49040
|
};
|
|
49041
|
+
const callAndCarryOut = async (client, key, name, args) => {
|
|
49042
|
+
const result = await client.callTool({
|
|
49043
|
+
name,
|
|
49044
|
+
arguments: args
|
|
49045
|
+
});
|
|
49046
|
+
const toExecute = tradeRequestToExecute(name, args, result);
|
|
49047
|
+
if (!toExecute)
|
|
49048
|
+
return { result };
|
|
49049
|
+
const executed = await executeWithKey(toExecute.id, toExecute.asked, key);
|
|
49050
|
+
const totals = "status" in executed && executed.status === "executed" ? await client.callTool({
|
|
49051
|
+
name: "get_trade_request",
|
|
49052
|
+
arguments: { request_id: toExecute.id }
|
|
49053
|
+
}).then((readBack) => fillTotalsOf(readBack.content)).catch(() => {
|
|
49054
|
+
return;
|
|
49055
|
+
}) : undefined;
|
|
49056
|
+
return {
|
|
49057
|
+
result: {
|
|
49058
|
+
...result,
|
|
49059
|
+
content: withExecution(result.content, { ...executed, ...totals })
|
|
49060
|
+
},
|
|
49061
|
+
toExecute,
|
|
49062
|
+
executed
|
|
49063
|
+
};
|
|
49064
|
+
};
|
|
48983
49065
|
server.setRequestHandler("tools/list", async () => {
|
|
48984
49066
|
const tools = await linked().then((client) => client?.listTools()).then((listed) => listed?.tools).catch((error2) => {
|
|
48985
49067
|
if (isUnauthorized(error2))
|
|
@@ -48997,23 +49079,18 @@ var createDreamcashServer = ({
|
|
|
48997
49079
|
const client = await linked();
|
|
48998
49080
|
if (!client || !account)
|
|
48999
49081
|
return failure2(NOT_CONNECTED);
|
|
49000
|
-
const result = await client
|
|
49001
|
-
|
|
49002
|
-
|
|
49003
|
-
});
|
|
49004
|
-
const toExecute = tradeRequestToExecute(name, args, result);
|
|
49005
|
-
if (!toExecute)
|
|
49082
|
+
const { result, toExecute, executed } = await callAndCarryOut(client, account, name, args);
|
|
49083
|
+
const legs = toExecute && legsFromFill(toExecute.id, toExecute.asked, executed);
|
|
49084
|
+
if (!legs)
|
|
49006
49085
|
return result;
|
|
49007
|
-
const
|
|
49008
|
-
|
|
49009
|
-
|
|
49010
|
-
|
|
49011
|
-
})
|
|
49012
|
-
return;
|
|
49013
|
-
}) : undefined;
|
|
49086
|
+
const legsSet = "problem" in legs ? { set: false, warning: legs.problem } : await callAndCarryOut(client, account, SET_LEGS_TOOL, legs.call).then((set) => legsSetBy(legs.call, set.result)).catch((error2) => ({
|
|
49087
|
+
set: false,
|
|
49088
|
+
error: guidanceFor(error2),
|
|
49089
|
+
warning: LEGS_NOT_SET
|
|
49090
|
+
}));
|
|
49014
49091
|
return {
|
|
49015
49092
|
...result,
|
|
49016
|
-
content:
|
|
49093
|
+
content: withField(result.content, "legs_from_fill", legsSet)
|
|
49017
49094
|
};
|
|
49018
49095
|
} catch (error2) {
|
|
49019
49096
|
if (isUnauthorized(error2))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dreamcash-org/mcp",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Connect your own AI agent to your Dreamcash account: it reads your account and trades, each trade confirmed by you or on its own within your limits.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|