{
  "name": "Build a sports betting odds tracker with dino.markets, Google Sheets, and Telegram",
  "nodes": [
    {
      "id": "00000001-0000-4000-8000-000000000000",
      "name": "Every hour",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours"
            }
          ]
        }
      }
    },
    {
      "id": "00000002-0000-4000-8000-000000000000",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        300
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "league",
              "value": "nba",
              "type": "string"
            },
            {
              "id": "2",
              "name": "market",
              "value": "moneyline",
              "type": "string"
            },
            {
              "id": "3",
              "name": "daysAhead",
              "value": 3,
              "type": "number"
            },
            {
              "id": "4",
              "name": "minMovePoints",
              "value": 2,
              "type": "number"
            },
            {
              "id": "6",
              "name": "sheetUrl",
              "value": "PASTE_YOUR_GOOGLE_SHEET_URL",
              "type": "string"
            },
            {
              "id": "7",
              "name": "telegramChatId",
              "value": "PASTE_YOUR_TELEGRAM_CHAT_ID",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "00000003-0000-4000-8000-000000000000",
      "name": "Read saved prices",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        500,
        300
      ],
      "parameters": {
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "={{ $('Settings').first().json.sheetUrl }}"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Prices"
        },
        "options": {
          "outputFormatting": {
            "values": {
              "general": "UNFORMATTED_VALUE",
              "date": "FORMATTED_STRING"
            }
          }
        }
      },
      "alwaysOutputData": true
    },
    {
      "id": "00000004-0000-4000-8000-000000000000",
      "name": "Read live odds",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        720,
        300
      ],
      "parameters": {
        "url": "https://api.dino.markets/v2/odds",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "league",
              "value": "={{ $('Settings').first().json.league }}"
            },
            {
              "name": "markets",
              "value": "={{ $('Settings').first().json.market }}"
            },
            {
              "name": "status",
              "value": "scheduled"
            },
            {
              "name": "limit",
              "value": "100"
            },
            {
              "name": "start_before",
              "value": "={{ $now.toUTC().plus({ days: $('Settings').first().json.daysAhead }).startOf('second').toISO({ suppressMilliseconds: true }) }}"
            }
          ]
        },
        "options": {
          "timeout": 30000
        }
      },
      "executeOnce": true,
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000,
      "onError": "continueErrorOutput"
    },
    {
      "id": "00000005-0000-4000-8000-000000000000",
      "name": "Stop and show the API error",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        960,
        520
      ],
      "parameters": {
        "errorMessage": "=Odds were not read: {{ $json.error.status || '' }} {{ $json.error.message || $json.error }}. Check your key, your credits at dino.markets/dashboard, and the league in Settings."
      }
    },
    {
      "id": "00000006-0000-4000-8000-000000000000",
      "name": "Find moved prices",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        960,
        300
      ],
      "parameters": {
        "jsCode": "const settings = $('Settings').first().json;\nconst minMove = Number(settings.minMovePoints);\nconst answer = $('Read live odds').first().json;\n\n// Last alerted price of each side, from the sheet. Empty on the first run.\nconst saved = {};\nfor (const row of $('Read saved prices').all()) {\n  if (row.json.key) saved[row.json.key] = row.json;\n}\n\n// Best current price of each side, across every book in the answer.\nconst best = {};\nfor (const event of answer.events || []) {\n  if (event.kind !== 'game' || event.status !== 'scheduled') continue;\n  const game = event.away.name + ' at ' + event.home.name;\n  for (const book of event.books) {\n    for (const market of book.markets) {\n      if (market.key !== settings.market) continue;\n      for (const o of market.outcomes) {\n        const key = event.id + '|' + market.key + '|' + o.side;\n        const price = Number(o.price);\n        if (!(price > 1)) continue;\n        if (!best[key] || price > best[key].price) {\n          best[key] = { key, game, start_time: event.start_time, pick: o.name, price, american: o.american, book: book.name };\n        }\n      }\n    }\n  }\n}\n\n// Keep new sides and real moves. A small move keeps the old saved price, so small moves add up.\nconst out = [];\nfor (const row of Object.values(best)) {\n  const old = saved[row.key];\n  const oldPrice = old ? Number(old.price) : NaN;\n  const isNew = !(oldPrice > 1);\n  const points = isNew ? 0 : 100 / row.price - 100 / oldPrice;\n  if (!isNew && Math.abs(points) < minMove) continue;\n  out.push({ json: { ...row, checked_at: answer.as_of, moved: !isNew,\n    old_american: isNew ? '' : (Number(old.american) > 0 ? '+' : '') + Number(old.american), old_book: isNew ? '' : old.book,\n    move_points: Math.round(points * 10) / 10 } });\n}\nreturn out;\n"
      }
    },
    {
      "id": "00000007-0000-4000-8000-000000000000",
      "name": "Keep moves only",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        1240,
        180
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "1",
              "leftValue": "={{ $json.moved }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "00000008-0000-4000-8000-000000000000",
      "name": "Write one message",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1460,
        180
      ],
      "parameters": {
        "jsCode": "// One message for all moves of this run, cut to fit Telegram's 4,096 characters.\nconst rows = $input.all().map(i => i.json);\nif (rows.length === 0) return [];\n// Telegram reads the text as HTML, so these three characters are escaped.\nconst safe = s => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\nconst lines = rows.map(r => safe(`${r.pick} (${r.game}): best price ${r.old_american} at ${r.old_book}, now ${r.american} at ${r.book} (${r.move_points > 0 ? '+' : ''}${r.move_points} points)`));\nlet text = `Prices moved: ${rows.length}`;\nlet shown = 0;\nfor (const line of lines) {\n  if ((text + '\\n' + line).length > 3900) break;\n  text += '\\n' + line;\n  shown++;\n}\nif (shown < lines.length) text += `\\n${lines.length - shown} more in the sheet`;\nreturn [{ json: { text } }];\n"
      }
    },
    {
      "id": "00000009-0000-4000-8000-000000000000",
      "name": "Send Telegram alert",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1680,
        180
      ],
      "parameters": {
        "chatId": "={{ $('Settings').first().json.telegramChatId }}",
        "text": "={{ $json.text }}",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      }
    },
    {
      "id": "00000010-0000-4000-8000-000000000000",
      "name": "Save new and moved prices",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1240,
        420
      ],
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "={{ $('Settings').first().json.sheetUrl }}"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Prices"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "key"
          ],
          "value": {
            "key": "={{ $json.key }}",
            "game": "={{ $json.game }}",
            "start_time": "={{ $json.start_time }}",
            "pick": "={{ $json.pick }}",
            "price": "={{ $json.price }}",
            "american": "={{ $json.american }}",
            "book": "={{ $json.book }}",
            "checked_at": "={{ $json.checked_at }}"
          },
          "schema": [
            {
              "id": "key",
              "displayName": "key",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "game",
              "displayName": "game",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "start_time",
              "displayName": "start_time",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "pick",
              "displayName": "pick",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "american",
              "displayName": "american",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "book",
              "displayName": "book",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "checked_at",
              "displayName": "checked_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {
          "cellFormat": "RAW"
        }
      }
    },
    {
      "id": "00000011-0000-4000-8000-000000000000",
      "name": "Note 10",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -560,
        -60
      ],
      "parameters": {
        "content": "### How it works\nFor people who compare sports odds and want to know when the best available price changes. Every hour it reads one league's upcoming games from the dino.markets API, finds the best price on each side across sportsbooks and prediction markets, and compares it with the last price saved in your Google Sheet. When the implied chance (100 / decimal price) has moved enough, it sends one Telegram message listing every move, then saves the new prices. The first run only saves prices. If Telegram fails, nothing is saved, so the next run tries again.\n\n### Setup\n1. Create a free dino.markets key and add it as a Header Auth credential on **Read live odds**: name `x-api-key`, value your key.\n2. Make a Google Sheet with a tab named `Prices` and this first row: key, game, start_time, pick, price, american, book, checked_at. Connect your Google account on both Sheets nodes.\n3. Connect a Telegram bot and send it a message once.\n4. Fill in **Settings**, then run it once by hand.\n\n[Full setup guide](https://dino.markets/guides/sports-odds-in-n8n/)\n\n### Customization\nChange the league, market, days ahead and smallest move in **Settings**. For soccer use `moneyline_3way`. Spreads and totals are not supported, because their lines can change.\n\n### Limits\nOne call an hour is up to 744 credits a month. Reads up to 100 games. Exchange and prediction market prices are before their fees. Prices are read every 30 seconds to 5 minutes, so check the book before acting. If a save fails after an alert, that alert can repeat. Old rows stay until you delete them.",
        "width": 500,
        "height": 860
      }
    },
    {
      "id": "00000012-0000-4000-8000-000000000000",
      "name": "Note 11",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        180
      ],
      "parameters": {
        "content": "## Schedule and settings\nEdit **Settings** before the first run.",
        "width": 420,
        "height": 300,
        "color": 7
      }
    },
    {
      "id": "00000013-0000-4000-8000-000000000000",
      "name": "Note 12",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        440,
        180
      ],
      "parameters": {
        "content": "## Read saved and live prices\nThe sheet holds the last alerted price. Failed calls are retried, then reported.",
        "width": 440,
        "height": 300,
        "color": 7
      }
    },
    {
      "id": "00000014-0000-4000-8000-000000000000",
      "name": "Note 13",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        900,
        180
      ],
      "parameters": {
        "content": "## Compare prices\nFind the best price on each side and measure the move.",
        "width": 240,
        "height": 300,
        "color": 7
      }
    },
    {
      "id": "00000015-0000-4000-8000-000000000000",
      "name": "Note 14",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1180,
        40
      ],
      "parameters": {
        "content": "## Alert\nOne Telegram message for all moves in this run.",
        "width": 700,
        "height": 280,
        "color": 7
      }
    },
    {
      "id": "00000016-0000-4000-8000-000000000000",
      "name": "Note 15",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1180,
        340
      ],
      "parameters": {
        "content": "## Save\nAdds new sides and updates moved ones.",
        "width": 300,
        "height": 240,
        "color": 7
      }
    }
  ],
  "connections": {
    "Every hour": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Read saved prices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read saved prices": {
      "main": [
        [
          {
            "node": "Read live odds",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find moved prices": {
      "main": [
        [
          {
            "node": "Keep moves only",
            "type": "main",
            "index": 0
          },
          {
            "node": "Save new and moved prices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep moves only": {
      "main": [
        [
          {
            "node": "Write one message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write one message": {
      "main": [
        [
          {
            "node": "Send Telegram alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read live odds": {
      "main": [
        [
          {
            "node": "Find moved prices",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Stop and show the API error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}