狠狠撸

狠狠撸Share a Scribd company logo
Trading at market
speed
with the latest
KAFKA features
??igo González Ponce
@exocert
? Didn’t like databases, stats
? Very critical about so-called ‘big-data’
stacks. Tell me why later.
? Sysadmin for more than 20 years.
? Data & ML Product @One2One
? Data Science Awards 2016: Best data
Engineer.??igo González
@exocert
$> whoami
Disclaimer
?VERY HIGH RISK
? Don’t risk money you cannot
afford to loose.
? You’ll be trading high volatility
markets. Easily manipulated, too.
? Software bugs might make you
loose money.
6/6Inversión de muy alto riesgo.
Ud. Puede perder hasta la camisa por un
error en su código o por situaciones que
están fuera de su control.
Tenga miedito. Es más seguro.
This talk reflect my views and opinion, not my employer’s.
Automated trading (late 80’s)
The ability of trading in a market without continuous human
intervention.
You need:
Something that watches the market
Something able to execute orders based on your instructions.
High Frecuency trading
Automated trading
At milisecond speed
Able to trade multiple exchanges at once
*VERY* expensive to do:
Software licenses for CEPs started at $10,000
for cpu core.
Now it’s different
HOW to make money
trading cryptocurrencies?
(if you don’t have too many bugs)
Big data spain 2017 -  I?igo Gonzalez: Trading at market speed with the latest kafka features
Meet the
orderbook
The orderbook
The
orderbook is a
queue
Think about a queue in a staircase.
Every step is a bid/ask Price
On every step you can have one or more orders in
a queue.
ORDERS are executed on a FIRST-COME-FIRST-
SERVE basis.
Orderbook
and Liquidity
There is a STRONG incentive to be early in the
orderbook…
… because you’re the first in the line to execute
your orders.
BTW: Some markets have 0% trading fee for
market MAKERS.
Strategy
?Be early in the orderbook: send
orders ASAP.
?Be a Market maker (low/0% fees)
HOW?
Kafka
Kafka streams
KSQL
Big data spain 2017 -  I?igo Gonzalez: Trading at market speed with the latest kafka features
Big data spain 2017 -  I?igo Gonzalez: Trading at market speed with the latest kafka features
Big data spain 2017 -  I?igo Gonzalez: Trading at market speed with the latest kafka features
Big data spain 2017 -  I?igo Gonzalez: Trading at market speed with the latest kafka features
Big data spain 2017 -  I?igo Gonzalez: Trading at market speed with the latest kafka features
Big data spain 2017 -  I?igo Gonzalez: Trading at market speed with the latest kafka features
Big data spain 2017 -  I?igo Gonzalez: Trading at market speed with the latest kafka features
Use case :
Shotgun order
Big data spain 2017 -  I?igo Gonzalez: Trading at market speed with the latest kafka features
Orderbook inside a Kafka topic
=
Orderbook from topic to stream
CHANGE DATATYPES (tricky with arrays)
select price, sum(amount) from ob_USDBTC group by price ;
Finally see if the orderbook spot is occupied
? Make a Price_Candidates topics
? Put there the prices you might want to trade.
? I mean, the prices your _automated_ strategy believes it’s ok to trade.
? Join that with the data values you have in the orderbook.
? Those are the prices you DO NOT want to trade
? Why? because someone else has an order there.
create table xUSDBTC (price varchar, amount double, count double) with
(KEY='price', kafka_topic=‘ob_USDBTC', value_format='json’);
Create stream do_not_trade_here as 
select x.Price from xUSDBTC x 
left join Price_candidates pc on x.Price = pc.Price ;
The big picture:
What we need in
the real world?
Get
market
data
Store
market
data
Replay
market
data
Test
strategy
Watch
fror entry
signals
Watch for
exit
signals
Execute
trades
Manage
Risk
Predict
orderbok
changes
Thanks! ?Gracias!
Danke! Obrigado 谢谢
I?igo Gonzalez
@exocert

More Related Content

Big data spain 2017 - I?igo Gonzalez: Trading at market speed with the latest kafka features

  • 1. Trading at market speed with the latest KAFKA features ??igo González Ponce @exocert
  • 2. ? Didn’t like databases, stats ? Very critical about so-called ‘big-data’ stacks. Tell me why later. ? Sysadmin for more than 20 years. ? Data & ML Product @One2One ? Data Science Awards 2016: Best data Engineer.??igo González @exocert $> whoami
  • 3. Disclaimer ?VERY HIGH RISK ? Don’t risk money you cannot afford to loose. ? You’ll be trading high volatility markets. Easily manipulated, too. ? Software bugs might make you loose money. 6/6Inversión de muy alto riesgo. Ud. Puede perder hasta la camisa por un error en su código o por situaciones que están fuera de su control. Tenga miedito. Es más seguro. This talk reflect my views and opinion, not my employer’s.
  • 4. Automated trading (late 80’s) The ability of trading in a market without continuous human intervention. You need: Something that watches the market Something able to execute orders based on your instructions.
  • 5. High Frecuency trading Automated trading At milisecond speed Able to trade multiple exchanges at once *VERY* expensive to do: Software licenses for CEPs started at $10,000 for cpu core. Now it’s different
  • 6. HOW to make money trading cryptocurrencies? (if you don’t have too many bugs)
  • 10. The orderbook is a queue Think about a queue in a staircase. Every step is a bid/ask Price On every step you can have one or more orders in a queue. ORDERS are executed on a FIRST-COME-FIRST- SERVE basis.
  • 11. Orderbook and Liquidity There is a STRONG incentive to be early in the orderbook… … because you’re the first in the line to execute your orders. BTW: Some markets have 0% trading fee for market MAKERS.
  • 12. Strategy ?Be early in the orderbook: send orders ASAP. ?Be a Market maker (low/0% fees)
  • 13. HOW?
  • 24. Orderbook inside a Kafka topic =
  • 25. Orderbook from topic to stream
  • 26. CHANGE DATATYPES (tricky with arrays)
  • 27. select price, sum(amount) from ob_USDBTC group by price ;
  • 28. Finally see if the orderbook spot is occupied ? Make a Price_Candidates topics ? Put there the prices you might want to trade. ? I mean, the prices your _automated_ strategy believes it’s ok to trade. ? Join that with the data values you have in the orderbook. ? Those are the prices you DO NOT want to trade ? Why? because someone else has an order there. create table xUSDBTC (price varchar, amount double, count double) with (KEY='price', kafka_topic=‘ob_USDBTC', value_format='json’); Create stream do_not_trade_here as select x.Price from xUSDBTC x left join Price_candidates pc on x.Price = pc.Price ;
  • 29. The big picture: What we need in the real world? Get market data Store market data Replay market data Test strategy Watch fror entry signals Watch for exit signals Execute trades Manage Risk Predict orderbok changes
  • 30. Thanks! ?Gracias! Danke! Obrigado 谢谢 I?igo Gonzalez @exocert