In-Development TradeDangerous: power-user trade optimizer

This actually turned out to be less useful than I originally thought it would be, since I have to specify the exact station rather than telling the script itself that I want to start and stop at the same unspecified station with a single jump.

In TD parlance a "jump" is a hyperspace jump between two stars, while a "hop" is buying at A and selling at B (TD doesn't yet factor in gas stops).

To providing a feature to access "round trips", I've talked to that a couple of times previously (e.g. https://forums.frontier.co.uk/showthread.php?t=34986&page=2&p=678898&highlight=round trip#post678898). Round-trips are an old habit that familiarizing yourself with TD can free you from.

TD doesn't artificially avoid round trips - Try some queries with "--hops 30" and you'll find that sometimes round-trips show up.

But the game is designed to generally preclude profitable round-trips; trade is designed to be primarily asymmetrical.

That's why TD has the "--hops" thing. You can ask it to look many hops forward for you, so that you can find things like this:

From A->B: 600cr/unit
From B->A: 40cr/unit
From B->C: 150cr/unit
From C->A: 500cr/unit

Obviously A->B->A is only 640cr/unit while A->B->C is 750cr/unit, but compare the following:

A->B->A->B->A->B->A
vs
A->B->C->A->B->C

600 * 3 + 40 * 3 = 1920cr/unit
vs
600 * 2 + 150 * 2 + 500 * 2 = 2500cr/unit

And bear in mind - the second route was shorter; if you make the routes by returning to A on the second route, you're talking 3100cr/unit vs 1920cr/unit.
 
Last edited:
That's a wonderful explanation, thank you for the information. Continuing in the vein of less-than-ideal routes, is there a way to specify that I don't want any "empty" (ie no cargo) jumps?

EDIT: On a related note, would it be possible to implement an external "avoid" file? There are certain stations I always want to avoid due to how far they are from the primary star in a system, and the list of --avoids I'm passing to trade.py is getting pretty... robust. Being able to list all of the stations, systems, or goods I never want to deal with in a text file, then just passing --avoidlist or something similar to trade.py would be a lot simpler in the long-run for me.
 
Last edited:
Artip:

I'm not sure I understand exactly what you mean. Are you referring to when, for example, TD says

"Buy Indium at Styx, jump to Eranin then Jump to Asellus, then sell your Indium?"

If so, then, sure. You can use "--jump 1". I would suggest you experiment with something like:

trade.py -v run --cap 16 --cr 10000 --ly 9 --from aulin --hops 10 --jumps 1
trade.py -v run --cap 16 --cr 10000 --ly 9 --from aulin --hops 10 --jumps 2

and see what a huge difference it makes.

Why would you want to avoid the above route? You are just jumping into Eranin and then as soon as you have control, setting Asellus as your destination and jumping there?

If (like me) you find it to keep hard to tracking these routes late at night - have you tried using the --checklist option?

As for the sticky config stuff: Yeah, I have a plan to do that, but I want to allow groups of configs so you can combine ships and configs so you can say "my trading asp" or "my pirating cobra" and have it load the right settings/config for the particular ship/role you're playing. Right now I haven't had chance to get to it clearing the backlog of beta 3 stuff and trying to add features to support people building web/gui interfaces :)
 
There were a number of conflicts between Smacker's station list and maddavo's Stations.csv, plus maddavo's Stations.csv had a number of errors ("Moxons Mojo" and "Abnett Plateform").

I did a quick bit of scripting and the "corrections.py" should now correct all of these. I've also changed the parsers to adjust for mistakes in the Stations.csv so that corrections is now the boss of, well, everyone.

The upshot is that most people's .prices file should be unbroken right now, but I'll need to co-ordinate with mad and Smacker on what the actual station names are.

Hi all, I've fixed up some of the variances in Station names the prices data now. This is going to be an ongoing issue if any new station data is entered without taking careful notice of the exact syntax of the Station/System - including apostrophies. The sharing site simply accepts any new station/system so please double check if you're entering a new station - I had to do it this way because there is no list of station names for the 700+ market systems - that's what we are trying to build. The Station.csv on the sharing site is autogenerated from the prices data so it should always work with the data and only contains market stations.

You usually have to update your own Station.csv when entering a new station so that's a good time to check the name when entering a new station.
 
Excellent tool! Thank you so much for being pythonic and enabling the core functions to be imported!

Beta 3 has shown that the markets can vary pretty wildly over short periods of time. Any plans to incorporate some other's market data? Slopey's seems popular, but the data is rather dirty. I tried for a short while today to cook up an import for his data, but the differences in station names and variance in system names made this pretty much a lost cause.

