0
$\begingroup$

An (forex) Order Book (OB) for a trading (forex) pair (e.g. XBT-USD) has ASK and BID rows. Each row has PRICE and VOLUME (at least). Each row represents an offer for selling or buying a maximum of VOLUME amount at PRICE.

Starting with a START-AMOUNT in BASE currency, how can I calculate exactly how many rows, starting from the 1st, i.e. the "cheaper-for-me"?

It is a simple calculation yet I am confused:

  1. as to whether I need to use the ASK or BID rows.
  2. as to what currency is VOLUME in.
  3. as to whether VOLUME in ASK and VOLUME in BID are in different currencies.
  4. Sometimes I will need to buy USD with XBT and so I will need the USD-XBT OB which does not exist (at least in kraken.com where I focus), can I use XBT-USD OB in order to buy XBT with USD? How?

Additionally, how should I use the "pair decimals" and "lot decimals" for the specific trading pair in order to do accurate, integer calculations? Note: terminology specifically refers to kraken.com's OB from the kraken.com's Asset-pair metadata but mainly I am asking: if someone tells us that in a specific book, currency (I guess BASE?) is expressed in 1 decimals and volume in 8, how can I do the calculations in integers to be accurate. (I realise that can be a question on its own and can ask it separately if people suggest it).

I am not sure if different forex platforms have different conventions, if they do then I am working with kraken.com . Here is some example data specific to kraken.com:

XBTUSD (get it with this API call from browser:

ASKS:
45867.70000,0.002
45870.90000,0.001
45873.80000,0.001
45875.90000,0.379
45880.70000,0.215
BIDS:
45867.60000,3.708
45867.30000,0.186
45866.80000,1.090
45865.90000,0.436
45865.50000,0.030

XBTUSD metadata (get it with this API call from browser):

...
pair_decimals:1,lot_decimals:8
...

p.s. I have very little experience with finance, more with programming and algorithms.

$\endgroup$

1 Answer 1

3
$\begingroup$
  1. This question is unclear to me, what is your goal?
  2. It's in BTC
  3. Both BTC
  4. You can increase your BTC position and decrease your USD position by buying the pair and decrease your BTC position and increase your USD position by selling the pair.

You can just multiply by the number of decimals to get ints?

$\endgroup$
6
  • $\begingroup$ Is it correct to say: (1) I want to sell 0.0025 BTC and get back USD. I go to the 1st row of BID (he has BTC and wants to sell it for USD). $\endgroup$
    – bliako
    Aug 17, 2021 at 19:31
  • $\begingroup$ You don't really 'go' there. If you send a market order Kraken will match your order against the best (best = cheapest when you buy, most expensive when you sell) available order you can see. $\endgroup$
    – Bob Jansen
    Aug 17, 2021 at 19:39
  • $\begingroup$ Yes, but I want to be able to calculate that in advance, before execution. Even if there is the risk of all changing in little time. Let's say I am doing some simulations. etc. $\endgroup$
    – bliako
    Aug 17, 2021 at 19:43
  • $\begingroup$ Is it correct to say: (case1) I want to sell 0.0025 BTC and get back USD. So, I go to the 1st row of BID (he has BTC and wants to sell it for USD) and I am covered. (case2) I want to sell 200 USD and get back BTC. I go to 1st row of ASK: 200/45867.7=.00436, Not enough that's only 45867.7*0.002=91.735USD, so I go to the 2nd row for 200-91.735=108.265USD. Similarly, not enough, she can supply only 45870.9*0.001=45.8709USD, I need 108.265-45.8709=62.3941USD. So on to the 3rd ASK row, which is not enough and on to the 4th row which covers me. Above calcs can't be done as integers alone! $\endgroup$
    – bliako
    Aug 17, 2021 at 19:43
  • $\begingroup$ Your method looks correct to and please add additional clarifications to your question. I don't think anybody is bothering to do this in integers for their trading system, only for bookkeeping. For bookkeeping you just use the executions you get from Kraken or dive into the documentation on how Kraken exactly handles rounding. $\endgroup$
    – Bob Jansen
    Aug 17, 2021 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.