0%

比特币介绍

比特币(BitCoin)的概念最初由中本聪在2009年提出,根据中本聪的思路设计发布的开源软件以及建构其上的P2P网络。比特币是一种P2P形式的数字货币。点对点的传输意味着一个去中心化的支付系统。

货币特征

  • 去中心化:比特币是第一种分布式的虚拟货币,整个网络由用户构成,没有中央银行。去中心化是比特币安全与自由的保证 。
  • 全世界流通:比特币可以在任意一台接入互联网的电脑上管理。不管身处何方,任何人都可以挖掘、购买、出售或收取比特币。
  • 专属所有权:操控比特币需要私钥,它可以被隔离保存在任何存储介质。除了用户自己之外无人可以获取。
  • 低交易费用:可以免费汇出比特币,但最终对每笔交易将收取约1比特分的交易费以确保交易更快执行。
  • 无隐藏成本:作为由A到B的支付手段,比特币没有繁琐的额度与手续限制。知道对方比特币地址就可以进行支付。
  • 跨平台挖掘:用户可以在众多平台上发掘不同硬件的计算能力。

比特币与分叉币比较

什么是挖矿

比特币是怎么产出的?

首先我们来了解一下“区块链”,比特币的核心原理是“区块链”,每一个区块对应一个帐单,将所有的区块链接起来就是区块链,任何交易信息和转账记录都记录在区块链中。要注意的是区块链存在于整个互联网中,所以任何比特币持有者都不担心比特币遭受损失。

每隔一个时间点,比特币系统会在系统节点上生成一个随机代码,互联网中的所有计算机都可以去寻找此代码,谁找到此代码,就会产生一个区块,随即得到一个比特币,这个过程就是人们常说的挖矿。

挖矿设备介绍

现在市面上起码有几百种加密货币,主流的可以流通交易的也有不下20种。这么多的加密货币虽然都基于区块链技术,但不管是为了实现某些功能,还是为了形成差异,都会有所不同,从而导致挖不同的币使用的矿机也有所不同。通常来说,一台矿机只能挖一种或几种币,所以要挖什么比就要买什么型号的矿机。当然也存在全能选手,比如电脑就是,只是好多币种用电脑(CPU+显卡)挖的效率太低,无法盈利。

矿机可以有多种分类方式,硬件上可以分为ASIC矿机、GPU矿机、FPGA矿机,以及玩客云那类CDN矿机等等。按照所有权划分,可以分为本地矿机和云矿机。

首先,比特币(BTC)、以太坊(ETH)、比特币现金(BCH)、莱特币(LTC)、达世币(DASH)等主流币种,普遍采用PoW共识机制,挖矿就是通过贡献算力来维护网络安全、稳定的运行,并由此获得奖励币,所以都需要性能尽可能强大的矿机。但针对不同币种的算法,又细分出两种不同的矿机:ASIC矿机与GPU矿机。

中本聪打造比特币的时候,希望比特币是一个去中心化的货币,不仅使用、交易如此,挖矿也应该如此。但是事与愿违,随着比特币等加密货币的价值越来越高,挖矿成为了一个产业,竞争越来越激烈,对挖矿算力的追求越来越高,所以从普通电脑挖矿,进化出了ASIC矿机与GPU矿机。

主流矿机比较

目前市场上最热门的矿机是蚂蚁矿机S9,具体配置如下

矿池的选择

矿池的选择主要考虑以下两个因素:

  • 分配模式
  • 手续费

分配模式说明:

  1. Slush方式

Slush矿池基于积分制,较老的shares将比新的shares拥有更低的权重,以减少一轮中切换矿池的投机分子。
2. Pay-Per-Share方式

该方式为立即为每一个share支付报酬。该支出来源于矿池现有的比特币资金,因此可以立即取现,而不用等待区块生成完毕或者确认。这样可以避免矿池运营者幕后操纵。这中方法减少了矿工的风险,但将风险转移给了矿池的运营者。运营者可以收取手续费来弥补这些风险可能造成的损失
3. Luke-Jr方式