I also noted the schema in TradeDangerous appears to require stations have unique names. I seem to recall that systems are unique, but stations name may not be.
 
Excellent tool! Thank you so much for being pythonic and enabling the core functions to be imported!

Beta 3 has shown that the markets can vary pretty wildly over short periods of time. Any plans to incorporate some other's market data? Slopey's seems popular, but the data is rather dirty. I tried for a short while today to cook up an import for his data, but the differences in station names and variance in system names made this pretty much a lost cause.

I also noted the schema in TradeDangerous appears to require stations have unique names. I seem to recall that systems are unique, but stations name may not be.

I have imported Slopey's data and I have contacted Thrudd about an import/export. Slopey's data I imported twice and had to clean it up significantly each time. I'm working on trying to automate that, but I don't want to spend too much time on it - it was all s'posed to be a quick temporary hack to get us by until an API.
 
EggPlant/Davo:

I strongly suspect that the solution is going to be to approach someone like RedWizard and have them provide some form of registry whereby we can have fixed IDs for objects.
 
Hello all. I have downloaded python this script and a TradeDangerous.prices system.csv and station.csv file from http://www.davek.com.au/td/

trade.py --help works

But using the example in the Readme I get the following

Code:
trade.py run -vv --sh type6 --ho 5 --fr Dahan --cr 128871 --ins 20000
usage: trade.py [-h] [--debug] [--detail] [--quiet] [--db DB] [--cwd CWD]
                {buy,nav,local,run,update} ...
trade.py: error: unrecognized arguments: -vv

If I remove the -vv argument I get a different error:

Code:
trade.py run --sh type6 --ho 5 --fr Dahan --cr 128871 --ins 20000
*** INTERNAL ERROR: UNIQUE constraint failed: Station.name
CSV File: data\Station.csv:0
SQL Query: INSERT INTO Station (system_id,name,ls_from_star) VALUES((SELECT System.system_id FROM System WHERE System.name = ?),?,?)
Params: ['Styx', 'Chi Hub', '0']

Can anybody help please?
 
I've gone ahead and created functions in Python and JavaScript that generate compact, textual IDs for star-coordinates that could be used by TOR to generate a persistent ID for star systems based on their initial 2dp coordinates.

For the star at (51.5625, 32.1875, -27.125) the "id64" is "1gA:Oi:-Go"

Developers and cartographers can use these IDs as a common reference so that users don't have to, but so that data also isn't lost when names change.

What if a star moves? I'd propose keeping its ID.

Then what if a new star comes along with the same original coordinates?

When the TOR registers its ID, it should add ":1" to the end of the ID, or ":2" etc.

I'll try and get around to proposing this in the other discussions over the weekend.

- - - - - Additional Content Posted / Auto Merge - - - - -

Hello all. I have downloaded python this script and a TradeDangerous.prices system.csv and station.csv file from http://www.davek.com.au/td/

trade.py --help works

But using the example in the Readme I get the following

Code:
trade.py run -vv --sh type6 --ho 5 --fr Dahan --cr 128871 --ins 20000
usage: trade.py [-h] [--debug] [--detail] [--quiet] [--db DB] [--cwd CWD]
                {buy,nav,local,run,update} ...
trade.py: error: unrecognized arguments: -vv

If I remove the -vv argument I get a different error:

Code:
trade.py run --sh type6 --ho 5 --fr Dahan --cr 128871 --ins 20000
*** INTERNAL ERROR: UNIQUE constraint failed: Station.name
CSV File: data\Station.csv:0
SQL Query: INSERT INTO Station (system_id,name,ls_from_star) VALUES((SELECT System.system_id FROM System WHERE System.name = ?),?,?)
Params: ['Styx', 'Chi Hub', '0']

Can anybody help please?

Apologies for that, the "-vv" needs to go before the "run" commands. Type "trade.py run -h" for the command's help.

As to the second problem, it's telling you that the Station.csv has two stations with the same name. Open the data directory and open the file Station.csv in notepad and remove one of the two "Styx,Chi Hub" lines.
 
Okay so this is what I did:

1) download from https://bitbucket.org/kfsone/tradedangerous/downloads
2) download data from http://www.davek.com.au/td/ button "TradeDangerous"
3) unpack kfsone-tradedangerous-aed777b26076.zip (dunno if this is unique for my download or is with this file name really)
4) move TradeDangerous.prices file to data/ directory
5) run python3 trade.py run --credits 1000

And result is error:
Code:
trade.py: data/TradeDangerous.prices:7 Unrecognized STAR/Station, '10 CANUM VENATICORUM/Janifer Port'.
Where did I go wrong?

