• 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 7 and 8
    Revision 7 as of 2012-12-21 04:20:44
    Size: 2472
    Editor: Romulus
    Comment:
    Revision 8 as of 2012-12-23 02:37:34
    Size: 2289
    Editor: Inanna
    Comment:
    Deletions are marked like this. Additions are marked like this.
    Line 1: Line 1:
    {{{
        // Simple Trading Script v0.06 (c) 2012 NeatPortal.com
        // WARNING: This script requires version 2720+ 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
        //
        
    // 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 ]
     {{{
    // Simple Trading Script v0.06 (c) 2012 NeatPortal.com
    // WARNING: This script requires version 2720+ 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
    //
    // 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 ]
    Line 15: Line 15:
        // How aggressive we want to be (lower number would increase trading gains at the cost of potentially slower trade execution), from 0% to 49%
        aggr = 5%
    // How aggressive we want to be (lower number would increase trading gains at the cost of potentially slower trade execution), from 0% to 49%
    aggr = 5%
    Line 18: Line 18:
        // Only trade if we expect this much gain
        gain = 1%
    // Only trade if we expect this much gain
    gain = 1%
    Line 21: Line 21:
        // ===== NOTHING TO CONFIGURE BELOW THIS LINE =====
        delay = 10
        config trade:0
        res = 0
        comm = 0.5%
        maxBatch = 9999999
        maxRes = 990B
    // ===== NOTHING TO CONFIGURE BELOW THIS LINE =====
    delay = 10
    config trade:0
    res = 0
    comm = 0.5%
    maxBatch = 9999999
    maxRes = 990B
    Line 29: Line 29:
        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[3]) / prices[2] < (1 + gain) 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
        execute "sleep " + delay
        label trynext
        res = (res + 1) MOD 4
        goto nextres
    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[3]) / prices[2] < (1 + gain) 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
    execute "sleep " + delay
    label trynext
    res = (res + 1) MOD 4
    goto nextres
    • // Simple Trading Script v0.06 (c) 2012 NeatPortal.com
      // WARNING: This script requires version 2720+ 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
      //
      // 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 49%
      aggr = 5%
      
      // Only trade if we expect this much gain
      gain = 1%
      
      // ===== NOTHING TO CONFIGURE BELOW THIS LINE =====
      delay = 10
      config trade:0
      res = 0
      comm = 0.5%
      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[3]) / prices[2] < (1 + gain) 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
      execute "sleep " + delay
      label trynext
      res = (res + 1) MOD 4
      goto nextres


    ScriptExamples

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