该方式借用了其他方式的长处,如Slush方式一样,矿工需要提供工作证明来获得shares,如puddinpop方式一样,当区块生成时马上进行支付。但是不象之前的方式,针对一个区块的shares,会被再次利用于生成下一个区块。为了区分一下参与矿工的交易传输费用,只有当矿工的余额超过1BTC时才进行支付。如果没有达到1BTC,那么将在下一个区块生成时进行累计。如果矿工在一周内没有提供一个share,那么矿池会将剩下的余额进行支付,不管余额是多少。
4. Triplemining方式

该方式是将一些中等大小矿池的计算力合并起来,然后将获得奖励的1%按照各个矿池计算力的比例分发给矿池运营者。
5. P2Pool方式

P2Pool的挖矿节点工作在类似比特币区块链的一种shares链上。由于没有中心,所以也不会受到DoS攻击。和其他现有的矿池技术都不一样—每个节点工作的区块,都包括支付给前期shares的所有者以及该节点自己的比特币。99%的奖励(注:50BTC+交易费用)会平均分给矿工,另外0.5%会奖励给生成区块的人。
6. Puddinpop方式

一种使用“元哈希”技术的方式,使用特定的puddinpop挖矿软件,现在没有矿池用这种方式

注意:

一个share(注:贡献/股份)为一个矿池给客户端的一个合法的工作证明,这也同时是用来生成区块的工作证明,但是没有这么复杂,只需要很少的时间就能达到一个share。

收益预测

蚂蚁矿机单机价格18000元,功率为1350w - 1512w,电费按0.3元/度计算,收益情况如下

计算方式1

矿池算力排名
https://btc.com/stats/pool?pool_mode=day

每十分钟产生一个区块,每个区块12.5个比特币,每天全球产生12.5*24*6=1800BTC

s9算力13.5T,当前全网算力22.52EH/s,1E=1024P,1P=1024T,1T=1024G,一台s9一天产生的比特币是[13.5/(22.5210241024)]*1800≈.001029054BTC

总收入

13.5/(22.52*1024*1024) * 1800 * 65000 * 365 = 24414.295 元

每天耗电36度,每年13140度电,电费约为 1.5*24*0.3 * 365 = 3942 元

总利润为 24414.295 - 3942 = 20472.295 元

计算方式2

挖矿算器

https://btc.com/tools/mining-calculator

参考

http://www.kuangjijia.com/category/492.html
https://shop.bitmain.com/productDetail.htm?pid=00020180205094056650FrOW7847062D
https://www.zhihu.com/question/20792042

挖掘机哪家强?主流矿机比拼,蚂蚁矿机领先
http://www.sohu.com/a/155209866_114877
彩云评测:比特大陆蚂蚁S9比特币挖矿机
https://www.cybtc.com/article-2338-1.html
一个挖矿者血本无归的教训总结
http://www.hnr.cn/finance/zt/b/df/201706/t20170626_2980454.html

Python量化交易实战
欢迎您扫码订阅我的微信公众号: pyquant

我的微信公众号:pyquant

区块链的价值是共识

共识算法其实分很多种,目前最常提到的,比特币和以太坊所用到的,是叫做POW的共识算法,基于工作量证明的一种信息保障的算法。

POW共识算法,效率低下

POW目前的局限是出块速度被限定了,比特币差不多10分钟出一个区块,所有交易均需要记录在区块内,所以这样也就限制了交易频率,由于一个区块只有1M,可以承载的交易信息是有限的,所以目前比特币的交易频次被限定在非常低的量级上,差不多一秒才可以支撑不到10个交易。

升级方案:

  • 提升出块大小,比特现金把区块大小提升到了8M区块
  • 提升出块速度,降低出块奖励
  • 区块分片化存储的方案,现在比特币这样的区块链虽然是去中心化分布式存储,但每个全节点存储的是记录全集,也就是规模总量和本地查询明显是受到制约的。
  • 闪电网络是指将小额的,频繁交易,先通过一些分支节点进行储存和计算,并在一定时间内整合归并到主链

以太坊是平台

以太坊可以认为是区块链的第二代平台,因为对智能合约的支持,以太坊的应用想象空间增加了很多,而且其出块效率也明显高于比特币。交易结算周期也明显有了更好的表现。