EDIT: I downloaded the CSV files and now finally I got it to run!
Code:
python3 trade.py run --credits 1000 --capacity 532 --ship type9
WYRD/Vonarburg Co-Operative -> LHS 3006/WCM Transfer Orbital:
 >-> At WYRD/Vonarburg Co-Operative, Buy: 24 x Algae,
  +  At STYX/Chu Hub, Buy: 131 x Food Cartridges,
 <-< LHS 3006/WCM Transfer Orbital gaining 33,456cr => 34,456cr total



Where can I download the correct file??
I have created and added the prices file & downloaded "system.csv" and "station.csv" from http://www.davek.com.au/td/ and added them to my /data directory.


Still..

getting this error.

Command:
>trade.py -vv run --ship sidew --cr 1000 --from azebancity --via dahangate --to azebancity --jump 1

Result:
trade.py: data\TradeDangerous.prices:242 Unrecognized STAR/Station, '36 URSAE MAJORIS/LIWEI OUTPOST'.



Tried this command:

>trade.py run --sh type6 --ho 5 --fr Dahan --cr 128871 --ins 20000

Result:
>trade.py: data\TradeDangerous.prices:242 Unrecognized STAR/Station, '36 URSAE MAJORIS/LIWEI OUTPOST'.
 
Last edited:
Getting clsoer?

Apologies for that, the "-vv" needs to go before the "run" commands. Type "trade.py run -h" for the command's help.

As to the second problem, it's telling you that the Station.csv has two stations with the same name. Open the data directory and open the file Station.csv in notepad and remove one of the two "Styx,Chi Hub" lines.

So I edited station.csv and now there is this error.

Code:
trade.py -vv run --sh type6 --ho 5 --fr Dahan --cr 128871 --ins 20000
rade.py: data\TradeDangerous.prices:16393 Second entry for station 'STYX/CHI HUB', previous at line 16312.

Edit: There was also a double entry in the .prices file. I deleted it and it's working now.
 
Last edited:
2nd Try..

--Downloaded Trade.py (again)
--Downloaded TradeDangerous.prices --> placed in Data directory.

Ran Command: trade.py -vv run --sh type6 --ho 5 --fr Dahan --cr 128871 --ins 2000
Result: \trade.py: data\TradeDangerous.prices:242 Unrecognized STAR/Station, '36 URSAE MAJORIS/LIWEI OUTPOST'.


Next: Downloaded Station.csv --> placed in Data directory

Ran same command as above

Result: *** INTERNAL ERROR: UNIQUE constraint failed: Station.name
CSV File: data\Station.csv:0
SQL Query: INSERT INTO Station (system_id,name,ls_from_star) VALUES((SELECT System.system_id FROM System WHERE System.name =
?),?,?)
Params: ['Styx', 'Chi Hub', '0']


Also replaced system.csv .... same result as above.
 
Last edited:
2nd Try..

--Downloaded Trade.py (again)
--Downloaded TradeDangerous.prices --> placed in Data directory.

Ran Command: trade.py -vv run --sh type6 --ho 5 --fr Dahan --cr 128871 --ins 2000
Result: \trade.py: data\TradeDangerous.prices:242 Unrecognized STAR/Station, '36 URSAE MAJORIS/LIWEI OUTPOST'.


Next: Downloaded Station.csv --> placed in Data directory

Ran same command as above

Result: *** INTERNAL ERROR: UNIQUE constraint failed: Station.name
CSV File: data\Station.csv:0
SQL Query: INSERT INTO Station (system_id,name,ls_from_star) VALUES((SELECT System.system_id FROM System WHERE System.name =
?),?,?)
Params: ['Styx', 'Chi Hub', '0']

"Chi Hub" is an invalid station - it should be "Chu Hub". I have fixed the data and put it into a corrections table. Try getting the data and the Station.csv now.
 
Last edited:
Downloaded everything again..

C:\Trade Dangerous>trade.py run --credits 1000 --capacity 532 --ship type9
*** INTERNAL ERROR: UNIQUE constraint failed: Station.name
CSV File: data\Station.csv:0
SQL Query: INSERT INTO Station (system_id,name,ls_from_star) VALUES((SELECT System.system_id FROM System WHERE System.name = ?),?,?)
Params: ['Styx', 'Chi Hub', '0']


Another command:

C:\Trade Dangerous>trade.py -vv run --sh type6 --ho 5 --fr Dahan --cr 128871 --ins 20000
*** INTERNAL ERROR: UNIQUE constraint failed: Station.name
CSV File: data\Station.csv:0
SQL Query: INSERT INTO Station (system_id,name,ls_from_star) VALUES((SELECT System.system_id FROM System WHERE System.name = ?),?,?)
Params: ['Styx', 'Chi Hub', '0']
 
