Skip to content

Commit

Permalink
Okex precision loss
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouaini528 committed Aug 12, 2019
1 parent 4ed3614 commit 2d3d192
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/Api/Trader.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ function buy(array $data){
$trader=$this->map->response_trader()->buy(['result'=>$result,'request'=>$data]);

//如果交易默认完成,则不用再查询
if(isset($trader['_status']) && in_array($trader['_status'],['FILLED','FAILURE'])) return ['_error'=>$trader];
if(isset($trader['_status'])) {
if(in_array($trader['_status'],['FAILURE'])) return ['_error'=>$trader];
if(in_array($trader['_status'],['CANCELLED'])) return $trader;
}

//交易所是撮合交易,所以查询需要间隔时间
sleep(Exchanges::$TRADER_SHOW_TIME);
Expand Down Expand Up @@ -90,7 +93,10 @@ function sell(array $data){

//如果交易默认完成,则不用再查询
//bitmex 存在可能
if(isset($trader['_status']) && in_array($trader['_status'],['FILLED','FAILURE'])) return ['_error'=>$trader];
if(isset($trader['_status'])) {
if(in_array($trader['_status'],['FAILURE'])) return ['_error'=>$trader];
if(in_array($trader['_status'],['CANCELLED'])) return $trader;
}

//交易所是撮合交易,所以查询需要间隔时间
sleep(Exchanges::$TRADER_SHOW_TIME);
Expand Down Expand Up @@ -136,7 +142,10 @@ function cancel(array $data){
$trader=$this->map->response_trader()->cancel(['result'=>$result,'request'=>$data]);

//如果交易默认完成,则不用再查询
if(isset($trader['_status']) && in_array($trader['_status'],['CANCELLED','FAILURE'])) return ['_error'=>$trader];
if(isset($trader['_status'])) {
if(in_array($trader['_status'],['FAILURE'])) return ['_error'=>$trader];
if(in_array($trader['_status'],['CANCELLED'])) return $trader;
}

//交易所是撮合交易,所以查询需要间隔时间
sleep(Exchanges::$TRADER_SHOW_TIME);
Expand Down
6 changes: 4 additions & 2 deletions src/Map/ResponseTraderMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,12 @@ function show(array $data){
//判断是期货还是现货
switch ($this->checkType($data['result']['instrument_id'])){
case 'spot':{
//okex 小币种 精度又丢失的情况 不如dash-usdt filled_notional:只精度到0.1位 所以采用倒推的方式 filled_notional=price_avg*filled_size
$map['_filed_amount']=bcmul(strval($data['result']['price_avg']),strval($data['result']['filled_size']),16);

$map['_filled_qty']=$data['result']['filled_size'];
$data['result']['filled_size']==0?$map['_price_avg']=0:$map['_price_avg']=bcdiv(strval($data['result']['filled_notional']),strval($data['result']['filled_size']),16);
$data['result']['filled_size']==0 ? $map['_price_avg']=0 : $map['_price_avg']=bcdiv(strval($map['_filed_amount']),strval($data['result']['filled_size']),16);
$map['_status']=$this->okex_status['spot'][$data['result']['state']];
$map['_filed_amount']=$data['result']['filled_notional'];
break;
}
case 'future':{
Expand Down

0 comments on commit 2d3d192

Please sign in to comment.