pyircbot/docs/api/modules/stockplay.rst

135 lines
4.4 KiB
ReStructuredText
Raw Normal View History

2019-02-26 19:39:40 -08:00
:mod:`StockPlay` --- Stock-like trading game
============================================
2019-02-11 12:05:06 -08:00
This module provides a simulated stock trading game. Requires and api key from
https://www.alphavantage.co/ to fetch stock quotes.
Most commands require that the player login as described in the NickUser module.
Note that it is important to configure api limitations when configuring this module. The alphavantage.co api allows a
2019-02-26 19:39:40 -08:00
maximum of 5 requests per minute and 500 requests per day. For reasonable trading - that is, executing trades at the
current market price - we need to be able to lookup the price of any symbol at any time. Likewise, to generate reports
we need to keep the prices of all symbols somewhat up to date. This happens at some interval - see *bginterval*.
2019-02-11 12:05:06 -08:00
Considering the daily limit means, when evenly spread, we can sent a request *no more often* than 173 seconds:
2019-02-26 19:39:40 -08:00
`(24 * 60 * 60 / 500)` - and therefore, the value of *bginterval* must be some value larger than 173, as this value will
completely consume the daily limit.
2020-04-08 22:56:07 -07:00
When trading, the price of the traded symbol is allowed to be *trade_cache_seconds* seconds old before the API will be
used to fetch a more recent price. This value must be balanced against *bginterval* depending on your trade frequency
2019-02-26 19:39:40 -08:00
and variety.
Background or batch-style tasks that rely on symbol prices run afoul with the above constraints - but in a
2020-04-08 22:56:07 -07:00
magnified way as they rely on api-provided data to calculate player stats across many players at a time.
2019-02-11 12:05:06 -08:00
Commands
--------
.. cmdoption:: .buy <amount> <symbol>
2019-02-26 19:39:40 -08:00
Buy some number of the specified symbol such as ".buy 10 amd"
2019-02-11 12:05:06 -08:00
.. cmdoption:: .sell <amount> <symbol>
Sell similar to .buy
2019-02-26 19:39:40 -08:00
.. cmdoption:: .port [<player>] [<full>]
2019-02-11 12:05:06 -08:00
2019-02-26 19:39:40 -08:00
Get a report on the calling player's portfolio. Another player's name can be passed as an argument to retrieve
information about a player other than the calling player. Finally, the 'full' argument can be added to retrieve a
2020-04-08 22:56:07 -07:00
full listing of the player's holdings.
2019-02-11 12:05:06 -08:00
Config
------
.. code-block:: json
{
"startbalance": 10000,
"tradedelay": 0,
2020-04-08 22:56:07 -07:00
"trade_cache_seconds": 300,
"bginterval": 300,
2019-10-06 09:39:18 -07:00
"announce_trades": false,
2020-04-08 22:56:07 -07:00
"announce_channel": "#trades",
"providers": [
{
"provider": "iexcloud",
"apikey": "xxxxxxxxxxxxxxx"
},
{
"provider": "alphavantage",
"apikey": "xxxxxxxxxxxxxxx"
}
]
2019-02-11 12:05:06 -08:00
}
.. cmdoption:: startbalance
Number of dollars that players start with
.. cmdoption:: tradedelay
Delay in seconds between differing trades of the same symbol. Multiple buys OR multiple sells are allowed, but
not a mix.
NOT IMPLEMENTED
2020-04-08 22:56:07 -07:00
.. cmdoption:: providers
2019-02-11 12:05:06 -08:00
2020-04-08 22:56:07 -07:00
A list of providers to fetch stock data from
2019-02-11 12:05:06 -08:00
2020-04-08 22:56:07 -07:00
Supported providers:
2019-02-11 12:05:06 -08:00
2020-04-08 22:56:07 -07:00
* https://www.alphavantage.co/
* https://iexcloud.io/
2019-02-11 12:05:06 -08:00
2020-04-08 22:56:07 -07:00
.. cmdoption:: trade_cache_seconds
2019-02-11 12:05:06 -08:00
2020-04-08 22:56:07 -07:00
When performing a trade, how old of a cached symbol price is permitted before fetching from API.
2019-02-11 12:05:06 -08:00
2020-04-08 22:56:07 -07:00
Recommended ~30 minutes (1800)
2019-02-11 12:05:06 -08:00
.. cmdoption:: bginterval
Symbol prices are updated in the background. This is necessary because fetching a portfolio report may require
fetching many symbol prices. The alphavantage.co api allows only 5 calls per minute. Because of this limitation,
fetching a report would take multiple minutes with more than 5 symbols, which would not work.
For this reason, we update symbols at a low interval in the background. Every *bginterval* seconds, a task will be
2020-04-08 22:56:07 -07:00
started that updates the price of the oldest symbol.
2019-02-11 12:05:06 -08:00
Estimated 5 minute (300), but likely will need tuning depending on playerbase
.. cmdoption:: midnight_offset
Number of seconds **added** to the clock when calculating midnight.
At midnight, the bot logs all player balances for use in gain/loss over time calculations later on. If you want this
to happen at midnight system time, leave this at 0. Otherwise, it can be set to some number of seconds to e.g. to
compensate for time zones.
Default: 0
2019-10-06 09:39:18 -07:00
.. cmdoption:: announce_trades
Boolean option to announce all trades in a specific channel.
Default: false
.. cmdoption:: announce_channel
Channel name to announce all trades in.
Default: not set
2019-02-11 12:05:06 -08:00
Class Reference
---------------
.. automodule:: pyircbot.modules.StockPlay
:members:
:undoc-members:
:show-inheritance: