git clone https://github.com/pirate/cryto-trader.git
cd crypto-trader
pip3 install -r requirements.txt
cp secrets_default.py secrets.py
nano secrets.py # add key & secret here
import gemini_api as api
from symbols import Order, ETH, USD
current_price = USD(api.ticker('ethusd')['last'])
if current_price > USD(950.00):
buy_order = Order(api.new_order('buy', 'ethusd', ETH(0.001), current_price))
for event in order_events(buy_order.id):
print(event)
nano settings.py # Confirm your bot parameters
python3 ./example.py ethusd # Run the example theshold bot
secrets.py
settings.py
import gemini_api as api
from symbols import Order, USD, BTC, ETH
Currencies:
symbols.USD
: US Dollar USD(1.25)
symbols.BTC
: Bitcoin BTC(0.000001)
symbols.ETH
: Ethereum ETH(0.0001)
All currency symbols are based on the base type symbols.Currency
.
Order:All API functions that deal with order data like new_order
or order_status
return a raw json dict from Gemini with the schema below. It can be converted to a type-checked python object by using Order(order_json)
.
order_json = {
"order_id": "44375901",
"id": "44375901",
"symbol": "btcusd",
"exchange": "gemini",
"avg_execution_price": "400.00",
"side": "buy",
"type": "exchange limit",
"timestamp": "1494870642",
"timestampms": 1494870642156,
"is_live": False,
"is_cancelled": False,
"is_hidden": False,
"was_forced": False,
"executed_amount": "3",
"remaining_amount": "0",
"options": [],
"price": "400.00",
"original_amount": "3",
}
buy_order = Order(order_json)
order_id = buy_order.id # values can be accessed as properties
The Gemini REST API functions documentation can be found here:
https://docs.gemini.com/rest-api/#requests
api.ticker(symbol: str) -> dict
:
Get the ticker price info for a given symbol, e.g.:
ticker_info = api.ticker('ethusd')
# {'bid': '914.00', 'ask': '914.44', 'volume': {'ETH': '94530.56656129', 'USD': '83955829.9730076926', 'timestamp': 1515014100000}, 'last': '915.39'}
last_price = USD(ticker_info['last'])
api.new_order(side: str, symbol: str, amt: Currency, price: Currency) -> dict
:
Submit a new order to Gemini, e.g:
buy_order = Order(api.new_order('buy', 'ethusd', ETH(0.01), USD(965)))
sell_order = Order(api.new_order('sell', 'ethusd', ETH(0.01), USD(965)))
api.order_status(order_id: str) -> dict
:
Get the updated order info json from Gemini for a given order_id, e.g.:
buy_order = Order(api.order_status('44375901'))
print(buy_order.filled_amt)
The Gemini WebSocket API functions documentation can be found here:
https://docs.gemini.com/websocket-api/#websocket-request
api.order_events(order_id: str) -> Generator[dict]
:
Get a live-updating stream of order events via WebSocket e.g.:
for event in api.order_events('44375901'):
print(event)
example.py
is a simple example bot that randomly creates some initial buys, then sells the moment it makes a certain threshold percentage of profit.
It might profit if the market is trending upwards, but generally this strategy doesn't work if you want to make any real money. This code serves as a boilerplate example upon which to build other, more advanced bots.
This type of tight, risk-averse bot will only make small profits because it never waits for big upward trends to max out, it sells as soon as it goes in the green. The days where it starts in the red and stays there also end up sucking much of the profit away.
This library is built on Python 3.6 and uses MyPy for type checking.
Check MyPy types:
env MYPYPATH=./stubs mypy example.py
I'm not responsible for any money you lose from this code. The code is MIT Licensed.
Overview 因为Java的Crypto API始终有点难用,SpringSide在core module中的org.springside.modules.security.utils中提供了封装。 API的出入参数都是byte[]数组,需要配合Encodes来转换成Hex或Base64存储。 Digests消息摘要 去年一轮的密码被盗风波后,使用salt并迭代N次的sha-1式密码存储已经是
The crypto component hosts all the implementations of cryptographic primitives we use in Libra: hashing, signing, and key derivation/generation. The NextGen directory contains implementations of crypt
crypto 跟加密相关的一些功能,包括安全验证等。
crypto 包括 attr、ecdsa、utils 子包。 attr:chaincode 属性检查校验; ecdsa:ecdsa 加密算法接口,一些 hash 和签名校验方法。 utils:提供 aes、ecdsa、x509 等方法。
crypto模块的目的是为了提供通用的加密和哈希算法。用纯JavaScript代码实现这些功能不是不可能,但速度会非常慢。Nodejs用C/C++实现这些算法后,通过cypto这个模块暴露为JavaScript接口,这样用起来方便,运行速度也快。 MD5和SHA1 MD5是一种常用的哈希算法,用于给任意数据一个“签名”。这个签名通常用一个十六进制的字符串表示: const crypto = req
import "crypto" crypto包搜集了常用的密码(算法)常量。 type PublicKey type PublicKey interface{} 代表一个使用未指定算法的公钥。 type PrivateKey type PrivateKey interface{} 代表一个使用未指定算法的私钥。 type Hash type Hash uint Hash用来识别/标识另一个包里实现