2166
Comment:
|
2135
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
!NeatPortal's Market Trading Script |
{{{ |
Line 9: | Line 8: |
//laber autorun | //label autorun |
Line 44: | Line 43: |
}}} |
// Simple Trading Script v0.05 (c) 2012 NeatPortal.com // WARNING: Requires version 2718+ to work properly // // The script tries to gain more resources by using spread between bid and ask prices // Algorithm is simplified, but should work reasonably well // Uncomment to enable auto start //label autorun // Extra resources to reserve (in addition to city's reserved resources) // food, wood, stone, iron, gold: extra = [ 10m, 2m, 5m, 2m, 0 ] // How aggressive we want to be (lower number would increase trading gains at the cost of potentially slower trade execution), from 0 to 0.49 aggr = 0.05 // === nothing to configure below this line === config trade:0 res = 0 comm = 0.005 maxBatch = 9999999 maxRes = 990B label nextres if !m_context.marketReady() goto nextres resName = ResourceIntNames[res] if city.resource[resName].amount > maxRes goto tryother reserved = city.reservedResource resGold = max(reserved.gold + extra[4], (city.resource.gold + reserved.gold + extra[4]) / 2) buyVolume = 0 label trading if city.tradesArray.length > 8 execute "canceltrade " + city.tradesArray[0].id if city.tradesArray.length > 8 goto trading prices = [ Price(res, aggr), Price(res, 1 - aggr), Price(res, aggr) * (1 + comm), Price(res, 1 - aggr) * comm ] if prices[1] / prices[0] < 1.01 goto trynext sellVolume = floor(min(city.resource[resName].amount - reserved[resName] - extra[res], (city.resource.gold - resGold) / prices[3], 1.1 * maxBatch - buyVolume / 10)) if sellVolume <= 0 sellVolume = max(0, floor(min(1, city.resource[resName].amount - reserved[resName] - extra[res], (city.resource.gold - 1) / prices[3], 1.1 * maxBatch - buyVolume / 10))) if sellVolume > 0 execute "sell " + res + " " + min(sellVolume, maxBatch) + " " + prices[1] buyVolume = max(0, floor((city.resource.gold - resGold) / prices[2])) if buyVolume > 0 execute "buy " + res + " " + min(buyVolume, maxBatch) + " " + prices[0] if city.tradesArray.length < 8 if buyVolume + sellVolume > 0 goto trading label tryother sleep 10 label trynext res = (res + 1) MOD 4 goto nextres