flowchart LR;
UI[UI Component - WPF/Web/etc] --> B;
B([Trading Bot APIs]) -- list --> SR[[Strategy Registry]];
SR --x SI[Strategy Implementations...];
T[Tasks] --> E;
SI o--o E[Executors Pool];
B -- create, list, activate, deactivate --> C[[Accounts Configs / Strategy params]];
C --> T;
E --> L[[Logging]];
C --x L;
TBD(donghan): API spec and protocol.
Stategy Registry
- strategies.list
Account Config
- accountConfigs.list
- accountConfigs.create
- accountConfig.activate
- accountConfig.deactivate
AccountConfigs
- config id
- account credentials
- current_strategy
- strategy_params {}
AccountOperations (Logging, it is important to keep track of all trades that were placed)
- operation id
- config id
- action (BUY/SELL)
- operation params {}
All strategies implement the follwing interface.
interface IStrategy {
// Name of the stragey
string name();
// Strategy details
string description();
// execution logic, no blocking code is allowed.
async Task Run();
}
For example, a strategy that does nothing.
class NoopStrategy : IStrategy {
// Name of the stragey
string name() {
return "no-op";
}
// Strategy details
string description() {
return "i do nothing";
}
// execution logic, no blocking code is allowed.
async Task Run() {
// Async method never holds an idle thread. This code will not impact the overall throughput.
await Task.Delay(60000);
System.out.println("no harm is done");
}
}
A singleton class that contains all strategies
public sealed class StrategyRegistry
{
SortedList strategies = new SortedList() {
{StrategyA.name(), StrategyA.class},
};
private StrategyRegistry() { }
private static StrategyRegistry _instance;
public static Singleton GetInstance()
{
if (_instance == null)
{
_instance = new Singleton();
}
return _instance;
}
}
IStrategy strategy = (IStrategy) Activator.CreateInstance(type);
await strategy.Run();