以太坊是一个平台,上面跑了几千种虚拟货币,其中之一是以太坊自身的代币。而这个平台不但可以发布货币,还可以发布应用,智能合约的应用

智能合约

在区块中传递的合约,或者说传递的字符串,不是单纯的字符串和信息,而是一段可执行的脚本,比如说,有触发条件,有交互能力。

比特币是资产还是货币?

硬分叉

硬分叉,是分叉方约定,在某个区块节点开始,启用新的系统架构继续前进,不再和主链保持一致,但同时也继承了该节点之前的所有区块。在这个节点之后,双方各自挖各自的矿,各自爆各自的块,各自走各自的路

其实硬分叉不需要主链允许或通过,任何人都可以发起硬分叉,都可以基于自己的理解和判断发起一个新的分支,但对于信仰者来说,每个分叉都是对共识的撕裂,是在破坏共识。共识算法本身就是防范故障或者恶意分叉的,而人为强行分叉显然是算法所不能处理的。

EOS

99%的ICO是基于以太坊的,其实EOS的ICO,目前而言,也是基于以太坊的。但EOS要做的并不只是躺在以太坊身上薅点韭菜的钱。他们的野心还是蛮大的,按照白皮书的说法,感觉是想成为第三代区块链的平台,

零知识证明

可以有效保护交易隐私,隐藏交易来源并防止追溯,同时也能保证交易是安全的,因为任何试图修改交易的行为都无法通过验证。

信息安全

第一,算力劫持,其实共识算法并非是完美无瑕的,其存在的假设前提是,大部分节点是正确的,可信任的。所以不同的共识算法,理论上都存在一些风险,就是如果坏人掌握了足够多的节点。比如说基于POW共识的比特币,如果一家矿场或者矿池掌握了超过全网51%的算力,理论上可以劫持所有交易,改变交易数据。而基于DPOS的需要保障2/3的节点是可靠的,否则也存在强行分叉或者干扰主链的风险。

第二,重放攻击,这是硬分叉首先需要小心解决的问题,如果系统设计不周全,会导致在分叉上执行的交易被复制到主链,从而带来币拥有者未确认的交易发生,造成损失。所以很多交易所和钱包服务商,不敢去支持名目繁多的分叉币,也是担心由此带来风险。

第三,关于私钥安全,由于新入场的区块链玩家很多,实际上很多人并不明白区块链私钥的意义和价值,会出现这样的情况,认为在交易所,或者钱包的账号和密码是最关键的,保护好了账号密码就万无一失,但糊里糊涂就被人钓鱼,把私钥拱手送出。

第四,交易平台和钱包工具的安全,这在历史上出现过很多起,最近也出现过,一些交易所失窃,或者钱包工具失窃,导致用户的币丢失,而且基本上全都无可挽回。

第五,智能合约的安全,有一个基于区块链众筹的风险投资基金,叫做the DAO,这个众筹计划是用一段智能合约代码约束的,这段代码被发布到了网上,并募集了超过数亿美元的资金,看上去是一个非常不错的故事,但很遗憾,这段代码中有一个安全风险,结果,黑客通过代码漏洞轻松劫持了超过5500万美元

回顾

1、共识算法是区块链的核心技术;
2、当前的共识算法存在一些问题,是区块链应用场景普及所需要面对的重大问题。
3、从比特币到以太坊,实际上区块链的技术方案正在演进,但谁是第三代,目前还有待争议。
4、智能合约是区块链应用场景扩展最具有想象力的地方,不过受限于基础架构和算力问题,目前智能合约还很难做出复杂应用,图灵完备在当前阶段尚不具备应用意义。
5、零知识证明还没有全面应用起来,但这个逻辑被认可度是非常高的。
6、共识算法,零知识证明,都是人类数学和信息科学的重大进步,并不单纯是为区块链服务的,更不是为发币的骗子们服务的。
8、信息安全在区块链投资中的重要性非常高,而目前绝大部分新入场的用户对此并没有足够清醒的认识,整个区块链产业出现的严重安全事故已经很多起了,入局者希望能引以为诫。

代币

现在主要有两种模式,一种是跟法币绑定的,一个很神奇的东西,叫做USDT,是香港一家公司发行的,他宣称 ,每发行一个USDT,背后都有1美元的储蓄作为担保,并且有多个商业银行担保。也就是和美元1:1购买,1:1赎回,那么他的商业模式是什么呢?赎回的时候收取1%的手续费。

Python量化交易实战
欢迎您扫码订阅我的微信公众号: pyquant

安装gitlab-runner

https://docs.gitlab.com/runner/install/index.html

国内镜像地址

https://mirrors.tuna.tsinghua.edu.cn/help/gitlab-ci-multi-runner/

注册Runner

https://docs.gitlab.com/runner/register/

步骤

注意:用户为root用户

root@sw:/home/sw# gitlab-runner register xuqi
Running in system-mode.

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://10.168.2.114/

Please enter the gitlab-ci token for this runner:

输入gitlab的token

Please enter the gitlab-ci description for this runner:
[sw]: xuqi
Please enter the gitlab-ci tags for this runner (comma separated):

Whether to lock the Runner to current project [true/false]:
[true]: true
Registering runner... succeeded                     runner=wzb81TcG
Please enter the executor: docker, parallels, shell, virtualbox, docker+machine, kubernetes, docker-ssh, ssh, docker-ssh+machine:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

注意: token位置在http://localhost/xxx/xxx/settings/ci_cd 页面里的Runners settings里

如何删除在gitlab中不再使用的runner

gitlab-runner verify --delete

关于executors的选择

https://docs.gitlab.com/runner/executors/README.html

如何编写.gitlab-ci.yml

官方文档

https://gitlab.com/help/ci/yaml/README.md

stages

stages用来定义可以被job调用的stages。stages的规范允许有灵活的多级pipelines。

Jobs

.gitlab-ci.yml允许指定无限量jobs。每个jobs必须有一个唯一的名字,而且不能是上面提到的关键字。job由一列参数来定义jobs的行为

demo

image: python:3.6.1

before_script:
   - export BIZDATE=`date +%Y%m%d`
   - export PROJECT_NAME=$CI_PROJECT_NAME
   - export VERSION=$CI_COMMIT_TAG-$CI_COMMIT_SHA

stages:
  - build
  - package
  - deploy

build:
  stage: build
  script: 
    - /home/gitlab-runner/anaconda3/bin/python3.6 -O -m compileall .
    - find . -name '*.pyc' -exec rename 's/.cpython-36.opt-1//' {} \;
    - find . -name '*.pyc' -execdir mv {} .. \;
    - find . -name '*.py' -type f -print -exec rm {} \;
    - find . -name '__pycache__' -exec rm -rf {} \;
    
package:
  stage: package
  script:
    - rm -rf .git
    - rm -rf .gitlab-ci.yml
    - $(tar -zcf ../deploy-$VERSION.tar.gz .)
    - $(mkdir -p /home/gitlab-runner/backup/$PROJECT_NAME/$BIZDATE)
    - $(cp ../deploy-$VERSION.tar.gz /home/gitlab-runner/backup/$PROJECT_NAME/$BIZDATE/)
    - $(rm -rf ../deploy-$VERSION.tar.gz)
    - rm -rf .

deploy:
  stage: deploy
  script:
    - echo 'deploy'

服务器版本,使用脚本编写如上内容

before_script:
   - export PROJECT_NAME=$CI_PROJECT_NAME
   - export VERSION=$CI_COMMIT_TAG-$CI_COMMIT_SHA
   - export WORK_DIR=`pwd`
   - export HOST=''

stages:
  - deploy

deploy:
  stage: deploy
  only:
    - /^release-.*$/
  script:
    - ~/script/deploy.sh $WORK_DIR $HOST

deploy.sh 脚本内容

workdir=$1
BIZDATE=`date +%Y%m%d`
echo $workdir
cd $workdir
rm -rf .git
rm -rf .gitlab-ci.yml
tar -zcf ../bak-$VERSION.tar.gz .
mkdir -p /home/gitlab-runner/backup/$PROJECT_NAME/$BIZDATE
cp ../bak-$VERSION.tar.gz /home/gitlab-runner/backup/$PROJECT_NAME/$BIZDATE/
rm -rf ../bak-$VERSION.tar.gz
/home/gitlab-runner/anaconda3/bin/python3.6 -O -m compileall .
find . -name '*.pyc' -exec rename 's/.cpython-36.opt-1//' {} \;
find . -name '*.pyc' -execdir mv {} .. \;
find . -name '*.py' -type f -print -exec rm {} \;
find . -name '__pycache__' -exec rm -rf {} \;
#rm -rf $1/*

tar -zcf ../deploy-$VERSION.tar.gz .
for line in `cat hosts`
do
   pem=`echo $line | cut -d \: -f 1`
   host=`echo $line | cut -d \: -f 2`
   echo $pem
   echo $host
   scp -i ~/keys/$pem ../deploy-$VERSION.tar.gz ubuntu@$host:/home/ubuntu/
done
echo 'finish'

参考

https://scarletsky.github.io/2016/07/29/use-gitlab-ci-for-continuous-integration/

https://segmentfault.com/a/1190000010442764

Python量化交易实战
欢迎您扫码订阅我的微信公众号: pyquant

Filled相关Order类型:

  1. Market Order

    • 当订单规模很大时,broker可能会将订单拆分成多个规模较小的订单,导致以不同价格成交不同订单
    • bid-ask spreads 较大时风险较大
  2. Limit Order

    • Some brokers may charge different commissions between Market & Limit Orders.
  3. Market On Close(MOC) Order

    A Market-on-Close (MOC) order is a market order that is submitted to execute as close to the closing price as possible.

  4. Limit On Close(LOC) Order

    A Limit-on-close (LOC) order will be submitted at the close and will execute if the closing price is at or better than the submitted limit price.

  5. Market On Open(MOO) Order

    A Market-on-Open (MOO) order combines a market order with the OPG time in force to create an order that is automatically submitted at the market’s open and fills at the market price.

  6. Limit On Open(LOO) Order

    A Limit-on-Open (LOO) order combines a limit order with the OPG time in force to create an order that is submitted at the market’s open, and that will only execute at the specified limit price or better. Orders are filled in accordance with specific exchange rules.

  7. Martet To Limit(MTL) Order

    A Market-to-Limit (MTL) order is submitted as a market order to execute at the current best market price. If the order is only partially filled, the remainder of the order is canceled and re-submitted as a limit order with the limit price equal to the price at which the filled portion of the order executed.

  8. Iceberg/Reserve Orders

    提交大额股票、权证、期货和期权定单的投资者可能希望取消其定单的所有欲交易量以避免其他市场参与者可以预见并采取相应行动。冰山/保留属性(可在显示尺寸区域设置)可以帮助投资者以增量方式提交提交大宗定单,同时又只公开显示整体定单尺寸的某一特定部分。客户可以通过设置布局管理者或选择相应的区域向TWS的交易页面添加显示尺寸区域,输入定单时客户可以填充此项以显示整个定单的一部分。

    Investors submitting large volume orders for stocks, warrants, futures and options may wish to conceal the full size of their order to avoid anticipatory action from other market participants. The Iceberg/Reserve attribute, applied through the Display Size field, provides a way to submit large volume orders to the market in increments while publicly displaying only a specified portion of the total order size. The Display Size field can be added to a trading page within TWS by configuring the Layout Manager and selecting the appropriate field, which can be user-populated at the time of order input, to display just a fraction of the entire order.

TIMING / DURATION:

档提交一个订单后,当我们希望订单在指定时间内有效或订单的持续时间,可以使用如下订单类型

  1. Day Order

    A day order is an order to buy or sell a security that automatically expires if not executed on the day the order was placed. If it is not filled, it is canceled, and it is not filled if the limit or stop order price was not met during the trading session. It is one of several different order duration types that determines how long the order is in the market before it is canceled.

  2. Good Till Cancelled(GTC)

    A good 'til canceled (GTC) order can be placed by an investor to buy or sell a security at a specified price that remains active until it is either rescinded by the investor or the trade is executed. GTC orders offer an alternative to placing a sequence of day orders, which expire at the end of each trading day. Rather than leave orders open ended, which poses the risk of being forgotten by investors until an eventual execution, GTC orders are commonly set to expire of 30 to 90 days after the trades are entered.

    • GTC Buy Orders
    • GTC Sell Orders
  3. Good Till Date/Time(GTD)

    The GTD (Good-til-Date/Time) time in force lets you select an expiration date and time up until which an order will continue to work. Setting this attribute requires both a time in force selection of GTD, a date entry in the Expiration Date field, and a time entry in the Expiration Time field if that level of detail is required. Note that if you only enter a good-till date, the unfilled order will cancel at the close of the market on the specified day.

  4. Time Of Day Order

    An order to buy or sell an asset that is placed at a specific time period during a trading session. A time-of-day order enters the market at a predetermined minute and remains good until canceled, unless otherwise specified.

CONTIGENCY ORDERS

如果我们希望订单在满足某些特定条件才执行的话,特别是当你无法一直监视市场的时候。
这些订单类型允许交易者在一定条件满足时自动开仓或平仓。

  1. Fill Or Kill(FOK): 全额即时订单

    全额即时订单也称为全部即刻执行否则撤销订单,指要求立即以特定的价格(通常只能为限价)予以执行,否则撤销订单。全额即时订单只能全部成交,而不能成交订单数量的一部分。

    Fill or kill (FOK) is a type of time-in-force designation used in securities trading that instructs a brokerage to execute a transaction immediately and completely or not at all. This type of order is most likely to be used by active traders and is usually for a large quantity of stock. The order must be filled in its entirety or canceled (killed).

  2. Fill And Kill(FAK): 非全额即时订单

    非全额即时订单指要求立即以特定的价格(可以为限价或市价)予以执行,否则撤销的订单。非全额即时订单允许部分成交,在部分成交时未成交的部分立刻撤销。

  3. Immediate Or Cancel(IOC)

    The Immediate-or Cancel (IOC) time in force applied to an order dictates that any portion of the order that does not fill immediately will be canceled.

  4. All Or None(AON)

    All or none (AON) is an instruction used on a buy or sell order that instructs the broker to fill the order completely or not at all. ** If there are not enough shares available to fill the order completely, the order is canceled when the market closes. ** An AON order is considered a duration order because the investor provides instructions to the trader about how the order must be filled, which impacts how long the order remains active.

For Automatic OPENING of a Position

  1. Market If Touched(MIT) Order

    触价指令是指市场价格只要触及客户所规定的价格水平时就生效的指令。当市场价格触及指定价格时才执行买进或卖出动作。

    A Market if Touched (MIT) is an order to buy (or sell) an instrument below (or above) the market. Its purpose is to take advantage of sudden or unexpected changes in share or other prices and provides investors with a trigger price to set an order in motion. Investors may be waiting for excessive strength (or weakness) to cease, which might be represented by a specific price point. MIT orders can be used to determine whether or not to enter the market once a specific price level has been achieved. This order is held in the system until the trigger price is touched, and is then submitted as a market order. An MIT order is similar to a stop order, except that an MIT sell order is placed above the current market price, and a stop sell order is placed below.

  2. Limit If Touched(LIT) Order: 触及限价定单

    触及限价定单是一种以特定或更优的价格,以及低于(或高于)市价的价格买入(或卖出)金融产品的定单。这类定单被持有在系统中直到触发价格被触及。触及限价定单与限价止损定单相似,除了触及限价卖出定单以高于当前市场价格被下达,而限价止损卖出定单则是以低于市价被下达的。
    使用触及限价定单帮助确保,如果定单被执行的话,定单将不会以劣于限价的价格执行。

For Automatic CLOSING of a Position

  1. Stop Order: 止损定单

    止损定单指令系统在用户指定的止损触发价格被达到提交一份买或卖的市价单。止损定单不担保某个特定的执行价格且有可能执行价格远离其止损价格。卖出止损定单总是以低于当前的市场价格下达,通常用于限制某个多头股票头寸的损失或保护其利润。买入止损定单总是以高于当前的市场价格下达,通常用于限制某个卖空头寸的损失或帮助其保护利润。

  2. Stop Limit Order: 止损限价单

    止损限价单指令系统在用户指定的止损触发价格被触碰或超越时提交一份买或卖限价单。该定单由两个基本部分组成:止损价和限价。当一笔交易以止损价或通过止损价发生时,定单成为可执行的并以限价单(以某个特定的价格或更好的价格买入或卖出的定单)的形式进入市场。
    止损限价单避免了止损单具有的价格风险(此风险是指不能担保执行价格),但投资人需承担即使在止损价格达到时定单仍不能执行的风险。投资人有可能完全“失去市场”。

  3. Trailing Stop Order: 追踪止损定单

    一个卖出追踪止损定单将止损价格设置为低于市场价格的一个固定金额,并带有附加的“追踪”金额。随着市场价格上涨,止损价格上涨的幅度为追踪金额,但如果股票价格下跌,止损价格不改变,当止损价格被触及时,一份市价定单将被提交。这种方法被设计用来允许投资者对可能损失的最大值指定限额,而不用对可能收益的最大值设定限额。“买入”追踪止损定单是卖出追踪止损定单的镜像,最适合用在下跌的市场中。

  4. Trailing Stop Limit Order: 追踪止损限价定单

    追踪止损限价定单允许投资者对可能损失的最大值指定限额,而不用对可能收益的最大值设定限额。追踪止损限价卖出定单与市场价格一起移动,并根据用户定义的“追踪”金额,连续地以低于市价的固定金额重新计算止损触发价格。限价定单价格同样根据限价抵消被连续地计算。随着市场价格上涨,止损价格和限价的上涨幅度分别为追踪金额和限价抵消,但如果股票价格下跌,止损价格保持不变,当止损价格被触及时,一份限价定单将以最后计算的限价被提交。追踪止损限价“买入”定单是追踪止损限价卖出定单的镜像,并通常被用在下跌的市场中。

More COMPLEX Types of Contingency Orders

  1. Conditional / Contingent Order

  2. Bracketed Order: 括号定单

    括号定单旨在通过用两个方向相反的定单将定单“括”起来以帮助您限制损失、锁定利润。给买单加括号,使用的是一份高位卖出限价定单和一份低位卖出止损定单。给卖单加括号,使用的是一份高位买入止损定单和一份低位买入限价定单。
    高位和低位括号定单的定单数量与最初的定单数量相匹配。默认情况下,括号定单从当前价格偏离1.0。您能够在特定定单的定单行上更改该偏离金额,也可使用全局配置中的定单预设功能修改产品、合约或策略的默认水平值。

  3. One Cancels Other(OCO) & One Cancels All(OCA) Orders

    A one-cancels-the-other order (OCO) is a pair of orders stipulating that if one order is executed, then the other order is automatically canceled. A one-cancels-the-other order (OCO) combines a stop order with a limit order on an automated trading platform. When either the stop or limit level is reached and the order executed, the other order will be automatically canceled. Seasoned traders use OCO orders to mitigate risk.
    one-Cancels All (OCA) order type allows an investor to place multiple and possibly unrelated orders assigned to a group. The aim is to complete just one of the orders, which in turn will cause TWS to cancel the remaining orders. The investor may submit several orders aimed at taking advantage of the most desirable price within the group. Completion of one piece of the group order causes cancellation of the remaining group orders while partial completion causes the group to rebalance. An investor might desire to sell 1000 shares of only ONE of three positions held above prevailing market prices. The OCA order group allows the investor to enter prices at specified target levels and if one is completed, the other two will automatically cancel. Alternatively, an investor may wish to take a LONG position in eMini S&P stock index futures in a falling market or else SELL US treasury futures at a more favorable price. Grouping the two orders using an OCA order type offers the investor two chances to enter a similar position, while only running the risk of taking on a single position.

  4. One Triggers Other(OTO) & One Triggers All(OTA) Orders

