· 6 years ago · Nov 30, 2019, 09:00 AM
1Inputs:
2
3-My api details (API key and secret, used to connect the app to my specific Bitmex account)
4
5-Risk amount per trade in BTC (this will be a decimal number like 0.01 for example)
6
7These inputs can either be set in some sort of config file, or just in the app itself (whatever is easier/you think is better). I would rather the actual interface of the app was kept small and succinct in size (so it doesn't take up much space on my screen), so better if there is just a pop up that appears when the program launches and asks for my input for 'risk amount per trade' and then dissapears once ive entered it.
8
9
10Functionality:
11
12The main functionality of the application is to submit 'market buy' and 'market sell' orders to bitmex using the buttons in the diagram, and also submit an attached 'stop market' order at the same time. Depending on which button I press, the quantity (size) of the 'market buy' or sell order will vary based on a few variables used in the calculation (I will give you the specific calculations/formulas to work out what this quantity is separatley):
13
14
15-Current/last traded price of the XBTUSD contract on bitmex (for our purposes this is the current bitcoin price). This data will need to be constantly streamed via websockets as obviously the price is changing every second.
16
17-The 'Risk Amount Per Trade' input that I set.
18
19-The 'offset' or how far away my stop order is (which is the number on the button, e.g. '-10', '+25' etc) I will explain what this all means further ahead.
20
21--------------------------------------------------
22
23
24Let me explain what the '-15' or '+30' on the buttons means.
25
26When one of those buttons is pressed (e.g. the '-20' button on the left hand side), two orders will be actually sent to bitmex:
27
28The first one is simply a 'market buy' or 'market sell' order, which just means buy or sell at what ever the current price is, you don't specify a price yourself.
29
30The second order that is sent will be a 'stop market' order, which is an order to buy or sell at a specific price that you choose (in contrast to the market buy/sell, which is just to buy or sell at whatever the current price is). This is used to close out the trade entered with the 'market order'.
31
32In the case of buttons on the 'buy' side, the '-10' means that the stop market order will be placed at whatever the current price is, -10. And as it is on the 'buy' side, this means it will be a stop market sell, because the aim of the order is to close out of the trade if the price goes down to that point. Similarly, if I clicked a button on the 'sell' side, it would be a 'stop market buy' that is used, to close that position.
33
34For example, if the price of bitcoin was currently $5000 and I clicked on the '-15' button on the 'buy' side, an order would be submitted to 'market buy' bitcoin (which would be at the current price of bitcoin, $5000), and a second order would be submitted as a 'stop market sell order', to sell the same amount (quantity) of bitcoin that was bought at a stop price of $4985 (which is the current price at the time of execution -15).
35
36similarly on the 'sell side' if I clicked +25, An order would be submitted to 'market sell' bitcoin (which executes at the current price), and a 'stop market buy' order would be submitted which would buy back the same quantity of bitcoin if the price reached $5025.
37
38-------------------------------------------------
39
40Now, depending on which button I press (which means depending on how far away the 'stop market order' is from the current price at the time I click the button), a different order quantity will be submitted in the order.
41
42
43Another important thing, is that all the stop market orders MUST be submitted with the 'Close' execution instruction. You can find all the details about this and about everything on the Bitmex API explorer found here: https://www.bitmex.com/api/explorer/#!/Order/Order_new
44(just scroll down and look at 'Placing Orders' under the 'order' section).
45
46You can also find detailed information about what different order types mean etc here: https://www.bitmex.com/app/orderTypeFAQ
47
48Please ask if you need me to clarify anything, I'm probably not the best at making this super clear.