0

In a table I try to bring together the rows that have the same price by adding the quantities for an order book all_order_ask:([]ask:();ask_qty:();exchange_name:()) Keep the same ask but when it's the same price add the quantities

Nathan
  • 91
  • 6
  • 2
    The simple approach is something like `select sum ask_qty by ask from all_order_ask` but this leaves a lot of questions: how do you want the resulting table to be ordered? What do you plan to do when there's more than one exchange quoting at a given price, show the first, last, all of them? Assuming your ask prices are floats you will have to manage the fact that there will be float precision issues so two floats that appear to be the "same" may not be the same and so they won't group properly. – terrylynch Jul 25 '22 at 12:56
  • Do you know how can i combine symbol Like if exchange_name:() is Ftx and the second Kraken When i combine them i ll get `FtxKraken a new symbol Thks – Nathan Aug 01 '22 at 11:35

1 Answers1

1

To answer your followup question: combining the exchange names would be like this:

select sum ask_qty,raze string exchange_name by ask from all_order_ask

assuming that exchange_name values are symbols...if they're already strings then you only need to raze.

I'll highlight again some caveats from my earlier comment:

this leaves a lot of questions: how do you want the resulting table to be ordered? Assuming your ask prices are floats you will have to manage the fact that there will be float precision issues so two floats that appear to be the "same" may not be the same and so they won't group properly
terrylynch
  • 11,844
  • 13
  • 21
  • Thanks You for all A last question about this subject , i want to do a if like If ftx and ftx to dont get "FtxFtx" I am starting on kdb Thanks for everythings – Nathan Aug 01 '22 at 13:12
  • 1
    You could use `distinct` to get only the unique ones. So `select sum ask_qty,raze string distinct exchange_name by ask from all_order_ask` – terrylynch Aug 01 '22 at 15:21
  • The fact is that command return a Dict and then i can't combine ask and bid in the same table Do you Know a solution thanks – Nathan Aug 02 '22 at 12:06
  • It's a keyed table (which is implemented like a dictionary and has the same datatype). You can unkey the keyed table using `0!select .....` – terrylynch Aug 02 '22 at 13:51
  • Is there a way to sort by ask while doing this operation – Nathan Sep 08 '22 at 13:34
  • I don't know why but it messed me up my table – Nathan Sep 08 '22 at 13:35