{
  "name": "P2P_OrderWatcher_Download",
  "nodes": [
    {
      "parameters": {
        "action": "hmac",
        "type": "SHA256",
        "value": "={{ $json[\"queryString\"] }}",
        "dataPropertyName": "signature",
        "secret": "=xxxxxxxxxxxxxxxxxxxxxxxxx"
      },
      "type": "n8n-nodes-base.crypto",
      "typeVersion": 1,
      "position": [
        192,
        0
      ],
      "id": "00cdd8fc-cc24-4ccd-bbf2-bb9a7c36196b",
      "name": "Crypto"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 30
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        -240,
        0
      ],
      "id": "df7f7cda-df37-4f43-ab8c-7777746250f5",
      "name": "Schedule Trigger"
    },
    {
      "parameters": {
        "fieldToSplitOut": "data",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        -16,
        256
      ],
      "id": "9d8a8c48-63e8-45e3-bf12-6385be29f45a",
      "name": "Split Out"
    },
    {
      "parameters": {
        "operation": "removeItemsSeenInPreviousExecutions",
        "dedupeValue": "={{ $json.orderNumber }}",
        "options": {}
      },
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        384,
        256
      ],
      "id": "061a62eb-4879-4233-897c-f7c979bdfc0d",
      "name": "Remove Duplicates"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "0d1b69f8-2761-4bf0-922f-d0f8fe63554a",
              "leftValue": "={{ $json.orderStatus }}",
              "rightValue": "COMPLETED",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        192,
        256
      ],
      "id": "6d223ff8-eb49-45e9-8472-2dc1e5dbacbb",
      "name": "Filter"
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "1eD5ug1Ffz1ChnavxUDCh8t0jff55wev3mrpniS4_kTQ",
          "mode": "list",
          "cachedResultName": "PersonalPortfolio",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1eD5ug1Ffz1ChnavxUDCh8t0jff55wev3mrpniS4_kTQ/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 918722895,
          "mode": "list",
          "cachedResultName": "TOTAL",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1eD5ug1Ffz1ChnavxUDCh8t0jff55wev3mrpniS4_kTQ/edit#gid=918722895"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "ORDER": "={{ $json.orderNumber }}",
            "FECHA": "={{ new Date($json.createTime).toDateTime().format('yyyy-MM-dd') }}",
            "MOVIMIENTO": "={{ $json.tradeType }}",
            "COP": "={{ $json.totalPrice }}",
            "USDT": "={{ $json.amount }}"
          },
          "matchingColumns": [
            "ORDER"
          ],
          "schema": [
            {
              "id": "ORDER",
              "displayName": "ORDER",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "FECHA",
              "displayName": "FECHA",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "MOVIMIENTO",
              "displayName": "MOVIMIENTO",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "COP",
              "displayName": "COP",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "USDT",
              "displayName": "USDT",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "NOTE",
              "displayName": "NOTE",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        -16,
        512
      ],
      "id": "4eae4f5c-b0d0-45fa-8c4a-cde1198c34f5",
      "name": "Append or update row in sheet",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "yAhvc5Kuvdgv1z5Z",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const timestamp = Date.now();\nconst recvWindow = 5000;\n\nconst params = [\n  `timestamp=${timestamp}`,\n  `recvWindow=${recvWindow}`,\n];\n\nconst queryString = params.join('&');\n\nreturn [\n  {\n    json: {\n      timestamp,\n      recvWindow,\n      queryString,\n    }\n  }\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -16,
        0
      ],
      "id": "561a2c4c-eacf-4a0f-84a5-7609af50851f",
      "name": "generateQuery"
    },
    {
      "parameters": {
        "chatId": "telegram_bot_id",
        "text": "=Binance Bot ha sincronizado las ordenes P2P",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        192,
        512
      ],
      "id": "ec4e3ffa-acb5-4015-b5e6-964972740cc9",
      "name": "NotifyTelegram",
      "webhookId": "25f28f62-2742-45ad-a48c-c2af4692c7a6",
      "credentials": {
        "telegramApi": {
          "id": "ap7x1qDyld9KmbHt",
          "name": "Telegram account ONTP"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "content": "## Step 1\nSet your secret key here",
        "height": 240,
        "width": 192,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        144,
        -80
      ],
      "typeVersion": 1,
      "id": "736535ea-b7b3-4e5a-b143-94878002e6c0",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "## Step 2\nCreate and use a header auth with name:\nX-MBX-APIKEY",
        "height": 288,
        "width": 192,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        352,
        -128
      ],
      "typeVersion": 1,
      "id": "e9e65833-5db4-4a10-93e2-a1b8e7d52898",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "url": "https://api.binance.com/sapi/v1/c2c/orderMatch/listUserOrderHistory",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "timestamp",
              "value": "={{ $json.timestamp }}"
            },
            {
              "name": "signature",
              "value": "={{ $json.signature }}"
            },
            {
              "name": "recvWindow",
              "value": "={{ $json.recvWindow }}"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "options": {
          "redirect": {
            "redirect": {}
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        400,
        0
      ],
      "id": "7f23d229-0e1d-4764-8ac0-4e9a2b9cecf4",
      "name": "BinanceP2P",
      "credentials": {
        "httpHeaderAuth": {
          "id": "Wxy2kFUQWUDcB72S",
          "name": "BinanceApiKey"
        }
      }
    },
    {
      "parameters": {
        "content": "## Step 3\nCreate and select your Google Spread Sheet with headers:\n\n[ORDER]\n[FECHA]\n[MOVIMIENTO]\n[COP]\n[USDT]",
        "height": 272,
        "width": 320,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        416
      ],
      "typeVersion": 1,
      "id": "1aa114f7-3dd1-402a-9671-ddde3b10ea4e",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "content": "## Step 4\nConfigure or delete this node to receive update notification vía telegram.",
        "height": 128,
        "width": 224,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        672
      ],
      "typeVersion": 1,
      "id": "07884dfb-7663-4c74-b8ba-3604e18e17fe",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "content": "## Important\nApiKey must be readonly and limited to c2c only:\nEnable P2P / C2C API",
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -576,
        -16
      ],
      "typeVersion": 1,
      "id": "7c107262-d23a-40ff-ab2b-4fcdf99e199f",
      "name": "Sticky Note4"
    }
  ],
  "pinData": {},
  "connections": {
    "Crypto": {
      "main": [
        [
          {
            "node": "BinanceP2P",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "generateQuery",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter": {
      "main": [
        [
          {
            "node": "Remove Duplicates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Duplicates": {
      "main": [
        [
          {
            "node": "Append or update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append or update row in sheet": {
      "main": [
        [
          {
            "node": "NotifyTelegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "generateQuery": {
      "main": [
        [
          {
            "node": "Crypto",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "BinanceP2P": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "timezone": "America/Bogota",
    "callerPolicy": "workflowsFromSameOwner",
    "availableInMCP": false
  },
  "versionId": "388fb981-7f79-4218-b6fa-19a0c4a2b97d",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "fa6555c0fdb22a62d930b2a5bc4baaced72024dea55b15842315ef05eb4677ba"
  },
  "id": "OejAsAaDmcBoodFe",
  "tags": []
}