Last edited:
now...

C:\Trade Dangerous>trade.py -v run --cap 16 --cr 10000 --ly 9 --from aulin --hops 10 --jumps 2

C:\Trade Dangerous\trade.py: data\TradeDangerous.prices:242 Unrecognized STAR/Station, '36 URSAE MAJORIS/LIWEI OUTPOST'.
 
Downloaded everything again..

C:\Trade Dangerous>trade.py run --credits 1000 --capacity 532 --ship type9
*** INTERNAL ERROR: UNIQUE constraint failed: Station.name
CSV File: data\Station.csv:0
SQL Query: INSERT INTO Station (system_id,name,ls_from_star) VALUES((SELECT System.system_id FROM System WHERE System.name = ?),?,?)
Params: ['Styx', 'Chi Hub', '0']

I had the exact same problem as this (just a few posts above yours). You need to edit a rogue line out of station.csv. You can use Notepad.

As for your other error, I think this is because your TradeDangerous.prices file that you downloaded might be corrupt. That happened to me too. :)
 
Sub-optimal calculations?

I have discovered some sub-optimal calculations going on. Here I ask trade.py for a fairly simple calculation for 2 hops between a couple of systems that are fairly close together.

The 2nd time I ask, I use a profit reduction margin of 10% (Default is 1% according README). You can see that the 2nd time, even though it is supposed to be more conservative and produce less profit, on the 2nd hop it comes up with a slightly different cargo payload that makes more profit!

Code:
trade.py -vv run --sh cobra --fr "TAIMA BAIJUHACMOORA" --to "BD+29 2405" --cr 109278 --ins 14250 --ly 9.24 --cap 36
With 109,278cr / From Mills Park / To Shaara City
36 cap, 2 hops, max 2 jumps/hop and max 9.24 ly/jump

TAIMA BAIJUHACMOORA/Mills Park -> BD+29 2405/Shaara City:
Start CR:     95,028
Hops    :          2
Jumps   :          3
Gain CR :     40,322
Gain/Hop:     20,161
Final CR:    135,350

 >-> At TAIMA BAIJUHACMOORA/Mills Park, Buy:
  |     28 x Auto-Fabricators               @      3,313cr each,     92,764cr total,
  |      1 x Robotics                       @      1,571cr each,      1,571cr total,
  |      4 x Microbial Furnaces             @        162cr each,        648cr total,
  |   95,028cr => TAIMA BAIJUHACMOORA -> BD+29 2405 -> ZARALUVUL => Gain 26,909cr (815cr/ton) => 121,937cr
  +  At ZARALUVUL/Sturckow City, Buy:
  |     25 x Gallium                        @      4,783cr each,    119,575cr total,
  |      4 x Dom. Appliances                @        508cr each,      2,032cr total,
  |      7 x Food Cartridges                @         47cr each,        329cr total,
  |   121,937cr => ZARALUVUL -> BD+29 2405 => Gain 13,413cr (372cr/ton) => 135,350cr
 <-< BD+29 2405/Shaara City gaining 40,322cr => 135,350cr total


trade.py -vv run --sh cobra --fr "TAIMA BAIJUHACMOORA" --to "BD+29 2405" --cr 109278 --ins 14250 --ly 9.24 --cap 36 --margin 0.1
With 109,278cr / From Mills Park / To Shaara City
36 cap, 2 hops, max 2 jumps/hop and max 9.24 ly/jump

TAIMA BAIJUHACMOORA/Mills Park -> BD+29 2405/Shaara City:
Start CR:     95,028
Hops    :          2
Jumps   :          3
Gain CR :     40,417
Gain/Hop:     20,208
Final CR:    135,445

 >-> At TAIMA BAIJUHACMOORA/Mills Park, Buy:
  |     28 x Auto-Fabricators               @      3,313cr each,     92,764cr total,
  |      1 x Robotics                       @      1,571cr each,      1,571cr total,
  |      4 x Microbial Furnaces             @        162cr each,        648cr total,
  |   95,028cr => TAIMA BAIJUHACMOORA -> BD+29 2405 -> ZARALUVUL => Gain 26,909cr (815cr/ton) => 121,937cr
  +  At ZARALUVUL/Sturckow City, Buy:
  |     24 x Gallium                        @      4,783cr each,    114,792cr total,
  |      8 x Dom. Appliances                @        508cr each,      4,064cr total,
  |      4 x Scrap                          @         52cr each,        208cr total,
  |   121,937cr => ZARALUVUL -> BD+29 2405 => Gain 13,508cr (375cr/ton) => 135,445cr
 <-< BD+29 2405/Shaara City gaining 40,417cr => 135,445cr total
 
Back
Top Bottom