Embedded Python Real-Time FrameWork : API  Build 20250616.1
 All Classes Namespaces Files Functions Variables Pages
pyRT.crypto.Algo.SpreadMaker Namespace Reference

Logic:

  1. We have 2 related coins A and B; Order doesn't matter
  2. You want a Cockpit-adjustable spread of 10:
  3. A is 11 bid at 12; B is 21 bid at 22
  4. Put BUY order on A for 11; SELL on B for 22; Spread is 11
More...

Classes

class  Context
 Current Config, controlled by Cockpit. More...
 
class  Manager
 A little How-do-you-do. More...
 
class  Record
 Real-time Record. More...
 
class  Spread
 Spread between 2 Records. More...
 

Functions

def OnAlgoStart
 Called from AlgoServer Reactor : Algo Start. More...
 
def OnAlgoStop
 Called from AlgoServer Reactor : Stop Algo. More...
 
def OnConnectOMS
 Called from AlgoServer Reactor : OMS Connection Change (UP / DOWN) More...
 
def OnEngineLoad
 Called from AlgoServer Reactor : Engine Loaded (server start) More...
 
def OnEngineUnload
 Called from AlgoServer Reactor : Unload Engine (server stop) More...
 
def OnExchange
 Called from AlgoServer Reactor : OMS Exchange Status Change (UP / DOWN) More...
 
def OnHttpGet
 Called from AlgoServer Reactor : Http GET. More...
 
def OnOMSMsg
 Called from AlgoServer Reactor : OMS Message Received (ExecRpt) More...
 

Detailed Description

Logic:

  1. We have 2 related coins A and B; Order doesn't matter
  2. You want a Cockpit-adjustable spread of 10:
  3. A is 11 bid at 12; B is 21 bid at 22
  4. Put BUY order on A for 11; SELL on B for 22; Spread is 11

Questions:

  1. A jumps from 11 bid at 12 to 15 bid at 16; B doesn't move. What do i do?
  2. No one moves and my 11 BID on A gets hit; What do I do? SELL A at 12?
  3. A is 15 bid at 16; B is 21 bid at 22; Spread from Cockpit is 10
    • Do I BUY A at 13 and SELL B at 23? BUY A at 14 and SELL B at 24?

Answers:

  1. When the abs( MID.A, MID.B ) is < Cockpit, all orders are cancelled:
    • Becomes undoable when Spread too low
    • MID.X = math.sqrt( BID.X * ASK.X )
    • So 11.5 vs 21.5 + 10 15.5 vs 21.5 doesnt work
  2. We will have a box that if checked changes the second part of the order into OCO (Order Cancels Order) AS BOTH OFFERS ARE CONTINUOUSLY MOVED TO BEST OFFER.
    • If box isnt checked then you are best offer on the second product until filled.
  3. Do not post BUY / SELL : Spread too low; Algo not doable

More Logic:

  1. Automatic that after we get an entry fill with
    • Size that the algo uses that figure, or
    • A total value of position ) to exit the trade.
  2. Also if we enter in product a we can exit in both products A and B
    • This assumes we are not trying to sell bitcoins we don't have.
  3. Lastly we have constraints that prevent trading at inopportune times.
    • Was the High or Low of the last hour in the last X minutes ? If so do not trade.
    • Was the mileage of the last x minutes < x?
    • Was the range of the last x minutes < x
  4. Then have absolutes for trading.
    • If the market is moving x dollars in y minutes then trade with trailing ..

Function Documentation

def pyRT.crypto.Algo.SpreadMaker.OnAlgoStart (   cxt)

Called from AlgoServer Reactor : Algo Start.

Parameters
cxt- Opaque Context from AlgoServer Reactor
def pyRT.crypto.Algo.SpreadMaker.OnAlgoStop (   cxt)

Called from AlgoServer Reactor : Stop Algo.

Parameters
cxt- Opaque Context from AlgoServer Reactor
def pyRT.crypto.Algo.SpreadMaker.OnConnectOMS (   cxt,
  bUP,
  msg 
)

Called from AlgoServer Reactor : OMS Connection Change (UP / DOWN)

Parameters
cxt- Opaque Context from AlgoServer Reactor
bUP- True if UP; False if DOWN
msg- Message
def pyRT.crypto.Algo.SpreadMaker.OnEngineLoad (   cxt)

Called from AlgoServer Reactor : Engine Loaded (server start)

We Create the Manager

Parameters
cxt- Opaque Context from AlgoServer Reactor
def pyRT.crypto.Algo.SpreadMaker.OnEngineUnload (   cxt)

Called from AlgoServer Reactor : Unload Engine (server stop)

We Stop the Manager

Parameters
cxt- Opaque Context from AlgoServer Reactor
See Also
Manager.Stop()
def pyRT.crypto.Algo.SpreadMaker.OnExchange (   cxt,
  exch,
  bUP,
  ddb 
)

Called from AlgoServer Reactor : OMS Exchange Status Change (UP / DOWN)

Parameters
cxt- Opaque Context from AlgoServer Reactor
exch- Exchange Name
bUP- True if UP; False if DOWN
ddb- Dict received
def pyRT.crypto.Algo.SpreadMaker.OnHttpGet (   cxt,
  qry 
)

Called from AlgoServer Reactor : Http GET.

Parameters
cxt- Opaque Context from AlgoServer Reactor
qry- Http Query (JSON)
Returns
Http Response (JSON)
def pyRT.crypto.Algo.SpreadMaker.OnOMSMsg (   cxt,
  ddb 
)

Called from AlgoServer Reactor : OMS Message Received (ExecRpt)

Parameters
cxt- Opaque Context from AlgoServer Reactor
ddb- Dict received