DEV Community

Cover image for My LLM journey in a new domain as a software engineer
Dale Waterworth
Dale Waterworth

Posted on

My LLM journey in a new domain as a software engineer

A rant about diving into the deep end of a new domain. I put myself in the shoes of a non-developer, trying to conquer the world in unfamiliar territory armed with AI

Over the holidays when i had some time off I was pondering the thought of how to make some passive income.

In this day and age of AI and all the hype i'm thinking the world is my oyster.

With the threat of AI taking over the world, especially in my day-to-day as a software engineer, i should start bucking up my ideas and get involved as some non-coder can whip up a coding storm or can they?

What to do?

AI is smart right? It can blurt out code that I don't have committed to memory. Furthermore it can churn out mathematical algorithms way smarter than i could. It solves the conundrums i'm thinking about in a second. It's my new sidekick. I can do anything!

Why not try something new? There is some hype going around that a non-developer can spin up a fully fledged app. They will be able to whip up complex APIs, have it secure, running efficiently, have some persistent storage, the list goes on but ultimately, make money!

I'll put myself in their shoes and make the impossible possible!

What to do?

Lets try something new

I have no idea about trading, stocks and crypto. With the backing of an LLM at my side and its fountain of knowledge i'm surely on track to crack this industry.

As a newbie to the domain and the confidence of a superior AI to roll out smart trading algorithms, i'm like that hype that is being broadcast - AI can do it, AI can do it for me.

I started researching. Watching videos, reading blogs and getting my head into the space. I'm a developer, i can do this!

In a naive mindset i'm thinking of all the possibilities. Primarily, making a 'trading bot' letting it run, trading automatically. Making money while i sleep with this new fan-dangled LLM steering the way.

I'm thinking, if a currency is worth 100, it goes up to 120. There's a window there to gain 20 if bought and sold at the right time.

I go away and hammer an LLM for a while. Dreaming up scenarios and asking newbie questions.

I'm sold. This could be the key to an early retirement.

Let the journey begin

Again i remind my self, some non-dev is going to come along and use an LLM to take my job as they will be able to whip this up in no time.

So to trade, one needs some form of broker to be able to do this. Being in the UK is somewhat restricted compared to US in terms of functionality and access to markets.

So i set up an account with Coinbase. The first tricky part is accessing their API also finding the right API docs wasn't easy with a whole bunch of resources i was not familiar with.

Looking around the advanced trading screen i was overwhelmed with information. Vast amounts options and the lovely candle sticks graphs that in itself, are whole new topic to learn and research.

More Youtube videos and blogs to consume.

Candle stick image

I then thwarted to the complex API documentation. 100's of new words and industry terms. It's ok i said to myself - i can use an LLM to guide me.

I wanted to jump straight into some code and at least call something from their API.

This was first stumbling block - LLM to the rescue.

Give me an example using the Coinbase api to get candle stick data.

For a newbie this would be very tough to figure out. API keys and secrets, creating a client with fields. Calling the API with specific params, parsed into specific types eg. unix time stamps, floats, strings.

The LLM provided a rough example that was using an incorrect / out of date client but for the most part it was ok. After some tweaking, the fields matched up with the request et voila, i was getting candle stick data back.

[{
   start: '1736201400',
   low: '101683.99',
   high: '101800.17',
   open: '101762.41',
   close: '101754.57',
   volume: '13.58472385'
 },
 ...
]
Enter fullscreen mode Exit fullscreen mode

I was getting back 1000's of results. I had again to do some research to figure what these actually meant, which i won't go into here but the main value is the close field.

Looking at the API i realised there lots of endpoints i will need to be calling. Luckily i found a Typescript library Coinbase provides containing all the endpoints.

This library is not part of npm so it requires building it locally and adding it to your project. In doing so, it was apparent that none of the types were exported and meant i would have to create all the DTO's to call and consume the library. I did a quick and dirty fork of that repo and exported the types which can be found here.

Now i was able to build the forked repo and simply run npm link then in my project i could consume that by running

npm link @coinbase-samples/advanced-sdk-ts

This then exposed to the types so i could use things like

import { RESTClient } from '@coinbase-samples/advanced-sdk-ts';

 this.clientInstance = new RESTClient(
  process.env.COINBASE_API_KEY,
  process.env.COINBASE_API_SECRET,
);
Enter fullscreen mode Exit fullscreen mode

Yikes! That's a lot of faffing around to get this up and running - I think my job is going to be safe from AI taking over for sometime yet with these shenanigans.

Say the newbie got around this issue and can call these APIs. We're at a level playing field now.

Down to business

So we need a strategy. The videos i watched all seemed to mention RSI - Relative Strength Index. So i'll start off with that.

In a nutshell it takes a period of close values, default of 14 values and calculates an index. When the index goes below 30 this is a sign of overselling - this indicates the market price might start rising - bullish. If it goes above 70 then it's a sign of overbuying and indicates the the price may start falling - bearish.

Sounds amazing! Buy when its 30 sell when it 70 ka-ching!

So it's pretty complicated to do this calculation and i don't want to spend time doing this, maybe another time. Fortunately, there is a technical-indicators library to use, so i'll run with that expecting that it's solid, precise, bug free, fully tested and works as it should.

Using an LLM i gave it my prompt in the region of use that library and create a function to get the candles from the API and another function to buy and sell when these values are hit. It did as i asked and gave a long script to carry out of these actions.

It didn't really work too well. The call to the API was incorrect. The RSI function shifted the last element from the index and didn't provide and index value.

