Skip to content

Instantly share code, notes, and snippets.

@LTNMinh
Last active November 5, 2024 04:33
Show Gist options
  • Save LTNMinh/0bfc712d6276b79c13d06de45bf69712 to your computer and use it in GitHub Desktop.
Save LTNMinh/0bfc712d6276b79c13d06de45bf69712 to your computer and use it in GitHub Desktop.

How to debug cctx using Devcontainer

1. Create Devcontainer

In your project.

Create .devcontainer folder Create devcontainer.json inside .devcontainer folder

{
    "name": "TypeScript Dev Container",
    "build": {
        "dockerfile": "../Dockerfile",
        "context": "../"
    },
    "customizations": {
        "vscode": {
            "settings": {
                "typescript.tsdk": "/usr/local/lib/node_modules/typescript/lib" // Path to TypeScript SDK
            },
            "extensions": [
                "ms-vscode.vscode-typescript-tslint-plugin", // TypeScript/TSLint support
                "esbenp.prettier-vscode", // Prettier for code formatting
                "dbaeumer.vscode-eslint" // ESLint support
            ]
        }   
    }
}

Use vscode or intelliji to open in dev container

2. Add you exchange file and build the project

After add new exchange file, you should build the project.

npm run build

This will make exchange file compiles and usable in the next step.

3. Add new file main inside folder ts/

// ts/main.js

import ccxt from "./ccxt.js";

async function main() {
    const keystore = {
        "uid": "REPLACE WITH YOUR APP ID",
        "login": "REPLACE WITH YOUR SESSION ID",
        "apiKey": "REPLACE WITH YOUR SERVER PUBLIC KEY",
        "password": "REPLACE WITH YOUR SESSION PRIVATE KEY",
        "privateKey": "REPLACE WITH YOUR SPEND PRIVATE KEY",
        "secret": "REPLACE WITH YOUR OAUTH SECRET"
    }
    const exchange = new ccxt.your_new_exchange_here(keystore);
    // You code go here
}


main()

4. Modify tsconfig.json

{
  "compilerOptions": {
      ...
      "sourceMap": true,          // Uncomment this line.
      ... 
   }
   ....
}

5. Build the ts file.

tsc

6. Try to debug with breakpoint.

Add lauch.json in vscode

{ 
    "version": "0.2.0",
    "configurations":[{
        
                "type": "node",
                "request": "launch",
                "name": "Launch Program",
                "program": "${workspaceFolder}/js/main.js",
    }]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment