keyboard shortcuts for trading

Add your new features and requests here.
kb_trader
Posts: 30
Joined: Wed Oct 09, 2019 10:49 pm
Been thanked: 13 times

Re: keyboard shortcuts for trading

Post by kb_trader » Wed Oct 09, 2019 10:56 pm

Done.

Tried using Control + F keys to essentially get around the F10 which is a default main menu shortcut for java apps.
However this isn't ideal... yes it works to prevent the main menu from opening and sends the order but then
BM must be clicked on anywhere with the mouse or else it will no longer respond as BM is no longer in focus or most front.

If someone has found a better way?
If BM can implement something simple, built into the it would be most helpful.

Thanks

 
Attachments
KB SC.PNG
KB SC.PNG (11.66 KiB) Viewed 23284 times

mpxtreme
Posts: 33
Joined: Thu Oct 25, 2018 12:20 am
Been thanked: 6 times

Re: keyboard shortcuts for trading

Post by mpxtreme » Sat Oct 12, 2019 2:05 am

AndreyR wrote:
Tue Aug 13, 2019 3:25 pm
Hi IntheZone,
the code I have posted is a sample 'custom user module' created for Bookmap with a Simplified API. Take a look at this package
https://github.com/BookmapAPI/DemoStrategies
There's a brief overview in the Doc folder. You are welcome to ask your questions if something goes wrong.
There are a bunch of simplified demo strategies in that package, take a look at them. they are created with a very simple yet powerful Simplified interface. To make your module work just extend some simple interfaces, launch your strategy to Bookmap and voila you have your own strategy working. All you need is some software development background

Is there a “flatten all” command?

Thanks
mpxtreme
Last edited by mpxtreme on Fri Nov 01, 2019 9:08 pm, edited 2 times in total.

Andry API support
Posts: 548
Joined: Mon Jul 09, 2018 11:18 am
Has thanked: 25 times
Been thanked: 85 times

Re: keyboard shortcuts for trading

Post by Andry API support » Sun Oct 13, 2019 7:38 pm

“flatten all” command is in the API
There's no flatten all command in the API. "Flatten" closes open positions and cancels pending orders. So to flatten you have to track your position and pending orders first. Then when you actually "flatten" place a position-sized market order to close it and cancel orders with API.

mpxtreme
Posts: 33
Joined: Thu Oct 25, 2018 12:20 am
Been thanked: 6 times

Re: keyboard shortcuts for trading

Post by mpxtreme » Mon Oct 14, 2019 11:05 pm

Thanks AndreyR!


I am also trying to find a way around the F10 key...seeing the same behavior where BM is no longer the front focused app.

Thanks
mpxtreme

Andry API support
Posts: 548
Joined: Mon Jul 09, 2018 11:18 am
Has thanked: 25 times
Been thanked: 85 times

Re: keyboard shortcuts for trading

Post by Andry API support » Fri Nov 01, 2019 2:19 pm

Hi! Here's a workaround that has not been thorouhly exemined. It is not perfect but I can place orders with F10 and not involve menu call.

Code: Select all


        Action action = new AbstractAction()
        {
            @Override
            public void actionPerformed(ActionEvent e){}
        };
        
        Frame[] frames = Frame.getFrames();
        for (Frame frame : frames) {
            Component[] components = frame.getComponents();
            for (Component component : components) {
                if (component instanceof JComponent) {
                    JComponent jcomponent = (JComponent) component;
                    String key = "F10";
                    KeyStroke f10 = KeyStroke.getKeyStroke( key );
                    InputMap map = jcomponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
                    map.put(f10, key);
                    jcomponent.getActionMap().put(key, action);
                }
            }
        }

blk
Posts: 44
Joined: Fri Nov 01, 2019 8:59 pm
Has thanked: 7 times

Re: keyboard shortcuts for trading

Post by blk » Fri Nov 01, 2019 9:05 pm

Hi Andrey,

I'm playing with shortcuts on BM and I'm wondering if there is a way to only enable the shortcuts when the heatmap is on focus? 

As of now, the shortcuts are going to all instruments where the addon is loaded. So my idea is to have the addon loaded on lets say, ES and CL and when I have the the ES heatmap on focus the shortcuts will be enabled and when I switch to CL heatmap the shortcuts will be disable on ES and enable on CL.

Appreciate any ideas you have for this.

Thanks

berenis
Posts: 14
Joined: Sat Oct 26, 2019 1:18 am
Been thanked: 3 times

Re: keyboard shortcuts for trading

Post by berenis » Tue Nov 19, 2019 11:18 am

Much needed, these shortcuts + offset so for example, joing the BID +0.01

Andry API support
Posts: 548
Joined: Mon Jul 09, 2018 11:18 am
Has thanked: 25 times
Been thanked: 85 times

Re: keyboard shortcuts for trading

Post by Andry API support » Thu Nov 21, 2019 9:29 am

blk wrote: my idea is to have the addon loaded on lets say, ES and CL and when I have the the ES heatmap on focus the shortcuts will be enabled and when I switch to CL heatmap the shortcuts will be disable on ES and enable on CL
This feature (reading an active symbol) will be available for the next release. I'll make an example and will post it in this topic.

blk
Posts: 44
Joined: Fri Nov 01, 2019 8:59 pm
Has thanked: 7 times

Re: keyboard shortcuts for trading

Post by blk » Tue Nov 26, 2019 7:38 pm

Thank you Andrey, Do you have an estimated date for the next release to be available?

Appreciate your help.

Andry API support
Posts: 548
Joined: Mon Jul 09, 2018 11:18 am
Has thanked: 25 times
Been thanked: 85 times

Re: keyboard shortcuts for trading

Post by Andry API support » Mon Dec 09, 2019 9:04 am

Hi blk,
b25 for 7.1.0 was released a few days ago.
Here is a code example. Please note it is expecting a KEY_PRESSED event so if the key is held down it is likely to fire over and over again causing lots of orders being placed.
Orders will be placed even if the trade control panel is locked.

Code: Select all

package layer1modules;

import java.awt.Component;
import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;

import javax.swing.JComponent;

import velox.api.layer1.Layer1ApiAdminAdapter;
import velox.api.layer1.Layer1ApiFinishable;
import velox.api.layer1.Layer1ApiProvider;
import velox.api.layer1.annotations.Layer1ApiVersion;
import velox.api.layer1.annotations.Layer1ApiVersionValue;
import velox.api.layer1.annotations.Layer1Attachable;
import velox.api.layer1.annotations.Layer1StrategyName;
import velox.api.layer1.annotations.Layer1TradingStrategy;
import velox.api.layer1.common.ListenableHelper;
import velox.api.layer1.common.Log;
import velox.api.layer1.data.OrderSendParameters;
import velox.api.layer1.data.SimpleOrderSendParametersBuilder;
import velox.api.layer1.messages.UserMessageLayersChainCreatedTargeted;

@Layer1Attachable
@Layer1TradingStrategy
@Layer1StrategyName("OrderByKeyAliasedSender")
@Layer1ApiVersion(Layer1ApiVersionValue.VERSION2)
public class OrderByKeyAliasedSender implements Layer1ApiFinishable, Layer1ApiAdminAdapter

{
    private KeyEventDispatcher customDispatcher;
    private Layer1ApiProvider provider;
    
    public OrderByKeyAliasedSender(Layer1ApiProvider provider) {
        this.provider = provider;
        ListenableHelper.addListeners(provider, this);
    }

    @Override
    public void onUserMessage(Object data) {
        if (data.getClass() == UserMessageLayersChainCreatedTargeted.class) {
            UserMessageLayersChainCreatedTargeted message = (UserMessageLayersChainCreatedTargeted) data;
            if (message.targetClass == getClass()) {
                listenForKey();
            }
        }
    }

    @Override
    public void finish() {
        KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(customDispatcher);
    }
    
    private void listenForKey() {
        customDispatcher = new KeyEventDispatcher() {
            @Override
            public boolean dispatchKeyEvent(KeyEvent e) {
                if (e.getID() == KeyEvent.KEY_PRESSED) {
                    Log.info(getClass().getSimpleName() + " keyPressed" );
                    String currentAlias = null;
                    Object source = e.getSource();
                    
                    while (currentAlias == null && source != null) {
                        if (source instanceof JComponent) {
                            JComponent jcomp = (JComponent)source;
                            Object object = jcomp.getClientProperty("bookmapAlias");
                            
                            if (object == null) { //no alias found so checking the parent
                                source = jcomp.getParent();
                            } else {//alias found
                                currentAlias = object.toString();
                            }
                        } else if (source instanceof Component) { //source is a separate window
                            source = ((Component)source).getParent();
                        } else { //some undesirable scenario
                            Log.info(getClass().getSimpleName() + " source of unknown nature");
                            break;
                        }
                    }
                    
                    if (e.getKeyChar() == 'q') {
                        Log.info("send order for " + currentAlias);
                        provider.sendOrder(getMarketOrderSendParameters(currentAlias, true, 5));
                    }
                    if (e.getKeyChar() == 's') {
                        Log.info("send order for " + currentAlias);
                        provider.sendOrder(getMarketOrderSendParameters(currentAlias, false, 5));
                    }
                }
                return false;
            }
        };
        KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        manager.addKeyEventDispatcher(customDispatcher);
    }
    
    private OrderSendParameters getMarketOrderSendParameters(String alias,  boolean isBuy, int size) {
        SimpleOrderSendParametersBuilder shortOrderSendParameters = new SimpleOrderSendParametersBuilder(alias,
                isBuy, size);
        OrderSendParameters order = shortOrderSendParameters.build();
        return order;
    }
}

Post Reply