After a short while of tweaking, i broke up the functionality into smaller components and separate files. The API was now being called and the RSI function was returning something that looked like an index.

In order to react to the market, i needed to poll the candle endpoint to get the latest values and plug that into the RSI function, that way when any buy or sell signals arise i can take action.

I didn't want to use to a timer for this as it would get out of sync so i set up a dynamic cron to run each minute, get the candle data then pass it in to the RSI manager.

trade() {  
    this.job = new CronJob(
        '* * * * *', // Cron expression for every minute
        async () => {
          const candles = await this.getCandles(
            'BTC-USD',
            'ONE_MINUTE' as Granularity,
            1, // Minutes ago
            1, // Limit
          );
          this.rsiManager.updateWithCandle(candles.candles[0]);
        },
        null,
        true)
} 
Enter fullscreen mode Exit fullscreen mode

I created an rsiManager to handle the logic. This would make it easier for the LLM to give me a complete file and could copy and paste as changes happen.

So at this stage i could fire up the app and start calling the candle api, run it through the RSI and get a sign to buy or sell.

I left it running for a while and monitored the logs and did indeed see some buy and sells, Great! I checked these against the Coinbase graph console so get an idea of what the candle stick looks like.

This isn't the exact RSI index signal i got but it's something like what i'm after.

Candle graph bearish and bullish

This is great, i'm on track for an early retirement for sure!

After some time i see the RSI function is constantly buying. In real life this would start to wipe out my finances. So i'm throwing this back to the LLM, telling it the issue and it turn it giving me some new code.

After some back and forth the LLM is getting more confused. It's changing the code for no reason. It's forgetting to apply conditions that i told it before. I started a new conversation a few times and that seemed to help.

Test Test Test

With the realisation that this could easily wipe out my account let alone any profits. I decided to get the boilerplate setup to start creating some tests to ensure that the RSI is actually working as expected.

This proved pretty difficult as the test data itself has to simulate peaks and troughs of the market. With a limited knowledge of the domain i struggled to create any meaningful test data. The LLM would blurt out a series of number that looked pretty simple. When you're trying to get patterns for days and weeks this becomes very complicated.

Clearly a sign of i don't know what i'm doing :)

I moved on to just consuming the API and simulating buys and sells, adding conditions like when i'm in sell mode don't buy anything.

In addition to this i got the LLM to start tracking and providing analysis of trades. This would give me data like

Cron job started.
{
  analysis: { rsi: 50.15, signal: 'HOLD', reason: 'Waiting for conditions' },
  currentPrice: 94312.93,
  time: 2025-01-11T14:14:00.246Z
}
{
  totalTrades: 0,
  winningTrades: 0,
  losingTrades: 0,
  breakEvenTrades: 0,
  winRate: 0,
  averageProfitPercent: 0,
  averageLossPercent: 0,
  largestWin: 0,
  largestLoss: 0,
  profitFactor: 0,
  totalProfitLoss: 0,
  maxDrawdown: 0,
  consecutiveWins: 0,
  consecutiveLosses: 0,
  maxConsecutiveWins: 0,
  maxConsecutiveLosses: 0
}
Enter fullscreen mode Exit fullscreen mode

Of course i would assume the LLMs calculations would be perfect!

I was very tempted get this fully up and running actually making buys and sells but good job i held back.

After running this for a few hours it become evident that this strategy would not work.

The RSI would signal a buy. The price could fluctuate and say drop by 5%. Then the market would pick up slightly and rise a couple of % the signal to sell would happen. As you guessed (or not) - the price is already lower than the buy price and would sell at a loss.

Again i fed this back into the LLM and it endeavoured to spit back the perfect working solutions. However, each time the code became more complex and further away from what i wanted.

Time to step back and re-evaluate that early retirement.

I have the basic building blocks now to start to build a bot. I just need to learn a lot more about the trading market abyss.

Key takeaways

  • Using an LLM in a new domain is not a silver bullet - you don't know what you don't know.

  • Given the complex nature of the domain and calculations required, you have to know what you need to do before you start otherwise it's possible to be led down the wrong path by the LLMs confidence.

  • It's very difficult for the LLM to keep on track as requirements change. It was a battle copying and pasting code each iteration, especially when it would say change these functions and the rest is the same.

  • Maybe i need to change tact and create a bullet point list for the prompt to manage requirements?

  • If you have the domain knowledge then i think an LLM would be a good addition to your arsenal.

  • I found it very challenging to write meaningful tests to test out the algorithms.

Conclusion

The main aim of this project was for me to try and jump into the deep end, in a new domain and create some software that could be used in the crypto trading market using an LLM.

I hopped between ChatGPT, Claude and Co-Pilot. I did not have a subscription for any, so once the free tier finished i would jump on another LLM. Ideally i would choose only one to be my companion.

On the next attempt (if ever), i would approach this as i would with my day to day. I would create tests with data that i understand and simulate scenarios. Without an economics degree and years of data to crunch this may be a taller order than i have time and energy for.

Overall i had some fun with this. I learned a lot about crypto and trading - the rabbit hole of this is massive. It's a long way to go yet before i go beyond scratching the surface.

My naivety of the stock market would have lost me money. There are existing bots out there that claim 20% returns but come at a risk but where's the fun in that.

Will i ever be a crypto millionaire? Well, that's to be seen.

Crypto mysteries

Top comments (0)

typescript

11 Tips That Make You a Better Typescript Programmer

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay