root/trac/hacks/marketplugin/0.9/doc/api-notes

Revision 44 (checked in by stevegt, 6 years ago)

checkpoint before merging Command back into Specialist, using context object instead of self to pass info to command methods

Line 
1 from trac.core import *
2
3
4
5 # XXX order matching is generic and can be done by generic auctioneer; order
6 # expiration, fills, and cancellation are specific to the contract
7 # type, and need to be handled by pit class;  make Pit a component;
8 # Book, Order, and Trade can be inherited from common
9 #
10 # how to abstract web vs xmlrpc:  different frontends, same
11 # backend
12
13
14
15 ------------ common.py ---------------
16 class Specialist(Component):
17
18     def order(self,req,size,symbol,currency,limit_price=None,stop_price=None):
19         """Create an order to buy or sell 'size' items.  Orders with
20         different denominations go into different books; we don't
21         perform automatic currency conversion.  Negative size means
22         sell, positive size means buy.  Limit_price == None and
23         stop_price == None means market order.  If single auction, use
24         sell for reserve price, buy for bids.  Returns order id."""
25
26     def cancel(self,req,order_id):
27         """Cancel an order.  Returns number of items not traded."""
28         # called by WikiMarket._cancel_order
29         # XXX replace with order.cancel()
30
31 ------------ wiki.py ---------------
32 from tracmarket.common import Specialist, Book, Order, Pit, Trade
33
34 class WikiSpecialist(Specialist):
35
36     def
37
38
39    
40 class ISpecialist(Interface):
41    
42
43     def match_symbol(req,symbol,currency):
44         """Returns True if this component can handle orders and market
45         data requests for symbol by current user, denominated in
46         currency."""
47
48     def order(req,size,symbol,currency,**kwargs):
49         """Create an order to buy or sell 'size' items.  Orders with
50         different denominations go into different books; we don't
51         perform automatic currency conversion.  Negative size means
52         sell, positive size means buy.  Kwargs are specific to the
53         type of instrument being traded.  Returns order object."""
54
55     def cancel(self,req,order_id):
56         """Cancel an order.  Returns order object -- check for
57         status."""
58
59     def open_orders(user):
60         """Return a list of open order objects for user."""
61         # called by WikiMarket._render_portfolio
62
63     def quote(symbol,currency,last_count=1):
64         """Return a consolidated quote containing order book and
65         'last_count' number of trades.  See common.py for definition of
66         Quote, Book, Order, and Trade objects."""
67
68     def _match_orders(symbol):
69         """Fill orders for symbol, posting deals to ILedger component.
70         Returns list of transaction IDs."""
71         # calls MarketDataConsumer.trade for each transaction
72         # XXX replace with book.match()
73
74
75
76 class ILedger(Interface):
77     """Extension point interface for components that can store
78     and report double-entry transactions for currency and inventory
79     items.
80     """
81    
82     def post(req, legs, memo=''):
83         """Record a transaction; 'legs' is a list of transaction legs
84         that have been created using mkleg().  Memo is a string.  Legs
85         can be mixed-currency.  Ensures debits and credits are
86         balanced within each currency.  Adds remote_user and
87         timestamp.  Returns integer transaction id."""
88         # called by Auctioneer._match_orders
89
90     def mkleg(entity, account, symbol, amount, serial=None):
91         """Convenience method to help create a proper transaction leg.
92         Does no storage.  Returns an object suitable for sending to
93         post().  Entity is an entity string.  Account is an account name
94         string.  Symbol is a string, and can be any symbol previously
95         defined by mksymbol().  Amount is a signed float, and will be
96         converted to debit or credit depending on normal balance of
97         account.  Serial is an optional string, and is used to
98         designate a unique instance of symbol to be transferred, e.g.
99         equipment, stock certificate, or banknote serial number.
100         Returns True if amount is available in account."""
101         # called by Auctioneer._match_orders
102
103     def mkentity(entity, description):
104         """Create a legal entity to group accounts under -- person,
105         corporation, etc.  Entity is a unique string.  Description is
106         a string."""
107         # called by WikiMarket._init_user
108
109     def chentity(entity, description=None):
110         """Change entity attributes."""
111
112     def mkaccount(entity, account, description, normal_balance):
113         """Create a currency or inventory account for entity.  Account
114         is an account name string.  Description is a string.
115         Normal_balance is a string: 'debit' or 'credit'."""
116         # called by WikiMarket._init_user
117
118     def chaccount(entity, account, description=None):
119         """Change account attributes."""
120
121     def mksymbol(symbol, description, divisible):
122         """Create a currency or inventory item symbol for later use in
123         transaction legs.  Symbol is a string (no spaces), and might
124         be a currency symbol, part number, or similar.  Description is
125         a string.  Divisible is a boolean; if false, it means that
126         amounts must be equal to a round integer; for example, a
127         dollar is divisible, but an inventory item might not be."""
128         # called by WikiMarket._init_version
129
130     def history(entity=None, account=None, symbol=None,
131             start_date=None, end_date=None, count=None):
132         """Return a list of transaction objects, sorted by
133         date."""
134         # called by WikiMarket._render_portfolio
135         # called by WikiMarket._timeline_item
136
137     def balance(entity, account, symbol, serial=None):
138         """Return quantity of symbol in account."""
139         # called by WikiMarket._render_portfolio
140
141
142 '''
143
144 class IQuartermaster(Interface):
145     """Extension point interface for components that can store
146     physical inventory location, manifests, ownership, and bills of
147     materials, and report movement and assembly progress.
148     """
149
150 class IPortfolio(Interface):
151     """Extension point interface for components that can provide a
152     consolidated view of currency, inventory, and orders for a given
153     user.
154     """
155
156
157 class OrderClerk(Interface):
158     """Accept, store, and report orders.  Orders are opaque objects;
159     the clerk knows nothing about their contents.  Does no matching,
160     accounting, valuations, or anything else which would require
161     looking inside the order."""
162
163     def post(req,order):
164         """Post order.  Returns order id string."""
165
166     def cancel(order_id):
167         """Cancel order.  Returns order object -- caller must inspect
168         the order object to see if the cancel was successful."""
169
170
171
172
173 '''
Note: See TracBrowser for help on using the browser.