Skip to content

Commit dbeca66

Browse files
authored
Merge pull request #1 from elizaOS/realitySpiral/cb-client
Reality spiral/cb client
2 parents 27bd9c3 + 36ee4a1 commit dbeca66

File tree

4 files changed

+192
-74
lines changed

4 files changed

+192
-74
lines changed

agent/src/index.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,9 @@ export async function createAgent(
566566
? nftGenerationPlugin
567567
: null,
568568
getSecret(character, "ZEROG_PRIVATE_KEY") ? zgPlugin : null,
569-
getSecret(character, "COINBASE_COMMERCE_KEY")
570-
? coinbaseCommercePlugin
571-
: null,
569+
// getSecret(character, "COINBASE_COMMERCE_KEY")
570+
// ? coinbaseCommercePlugin
571+
// : null,
572572
getSecret(character, "FAL_API_KEY") ||
573573
getSecret(character, "OPENAI_API_KEY") ||
574574
getSecret(character, "VENICE_API_KEY") ||
@@ -580,9 +580,9 @@ export async function createAgent(
580580
...(getSecret(character, "COINBASE_API_KEY") &&
581581
getSecret(character, "COINBASE_PRIVATE_KEY")
582582
? [
583-
coinbaseMassPaymentsPlugin,
584-
tradePlugin,
585-
tokenContractPlugin,
583+
// coinbaseMassPaymentsPlugin,
584+
// tradePlugin,
585+
// tokenContractPlugin,
586586
advancedTradePlugin,
587587
]
588588
: []),
@@ -591,9 +591,9 @@ export async function createAgent(
591591
: []),
592592
getSecret(character, "COINBASE_API_KEY") &&
593593
getSecret(character, "COINBASE_PRIVATE_KEY") &&
594-
getSecret(character, "COINBASE_NOTIFICATION_URI")
595-
? webhookPlugin
596-
: null,
594+
// getSecret(character, "COINBASE_NOTIFICATION_URI")
595+
// ? webhookPlugin
596+
// : null,
597597
goatPlugin,
598598
getSecret(character, "ABSTRACT_PRIVATE_KEY")
599599
? abstractPlugin

packages/client-coinbase/src/index.ts

+26-41
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import {
88
stringToUuid,
99
composeContext,
1010
generateText,
11-
ModelClass
11+
ModelClass,
12+
State
1213
} from "@elizaos/core";
1314
import { postTweet } from "@elizaos/plugin-twitter";
1415
import express from "express";
1516
import { WebhookEvent } from "./types";
17+
import { pnlProvider } from "@elizaos/plugin-coinbase";
1618

1719
export class CoinbaseClient implements Client {
1820
private runtime: IAgentRuntime;
@@ -93,19 +95,17 @@ export class CoinbaseClient implements Client {
9395
});
9496
}
9597

96-
private async generateTweetContent(event: WebhookEvent, _tradeAmount: number, formattedTimestamp: string): Promise<string> {
98+
private async generateTweetContent(event: WebhookEvent, amountInCurrency: number, pnlText: string, formattedTimestamp: string, state: State): Promise<string> {
9799
try {
98-
const roomId = stringToUuid("coinbase-trading");
99-
const amount = Number(this.runtime.getSetting('COINBASE_TRADING_AMOUNT')) ?? 1;
100-
101100
const tradeTweetTemplate = `
102101
# Task
103102
Create an engaging and unique tweet announcing a Coinbase trade. Be creative but professional.
104103
105104
Trade details:
106105
- ${event.event.toUpperCase()} order for ${event.ticker}
107-
- Trading amount: $${amount.toFixed(2)}
106+
- Trading amount: $${amountInCurrency.toFixed(2)}
108107
- Current price: $${Number(event.price).toFixed(2)}
108+
- Overall Unrealized PNL: $${pnlText}
109109
- Time: ${formattedTimestamp}
110110
111111
Requirements:
@@ -118,42 +118,23 @@ Requirements:
118118
7. Include the key information: action, amount, ticker, and price
119119
120120
Example variations for buys:
121-
"📈 Just added $1,000 of BTC to the portfolio at $50,000.00"
122-
"🎯 Strategic BTC purchase: $1,000 at $50,000.00"
121+
"📈 Just added $1,000 of BTC to the portfolio at $50,000.00. Overall Unrealized PNL: $${pnlText}"
122+
"🎯 Strategic BTC purchase: $1,000 at $50,000.00. Overall Unrealized PNL: $${pnlText}"
123123
124124
Example variations for sells:
125-
"💫 Executed BTC position: Sold $1,000 at $52,000.00"
126-
"📊 Strategic exit: Released $1,000 of BTC at $52,000.00"
125+
"💫 Executed BTC position: Sold $1,000 at $52,000.00. Overall Unrealized PNL: $${pnlText}"
126+
"📊 Strategic exit: Released $1,000 of BTC at $52,000.00. Overall Unrealized PNL: $${pnlText}"
127127
128128
Generate only the tweet text, no commentary or markdown.`;
129-
130129
const context = composeContext({
131130
template: tradeTweetTemplate,
132-
state: {
133-
event: event.event.toUpperCase(),
134-
ticker: event.ticker,
135-
amount: `${amount.toFixed(2)}`,
136-
price: `${Number(event.price).toFixed(2)}`,
137-
timestamp: formattedTimestamp,
138-
bio: '',
139-
lore: '',
140-
messageDirections: '',
141-
postDirections: '',
142-
persona: '',
143-
personality: '',
144-
role: '',
145-
scenario: '',
146-
roomId,
147-
actors: '',
148-
recentMessages: '',
149-
recentMessagesData: []
150-
}
131+
state
151132
});
152133

153134
const tweetContent = await generateText({
154135
runtime: this.runtime,
155136
context,
156-
modelClass: ModelClass.SMALL,
137+
modelClass: ModelClass.LARGE,
157138
});
158139

159140
const trimmedContent = tweetContent.trim();
@@ -179,7 +160,7 @@ Generate only the tweet text, no commentary or markdown.`;
179160
agentId: this.runtime.agentId,
180161
roomId,
181162
content: {
182-
text: `Place an advanced market order to ${event.event.toLowerCase()} $${amount} worth of ${event.ticker}`,
163+
text: `Place an advanced trade market order to ${event.event.toLowerCase()} $${amount} worth of ${event.ticker}`,
183164
action: "EXECUTE_ADVANCED_TRADE",
184165
source: "coinbase",
185166
metadata: {
@@ -194,15 +175,11 @@ Generate only the tweet text, no commentary or markdown.`;
194175
};
195176

196177
await this.runtime.messageManager.createMemory(memory);
197-
198-
const callback: HandlerCallback = async (content: Content) => {
199-
elizaLogger.info("Trade execution result:", content);
200-
return [];
201-
};
202-
203178
const state = await this.runtime.composeState(memory);
204-
await this.runtime.processActions(memory, [memory], state, callback);
205-
179+
const callback: HandlerCallback = async (content: Content) => {
180+
if (!content.text.includes("Trade executed successfully")) {
181+
return [];
182+
}
206183
// Generate tweet content
207184
const formattedTimestamp = new Intl.DateTimeFormat('en-US', {
208185
hour: '2-digit',
@@ -211,14 +188,22 @@ Generate only the tweet text, no commentary or markdown.`;
211188
timeZoneName: 'short'
212189
}).format(new Date(event.timestamp));
213190

191+
const pnl = await pnlProvider.get(this.runtime, memory);
192+
193+
const pnlText = `Unrealized PNL: $${pnl.toFixed(2)}`;
194+
214195
try {
215-
const tweetContent = await this.generateTweetContent(event, amount, formattedTimestamp);
196+
const tweetContent = await this.generateTweetContent(event, amount, pnlText, formattedTimestamp, state);
216197
elizaLogger.info("Generated tweet content:", tweetContent);
217198
const response = await postTweet(tweetContent);
218199
elizaLogger.info("Tweet response:", response);
219200
} catch (error) {
220201
elizaLogger.error("Failed to post tweet:", error);
221202
}
203+
return [];
204+
};
205+
206+
await this.runtime.processActions(memory, [memory], state, callback);
222207
}
223208

224209
async stop(): Promise<void> {

0 commit comments

Comments
 (0)