Need help starting market data in C#/JS

In visual studio, I have tried “marketdata”, “md”, “data”, “subscribe”, and other keywords but cannot find the class or function to request market data via Websockets.

I am able to connect to Websockets, pull account info, and send orders. Please help with market data if you can. Thank you!

If you post the key couple of statements to start market data in C#, that will help me very much! Thank you!

Here is me trying to get this:

void startMarketData(string symbol)
{
//md.requestMarketData(); does not exist
//requestMarketData(); does not exist
//Data.request(); does not exist
//DataUpdate d = new DataUpdate(); not correct class for market data
//WebSocketClient.RequestData(); does not exist

    }

What is the class or function to do this? If you can tell me where I can find it, I will much appreciate it too. It’s not part of C sharp sample on GitHub. I also searched through the Tradovate.Service solution without finding a good way to pull market data.

Thank you!

Hello @cat1,

I know this may not be the answer you want, but I would advise that you please use the JS examples provided here.

Thank you for the reply.

Is there no way to do it in C Sharp?

It’s a difference of couple more hours of C Sharp vs days or weeks of learning JS for me.

Update:
In addition, as I try to do this, what do you mean by:
" first open a terminal and navigate to the specific tutorial folder you’d like to work from. Once you’ve navigated to your chosen tutorial project’s root, install the dependencies:

> yarn install

"
In windows, I use command prompt to go to:
D:\tradovate\GitHub\example-api-js\tutorial\Access\EX-0-Access-Start

and type:
yarn install

nothing happens since there is no yarn executable.

Can you help me to get started on this if JS is the only way to do it?

Update:
I got it, install NODE JS then YARN then this step

1 Like

I followed each step for EX-0-Access-Start (from the JS script example)
Save file
yarn start: Compiled successfully

Readme says "When we run that code, we’ll get an error. We should see GET 400"

How do I run that code?
I try: node app.js
It gives error: SyntaxError: Cannot use import statement outside a module

I tried to combine env.js, connect.js and app.js into 1 file and compile.
Again compiles successfully.
I try: node app.js
Gives error: ReferenceError: fetch is not defined

Please help.

yarn start is the command to run the webpack dev server, so this should run the code. To see the code run, open a browser and navigate to localhost:8080. When that page opens it will be blank. Press ctrl+shift+i to open the dev tools. In the dev console, you should see the GET 400 error appear. node app.js uses node to launch a js file, so that makes sense that you’d get that error since fetch is a browser-only feature. You did add the code to the connect.js file and uncomment connect() in the app.js file right?

If you’re running the program in your command line, you have to do “npm install node-fetch” so node.js knows what the fetch function is.
Also, you have to add the following line at the top of your connect.js file:
“const fetch = require(“node-fetch”)”
This gets rid of the error: “ReferenceError: fetch is not defined”.

The example docs are based on webpack, which compiles JavaScript and ES6 (I think?) modules for the client (such as running it in a browser like Chrome or an Electron app). webpack relies on the import statements.

If you’re running node app.js you’ll need to take a slightly different approach, using CommonJS modules via require statements (instead of import).

For simplicity to get started, would recommend following the the docs with the yarn and webpack approach. There’s quite a bit of reconfiguration to run the app via node instead.

(Edit) Should also add: webpack will allow you to run the app as a web app in your browser, served from a webpack-dev-server, usually at localhost:8000 or similar, more of a frontend approach. node will allow you to run the app as a Node.js app (more like a Node server) in the terminal on your machine, more of a backend approach.

Refer: Module Methods | webpack

1 Like

I’m still learning how to use APIs, could you elaborate on how to run / debug the program via webpack to follow along on the Github Javascript examples? How do I “run” the modules provided by tradovate in a browser?

Thanks.