• My Pages
  • Comments
  • Add Link
  • Subscribe
  • Subscribe User
  • Edit (GUI)
  • Edit (Text)
  • Rename Page
  • Copy Page
  • Load Page
  • Save Page
  • Delete Page
  • Attachments
  • Check Spelling
  • Diffs
  • Info
  • Revert to this revision
  • XML
  • Render as Docbook
  • Print View
  • Raw Text
  • Delete Cache
  • Like Pages
  • Local Site Map
  • Remove Spam
  • Package Pages
  • Sync Pages
    • Diff for "TradeScript"
    Differences between revisions 3 and 10 (spanning 7 versions)
    Revision 3 as of 2012-12-19 19:32:00
    Size: 2166
    Editor: Romulus
    Comment:
    Revision 10 as of 2013-02-03 22:30:48
    Size: 2501
    Editor: Inanna
    Comment:
    Deletions are marked like this. Additions are marked like this.
    Line 1: Line 1:
    !NeatPortal's Market Trading Script

    // Simple Trading Script v0.05
    (c) 2012 NeatPortal.com
    // WARNING: Requires version 2718+ to work properly
     {{{
    // STS v0.10g - Sm
    art Trading Script (c) 2012-2013 NeatPortal.com
    // WARNING: This script requires NEATBOT 2735+ to run
    Line 7: Line 6:
    // Algorithm is simplified, but should work reasonably well
    // Uncomment to enable auto start
    //laber autorun
    // Algorithm is simplified, but should work reasonably well under broad range of conditions
    //
    // Comment out if you want to disable auto start
    label autorun
    // uncomment the next line if you are using 2720-2734 build
    // MAX_TRADE = 9999999

    // ===== OPTIONAL CONFIGURATION PARAMETERS =====
    Line 11: Line 15:
    // 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 ===
    // food, wood, stone, iron, gold:
    extra = [ 1m, 1m, 1m, 1m, 100 ]

    // How aggressive we want to be (lower number would increase trading gains at the cost of potentially slower trade execution)
    aggr = 2%

    // Only trade if we expect this much gain
    gain = 2%

    // ===== NOTHING TO CONFIGURE BELOW THIS LINE =====
    delay = 10
    Line 17: Line 27:
    res = 0
    comm = 0.005
    maxBatch = 9999999
    comm = 0.5%
    Line 21: Line 29:
    Line 22: Line 31:
    if !m_context.marketReady() goto nextres res = floor(random() * 4) // choose resource to trade randomly, helps with multiple trading running
    Line 24: Line 33:
    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

    label check
    if city.tradesArray.length > 8 execute "sleep " + delay
    Line 30: Line 37:
    if city.tradesArray.length > 8 goto trading if city.tradesArray.length > 8 goto check

    label no
    tready
    if !m_context.marketReady() goto notready
    Line 32: Line 42:
    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
    resGold = city.reservedResource.gold + extra[4] + max(0, city.resource.gold - city.reservedResource.gold - extra[4]) * 0.8
    canSell = (city.resource[resName].amount - city.reservedResource[resName] - extra[res]) * 0.8
    sellLimit = (city.resource.gold - resGold) / prices[3]
    if canSell > 0 if sellLimit >=1 if prices[1] - prices[3] < prices[2] * (1 + gain) goto nextres
    if sellLimit < 1 sellLimit = min(max(1, (resGold - city.resource.gold) / prices[1] / 2), (city.resource.gold - 1) / prices[3]) // we are low on gold
    sellVolume = floor(min(canSell, sellLimit, MAX_TRADE - max(0, floor(min(maxRes - city.resource[resName].amount, (city.resource.gold - resGold) / prices[2]))) / 3))
    if sellVolume > 0 execute "sell " + res + " " + sellVolume + " " + prices[1]
    buyVolume = floor(min(maxRes - city.resource[resName].amount, (city.resource.gold - resGold) / prices[2], MAX_TRADE))
    if buyVolume > 0 execute "buy " + res + " " + buyVolume + " " + prices[0]
    Line 44: Line 52:
    }}}
    • // STS v0.10g - Smart Trading Script (c) 2012-2013 NeatPortal.com
      // WARNING: This script requires NEATBOT 2735+ to run
      //
      // The script tries to gain more resources by using spread between bid and ask prices
      // Algorithm is simplified, but should work reasonably well under broad range of conditions
      //
      // Comment out if you want to disable auto start
      label autorun
      // uncomment the next line if you are using 2720-2734 build
      // MAX_TRADE = 9999999
      
      // ===== OPTIONAL CONFIGURATION PARAMETERS =====
      // Extra resources to reserve (in addition to city's reserved resources)
      //       food, wood, stone, iron, gold:
      extra = [  1m,   1m,    1m,   1m,  100 ]
      
      // How aggressive we want to be (lower number would increase trading gains at the cost of potentially slower trade execution)
      aggr = 2%
      
      // Only trade if we expect this much gain
      gain = 2%
      
      // ===== NOTHING TO CONFIGURE BELOW THIS LINE =====
      delay = 10
      config trade:0
      comm = 0.5%
      maxRes = 990B
      
      label nextres
      res = floor(random() * 4) // choose resource to trade randomly, helps with multiple trading running
      resName = ResourceIntNames[res]
      
      label check
      if city.tradesArray.length > 8 execute "sleep " + delay
      if city.tradesArray.length > 8 execute "canceltrade " + city.tradesArray[0].id
      if city.tradesArray.length > 8 goto check
      
      label notready
      if !m_context.marketReady() goto notready
      prices = [ Price(res, aggr), Price(res, 1 - aggr), Price(res, aggr) * (1 + comm), Price(res, 1 - aggr) * comm ]
      resGold = city.reservedResource.gold + extra[4] + max(0, city.resource.gold - city.reservedResource.gold - extra[4]) * 0.8
      canSell = (city.resource[resName].amount - city.reservedResource[resName] - extra[res]) * 0.8
      sellLimit = (city.resource.gold - resGold) / prices[3]
      if canSell > 0 if sellLimit >=1 if prices[1] - prices[3] < prices[2] * (1 + gain) goto nextres
      if sellLimit < 1 sellLimit = min(max(1, (resGold - city.resource.gold) / prices[1] / 2), (city.resource.gold - 1) / prices[3]) // we are low on gold
      sellVolume = floor(min(canSell, sellLimit, MAX_TRADE - max(0, floor(min(maxRes - city.resource[resName].amount, (city.resource.gold - resGold) / prices[2]))) / 3))
      if sellVolume > 0 execute "sell " + res + " " + sellVolume + " " + prices[1]
      buyVolume = floor(min(maxRes - city.resource[resName].amount, (city.resource.gold - resGold) / prices[2], MAX_TRADE))
      if buyVolume > 0 execute "buy " + res + " " + buyVolume + " " + prices[0]
      goto nextres


    ScriptExamples

    TradeScript (last edited 2013-02-03 22:30:48 by Inanna)