top of page

Extended Tutorial: Integrating Your Lurp-Based Open AI Agent for Crypto Trading

Prerequisites:

  • Basic HTML, CSS, and JavaScript skills.

  • Access to the Lurp library (e.g., CDN: https://your-lurp-host.com/lurp.min.js or npm: npm install lurp).

  • A crypto exchange account and API key (e.g., Binance, Coinbase, Kraken) with trading permissions enabled.

  • A local or live web server for testing.

1. Include the Lurp Library

Via CDN: Add this to your HTML <head> or <body>:

html

<script src="https://your-lurp-host.com/lurp.min.js"></script>

Via npm (for frameworks like React):

bash

npm install lurp

javascript

import { Agent } from 'lurp';

Verify: Ensure the library loads by adding <script>console.log(typeof Lurp);</script>—it should log "function" or "object".

2. Initialize the Lurp Agent with Crypto Trading

In a <script> tag or separate .js file, set up the agent:

javascript

const agent = new Lurp.Agent({

  apiKey: 'YOUR_LURP_API_KEY', // Provided during agent creation

  model: 'open-ai-crypto-model', // Optional: specify if Lurp uses a custom model

  cryptoExchange: {

    name: 'binance', // Supported exchanges: binance, coinbase, etc.

    apiKey: 'YOUR_EXCHANGE_API_KEY',

    secret: 'YOUR_EXCHANGE_SECRET'

  },

  options: {

    maxResponseTime: 5000, // Optional: timeout in ms

    currencyPair: 'BTC-USDT' // Default trading pair

  }

});

3. Build the Trading Interface

HTML: Add a basic structure to your page:

javascript

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <title>Lurp Crypto Trading Agent</title>

  <style>

    #trade-output { border: 1px solid #ccc; padding: 10px; height: 300px; overflow-y: scroll; }

    #trade-input { width: 70%; padding: 5px; }

    button { padding: 5px 10px; background: #1a73e8; color: white; border: none; }

  </style>

</head>

<body>

  <h1>Crypto Trading Assistant</h1>

  <div id="trade-output"></div>

  <input id="trade-input" type="text" placeholder="e.g., Buy 0.1 BTC or Get ETH price" />

  <button onclick="sendTradeRequest()">Send</button>

  <script src="https://your-lurp-host.com/lurp.min.js"></script>

  <script src="script.js"></script>

</body>

</html>

JavaScript (script.js): Handle sending and receiving messages:

javascript

const agent = new Lurp.Agent({

  apiKey: 'YOUR_LURP_API_KEY',

  cryptoExchange: {

    name: 'binance',

    apiKey: 'YOUR_EXCHANGE_API_KEY',

    secret: 'YOUR_EXCHANGE_SECRET'

  }

});

 

function sendTradeRequest() {

  const input = document.getElementById('trade-input').value;

  if (!input) return;

  const output = document.getElementById('trade-output');

 

  // Show user input

  output.innerHTML += `<p><strong>You:</strong> ${input}</p>`;

  output.scrollTop = output.scrollHeight;

 

  // Send request to agent

  agent.processCryptoRequest(input)

    .then(response => {

      output.innerHTML += `<p><strong>Agent:</strong> ${response}</p>`;

      output.scrollTop = output.scrollHeight;

    })

    .catch(error => {

      output.innerHTML += `<p><strong>Error:</strong> ${error.message}</p>`;

    });

 

  // Clear input

  document.getElementById('trade-input').value = '';

}

 

// Optional: Enter key support

document.getElementById('trade-input').addEventListener('keypress', (e) => {

  if (e.key === 'Enter') sendTradeRequest();

});

4. Test the Integration

Open your HTML file in a browser (use a local server like npx serve for CORS compatibility).

Test commands:

  • “Get BTC price” → Expect a response like “BTC is $60,000 on Binance.”

  • “Buy 0.01 BTC” → Confirm the trade executes (check your exchange account).

Debug:

  • Open DevTools (F12) > Console for errors.

  • Verify API keys and exchange connectivity.

5. Customize and Enhance

Styling: Adjust CSS to match your site’s design

javascript

#trade-output { background: #f0f0f0; font-family: Arial; } button:hover { background: #1557b0; }

Features:

  • Add real-time price updates: agent.getLivePrice('BTC-USDT');

  • Enable portfolio tracking: agent.checkPortfolio();

  • Set trading limits: agent.setLimit({ maxTrade: 1000 }); (if supported).

6. Deploy to Your Website

  • Upload your HTML, CSS, and JS files to your hosting provider (e.g., Wix, Netlify).

  • Test live commands and ensure API calls work over HTTPS.

Troubleshooting:

  • No Response: Check Lurp API key, exchange credentials, or network issues.

  • Trade Fails: Verify exchange API permissions (e.g., enable trading).

  • Errors: Contact [your-support-email] with error details.

Next Steps:

  • Explore advanced Lurp crypto features in our [docs link].

  • Reach out at [your-support-email] for custom trading strategies or support.

image (12).png

Please switch to the desktop interface

Icons-App-Store-Google-play.png

App coming soon...

Please switch to the desktop interface

image (12).png

App coming soon...

Icons-App-Store-Google-play.png
bottom of page