grantcolley / tradeview

A .NET Core 3.1 WPF client and ASP.NET Core Web API platform for trading crypto currency pairs on crypto exchanges and running crypto currency pair strategies.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

strategy with multi Charts

overstartup opened this issue · comments

Hi Grant Colley,
I need help to create new strategy, well I need to use 4 EMA, 1 HMA ,MACD and fibo charts in this strategy. Could you please tell me how I can do that?
Is it possible to create the logic and view?

Hi Ahmad,

The MovingAverage strategy and it's corresponding UI logic is there to provide an example that can be followed when creating your own custom strategy and corresponding view. A quick option would be to clone it and replace the implementation details with your own custom code. The code can be found in the following projects:


In the strategy, subscribe to the relevant feeds e.g. trade, candlestick, statistics etc. See create a strategy for some more information.


Provide your own implementation for representing data you want fed back to the UI for rendering on charts etc. See the example in MovingAverage strategy which implements the following:


In the view model, provide the necessary logic for translating the data to be rendered in the charts. For an example take a look at the TradeNotificationsAsync method in MovingAverageViewModel.

See create a wpf strategy component for some more information.


You will also need to make the necessary changes to the charts in the view so have a look at how MovingAverageView does this. I also suggest looking at Live Charts for examples of how to chart your data. You can also easily replace the live chart component with another one if you prefer.


Finally, you will need to configure your account and strategy in the configuration module.

Great, thank you very much.

I have another question, is it possible to have robot trader? You know, I want to have bot to trade features in binance. If you have any suggestion, that will be nice.

The strategy runs on the TradeServer independently of the UI, which means it can act like a 'bot'.

You can create a custom strategy to subscribe to real-time trade feeds, order book, candlestick (if available), statistics and account details and real-time open orders etc. The custom strategy can be configured to run against a specified exchange (e.g. Binance) and you can provide an api key, secret key and, depending on the exchange, an optional pass phrase (e.g. pass phrase is required by Kucoin but not Binance). This will give the strategy access to the account and the ability to place or cancel orders based on your own custom logic i.e. based on real-time decisions your custom logic makes from the feeds the strategy has subscribed to.

Currently Binance and Kucoin API's are supported however, you can extend this to any exchange or add new features an exchange supports.

The TradeView UI simply allows you to do the following:

Note, if you launch a strategy from the UI, you can close the UI and the strategy will continue to run on the TradeServer.

You can also free to write your own custom app for launching a strategy. To do this you will need to understand how the TradeServer works.

Thank you very much.
Could you please give me help to set a strategy?
image

i got this error:
image

Why i can not see anything there?

To run a strategy you will need to do the following:

  1. Configure a strategy in Configuration -> Manage Strategies
  2. Configure a trade server in Configuration -> Manage Trade Servers
  3. Run the Trade Server console application
  4. Run the Trade Viewer WPF application
  5. Select the strategy in the Strategies Module
  6. Select a Trade Server from the trade server drop down list
  7. Click the run button

My recommendation is you first get the demo "Moving Average Strategy" working running then you can use that as a template for creating your own.

Here I will share some more information about each of the steps above.

1. Configure a strategy

Configuration -> Manage Strategies

Strategy Configuration

The top group box, Strategy Runner, is for configuring the strategy that is run on the trade server, where:

  • Target Assembly = the strategy assembly
  • Target Type = The strategy class including namespace.
  • Target Assembly Dependencies = a list of all the assemblies that make up the strategy
  • Parameters = custom strategy parameters in json format which is de-serialised into an object when running the strategy
  • Subscriptions = the symbol you want to run the strategy for, the exchange and api key / secret, and the feeds you want to subscribe for the symbol

The bottom group box, Strategy Display, is for configuring the WPF component to monitor the strategy is real time (this is what gets rendered in the area that empty in your second screenshot above):

  • Display Assembly = the assembly for the WPF component that renders the strategy. It will contain view / view model and supporting code
  • Display View Type = the class and namespace of the view
  • Display View Model Type = the class and namespace of the view model
  • Display Assembly Dependencies = a list of the assemblies that make up the WPF component for monitoring a strategy
  • Trade and Order Book display counts = this is the number of rows you want to see in the trade list and order book.
    • Trade Display Count of 13 means you will see the 13 most recent trades updated in real time.
    • Trade Chart Display Count of 1000 means you will see the most recent 1000 trades in the chart updated in real time.
    • Same applies to Order Book where a display count of 9 will give you the top 9 buys / sells when displaying the Order Book.
    • Order Book Chart Display Count is the cumulative order book.

2. Configure a trade server

Configuration -> Manage Trade Servers
The Trade Server Name and Uri must correspond to that which is specified for the Trade Server in step 3. below.
Configure a Trade Server

3. Run the Trade Server console application

This is DevelopmentInProgress.TradeServer.Console application. Have a look at its Program.cs file and note the args which includes the uri and instance name, which is configured in step 2. above. Also look at the Startup.cs in DevelopmentInProgress.TradeServer.StrategyExecution.WebHost to see how the args are used.

4. Start running a strategy from the Trade Viewer WPF application

Run the Trade Viewer WPF application click on the Strategies Module in the navigation panel and select the strategy.
Select the Trade Server from the trade server drop down list - image below. A green icon shows the trade server (from step 3 above) is running. Then click the Run Strategy button which is the icon to the right of the dropdown.
image

Set some Breakpoints and step through to see how it all works

Breakpoint 1 - Run Strategy button

Put a breakpoint behind the Run Strategy button at RunAsync() in StrategyRunnerViewModel.cs. You will see the strategy binaries configured in step 1 above, are uploaded to the running instance of the Trade Server via a HttpClient request:

await httpClient.PostAsync(uri, multipartFormDataContent, cancellationToken).ConfigureAwait(false);

Breakpoint 2 - Inside the trade server Middleware

Put a breakpoint in the RunStrategyMiddleware of the trade servers DevelopmentInProgress.TradeServer.StrategyExecution.WebHost to see the incoming request to run the strategy. Step through and you will see the strategy assemblies loaded into memory and the strategy is executed.

Breakpoint 3 - Inside the MovingAverageStrategy

Put a breakpoint inside the SubscribeTrades(TradeEventArgs tradeEventArgs) in the MovingAverageStrategy.cs class and you will see the live trade feed.

Once the demo strategy is working you should see something like:
a running strategy

@overstartup here are some additional suggestions to help you get the demo "Moving Average Strategy" running.

If you are running Visual Studio:

Set the output path for each project to ..\..\output\.

image

In the solution's properties, setting the following as startup projects so both the server and WPF app launch at startup.

  • DevelopmentInProgress.TradeView.Wpf.Host
  • DevelopmentInProgress.TradeServer.Console

image

Here are some default config files. You will need to place the config files in the same folder the binaries are output to e.g. ..\output\netcoreapp3.1.

image

REPLACE_WITH_YOUR_USER_NAME_Accounts.txt
REPLACE_WITH_YOUR_USER_NAME_Strategies.txt
REPLACE_WITH_YOUR_USER_NAME_TradeServers.txt

The config file names starts with your login username so you will need to rename them to be picked up.

            var userAccountsFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{Environment.UserName}_Accounts.txt");
            var userStrategiesFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{Environment.UserName}_Strategies.txt");
            var userServersFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{Environment.UserName}_TradeServers.txt");

Note: the config is set to run the strategy against Binance however, to get started you don't need to have a Binance account as the demo strategy doesn't actually place live orders.

Let me know how you get on.

Thank you very much. i will try it