o = e.source currency = o.symbol[:3] if o.status == Contract.Status.ORDERING \ or o.status == Contract.Status.CLOSING: print('%s_%s*%s*' % (o.symbol, o.contract_type, type_c[o.order_type]), '$%.3f(%d张)' % (0 if o.price is None else o.price, o.amount)) elif o.status == Contract.Status.ORDERED: print('%s_%s*%s*完成' % (o.symbol, o.contract_type, type_c[o.order_type]), '$%.3f(%d张), 费用%.5f%s' % (o.price, o.amount, o.fee, currency)) elif o.status == Contract.Status.CLOSED: print('%s_%s*%s*完成' % (o.symbol, o.contract_type, type_c[o.order_type]), '$%.3f(%d张)' % (o.price, o.amount), ', 利润%.5f%s (%s), 费用%.5f%s' % (o.margin, currency, '{:.2%}'.format(o.margin_rate), o.fee, currency)) elif o.status == Contract.Status.CANCELLED: print('%s_%s取消了*%s* $%.3f(%d张)' % (o.symbol, o.contract_type, type_c[o.order_type], o.price, o.amount)) else: print('%s_%s错误的通知类型*%s*' % (o.symbol, o.contract_type, o.status)) c = Contract(App.get_exchange('quarter'), symbol='EOS/USD', contract_type='quarter') c.subscribe(gaga) # c.order(Contract.OrderType.SELL, price=5) # time.sleep(20) # c.cancel() c.order(Contract.OrderType.SELL, price=5) time.sleep(10) # c.close(price=5) # time.sleep(10) # c.cancel() c.close()
self.fire(new_k=new_k) def data(self): return self.k def timestamp(self): return self.last_period.name def current(self): return self.last_period if __name__ == "__main__": import os from Application import Application as App App.read_config( os.path.split(os.path.realpath(__file__))[0] + '/../global.conf') logging.basicConfig(level=logging.INFO) def gaga(event): k = event.source print(dt.now(), len(k.data()), k.timestamp(), k.current()[K.VOLUME], event.new_k) k = K.k(App.get_exchange('quarter'), symbol='eos_usd', period='1min') k.subscribe(gaga) k.start()