订单优先原则

  1. 价格优先原则

    价格优先原则指交易所(或做市商)在对投资者的订单进行撮合时,按照价格的高低原则进行排序,较高价格的买进订单优先于较低价格的买进订单,较低价格的卖出订单优先于较高价格的卖出订单。

  2. 时间优先原则

    按比例分配原则是指所有订单在价格相同的情况下,成交数量基于订单数量按比例进行分配。纽约证券交易所的大厅交易、芝加哥期权交易所等采取了按比例分配的订单优先原则。

  3. 按比例分配原则

    按比例分配原则是指所有订单在价格相同的情况下,成交数量基于订单数量按比例进行分配。纽约证券交易所的大厅交易、芝加哥期权交易所等采取了按比例分配的订单优先原则。

  4. 数量优先原则

    在价格一样、甚至价格一样且无法区分时间先后的情况下,有些交易所规定应遵循数量优先原则。数量优先原则而有两种形式,一是在订单价格相同且时间也相同的情况下,订单数量较大者优先于订单数量较小者;二是在数量上完全匹配的订单(即买进订单和卖出订单在数量上相等)优先于数量不一致的订单。第一种形式使得经纪商优先处理数量较大的订单,因而提高了流动性;第二种形式则减少了订单部分执行的情况。

  5. 客户优先原则

    客户优先原则通常指在同一价格条件下,公共订单优先于经纪商自营账户的订单。纽约证券交易所采取这一原则,客户的订单优先于专家的订单。客户优先原则减轻了客户与经纪商自营之间的利益冲突。

参考

https://www.interactivebrokers.com/cn/index.php?f=3361
https://www.zhihu.com/question/23667442

Python量化交易实战
欢迎您扫码订阅我的微信公众号: pyquant

资源

https://github.com/kennethreitz/awesome-coins

数据

  1. https://www.cryptocompare.com/api

Cryptocurrency data API for over 40 exchanges and 600 coins(BTC,ETH,XMR + 600 other cryptos)

Get open, high, low, close, volumefrom and volumeto from the each minute historical data. This data is only stored for 7 days, if you need more,use the hourly or daily path. It uses BTC conversion if data is not available because the coin is not trading in the specified currency

  1. https://bitcoincharts.com/about/markets-api/

Bitcoincharts’ API is accessable through HTTP
Parameters are passed using GET-requests
returned data is JSON encoded
Don’t query more often than once every 15 minutes!

Trade data is available as CSV, delayed by approx. 15 minutes. It will return the 2000 most recent trades.

  1. http://api.bitcoincharts.com/v1/csv/

  2. https://www.coinigy.com/bitcoin-data/

  3. https://www.quora.com/Where-can-I-get-per-tick-historical-bitcoin-price-data

  4. https://coinmarketcap.com/historical/

  5. https://github.com/CoinCapDev/CoinCap.io

  6. http://www.yucezhe.com/product/data#!?series=digital_currency

回测&交易

  1. https://github.com/CoinTK/CoinTK

Bitcoin Trading Algorithm Backtesting and Analysis Toolkit

  1. https://gekko.wizb.it/docs/introduction/about_gekko.html

A bitcoin trading bot written in node - https://gekko.wizb.it/

  1. https://cryptotrader.org/

  2. http://www.abuquant.com/lecture/lecture_10.html

比特币, 莱特币的走势数据分析 http://www.abuquant.com/

  1. https://github.com/ctubio/Krypto-trading-bot

Self-hosted crypto trading bot (automated high frequency market making) in node.js, angular, typescript and c++ https://127.0.0.1:3000

  1. https://www.kaggle.com/smitad/bitcoin-trading-strategy-simulation

API

Python

https://python-binance.readthedocs.io/en/latest/overview.html

binance

Java

https://github.com/timmolter/XChange

XChange is a Java library providing a streamlined API for interacting with 60+ Bitcoin and Altcoin exchanges providing a consistent interface for trading and accessing market data.

https://www.botvs.com/api

源码实现

https://github.com/bisq-network/exchange

The decentralized bitcoin exchange https://bisq.network

https://github.com/bitcoin/bitcoin

Bitcoin Core integration/staging tree

https://github.com/jamesob/tinychain

A pocket-sized implementation of Bitcoin

Python量化交易实战
欢迎您扫码订阅我的微信公众号: pyquant